In an infinite array with two rows, the numbers in the top row are denoted
`. . . , A[−2], A[−1], A[0], A[1], A[2], . . .`
and the numbers in the bottom row are denoted
`. . . , B[−2], B[−1], B[0], B[1], B[2], . . .`
For each integer `k`, the entry `A[k]` is directly above
the entry `B[k]` in the array, as shown:
...|A[-2]|A[-1]|A[0]|A[1]|A[2]|...
...|B[-2]|B[-1]|B[0]|B[1]|B[2]|...
For each integer `k`, `A[k]` is the average of the entry to its left, the entry to its right,
and the entry below it; similarly, each entry `B[k]` is the average of the entry to its
left, the entry to its right, and the entry above it.
Given `A[0], A[1], A[2] and A[3]`, determine the value of `A[n]`. (Where range of n is -1000 Inputs and Outputs in BigInt!** 
Adapted from 2018 Euclid Mathematics Contest.
https://www.cemc.uwaterloo.ca/contests/past_contests/2018/2018EuclidContest.pdf
def find_a(array, n):
    if 0 <= n <= 3: return array[n]
    a0 = array[0]
    a1 = array[1]
    a2 = array[2]
    a3 = array[3]
    b1 = 3*a1 - a0 - a2
    b2 = 3*a2 - a1 - a3
    b3 = 3*b2 - b1 - a2
    b0 = 3*b1 - b2 - a1
    if n > 3:
        for k in range(4, n+1, 1):
            an = 3*a3 - a2 - b3
            bn = 3*b3 - b2 - a3
            
            a2, a3 = a3, an
            b2, b3 = b3, bn
            
    else: 
        for k in range(-1, n-1, -1):
            an = 3*a0 - a1 - b0
            bn = 3*b0 - b1 - a0
            
            a0, a1 = an, a0
            b0, b1 = bn, b0
    
    return an
def find_a(array, n):
    if 0 <= n <= 3: return array[n]
    a0 = array[0]
    a1 = array[1]
    a2 = array[2]
    a3 = array[3]
    b1 = 3*a1 - a0 - a2
    b2 = 3*a2 - a1 - a3
    b3 = 3*b2 - b1 - a2
    b0 = 3*b1 - b2 - a1
    if n > 3:
        for k in range(4, n+1, 1):
            an = 3*a3 - a2 - b3
            bn = 3*b3 - b2 - a3
            
            a2, a3 = a3, an
            b2, b3 = b3, bn
            
    else: 
        for k in range(-1, n-1, -1):
            an = 3*a0 - a1 - b0
            bn = 3*b0 - b1 - a0
            
            a0, a1 = an, a0
            b0, b1 = bn, b0
    
    return an