Johnny and the Beanstalk

My initial solution in Python gave TLE the exact same solution in Java
yielded AC