Here is my code: IDE 284335
I am getting correct answer when I compile but am getting run error when I am submitting the code
look at constraints
Constraints
1<=N<=10^6
so make size of array = 10^6
also use long long int instead of int
Modified code
i hope this helps
if yes hit a like and don’t forgot to mark doubt as resolved 
if you have more doubts regarding this feel free to ask
i think your doubt is resolved
so please mark doubt as resolved
if not then feel free to ask