Harryxun/stf_run huggingface dataset:
N=int(input())

red=[]
blue=[]

for i in range(N):
    a,b=map(int,input().split())
    red.append((a,b))

for i in range(N):
    c,d=map(int,input().split())
    blue.append((c,d))

red=sorted(red,key=lambda x:-x[1])
blue=sorted(blue,key=lambda x:x[0])

answer=0
for i,b in enumerate(blue):
    for j,r in enumerate(red):
        if red[0]<blue[0] and red[1]<blue[1]:
            answer+=1
            red.pop(j)
            break

print(answer)

### FIXED CODE ###

N=int(input())

red=[]
blue=[]

for i in range(N):
    a,b=map(int,input().split())
    red.append((a,b))

for i in range(N):
    c,d=map(int,input().split())
    blue.append((c,d))

red=sorted(red,key=lambda x:-x[1])
blue=sorted(blue,key=lambda x:x[0])

answer=0
for i,b in enumerate(blue):
    for j,r in enumerate(red):
        if r[0]<b[0] and r[1]<b[1]:
            answer+=1
            red.pop(j)
            break

print(answer)
N = int(input())
S = input()
count = 0
for i in range(1, N - 1):
  if S[i-1] + S[i] + S[i + 1] = 'ABC':
    count += 1
print (count)

### FIXED CODE ###

N = int(input())
S = input()
print(S.count("ABC"))
A,V = (int(x) for x in input().split())
B,W = (int(x) for xin input().split())
T = int(input())

if V>W and abs(A-B)/(V-W)<=T:
    Flag = True
else:
    Flag = False
    
if Flag:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

A,V = (int(x) for x in input().split())
B,W = (int(x) for x in input().split())
T = int(input())

if V>W and abs(A-B)/(V-W)<=T:
    Flag = True
else:
    Flag = False
    
if Flag:
    print('YES')
else:
    print('NO')
import itertools
import numpy as np

def powerset(L):
  pset = set()
  for n in range(len(L) + 1):
    for sset in itertools.combinations(L, n):
      pset.add(sset)
  return pset
    
def list_diff(first, second):
        first = first.copy()
        for s in second:
            first.remove(s)
        return first

def main():
    N = int(input())
    facs = factors(N)
    st = powerset(facs)

    mn_ij = 10**12
    for i in st:
        i = list(i)
        j = list_diff(facs, i)
        i, j = np.prod(i), np.prod(j)

        mn_ij = min(mn_ij, i+j)

    print(int(mn_ij-2))

if __name__ == "__main__":
    main()


### FIXED CODE ###

import math

def main():
    N = int(input())
    rt_N = math.ceil(math.sqrt(N))

    mn_ij = 10**12
    for i in range(1, rt_N+1):
        if N % i == 0:
            j = N // i

            mn_ij = min(mn_ij, i+j)
        
        mn_ij = min(mn_ij, i+j)

    # print(list(map(len,[ st, facs]) ))
    print(int(mn_ij-2))

if __name__ == "__main__":
    main()
import sys
 
sys.setrecursionlimit(150000)sys.setrecursionlimit(150000)

def gdp(n, dp, G):
    if dp[n]!=-1:
        return dp[n]
 
    if G[n]==[]:
        dp[n]=0
        return 0
 
    for i in G[n]:
        ll=gdp(i, dp, G)
        if dp[n]<ll+1:
            dp[n]=ll+1
 
    return dp[n]
 
def solve(N: int, M: int, x: "List[int]", y: "List[int]"):
    G=[[] for _ in range(N)]
    for i in range(M):
        G[x[i]-1].append(y[i]-1)
 
    dp=[-1]*N
 
    print(max(gdp(i, dp, G) for i in range(N)))
 
    return
 
 
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    x = [int()] * (M)  # type: "List[int]"
    y = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, M, x, y)
 
if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/env python3
import sys
 
sys.setrecursionlimit(150000)

def gdp(n, dp, G):
    if dp[n]!=-1:
        return dp[n]
 
    if G[n]==[]:
        dp[n]=0
        return 0
 
    for i in G[n]:
        ll=gdp(i, dp, G)
        if dp[n]<ll+1:
            dp[n]=ll+1
 
    return dp[n]
 
def solve(N: int, M: int, x: "List[int]", y: "List[int]"):
    G=[[] for _ in range(N)]
    for i in range(M):
        G[x[i]-1].append(y[i]-1)
 
    dp=[-1]*N
 
    print(max(gdp(i, dp, G) for i in range(N)))
 
    return
 
 
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    x = [int()] * (M)  # type: "List[int]"
    y = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, M, x, y)
 
if __name__ == '__main__':
    main()
import xgboost as xgb
from sklearn.model_selection import GridSearchCV
import math
import pandas as pd
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns  # pip install seaborn
import re
import statsmodels.api as sm
import statsmodels.formula.api as smf
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split

S=input()

if S[0:math.floor((len(S)/2))] == S[math.floor((len(S)/2))+1:len(S)]:
    p = S[0:math.floor((len(S)/2))]
    q = S[math.floor((len(S)/2))+1:len(S)]
    print('Yes')
else:
    print('No')            

### FIXED CODE ###

import math

S=input()

if S[0:math.floor((len(S)/2))] == S[math.floor((len(S)/2))+1:len(S)]:
    p = S[0:math.floor((len(S)/2))]
    q = S[math.floor((len(S)/2))+1:len(S)]
    if p == p[len(p)::-1]:
        if q == q[len(q)::-1]:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')
a = input().split()

if int(a[0])<=int(a[1]) and int(a[0])<=int(a[2]):
  min = a[0]
  if int(a[1])<=int(a[2]):
    max = int(a[2])
  else:
    max = int(a[1])
elif int(a[1])<=int(a[2]) and int(a[1])<=int(a[0]):
  min = a[1]
  if int(a[0])<=int(a[2]):
    max = int(a[2])
  ele:
    max = int(a[0])
else:
  min = a[2]
  if int(a[0])<=int(a[1]):
    max = int(a[1])
  ele:
    max = int(a[0])

print(max-min)

### FIXED CODE ###

a = input().split()

if int(a[0])<=int(a[1]) and int(a[0])<=int(a[2]):
  min = int(a[0])
  if int(a[1])<=int(a[2]):
    max = int(a[2])
  else:
    max = int(a[1])
elif int(a[1])<=int(a[2]) and int(a[1])<=int(a[0]):
  min = int(a[1])
  if int(a[0])<=int(a[2]):
    max = int(a[2])
  else:
    max = int(a[0])
else:
  min = int(a[2])
  if int(a[0])<=int(a[1]):
    max = int(a[1])
  else:
    max = int(a[0])

print(max-min)
N=int(input())

for i in range(0, N):
  val = input()
  if val:
    S.append(val)
AC=S.count('AC')
WA=S.count('WA')
TLE=S.count('TLE')
RE=S.count('RE')

print("AC x ", end='') 
print(AC)
print("WA x ", end='') 
print(WA)
print("TLE x ", end='') 
print(TLE)
print("RE x ", end='') 
print(RE)

### FIXED CODE ###

N=int(input())
S=[]
for i in range(0, N):
    val = input()
    S.append(val)
ac=S.count('AC')
wa=S.count('WA')
tle=S.count('TLE')
re=S.count('RE')

print("AC x ", end='') 
print(ac)
print("WA x ", end='') 
print(wa)
print("TLE x ", end='') 
print(tle)
print("RE x ", end='') 
print(re)
if __name__ == "__main__":
    while True:
        n, m, a = map(int, raw_input().split())
        if n == 0 and m == 0 and a == 0:
            break

        now = a
        amida = [[] for i in range(1000)]

        for i in range(m):
            h, p, q = map(int, raw_input().split())
            amida[h].append((p, q))
        
        for height in range(1000 - 1, 0, -1):
            lines = amida[height]
            for l in lines:
                if l[0] == now:
                    now = l[1]
                elif l[1] == now:
                    now = l[0]

        print now

### FIXED CODE ###

if __name__ == "__main__":
    while True:
        n, m, a = map(int, raw_input().split())
        if n == 0 and m == 0 and a == 0:
            break

        now = a
        amida = [[] for i in range(1001)]

        for i in range(m):
            h, p, q = map(int, raw_input().split())
            amida[h].append((p, q))
        
        for height in range(1000 - 1, 0, -1):
            lines = amida[height]
            for l in lines:
                if l[0] == now:
                    now = l[1]
                elif l[1] == now:
                    now = l[0]

        print now
n,k = map(int,input().split())
left = 0
right = 10**19

while right - left >1:
  middle = (right + left)//2
  if middle < abs(middle - k) :
    left = middle
  else:
    right = middle
if n < k and k //n == 2:
  print(n)
elif n//k ==2:
    print(0)
else:
  print(min(left,abs(n-k),n))

### FIXED CODE ###

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

if n == 0:
  print(0)
elif n % k==0:
  print(0)
elif n >k:
  while n > abs(n - k):
    n = min(abs(n - k),n % k)
  print(n)
else:
  while n > abs(n - k):
    n = abs(n - k)
  print(n)
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve( lst_a, lst_b,n):
    if n.count("-")>=2:
        return "No"
    else:
        N,NN=n.split("-")
        if lst_a == len(N) and lst_b == len(NN):
            answer = "Yes"
        else:
            answer = "No"
    return answerr

# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line1 = sys.stdin.readline().rstrip()
    [str_n, str_i] = line1.split(' ')
    line2 = sys.stdin.readline().rstrip()
    return (int(str_n), int(str_i), line2)

def main():
    n, i, s = readQuestion()
    answer = solve(n, i, s)
    print(answer)
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve( lst_a, lst_b,n):
    if n.count("-")!=1:
        answer= "No"
    else:
        N,NN=n.split("-")
        if lst_a == len(N) and lst_b == len(NN):
            answer = "Yes"
        else:
            answer = "No"
    return answer

# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line1 = sys.stdin.readline().rstrip()
    [str_n, str_i] = line1.split(' ')
    line2 = sys.stdin.readline().rstrip()
    return (int(str_n), int(str_i), line2)

def main():
    n, i, s = readQuestion()
    answer = solve(n, i, s)
    print(answer)
    
if __name__ == '__main__':
    main()
import sys

N, W = map(int, input().split())
WV = [list(map(int, sys.stdin.readline().split())) for i in range(N)]

INF = 10**10 + 1
dp = [[INF]*(N+1) for i in range(1000*N+1)]

for i in range(N+1):
        dp[0][i]=0

i = 1

while(True):
        for j in range(1, N+1):
                if i-WV[j-1][1]>=0:
                        dp[i][j] = min(dp[i-WV[j-1][1]][j-1]+WV[j-1][0], dp[i][j-1])
                else:
                        dp[i][j] = min(dp[i][j-1], WV[j-1][0])
        #print(i, dp[i][N])
        if dp[i-1][N] <= W and dp[i][N] > W:
                break
        i += 1

print(i-1)

### FIXED CODE ###

import sys

N, W = map(int, input().split())
WV = [list(map(int, sys.stdin.readline().split())) for i in range(N)]
'''
w = [0]*N
v = [0]*N
for i in range(N):
        w[i], v[i] = map(int, sys.stdin.readline().split())
'''
INF = 10**11+1
dp = [[INF]*(N+1) for j in range(N*(10**3)+10)]
i = 1
ans = INF
while(True):
        for j in range(1, N+1):
                #print(i, j)
                w = WV[j-1][1]
                if i-w > 0:
                        dp[i][j] = min(dp[i][j-1], dp[i-w][j-1]+WV[j-1][0])
                        #dp[i][j] = max(dp[i-WV[j-1][0]][j-1]+WV[j-1][1], dp[i][j-1])
                else:
                        dp[i][j] = min(dp[i][j-1], WV[j-1][0])
        #print(dp[i][N])
        #print(i, dp[i][N])
        if dp[i][N] > W and ans <= W:
                print(i-1)
                exit()
        ans = dp[i][N]
        '''
        if dp[i][N] >= W:
                if ans == 0:
                        ans = dp[i][N]
                elif ans < dp[i][N]:
                        print(i)
                        exit()
                print(i, ans)
        '''
        i += 1
def main():
    from sys import stdin
    input = stdin.readline
    import numpy as np
    import scipy.sparse as sp

    n, m, s, t = map(int, input().split())
    uvab = np.array([list(map(int, input().split())) for _ in [0]*m])

    data = uvab[:, 2]
    row = uvab[:, 0] - 1
    col = uvab[:, 1] - 1

    matrix = sp.csr_matrix(
        (data, (row, col)), shape=(n, n), dtype=np.int64)
    yen = sp.csgraph.shortest_path(matrix, indices=s-1, directed=False)

    data = uvab[:, 3]
    matrix = sp.csr_matrix(
        (data, (row, col)), shape=(n, n), dtype=np.int64)
    snk = sp.csgraph.shortest_path(matrix, indices=t-1, directed=False)

    cost = yen+snk
    m = cost[-1]
    for i in range(n-1, -1, -1):
        m = min(cost[i], m)
        cost[i] = m

    cost = 10**15-cost

    for i in cost:
        print(int(i))


main()


### FIXED CODE ###

n,m,s,t=map(int,input().split())
uvab=[list(map(int,input().split())) for _ in [0]*m]
g_yen=[[] for _ in [0]*n]
[g_yen[u-1].append([v-1,a]) for u,v,a,b in uvab]
[g_yen[v-1].append([u-1,a]) for u,v,a,b in uvab]

g_snk=[[] for _ in [0]*n]
[g_snk[u-1].append([v-1,b]) for u,v,a,b in uvab]
[g_snk[v-1].append([u-1,b]) for u,v,a,b in uvab]

import heapq
def dijkstra(g,start):
    inf=10**15
    dist=[inf for _ in [0]*n]
    h=[(0,start)]
    heapq.heapify(h)
    while h:
        d,i=heapq.heappop(h)
        if dist[i]==inf:
            dist[i]=d
            for x,y in g[i]:
                heapq.heappush(h,(d+y,x))
    return dist

yen=dijkstra(g_yen,s-1)
snk=dijkstra(g_snk,t-1)

cost=[yen[i]+snk[i] for i in range(n)]
m=cost[-1]
for i in range(n-1,-1,-1):
    m=min(m,cost[i])
    cost[i]=m
    
for i in cost:
    print(10**15-i)
k, s = map(int, input().split())
p = 0
for x in range(0,k+1):
  for y in range(0,k+1):
    for z in range(0,k+1):
      if (x+y+z) == s:
        p+=1
      if (x+y+z) >= s:
        break
    if (x+y+Z) >= s:
      break
print(p)

### FIXED CODE ###

k, s = map(int, input().split())
p = 0
for x in range(0,k+1):
  for y in range(0,k+1):
    z = s - x - y
    if z >= 0 and z <= k:
      p += 1
print(p)
n = int(input())
num_list = list(map(int, input().split()))
num_unique = list(set(num_list))
num_unique.sort()
num_unique.reverse()
max_num = 0
flag = False
for i in range(num_unique[-2], 0, -1):
    if i == 1:
        max_num = 1
        break
    elif flag and count < 2:
        break
    else:
        flag = True
        count = 0
        max_num = i
    for num in num_unique:
        # print("-------------------------------------------")
        # print("最大公約数候補: {0}, 数: {1}, カウント: {2}".format(i, num, count))
        # print("割る： {0}, あまり: {1}".format(num / max_num, num % max_num))
        if num / max_num < 1 or num % max_num != 0:
            count += 1
            if count > 1:
                break
print(max_num)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
end = sorted(a)[1]

for i in range(end + 1, 0, -1):
    x = 0
    for j in a:
        if j % i != 0:
            x += 1
        if x >= 2:
            break
    if x <= 1:
        print(i)
        break
import sys
sys.setrecursionlimit(10**6)
N = int(input())
A = list(map(int, input().split()))
acts = [(x, i) for i, x in enumerate(A)]
acts.sort()
dp = [[-1]*N for _ in range(N)]
 
def rec(l, r):
    if r < l:
        return 0
    if dp[l][r] >= 0:
        return dp[l][r]
    k = r - l
    act, init_pos = acts[k]
    gain_l = act * abs(l - init_pos)
    gain_r = act * abs(r - init_pos)
    res = dp[l][r] = max(gain_l + rec(l+1, r), gain_r + rec(l, r-1))
    return res
 
print(solve(0, N-1))

### FIXED CODE ###

def main():
  N = int(input())
  INF = float('inf')
  A = [(i+1, a) for i, a in enumerate(map(int, input().split()))]
  A = sorted(A, key=lambda x: x[1], reverse = True)

  dp = [[-INF] * (N+1) for _ in range(N+1)]
  dp[0][0] = 0

  for s in range(1, N+1):
    for l in range(s+1):
      r = s - l
      dp[l][r] = max(dp[l-1][r] + A[s-1][1] * abs(A[s-1][0]-l), dp[l][r-1] + A[s-1][1] * abs(N-r+1-A[s-1][0]))
    
  ans = 0
  for m in range(N):
    if(dp[m][N-m] > ans):
      ans = dp[m][N-m]
    
  print(ans)

main()
import sys

dic = {}
while True:
	try:
		a,b = map(str,input(),split())
		page = int(b)

		if a not in dic:
			dic[a] = [page]
		else:
			dic[a].append(page)
			
	except EOFError:
		sorted(dic.keys())
		names = list(dic.keys())
		for i in range(len(names)):
			print(names[i])
			for j in range(len(dic[i])):
				if j == len(dic[i])-1:
					print(dic[i][j])
				else:
					sys.stdout.write(dic[i][j])
		break

### FIXED CODE ###

import sys

dic = {}
while True:
	try:
		a,b = map(str,input().split())
		page = int(b)

		if a not in dic:
			dic[a] = [page]
		else:
			dic[a].append(page)

	except EOFError:
		names = sorted(dic.keys())
		for i in range(len(names)):
			print(names[i])
			pages = sorted(dic[names[i]])
			for j in range(len(pages)):
				if j == len(pages)-1:
					print(pages[j])
				else:
					sys.stdout.write(str('{:} '.format(pages[j])))
		break
a,b = map(int,input().split())
n = input()
if n[a]=="-":
  n = n.pop(a)
  if n.isdecimal():
    print("Yes")
    exit()
print("No")

### FIXED CODE ###

a,b = map(int,input().split())
n = input()
if 1<=a<=5 and 1<=b<=5:
  if n[a]=="-":
    if n[0:a].isdecimal() and n[a+1:a+b+1].isdecimal():
      print("Yes")
      exit()
print("No")
n,m=map(int,input().split())
fib=[1]
a=1
b=1
for i in range(n):
    fib.append(b)
    c=b
    b+=a
    a=c

total=1
cannot=0
s=-1
for i in range(m):
    t=int(input())
    if t-s == 1:
        cannot+=1
        break
    else:
        total*=fib[t-s-2]
        total%=10**9+7
    s=t



if n+1-t <= 1:
    cannot+=1
else:
    total*=fib[n-t-1]
    total%=10**9+7

if cannot != 0:
    print(0)
else:
    print(total)

### FIXED CODE ###

n,m=map(int,input().split())
fib=[1]
a=1
b=1
for i in range(n):
    fib.append(b)
    c=b
    b+=a
    a=c

total=1
cannot=0
s=-1
if m==0:
    total=fib[n]%(10**9+7)
else:
    for i in range(m):
        t=int(input())
        if t-s == 1:
            cannot+=1
            break
        else:
            total*=fib[t-s-2]
            total%=10**9+7
        s=t



    if n+1-t <= 1:
        cannot+=1
    else:
        total*=fib[n-t-1]
        total%=10**9+7

if cannot != 0:
    print(0)
else:
    print(total)
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
N, M, S, T = [int(_) for _ in input().split()]
UVAB = [[int(_) for _ in input().split()] for _ in range(M)]
G1 = [[0] * N for _ in range(N)]
G2 = [[0] * N for _ in range(N)]

for u, v, a, b in UVAB:
    u -= 1
    v -= 1
    G1[u][v] = G1[v][u] = a
    G2[u][v] = G2[v][u] = b


def dijkstra(V, G, i):
    INF = float('inf')

    H = []
    d = 0
    D = [INF] * V
    D[i] = 0
    used = [False] * V
    used[i] = True

    while True:
        for j in G[i].keys():
            heapq.heappush(H, (d + G[i][j], j))
        v = -1
        while H:
            d, j = heapq.heappop(H)
            if not used[j]:
                v = j
                break
        if v == -1:
            break
        else:
            used[v] = True
            D[v] = d
            i = v
    return D


D1 = dijkstra(N, G1, S - 1)
D2 = dijkstra(N, G2, T - 1)

D = [_ for _ in itertools.accumulate([10**15 - sum(_) for _ in zip(D1, D2)][::-1], func=max)][::-1]
print(*D, sep='\n')


### FIXED CODE ###

import math, string, itertools, fractions, collections, re, array, bisect, sys, random, time, copy, functools
from heapq import heappush, heappop, heappushpop, heapify, heapreplace
input = sys.stdin.readline

N, M, S, T = [int(_) for _ in input().split()]
UVAB = [[int(_) for _ in input().split()] for _ in range(M)]
G1 = collections.defaultdict(lambda: collections.defaultdict(int))
G2 = collections.defaultdict(lambda: collections.defaultdict(int))

for u, v, a, b in UVAB:
    u -= 1
    v -= 1
    G1[u][v] = G1[v][u] = a
    G2[u][v] = G2[v][u] = b


def dijkstra(V, G, start):
    INF = float('inf')
    D = [INF for _ in range(V)]
    D[start] = 0
    H = [(0, start)]
    while H:
        du, u = heappop(H)
        if D[u] < du:
            continue
        for v, d in G[u].items():
            if D[v] > du + d:
                D[v] = du + d
                heappush(H, (D[v], v))
    return D


D1 = dijkstra(N, G1, S - 1)
D2 = dijkstra(N, G2, T - 1)

D = [10**15 - sum(_) for _ in zip(D1, D2)]
for i in range(N - 1, 0, -1):
    D[i - 1] = max(D[i - 1], D[i])
print(*D, sep='\n')
# -*- coding: utf-8 -*-
s,t,u=map(str,input().split)
A = s[0]
B = t[0]
C = u[0]
print("{}".format(A+B+C.upper()))

### FIXED CODE ###

# -*- coding: utf-8 -*-
s,t,u = map(str,input().split())
S = s[0]
T = t[0]
U = u[0]
print("{}".format((S+T+U).upper()))
import numpy as np

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



a = np.array(A)
l = int(((N**2)+1)/2)



b = np.tile((1,-1),(1,l))

print(1)

# c = (np.delete(b, 2*l-1, axis=None)).reshape(N,N)
# # print(c)
# d = c.reshape(N,N)

# inv = 0.5*( np.triu(c) - ( np.tril(c) - np.eye(N) ) )
# g = np.eye(N)
# print(inv)

# x = 2*(np.dot(inv,a))
# print(x)

# ans = list(map(str, list(map(int, list(x)))))
# print(" ".join(ans))

### FIXED CODE ###

import numpy as np
N = int(input())
A = list(map(int, input().split()))
a = np.array(A)
# l = int(((N*N)+1)/2)
b = []
for i in range(N):
    if i%2==0:
        b.append(1)
    else:
        b.append(-1)
c = np.dot(np.array(b),a)
x = [c]
for j in range(1,N):
    x_j = 2*a[j-1] - x[j-1]
    x.append(x_j)
ans = list(map(str, list(map(int, list(x)))))
print(" ".join(ans))
n=input()
a=list(map(int,input().split()))
k=[0,99999999]
for i in range(0,n):
    a[i]=a[i]%min(a)
    a.append(min(a))
    for j in range(n+1):
        if a[j]==0:
            a.remove(a[j])
            n-=1
print(a[0])

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
while len(a)>1:
    m=min(a)
    def f(n):
        return n%m
    a=map(f,a)
    a=set(a)
    a.add(m)
    a.remove(0)
    a=list(a)
print(a[0])