June cookoff 2020 PER CAPITA

Can anyone tell me why this is giving me runtime error is it because of the recursion limit in python?
https://www.codechef.com/viewsolution/34630691

Yes. Try setting recursion limit to 1e9.