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

N, W = map(int, input().split())
INF = 10 ** 9 + 7
wvLst = [list(map(int, input().split())) for _ in range(N)]
dp = [[INF for i in range(10 ** 5 + 1)] for _ in range(N + 1)]

dp[0][0] = 0
for i in range(N):
    for j in range(10 ** 5 + 1):
        if j - wvLst[i][1] >= 0:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - wvLst[i][1]] + wvLst[i][0])
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
ans = 0
for i in range(10 ** 5 + 1):
    if dp[N][i] <= W:
        ans = i

print(ans)

### FIXED CODE ###

N, W = map(int, input().split())
INF = 10 ** 9 + 7
wvLst = [list(map(int, input().split())) for _ in range(N)]
dp = [[INF for i in range(10 ** 5 + 1)] for _ in range(N + 1)]

dp[0][0] = 0
for i in range(N):
    for j in range(10 ** 5 + 1):
        if j - wvLst[i][1] >= 0:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - wvLst[i][1]] + wvLst[i][0])
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
ans = 0
for i in range(10 ** 5 + 1):
    if dp[N][i] <= W:
        ans = i

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

import numpy as np
import sys

N, M = list(map(int, input().split()))
if M == 0:
  h = []
else:
  h = np.array(sys.stdin.readlines()).flatten().astype(int)

if N==1:
  print(1)
elif N==2:
  if M==1:
    print(1)
  else:
    print(2)
else:
  DP = np.zeros(N+1)
  DP[0] = 1
  if 1 in h:
    DP[1] = -1
  else:
    DP[1] = 1
  for i in range(2,N+1):
    if DP[i-2]<0 and DP[i-1]<0:
      print(0)
      exit()
    if i in h:
      DP[i] = -1
    else:
      if DP[i-1]>=0:
        DP[i] += DP[i-1]
      if DP[i-2]>=0:
        DP[i] += DP[i-2]
      DP[i] = DP[i] % 1000000007
  print(int(DP[N]))

### FIXED CODE ###

import sys

N, M = list(map(int, input().split()))
if M == 0:
  h = []
else:
  h = sys.stdin.readlines()
  h = set(map(int, list(set(h))))

if N==1:
  print(1)
elif N==2:
  if M==1:
    print(1)
  else:
    print(2)
else:
  DP = []
  DP.append(1)
  if 1 in h:
    DP.append(-1)
  else:
    DP.append(1)
  for i in range(2,N+1):
    if DP[i-2]<0 and DP[i-1]<0:
      print(0)
      exit()
    DP.append(0)
    if i in h:
      DP[i] = -1
    else:
      if DP[i-1]>=0:
        DP[i] += DP[i-1]
      if DP[i-2]>=0:
        DP[i] += DP[i-2]
      DP[i] = DP[i] % 1000000007
  print(int(DP[N]))
### BUGGY CODE ###

import numpy as np
import math

s = input()[::-1]
length = len(s)
a = np.zeros(length, dtype=int)
d = np.zeros(length, dtype=int)
ans = np.zeros(2019+1)

for i in range(length):
    a[i] = int(s[i]) * pow(10, i) % 2019
d[0] = a[0]

for i in range(length-1):
    d[i+1] = (d[i] + a[i+1]) % 2019
    ans[d[i+1]] += 1

x = ans[np.where(ans > 1)]

print(int(sum([math.factorial(x[i]) for i in range(x.shape[0])]) / 2) + d.shape[0] - np.count_nonzero(d))

### FIXED CODE ###

import numpy as np

s = input()[::-1]
length = len(s)
a = np.zeros(length, dtype=int)
d = np.zeros(length, dtype=int)
ans = np.zeros(2019, dtype=int)
x = 10

a[0] = int(s[0])
d[0] = a[0]
ans[d[0]] += 1

for i in range(1, length):
    a[i] = int(s[i]) * x % 2019
    d[i] = (d[i-1] + a[i]) % 2019
    ans[d[i]] += 1
    x = x * 10 % 2019

ans_c = ans[np.nonzero(ans)]

print(int(sum([ans_c[i] * (ans_c[i]-1) for i in range(ans_c.shape[0])]) / 2) + ans[0])
### BUGGY CODE ###

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

res = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z == s:
                res += 1

print(res)

### FIXED CODE ###

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

res = 0
for x in range(k+1):
    for y in range(k+1):
        if x + y <= s:
            if x + y + k >= s:
                res += 1
        else:
            break

print(res)
### BUGGY CODE ###

k = int(input())
a = []

for  i in range(k+1):
    if i == 0:
        a.append(7%k)
    else:
        a.append((10*a[i-1] + 7)%k)
        if a[i] in a[:i-1]:
            break

if 0 in a:
    print(a.index(0)+1)
else:
    print('-1')

### FIXED CODE ###

k = int(input())
ku = k
a = [0]*ku
c = [0]*ku
b = [0]*ku

for i in range(ku):
    if i == 0:
        b[i] = 7%k
    else:
        b[i] = (b[i-1]*10+7)%k

if 0 in b:
    print(b.index(0)+1)
else:
    print(-1)
### BUGGY CODE ###

N=int(input())
u=[0 for i in range(0,N-1)]
v=[0 for i in range(0,N-1)]
w=[0 for i in range(0,N-1)]
for i in range(0,N-1):
    u[i],v[i],w[i]=map(int,input().split())
w=[w[i]%2 for i in range(0,N-1)]
hen=[[] for i in range(0,N+1)]
for i in range(0,N-1):
    hen[u[i]].append([v[i],w[i]])
    hen[v[i]].append([u[i],w[i]])
ans=[[0,0] for i in range(0,N+1)]
ans[1]=[0,1]
q=[]
q.append(1)
sub=[]
while q!=[]:
    while q!=[]:
        x=q[0]
        q.remove(x)
        if ans[x][0]==0:
            for p in hen[x]:
                s=p[0]
                t=p[1]
                if ans[s][1]==0:
                    if p[1]==0:
                        ans[s][0]=0
                    else:
                        ans[s][0]=1
                    sub.append(s)
                    ans[s][1]=1
        else:
            for p in  hen[x]:
                s=p[0]
                t=p[1]
                if ans[s][1]==0:
                    if p[1]==0:
                        ans[s][0]=1
                    else:
                        ans[s][0]=0
                    sub.append(s)
                    ans[s][1]=1
        if q==[]:
            q=sub
            sub=[]
            break
ans[0]=100
ans.remove(100)
for i in range(0,N):
    print(ans[i][0])

### FIXED CODE ###

import heapq as h

N=int(input())
u=[0 for i in range(0,N-1)]
v=[0 for i in range(0,N-1)]
w=[0 for i in range(0,N-1)]
for i in range(0,N-1):
    u[i],v[i],w[i]=map(int,input().split())
w=[w[i]%2 for i in range(0,N-1)]
hen=[[] for i in range(0,N+1)]
for i in range(0,N-1):
    hen[u[i]].append([v[i],w[i]])
    hen[v[i]].append([u[i],w[i]])
ans=[[0,0] for i in range(0,N+1)]
ans[1]=[0,1]
q=[]
q.append(1)
h.heapify(q)
sub=[]
h.heapify(sub)
while q!=[]:
    while q!=[]:
        x=h.heappop(q)
        if ans[x][0]==0:
            for p in hen[x]:
                s=p[0]
                t=p[1]
                if ans[s][1]==0:
                    if p[1]==0:
                        ans[s][0]=0
                    else:
                        ans[s][0]=1
                    h.heappush(sub,s)
                    ans[s][1]=1
        else:
            for p in  hen[x]:
                s=p[0]
                t=p[1]
                if ans[s][1]==0:
                    if p[1]==0:
                        ans[s][0]=1
                    else:
                        ans[s][0]=0
                    h.heappush(sub,s)
                    ans[s][1]=1
        if q==[]:
            q=sub
            sub=[]
            h.heapify(sub)
            break
ans[0]=100
ans.remove(100)
for i in range(0,N):
    print(ans[i][0])
### BUGGY CODE ###

def dijkstra(n):
    inf = 10 ** 6 + 1
    dist = [0] + [inf] * (n - 1)
    visited = [False] * n

    while not all(visited):
        dmin = inf
        for i, (d, v) in enumerate(zip(dist, visited)):
            if v:
                continue
            elif dmin > d:
                dmin, u = d, i
        visited[u] = True
        for (v, c) in edge[u]:
            if dist[v] > dist[u] + c:
                dist[v] = dist[u] + c
    return dist

n = int(input())
edge = [[]] * n
for _ in range(n):
    l = list(map(int, input().split()))
    edge[l[0]] = (e for e in zip(l[2::2], l[3::2]))
for i, c in enumerate(dijkstra(n)):
    print(i, c)

### FIXED CODE ###

import heapq


def dijkstra(n):
    inf = 10 ** 6 + 1
    dist = [0] + [inf] * (n - 1)
    q = [(0, 0)]
    while q:
        u = heapq.heappop(q)[1]
        for (v, c) in edge[u]:
            alt = dist[u] + c
            if dist[v] > alt:
                dist[v] = alt
                heapq.heappush(q, (alt, v))
    return dist

n = int(input())
edge = [[]] * n
for _ in range(n):
    l = list(map(int, input().split()))
    edge[l[0]] = (e for e in zip(l[2::2], l[3::2]))
for i, c in enumerate(dijkstra(n)):
    print(i, c)
### BUGGY CODE ###

n, m = map(int, input().split())
p = [0] * m
y = [0] * m

for i in range(m):
    p[i], y[i] = map(int, input().split())

arr = [[] * n for i in range(n)]
for i in range(m):
    arr[p[i]-1].append(y[i])

for i in range(len(arr)):
    arr[i].sort()


for i in range(m):
    tmp = arr[p[i]-1]
    index = 1
    for l in tmp:
        if l == y[i]:
            break
        else:
            index += 1
    s_p = str(p[i]).zfill(6)
    y_p = str(index).zfill(6)
    print(s_p + y_p)


### FIXED CODE ###

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

arr = [[] for _ in range(n)] 

p = [0] * m
y = [0] * m

for i in range(m):
    p[i], y[i] = map(int, input().split())
    arr[p[i]-1].append(y[i])    

for i in range(n):
    arr[i].sort()

import bisect
for i in range(m):
    num = bisect.bisect_left(arr[p[i]-1], y[i]) + 1
    a = str(p[i])
    b = str(num)
    print(a.zfill(6) + b.zfill(6))
### BUGGY CODE ###

N,A,B = map(int,input().split())
h = [0]*N
for i in range(N):
    h[i] = int(input())

# x回で全モンスター倒せるかどうかをにぶちゃん(にぱー)

left = 0
right = 10**10

def check(x):
    for i in range(N):
        res = h[i] - B*x
        if res >= (A-B)*x:
            return False
    return True

while abs(right-left) > 1:
    center = (right+left)//2
    
    if check(center) == True:
        right = center
    elif check(center) == False:
        left == center
        
print(center)

### FIXED CODE ###

N,A,B = map(int,input().split())
h = [0]*N
for i in range(N):
    h[i] = int(input())

# x回で全モンスター倒せるかどうかをにぶちゃん(にぱー)

import math

def check(x):
    count = 0
    for i in range(N):
        count += math.ceil(max(h[i] - B * x, 0) / (A - B))
           
    if count <= x:
        return True
    else:
        return False
    
def solve():
    
    left = -1
    right = 10**9+1
    
    while abs(right-left) > 1:
    
        center = (right+left)//2
    
        if check(center) == True:
            right = center
        elif check(center) == False:
            left = center
        
    return right
    
print(solve())
### BUGGY CODE ###

a, b, x = map(int,input().split())

count = 0
first = 0
for i in range(a, b+1):
#    print(i)
    if i%x == 0:
        first = i
        count = 1
        break
    
if count != 0:
    result  = (b-first) // x +1

else :
    result = 0


print(result)





### FIXED CODE ###

a, b, x = map(int,input().split())



## ことごとくTLEする件
# forを回すからだめなのかも→回さないですませるには？
# bまでに約数いくつあるか出す → a-1 までに約数いくつあるか出す→引き算



## まず、aが割り切れるかどうか判定
## aが割り切れるなら、最小値はa
## 割り切れないなら、a+（除数 - あまり ) が最小値

#### divmodを使ってみよう！！


result = 0

a_x = divmod(a,x)  ## a/x の商と余り
## a = x * a_x[0] + a_x[1]
if a_x[1]==0:  ## 割り切れるとき
    first = a
else:  ## 割り切れないとき
    first = x * (a_x[0]+1)
    first2 = a + (x - a_x[1])  ## 検算用


b_x = divmod(b-first, x)

result = b_x[0]+1

print(result)






"""
名答だと思ったがだめだった

count = 0
first = 0
for i in range(a, b+1):
#    print(i)
    if i%x == 0:
        first = i
        count = 1
        break
    
if count != 0:
    result  = (b-first) // x +1

else :
    result = 0


print(result)



"""
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
count = 0
x = -1
for i in range(1,N+1):
  if i in A[x+1:]:
    x = A[x+1:].index(i)
    count += 1
  else:
    break
if count != 0:
  print(N-count)
else:
  print(-1)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
count = 0
x = -1
num = 1
for i in range(N):
  if A[i] == num:
    count += 1
    num += 1
if count != 0:
  print(N-count)
else:
  print(-1)
### BUGGY CODE ###

import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)
INF=10 ** 10
N = int(input())
XL = sorted([list(map(int,input().split())) for _ in range(N)])
# print(N,XL)

DP = [ INF for _ in range(N+1)]
DP[0] = -INF
for i in range(N):
    #print(DP)
    (x,l) = XL[i]
    # print(x,l)
    for j in range(1,N+1):
        if DP[j-1] > x -l:
            break
        if ( DP[j-1]<= x -l and x + l < DP[j]):
                DP[j] = x + l
#print(DP)
for i in range(2,N+1):
    if DP[i] == INF:
        print(i-1)
        exit(0)
print(N)



### FIXED CODE ###

import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)
INF=10 ** 10
N = int(input())
XL = [list(map(int,input().split())) for _ in range(N)]
XLs =sorted([ [xl[0]+xl[1],xl[0]-xl[1]] for xl in XL ])
# print(N,XL,XLs)

t = -INF 
n = 0

for xl in XLs:
    if t <= xl[1]:
        t = xl[0]
        n = n + 1
print(n)
### BUGGY CODE ###

from collections import defaultdict
d=defaultdict(int)
N=int(input())
L=[]
for _ in range(N):
 s=input()
 d[s]+=1
for k, v in d.items():
 if v == max(d.values()):
  L.append(k)
L.sort()
for i in L:
 print(i)

### FIXED CODE ###

n=int(input())
arr=[input() for _ in range(n)]
dic={}
for i in range(n): #各単語の出現回数を数える
 if arr[i] not in dic:
   dic[arr[i]]=1
 else:
   dic[arr[i]]+=1
largest=max(dic.values()) #最大の出現回数を求める
ans=[]
for keys in dic.keys():
 if dic[keys]==largest: #出現回数が最も多い単語を集計する
   ans.append(keys)
ans=sorted(ans) #単語を辞書順に並べ替えて出力する
for words in ans:
 print(words)
### BUGGY CODE ###

def cmb(a,b):
    b = min(b,a-b)
    num = 1
    for i in range(b):
        num = num*(a-i)
    den = 1
    for i in range(b):
        den = den*(i+1) 
    return num // den 

mod = 10**9+7
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
c = cmb(n-1,k-1)
if k == 1:
    print(0)
    exit()
for i in range(n-k+1):
    ans -= a[i] * c
    ans += a[-i-1] * c
    ans %= mod
    c = c*(n-k-i)//(n-i-1)
if ans < 0:
    ans += mod
print(ans)

### FIXED CODE ###

def cmb(a,b,c):
    b = min(b,a-b)
    num = 1
    for i in range(b):
        num = num*(a-i) % c
    den = 1
    for i in range(b):
        den = den*(i+1) % c
    return num * pow(den,c-2,c) % c
mod = 10**9 + 7
n,k = map(int,input().split())
inv = [0,1]
for i in range(2,n):
  inv += [inv[mod % i]*(mod - mod//i) % mod]
a = list(map(int,input().split()))
a.sort()
ans = 0
c = 1
x = 1
if k == 1:
    print(0)
    exit()
for i in range(n-k+1):
    ans -= a[n-k-i] * c
    ans += a[k+i-n-1] * c
    ans %= mod
    c = c*(i+k)*inv[i+1] % mod
if ans < 0:
    ans += mod
print(ans)
### BUGGY CODE ###

s = int(input())
start = 1

x1, y1, x2, y2, x3, y3 = 0, 0, 0, 0, 0, 0

while True:
    if s >= 10e9:
        start = s//2

    for i in range(start, int(s**0.5)+1):
        if s % i == 0 and i <= 10e9 and s % i <= 10e9:
            x2 = i - x1
            y3 = s//i - y1
        break

    if x2 == 0 and y3 == 0:
        x1 += 1
        y1 += 1
        continue
    break

print(x1, y1, x2, y2, x3, y3)


### FIXED CODE ###

s = int(input())

e = 10**9
if s == e**2:
    print(0, 0, e, 1, 0, e)
else:
    y = s//e + 1
    x = y*e - s
    print(0, 0, e, 1, x, y)
### BUGGY CODE ###

N, K = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort()

counter = 0
array1 = []

for i in range(N):
  for j in range(ab[i][1]):
    array1.append(ab[i][0])
    if len(array1) >= K:
      break
    
print(array1[K-1])

### FIXED CODE ###

N, K = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort()

counter = 0
array1 = []

for i in range(N):
  counter += ab[i][1]
  if K <= counter:
    ans = ab[i][0]
    break

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

n = int(input())
v = list(map(int,input().split()))
odd = v[::2 ]
even = v[1::2]
def count(aaa):
    if len(set(aaa))!=1:
        aaa_min = min(aaa, key=aaa.count)
    else:
        aaa_min = 0
    return int(aaa_min)
if len(set(v))==1:
    print(int(n/2))
else:
    even_min = count(even)
    odd_min = count(odd)
    print(even_min+odd_min)

### FIXED CODE ###

from collections import Counter
 
n = int(input())
v = list(map(int,input().split()))
ac = Counter(v[::2]).most_common(2)
bc = Counter(v[1::2]).most_common(2)


if ac[0][0] != bc[0][0]:           
    ans =  n - ac[0][1] - bc[0][1] 
else:                               
    if len(bc) == 1 or len(ac) == 1:
        ans = n // 2
    else: 
        ans = n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])
print(ans)
### BUGGY CODE ###

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

hats = A[:]

from collections import defaultdict
d = defaultdict(lambda: {})

for i, h1 in enumerate(hats):
    hats2 = hats[i+1:]
    for j, h2 in enumerate(hats2):
        h3 = h1^h2
        d[h1][h3] = h2
        d[h3][h1] = h2

#print(d)
        
def dfs(top, now1, now2, count):
    if now2 == top:
        #print(count)
        if count == N:
            return True
        else:
            return False

    if d[d[now1][now2]] == {}:
        return False
    
    now1, now2 = now2, now2 ^ d[now1][now2]

    return dfs(top, now1, now2, count+1)
    
ans = False
h1 = hats[0]
for h2 in d[h1]:
    if dfs(h1, h1, h2, 2):
        ans = True
        break
        
if ans:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

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

hats = A[:]
import copy
from collections import defaultdict
d = defaultdict(lambda: 0)

for h in hats:
    d[h] += 1

def f():
    if len(d) == 3:
        xor = 0
        for key in d:
            xor ^= key
        if xor == 0:
            lsit_d = list(d.keys())
            if d[lsit_d [0]] == d[lsit_d [1]] and d[lsit_d [0]] == d[lsit_d [2]]:
                return 'Yes'
            else:
                return 'No'
        else:
            return 'No'

    if len(d) == 1:
        lsit_d = list(d.keys())
        if lsit_d [0] == 0:
            return 'Yes'
        
    if len(d) == 2:
        if d[0] * 2 == N - d[0]:
            return 'Yes'
    
    return 'No'
    
print(f())
### BUGGY CODE ###

h,w,m = map(int,input().split())
hw = [list(map(int,input().split()))for _ in range(m)]

tate = [0]*(h+1)
yoko = [0]*(w+1)

for x,y in hw:
    tate[x] += 1
    yoko[y] += 1

ans_x = []
ans_y = []
x_max = max(tate)
y_max = max(yoko)
for i in range(len(tate)):
    if tate[i] == x_max:
        ans_x.append(i)
for i in range(len(yoko)):
    if yoko[i] == y_max:
        ans_y.append(i)

ans = x_max + y_max
for x in ans_x:
    for y in ans_y:
        if [x,y] not in hw:
            print(ans)
            exit()
print(ans - 1)

### FIXED CODE ###

import sys
input = sys.stdin.readline
h,w,m = map(int,input().rstrip().split())
hw = [list(map(int,input().rstrip().split()))for _ in range(m)]

tate = [0]*(h+1)
yoko = [0]*(w+1)
bombpoint = set()

for x,y in hw:
    tate[x] += 1
    yoko[y] += 1
    bombpoint.add((x,y))

ans_x = []
ans_y = []
x_max = max(tate)
y_max = max(yoko)
for i in range(len(tate)):
    if tate[i] == x_max:
        ans_x.append(i)
for i in range(len(yoko)):
    if yoko[i] == y_max:
        ans_y.append(i)

ans = x_max + y_max
for x in ans_x:
    for y in ans_y:
        if (x,y) not in bombpoint:
            print(ans)
            exit()
print(ans - 1)
### BUGGY CODE ###

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

ans = 0
for i in range(0,n):
    for j in range(0,i+1):
        if p[i] > p[j]:
            break
        elif j == i:
            ans += 1
print(ans)

### FIXED CODE ###

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

ans = 0
n_min = 0
for i in range(0,n):
    if i == 0:
        ans += 1
        n_min = p[i]
        continue
    if p[i] <= n_min:
        ans += 1
        n_min = p[i]
print(ans)
### BUGGY CODE ###

N,M = map(int,input().split())
H = []
for i in range(M):
  H.append(int(input()))

dp = [0]*(N+1) # 初期条件
dp[0] = 1
dp[1] = 0 if 1 in H else 1
for i in range(2,N+1):
      if i in H:
        dp[i] = 0
      else:
        dp[i] = (dp[i-1]+dp[i-2])%1000000007

print(dp[-1])

### FIXED CODE ###

mod = 10**9+7
n,m = map(int,input().split())
a = set()
for i in range(m):
  a.add(int(input()))
dp = [0]*(n+1)
dp[0] = 1
for i in range(1,n+1) :
    dp[i] = (dp[i-1] + dp[i-2]) % mod
    if i in a :
        dp[i] = 0
print(dp[n])
### BUGGY CODE ###

N = int(input())

A = [int(x) for x in input().split()]

a = 0
while a < N:  
  B = sorted(A[:a]+A[a+1:])
  a += 1
  print(B[(N-1)//2])

### FIXED CODE ###

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

B = sorted(A)
 
for i in range(N):  
  if A[i] < B[N//2]:
    print(B[N//2])
  else:
    print(B[N//2-1])
### BUGGY CODE ###

#入力高速化 + 再帰回数制限解除
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10000000)
#ダイクストラ
#単一始点最短経路(正の辺のみ)
#s=始点 n=頂点数 edgeは隣接リスト(edge=[[[1,2],[2,4]],[[2,1]],[]])
#0-indexed
from heapq import heappop,heappush
def dijkstra(s,n,edge):
  inf=10**16
  ans=[inf]*n
  ans[s]=0
  h=[[0,s]]
  while h:
    c,v=heappop(h)
    if ans[v]<c:continue
    for u,t in edge[v]:
      if c+t<ans[u]:
        ans[u]=c+t
        heappush(h,[c+t,u])
  return ans
#solve
n,m,s,t=map(int,input().split())
s-=1
t-=1
yen_edge=[[]for _ in range(n)]
snuuk_edge=[[]for _ in range(n)]
for _ in range(m):
  u,v,a,b=map(int,input().split())
  u-=1
  v-=1
  yen_edge[u].append([v,a])
  yen_edge[v].append([u,a])
  snuuk_edge[u].append([v,b])
  snuuk_edge[v].append([u,b])
yen=dijkstra(s,n,yen_edge)
snuuk=dijkstra(t,n,snuuk_edge)
ans=[yen[i]+snuuk[i] for i in range(n)]
for i in range(n-1,0,-1):ans[i-1]=min(ans[i],ans[i-1])
for i in ans:print(10**15-i)

### FIXED CODE ###

#入力高速化 + 再帰回数制限解除
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10000000)
#ダイクストラ
#単一始点最短経路(正の辺のみ)
#s=始点 n=頂点数 edgeは隣接リスト(edge=[[[1,2],[2,4]],[[2,1]],[]])
#0-indexed
from heapq import heappop,heappush
def dijkstra(s,n,edge):
  inf=10**16
  ans=[inf]*n
  ans[s]=0
  h=[[0,s]]
  while h:
    c,v=heappop(h)
    if ans[v]<c:continue
    for u,t in edge[v]:
      if c+t<ans[u]:
        ans[u]=c+t
        heappush(h,[c+t,u])
  return ans
#solve
n,m,s,t=map(int,input().split())
s-=1
t-=1
yen_edge=[[]for _ in range(n)]
snuuk_edge=[[]for _ in range(n)]
for _ in range(m):
  u,v,a,b=map(int,input().split())
  u-=1
  v-=1
  yen_edge[u].append([v,a])
  yen_edge[v].append([u,a])
  snuuk_edge[u].append([v,b])
  snuuk_edge[v].append([u,b])
yen=dijkstra(s,n,yen_edge)
snuuk=dijkstra(t,n,snuuk_edge)
ans=[10**15-(yen[i]+snuuk[i])for i in range(n)]
for i in range(n-2,-1,-1):ans[i]=max(ans[i],ans[i+1])
for i in ans:print(i)
### BUGGY CODE ###

q = int(input())
like2017 = []

def is_prime(x):
    if x==2:
        return True
    elif x%2==0:
        return False

    for i in range(3, x, 2):
        if x!=i and x%i==0:
            return False
    return True

for i in range(1, 10001):
    if i>2 and is_prime(i) and is_prime(int((i+1)/2)):
        like2017.append(1)
    else:
        like2017.append(0)

for i in range(q):
    l, r = map(int, input().split())
    print(sum(like2017[:r])-sum(like2017[:l-1]))


### FIXED CODE ###

import numpy as np
n=123456
q = int(input())
 
is_prime = np.ones(n+1,dtype=int)
is_prime[0]=0
is_prime[1]=0
 
for i in range(2,n+1):
    if(is_prime[i]==1):
        j=i+i
        while j <= n:
            is_prime[j] = 0
            j += i
 
cnt = [is_prime[x]*is_prime[(x+1)//2] for x in range(0,n+1)]
 
for i in range(1,n+1):
    cnt[i]+=cnt[i-1]
 
for i in range(q):
    l,r = map(int, input().split())
    print(cnt[r]-cnt[l-1])
### BUGGY CODE ###

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

l = []
X = sum(a)
for i in range(N-1):
	x = sum(a[:i+1])
	l.append(abs(X - 2 * x))

print(min(l))

### FIXED CODE ###

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

X = sum(a)
x = 0
ans = 10**100

for i in range(N-1):
	x += a[i]
	ans = min(ans,abs(X - 2 * x))
    
print(ans)