Harryxun/stf_run huggingface dataset:
def dia(Node):
	lst = []
	if(len(Node) == 0):
		lst.append(1)
	else:
		for n in Node:
			t = dia(d[n])
			lst.append(t+1)
	return max(lst)
		
N = input()
A = []
for i in range(N-1):
	a2,b2 = map(int, raw_input().split())
	if(a2 > b2):
		a2,b2 = b2,a2
	k = [a2,b2]
	A.append(k)
root = A[0][0]
rootd = [A[0][1]]
d = {A[0][0]:[A[0][1]],A[0][1]:[]}
A.pop(0)
for a2 in A:
	if(a2[0] in d):
		t = d[a2[0]]
		n = a2[1]
	elif(a2[1] in d):
		t = d[a2[1]]
		n = a2[0]
	else:
		A.append(a2)
		continue
	t.append(n)
	d[n] = []
lst = []
for n in d[root]:
	lst.append(dia(d[n]))
m1 = max(lst)
lst.remove(m1)
if(len(lst) == 0):
	m2 = 1
else:
	m2 = max(lst)+1
if((m1 + m2) % 3 == 2):
	print("Second")
else:
	print("First")

### FIXED CODE ###

from collections import deque
def dia(i):
	lst = [-1]*N
	lst[i] = 0
	q = deque([i])
	while q:
		c = q.popleft()
		l = lst[c]
		for i in A[c]:
			if lst[i] != -1:
				continue
			else:
				lst[i] = l+1
				q.append(i)
	return lst.index(max(lst))
def dia2(i):
	lst = [-1]*N
	lst[i] = 0
	q = deque([i])
	while q:
		c = q.popleft()
		l = lst[c]
		for i in A[c]:
			if lst[i] != -1:
				continue
			else:
				lst[i] = l+1
				q.append(i)
	return max(lst)+1
N = input()
A = [[] for i in range(N)]
for i in range(N-1):
	a2,b2 = map(int, raw_input().split())
	A[a2-1].append(b2-1)
	A[b2-1].append(a2-1)
if((dia2(dia(0))) % 3 == 2):
	print("Second")
else:
	print("First")
def a(t,i):
    if i==l-1:
        return sum(map(int,t.split('+'))))
    return a(t+s[i+1],i+1)+a(t+'+'+s(i+1),i+1)
s=input()
l = len(s)
print(a(s[0],0))


### FIXED CODE ###

def dfs(i,s):
    if i==n-1:
        return sum(map(int,s.split('+')))
    return dfs(i+1,s+S[i+1])+dfs(i+1,s+'+'+S[i+1])

S=input()
n=len(S)
ans=dfs(0,S[0])
print(ans)
a=input()
print(input()+a)

### FIXED CODE ###

s = input().split()
print(s[1]+s[0])
n, k = map(int, input().split())
a = list(map(lambda x: int(x)-1, input().split()))
n = a[0]
his = [-1, n]
while True:
    n = a[n]
    if n in his:
        his.append(n)
        break
    his.append(n)
idx = his.index(his[-1])
loop = len(his[his.index(his[-1]):-1])
if len(his) > k:
    print(his[k]+1)
else:
    t = (k - idx) % loop
    g = his[idx:-1]
    print(g[t]+1)

### FIXED CODE ###

s = input()
t = input()
if len(s) +1 != len(t):
    print('No')
    exit()
if s == t[:-1]:
    print('Yes')
    exit()
print('No')
N = int(input())
A = list(map(int, input().split()))

nums = A[:]
import math

def cal_gcd(i, flag, ans):
    if i == len(nums):
        return ans
    ans_0 = -1
    if flag == False:
        ans_0 = cal_gcd(i+1, True, ans)
    
    if ans == 0:
        ans = nums[i]
    #print(i)
    ans = math.gcd(ans, nums[i])
    ans_1 = cal_gcd(i+1, flag, ans)
    return max(ans_0, ans_1)
    
ans = cal_gcd(0, False, 0)
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))

nums = A[:]
import fractions

gcd_queue = [
    (nums[0], True),
    (nums[1], True),
    (fractions.gcd(nums[0], nums[1]), False),
]
for n in nums[2:]:
    tmp_queue = []
    for q in gcd_queue:
        if q[1] == True:
            tmp_queue.append((fractions.gcd(q[0], n), True))
        else:
            tmp_queue.append((fractions.gcd(q[0], n), False))
            tmp_queue.append((q[0], True))
    gcd_queue = set(tmp_queue[:])

ans = 0
for q in gcd_queue:
    ans = max(ans, q[0])
print(ans)
n = int(input())
li = [list(map(int,input().split())) for i in range(n)]

if li[1][1] - abs(li[1][2]) - abs(li[1][3]) < 0:
  print("NO")
  exit()
elif li[1][1] - abs(li[1][2]) - abs(li[1][3]) > 0:
  if (li[1][1] - abs(li[1][2]) - abs(li[1][3])) % 2 != 0:
    print("NO")
    exit()
else:
  for k in range(1,n):
    t = li[k][1]
    x = li[k][2]
    y = li[k][3]
    tt = li[k-1][1]
    xx = li[k-1][2]
    yy = li[k-1][3]
    if t - tt - abs(x - xx) - abs(y - yy) <0:
      print("NO")
      exit()
    elif t - tt - abs(x - xx) - abs(y - yy) <0:
      (t - tt - abs(x - xx) - abs(y - yy)) % 2 != 0:
        print("NO")
        exit()
print("YES")

### FIXED CODE ###

n = int(input())
li = [list(map(int,input().split())) for i in range(n)]
 
if li[0][0] - abs(li[0][1]) - abs(li[0][2]) < 0:
  print("No")
  exit()
elif li[0][0] - abs(li[0][1]) - abs(li[0][2]) > 0:
  if (li[0][0] - abs(li[0][1]) - abs(li[0][2])) % 2 != 0:
    print("No")
    exit()
else:
  for k in range(1,n):
    t = li[k][0]
    x = li[k][1]
    y = li[k][2]
    tt = li[k-1][0]
    xx = li[k-1][1]
    yy = li[k-1][2]
    if t - tt - abs(x - xx) - abs(y - yy) <0:
      print("No")
      exit()
    elif t - tt - abs(x - xx) - abs(y - yy) <0:
      if (t - tt - abs(x - xx) - abs(y - yy)) % 2 != 0:
        print("No")
        exit()
print("Yes")
import numpy as np
s = input()
cnt = 0
ss = []
nums = np.array([(i+1)*2019 for i in range(200000//2019) if not "0" in str((i+1)*2019)])
for start in range(len(s)):
  end = start + 3
  while(end+1<=len(s)):
    if int(s[start:end+1]) in nums:
      cnt += 1
    end += 1
print(cnt)

### FIXED CODE ###

s = input()
l = len(s)
dp = [0]*2019
dp[0] = 1
r = 0
for i in range(1, l + 1):
    r += int(s[-i]) * pow(10, i - 1, 2019)
    r %= 2019
    dp[r] += 1
    
print(sum([(i * (i - 1)) // 2 for i in dp]))
a,b,k=(map(int, input().split()))
 if a>k:
  print(a-k,b)
else:
  if a+b>k:
    print(0,a+b-k)
  else:
    print(0,0)

### FIXED CODE ###

a,b,k=(map(int, input().split()))
if a>k:
  print(a-k,b)
else:
  if a+b>k:
    print(0,a+b-k)
  else:
    print(0,0)
N,P = map(int,input().split())
if N==1:
    print(P)
else:
    cmax = 1
    for i in range(1,int(P**0.5)+1):
        if P%(i**N)==0:
            cmax = i
    print(cmax)

### FIXED CODE ###

N,P = map(int,input().split())
if N==1 or P==1:
    print(P)
else:
    k = 0
    x = P
    while x>1:
        x = x//2
        k += 1
    if N>k:
        print(1)
    else:
        cmax = 1
        for i in range(1,int(P**0.5)+1):
            if P%(i**N)==0:
                cmax = i
        print(cmax)
# coding: UTF-8
N = int(input())
ans = N / (N // 2)
print(ans)

### FIXED CODE ###

# coding: UTF-8
N = int(input())
ans = -(-N // 2) / N
print(ans)
x, y = map(int, input().split())
    if 0 < x < 10 and 0 < y < 10:
        print(x * y)
    else:
        print(-1)

### FIXED CODE ###

x, y = map(int, input().split())
if 0 < x < 10 and 0 < y < 10:
    print(x * y)
else:
    print(-1)
while True:
    a,b,c = map(int, input().strip().split(' '))
    temp = 0
    if a == 0 and b == 0 and c == 0:
        break
    for i in range(1, c+1):
        for j in range(1, c+1):
            if i*(100+a)//100 + j*(100+a)//100 == c:
                if temp < i*(100+b)//100 + j*(100+b)//100:
                    temp = i*(100+b)//100 + j*(100+b)//100
    print(temp)


### FIXED CODE ###

while True:
    a,b,c = map(int, input().strip().split(' '))
    temp = 0
    if a == 0 and b == 0 and c == 0:
        break
    for i in range(1, c):
        for j in range(i, c):
            if i*(100+a)//100 + j*(100+a)//100 == c:
                if temp < i*(100+b)//100 + j*(100+b)//100:
                    temp = i*(100+b)//100 + j*(100+b)//100
    print(temp)
x, t = map(int, input().split())
print(x-t)x, t = map(int, input().split())
print(max(x-t,0))

### FIXED CODE ###

x, t = map(int, input().split())
print(max(x-t,0))
count = 1
while True:
x = input().strip()
if x == '0':
     break
print('Case %s: %s' % (count, x))
count = count + 1

### FIXED CODE ###

import sys
count = 1
while True:
    x = input().strip()
    if x == '0':
         break
    print('Case %s: %s' % (count, x))
    count = count + 1
List =[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

i = int(input())

print(List[i])

### FIXED CODE ###

List =[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
 
i = int(input())
 
print(List[i-1])
"""
in1 = '7 4 4'
in2 = ['1 2', '2 3', '2 5', '6 7', '3 5', '4 5', '3 4', '6 7']
N, K, L = [int(_) for _ in in1.split()]
pqrs = [[int(_) for _ in _.split()] for _ in in2]
"""
N, K, L = [int(_) for _ in input().split()]
pqrs = [[int(_) for _ in _.split()] for _ in input()]

def makeTree(a):
    aT = list(range(N + 1))
    for p, q in a:
        rootp     = getRoot(aT, p)
        rootq     = getRoot(aT, q)
        thisRoot  = max(rootp, rootq, q)
        aT[p]     = thisRoot
        aT[q]     = thisRoot
        aT[rootp] = thisRoot
        aT[rootq] = thisRoot
    return aT

def getRoot(a,i):
    if a[i] == i:
        return i
    else:
        a[i] = getRoot(a, a[i])
        return a[i]

MTree = makeTree(pqrs[0:K])
TTree = makeTree(pqrs[K:])

aRet = []
dRet = {}
for idx1 in range(1, N + 1):
    Comb = (getRoot(MTree, idx1), getRoot(TTree, idx1))
    aRet.append(Comb)
    if Comb in dRet:
        dRet[Comb] += 1
    else:
        dRet[Comb] = 1

print(" ".join([str(dRet[_]) for _ in aRet]))


### FIXED CODE ###

"""
in1 = '7 4 4'
in2 = ['1 2', '2 3', '2 5', '6 7', '3 5', '4 5', '3 4', '6 7']
N, K, L = map(int, in1.split())
pqrs = []
for idx1 in range(K + L):
    temp0, temp1 = map(int, in2[idx1].split())
    pqrs.append([temp0, temp1])
"""

def makeTree(a):
    aT = list(range(N + 1))
    for p, q in a:
        rootp     = getRoot(aT, p)
        rootq     = getRoot(aT, q)
        thisRoot  = max(rootp, rootq, q)
        aT[p]     = thisRoot
        aT[q]     = thisRoot
        aT[rootp] = thisRoot
        aT[rootq] = thisRoot
    return aT

def getRoot(a,i):
    if a[i] == i:
        return i
    else:
        a[i] = getRoot(a, a[i])
        return a[i]

N, K, L = map(int, input().split())
pqrs = []
for idx1 in range(K + L):
    temp0, temp1 = map(int, input().split())
    pqrs.append([temp0, temp1])

MTree = makeTree(pqrs[0:K])
TTree = makeTree(pqrs[K:])

aRet = []
dRet = {}
for idx1 in range(1, N + 1):
    Comb = (getRoot(MTree, idx1), getRoot(TTree, idx1))
    aRet.append(Comb)
    if Comb in dRet:
        dRet[Comb] += 1
    else:
        dRet[Comb] = 1

print(" ".join([str(dRet[_]) for _ in aRet]))
import numpy as np
 
X,N = map(int,input().split())
p = input()
 
if N != 0:
    
    p_list = [int(n) for n in p.split()]
    
    X_near = np.array(list(range(int(np.ceil(X - N/2)), int(np.floor(X + N/2)) + 1)))
 
    remain_list = []
 
    for i in X_near:
        if i not in p_list:
            remain_list.append(i)
        
 
    remain_array = np.array(remain_list)
    min_bool = np.abs(X - remain_array).min() == np.abs(X - remain_array)
    print(remain_array[min_bool].min())
    
if N == 0:
    print(X)

### FIXED CODE ###

import numpy as np
 
X,N = map(int,input().split())
p = input()
 
if N != 0:
    
    p_list = [int(n) for n in p.split()]
    
    X_near = np.array(list(range(int(np.ceil(X - N/2 - 1)), int(np.floor(X + N/2)) + 2)))
 
    remain_list = []
 
    for i in X_near:
        if i not in p_list:
            remain_list.append(i)
        
 
    remain_array = np.array(remain_list)
    min_bool = np.abs(X - remain_array).min() == np.abs(X - remain_array)
    print(remain_array[min_bool].min())
    
if N == 0:
    print(X)
num = input().split()

str = input()
strc = ''
for i in range(int(num[0])-1):
  strc = input()
  if str > strc:
    str = strc + str
  else:
    str = str + strc
print(str)

### FIXED CODE ###

num= input().split()
count5 = 0
count7 = 0
 
for i in range(len(num)):
    if num[i] == '5':
        count5 += 1
    elif num[i] == '7':
        count7 += 1
    else:
        continue
if count5 == 2 and count7 == 1:
    print('YES')
else:
    print('NO')
#!/usr/bin/env python3

N,M = map(int, input().split())
from collections import defaultdict
d = defaultdict(int)
S = [1]+[0]*(N-1)
for i in range(M):
    s,c = map(int, input().split())
    s -= 1
    if d[s] > 0 and S[s] != c:
        print(-1)
        exit()
    S[s] = c
    d[s] += 1
if S[0] == 0:
    print(-1)
    exit()
if len(S) == 1:
    print("".join([str(s) for s in S]))
else:
    if d[s] == 0:
        x = [1]+[0]*(N-1)
        ans = "".join([str(_) for _ in x])
        print(ans)
    else:
        print("".join([str(s) for s in S]))


### FIXED CODE ###

#!/usr/bin/env python3

N,M = map(int, input().split())
from collections import defaultdict
d = defaultdict(int)
S = [1]+[0]*(N-1)
flg = True
for i in range(M):
    s,c = map(int, input().split())
    s -= 1
    if d[s] > 0 and S[s] != c:
        flg = False
    S[s] = c
    d[s] += 1

if M == 0 and N == 1:
    print(0)
    exit()
if not flg:
    print(-1)
    exit()
if S[0] == 0:
    if len(S) == 1:
        print(*S)
    else:
        print(-1)
    exit()
print("".join([str(s) for s in S]))
n = int(input())
Num = [2,1]

for i in range(2,86):
    new = Num[i-1] + Num[i-2]
    Num.append(new)

ans = Num[n]
print(ans)

### FIXED CODE ###

n = int(input())
Num = [2,1]

for i in range(2,87):
    new = Num[i-1] + Num[i-2]
    Num.append(new)

ans = Num[n]
print(ans)
a, b, c = map(int, input().split())
if (100*r + 10*g + b)%4 == 0:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

r, g, b = map(int, input().split())
if (100*r + 10*g + b)%4 == 0:
    print("YES")
else:
    print("NO")
h,w = map(int,input().split())

arr = ["0" *(w + 2)]
for i in range(h):
    arr.append("0" + input() + "0")
arr.append("0" *(w + 2))

flg = [[-1 for i in range(h+2)] for j in range(w+2)]

ima = []
for i in range(h+2):
    for j in range(w+2):
        if arr[i][j] == "#":
            ima.append([i,j])
            flg[i][j] = 0

while len(ima) > 0:
    tugi = []
    for x,y in ima:
        if arr[x+1][y] == "." and flg[x+1][y] == -1:
            tugi.append([x+1,y])         
            flg[x+1][y] = flg[x][y] + 1
        if arr[x-1][y] == "." and flg[x-1][y] == -1:
            tugi.append([x-1,y])
            flg[x-1][y] = flg[x][y] + 1
        if arr[x][y+1] == "." and flg[x][y+1] == -1:
            tugi.append([x,y+1])
            flg[x][y+1] = flg[x][y] + 1
        if arr[x][y-1] == "." and flg[x][y-1] == -1:
            tugi.append([x,y-1])
            flg[x][y-1] = flg[x][y] + 1
    ima = tugi

ans = -1
for i in flg:
    for j in i:
        if ans < j:
            ans = j
print(ans)

### FIXED CODE ###

h,w = map(int,input().split())

arr = ["0" *(w + 2)]
for i in range(h):
    arr.append("0" + input() + "0")
arr.append("0" *(w + 2))

flg = [[-1 for i in range(w+2)] for j in range(h+2)]

ima = []
for i in range(h+2):
    for j in range(w+2):
        if arr[i][j] == "#":
            ima.append([i,j])
            flg[i][j] = 0

while len(ima) > 0:
    tugi = []
    for x,y in ima:
        if arr[x+1][y] == "." and flg[x+1][y] == -1:
            tugi.append([x+1,y])         
            flg[x+1][y] = flg[x][y] + 1
        if arr[x-1][y] == "." and flg[x-1][y] == -1:
            tugi.append([x-1,y])
            flg[x-1][y] = flg[x][y] + 1
        if arr[x][y+1] == "." and flg[x][y+1] == -1:
            tugi.append([x,y+1])
            flg[x][y+1] = flg[x][y] + 1
        if arr[x][y-1] == "." and flg[x][y-1] == -1:
            tugi.append([x,y-1])
            flg[x][y-1] = flg[x][y] + 1
    ima = tugi

ans = -1
for i in flg:
    for j in i:
        if ans < j:
            ans = j
print(ans)
import numpy as np
n,m = map(int,input().split())
a = [int(input()) for i in range(m)]

dp = [0] * (n+1)
for i in range(n+1):
     if i in a:
          dp[i] = 0
     elif i == 0 or i == 1:
          dp[i] = 1
     else:
          dp[i] = (dp[i-1] + dp[i-2])%1000000007
print(dp[n])

### FIXED CODE ###

n, m = map(int, input().split())
mod = 10**9 + 7
dp = [1]*(n+1)
 
for _ in range(m):
    a = int(input())
    dp[a] = 0
 
for i in range(2, n+1):
    if dp[i]>0:
        dp[i] = (dp[i-1]+dp[i-2])%mod
 
print(dp[n])
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

x, y, a, b, c = LI()
p = LI()
q = LI()
r = LI()

p.sort(reverse=1)
q.sort(reverse=1)
r.sort(reverse=1)
r = list(accumulate(r))
ans = 0
h = []
s = sum(p[:x])
s += sum(q[:y])
for i in p[:x]:
    heappush(h, i)
for i in q[:y]:
    heappush(h, i)
ans = s
for i in range(c):
    f = heappop(h)
    s -= f
    tmp = s + r[i]
    ans = max(ans, tmp)
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

x, y, a, b, c = LI()
p = LI()
q = LI()
r = LI()

p.sort(reverse=1)
q.sort(reverse=1)
r.sort(reverse=1)
r = list(accumulate(r))
ans = 0
h = []
s = sum(p[:x])
s += sum(q[:y])
for i in p[:x]:
    heappush(h, i)
for i in q[:y]:
    heappush(h, i)
ans = s
for i in range(c):
    if len(h) > 0:
        f = heappop(h)
    else:
        break
    s -= f
    tmp = s + r[i]
    ans = max(ans, tmp)
print(ans)
N = int(input())
p = list(map(int, input().split()))

k = 0
counter = 1
for e in p:
    if e == counter:
        counter += 1
    else:
        k += 1
        counter += 1

if k <= 2:
    print('YES')
else:
    orint('NO')

### FIXED CODE ###

N = int(input())
p = list(map(int, input().split()))

k = 0
counter = 1
for e in p:
    if e == counter:
        counter += 1
    else:
        k += 1
        counter += 1

if k <= 2:
    print('YES')
else:
    print('NO')
N = int(input())

BLACK = -1
GRAY = 0
WHITE = 1
nodes = [GRAY] * N
nodes[0] = BLACK
neighbors = [[] for _ in range(N)]

for n in range(N-1):
    u, v, w = [int(i) for i in input().split()]
    neighbors[u-1].append((v-1, w))
    neighbors[v-1].append((u-1, w))


def dfs(u):
    neiss = neighbors[u]
    for neis in neiss:
        v, w = neis
        if nodes[v] == GRAY:
            if w % 2 == 0:
                nodes[v] = nodes[u]
            else:
                nodes[v] = -nodes[u]
            dfs(v)


dfs(0)

for n in nodes:
    if n == BLACK:
        print(0)
    else:
        print(1)


### FIXED CODE ###

from queue import Queue

N = int(input())

BLACK = -1
GRAY = 0
WHITE = 1
nodes = [GRAY] * N
nodes[0] = BLACK
neighbors = [[] for _ in range(N)]

for n in range(N-1):
    u, v, w = [int(i) for i in input().split()]
    neighbors[u-1].append((v-1, w))
    neighbors[v-1].append((u-1, w))


def bfs():
    q = Queue()
    q.put(0)
    while not q.empty():
        u = q.get()

        neiss = neighbors[u]
        for neis in neiss:
            v, w = neis
            if nodes[v] == GRAY:
                if w % 2 == 0:
                    nodes[v] = nodes[u]
                else:
                    nodes[v] = -nodes[u]
                q.put(v)


bfs()

for n in nodes:
    if n == BLACK:
        print(0)
    else:
        print(1)
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
M = 1000005
if __name__ == "__main__":
    n = int(input())
    a = sorted(list(map(int,input().split())))
    dp = [0]*(M)
    for i in range(n):
        if dp[a[i]] != 0:
            dp[a[i]] = 2
            continue
        for j in range(a[i],M+1,a[i]):
            dp[j]+=1
    cnt = 0
    for i in range(n):
        if dp[a[i]] == 1:
            cnt+=1
    print(cnt)

### FIXED CODE ###

import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

if __name__ == "__main__":
    n = int(input())
    a = sorted(list(map(int,input().split())))
    M = 1000005
    dp = [0]*(M)
    for i in range(n):
        if dp[a[i]] != 0:
            dp[a[i]] = 2
            continue
        for j in range(a[i],M,a[i]):
            dp[j]+=1
    cnt = 0
    for i in range(n):
        if dp[a[i]] == 1:
            cnt+=1
    print(cnt)
a,b,c,k=map(int,input().split())

if a>=k:
  print(a)
  break()
else:
  if k-a<b:
    print(a)
  else:
    c=k-a-b
    print(a-c)


### FIXED CODE ###

a,b,c,k=map(int,input().split())
 
if a>=k:
  print(k)
  exit()
else:
  if k-a<=b:
    print(a)
    exit()
  else:
    c=k-a-b
    print(a-c)
#coding:utf-8
import sys
sys.setrecursionlimit(1000000000000)
a, b, k = map(int, input().split())

for i in range(0, k):
    if a >= 1:
        a = a - 1
    elif b >= 1:
        b = b - 1
    else:
        pass

print(a, b)

### FIXED CODE ###

#coding:utf-8

a, b, k = map(int, input().split())

if k <= a:
    a = a - k
elif a < k and k <= (a + b):
    b = b - (k - a)
    a = 0
elif (a + b) < k:
    a = 0
    b = 0

print(a, b)
N, K = map(int, input().split())
A = list(map(int, input().split()))

def check(1):
  count = 0
  for L in A:
    count = count + L // 1
    if L % 1 != 0:
      count = count + 1
    count = count - 1
  return count <= K

bottom, top = 0, max(A)

while top - bottom > 1:
  mid = (top + bottom) // 2
  if check(mid):
    top = mid
  else:
    bottom = mid

print(top)

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))

def check(l):
    count = 0
    for L in A:
        count += L // l
        if L % l != 0:
            count += 1
        count -= 1
    return count <= K

bottom, top = 0, max(A)

while top - bottom > 1:
    mid = (top + bottom) // 2
    if check(mid):
        top = mid
    else:
        bottom = mid

print(top)
import sys
input=sys.stdin.readline

def main():
  h,w=map(int,input().split())
  a=[list(map(int,input().split())) for i in range(h)]
  b=[list(map(int,input().split())) for i in range(h)]
  
  dp=[[[] for i in range(w)] for j in range(h)]
  dp[0][0].append(abs(a[0][0]-b[0][0]))
  for i in range(h):
    for j in range(w):
      c[i][j]=abs(a[i][j]-b[i][j])
      for k in dp[i-1][j]:
        dp[i][j].append(abs(k-c[i][j]))
        dp[i][j].append(k+c[i][j])
      for k in dp[i][j-1]:
        dp[i][j].append(abs(k-c[i][j]))
        dp[i][j].append(k+c[i][j])
      dp[i][j]=list(set(dp[i][j]))
  print(min(dp[h-1][w-1]))

if __name__=='__main__':
  main()

### FIXED CODE ###

import sys
input=sys.stdin.readline

def main():
  h,w=map(int,input().split())
  a=[list(map(int,input().split())) for i in range(h)]
  b=[list(map(int,input().split())) for i in range(h)]
  dp=[[[0]*(80*(h+w+1)+1) for i in range(w)] for j in range(h)]
  dp[0][0][abs(a[0][0]-b[0][0])]=1
  for i in range(h):
    for j in range(w):
      c=abs(a[i][j]-b[i][j])
      if i!=0 or j!=0:
        for k in range(80*(i+j+1)+1):
          dp[i][j][k]=dp[i-1][j][abs(k-c)]|dp[i-1][j][k+c]|dp[i][j-1][abs(k-c)]|dp[i][j-1][k+c]
  for i in range(80*(h+w+1)+1):
    if dp[h-1][w-1][i]==1:
      print(i)
      break

if __name__=='__main__':
  main()
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
A = [[int(i)] for i in input().split()]
A_np =np.array(A)

#numpyで連立方程式を解く
mat_1 =np.zeros((N,N),dtype=int)
for i in range(N):
    mat_1[i,i]=1
    mat_1[i,(i+1)%N]=1 #余りをとらないと、i=N-1の時エラーになる
x =np.linalg.solve(mat_1,A_np)*2

#表示
for i in x:
    print(int(i[0]),end=" ")

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))

mt_rain =[0]*N
mt_all =sum(A)
dam_even = sum(A[1::2]) #偶数番目のダムの増えた水
mt_rain[0] = mt_all - 2*dam_even #1番目の山の降水量

#2番目の山以降
for i in range(1,N):
    mt_rain[i] =2*A[i-1] -mt_rain[i-1]
print(*mt_rain)