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

from heapq import heapify, heappop, heappush

def dijkstra_heap(s,edge): #edgeが複数パターンある場合には引数に入れることも可能 dijkstra_heap(s,edge)
    #始点sから各頂点への最短距離
    d = [float("inf")] * N
    used = [True] * N #True:未確定。始点として探索されたか。というかdが更新されたか。
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heappush(edgelist,e)
    while len(edgelist):
        minedge = heappop(edgelist)
        #まだ使われてない頂点の中からスタートから最小の距離のものを探す
        if not used[minedge[1]]: #すでに探索済みの場合にはスキップして次のプライオリティーキューへ。
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False #ここで始点として探索済みにする。
        for e in edge[v]:
            if used[e[1]]: #行き先がすでに始点として探索済みでない場合には値を更新。
                heappush(edgelist,(e[0]+d[v],e[1])) #重みをスタートからの最短重みにするため+d[v]
    return d ##始点sから各頂点への最短距離がアウトプットとなる。

N = int(input())
HQ = [];A = []
for i in range(N):
  temp = list(map(int,input().split()))
  A.append(temp)
  for j in range(i+1,N):
    heappush(HQ,(temp[j],i,j))
#print(HQ)
G = [[] for _ in range(N)]
ans = 0
while HQ:
  dis, start, goal = heappop(HQ)
  d = dijkstra_heap(start,G)
  if d[goal] < dis: #既に近い距離で到達できるなら矛盾
    print(-1); exit()
  elif d[goal] == dis:
    continue
  else: #d[goal] > dis:
    ans += dis
    G[start].append((dis,goal))
    G[goal].append((dis,start))
print(ans)
      



### FIXED CODE ###

import heapq
import sys
N = int(input())

r = [[1]*N for _ in range(N)]
g = [[]*N for _ in range(N)]
all = 0
for i in range(N):
  temp = list(map(int,(input().split())))
  g[i] = temp
  all += sum(temp)
#print(g,all)

for k in range(N):
  for i in range(N):
    for j in range(N):
      if g[i][j] > g[i][k] + g[k][j]:
        print("-1")
        sys.exit()
      elif g[i][j] == g[i][k] + g[k][j] and i != j and j != k and k != i:
        r[i][j] = 0
ans = 0
for i in range(N):
  for j in range(N):
    ans += g[i][j]*r[i][j]

ans = ans//2
print(ans)
### BUGGY CODE ###

from collections import deque
import sys
input = sys.stdin.readline

def bfs():
    st = deque([(0,-1)])
    while st:
        n,par = st.popleft()
        val = cnt[n]   
        for node in A[n]:
            if node == par:
                continue
            else:
                cnt[node] += val
                st.append([node,n])
    return cnt

        
N,Q = (int(i) for i in input().split())
A = [() for i in range(N)]

for _ in range(N-1):
    a,b = (int(i) for i in input().split())
    A[a-1] += (b-1,)
    A[b-1] += (a-1,)

cnt = [0]*N   
for q in range(Q):
   p,x = (int(i) for i in input().split())
   cnt[p-1] += x

bfs()

print(*cnt)

### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

for _ in range(N-1):
    a,b = (int(i) for i in input().split())
    A[a-1].append(b-1)
    A[b-1].append(a-1)

cnt = [0]*N   
for q in range(Q):
   p,x = (int(i) for i in input().split())
   cnt[p-1] += x

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
G = [[] for _ in range(N+1)]
for _ in range(M):
    A, B = map(int, input().split())
    G[A].append(B)

def dfs(v, o):
    ret = []
    ancestors.add(v)
    for c in G[v]:
        if c == o:
            ret.append([v])
        elif c in ancestors:
            continue
        else:
            for a in dfs(c, o):
                ret.append([v] + a)
    ancestors.remove(v)
    return ret

for v in range(1, N+1):
    ancestors = set()
    for cand in dfs(v, v):
        cand = set(cand)
        for v in cand:
            cnt = 0
            for c in G[v]:
                if c in cand:
                    cnt += 1
            if cnt >= 2:
                break
        else:
            print(len(cand))
            print(*cand, sep='\n')
            exit()
print(-1)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N, M = map(int, input().split())
G = [[] for _ in range(N+1)]
for _ in range(M):
    A, B = map(int, input().split())
    G[A].append(B)

def dfs(v, o):
    for c in G[v]:
        if c == o:
            return [v]
    for c in G[v]:
        if visited[c]:
            continue
        visited[c] = True
        ret = dfs(c, o)
        if ret:
            return [v] + ret

for v in range(1, N+1):
    visited = [False] * (N+1)
    cur = dfs(v, v)
    if cur:
        break
else:
    print(-1)
    exit()

while True:
    cur_set = set(cur)
    unused = None
    for i in range(len(cur)):
        u, v = cur[i], cur[(i+1) % len(cur)]
        for c in G[u]:
            if c == v:
                continue
            elif c in cur_set:
                unused = (i, cur.index(c))
                break

    if not unused:
        break
    else:
        t, s = unused
        nxt = []
        i = s
        while i != t:
            nxt.append(cur[i])
            i = (i + 1) % len(cur)
        nxt.append(cur[t])
        cur = nxt

print(len(cur))
print(*cur, sep='\n')
### BUGGY CODE ###

n, m = map(int, input().split())

card = list(range(1, n+1))
delete = set()

for i in range(m):
  l,r = map(int, input().split())
  delete.update(card[:(l-1)])
  delete.update(card[r:])

card = set(card)
print(len(card^delete))

### FIXED CODE ###

n,m = map(int, input().split())

l = []
r = []

for i in range(m):
  L,R = map(int, input().split())
  l.append(L)
  r.append(R)

ans = min(r) - max(l) + 1

print(max(ans, 0))
### BUGGY CODE ###

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

dp = [0]*N

for i in range(N-1):
    if i >= K:
        for j in range(K):
            x = dp[i-j]+abs(h[i+1]-h[i-j])
            if dp[i+1] == 0:
                dp[i+1] = x
            elif x < dp[i+1]:
                dp[i+1] = x
    else:
        for j in range(i+1):
            x = dp[i-j]+abs(h[i+1]-h[i-j])
            if dp[i+1] == 0:
                dp[i+1] = x
            elif x < dp[i+1]:
                dp[i+1] = x            



print(dp[-1])

### FIXED CODE ###

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

dp = [0]*N

for i in range(N-1):
    if i >= K:
        x = dp[i]+abs(h[i+1]-h[i])
        for j in range(1,K):
            x = min(x,dp[i-j]+abs(h[i+1]-h[i-j]))
            
    else:
        x = dp[i]+abs(h[i+1]-h[i])
        for j in range(1,i+1):
            x = min(x,dp[i-j]+abs(h[i+1]-h[i-j]))
    
    dp[i+1] = x            



print(dp[-1])
### BUGGY CODE ###

N = int(input())
L = list(map(int, input().split()))
import itertools
A = list(itertools.combinations(L,3))
ans = 0
for a in A:
    ok = True
    if a[0] >= a[1]+a[2]:
        ok = False
    if a[1] >= a[0]+a[2]:
        ok = False
    if a[2] >= a[0]+a[1]:
        ok = False
    if ok:
        ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))
C = sorted(L)
def X(n,j):
    L1 = j+1
    L2 = N-1
    while L1 != L2:
        a = (L1+L2)//2
        if C[a] == n:
            while C[a] == C[a-1]:
                a = a-1
            return len(C[j+1:a])
        elif L2 - L1 <= 1:
            if C[L2] < n:
                return len(C[j+1:L2+1])
            elif C[L1] < n <= C[L2]:
                return len(C[j+1:L2])
            while C[L1] == C[L1-1]:
                if j+1 <= L1-1:
                    L1 = L1-1
                else:
                    break
            if C[L1] > n:
                return len(C[j+1:L1])
            elif C[L1] == n:
                return len(C[j+1:L1])
        elif C[a] < n:
            L1 = a
        else:
            L2 = a
    if C[L1] < n:
        return 1
    else:
        return 0
ans = 0
# print(C)
for i in range(N-2):
    for j in range(i+1,N-1):
        # print(X((C[i]+C[j]),j))
        ans += X((C[i]+C[j]),j)
print(ans)
### BUGGY CODE ###

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

ans = 0

for i in range(n):
  ans += a[i]*sum(a[i+1:n])
  ans %= 1000000000+7
  
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
zenbu = sum(a)
ans = 0

for i in range(n):
  ans += a[i]*(zenbu-a[i])
 
print(ans // 2 % 1000000007)
### BUGGY CODE ###

def c_synthetic_kadomatsu(N, A, B, C, L):
    from itertools import permutations

    ans = float('inf')
    # 竹の並び方を決める
    for perm in permutations(range(N)):
        # 左から竹をj, k, l本取り、それらを別々に合成し、
        # それらの長さと A, B, C とがどれだけ違うかを計算する
        for j in range(1, N):
            for k in range(1, N - j):
                for l in range(1, N - j - k + 1):
                    cost = 0
                    s, t, u = perm[:j], perm[j:j + k], perm[j + k:j + k + l]
                    a, b, c = [], [], []
                    for _s in s:
                        a.append(L[_s])
                    for _t in t:
                        b.append(L[_t])
                    for _u in u:
                        c.append(L[_u])
                    cost += (len(a) + len(b) + len(c) - 3) * 10
                    cost += abs(sum(a) - A) + abs(sum(b) - B) + abs(sum(c) - C)
                    ans = min(ans, cost)
    return ans

N, A, B, C = [int(i) for i in input().split()]
L = [int(input()) for _ in range(N)]
print(c_synthetic_kadomatsu(N, A, B, C, L))


### FIXED CODE ###

def c_synthetic_kadomatsu(N, A, B, C, L):
    from itertools import permutations
    # for j in range(1, N):
    #     for k in range(1, N - j):
    #         for l in range(1, N - j - k + 1):
    #             print(j, k, l, L[:j], L[j:j + k], L[j + k:j + k + l])
    ans = float('inf')
    for perm in permutations(range(N)):
        for j in range(1, N):
            for k in range(1, N - j):
                for l in range(1, N - j - k + 1):
                    cost = 0
                    s, t, u = perm[:j], perm[j:j + k], perm[j + k:j + k + l]
                    a, b, c = [], [], []
                    for _s in s:
                        a.append(L[_s])
                    for _t in t:
                        b.append(L[_t])
                    for _u in u:
                        c.append(L[_u])
                    cost += (len(a) + len(b) + len(c) - 3) * 10
                    cost += abs(sum(a) - A) + abs(sum(b) - B) + abs(sum(c) - C)
                    ans = min(ans, cost)
    return ans

N, A, B, C = [int(i) for i in input().split()]
L = [int(input()) for _ in range(N)]
print(c_synthetic_kadomatsu(N, A, B, C, L))
### BUGGY CODE ###

def main():
    from collections import Counter
    import sys
    input = sys.stdin.readline

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

    for i in range(n):
        new_list = []
        Sum = 0
        if i == 0:
            new_list = li[1:n]
            S=Counter(new_list)
            for k in range(n):
                if S[k] > 1:
                    Sum += (S[k] * (S[k] -1)) / 2
                else:
                    continue
            print(int(Sum))
        elif i == n-1:
            new_list = li[:n-1]
            S=Counter(new_list)
            for k in range(n):
                if S[k] > 1:
                    Sum += (S[k] * (S[k] -1)) / 2
                else:
                    continue
            print(int(Sum))
        else:
            new_list = li[:i] + li[i+1:]
            S=Counter(new_list)
            for k in range(n):
                if S[k] > 1:
                    Sum += (S[k] * (S[k] -1)) / 2
                else:
                    continue
            print(int(Sum))

if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
li = list(map(int,input().split()))
S=Counter(li)
Sum = 0
for k in range(n):
            if S[k+1] > 1:
                Sum += (S[k+1] * (S[k+1] -1)) / 2
            else:
                continue

#k個目が何なのかを考える
for i in range(n):
    if S[li[i]] > 1:
        Sum_2 = Sum
        Sum_2 = Sum_2 - (S[li[i]] * (S[li[i]] -1)) / 2 + ((S[li[i]]-1) * (S[li[i]] -2)) / 2
        print(int(Sum_2))
    else:
        print(int(Sum))
### BUGGY CODE ###

def bfs(graph, start, goal, connection):
    visited = {start: None}
    unvisited = [start]
    while unvisited:
        now = unvisited[0]
        if now == goal or (1000000*now + goal) in connection:
            connection[1000000*start + goal] = 1
            return "yes"
        unvisited = unvisited[1:]
        for next in graph[now]:
            if not (next in visited):
                unvisited.append(next)
                visited[next] = now
    return "no"

n, m = map(int, input().split())
g = [[] for i in range(n)]
c = {}

for i in range(m):
    inp = list(map(int, input().split()))
    g[inp[0]].append(inp[1])
    g[inp[1]].append(inp[0])

q = int(input())

for i in range(q):
    s, t = map(int, input().split())
    print(bfs(g, s, t, c))

### FIXED CODE ###

from collections import deque

def bfs(graph, start):
    visited = {start: None}
    unvisited = deque()
    unvisited.append(start)
    while unvisited:
        now = unvisited.popleft()
        for next in graph[now]:
            if not (next in visited):
                unvisited.append(next)
                visited[next] = now
    return visited

n, m = map(int, input().split())
g = [set() for i in range(n)]
group = []

for i in range(m):
    a, b = map(int, input().split())
    g[a].add(b)
    g[b].add(a)

q = int(input())

for i in range(q):
    s, t = map(int, input().split())
    for j in range(len(group)):
        if s in group[j] and t in group[j]:
            print("yes")
            break
        elif s in group[j]:
            print("no")
            break
    else:
        group_tmp = set(bfs(g, s).keys())
        if t in group_tmp:
            print("yes")
        else:
            print("no")
        group.append(group_tmp)
### BUGGY CODE ###

N = int(input())
A = [int(i) for i in input().split()]
ans = 1
lim = 10 ** 18
for i in A:
  ans *= i
if ans == 0:
  print(0)
elif ans > lim:
  print(-1)
else:
  print(ans)


### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
ans = 1
lim = 10 ** 18
if not (0 in A):
  for i in A:
    ans *= i
    if ans > lim:
      break
  if ans > lim:
    print(-1)
  else:
    print(ans)
else:
  print(0)
### BUGGY CODE ###

N=int(input())
A=[int(i) for i in input().split()]
arr={}
for a in A:
	if a in arr:
		arr[a]+=1
	else:
		arr[a]=1
Q=int(input())
for q in range(Q):
	B,C=[int(i) for i in input().split()]
	if B in arr:
		if C in arr:
			arr[C]+=arr[B]
		else:
			arr[C]=arr[B]
		del arr[B]
	print(sum([i[0]*i[1] for i in arr.items()]))


### FIXED CODE ###

N=int(input())
A=[int(i) for i in input().split()]
arr={}
P={}
for a in A:
	if a in arr:
		arr[a]+=1
	else:
		arr[a]=1
for k,v in arr.items():
	P[k]=k*v
S=sum([i for i in P.values()])
Q=int(input())
for q in range(Q):
	B,C=[int(i) for i in input().split()]
	if B in arr:
		if C in arr:
			arr[C]+=arr[B]
			P[C]+=arr[B]*C
		else:
			arr[C]=arr[B]
			P[C]=arr[B]*C
		S-=P[B]
		S+=arr[B]*C
		del arr[B]
		del P[B]
	print(S)
### BUGGY CODE ###

#DP D
def main():
    import sys
    N, limit = map(int, sys.stdin.readline().split())
    L = tuple([tuple(map(int, sys.stdin.readline().split())) for _ in range(N)])
    dp = [[0 for _ in range(limit+1)] for _ in range(N)]
    dp[0][L[0][0]] = L[0][1] #初期値
    for i in range(1, N):
        dp[i] = dp[i-1].copy() #前回をコピー(初)
        w, v = L[i][0], L[i][1]
        dp[i][w] = max(v, dp[i][w])
        for j in range(limit+1-w):
            if dp[i-1][j] >0:
                dp[i][w+j] = max(v+ dp[i-1][j], dp[i][w+j])
            
    
    
    print(max(dp[-1]))



if __name__=='__main__':
    main()


### FIXED CODE ###

import sys
n, W = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

dp = [[0 for _ in range(W+1)] for _ in range(n)]
for w in range(W+1):
    if w>=L[0][0]:
        dp[0][w] = L[0][1]

#print(dp)
for i in range(1, n):
    for w in range(W+1):
        if w <L[i][0]: #そもそも加えられないとき
            dp[i][w] = dp[i-1][w] #前回の状態を代入。
        else: #加えようとしたら入るとき
            dp[i][w] = max(dp[i-1][w-L[i][0]] + L[i][1], dp[i-1][w]) #max(加えた時の価値, 前回の状態)
            
#print(dp)
print(max(dp[-1]))
### BUGGY CODE ###

import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n, k = MI()
    A = LI()
    score = [1]*n
    for i in range(0, k):
        score[k-1] *= A[i]
    for i in range(k, n):
        score[i] = (score[i-1]//A[i-k])*A[i]
        if score[i-1] < score[i]:
            print('Yes')
        else:
            print('No')



if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n, k = MI()
    A = LI()
    for i in range(k, n):
        if A[i-k] < A[i]:
            print('Yes')
        else:
            print('No')

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

# ABC056c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

x = int(input())


def calc(time, pos):
    if pos == x:
        return time
    if pos > x:
        return -1
    for i in range(time+1, x+1):
        result = calc(i, pos+i)
        if result != -1:
            return result
    return -1


print(calc(0, 0))


### FIXED CODE ###

# ABC056c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

x = int(input())
w = 0
for i in range(1, 10**8):
    if x <= (i+1)*i//2:
        w = i
        break
print(w)
### BUGGY CODE ###

N = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(N+1):
  for j in range(N+1):
    if j > i :
      ai = a[i:j]
      go = sum(ai)
      if go == 0:
        count += 1
print(count) 

### FIXED CODE ###

from collections import Counter
N = int(input())
a = list(map(int, input().split()))
count = 0
s = list()
s.append(0)
for i in range(N):
  s.append(a[i] + s[i])
for j in  Counter(s).values():
  count += (j * (j-1))/2
print(int(count))
### BUGGY CODE ###

N , M = [int(i) for i in input().split()]
data = list()
sorted_data = dict()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([p,y])
for p, y in sorted(data):
    if sorted_data.get(p) is None:
        sorted_data[p] = []
    sorted_data[p].append(y)

def num2str(num, len_str=6):
    return "0" * (len_str - len(str(num))) + str(num)

for p, y in data:
    rank = sorted_data[p].index(y) + 1
    print(num2str(p) + num2str(rank))

### FIXED CODE ###

N, M = [int(i) for i in input().split()]
data = list()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([i, p, y])
data.sort(key=lambda x:(x[1],x[2]))
ind = 1
for j, (i, p, y) in enumerate(data):
    if data[j-1][1] != p:
        ind = 1
    data[j].append(ind)
    ind += 1
data.sort(key=lambda x:x[0])
for i, p, y, j in data:
    print(str(p).zfill(6) + str(j).zfill(6))
### BUGGY CODE ###

import sys
N = int(sys.stdin.readline())
for n in range(1,N+1):
  if n < 6:
    x,y,z = 0,0,0
  else:
    x = int((n / 6)**0.5)
    y = int(round((((n -1)/3) - 1/9)**0.5 - 1/3 + 0.5,0))
    z = int((n - 5)**0.5 + 1)
  ans = 0
  for i in range(1,x+1):
    for j in range(i,y+1):
      if i % 2 == j % 2:
        d = 2
        if n % 2 == 0:
          c = 0
        else:
          c = 1
      else:
        d = 1
        if n % 2 == 0:
          c = 10000
        else:
          c = 0    
      for k in range(j + c, z+1, d):
        p = (i + j + k)**2 - i*(j + k) - j*k
        if n < p:
          break
        if n == p:
          if i == j:
            if j == k:
              ans += 1
            else:
              ans += 3
          else:
            if i == k:
              ans += 3
            else:
              if j == k:
                ans += 3
              else:
                ans += 6
  print(ans)

### FIXED CODE ###

import sys
N = int(sys.stdin.readline())
if N < 6:
  x, y, z = 0, 0, 0
else:
  x = int((N / 6)**0.5)
  y = int(round(((((N -1)/3) - 1/9)**0.5 - 1/3)+ 0.5, 0))
  z = int((N - 5)**0.5 + 1)            
n = [0]*(N+1)
for i in range(1,x+1):
  for j in range(i,y+1):
    for k in range(j, z+1):
      p = int((i + j + k)**2 - i*(j + k) - j*k)
      if N < p:
        break
      if i == j:
        if j == k:
          n[p] += 1
        else:
          n[p] += 3
      else:
        if i == k:
          n[p] += 3
        else:
          if j == k:
            n[p] += 3
          else:
            n[p] += 6
for i in range(1,N+1):
  print(n[i])
### BUGGY CODE ###

n, a, b = map(int, input().split())
mod = pow(10, 9) + 7
ans = 0
u, d = 1, 1

for i in range(1, n+1):
    u *= (n+1-i)
    u %= mod
    d *= i
    d %= mod
    if i not in (a, b):
        ans += u//d
        ans %= mod

print(ans)

### FIXED CODE ###

def cmb(n, r, p):
    r = min(r, n - r)
    upper = 1
    for i in range(n, n - r, -1):
        upper = (upper * i) % p

    lower = 1
    for i in range(1, r + 1):
        lower = (lower * i) % p

    # フェルマーの小定理よりp素数ならupper**(p-2)は逆元
    return (upper * pow(lower, p - 2, p)) % p

mod = pow(10, 9) + 7
n, a, b = map(int, input().split())
ans = (pow(2, n, mod) - 1 - cmb(n, a, mod) - cmb(n, b, mod))%mod
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 0
mod = 10**9 + 7

for i in range(n):
    ans += (a[i] * sum(a[i+1:]))
print(ans%mod)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
ans = 0
mod = 10**9 + 7

for i in range(n):
    sum_a -= a[i]
    ans += a[i] * sum_a
    ans %= mod
print(ans)
### BUGGY CODE ###

N=int(input())
temp=input().split()
A=[int(temp[i]) for i in range(N)]

x1=sum([pow(-1, i)*A[i] for i in range(N)])/2
print(int(2*x1), end=' ')

for i in range(1, N):
  print(int(2*(sum([pow(-1, k-i)*A[k] for k in range(i, N)])-pow(-1, i)*x1)), end=' ')

### FIXED CODE ###

N=int(input())
temp=input().split()
A=[int(temp[i]) for i in range(N)]
As=[]
As.append(sum([A[i]*pow(-1, i) for i in range(N)]))
for i in range(1, N):
  As.append(A[i-1]-As[i-1])

x1=As[0]/2
print(int(2*x1), end=' ')

for i in range(1, N):
  print(2*int(As[i]-x1*pow(-1, i)), end=' ')
### BUGGY CODE ###

[n,k]=list(map(int,input().split()))
akarusa=list(map(int,input().split()))

for i in range(k):
    akarusanext=[0]*n
    for j in range(n):
        kagen=max(j-akarusa[j],0)
        jogen=min(j+akarusa[j],n-1)
        for k in range(kagen,jogen+1):
            akarusanext[k]+=1
    akarusa=akarusanext

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


### FIXED CODE ###

[n,k]=list(map(int,input().split()))
akarusa=list(map(int,input().split()))


for i in range(k):
    imos=[0]*n
    for j in range(n):
        kagen=max(j-akarusa[j],0)
        jogen=min(j+akarusa[j],n-1)
        imos[kagen]+=1
        if jogen+1<n:
            imos[jogen+1]-=1
    akarusanext=imos
    for j in range(1,n):
        akarusanext[j]+=akarusanext[j-1]
    
    if akarusa==akarusanext:
        break
    else:
        akarusa=akarusanext

for i in range(n):
    print(akarusa[i], end=" ")
### BUGGY CODE ###

n = int(input())
list_a = list((map(int, input().split())))
memo = 0
ans = 0
i = 0
j = 0
while i < n:
    while j < n-i:
        memo += list_a[i+j]
        #print(memo)
        if memo == 0:
            ans += 1
        j += 1
    memo = 0
    i += 1
    j = 0
print(ans)


### FIXED CODE ###

n = int(input())
list_a = list((map(int, input().split())))
memo = 0
memo_dict = {0:1}
for i in range(0,n):
    memo += list_a[i]
    if memo in memo_dict:
        memo_dict[memo] += 1
    else:
        memo_dict[memo] = 1
ans = 0
for number in memo_dict.values():
    ans += number * (number-1) / 2
print(int(ans))
### BUGGY CODE ###

import math
a,b,n = map(int,input().split())
ans = 0
for i in range(1,n+1):
    x = i
    z = math.floor(a*x/b)-a*math.floor(x/b)
    if z > ans:
        ans = z
print(ans)

### FIXED CODE ###

from math import floor
a,b,n = map(int,input().split())
x = min(b-1,n)
print(floor(a*x/b)-a*floor(x/b))