Code not working properly

if i am taking 10^6 it is showing wrong ans and when i am taking 10^5 one test case is not passing.

this attached code is with 10^6 . please tell me the reasons why it is not working properly with 10^6.

hello @shivamgoel150
declare both array as global array.
reason >global scope can have higher memory capacity than function scope.
ur update code