the lead game

Runtime Error(SIGSEGV)
#include<stdio.h>
int main()
{
int test,max=0,i,diff=0,flag=1;
int ar1[1001],ar2[1001];
scanf("%d",&test);
for(i=0;i<test;i++)
scanf("%d%d",&ar1[i],&ar2[i]);
for(i=0;i<test;i++)
{
diff=(ar1[i]>ar2[i])?(ar1[i]-ar2[i]):(ar2[i]-ar1[i]);
if(diff>max)
{
max=diff;
if(ar1[i]>ar2[i])
flag=i%2+1;

        else if(ar2[i]>ar1[i])
          flag=i%2+1;
    }
    
  
}
 printf("%d %d",flag,max);
return 0;
}

Your code get runtime error because of small size.so,Change array size arr1[1001] to arr1[10001] and arr2[1001] to arr2[10001].

//