KIIT Coding Weekends problem in submission

in the KIIT Coding Weekends competition I tried the Large Products problem. My code works successfully on CodeBlocks and ideone.com it results in a ‘Wrong Answer’ in the codeChef IDE.
Can anyone try to help me…
here is my code…

#include <iostream>

using namespace std;

int main()
{

long long n;
cin>>n;
long long a[n];
for(long long i=0;i<n;i++)
{
    cin>>a[i];
    
}
long long p=1;
for(long long  i=0;i<n;i++)
{
    p*=a[i];
}
cout<<p+(1000000007)%(1000000007)<<" "<<endl;

}

Don’t post questions related to ongoing contest…

You should do the modulus at each step of multiplication so that the answer doesn’t become out of bound before we reach the last element . And use unsigned long long int for maximum number that can be stored .