Problem: There are N mountains in a circle, called Mountain 1, Mountain 2, ..., Mountain N in clockwise order. N is an _odd_ number.  Between these mountains, there are N dams, called Dam 1, Dam 2, ..., Dam N. Dam i (1 \leq i \leq N) is located between Mountain i and i+1 (Mountain N+1 is Mountain 1).  When Mountain i (1 \leq i \leq N) receives 2x liters of rain, Dam i-1 and Dam i each accumulates x liters of water (Dam 0 is Dam N).  One day, each of the mountains received a non-negative **even** number of liters of rain.  As a result, Dam i (1 \leq i \leq N) accumulated a total of A_i liters of water.  Find the amount of rain each of the mountains received. We can prove that the solution is unique under the constraints of this problem.

Submission attempts (in order):
n = int(input())
dl = list(map(int, input().split()))

ml = [0 for _ in range(n)]

while len(set(dl)) != 1 :
    m = max(dl)
    for i in range(n) :
        if dl[i] == m :
            if dl[i-1] >= dl[(i+1)%n] :
                lain = max(dl[i-1]-dl[i-2], dl[i]-dl[(i+1)%n])
                dl[i-1] -= lain
                dl[i] -= lain
                ml[i] += 2*lain
            else :
                lain = max(dl[i]-dl[i-1], dl[(i+1)%n]-dl[(i+2)%n])
                dl[i] -= lain
                dl[(i+1)%n] -= lain
                ml[(i+1)%n] += 2*lain
else :
    for i in range(n) :
        ml[i] += dl[-1]

for i in range(n) :
    print(ml[i],end=" ")

n = int(input())
dl = list(map(int, input().split()))

ml = [0 for _ in range(n)]

while len(set(dl)) != 1 :
    for i in range(n) :
        if dl[i] == max(dl) :
            if dl[i-1] >= dl[(i+1)%n] :
                lain = dl[i]-dl[(i+1)%n]
                dl[i-1] -= lain
                dl[i] -= lain
                ml[i] += 2*lain
            else :
                lain = dl[i]-dl[i-1]
                dl[i] -= lain
                dl[(i+1)%n] -= lain
                ml[(i+1)%n] += 2*lain
else :
    for i in range(n) :
        ml[i] += dl[-1]

for i in range(n) :
    print(ml[i],end=" ")

n = int(input())
dl = list(map(int, input().split()))

ml = [0 for _ in range(n)]

while len(set(dl)) != 1 :
    for i in range(n) :
        if dl[i] == max(dl) :
            if dl[i-1] >= dl[(i+1)%n] :
                lain = dl[i]-dl[i-2]
                dl[i-1] -= lain
                dl[i] -= lain
                ml[i] += 2*lain
            else :
                lain = dl[i]-dl[(i+2)%n]
                dl[i] -= lain
                dl[(i+1)%n] -= lain
                ml[(i+1)%n] += 2*lain
else :
    for i in range(n) :
        ml[i] += dl[-1]

for i in range(n) :
    print(ml[i],end=" ")

n = int(input())
dl = list(map(int, input().split()))

ml = [0 for _ in range(n)]

while len(set(dl)) != 1 :
    m = max(dl)
    for i in range(n) :
        if dl[i] == m :
            if dl[i-1] >= dl[(i+1)%n] :
                lain = dl[i]-dl[(i+1)%n]
                dl[i-1] -= lain
                dl[i] -= lain
                ml[i] += 2*lain
            else :
                lain = dl[i]-dl[i-1]
                dl[i] -= lain
                dl[(i+1)%n] -= lain
                ml[(i+1)%n] += 2*lain
else :
    for i in range(n) :
        ml[i] += dl[-1]

for i in range(n) :
    print(ml[i],end=" ")

n = int(input())
a = list(map(int, input().split()))

# m0 + m1 + m2 + m3 + m4 = d0 + d1 + d2 + d3 + d5
# d0 = (m0 + m1)//2
# d1 = (m1 + m2)//2
# d2 = (m2 + m3)//2
# d3 = (m3 + m4)//2
# d4 = (m4 + m0)//2
# m0 =  d0 - d1 + d2 - d3 + d4
# m1 =  d0 + d1 - d2 + d3 - d4
# m2 = -d0 + d1 + d2 - d3 + d4
# m3 =  d0 - d1 + d2 + d3 - d4
# m4 = -d0 + d1 - d2 + d3 + d4   

b = [a[i:]+a[:i] for i in range(n)]
print(*[sum(b[::2])-sum(b[1::2]) for i in range(n)])

n = int(input())
a = list(map(int, input().split()))

# m0 + m1 + m2 + m3 + m4 = d0 + d1 + d2 + d3 + d5
# d0 = (m0 + m1)//2
# d1 = (m1 + m2)//2
# d2 = (m2 + m3)//2
# d3 = (m3 + m4)//2
# d4 = (m4 + m0)//2
# m0 =  d0 - d1 + d2 - d3 + d4
# m1 =  d0 + d1 - d2 + d3 - d4
# m2 = -d0 + d1 + d2 - d3 + d4
# m3 =  d0 - d1 + d2 + d3 - d4
# m4 = -d0 + d1 - d2 + d3 + d4   
s = sum(a)
p = [0 for _ in range(n)]
q = [0 for _ in range(n+1)]
for i in range(n) :
    if i>1 :
        p[i] = p[i-2] + a[i-2]
    q[n-i-2] = q[n-i] + a[n-i-1]

print(*[s-2*p[i]-2*q[i] for i in range(n)])

Verdicts: Time Limit Exceeded

Time Limit Exceeded

Time Limit Exceeded

Time Limit Exceeded

Runtime Error

Accepted