Project Euler 335 - Gathering the beans

Official link: https://projecteuler.net/problem=335