Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from collections import namedtuple
from queue import Queue
from copy import deepcopy

def bfs(start, stage):
    if stage[start.y][start.x] == "#":
        return -1
    ans = 0
    q = Queue()
    q.put(start)
    stage[start.y][start.x] = 0
    while not q.empty():
        current = q.get()
        for move in moves:
            nxt = point(current.y + move.y, current.x + move.x)
            can_move = 0 <= nxt.y < h and 0 <= nxt.x < w and stage[nxt.y][nxt.x] == "."
            if can_move:
                q.put(nxt)
                stage[nxt.y][nxt.x] = stage[current.y][current.x] + 1
                ans = stage[current.y][current.x] + 1
    return ans


point = namedtuple("point", "y, x")
moves = [point(-1, 0), point(0, 1), point(1, 0), point(0, -1)]
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
ans = -1
for y in range(h):
    for x in range(w):
        steps = bfs(point(y, x), deepcopy(S))
        ans = max(ans, steps)
print(ans)


### FIXED CODE ###

from collections import namedtuple
from queue import Queue
from copy import deepcopy

def bfs(start, stage):
    if stage[start.y][start.x] == "#":
        return -1
    ans = 0
    q = Queue()
    q.put(start)
    stage[start.y][start.x] = 0
    while not q.empty():
        current = q.get()
        for move in moves:
            nxt = point(current.y + move.y, current.x + move.x)
            can_move = 0 <= nxt.y < h and 0 <= nxt.x < w and stage[nxt.y][nxt.x] == "."
            if can_move:
                q.put(nxt)
                stage[nxt.y][nxt.x] = stage[current.y][current.x] + 1
                ans = stage[current.y][current.x] + 1
    return ans


point = namedtuple("point", "y, x")
moves = [point(-1, 0), point(0, 1), point(1, 0), point(0, -1)]
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
ans = -1
for y in range(h):
    for x in range(w):
        steps = bfs(point(y, x), deepcopy(S))
        ans = max(ans, steps)
print(ans)
### BUGGY CODE ###

import sys

def main():
    S  = list(map(int, input()))

    del_cnt = 0
    while True:
        now_S = len(S)
        for i in range(now_S - 1):
            if S[i] != S[i+1]:
                del S[i:i+2]
                del_cnt += 1
                break
        done_S = len(S)

        if now_S == done_S:
            break

    print(del_cnt * 2)

main()

### FIXED CODE ###

import sys

def main():
    S  = list(map(int, input()))
    o = S.count(0)
    l = S.count(1)

    print(min(o, l) * 2)

main()
### BUGGY CODE ###

x,y,z,k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)

li = []

for i in range(x):
    for j in range(y):
        li.append(a[i] + b[j])
        
li.sort(reverse = True)
li = li[:min(k,x*y)]

box = []

for i in range(len(li)):
    for j in range(z):
        box.append(li[i] + c[j])

box.sort(reverse = True)

for i in range(k):
    print(box[i])

### FIXED CODE ###

x,y,z,k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
li = []
box = []
for i in a:
    for j in b:
        li.append(i + j) 
li.sort(reverse = True)
li = li[:min(k,x*y)]
for i in c:
    for j in li:
        box.append(i + j)
box.sort(reverse = True)
for i in range(k):
    print(box[i])
### BUGGY CODE ###

from numpy import array
from numpy.linalg import solve
import sys

N=int(input())
#A=list(map(int, input().split())) 
A=list(map(int, sys.stdin.readline().split())) 

L=[]
for i in range(N-1):
	L.append ([0]*i+[1,1]+[0]*(N-i-2)) 

L.append([1]+[0]*(N-2)+[1])


a=array(L) 
b=array(A)       
L=solve(a,b) 

for ans in L:
	print (int(ans)*2, end=" ")


### FIXED CODE ###

import sys
from collections import deque

N=input()
A=map(int, sys.stdin.readline().split())
A=map(lambda x: x*2, A)

a=sum(A)/2

for i in range(1,N):
	if i%2==1:
		a-=A[i]

#a
print a,

prev=a
for x in A[:-1]:
	x-=prev
	print x,
	prev=x
### BUGGY CODE ###

a=int(input())
x=1
for i in range(1,a+1):
    x *= i
print(x%(10**9+7))


### FIXED CODE ###

X=10**9+7

def A(c,d):
    return c*d%X

a=int(input())
x=1
for i in range(1,a+1):
    x = A(x,i)

print(x)
### BUGGY CODE ###

h, w, kkk = map(int, input().split())
choco = [0]*h
for i in range(h):
  choco[i] = input()
answer = h+w-2
for i in range(max([2**(h-1), 1])):
  flag = True
  board = [0]*(h-1)
  for j in range(h-1):
    if (i >> j)&1:
      board[j] = 1
  count = sum(board)
  key = [0]*(count+1)
  ans = count
  for p in range(w):
    max_board = [0]*(count+1)
    k = 0
    for q in range(h):
      if choco[q][p] == "1":
        max_board[k] += 1
      if q == h-1:
        if max(max_board) > kkk:
          flag = False
        break
      if board[q] == 1:
        k += 1
  if not flag:
    continue
  for p in range(w):
    k = 0
    for q in range(h):
      if choco[q][p] == "1":
        key[k] += 1
      if q == h-1:
        break
      if board[q] == 1:
        k += 1
    for u in range(count+1):
      if key[u] <= kkk:
        continue
      ans += 1
      key = [0]*(count+1)
      k = 0
      for q in range(h):
        if choco[q][p] == "1":
          key[k] += 1
        if q == h-1:
          break
        if board[q] == 1:
          k += 1
      break
  if ans < answer and flag:
    answer = ans
print(answer)


### FIXED CODE ###

h, w, kkk = map(int, input().split())
choco = [0]*h
for i in range(h):
  choco[i] = input()
answer = h+w-2
for i in range(max([2**(h-1), 1])):
  flag = True
  board = [0]*(h-1)
  for j in range(h-1):
    if (i >> j)&1:
      board[j] = 1
  count = sum(board)
  key = [0]*(count+1)
  ans = count
  for p in range(w):
    max_board = [0]*(count+1)
    k = 0
    for q in range(h):
      if choco[q][p] == "1":
        max_board[k] += 1
      if q == h-1:
        if max(max_board) > kkk:
          flag = False
        break
      if board[q] == 1:
        k += 1
  if not flag:
    continue
  for p in range(w):
    k = 0
    for q in range(h):
      if choco[q][p] == "1":
        key[k] += 1
      if q == h-1:
        break
      if board[q] == 1:
        k += 1
    for u in range(count+1):
      if key[u] <= kkk:
        continue
      ans += 1
      key = [0]*(count+1)
      k = 0
      for q in range(h):
        if choco[q][p] == "1":
          key[k] += 1
        if q == h-1:
          break
        if board[q] == 1:
          k += 1
      break
  if ans < answer and flag:
    answer = ans
print(answer)
### BUGGY CODE ###

n = int(input())
s = str(input())
r = []
g = []
b = []
for i in range(n):
  if s[i] == "R":
    r.append(i)
  elif s[i] == "G":
    g.append(i)
  else:
    b.append(i)
c = len(r)*len(g)*len(b)
for ri in r:
  for gi in g:
    for bi in b:
      if 3*(max(ri,gi,bi)+min(ri,gi,bi)) == 2*sum([ri,gi,bi]):
        c -= 1
print(c)

### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
s = str(input())
r = 0
g = 0
for i in range(n):
  if s[i] == "R":
    r += 1
  elif s[i] == "G":
    g += 1
c = r*g*(n-r-g)
for j in range(1,n-1):
  for i in range(1,min(n-j-1,j)+1):
    if (s[j-i] != s[j]) and (s[j] != s[j+i]) and (s[j+i] != s[j-i]):
      c -= 1
print(c)
### BUGGY CODE ###

#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())

n = I()
ab = set()
for c in range(1,n):
    nc = n-c
    ab.add(nc)
ans = 0
for v in ab:
    if v == 1:
        ans += 1
        continue
    #print(v)
    i = 1
    while i*i <= v:
        # print('?')
        if v%i == 0:
            #print('?')
            div = v//i
            if i == div:
                ans += 1
            else:
                ans += 2
        i += 1
print(ans)


### FIXED CODE ###

#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())

is_prime = [1] * (10**6+1)

for a in range(2,10**6+1):
        for v in range(a,10**6+1,a):
            is_prime[v] += 1
# print(is_prime[:10])

n = I()
ans = 0
for c in range(1,n):
    nc = n-c
    ans += is_prime[nc]
print(ans)
### BUGGY CODE ###

n,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr1=sorted(arr1)
arr2=list(map(int,input().split()))
arr2=sorted(arr2,reverse=True)
l=-1
r=10**12+1
while r-l!=1:
  m=(r+l)//2
  tmp=0
  for i in range(n):
    if arr1[i]>m//arr2[i]:
      tmp+=(arr1[i]-m//arr2[i])
  if tmp<=k:
    r=m
  else:
    l=m
print(r)

### FIXED CODE ###

n,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr1=sorted(arr1)
arr2=list(map(int,input().split()))
arr2=sorted(arr2,reverse=True)
l=-1
r=10**12+1
while r-l!=1:
  m=(r+l)//2
  tmp=0
  for i in range(n):
    if arr1[i]>m//arr2[i]:
      tmp+=(arr1[i]-m//arr2[i])
  if tmp<=k:
    r=m
  else:
    l=m
print(r)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
B =[]
for i in range(1,N+1):
  B.append(A.index(i)+1) 
print(' '.join(map(str, B)))
 

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
D = [0]*N
for i in range(N):
  a = A[i]
  D[a-1] = i+1
d = str(D[0])
for i in range(1,N):
  d += ' '+str(D[i])
print(d)
### BUGGY CODE ###

L, R = map(int, input().split())
ans = 2018
END = False

for i in range(2019):
    j = i + 1
    while j <= R-L:
        ans = min( ((L+i)*(L+j)) % 2019, ans)
        j += 1
        if ans == 0:
            END = True
    if END or i > R-L:
        break

print(ans)

### FIXED CODE ###

L, R = map(int, input().split())
ans = 2018
END = False

for i in range(2019):
    j = i + 1
    while j <= R-L:
        ans = min( ((L+i)*(L+j)) % 2019, ans)
        j += 1
        if ans == 0:
            END = True
            break
    if END or i > R-L:
        break

print(ans)
### BUGGY CODE ###

h,w = [int(i) for i in input().split()]
x = []
for i in range(h):
    x.append(input())

search = []
board = {}
for i in range(h):
    for j in range(w):
        if x[i][j] == "#":
            board[(i,j)] = 0
            search.append((i,j))

count = 1
ans = 0
while search:
    search2 = []
    for xy in search:
        x,y = xy
        if (x+1,y) not in board and x+1 <h:
            board[(x+1,y)] = count
            search2.append((x+1,y))
            ans = count
        if (x-1,y) not in board and x-1 >=0:
            board[(x-1,y)] = count
            search2.append(((x-1,y)))
            ans = count
        if (x,y+1) not in board and y+1 <w:
            board[(x,y+1)] = count
            search2.append((x,y+1))
            ans = count
        if (x,y-1) not in board and y-1 >=0:
            board[(x,y-1)] = count
            search2.append((x,y-1))
            ans = count
    search = search2
    count +=1

print(ans)


### FIXED CODE ###

from collections import deque

def inside(x, l, r):
    return l <= x < r

if __name__ == '__main__':
    h, w = map(int, input().split())

    a = []
    for i in range(h):
        a.append(list(input()))

    qu = deque()
    
    nokori = h*w
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                nokori -= 1
                qu.append((i, j))

    ans = 0
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]
    while True:
        if nokori == 0:
            break
        ans += 1
        qu2 = deque()
        while len(qu) > 0:
            i0, j0 = qu.popleft()
            for k in range(4):
                ni = i0 + dx[k]
                nj = j0 + dy[k]
                if not (inside(ni, 0, h) and inside(nj, 0, w)):
                    continue
                if a[ni][nj] == '.':
                    a[ni][nj] = '#'
                    nokori -= 1
                    qu2.append((ni, nj))
        qu = qu2
    print(ans)
### BUGGY CODE ###

n = int(input())
temparr = input()
temparr = temparr.split()
arr = []
for i in temparr:
    arr.append(int(i)  % 1000000007)
    
ans = 0 
for i in range(n - 1):
    curnum = arr[i]
    newcur = 0 
    for j in range(i + 1, n):
        newcur += arr[j]
    newcur  = newcur % 1000000007
    ans += curnum * newcur
    if ans >= 1000000007:
        ans = ans % 1000000007

if ans >= 1000000007:
    print(ans % 1000000007)
else:
    print(ans)

### FIXED CODE ###

n = int(input())
temparr = input()
temparr = temparr.split()
arr = []
for i in temparr:
    arr.append(int(i)  % 1000000007)
    
ans = 0 
total = []
curtotal = sum(arr)
total.append(curtotal)
for i in range(n):
    curtotal -= arr[i]
    total.append(curtotal)
for i in range(n):
    total[i] = total[i] % 1000000007

for i in range(n - 1):
    curnum = arr[i]
    tempans = curnum * total[i + 1]
    if tempans >= 1000000007:
        tempans = tempans % 1000000007
    ans += tempans

if ans >= 1000000007:
    print(ans % 1000000007)
else:
    print(ans)
### BUGGY CODE ###

def main():
    n = int(input())
    a = list(int(input()) for _ in range(n))
    MAX = max(a)
    for i in range(n):
        ans = MAX
        if a[i] == MAX:
            ans = max(a[:i] + a[i+1:]) if i != n - 1 else max(a[:i])
        print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n = int(input())
    a = list(int(input()) for _ in range(n))
    s = sorted(a)
    MAX1, MAX2 = s[-1], s[-2]
    for i in range(n):
        ans = MAX2 if a[i] == MAX1 else MAX1
        print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

L,R=map(int,input().split())
M=2019
for i in range(L,R):
    for j in range(i+1,R+1) :
        if (i*j)%2019 < M :
            M = (i*j)%2019
            if M == 0:
                break
print (M)

### FIXED CODE ###

L,R=map(int,input().split())
M=2019
import sys
for i in range(L,R):
    for j in range(i+1,R+1) :
        if (i*j)%2019 < M :
            M = (i*j)%2019
            if M == 0:
                print(M)
                sys.exit()
print (M)
### BUGGY CODE ###

N,X,Y = map(int,input().split())
for k in range(1,N):
    S = 0
    for i in range(1,N):
        for j in range(i+1,N+1):
            if (i<= X and j<=X) or (i>=Y and j>=Y):
                if j-i == k:
                    S += 1
            elif i <= X and j >= Y:
                if j-i+X-Y+1 == k:
                    S += 1
            elif i > X and j < Y:
                if j-i <= Y-j+i-X+1:
                    if j-i == k:
                        S += 1
                else:
                    if Y-j+i-X+1 == k:
                        S += 1
            elif i <= X:
                if j-i <= X+Y-i-j+1:
                    if j-i == k:
                        S += 1
                else:
                    if X+Y-i-j+1 == k:
                        S += 1
            else:
                if j-i <= -X-Y+i+j+1:
                    if j-i == k:
                        S += 1
                else:
                    if -X-Y+i+j+1 == k:
                        S += 1
    print(S)

### FIXED CODE ###

N,X,Y = map(int,input().split())
A = [0 for i in range(N)]
for i in range(N-1):
    a = i+1
    for j in range(i+1,N):
        b = j+1
        A[min([b-a,abs(X-a)+abs(Y-b)+1])] += 1
for i in range(1,N):
    print(A[i])
### BUGGY CODE ###

import copy
N,*D=map(int,open(0).read().split())
for i in range(N):
  A=copy.deepcopy(D)
  del A[i]
  print(max(A))

### FIXED CODE ###

N,*D=map(int,open(0).read().split())
S=sorted(D,reverse=True)
if S[1]==S[0]:
  [print(S[0]) for i in range(N)]
else:
  import numpy as np
  max_i=np.arange(N)[np.array(D)==S[0]]
  for i in range(N):
    if i==max_i:
      print(S[1])
    else:
      print(S[0])
### BUGGY CODE ###

from collections import deque

def main():
  H, W = map(int, input().split())
  M = [['#' == x for x in input()] for _ in range(H)]
  que = deque([[i, j] for i in range(H) for j in range(W) if M[i][j]])
  ans = 0
  while que:
    qq = []
    ans += 1
    for nh, nw in que:
      if nw+1<=W-1 and not M[nh][nw+1]:
        qq.append([nh,nw+1])
        M[nh][nw+1] = True
      if  0<=nw-1 and not M[nh][nw-1]:
        qq.append([nh,nw-1])
        M[nh][nw-1] = True
      if nh+1<=H-1 and not M[nh+1][nw]:
        qq.append([nh+1,nw])
        M[nh+1][nw] = True
      if 0<=nh-1 and not M[nh-1][nw]:
        qq.append([nh-1,nw])
        M[nh-1][nw] = True
    que = qq
  print(ans-1)

if __name__ == "__main__":
  main()

### FIXED CODE ###

import copy
from collections import deque
def main():
  H, W = map(int, input().split())
  G = [['#' == x for x in input()] for _ in range(H)]
 
  black = deque([(i, j) for i in range(H) for j in range(W) if G[i][j]])
 
  ans = 0
  while True:
    ans += 1
    next_black = deque()
    while black:
      bi, bj = black.popleft()
      if bi > 0 and not G[bi - 1][bj]:
        G[bi - 1][bj] = True
        next_black.append((bi - 1, bj))
      if bj > 0 and not G[bi][bj - 1]:
        G[bi][bj - 1] = True
        next_black.append((bi, bj - 1))
      if bi < H - 1 and not G[bi + 1][bj]:
        G[bi + 1][bj] = True
        next_black.append((bi + 1, bj))
      if bj < W - 1 and not G[bi][bj + 1]:
        G[bi][bj + 1] = True
        next_black.append((bi, bj + 1))
    if next_black:
       black = copy.copy(next_black)
    else:
       break
  print(ans - 1)
  
if __name__ == "__main__":
  main()
### BUGGY CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())
sum = 0

for i in range(K):
    for j in range(K):
        for k in range(K):
            sum += gcd((i+1),(j+1),(k+1))

print(sum)

### FIXED CODE ###

from math import gcd

K = int(input())
sum = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            sum += gcd(gcd(i,j),k)

print(sum)
### BUGGY CODE ###

s = input()
p = [0]*13
p[0] = 1

for si in range(len(s)):
  a = [0]*13
  if s[si] == '?':
    for j in range(10):
      for i in range(13):
        a[(i*10+j)%13] += p[i]
  else:
    c = int(s[si])
    for i in range(13):
      a[(i*10+c)%13] += p[i]
  for i in range(13):
    p[i] = a[i]%1000000007
print(p[5])

### FIXED CODE ###

import numpy as np

s = input()
p = np.array([0]*13)
p[0] = 1

amari = [[0]*13 for _ in range(13)]
for j in range(10):
  for i in range(13):
    amari[i][(i*10+j)%13] += 1
M = np.array(amari)

for si in range(len(s)):
  a = np.array([0]*13)
  if s[si] == '?':
    a = np.dot(p,M)
  else:
    c = int(s[si])
    for i in range(13):
      a[(i*10+c)%13] += p[i]
  p = np.mod(a,1000000007)
print(p[5])
### BUGGY CODE ###

N = int(input())
A = []
B = 0
while N>0:
    A.append(N%10)
    N //=10
for i in range(len(A)):
    B = B+A[i]
if B%9 == 0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

N = list(input())
A = 0

for i in range(len(N)):
    B = int(N[i])
    A += B
if A%9 == 0:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

import math
A, B = map(int, input().strip().split())

minAB = min(A,B);

upper = int(math.sqrt(minAB+1))
ans = 1

for i in range(2, minAB+1):
    if A % i != 0 or B % i != 0:
        continue;
    falg = True
    for j in range(2, i-1):
        if(i % j == 0):
            falg = False
            break
    if falg:
        ans+=1
        
print(ans)

### FIXED CODE ###

import math
A, B = map(int, input().strip().split())

divisors = []

minAB = min(A,B)
maxAB = max(A,B)
upper = int(math.sqrt(minAB+1) + 1)
ans = 1

for i in range(1, upper):
    if minAB % i == 0:
        divisors.append(i)
        if i != minAB//i:
            divisors.append(minAB//i)

divisors.sort()
#print(divisors)

flag = [True] * len(divisors)
for i, num in enumerate(divisors):
    if maxAB % num != 0:
        flag[i] = False
        continue
    for x in divisors:
        if x == 1 :
            continue
        if x > math.sqrt(num):
            break
        if num % x ==0:
            flag[i] = False
            break

print(flag.count(True))
### BUGGY CODE ###

def main():
  import numpy as np
  n=int(input())
  rain=[int(i)*2 for i in input().split()]
  
  matrix=[[0]*n for _ in range(n)]
  for i in range(n):
    if i!=n-1:
      matrix[i][i],matrix[i][i+1]=1,1
    else:
      matrix[i][i],matrix[i][0]=1,1
      
  matrix=np.array(matrix,dtype=np.int64)
  print(*list(map(int,np.linalg.solve(matrix,rain))))
 
if __name__=='__main__':
  main()

### FIXED CODE ###

def main():
  n=int(input())
  rain=[int(i) for i in input().split()]
  
  test=0
  for i in range(n):
    test=rain[i]-test
  ans=test
  
  fall=[0]*n
  fall[0]=test
  for i in range(n-1):
    tmp=rain[i]-fall[i]//2
    fall[i+1]=2*tmp
  
  print(*fall)
if __name__=='__main__':
  main()
### BUGGY CODE ###

N=int(input())
inp=list(map(int, input().strip().split(' ')))

med = int(N/2)
for i in range(N):
  X=[]
  for j in range(N):
    if i!=j:
      X.append(inp[j])
  Xsort = sorted(X)
  print(Xsort[med-1])


### FIXED CODE ###

N=int(input())
inp=list(map(int, input().strip().split(' ')))
Xsort=sorted(inp)
med = int(N/2)
for i in range(N):
  if Xsort[med-1] >= inp[i] :
    print(Xsort[med])
  else:
    print(Xsort[med-1])
### BUGGY CODE ###

s=int(input())
for i in range(1,3501):
    for j in range(1,3501):
        t=4*i*j-i*s-j*s
        if t<=0:
            continue
        if s*i*j%t==0:
            print(s*i*j//t,i,j)
            exit()

### FIXED CODE ###

s=int(input())
for i in range(s//4,3501):
    for j in range(1,3501):
        t=4*i*j-i*s-j*s
        y=s*i*j
        if t>0 and s*i*j%t==0:
            print(s*i*j//t,i,j)
            exit()
### BUGGY CODE ###

import bisect

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

a.sort()
b.sort()
c.sort()

count = 0
for i in a:
  for j in range(bisect.bisect(b, i), len(b)):
    for k in range(bisect.bisect(c, b[j]), len(c)):
      count += 1
print(count)


### FIXED CODE ###

import bisect

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

a.sort()
b.sort()
c.sort()

count = 0
for i in b:
  count += bisect.bisect_left(a, i) * (len(c) - bisect.bisect(c, i))
print(count)
### BUGGY CODE ###

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


ans = [0]*n
for i in range(1,n+1):
    ans[i-1] = s.index(i) + 1

print(*ans)

### FIXED CODE ###

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

ans = [0]*n
for i in range(n):
    ans[s[i]-1] = i+1

print(*ans)