Why is it showing run error?

Basically, you have to use long long int instead of only int everywhere in the code, since constraints are large, and use
long long int A[1000000]; as the size in your code is less, thts why its producing run time error

No, I changed all variables to long long still no success. :frowning:

I have modified your code a little bit, now try to submit your code