ADIGIT wrong answer

I checked all the corner cases but still getting wrong answer…

#include<stdio.h>

int main()

{

long int n,m,x,i,c1,c2;
long long int ans;
int j;
scanf("%ld %ld",&n,&m);
char a[n];
long int dp[n][10];
scanf("%s",a);
for(j=0;j<=9;j++)
dp[0][j]=0;
dp[0][a[0]-'0']=1;
for(i=1;i<n;i++)
{
	for(j=0;j<=9;j++)
	{
		if((a[i]-'0')==j)
		dp[i][j]=dp[i-1][j]+1;
		else
		dp[i][j]=dp[i-1][j];
	}
}
while(m--)
{
	scanf("%ld",&x);
	c1=0;
	c2=0;
	ans=0;
	if(x==1)
	printf("%lld\n",a[x-1]-'0');
	else
	{
	for(i=0;i<=9;i++)
	{
		if((a[x-1]-'0')>=i)
		{
			ans=ans-dp[x-2][i]*i;
			c1=c1+dp[x-2][i];
		}
		else
		{
			ans=ans+dp[x-2][i]*i;
			c2=c2+dp[x-2][i];
		}
	}
	printf("%lld\n",(c1-c2)*(a[x-1]-'0')+ans);
}	
}
return 0;

}

Here are the mistakes:

  1. The answer for x==1 is always 0.

    So, instead of printf("%lld\n",a[x-1]-‘0’);, just write printf(“0\n”);

  2. There is no need for long long int, long int, use int, it is sufficient.

If you still have any problem, comment below.