brute force solution, some parts can be improved
easy python solution, cpp needs big integer handling