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

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

weight=[]
value=[]
for i in range(n):
  a,b=map(int,input().split())
  weight.append(a)
  value.append(b)

  
dp=[[float('inf')]*(sum(value)+1) for i in range(n+1)]
dp[0][0]=0

for i in range(n):
  for j in range(sum(value)+1):
    dp[i+1][j]=min(dp[i+1][j],dp[i][j])                             #+1、個数制限なし
    dp[i+1][min(j+value[i],sum(value))]=min(dp[i+1][min(j+value[i],sum(value))],dp[i][j]+weight[i])

ans=0
for i in range(sum(value)+1):
  if dp[-1][i]<=w:
    ans=max(ans,i)

print(ans)

### FIXED CODE ###

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

weight=[]
value=[]
for i in range(n):
  a,b=map(int,input().split())
  weight.append(a)
  value.append(b)

xxx=sum(value)
dp=[[float('inf')]*(sum(value)+1) for i in range(n+1)]
dp[0][0]=0

for i in range(n):
  for j in range(xxx+1):
    dp[i+1][j]=min(dp[i+1][j],dp[i][j])                             #+1、個数制限なし
    dp[i+1][min(j+value[i],xxx)]=min(dp[i+1][min(j+value[i],xxx)],dp[i][j]+weight[i])

ans=0
for i in range(xxx+1):
  if dp[-1][i]<=w:
    ans=max(ans,i)

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

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

ans = 10000000000


for i in range(N-1):
    sum_a = sum(a[:i+1])
    sum_b = sum(a[i+1:])
    sa = abs(sum_a-sum_b)
    ans = min(ans, sa)

print(ans)


### FIXED CODE ###

input()
cards = tuple(map(int, input().split(' ')))

a = sum(cards[1:])
s = cards[0]
diff_min = abs(a - s)

for card in cards[1:-1]:
    a -= card
    s += card
    diff_min = min(diff_min, abs(a - s))

print(diff_min)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
c=0
for x in b:
  c=a.count(x)
  if c>=int(x):
    for i in range(int(x)):
      a.remove(x)
print(len(a))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a.sort()
cnt,ans=0,0
p=0
for x in a:
  if p==x:
    cnt+=1
  else:
    if cnt>p:
      ans+=cnt-p
    elif cnt<p:
      ans+=cnt
    p=x
    cnt=1
if cnt>p:
  ans+=cnt-p
elif cnt<p:
  ans+=cnt
print(ans)
### BUGGY CODE ###

num = list(map(int, input().split()))
n, tw = num[0], num[1]

w = [0]
v = [0]

for i in range(n):
    vals = list(map(int, input().split()))
    w.append(vals[0])
    v.append(vals[1])

dp = [[0 for i in range(tw+1)] for j in range(n+1)]

for i in range(1,n+1):
    for j in range(1,tw+1):
        if w[i] > j:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j], v[i] + dp[i-1][j-w[i]])

print(dp[-1][-1])




### FIXED CODE ###

num = list(map(int, input().split()))
n, tw = num[0], num[1]

w = [0]
v = [0]

for i in range(n):
    vals = list(map(int, input().split()))
    w.append(vals[0])
    v.append(vals[1])

if sum(w) < tw:
    tw = sum(w)

dp = [[0 for i in range(tw+1)] for j in range(n+1)]

for i in range(1,n+1):
    for j in range(1,tw+1):
        if w[i] > j:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j], v[i] + dp[i-1][j-w[i]])

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

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))

def gcd(a,b):
    if a < b:
        a,b = b,a
    while b:
        a,b = b,a%b
    return a

ans = 1
tmp = 0
for i in range(n):
    _a = a[:]
    _a.pop(i)
    tmp = _a[0]
    for j in range(n-1):
        tmp = gcd(tmp,_a[j])
    if tmp > ans:
        ans = tmp

print(ans)


### FIXED CODE ###

#EOFERROR
# import math
# import copy
# from functools import reduce
# n = int(input())
# a = list(map(int,input().split()))
# ans = reduce(math.gcd,a)
# if n<=2 or (min(a)==max(a)):
#     print(max(a))
# else:
#     for i in range(n):
#         _a = copy.copy(a)
#         _a.pop(i)
#         tmp = reduce(math.gcd,_a)
#         if tmp > ans:
#             print(tmp)
#             break
#         else:
#             pass

def gcd(a,b):
    if b>a :
        a,b = b,a
    while b:
        a,b = b,a%b
    return a

def cul(n,x):
    l = len(x)
    b = [x[i] for i in range(l)]
    b.pop(n)
    tmp = b[0]
    for i in range(1,l-1):
        tmp = gcd(tmp,b[i])
    return tmp

import sys
p = 50
N = int(input())
if p>N : p=N
a = list(map(int,input().split()))

ans = 0

for i in range(p):
    s = cul(i,a[:p])
    if s>ans : ans=s

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

n,k = map(int,input().split())
a_li = list(map(int,input().split()))
ruiseki = [0]*n
ruiseki[0] = a_li[0]
for i in range(1,n):
    ruiseki[i] = ruiseki[i - 1]*a_li[i]
num = ruiseki[k-1]
for i in range(k,n):
    dum = ruiseki[i]//ruiseki[i-k]
    if dum > num:
        print("Yes")
    else:
        print("No")
    num = dum

### FIXED CODE ###

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

for i in range(k,n):
    if a_li[i-k] < a_li[i]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

import numpy as np 
n = int(input())
size_ls = list(map(int, input().split()))
size_ls.sort()
csum_size = list(np.cumsum(size_ls))

# とりあえず、与えられたインデックスの生き物が全部食べることをできるか返す関数
def isOK(start):
    res = True
    for i in range(start, n-1):
            if not 2 * csum_size[i] >= size_ls[i + 1]:
                res = False
                break
    return res

ans = 1
for i in range(n-1):
    if isOK(i):
        ans += 1
print(ans)

### FIXED CODE ###

import numpy as np 
n = int(input())
size_ls = list(map(int, input().split()))
size_ls.sort()
csum_size = list(np.cumsum(size_ls))

can_ls = [0] * n
can_ls[-1] = 1
for i in range(n-1):
    if 2 * csum_size[i] >= size_ls[i+1]:
        can_ls[i] = 1
ans = 0
for i in range(n-1,-1,-1):
    if can_ls[i] != 1:
        break
    ans += 1
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 9)


def func(v, color):
    if visited[v] != 2:
        return
    visited[v] = color
    for next_v in range(n):
        if graph[v][next_v] != 0:  # vとnext_vが繋がっている場合
            if graph[v][next_v] % 2 == 0:
                func(next_v, color)
            else:
                func(next_v, color ^ 1)


n = int(input())
side = [list(map(int, sys.stdin.readline().split())) for _ in range(n-1)]
graph = [[0] * n for _ in range(n)]
visited = [2] * n  # 2は未訪問 0は白 黒は1

for u, v, w in side:
    graph[u-1][v-1] = w
    graph[v-1][u-1] = w

func(0, 0)

for i in visited:
    print(i)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 9)


def func(v, c):
    for next_v, w in graph[v]:
        if color[next_v] == -1:
            color[next_v] = (c + w) & 1
            func(next_v, c + w) 

n = int(input())
graph = [[] for _ in range(n)]
color = [-1] * n

for _ in range(n-1):
    u, v, w = map(int, sys.stdin.readline().split())
    graph[u-1].append((v-1, w))
    graph[v-1].append((u-1, w))


color[0] = 0
func(0, 0)

for i in color:
    print(i)
### BUGGY CODE ###

n = int(input())
ans = 0

for i in range(n + 1):
    if "3" in str(i) and \
            "5" in str(i) and \
            "7" in str(i) and \
            "1" not in str(i) and \
            "2" not in str(i) and \
            "4" not in str(i) and \
            "6" not in str(i) and \
            "8" not in str(i) and \
            "9" not in str(i) and \
            "0" not in str(i):
        ans += 1

print(ans)


### FIXED CODE ###

import itertools as it

n = input()
ans = 0
nums = ['3', '7', '5']

for j in range(1, len(n) + 1):
    for i in it.product(nums, repeat=j):
        if int(n) >= int("".join(i)) and '3' in i and '5' in i and '7' in i:
            ans += 1

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

N=int(input())
L=list(map(int, input().split()))
a=0
L.sort()
for i in range(0,N-2,1):
  for j in range(i+1,N-1,1):
    ke=L[i]+L[j]
    left=0
    right=N-(j+1)
    while left<right:
      mid=(left+right)//2
      if ke<=L[mid+j+1]:
        right=mid
      else:
        left=mid+1
    a+=left
print(a)

### FIXED CODE ###

from bisect import bisect_left
N=int(input())
L=list(map(int,input().split()))

L.sort()
a=0
for i in range(N-2):
    for j in range(i+1,N-1):
        a+=bisect_left(L,L[i]+L[j])-j-1
print(a)
### BUGGY CODE ###

from bisect import bisect_left

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

n,m = myinput()
a = list(myinput())
bc = mylistinput(m)

a.sort()
bc = mysort(bc,1,True)

ans = 0
for i in range(m):
    b,c = bc[i]
    index = bisect_left(a,c)
    if index==0:
        continue
    ans += sum(a[index:])
    a = a[:index]
    p = min(b,len(a))
    ans += c*p
    a = a[p:] 
ans += sum(a)
print(ans)

### FIXED CODE ###

from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from bisect import bisect_left
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n,m = myinput()
a = list(myinput())
bc = mylistinput(m)

a.sort()
bc = mysort(bc,1,True)

d = []
for i in range(m):
    b = bc[i][0]
    c = bc[i][1]
    d_add = [c]*b
    d.extend(d_add)
    if len(d)>=n:
        d = d[:n]
        break
d.sort()
# print(d)

for i in range(n):
    if len(d)==0:
        break
    e = d.pop()
    if a[i]<e:
        a[i]= e
    else:
        break
# print(a)
ans = sum(a)
print(ans)
### BUGGY CODE ###

from sys import stdin
import numpy as np

if __name__ == '__main__':

    N = int(stdin.readline())
    # A だけどNUMPYにあわせてｂ
    b = [int(x) for x in stdin.readline().rstrip().split()]

    a = list()
    for i in range(N):
        tmp = [0] * N
        if i == N - 1:
            tmp[0] = 0.5
            tmp[i] = 0.5
        else:
            tmp[i] = 0.5
            tmp[i+1] = 0.5

        a.append(tmp)

    A = np.array(a)
    B = np.array(b)

    # [\[Pythonで数値解析\]\(第5回\)連立一次方程式の数値解法 \- Qiita](https://qiita.com/Y_F_Acoustics/items/b386ff8da11e2c912712)
    ans = np.linalg.solve(A, B)

    int_ans = [str(int(x)) for x in ans]
    print(' '.join(int_ans))


### FIXED CODE ###

from sys import stdin

if __name__ == '__main__':

    N = int(stdin.readline())
    A = [int(x) for x in stdin.readline().rstrip().split()]

    tmp = list()
    for i in range(N):
        if i % 2 == 0:
            continue

        tmp.append(A[i])

    X = list()
    X.append(sum(A) - sum(tmp) * 2)

    for i in range(N):
        if i == 0:
            continue

        X.append(2 * A[i-1] - X[i-1])

    print(' '.join([str(x) for x in X]))
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
from collections import Counter
for k in range(1,N+1):
    c=Counter(A)
    ans=0
    if len(c)<k:
        print(0)
    else:
        while True:
            for (i,j) in c.most_common()[:k]:
                c[i]-=1
            if c.most_common()[-1][1]<0:
                break
            ans+=1
        print(ans)


### FIXED CODE ###

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

c = [0] * (N + 1)
Dx = [0] * (N + 1)
for a in A:
    c[a] += 1 #cは、aという数が出た回数を記録
    Dx[c[a]]+=1
    #Dxは、その回数のところに種類を記録。賢い。

Sx=[0]#初項は0
for j in range(1,N+1):
    Sx.append(Sx[j-1]+Dx[j])
#解法2を真似してみる。
for h in range(1,N+1):
    Sx[h]=Sx[h]/h

x=N
k=1
while k<N+1:
    if x<0:
        for _ in range(N-k+1):
            print(0)
        exit(0)
    if k<=Sx[x]:
        print(x)
        k+=1
    else:
        x-=1
### BUGGY CODE ###

# Python3ではTLE
# PyPyなら回る
h, n = map(int, input().split())
inf = 1001001001
dp = [[inf for _ in range(h+1)] for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
    a, b = map(int, input().split())
    for j in range(h + 1):
        # 外側参照しないように
        nj = max(0, j-a)
        dp[i+1][j] = min(dp[i][j], dp[i+1][nj]+b)

print(dp[n][h])


### FIXED CODE ###

h, n = map(int, input().split())
inf = 1001001001
dp = [inf for _ in range(h+1)]
dp[0] = 0
ans = inf
for i in range(n):
    a, b = map(int, input().split())
    for j in range(h + 1):
        # 外側参照しないように
        nj = min(j+a, h)
        dp[nj] = min(dp[nj], dp[j]+b)

print(dp[h])
### BUGGY CODE ###

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

    if (result < min):
        min = result

print(min)

### FIXED CODE ###

L, R = map(int, input().split())
  
min = 2018

for i in range(L, R):
  for j in range(L + 1, R + 1):
    result = (i * j) % 2019
    if (result < min):
      min = result
      if min == 0:
        break
  if min == 0:
    break
    
print(min)
### BUGGY CODE ###

import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################


H,W = II()
A = []
B = []
for i in range(H):
    A.append(III())
for i in range(H):
    B.append(III())

def calc(n):
    return n + (H+W-1)*80

d = [[set() for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if i==0 and j==0:
            d[i][j].add(calc(A[i][j]-B[i][j]))
            d[i][j].add(calc(-A[i][j]+B[i][j]))
        elif j==0:
            for k in d[i-1][j]:
                    d[i][j].add(k+A[i][j]-B[i][j])
                    d[i][j].add(k-A[i][j]+B[i][j])
        elif i==0:
            for k in d[i][j-1]:
                    d[i][j].add(k+A[i][j]-B[i][j])
                    d[i][j].add(k-A[i][j]+B[i][j])
        else:
            for k in d[i-1][j]:
                    d[i][j].add(k+A[i][j]-B[i][j])
                    d[i][j].add(k-A[i][j]+B[i][j])
            for k in d[i][j-1]:
                    d[i][j].add(k+A[i][j]-B[i][j])
                    d[i][j].add(k-A[i][j]+B[i][j])

ans = 2*(H+W-1)*80+1
for i in d[H-1][W-1]:
        now = abs(i-(H+W-1)*80)
        if ans>now:
            ans = now
print(ans)


### FIXED CODE ###

import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

H,W = II()
A,B,C = [],[],[]
for i in range(H):
    A.append(III())
for i in range(H):
    B.append(III())
for i in range(H):
    C.append([abs(A[i][j]-B[i][j]) for j in range(W)])

def calc(n):
    return n+80*(H+W-1)

d = [[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if i==0 and j==0:
            d[i][j] = 2**calc(-C[i][j]) | 2**calc(C[i][j])
        elif i==0:
            d[i][j] = (d[i][j-1]<<C[i][j]) | (d[i][j-1]>>C[i][j])
        elif j==0:
            d[i][j] = (d[i-1][j]<<C[i][j]) | (d[i-1][j]>>C[i][j])
        else:
            d[i][j] = (d[i][j-1]<<C[i][j]) | (d[i][j-1]>>C[i][j]) | \
                        (d[i-1][j]<<C[i][j]) | (d[i-1][j]>>C[i][j])

ans = (H+W-1)*80+1
for i in range(160*(H+W-1)+1):
    if (d[H-1][W-1]>>i)&1:
        val = abs(i-80*(H+W-1))
        if val<ans:
            ans = val

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

n=int(input())
ansl=[]
for i in range(n):
    a=int(input())
    if a in ansl:
        ansl.remove(a)
    else:
        ansl.append(a)
print(len(ansl))

### FIXED CODE ###

n=int(input())
ansl=set([])
for i in range(n):
    a=int(input())
    if a in ansl:
        ansl.remove(a)
    else:
        ansl.add(a)
print(len(ansl))
### BUGGY CODE ###

#import random
import numpy as np

N=int(input())
Ln_d=list(map(int,input().split()))
Ln=np.array(Ln_d)

#for i in range(N):
#    Ln=np.append(Ln,[random.randint(1,1000)])

Ln=np.sort(Ln)[::-1]

Ans=0
left=0
right=0
count=0

for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        A=Ln[di-1]
        B=Ln[dj-1]
        if (B+Ln[dj])<A : break

        right=N-1
        left=dj
        while left<=right :
            count +=1
            mid=int((right+left)/2)
            if (B+Ln[mid])>A :
                left=mid+1
            else :
                right=mid-1
        Ans+=(left-1)-(dj-1)

print(Ans)

### FIXED CODE ###

N=int(input())
Ln=list(map(int,input().split()))
Ln.sort(reverse=True)
Ans=0
left=0
right=0
 
for i in range(N-2):
    di=i+1
    for j in range(N-di-1):
        dj=di+j+1
        A=Ln[di-1]
        B=Ln[dj-1]
        if (B+Ln[dj])<A : break
 
        right=N-1
        left=dj
        while left<=right :
            mid=int((right+left)/2)
            if (B+Ln[mid])>A :
                left=mid+1
            else :
                right=mid-1
        Ans+=(left-1)-(dj-1)
 
print(Ans)
### BUGGY CODE ###

a=int(input())
li=[0]*10000000
count=1
i=2 # ??????????????°
while i<a:    
    r=0
    ta=a
    b=i
    if li[i]!=1:
        while True:
                    
            r=ta%b
            if r==0:
                break
            ta=b
            b=r
        if b==1:
            count+=1
        else:
            temp=i
            l=2
            while True:
               li[temp*l]=1
               l+=1
               if temp*l>a:
                   break
    i+=1                
print(count)

### FIXED CODE ###

def soi(n): #?´??????°????§£?????¢?????´?????????
    i=2
    while True:
        if i*i>n:
            return n
        
        if n%i==0:
            return i
        i+=1


a=int(input())
ans=a
count=1
i=2 # ??????????????°
while True:
    temp=soi(a)
    if a==1: #?´??????°??????????????°
        break
    while a%temp==0: #?´??????°??§???????¶???????
        a/=temp
     #   print (a)

    ans*=(1-1/temp)
    #print (ans)

print(int(ans))


                
       

def gcd(a,b): #?????§??¬?´???°???????????°??????
    r=0
    while True:
       r=a%b
       if r==0:
           break
       a=b
       b=r
    return b
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)

N=int(input())
L=[0]*(N-1) 
MAP=[-1]*(N+1)
MAP[1]=0
for i in range(N-1):
    L[i]=list(map(int,input().split()))
    t=[L[i][1],L[i][0],L[i][2]]
    L.append(t)

L1=sorted(L,key=lambda x: (x[0],x[1]))
LIST=[[]for i in range(N+1)]

for i in range(len(L)):
    LIST[L1[i][0]].append([L1[i][1],L1[i][2]])

def calc(k):
    global MAP
    for i in range(len(LIST[k])):
        #print(LIST[k],len(LIST[k]))
        if(MAP[LIST[k][i][0]]==-1):
            MAP[LIST[k][i][0]]=(MAP[k]+LIST[k][i][1])%2
            #print(LIST[k][i][0],MAP[LIST[k][i][0]])
            calc(LIST[k][i][0])

calc(1)
for i in range(1,N+1):
    print(MAP[i])


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

N=int(input())
L=[0]*(N-1) 
MAP=[-1]*(N+1)
MAP[1]=0
for i in range(N-1):
    L[i]=list(map(int,input().split()))
    t=[L[i][1],L[i][0],L[i][2]]
    L.append(t)

L1=sorted(L,key=lambda x: (x[0],x[1]))
LIST=[[]for i in range(N+1)]

for i in range(len(L)):
    LIST[L1[i][0]].append([L1[i][1],L1[i][2]])

def calc(k):
    global MAP
    for i in range(len(LIST[k])):
        #print(LIST[k],len(LIST[k]))
        if(MAP[LIST[k][i][0]]==-1):
            MAP[LIST[k][i][0]]=(MAP[k]+LIST[k][i][1])%2
            #print(LIST[k][i][0],MAP[LIST[k][i][0]])
            calc(LIST[k][i][0])

calc(1)
for i in range(1,N+1):
    print(MAP[i])
### BUGGY CODE ###

x, y, z, k = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]
c = [int(i) for i in input().split(" ")]
top_bc = []

for bi in b:
    for ci in c:
        top_bc.append(bi + ci)

top_bc = sorted(top_bc, reverse=True)

top_ak = []

for ki in top_bc[0:k]:
    for ai in a:
        top_ak.append(ai + ki)

top_ak = sorted(top_ak, reverse=True)

for top_k in top_ak[0:k]:
    print(top_k)

### FIXED CODE ###

x, y, z, k = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]
c = [int(i) for i in input().split(" ")]
top_bc = []

for bi in b:
    for ci in c:
        top_bc.append(bi + ci)

top_bc = sorted(top_bc, reverse=True)

top_ak = []

for ki in top_bc[0:k]:
    for ai in a:
        top_ak.append(ai + ki)

top_ak = sorted(top_ak, reverse=True)

for top_k in top_ak[0:k]:
    print(top_k)
### BUGGY CODE ###

import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

H, W = MAP()
M = [input().rstrip() for _ in range(H)]
# for m in M:
# 	print(m)

O = []
for i in range(H):
	for j in range(W):
		if M[i][j] == '#': O.append([i, j])

# print(O)

MOVE = [[-1,0],[1,0],[0,-1],[0,1]]

ans = 0
for i in range(H):
	for j in range(W):
		if M[i][j] == '#': continue
		cnt = 1 # 自分
		for move in MOVE:
			nh, nw = i, j
			dh, dw = move
			while True:
				nh += dh
				nw += dw
				# print(i, j, nh, nw)
				if nh>H-1 or nh<0 or nw>W-1 or nw<0: break
				if M[nh][nw] == '#': break
				cnt += 1
		ans = max(ans, cnt)
	
print(ans)

### FIXED CODE ###

import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	H, W = MAP()
	M = [input().rstrip() for _ in range(H)]

	DU = tuple([-1,1])
	LR = tuple([-1,1])
	memo = [[-1]*W for _ in range(H)]
	ans = 0
	for i in range(H):
		for j in range(W):
			if M[i][j] == '#': continue
			tmp = [0,0]
			
			skip = -1
			if memo[i-1][j] != -1:
				tmp[0] = memo[i-1][j][0]
				skip = 1
			if memo[i][j-1] != -1:
				tmp[1] = memo[i][j-1][1]
				skip = 5 if skip == 1 else 2
			
			if skip == 1 or skip == -1:
				lr = 0
				for move in LR:
					nw = j
					dw = move
					while True:
						nw += dw
						# print(i, j, nh, nw)
						if nw>W-1 or nw<0 or M[i][nw] == '#': break
						lr += 1
					tmp[1] = lr

			if skip == 2 or skip == -1:
				du = 0
				for move in DU:
					nh = i
					dh = move
					while True:
						nh += dh
						# print(i, j, nh, nw)
						if nh>H-1 or nh<0 or M[nh][j] == '#': break
						du += 1
					tmp[0] = du
			
			memo[i][j] = tuple(tmp)
			ans = max(ans, sum(tmp)+1)
		
	# for mem in memo:
	# 	print(mem)
	# for m in M:
	# 	print(m)
	print(ans)

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

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

total = sum(A)
ans = 10**9
if n > 2:
    for i in range(1,n-1):
        res = abs(total - 2*sum(A[:i]))
        ans = min([ans, res])
else:
    ans = (A[0] - A[1])
print(ans)


### FIXED CODE ###

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

total = sum(A)
ans = 10**10
res = 0

for i in range(n-1):
    res += A[i]
    ans = min(ans, abs(total -2*res))

print(ans)