Help in oct long contest prob msng

Well my code is giving correct answers for inputs but on submission its giving wrong answer…

i want to know whats wrong in the approach i have used or a particular test case which is failing…

problem - https://www.codechef.com/OCT19B/problems/MSNG
my solution - https://www.codechef.com/viewsolution/27370885

brief about approach used -

firstly i have taken base and the string , then when it is taking input for first time i have stored the possible answers in an array named arr, then i have checked if value of answer is their in arr or not for all other inputs … and i have also taken care for the condition when n=1.

its been 5 days i am looking for a case where the code is failing but i cant find one. …
It will be really thankfull if someone helps me in doing so…

check this test case:
1
1
-1 Z00000000000000000000000000000000000

your solution gives -9223372036854775808 as output. i think it should be “-1”

OOH! So this was it…

how to fix this??
i tried couple of things but none is working for this case…

PS - thanks for the reply …

use the boost library of c++…it can handle the larger numbers