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

import bisect


def make_divisors(n):
    lower_divisors, upper_divisors = set(), set()
    tmp = 1
    while tmp * tmp <= n:
        if n % tmp == 0:
            lower_divisors.add(tmp)
            if tmp != n // tmp:
                upper_divisors.add(n // tmp)
        tmp += 1
    return lower_divisors | upper_divisors


n = int(input())
*A, = map(int, input().split())
A.sort()
setA = set(A)
cnt = 0
for i, a in enumerate(A):
    if bisect.bisect_right(A, a) - bisect.bisect_left(A, a) != 1:
        cnt += 1
        continue
    X = make_divisors(a)
    for x in X:
        if x != a and bisect.bisect_right(
                A, x, hi=i) - bisect.bisect_left(A, x, hi=i) != 0:
            cnt += 1
            break
print(n - cnt)


### FIXED CODE ###

n = int(input())
*A, = map(int, input().split())
maxA = max(A)
# C[a] = A内のaの個数
C = {a: 0 for a in range(1, maxA + 1)}
for a in A:
    C[a] += 1
# D[a]=1: Aにaより小さいaの約数が存在する
D = {a: 0 for a in range(1, maxA + 1)}
for a in A:
    if C[a] > 0:
        tmp = 2
        while a * tmp <= maxA:
            D[a * tmp] = 1
            tmp += 1
ans = 0
for a in A:
    if C[a] == 1 and D[a] == 0:
        ans += 1
print(ans)
### BUGGY CODE ###

h,w,m=map(int,input().split())
bomb_h = [0]*h
bomb_w = [0]*w
place = [[0 for _ in range(w)] for _ in range(h)]
for _ in range(m):
  x,y=map(int,input().split())
  bomb_h[x-1]+=1
  bomb_w[y-1]+=1
  place[x-1][y-1] = 1
x_cand = list()
x_max = 0
for x in range(h):
  if x_max < bomb_h[x]:
    x_cand = [x]
    x_max = bomb_h[x]
  elif x_max == bomb_h[x]:
    x_cand.append(x)
y_cand = list()
y_max = 0
for y in range(w):
  if y_max < bomb_w[y]:
    y_cand = [y]
    y_max = bomb_w[y]
  elif y_max == bomb_w[y]:
    y_cand.append(y)
ans = 0
for x in x_cand:
  for y in y_cand:
    ans = max(ans, x_max+y_max-place[x][y])
    
print(ans)

### FIXED CODE ###

import sys
h,w,m=map(int,input().split())
bomb_h = [0]*h
bomb_w = [0]*w
place = list()
#O(m)
for _ in range(m):
  x,y=map(int,input().split())
  bomb_h[x-1]+=1
  bomb_w[y-1]+=1
  place.append([x-1,y-1])
x_cand = list()
x_max = 0
#O(H)
for x in range(h):
  if x_max < bomb_h[x]:
    x_cand = [x]
    x_max = bomb_h[x]
  elif x_max == bomb_h[x]:
    x_cand.append(x)
y_cand = list()
y_max = 0
#O(W)
for y in range(w):
  if y_max < bomb_w[y]:
    y_cand = [y]
    y_max = bomb_w[y]
  elif y_max == bomb_w[y]:
    y_cand.append(y)
ans = x_max+y_max
# ここまで10^6
cnt = 0
#O(M)
for p in place:
  if bomb_h[p[0]]== x_max and bomb_w[p[1]]==y_max:
    cnt += 1
if len(x_cand)*len(y_cand) > cnt:
  print(ans)
else:
  print(ans-1)
### BUGGY CODE ###

n = int(input())
num = list(map(int, (input().split(' '))))

ans = 1
for i in range(n):
  ans *= num[i]
  
if ans <= 10**18:
  print(ans) 
else:
  print('-1')

### FIXED CODE ###

n = int(input())
num = list(map(int, (input().split(' '))))

flag = 1
if 0 in num:
  print(0)
  flag=0

if flag == 1:  
  ans = 1
  for i in range(n):
    if flag == 1:
      ans *= num[i]
      if ans > 10**18:
        flag = 0
        print('-1')
        break

if flag==1:
  print(ans)
### BUGGY CODE ###

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

cnt = 0
for i in range(a, b+1):
    if i % x == 0:
         cnt += 1
print(cnt)

### FIXED CODE ###

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

result = b // x - ~-a // x
print(result)
# result = [i % x for i in range(a, b + 1)].count(0)
# print(result)
### BUGGY CODE ###

n=int(input())

score=[]
ans=0

for _ in range(n):
    s=int(input())
    score.append(s)

# if score%10==0:
#     ans=0

# score=sorted(score,reverse=True)
# for _ in range(n):
#     score.pop()
#     tmp=sum(score)
#     if tmp%10==0:
#         tmp=0

#     ans=max(ans,tmp)

from itertools import combinations 

for m in range(1,n+1):
    c=combinations(score,m)

    for i in c:
        tmp=sum(i)
        if tmp%10==0:
            tmp=0

        ans=max(ans,tmp)

print(ans)
    

### FIXED CODE ###

n=int(input())

score=[]
for _ in range(n):
    s=int(input())
    score.append(s)

#すべて10の倍数ならば0である
non10=[]
flg10=0
for i in range(n):
    if score[i]%10!=0:
        non10.append(score[i])
        flg10=1
    
if flg10==0:
    ans=0
else:
    if sum(score)%10==0:
        ans=sum(score)-min(non10)
    else:
        ans=sum(score)
print(ans)
### BUGGY CODE ###

import collections
s = input()
r = []
for i in range(len(s)):
  r.append(int(s[i:])%2019)
d = collections.Counter(r) 
ans = 0
if 0 in d:
  ans += d[0]
for k,v in d.items():
  if v >= 2:
    ans += v*(v-1)//2
print(ans)


### FIXED CODE ###

s = list(map(int,input()))
d = [0 for _ in range(2019)]
r = 0
x = 1
for si in reversed(s):
  r += si*x
  r %= 2019
  d[r] += 1
  x *= 10
  x %= 2019
ans = d[0]
for v in d:
  if v >= 2:
    ans += v*(v-1)//2
print(ans)
### BUGGY CODE ###

from collections import deque


def solve():
    N, Q = map(int, input().split())
    ab = [[0, 0] for _ in range(N-1)]
    for i in range(N-1):
        ab[i] = list(map(int, input().split()))
    px = [[0, 0] for _ in range(Q)]
    for i in range(Q):
        px[i] = list(map(int, input().split()))

    graph = [[] for _ in range(N+1)]
    for a, b in ab:
        graph[a].append(b)
        graph[b].append(a)

    val = [0 for _ in range(N+1)]
    for p, x in px:
        val[p] += x

    que = deque([1])
    parent = [0 for _ in range(N+1)]
    while que:
        i = que.popleft()
        for j in graph[i]:
            if j == parent[i]:
                continue
            parent[j] = i
            que.append(j)
            val[j] += val[i]

    print(*val[1:])


if __name__ == '__main__':
    solve()

### FIXED CODE ###

from collections import deque


def solve():
    N, Q = map(int, input().split())
    ab = [[0, 0] for _ in range(N-1)]
    for i in range(N-1):
        ab[i] = list(map(int, input().split()))
    px = [[0, 0] for _ in range(Q)]
    for i in range(Q):
        px[i] = list(map(int, input().split()))

    graph = [[] for _ in range(N+1)]
    for a, b in ab:
        graph[a].append(b)
        graph[b].append(a)

    val = [0 for _ in range(N+1)]
    for p, x in px:
        val[p] += x

    que = deque([1])
    parent = [0 for _ in range(N+1)]
    while que:
        i = que.popleft()
        for j in graph[i]:
            if j == parent[i]:
                continue
            parent[j] = i
            que.append(j)
            val[j] += val[i]

    print(*val[1:])


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

N = int(input())
A = [int(input()) for _ in range(N)]
sorted_A = sorted(A)

for i in A:
  array = sorted_A.copy()
  array.remove(i)
  print(array[-1])

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
sorted_A = sorted(A)

for i in A:
  if i == sorted_A[-1]:
    print(sorted_A[-2])
  else: 
    print(sorted_A[-1])
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split())) # 横入力

b = [0]
aaa = 0
for i in range(n):
    aaa += a[i]
    b.append(aaa)

ans = 202020202020
for i in range(n):
    ans = min(ans, abs(sum(a) - b[i]*2))
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split())) # 横入力

x = [0]
aaa = 0
for i in range(n):
    aaa += a[i]
    x.append(aaa)
aa = sum(a)
y = [aa]
for i in range(n):
    aa -= a[i]
    y.append(aa)

ans = 202020202020
for i in range(n+1):
    ans = min(ans, abs(x[i] - y[i]))

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

N=int(input())
A=[list(map(int, input().split())) for _ in range(N)]
A.insert(0,[0]*(N-1))
day=0
fin=[0]*(N+1)
no_match=True
impossible=False
while sum(fin) < N:
  no_match=True
  fighter=[False]*(N+1)
  for i in range(1,N+1):
    if fin[i]==1:
      continue
    f=A[i][0]
    if fighter[i] or fighter[f]:
      continue
    if A[f][0]==i:
      no_match=False
      fighter[i]=True
      fighter[f]=True
      A[i]=A[i][1:]
      A[f]=A[f][1:]
      if len(A[i])==0:
        fin[i]=1
      if len(A[f])==0:
        fin[f]=1
  if no_match:
    impossible=True
    break
  day+=1
if impossible:
  print(-1)
else:
  print(day)
      

### FIXED CODE ###

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
    for j in range(n-1):
        a[i][j] -= 1

MAXN = 1005
MAXV = MAXN*(MAXN-1)//2

to = [[] for _ in range(MAXV)]
# 頂点番号
id = [[0 for _ in range(MAXN)] for _ in range(MAXN)]
def toID(i, j):
    if i > j:
        i, j = j, i
    return id[i][j]

# 頂点番号のラベリング
V = 0
for i in range(n):
    for j in range(n):
        if i < j:
            id[i][j] += V
            V += 1

# aを、頂点番号に書き換え、試合の依存関係を表す辺を張る(辺の向きは逆にする)
for i in range(n):
    for j in range(n-1):
        a[i][j] = toID(i, a[i][j])
    for j in range(n-2):
        to[a[i][j+1]].append(a[i][j])

# dfsする
visited = [False for _ in range(MAXV)]
calculated = [False for _ in range(MAXV)] # loop 検出用
dp = [0 for _ in range(MAXV)] # max length of path from v
def dfs(v):
    if visited[v]:
        if not calculated[v]:
            return -1
        return dp[v]
    visited[v] = True
    dp[v] = 1
    for u in to[v]:
        res = dfs(u)
        if res == -1:
            return -1
        dp[v] = max(dp[v], res+1)
    calculated[v] = True
    return dp[v]

ans = 0
ok = True
for i in range(V):
    res = dfs(i)
    if res == -1:
        ok = False
        break
    ans = max(ans, res)
if ok:
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

def popcnt(n):
    c = (n & 0x5555) + ((n>>1) & 0x5555)
    c = (c & 0x3333) + ((c>>2) & 0x3333)
    c = (c & 0x0f0f) + ((c>>4) & 0x0f0f)
    c = (c & 0x00ff) + ((c>>8) & 0x00ff)
    return c

N = int(input())
X = []
Y = []
P = []
for _ in range(N):
    x, y, p = map(int, input().split())
    X.append(x)
    Y.append(y)
    P.append(p)

DX = [[0] * (1 << N) for _ in range(N)]
DY = [[0] * (1 << N) for _ in range(N)]

for i, x in enumerate(X):
    for k in range(1 << N):
        d = abs(x)
        for j, xx in enumerate(X):
            if k & (1 << j):
                d = min(d, abs(xx - x))
        DX[i][k] = d * P[i]
for i, y in enumerate(Y):
    for k in range(1 << N):
        d = abs(y)
        for j, yy in enumerate(Y):
            if k & (1 << j):
                d = min(d, abs(yy - y))
        DY[i][k] = d * P[i]

ANS = [1 << 100] * (N + 1)

for i in range(1 << N):
    m = i ^ ((1 << N) - 1)
    j = m
    while 1:
        ans = 0
        for k in range(N):
            ans += min(DX[k][i], DY[k][j])
        
        pc = popcnt(i) + popcnt(j)
        ANS[pc] = min(ANS[pc], ans)
        
        if not j:
            break
        j = m & (j - 1)

print(*ANS, sep = "\n")

### FIXED CODE ###

N = int(input())
X = []
Y = []
P = []
for _ in range(N):
    x, y, p = map(int, input().split())
    X.append(x)
    Y.append(y)
    P.append(p)

DX = [[0] * (1 << N) for _ in range(N)]
DY = [[0] * (1 << N) for _ in range(N)]

for i, x in enumerate(X):
    for k in range(1 << N):
        d = abs(x)
        for j, xx in enumerate(X):
            if k & (1 << j):
                d = min(d, abs(xx - x))
        DX[i][k] = d * P[i]
for i, y in enumerate(Y):
    for k in range(1 << N):
        d = abs(y)
        for j, yy in enumerate(Y):
            if k & (1 << j):
                d = min(d, abs(yy - y))
        DY[i][k] = d * P[i]

ANS = [1 << 100] * (N + 1)
PC = [0] * (1 << N)
for i in range(1, 1 << N):
    j = i ^ (i & (-i))
    PC[i] = PC[j] + 1

RA = []
for i in range(1 << N):
    t = []
    for j in range(N):
        if i & (1 << j):
            t.append(j)
    RA.append(tuple(t))


mm = (1 << N) - 1
for i in range(1 << N):
    m = i ^ mm
    j = m
    while 1:
        ans = 0
        for k in RA[i^j^mm]:
            ans += min(DX[k][i], DY[k][j])
        
        pc = PC[i] + PC[j]
        ANS[pc] = min(ANS[pc], ans)
        
        if not j:
            break
        j = m & (j - 1)

print(*ANS, sep = "\n")
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
M = 1000000007
ans = 0
for i in range(1,n):
    ans += (A[i-1] * (sum(A[i::])%M))%M
print(ans%M)

### FIXED CODE ###

import sys
input = sys.stdin.readline
M = 1000000007
n = int(input())
A = list(map(int, input().split()))
ans = 0
s = 0
for i in range(n):
    s += A[i]
    s %= M

for i in range(n):
    s = s - A[i]
    if s < 0:
        s += M
    ans += A[i] * s
    ans %= M
print(ans)
### BUGGY CODE ###

n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]

from heapq import heappop, heappush
push = lambda x,i: heappush(BB,(-x,i))
BB=[]

for i in range(n):
  push(B[i],i)

ans=0
while BB:
  b,ind=heappop(BB)
  b,ai=-b,A[ind]
  if b<ai:
    ans=-1
    break
  d=B[(ind-1)%n]+B[(ind+1)%n]
  dd=(b-ai)//d
  if dd==0:
    if b==ai:
      continue
    ans=-1
    break
  ans+=dd
  B[ind]-=d*dd
  push(b-d*dd,ind)
  
print(ans)


### FIXED CODE ###

n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]

from heapq import heappop, heappush
push = lambda x,i: heappush(BB,(-x,i))
BB=[]

for i,b in enumerate(B):
  push(b,i)

ans=0
while BB:
  b,ind=heappop(BB)
  b,ai=-b,A[ind]
  if b<ai:
    ans=-1
    break
  d=B[(ind-1)%n]+B[(ind+1)%n]
  dd=(b-ai)//d
  if dd==0:
    if b==ai:
      continue
    ans=-1
    break
  ans+=dd
  B[ind]-=d*dd
  push(b-d*dd,ind)
  
print(ans)
### BUGGY CODE ###

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

import sys
sys.setrecursionlimit(40000000)

n,q = mi()
b = [[] for i in range(n)]
ans = [0]*n
for i in range(n-1):
    a,c = mi()
    b[a-1].append(c-1)
    b[c-1].append(a-1)


def chil_pop(l):
    for i in b[l]:
        b[i].pop(b[i].index(l))
        chil_pop(i)

chil_pop(0)

def chil_add(z,x):
    ans[z] += x
    for i in b[z]:
        chil_add(i,x)

for i in range(q):
    p,x = mi()
    chil_add(p-1,x)

for i in range(n):
    print(ans[i],end=' ')


### FIXED CODE ###

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

import sys
sys.setrecursionlimit(40000000)

n,q = mi()
b = [[] for i in range(n)]
ans = [0]*n

# O(2n)
for i in range(n-1):
    a,c = mi()
    b[a-1].append(c-1)
    b[c-1].append(a-1)

# jun = []
# O(2n)
# def chil_pop(l,p):
#     jun.append(l)
#     for i in b[l]:
#         if i == p:
#             continue
#         chil_pop(i,l)
#     b[l] = p

# chil_pop(0,-1)


# O(q)
for i in range(q):
    p,x = mi()
    ans[p-1] += x


count = 0
q = [(0,-1)]
while q:
    c,p = q.pop()
    for i in b[c]:
        if i == p:
            continue
        ans[i] += ans[c]
        q.append((i,c))
    
    

# for i in jun[1:]:
#     ans[i] += ans[b[i]]

# ans_str = ''
# for i in range(n):
#     print(ans[i],end=' ')
#     # ans_str = ans_str + str(ans[i]) + ' '
print(*ans)
### BUGGY CODE ###

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

Aset = set(A)
lst = {}
for i in Aset:
    lst[i] = 0
    
for i in range(N):
    lst[A[i]] += 1

Q = int(input())

ans = []
for i in range(Q):
    B, C = map(int, input().split())
    if B in lst:
        if C in lst:
            lst[C] += lst[B]
            lst.pop(B)
        else:
            lst[C] = lst[B]
            lst.pop(B)
            
        ans_tmp = 0
        for i in lst:
            ans_tmp += i*lst[i]

        ans.append(ans_tmp)
        
    elif i != 0:
        ans.append(ans[-1])
    else:
        ans_tmp = 0
        for i in lst:
            ans_tmp += i*lst[i]
        ans.append(ans_tmp)

for i in ans:
    print(i)

### FIXED CODE ###

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

Aset = set(A)
lst = {}
for i in Aset:
    lst[i] = 0
    
for i in range(N):
    lst[A[i]] += 1

Q = int(input())

# 最初の全てのA_iの和
ans_init = 0
for i in lst:
    ans_init += i*lst[i]

# 初期値からのプラスマイナス分
ans_pm = 0
ans = []
for i in range(Q):
    B, C = map(int, input().split())
    if B in lst:
        # 更新する前に、lst中のkeyがBの個数をBnumに記憶しておく。
        Bnum = lst[B]
        # lstを更新
        if C in lst:
            lst[C] += lst[B]
            lst.pop(B)
        else:
            lst[C] = lst[B]
            lst.pop(B)
    
        # 初期値からの増減分をここで算出。
        ans_pm += Bnum*(C-B)
        ans.append(ans_init + ans_pm)
        
    else:
        ans.append(ans_init + ans_pm)

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


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
import math
from collections import *
from functools import reduce,cmp_to_key,lru_cache
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
import sys
# input = sys.stdin.readline



M = mod = 10**9 + 7 
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
 
def li():return [int(i) for i in input().rstrip().split()]
def st():return str(input().rstrip())[2:-1]
def val():return int(input().rstrip())
def li2():return [str(i)[2:-1] for i in input().rstrip().split()]
def li3():return [int(i) for i in st()]
 



sys.setrecursionlimit(10 ** 5 + 10)

g = 0
@lru_cache(None)
def dp(i, par = -1, black = 0):
    global g
    ans = 1

    nokids = 1
    if black:
        for j in g[i]:
            if j != par:
                nokids = 0
                ans = ans * dp(j, i, 0) % mod
    else:
        for j in g[i]:
            if j != par:
                nokids = 0
                ans = ( ans * (dp(j, i, 0) + dp(j, i, 1)) ) % mod

    if nokids:ans = 1
    return ans



n = val()
g = defaultdict(set)

for _ in range(n - 1):
    a, b = li()
    g[a].add(b)
    g[b].add(a)


root = 1
ans = dp(root, -1, 0) + dp(root, -1, 1)

print(ans % mod)

### FIXED CODE ###

from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop,heapify
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

from itertools import accumulate
from functools import lru_cache

M = mod = 10 ** 9 + 7
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
 
def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n')]
def li3():return [int(i) for i in input().rstrip('\n')]
 



sys.setrecursionlimit(10 ** 6)

g = 0
@lru_cache(None)
def dp(i, par = -1, black = 0):
    global g
    ans = 1
    nokids = 1
    if black:
        for j in g[i]:
            if j != par:
                nokids = 0
                ans = ans * dp(j, i, 0) % mod
    else:
        for j in g[i]:
            if j != par:
                nokids = 0
                ans = ( ans * (dp(j, i, 0) + dp(j, i, 1)) ) % mod

    if nokids:ans = 1
    return ans



n = val()
g = [[] for i in range(n + 1)]

l = []
for _ in range(n - 1):
    a, b = li()
    g[a].append(b)
    g[b].append(a)


root = 1    
ans = dp(root, -1, 0) + dp(root, -1, 1)

print(ans % mod)
### BUGGY CODE ###

N = int(input())
S = []
for i in range(N):
    S.append(input())
def check(S, A, B):
    for i in range(N):
        for j in range(N):
            if i + A < N:
                a = i + A
            else:
                a = i + A - N
            if j + B < N:
                b = j + B
            else:
                b = j + B - N
            if j + A < N:
                c = j + A
            else:
                c = j + A - N
            if i + B < N:
                d = i + B
            else:
                d = i + B - N
            if S[a][b] != S[c][d]:
                return False
    return True

cnt = 0
for i in range(N):
    for j in range(N):
        if check(S, i, j):
            cnt += 1
print(cnt)

### FIXED CODE ###

N = int(input())
S = []
for i in range(N):
    S.append(input())

def check(S, A, B):
    for i in range(N):
        for j in range(i+1, N):
            if S[i][j] != S[j][i]:
                return 0
    return 1

cnt = 0
for i in range(N):
    cnt += check(S[i:] + S[:i], 0, i)
print(cnt * N)
### BUGGY CODE ###

from fractions import gcd
k=int(input())
r1=[]
sum=0
for l in range(1,k+1):
    for m in range(1,k+1):
        r1.append(gcd(l,m))

for i in range(len(r1)):
    for j in range(1,k+1):
        sum += gcd(r1[i],j)
print(sum)



### FIXED CODE ###

from fractions import gcd
k=int(input())
l=[]
dp=[[0]*(k+1) for i in range(k+1)]

for i in range(1,k+1):
    for j in range(1,k+1):
        dp[i][j]=gcd(i,j)
        l.append(gcd(i,j))
sum=0
for x in range(1,k+1):
    for y in range(len(l)):
        sum += int(dp[l[y]][x])
print(sum)
### BUGGY CODE ###

N,T=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(N)]
#dp[i][j] 料理iまでの間で、時間jまでに達成できる最大効用
dp=[[0]*(T+1) for _ in range(N+1)]
AB.sort()
for i in range(1,N+1):
  dp[i]=dp[i-1][:]
  time=AB[i-1][0]
  happy=AB[i-1][1]
  for j in range(T):
    dp[i][min(j+time,T)]=max(dp[i][min(j+time,T)],dp[i-1][j]+happy)
print(dp[N][T])
    

### FIXED CODE ###

N,T=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(N)]
#dp[i][j] 料理iまでの間で、時間jまでに達成できる最大効用
dp=[[0]*(T+1) for _ in range(N+1)]
AB.sort()
for i in range(1,N+1):
  dp[i]=dp[i-1][:]
  time=AB[i-1][0]
  happy=AB[i-1][1]
  for j in range(T):
    dp[i][min(j+time,T)]=max(dp[i][min(j+time,T)],dp[i-1][j]+happy)
print(dp[N][T])
### BUGGY CODE ###

s=input()
q=int(input())
l = [list(input().split()) for i in range(q)]
for i in range(q):
  if l[i][0]=="1":
    s=s[::-1]
  elif l[i][1]=="1":
    s=l[i][2]+s
  else:
    s=s+l[i][2]
print(s)

### FIXED CODE ###

from collections import deque
s=deque(list(input()))
q=int(input())
l = [list(input().split()) for i in range(q)]
c=0
for i in range(q):
  if l[i][0]=="1":
    c+=1
  elif c%2==0 and l[i][1]=="1":
    s.appendleft(l[i][2])
  elif c%2==0:
    s.append(l[i][2])
  elif c%2==1 and l[i][1]=="1":
    s.append(l[i][2])
  else:
    s.appendleft(l[i][2])
s=list(s)
if c%2==1:
  s=s[::-1]
print(*s, sep="")
### BUGGY CODE ###

n = int(input())
S = [ input() for _ in range(n) ]

import collections

c = collections.Counter(S)

ls_ans = []
ls_ans.append( c.most_common()[0][0] )

a = c.most_common()[0][1]
for i in range(1,len(c)):
    if c.most_common()[i][1]==a:
        ls_ans.append(c.most_common()[i][0])
    else:
        break
ans = sorted(ls_ans)
print("\n".join(ans))
exit()

### FIXED CODE ###

n = int(input())
S = [ input() for _ in range(n) ]

import collections

c = collections.Counter(S)
b = c.most_common()

ls_ans = []
ls_ans.append( b[0][0] )

a = b[0][1]

for i in range(1,len(b)):
    if b[i][1]==a:
        ls_ans.append(b[i][0])
    else:
        break
ans = sorted(ls_ans)
print("\n".join(ans))
exit()
### BUGGY CODE ###

n = int(input())
x = 0
for i in range(1, n+1):
  if i%3 == 0:
    print(' %d'%i, end="")
  else:
    x = i
while(x):
  if x%10 == 3:
    print(' %d'%i, end="")
    break
    x //= 10
print()


### FIXED CODE ###

N = int(input())
x = 0
 
for i in range(1,N+1):
 
    if i%3 == 0:
            print(" %d"%i,end = "");
    else:
        x = i
        while (x):
            if x%10 == 3:
                print(" %d"%i,end = "")
                break
            x //= 10
print()
### BUGGY CODE ###

import math

x = int(input())


for i in range(1, x+1):
    if x % i == 0:
        for a in range(i//2,x,1):
            b = a - i
            if a**5 - b**5 == x:
                print(a, b)
                break
            elif a**5 - b**5 > x:
                break


### FIXED CODE ###

import math

x = int(input())

divisors = []

for i in range(1, int(x**0.5)+1):
    if x % i == 0:
        divisors.append(i)

        if i != x//i:
            divisors.append(x//i)


for i in divisors:
    for a in range(i//2,x,1):
        b = a - i
        if a**5 - b**5 == x:
            print(a, b)
            break
        elif a**5 - b**5 > x:
            break
### BUGGY CODE ###

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

Sc = list()

for i in range(1, n):
    Sc.append(abs( sum(As[:i]) - sum(As[i:])))

print(min(Sc))

### FIXED CODE ###

import sys

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

Sc = list()

dp = [10**9] * (n-1)
ep = [10**9] * (n-1)
s = sum(As)

if n-2 == 0:
    print(abs(As[0] - As[1]))
    sys.exit()

for i in range(n-2):
    if i == 0:
        dp[i] = As[i]
    else:
        dp[i] = dp[i-1] + As[i]
    ep[i] = abs(dp[i] - s + dp[i])


print(min(ep))