Ambiguous permutation Runtime Error(SIGSEGV)

I am encountering a problem in practice questions(EASY)-Ambiguous Permutations.It says Runtime Error(SIGSEGV),even though it runs fine for all cases on my computer.Here is the code.

#include<stdio.h>
int main()
{
    int n = -1,i;
    while(n!=0)
    {
        int flag = 0;
        scanf("%d",&n);
        if(n==0)
        {
            break;
        }
        int a[10000];
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        for(i=1;i<=n;i++)
        {
            if(a[a[i]]!=i)
            {
                flag++;
            }
        }
        if(flag!=0)
        {
            printf("\nnot ambigious\n");
        }
        else
        {
            printf("\nambigious\n");
        }
    }
    return 0;
}

Please help.

1)The array size should not be 10000 but more. exactly how much? think!

2)Only 1 “\n” is sufficient (at the end).

3)your spelling of “ambiguous” is wrong :smiley:

Thanks.It worked out.So codechef checks for spellings as well?

Yes. you have to follow the exact o/p format specified in the question.

//