Why i am getting runtime error?

Hi, please have a look at my code of fun with rotation and find out why i am getting run time error.

Link : http://www.codechef.com/viewsolution/4838245

 #include
 #include
 #define LL long long
 #define M 1000000007
 LL arr[100005];
int main()
{
LL n,i,m,start=1,index=0,d;
char c;
scanf("%lld %lld",&n,&m);
for(i=1;i<=n;i++)
scanf("%lld",&arr[i]);
while(m--)
{
	fflush(stdin);
	scanf("%c",&c);
	scanf("%lld",&d);
	if(c=='R')
	{
		if(start+d-1<=n)
	 printf("%lld\n",arr[start+d-1]);
	 else
	 {
	 	index=n-start+1;
	 	printf("%lld\n",arr[d-index]);
	 }
	}
	else if(c=='C')
	{
		start+=d;
		if(start>n)
	 start-=n;
	}
	else
	{
		start-=d;
		if(start<1)
	 start+=n;
	}
}
return 0;
}

add another line “scanf(”%c",&c)" after “scanf(”%c",&c)"

see this link for explanation

Thank you abhinav1234 for such a nice answer. But i want to ask whether fflush(stdin); will not store the extra character when we hit the enter after entering the integer.