Why is this program so slow?

(This is a template, feel free to delete it.)

What's problem you are encountering?

Program runs extremely slowly. About 90 seconds on either the Berkeley site or locally. An equivalent Python program runs locally almost instantaneously. (I understand I'm losing 12 seconds to the three "say" operations that occur with this input data.)

What have you tried that didn't work?

I tried pulling some logic out of the loop. I tried replacing the list lookup in the loop with a variable that is updated only when the value changes. I tried replacing the exponents with multiplications. If I pull all of the logic out of the loop, except the increment that allows it to terminate, elapsed time drops to about 1/5th of a second.

Post a project example, link, or screenshot:

When I run it either inside a WARP block or with Turbo mode on, it takes 12 seconds.

I get similar results. I had never used either capability before. Thanks for identifying them.