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

#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,k = readInts()
A = readInts()
mi = float('inf')
for pa in combinations(A,k):
    nya = sum(pa)
    mi = min(mi,nya)
print(mi)


### FIXED CODE ###

#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,k = readInts()
A = readInts()
mi = float('inf')
A = sorted(A)

print(sum(A[:k]))
### BUGGY CODE ###

n, m = map(int, input().split())
s = []
e = []
ans = 'IMPOSSIBLE'
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        s.append(b)
    elif b == n:
        e.append(a)
if len(s) != 0 and len(e) != 0:
    for i in s:
        if i in e:
            ans = 'POSSIBLE'
print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
s = []
e = []
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        s.append(b)
    elif b == n:
        e.append(a)
if len(set(s) & set(e)) != 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
### BUGGY CODE ###

a,b=sorted(map(int,input().split()))
ans=0
ans2=0
for i in range(a,b+1):
    if abs(a-i)==abs(b-i):
        ans=1
        ans2=i
print(ans2 if ans==1 else "IMPOSSIBLE")

### FIXED CODE ###

a,b=map(int,input().split())
print(int(min(a,b)+abs(a-b)/2) if (a-b)%2==0 else "IMPOSSIBLE")
### BUGGY CODE ###

L,R=map(int,input().split())
m=(L*(L+1))%2019
for i in range(L,R):
    for j in range(i+1,R+1):
        s=(i*j)%2019
        m=min(m,s)
print(m)


### FIXED CODE ###

L,R=map(int,input().split())
if L%2019==0 or R%2019==0:
  print(0)
else:
  start=L%2019
  end=R%2019
  if start>=end or R-L>=2018: #中に2019の倍数が含まれるとき
    print(0)
  else:
    m=(L*(L+1))%2019
    for i in range(L,R):
      for j in range(i+1,R+1):
        s=(i*j)%2019
        m=min(m,s)
    print(m)
### BUGGY CODE ###

import math
n,d = map(int,input().split())

y = list()
x = list()
xy = list()

for i in range(n):
    xy += map(int,input().split())

xy_2 = int(len(xy) / 2)
for i in range(xy_2):
    x.append(xy.pop(0))
    y.append(xy.pop(0))

ans = 0
for i in range(n):
    if d >= math.sqrt(x[i]**2 +y[i]**2):
        ans += 1

print(ans)

### FIXED CODE ###

n,d = map(int,input().split())
d2 = d ** 2

xy2 = list()
for i in range(n):
    x,y = map(int,input().split())
    xy2.append(x**2+y**2)

    ans = 0
for i in xy2:
    if d2 >= i:
        ans += 1
print(ans)
### BUGGY CODE ###

import bisect
A, B, Q = map(int,input().split())
S = [-float("inf")] + sorted([int(input()) for k in range(A)]) + [float("inf")]
T = [-float("inf")] + sorted([int(input()) for k in range(B)]) + [float("inf")]
X = [int(input()) for k in range(Q)]

for x in X:
    p = bisect.bisect_left(S,x)
    q = bisect.bisect_left(T,x)
    t1 = max(abs(S[p]-x),abs(T[q]-x))
    t2 = max(abs(S[p-1]-x),abs(T[q-1]-x))
    t3 = abs(S[p-1]-x)+abs(S[p-1]-T[q])
    t4 = abs(T[q-1]-x)+abs(S[p]-T[q-1])    
    t5 = abs(S[p]-x)+abs(S[p]-T[q-1])    
    t6 = abs(T[q]-x)+abs(S[p-1]-T[q])
    print(min(t1,t2,t3,t4,t5,t6))

### FIXED CODE ###

import bisect
A, B, Q = map(int,input().split())
S = [-float("inf")] + sorted([int(input()) for k in range(A)]) + [float("inf")]
T = [-float("inf")] + sorted([int(input()) for k in range(B)]) + [float("inf")]
X = [int(input()) for k in range(Q)]

for x in X:
    p = bisect.bisect_left(S,x)
    q = bisect.bisect_left(T,x)
    t1 = max(abs(S[p]-x),abs(T[q]-x))
    t2 = max(abs(S[p-1]-x),abs(T[q-1]-x))
    t3 = abs(S[p-1]-x)+abs(S[p-1]-T[q])
    t4 = abs(T[q-1]-x)+abs(S[p]-T[q-1])    
    t5 = abs(S[p]-x)+abs(S[p]-T[q-1])    
    t6 = abs(T[q]-x)+abs(S[p-1]-T[q])
    print(min(t1,t2,t3,t4,t5,t6))
### BUGGY CODE ###

def main():
    import sys
    sys.setrecursionlimit(100000)
    n, m, *ab, = map(int, open(0).read().split())

    p = [-1] * (n + 1)

    def f(x):
        if p[x] < 0:
            return x
        else:
            return f(p[x])

    ans = -1
    order = set()
    for i, j in zip(ab[::2], ab[1::2]):
        if i > j:
            i, j = j, i
        if (i, j) in order:
            continue

        pi, pj = f(i), f(j)
        if pi == pj:
            continue
        p[pi] += p[pj]
        ans = min(ans, p[pi])
        p[j] = pi
        p[pj] = pi
        order.add((i, j))
    print(-ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n, m, *ab, = map(int, open(0).read().split())
    p = [-1] * (n + 1)

    def find(x):
        while p[x] > 0:
            x = p[x]
        return x

    def union(i, j):
        pi, pj = find(i), find(j)
        if pi == pj:
            return
        if p[pi] < p[pj]:
            pi, pj = pj, pi
            i, j = j, i
        p[pi] += p[pj]
        p[pj] = pi
        reconnect(j, pi)

    def reconnect(i, j):
        while p[i] > 0:
            k = p[i]
            p[i] = j
            i = k

    for i, j in zip(ab[::2], ab[1::2]):
        union(i, j)

    print(-min(p))


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

k = int(input())
import math

a = 0
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            a = math.gcd(i, j)
            ans = ans + math.gcd(a, k)
            
print(ans)
            

### FIXED CODE ###

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

N, Y = map(int, input().split())

out = '-1 -1 -1'
is_found = False


def price(t_thousand_num, f_thousand_num, thousand_num):
    return t_thousand_num * 10000 + f_thousand_num * 5000 + thousand_num * 1000


def sum_of_bills(t_thousand_num, f_thousand_num, thousand_num):
    return t_thousand_num + f_thousand_num + thousand_num


def is_over(t_thousand_num, f_thousand_num, thousand_num):
    return price(t_thousand_num, f_thousand_num, thousand_num) > Y or \
           sum_of_bills(t_thousand_num, f_thousand_num, thousand_num) > N


def is_match(t_thousand_num, f_thousand_num, thousand_num):
    return price(t_thousand_num, f_thousand_num, thousand_num) == Y and \
           sum_of_bills(t_thousand_num, f_thousand_num, thousand_num) == N


for t_thousand_num in range(N + 1):

    if is_over(t_thousand_num, 0, 0) or is_found:
        break
    elif is_match(t_thousand_num, 0, 0):
        out = '{} {} {}'.format(t_thousand_num, 0, 0)
        break

    for f_thousand_num in range(N + 1):
        if is_over(t_thousand_num, f_thousand_num, 0) or is_found:
            break
        elif is_match(t_thousand_num, f_thousand_num, 0):
            out = '{} {} {}'.format(t_thousand_num, f_thousand_num, 0)
            is_found = True
            break
        for thousand_num in range(N + 1):
            if is_over(t_thousand_num, f_thousand_num, thousand_num):
                break
            elif is_match(t_thousand_num, f_thousand_num, thousand_num):
                out = '{} {} {}'.format(t_thousand_num, f_thousand_num, thousand_num)
                is_found = True
                break

print(out)


### FIXED CODE ###

N, Y = map(int, input().split())

out = '-1 -1 -1'
is_found = False


def price(t_thousand_num, f_thousand_num, thousand_num):
    return t_thousand_num * 10000 + f_thousand_num * 5000 + thousand_num * 1000


def sum_of_bills(t_thousand_num, f_thousand_num, thousand_num):
    return t_thousand_num + f_thousand_num + thousand_num


def is_over(t_thousand_num, f_thousand_num, thousand_num):
    return price(t_thousand_num, f_thousand_num, thousand_num) > Y or \
           sum_of_bills(t_thousand_num, f_thousand_num, thousand_num) > N


def is_match(t_thousand_num, f_thousand_num, thousand_num):
    return price(t_thousand_num, f_thousand_num, thousand_num) == Y and \
           sum_of_bills(t_thousand_num, f_thousand_num, thousand_num) == N


for t_thousand_num in range(N + 1):

    if is_over(t_thousand_num, 0, 0) or is_found:
        break
    elif is_match(t_thousand_num, 0, 0):
        out = '{} {} {}'.format(t_thousand_num, 0, 0)
        break

    for f_thousand_num in range(N + 1):
        thousand_num = N - f_thousand_num - t_thousand_num
        if is_over(t_thousand_num, f_thousand_num, thousand_num) or is_found or thousand_num < 0:
            break
        elif is_match(t_thousand_num, f_thousand_num, thousand_num):
            out = '{} {} {}'.format(t_thousand_num, f_thousand_num, thousand_num)
            is_found = True
            break

print(out)
### BUGGY CODE ###

N, k = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
isPossible = False

K = [k]

for a in A:
	if a in K:
		isPossible = True
		break
	else:
		K.append(abs(k-a))
for a in A:
	if a in K:
		isPossible = True
		break



if k in A:
	isPossible = True

if k > max(A):
	isPossible = False

# print(K)
if isPossible:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

### FIXED CODE ###

from fractions import gcd
N, K = map(int, input().split())
A = list(map(int, input().split()))
if K in A:
  print('POSSIBLE')
elif K > max(A):
  print('IMPOSSIBLE')
else:
  A_gcd = A[0]
  for i in range(1, N):
    A_gcd = gcd(A_gcd, A[i])

  if K % A_gcd == 0:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')
### BUGGY CODE ###

s = list(input())

while s[0] != 'A':
    s.pop(0)

while s[-1] != 'Z':
    s.pop()

print(len(s))

### FIXED CODE ###

s = list(input())

while s[0] != 'A' or s[-1] != 'Z':
    if s[0] == 'A':
        s.pop()
    elif s[-1] == 'Z':
        s.pop(0)
    else:
        s.pop(0)
        s.pop()

print(len(s))
### BUGGY CODE ###

from copy import deepcopy


def main():
    h, w = list(map(int, input().split()))
    matrix = []
    for _ in range(h):
        matrix.append([c for c in input()])

    adj = [(0, 1), (0, -1), (1, 0), (-1, 0)]

    def step(q, m):
        next = []
        filled = deepcopy(m)
        while len(q) > 0:
            y, x = q.pop(0)

            for dy, dx in adj:
                if -1 < y + dy < h and -1 < x + dx < w:
                    if m[y + dy][x + dx] == '.':
                        filled[y + dy][x + dx] = '#'
                        next.append((y + dy, x + dx))

        return next, filled

    iq = []
    for i in range(h):
        for j in range(w):
            if matrix[i][j] == '#':
                iq.append((i, j))

    count = 0
    m = matrix
    while len(iq) > 0:
        # finished = all([m[i][j] == '#' for i in range(h) for j in range(w)])
        next, m = step(iq, m)
        if len(next) > 0:
            count += 1
            iq = next

    print(count)


main()

### FIXED CODE ###

import numpy

def main():
    h, w = map(int, input().split())
    max_value = h + w
    gridmap = []

    for y in range(h):
        gridmap.append([0 if v == '#' else max_value for v in input().strip()])

    values = numpy.array(gridmap)

    for x in range(w - 1):
        values[:, x + 1] = numpy.minimum(values[:, x] + 1, values[:, x + 1])

    for x in range(w - 1, 0, -1):
        values[:, x - 1] = numpy.minimum(values[:, x] + 1, values[:, x - 1])

    for y in range(h - 1):
        values[y + 1, :] = numpy.minimum(values[y, :] + 1, values[y + 1, :])

    for y in range(h - 1, 0, -1):
        values[y - 1, :] = numpy.minimum(values[y, :] + 1, values[y - 1, :])

    print(numpy.max(values))


main()
### BUGGY CODE ###

# Nの入力
N = int(input())

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

result = 1
for i in A:
    result *= i

if result > 10 ** 18:
    result = -1
        

print(result) 
    

### FIXED CODE ###

# Nの入力
N = int(input())

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

result = 1
if 0 in A:
    result = 0
else:
    for i in A:
        result *= i
        if result > 10 ** 18:
            result = -1
            break
print(result)
### BUGGY CODE ###

n,m = map(int,input().split())
h = list(map(int,input().split()))
r = [list(map(int,input().split())) for _ in range(m)]
s = [[] for _ in range(n+1)]
for i in range(m):
    t1,t2 = r[i][0],r[i][1]
    s[t1].append(t2)
    s[t2].append(t1)
bad = []
cnt = 0
for i in range(1,n+1):
    if i not in bad:
        setsi = set(s[i])
        if all(h[i-1] > h[k-1] for k in setsi):
            cnt += 1
            for k in setsi:
                if k not in bad:
                    bad.append(k)
print(cnt)

### FIXED CODE ###

n,m = map(int,input().split())
h = list(map(int,input().split()))
ans = [1]*n
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    if h[a] <= h[b]:
        ans[a] = 0
    if h[b] <= h[a]:
        ans[b] = 0
print(sum(ans))
### BUGGY CODE ###

n = int(input())

box =[]

for x in range(1,n):
    for y in range(1,n):
        if x + y == n:
            xsum = sum(list(map(int, str(x))))
            ysum = sum(list(map(int, str(y))))
            box.append(xsum + ysum)
            
print(min(box))
            

### FIXED CODE ###

n = int(input())

box =[]

for x in range(1,n):
    y = n -x
    xsum = sum(list(map(int, str(x))))
    ysum = sum(list(map(int, str(y))))
    box.append(xsum + ysum)
            
    
            
print(min(box))
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  n = int(input())
  nums = list(map(int, [input() for _ in range(n)]))
  values = [0] * len(nums)
  value = 1

  for i in range(len(nums)):
    values[i] += value

    for j in range(i + 1, len(nums)):
      if nums[i] != nums[j] or nums[j - 1] == nums[j]:
        continue

      values[j] += value

    value = values[i]

  print(value, flush=True)


if __name__ == '__main__':
  main()



### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  value = 1
  skips = {}
  prev = -1

  for _ in range(int(input())):
    n = int(input())

    if n == prev:
      continue

    prev = n

    if n in skips:
      value += skips[n]

    skips[n] = value

  print(value % int(1e+9 + 7), flush=True)


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

import heapq
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)

done = [[[False for k in range(Z)] for j in range(Y)] for i in range(X)]
done[0][0][0] = True

hq = [(-(A[0]+B[0]+C[0]), 0, 0, 0)]
heapq.heapify(hq)  # リストhqのheap化

ans = 0
D = [(1, 0, 0), (0, 1, 0), (0, 0, 1)]

for _ in range(K):
    s, i, j, k = heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    print(-s)
    for d in D:
        ni, nj, nk = i+d[0], j+d[1], k+d[2]
        if ni < X and nj < Y and nk < Z and done[ni][nj][nk] is False:
            # heap化されたリストhqに要素xを追加
            heapq.heappush(hq, (-(A[ni]+B[nj]+C[nk]), ni, nj, nk))
            done[ni][nj][nk] = True


### FIXED CODE ###

import heapq
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)
# done = [[[True for _ in range(Z+1)] for _ in range(Y+1)] for _ in range(Z+1)]
done = set()

h = []
heapq.heappush(h, (-(A[0]+B[0]+C[0]), 0, 0, 0))  # リストaのheap化
done.add((0, 0, 0))

for _ in range(K):
    p, i, j, k = heapq.heappop(h)
    # print(h)
    print(-p)

    if (i+1, j, k) not in done and i+1 < X:
        # heap化されたリストaに要素xを追加
        heapq.heappush(h, (-(A[i+1]+B[j]+C[k]), i+1, j, k))
        # print(h)
        done.add((i+1, j, k))

    if (i, j+1, k) not in done and j+1 < Y:
        # heap化されたリストaに要素xを追加
        heapq.heappush(h, (-(A[i]+B[j+1]+C[k]), i, j+1, k))
        # print(h)
        done.add((i, j+1, k))

    if (i, j, k+1) not in done and k+1 < Z:
        # heap化されたリストaに要素xを追加
        heapq.heappush(h, (-(A[i]+B[j]+C[k+1]), i, j, k+1))
        # print(h)
        done.add((i, j, k+1))
### BUGGY CODE ###

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

a.insert(0,0)

ans = [0]*(n+1)

for i in range(n,0,-1):
    value = 0
    for j in range(2*i,n+1):
        value = value ^ ans[j]
    ans[i] = value ^ a[i]
print(sum(ans))
for i in range(1,n+1):
    if ans[i] == 1:
        print(i,end = " ")



### FIXED CODE ###

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

a.insert(0,0)

ans = [0]*(n+1)

for i in range(n,0,-1):
    value = 0
    for j in range(2*i,n+1,i):
        value = value ^ ans[j]
    ans[i] = value ^ a[i]
print(sum(ans))
for i in range(1,n+1):
    if ans[i] == 1:
        print(i,end = " ")
### BUGGY CODE ###

import sys
input=sys.stdin.readline
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
L=len(format(max(a),"b"))
s=[0]*L
for i in range(n):
  c=format(a[i], 'b').zfill(L)
  for j in range(L)[::-1]:
    s[j]+=int(c[j])
ans=0
for i in range(len(s))[::-1]:
  ans+=2**(i)*(s[L-i-1])*(n-s[L-i-1])
  ans%=mod
print(ans)


### FIXED CODE ###

import sys
input=sys.stdin.readline
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
s=[0]*61
for i in range(n):
  c=format(a[i], 'b')
  L=len(c)
  for j in range(L)[::-1]:
    s[L-j-1]+=int(c[j])
ans=0
for i in range(61):
  ans+=2**(i)*(s[i])*(n-s[i])
  ans%=mod
print(ans)
### BUGGY CODE ###

N,M = list(map(int,input().split()))
a = []
for _ in range(M):
    a.append(int(input()))
dp = [0] * (N + 1)
dp[0] = 1
dp[1] = 1
for i in range(2,N + 1):
    p = i-1 not in a
    q = i-2 not in a
    if p:
        dp[i] += dp[i-1]
        dp[i] %= 1000000007
    if q:
        dp[i] += dp[i-2]
        dp[i] %= 1000000007
print(dp[N])

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    N,M = list(map(int,input().split()))
    a = []
    A = [0] * (1 + 10 ** 5)
    for _ in range(M):
        A[int(input())] = 1
    dp = [0] * (N + 1)
    dp[0] = 1
    if A[1]:
        dp[1] = 0
    else:
        dp[1] = 1
    for i in range(2,N + 1):
        if A[i]:
            dp[i] = 0
        else:
            dp[i] = dp[i-1] + dp[i-2]
            dp[i] %= 1000000007
    print(dp[N])
if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import deque
h,w,k=map(int,input().split())
sy,sx,gy,gx=map(int,input().split())
maze=[list(input()) for _ in range(h)]

sy-=1
sx-=1
gy-=1
gx-=1

maze[sy][sx]="S"

dis=[[-1]*w for _ in range(h)]

dis[sy][sx]=0

d = deque([(sx,sy)])
while len(d)>0:
    (x,y)=d.popleft()
    if x==gx and y==gy:
        print(dis[gy][gx])
        exit()

    for (mx,my) in ((0,1),(1,0),(-1,0),(0,-1)):
        #print(mx,my,d)
        tmp=[]
        for j in range(1,k+1):
            nx=x+mx*j
            ny=y+my*j
            #print(y,x,">>",ny,nx)
            if 0<=nx<w and 0<=ny<h:
                if maze[ny][nx]=="." and (dis[ny][nx]==-1 or dis[ny][nx]==dis[y][x]+1):
                    dis[ny][nx]=dis[y][x]+1
                    tmp.append((nx,ny))
                    #pri(dis)
                else:
                    break
            else:
                break
        for item in tmp[::-1]:
            d.append(item)

print(-1)
    


                










### FIXED CODE ###

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

    h,w,k=map(int,input().split())
    sy,sx,gy,gx=map(int,input().split())

    #maze=[]
    #for _ in range(h):
    #    maze.append(tuple(input()))

    maze=[tuple(input()) for _ in range(h)]

    sy-=1
    sx-=1
    gy-=1
    gx-=1

    #maze[sy][sx]="S"

    dis=[[-1]*w for _ in range(h)]



    dis[sy][sx]=0



    d = deque([(sx,sy)])
    while len(d)>0:
        (x,y)=d.popleft()
        if x==gx and y==gy:
            print(dis[gy][gx])
            #maze[gy][gx]="G"

            #pri(dis)
            #pri(maze)

            exit()

        for (mx,my) in ((0,1),(1,0),(-1,0),(0,-1)):
            #print(mx,my,d)
            for j in range(1,k+1):
                nx=x+mx*j
                ny=y+my*j
                #print(y,x,">>",ny,nx)
                if 0<=nx<w and 0<=ny<h:
                    if maze[ny][nx]=="." and (dis[ny][nx]==-1 or dis[ny][nx]==dis[y][x]+1):
                        if dis[ny][nx]==-1:
                            d.append((nx,ny))
                        dis[ny][nx]=dis[y][x]+1
                        
                        #pri(dis)
                    else:
                        break
                else:
                    break

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

N = int(input())
array=[int(n) for n in input().split()]
lst=[]
for i in range(N+1):
    left_array=array[:N+i]
    l = sorted(left_array)[-N:]
    right_array=array[N+i:]
    r = sorted(right_array)[:N]
    ans = sum(l)-sum(r)
    lst.append(ans)
print(max(lst))

### FIXED CODE ###

N = int(input())
array = [int(n) for n in input().split()]
import copy
import heapq
lst = [None for i in range(N + 1)]
left_lst = copy.deepcopy(lst)
right_lst = copy.deepcopy(lst)
left_array = array[:N]
right_array= [-n for n in array[-N:]]
l_sum = sum(left_array)
r_sum = sum(right_array)
heapq.heapify(left_array)
heapq.heapify(right_array)
left_lst[0] = l_sum
right_lst[0] = r_sum

for k in range(N, 2 * N):
    new_a, new_b = array[k], array[-k - 1]*-1
    heapq.heappush(left_array,new_a)
    heapq.heappush(right_array,new_b)
    old_a = heapq.heappop(left_array)
    l_sum += (new_a - old_a)
    left_lst[k - N + 1] = l_sum
    old_b = heapq.heappop(right_array)
    r_sum += (new_b - old_b)
    right_lst[k - N + 1] = r_sum
lst = [ a + b for a, b in zip(left_lst, list(reversed(right_lst)))]
print(max(lst))
### BUGGY CODE ###

import numpy as np
N=int(input())
A=[int(input()) for _ in range(N)]
Anp=np.array(A)
for i in range(N):
    vec=np.ones(N,dtype=bool)
    vec[i]=False
    print(max(Anp[vec]))

### FIXED CODE ###

N=int(input())
A=[int(input()) for _ in range(N)]
AS=sorted(A)
# for i in range(N):
#     if AS[-1]==A[i]:
#         print(AS[-2])
#     else:
#         print(AS[-1])
for i in range(N):
    print(AS[-2] if AS[-1]==A[i] else AS[-1])
### BUGGY CODE ###

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

xlist=[]
ylist=[]

for i,a in enumerate(alist):
    xlist.append((i+1)+a)
    ylist.append((i+1)-a)

output=0
for i in range(max(ylist)+1):
    output+= xlist.count(i)*ylist.count(i)

print(output)


### FIXED CODE ###

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

xdic={}
ydic={}

for i,a in enumerate(alist):
    #xlist.append((i+1)+a)
    #ylist.append((i+1)-a)
    tmpx=(i+1)+a
    tmpy=(i+1)-a
    if tmpx in xdic:
        xdic[tmpx]=xdic[tmpx]+1
    else:
        xdic[tmpx]=1
    if tmpy > 0:
        if tmpy in ydic:
            ydic[tmpy]=ydic[tmpy]+1
        else:
            ydic[tmpy]=1

output=0
for y in ydic:
    if y in xdic:
        output+= xdic[y]*ydic[y]

print(output)