Running the line starting with num = 2134 results in a Python process that uses 63.7 MB of memory on my system. I think it is unlikely to be an out of memory error. I don’t know what the problem could be though.