Marbles problem

I am failing at bigger values even after using python.
Please help