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

n, m = map(int, input().split())
tail = []
head = []
cost = []
for _ in range(m):
  l, r, c = map(int, input().split())
  tail.append(l - 1)
  head.append(r - 1)
  cost.append(c)
tail += list(range(1, n))
head += list(range(n - 1))
cost += [0] * (n - 1)

inf = sum(cost) + 1
dp = [0] + [inf] * (n - 1)
act = 0
unexplr = [False] + [True] * (n - 1)
while unexplr[-1]:
  for edge in range(m + n - 1):
    to = head[edge]
    if act == tail[edge] and unexplr[to]:
      if dp[to] > dp[act] + cost[edge]:
        dp[to] = dp[act] + cost[edge]
  short = inf
  for vertex in range(n):
    if unexplr[vertex] and dp[vertex] < short:
      act = vertex
      short = dp[vertex]
  unexplr[act] = False
if dp[-1] < inf:
  print(dp[-1])
else:
  print(-1)

### FIXED CODE ###

import heapq

n, m = map(int, input().split())
edge = [[]] + [[(0, i)] for i in range(n-1)]
for _ in range(m):
  l, r, c = map(int, input().split())
  edge[l-1].append((c, r-1))

inf = 1 << 60
dp = [0] + [inf] * (n - 1)
queue = [(0, 0)]
check = [False] * n
while queue and not check[-1]:
  dist, act = heapq.heappop(queue)
  check[act] = True
  for cost, vertex in edge[act]:
    if check[vertex]:
      continue
    d = dist + cost
    if dp[vertex] > d:
      heapq.heappush(queue, (d, vertex))
      dp[vertex] = d
if dp[-1] < inf:
  print(dp[-1])
else:
  print(-1)
### BUGGY CODE ###

def main():
    """"ここに今までのコード"""

n = int(input())
A = [int(a) for a in input().split()]
mod=10**9+7

ans=0
for i in range(60):
    l=sum([a>>i & 1 for a in A])
    ans+= l*(n-l) <<i
    ans = ans%mod
    

#ans=xor[0]
#for j in range(60-1):
#    ans=((2*ans)+xor[j+1])%mod
print(int(ans)) 

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    """"ここに今までのコード"""
 
n = int(input())
A = [int(a) for a in input().split()]
mod=10**9+7
 
ans=0
for i in range(60):
    l=sum([a%2 for a in A])
    ans=(ans+l*(n-l)*(2**i))%mod
    A=[a//2 for a in A]
    
 
#ans=xor[0]
#for j in range(60-1):
#    ans=((2*ans)+xor[j+1])%mod
print(int(ans)) 
 
if __name__ == '__main__':
    main()
### BUGGY CODE ###

import heapq
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(N)]

AB.sort(reverse=True)
works=[]
heapq.heapify(works)
ans=0
for i in range(1,M+1):
  day=M-i
  latest=i
  while AB and AB[-1][0]<=latest:
    a,b=AB[-1][0],AB[-1][1]
    AB=AB[:-1]
    heapq.heappush(works,-b)
  if not works:
    continue
  ans-=heapq.heappop(works)

print(ans)


### FIXED CODE ###

import heapq
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(N)]

AB.sort(reverse=True)
works=[]
heapq.heapify(works)
ans=0
for i in range(1,M+1):
  day=M-i
  latest=i
  while AB and AB[-1][0]<=latest:
    a,b=AB.pop()
    heapq.heappush(works,-b)
  if not works:
    continue
  ans-=heapq.heappop(works)

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

s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0]*(m+1) for _ in range(n+1)]
for i in range(1,n+1):
  for j in range(1,m+1):
    if s[i-1]==t[j-1]:
      dp[i][j]=dp[i-1][j-1]+1
    else:
      dp[i][j]=max(dp[i-1][j],dp[i][j-1])
x=dp[-1][-1]
i=n
j=m
ans=""
while x!=0:
  if dp[i][j]==dp[i][j-1]:
    j-=1
  elif dp[i][j]==dp[i-1][j]:
    i-=1
  else:
    ans+=s[i-1]
    i-=1
    j-=1
    x-=1
print(ans[::-1])


### FIXED CODE ###

s,t=input(),input()
ls,lt=len(s),len(t)
dp=[[0]*(lt+1) for _ in range(ls+1)]
for i in range(1,ls+1):
  for j in range(1,lt+1):
    if s[i-1]==t[j-1]:dp[i][j]=dp[i-1][j-1]+1
    else:dp[i][j]=max(dp[i-1][j],dp[i][j-1])
l=dp[-1][-1]
i,j,a=ls,lt,""
while l!=0:
  if dp[i][j]==dp[i][j-1]:j-=1
  elif dp[i][j]==dp[i-1][j]:i-=1
  else:a=s[i-1]+a;i-=1;j-=1;l-=1
print(a)
### BUGGY CODE ###

import collections

H,W = map(int,input().split())
L = [input() for i in range(H)]

dxy = [(1,0),(0,1)]

cnt_list = [[float("inf") for x in range(W)] for y in range(H)]
cnt_list[0][0] = 1

q = collections.deque([(0,0)])

while q :
    y,x = q.popleft()
    for dy,dx in dxy :
        ny = y + dy
        nx = x + dx
        
        if (ny < 0) or (ny >= H) or (nx < 0) or (nx >= W) :
            continue
        if L[ny][nx] == "#" :
            continue
        if cnt_list[ny][nx] < float("inf") :
            cnt_list[ny][nx] += cnt_list[y][x]
        else :
            cnt_list[ny][nx] = cnt_list[y][x]
            q.append((ny,nx))
ans = cnt_list[-1][-1]
if ans < float("inf") :
    ans %= 10**9+7
else :
    ans = 0

print(ans)


### FIXED CODE ###

import collections

H,W = map(int,input().split())
L = [input() for i in range(H)]

dxy = [(1,0),(0,1)]

cnt_list = [[float("inf") for x in range(W)] for y in range(H)]
cnt_list[0][0] = 1

q = collections.deque([(0,0)])

while q :
    y,x = q.popleft()
    for dy,dx in dxy :
        ny = y + dy
        nx = x + dx
        
        if (ny < 0) or (ny >= H) or (nx < 0) or (nx >= W) :
            continue
        if L[ny][nx] == "#" :
            continue
        if cnt_list[ny][nx] < float("inf") :
            cnt_list[ny][nx] += cnt_list[y][x]
        else :
            cnt_list[ny][nx] = cnt_list[y][x]
            q.append((ny,nx))
ans = cnt_list[-1][-1]
if ans < float("inf") :
    ans %= 10**9+7
else :
    ans = 0

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

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
r,g,b,n=IL()
ans=0
for i in range(0,n//r+1):
    for j in range(0,n//g+1):
        if (n-i*r-j*g)%b==0 and n-i*r-j*g>=0:
            ans+=1
            
print(ans)

### FIXED CODE ###

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
r,g,b,n=IL()
L=[r,g,b]
L.sort()
s,m,l=L
ans=0
for i in range(n//l+1):
    for j in range(n//m+1):
        if n-i*l-j*m<0:
            break
        elif (n-i*l-j*m)%s==0:
            ans+=1
            
print(ans)
### BUGGY CODE ###

X,K,D = map(int,input().split())
for i in range(K):
    if X >= 0:
        X -= D
    else:
        X += D
print(abs(X))

### FIXED CODE ###

X,K,D = map(int,input().split())
X = abs(X)
if X >= K*D:
    print(X-K*D)
else:
    if (K - X//D) % 2 == 0:
        print(X-X//D*D)
    else:
        print((X//D+1)*D-X)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    N,M,Q = map(int,input().split())
    go = [[0 for _ in range(N)] for i in range(N)]
    for _ in range(M):
        L,R = map(int,input().split())
        go[L-1][R-1] += 1
        
    qu = []
    for _ in range(Q):
        p,q = map(int,input().split())
        qu.append((p-1,q-1))
        
    num = [[0 for _ in range(N)] for _ in range(N)]
    for i in range(N):
        num[i][0] = go[i][0]
    for i in range(N):
        for j in range(N-1):
            num[i][j+1] = num[i][j] + go[i][j+1]
            
    for i in range(Q):
        ans = 0
        p,q = qu[i]
        for j in range(p,q+1):
            ans += num[j][q]
        print(ans)
    
if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    N,M,Q = map(int,input().split())
    go = [[0 for _ in range(N)] for i in range(N)]
    for _ in range(M):
        L,R = map(int,input().split())
        go[L-1][R-1] += 1
        
    qu = []
    for _ in range(Q):
        p,q = map(int,input().split())
        qu.append((p,q))
        
    num = [[0 for _ in range(N)] for _ in range(N)]
    _num = [[0 for _ in range(N)] for _ in range(N+1)]
    for i in range(N):
        num[i][0] = go[i][0]
    for i in range(N):
        for j in range(N-1):
            num[i][j+1] = num[i][j] + go[i][j+1]

    for i in range(N):
        for j in range(N):
            _num[j+1][i] = _num[j][i] + num[j][i]
            
    for i in range(Q):
        p,q = qu[i]
        ans = _num[q][q-1] - _num[p-1][q-1]
        print(ans)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

N=int(input())
arr=list(map(int,input().split()))
total=sum(arr)
mt=[0]*N


for i in range(total+1):
    mt[0]=i
    for j in range(N-1):
        mt[j+1]=arr[j]*2-mt[j]
    if sum(mt)==total:
        break
    
print(*mt)


### FIXED CODE ###

N=int(input())
arr=list(map(int,input().split()))
total=sum(arr)
mt=[0]*N

for j in range(N-1):
    mt[j+1]=arr[j]*2-mt[j]
a=total-sum(mt)

for i in range(N):
    if i%2==0:
        mt[i]+=a
    else:
        mt[i]-=a
        
print(*mt)
### BUGGY CODE ###

#coding: UTF-8

N = int(input())

a = [int(input()) for i in range(N)]

ans = []

for i in range(N-1):
    Rj = int(a.pop(0));
    tmp = max(a);
    ans.append(tmp - Rj);

print(max(ans))

### FIXED CODE ###

#coding: UTF-8

N = int(input())

a = [int(input()) for i in range(N)]

ans = set()

maxv = -9999999999
minv = a[0]
for i in range(1,N):
    if (a[i] - minv) > maxv:
        maxv = a[i] - minv
    if a[i] < minv:
        minv = a[i]

print(maxv)
### BUGGY CODE ###

import bisect
import statistics
n = int(input())
a = list((int(x) for x in input().split()))

a.sort()
incl = []
score = 0

for i in range(len(a)):
    ain = a.pop()
    incl.append(ain)
    if i==0: continue
    if (len(incl)%2 == 1):
        score += statistics.median(incl)
    else:
        # smaller of middle two
        score += incl[ int(len(incl)/2)-1 ]

print(score)

### FIXED CODE ###

import bisect
import statistics
n = int(input())
a = list((int(x) for x in input().split()))

a.sort()
incl = []
score = 0

for i in range(len(a)):
    ain = a.pop()
    incl.append(ain)
    if i==0: continue
    if (len(incl)%2 == 1):
        score += incl[ int(len(incl)/2) ]
    else:
        # smaller of middle two
        score += incl[ int(len(incl)/2)-1 ]

print(score)
### BUGGY CODE ###

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

xys = {}
xs = []
ys = []
for i in range(n):
  x, y = map(int, input().split())
  xys[i] = (x, y)
  xs.append(x)
  ys.append(y)
xs = sorted(xs)
ys = sorted(ys)
min_area = float('inf')

for li in range(n):
  for ri in range(li+1, n):
    left = xs[li]
    right = xs[ri]
    for bi in range(n):
      for ti in range(bi+1, n):
        bottom = ys[bi]
        top = ys[ti]
        area = (top - bottom) * (right - left)
        cnt = 0
        for i in range(n):
          xi, yi = xys[i]
          if (left <= xi <= right) and (bottom <= yi <= top):
            cnt += 1
            if cnt >= k:
              break
        if cnt >= k:
          min_area = min([min_area, area])

print(min_area)


### FIXED CODE ###

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

xys = {}
xs = []
ys = []
for i in range(n):
  x, y = map(int, input().split())
  xys[i] = (x, y)
  xs.append(x)
  ys.append(y)
xs = sorted(xs)
ys = sorted(ys)
min_area = float('inf')

for li in range(n):
  for ri in range(li+1, n):
    left = xs[li]
    right = xs[ri]
    for bi in range(n):
      for ti in range(bi+1, n):
        bottom = ys[bi]
        top = ys[ti]
        area = (top - bottom) * (right - left)
        cnt = 0
        for i in range(n):
          xi, yi = xys[i]
          if (left <= xi <= right) and (bottom <= yi <= top):
            cnt += 1
            if cnt >= k:
              break
        if cnt >= k:
          min_area = min([min_area, area])

print(min_area)
### BUGGY CODE ###

n,k,q=map(int,input().split())
a=[int(input())-1 for i in range(q)]
for i in range(n):
    print("Yes" if k-q+a.count(i)>0 else "No")

### FIXED CODE ###

n,k,q=map(int,input().split())
a=[int(input())-1 for i in range(q)]
point=[k-q for i in range(n)]
for i in a:
    point[i]+=1

for i in point:
    print("Yes" if i>0 else "No")
### BUGGY CODE ###

import sys
input = sys.stdin.readline

import math

N,M = map(int,input().split())
S = input()

if "1"*M in S:
  print(-1)
  exit()  

S = [int(S[i]) for i in range(N+1)]

max_n = [0]
mask = (1<<M) -1
b = (1<<M) -1
for i in range(N+1):
  b = ((b<<1) + S[i])&mask
  max_n.append(len(bin(mask-b))-2)

  
now = N
deme = []
while now > 0:
  x = max_n[now]
  now = now-x
  deme.append(x)
print(*deme[::-1])

### FIXED CODE ###

import sys
input = sys.stdin.readline

import math
import bisect

N,M = map(int,input().split())
S = input()

if "1"*M in S:
  print(-1)
  exit()  

S = [int(S[i]) for i in range(N+1)]

L = [(1<<i) -1 for i in range(1,M+1)]

max_n = [0]
mask = (1<<M) -1
b = 0
for i in range(N):
  b = ((b<<1) + (1- S[i])) & mask
  max_n.append(bisect.bisect_left(L,b)+1)

now = N
deme = []
while now != 0:
  x = max_n[now]
  now -= x
  deme.append(x)
print(*deme[::-1])
### BUGGY CODE ###

N, M, R = map(int, input().split())
R_LIST = list(map(int, input().split()))
ABC = []
for _ in range(M):
    a,b,c = map(int, input().split())
    ABC.append((a,b,c))
    
edges = ABC[:]


def warshall_floyd(d, n):
    # d: グラフ二次元リスト
    # n: 頂点数 (0始まり)
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

# グラフ無効グラフ化
graph = [[float("inf") for i in range(N+1)] for i in range(N+1)] 
for x,y,z in edges:
    graph[x][y] = z
    graph[y][x] = z
for i in range(N+1):
    graph[i][i] = 0 #自身のところに行くコストは０

#最短経路
shortest =  warshall_floyd(graph, N+1)
    
# 順列全探索
import sys
INT_MAX = sys.maxsize # 9223372036854775807
ans = INT_MAX

import queue

q = queue.Queue()
travels = R_LIST[:]

for t in travels:
    q.put((
        0,
        (t,)
    ))


def dfs(cost,past):
    #print('aaa', past)
    if len(past) == len(travels):
        return cost
    
    ret = INT_MAX
    for t in travels:
        if t in past:
            continue
        
        if len(past) == 0:
            tmp_ret = dfs(0, [t])
            ret = min(ret, tmp_ret)
        else:
            next_cost = cost + shortest[past[-1]][t]
            if ret <= next_cost:
                continue

            next_past = past[:] + [t]
            tmp_ret = dfs(next_cost, next_past)
            ret = min(ret, tmp_ret)
        
    return ret

print(dfs(0, []))
            
      
        
        



### FIXED CODE ###

N, M, R = map(int, input().split())
R_LIST = list(map(int, input().split()))
ABC = []
for _ in range(M):
    a,b,c = map(int, input().split())
    ABC.append((a,b,c))
    
    
edges = ABC[:]


def warshall_floyd(d, n):
    # d: グラフ二次元リスト
    # n: 頂点数 (0始まり)
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

# グラフ無効グラフ化
graph = [[float("inf") for i in range(N+1)] for i in range(N+1)] 
for x,y,z in edges:
    graph[x][y] = z
    graph[y][x] = z
for i in range(N+1):
    graph[i][i] = 0 #自身のところに行くコストは０

#最短経路
shortest =  warshall_floyd(graph, N+1)
    
# 順列全探索
import sys
INT_MAX = sys.maxsize # 9223372036854775807
ans = INT_MAX

import queue

rest = set(R_LIST[:])

import copy  
def dfs(cost,pre,rest):
    if len(rest) == 0:
        return cost
    
    ret = INT_MAX
    for r in rest:
        if pre == None:
            next_cost = 0
        else:
            next_cost = cost + shortest[pre][r]
        next_rest = copy.copy(rest)
        next_rest.remove(r)
        
        tmp_ret = dfs(next_cost, r, next_rest)
        ret = min(ret, tmp_ret)
        
    return ret
        
    

print(dfs(0, None, rest))
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
A.insert(0,0)
 
for y in range(1, N+1):
    hold = A[y]
    A.pop(y)
    price = 0
    
    for x in range(len(A)-1):
        price += abs(A[x+1] - A[x])
    price += abs(A[-1])
    print(price)
    A.insert(y, hold)

### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
A.insert(0,0)
A.append(0)
price = 0
for x in range(n+1):
    price += abs(A[x+1]-A[x])
for x in range(1, n+1):
    s = price
    s = s + abs(A[x-1]-A[x+1]) - (abs(A[x-1]-A[x])+abs(A[x]-A[x+1]))
    print(s)
### BUGGY CODE ###

def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

N = pow(10, 5)  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
mod = pow(10, 9) + 7

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)

n,k = map(int,input().split())
a = [int(i) for i in input().split()]
a.sort()
if k > 1:
    ans = 0
    for i in range(k-1, n):
        for j in range(0, i - k + 2):
            ans += (a[i] - a[j]) * cmb(i - j - 1, k - 2)
            #print(j, i, ' ', a[j],a[i], ' ', a[i] - a[j])
    ans %= pow(10, 9) + 7
    print(ans)
else:
    print(0)


### FIXED CODE ###

def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

N = pow(10, 5)  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
mod = pow(10, 9) + 7

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)

n,k = map(int,input().split())
a = [int(i) for i in input().split()]
a.sort()
if k > 1:
    ans = 0
    for i in range(k-1, n):
        maxs = a[i]
        ncr = cmb(i, k-1)
        #print(maxs, ncr, maxs * ncr)
        ans += maxs * ncr
        ans %= mod
    for i in range(n-k+1):
        mins = a[i]
        ncr = cmb(n-i-1, k-1)
        #print(mins, ncr, mins * ncr)
        ans -= mins * ncr
        ans %= mod
    print(ans)
else:
    print(0)
### BUGGY CODE ###

N = int(input())
nums = [int(e) for e in input().split()]

for i in range (1,N+1):
    print(nums.count(i))

### FIXED CODE ###

import collections as col

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

List = col.Counter(List)
Count_List = [0]*n
for i in List:
    Count_List[i-1] = List[i]

for i in range(0,len(Count_List)):
    print(Count_List[i])
### BUGGY CODE ###

N = int(input())
A = []
x = 0
for i in range(N):
    s = int(input())
    if A.count(s)==0:
        A.append(s)
    else:
        A.remove(s)



print(len(A))

### FIXED CODE ###

N = int(input())
A = set()
x = 0
for i in range(N):
    s = int(input())
    if s in A:
        A.remove(s)
    else:
        A.add(s)



print(len(A))
### BUGGY CODE ###

def main():
  def syaku(j,x,D):
    while True:
      if j+1>=N:
        break
      if XH[j+1][0]<=x+2*D:
        j+=1
      else:
        break
    return j
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  l=[0]*N
  x = XH[0][0]
  j = 0
  l[0]=syaku(j,x,D)
  for i in range(1,N):
    x = XH[i][0]
    j = l[i-1]
    l[i]=syaku(j,x,D)
  H = [xh[1] for xh in XH]
  for i,a in enumerate(l):
    h = H[i]
    if h<=0:
      continue
    else:
      b = (h+A-1)//A
      ans += b
      y = b*A
      for j in range(i,a+1):
        H[j]-=y
  print(ans)
main()

### FIXED CODE ###

def main():
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  S = [0]*(N+1)
  x = XH[0][0]
  h = XH[0][1]
  j = 0
  b = (h+A-1)//A
  ans += b
  y = b*A
  while True:
    if j+1>=N:
      break
    if XH[j+1][0]<=x+2*D:
      j+=1
    else:
      break
  S[0]+=y
  S[j+1]-=y
  S[1]+=S[0]
  for i in range(1,N):
    xh = XH[i]
    h = xh[1]
    s = S[i]
    rec = h-s
    if rec<=0:
      S[i+1]+=s
      continue
    else:
      x = xh[0]
      j = max(j,i)
      while True:
        if j+1>=N:
          break
        if XH[j+1][0]<=x+2*D:
          j+=1
        else:
          break
      b = (rec+A-1)//A
      ans += b
      y = b*A
      S[i]+=y
      S[j+1]-=y
      S[i+1]+=s+y
  print(ans)
main()
### BUGGY CODE ###

from collections import deque
n = int(input())
d = deque()
for _ in range(n):
  d.append(int(input()))
for _ in range(n):
  b = d.popleft()
  print(max(d))
  d.append(b)

### FIXED CODE ###

n = int(input())
d = []
for _ in range(n):
  d.append(int(input()))
a = sorted(d)
for i in range(n):
  if a[-1] == d[i]:
    print(a[-2])
  else:
    print(a[-1])
### BUGGY CODE ###

from math import factorial

def comb(n, r):
  return factorial(n) / factorial(r) / factorial(n - r)

n = int(input())
A = sorted(list(map(int, input().split())))
max_A = A[-1]
half_A = A[0]
for i in range(len(A) - 1):
  if A[i] < max_A / 2 and i < len(A) - 2:
    half_A = A[i]
  else:
    if comb(max_A, half_A) > comb(max_A, A[i]):
      print(max_A, half_A)
    else:
      print(max_A, A[i])
    exit()

### FIXED CODE ###

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

ans1 = max(A)
diff = 10 ** 9 
for i in range(N):
  if abs(A[i] - ans1 / 2) <= diff:
    ans2 = A[i]
    diff = abs(A[i] - ans1 / 2)
print(ans1, ans2)
### BUGGY CODE ###

n = int(input())
s = input()

rcnt = s.count('R')
gcnt = s.count('G')
bcnt = s.count('B')

sub = 0
for i in range(n):
    for j in range(i+1, n):
        k = j + (j - i)
        if n <= k: continue

        alp = set()
        alp.add(s[i])
        alp.add(s[j])
        alp.add(s[k])

        if len(alp) == 3: sub += 1

ans = rcnt * gcnt * bcnt - sub
print(ans)

### FIXED CODE ###

n = int(input())
s = input()

rcnt = s.count('R')
gcnt = s.count('G')
bcnt = s.count('B')

sub = 0
for i in range(n):
    for j in range(i+1, n):
        k = j + (j - i)
        if n <= k: break

        alp = set()
        alp.add(s[i])
        alp.add(s[j])
        alp.add(s[k])

        if len(alp) == 3: sub += 1

ans = rcnt * gcnt * bcnt - sub
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N):
  for j in range(N):
    if i < j:
      #ans += (A[i]*A[j])
      ans += (A[i]*A[j])%(10**9+7)
print(ans%(10**9+7))

### FIXED CODE ###

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

s = sum(a)
ans = 0

for i in a:
  s -= i
  s %= mod
  ans += s*i
  ans %= mod
  
print(ans)
### BUGGY CODE ###

import math
n = int(input())
ans = 0
for i in range(1, n + 1):
    for j in range(1,n+1):
        for k in range(1, n + 1):
            ans += math.gcd(math.gcd(i, j), k)
print(ans)

### FIXED CODE ###

import math
k = int(input())
ansA, ansB, ansC = 0, 0, 0
for a in range(k):
    ansC += a+1
    for b in range(k-a-1):
        GCDab = math.gcd(a+1, a+b+2)
        ansB += GCDab
        for c in range(k-a-b-2):
            GCDabc = math.gcd(GCDab, a+b+c+3)
            ansA += GCDabc
ans = ansA * 6 + ansB * 6 + ansC
print(ans)
### BUGGY CODE ###

n=int(input())
sums=0
for j in range(n):
    q=0
    i=1
    while i*i<=j+1:
        if (j+1)%i==0:
            q=q+2
            if (j+1)//i==i:
                q=q-1
        i=i+1
    sums=sums+(j+1)*q
print(sums)      

### FIXED CODE ###

n=int(input())
sums=0
i=1
while i<=n:
    m=n//i
    sums=sums+((m+1)/2*m)*i
    i=i+1
print(int(sums))
### BUGGY CODE ###

H,W=[int(s) for s in input().split()]
inls=[[int(s) for s in input().split()] for _ in range(H)]
for i in range(H):
  x=[int(s) for s in input().split()]
  for j in range(W):
    inls[i][j]=abs(inls[i][j]-x[j])
dp=[[set() for _ in range(W)] for _ in range(H)]
dp[0][0].add(inls[0][0])
for i in range(H):
  for j in range(W):
    x=80*(H+W-i-j)
    for e in dp[i-1][j]:
      if e+inls[i][j]<x:
        dp[i][j].add(e+inls[i][j])
      dp[i][j].add(abs(e-inls[i][j]))
    for e in dp[i][j-1]:
      if e+inls[i][j]<x:
        dp[i][j].add(e+inls[i][j])
      dp[i][j].add(abs(e-inls[i][j]))
print(min(dp[H-1][W-1]))


### FIXED CODE ###

import time
start = time.time()
H,W=[int(s) for s in input().split()]
inls=[[int(s) for s in input().split()] for _ in range(H)]
for i in range(H):
  x=[int(s) for s in input().split()]
  for j in range(W):
    inls[i][j]=abs(inls[i][j]-x[j])
dp=[[set() for _ in range(W)] for _ in range(H)]
dp[0][0].add(inls[0][0])
for i in range(H):
  for j in range(W):
    x=80*(H+W-i-j)
    for e in dp[i-1][j]:
      if e+inls[i][j]<x:
        dp[i][j].add(e+inls[i][j])
      dp[i][j].add(abs(e-inls[i][j]))
    for e in dp[i][j-1]:
      if e+inls[i][j]<x:
        dp[i][j].add(e+inls[i][j])
      dp[i][j].add(abs(e-inls[i][j]))
  if time.time() - start>1.7:
    dp[H-1][W-1].add(0)
    break
print(min(dp[H-1][W-1]))