The bruteforce/recursive solution is easy and explicit. However, it is possible that the recursive levels are so high that we are out of computing resources (memory & time) before reaching the result. For example, knowing A=1A, calculating A[1,000,000,000] recursively would be computationally formidable.

To cut down the running time, we need to find out the repeating patterns of the lists, if there exist. Some lists do have detectable repeating patterns. Your program would get accepted as long as the following three cases are handled.