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

import sys
import collections


def r(n, ab):

    s = [(x[0] + x[1])/2 for x in ab]
    
    scr = 0
    sente = True
    for _ in range(n):
        i = s.index(max(s))
        if sente:
            scr += ab[i][0]
        else:
            scr -= ab[i][1]
        del ab[i]
        del s[i]
        sente = not sente

    return scr

def main():
    input = sys.stdin.readline
    n = int(input())
    ab = [tuple(map(int, input().split())) for _ in range(n)]
    print(r(n, ab))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from operator import itemgetter


def r(n, ab):

    ss = [x + [x[0] + x[1]] for x in ab]
    ss.sort(key=itemgetter(2), reverse=True)
    
    scr = 0
    sente = True
    for s in ss:
        if sente:
            scr += s[0]
        else:
            scr -= s[1]
        sente = not sente

    return scr

def main():
    input = sys.stdin.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    print(r(n, ab))


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

import sys
INF=100000000
def frog(i,K,h,dp):
    global INF
    if dp[i]!=INF:
        return dp[i]
    else:
        cost=[]
        for k in range(1,K+1):
            if i-k-1>=0:
                cost.append(frog(i-k,K,h,dp)+abs(h[i-1]-h[i-k-1]))
                continue
            break
        dp[i]=min(cost)
        return dp[i]
sys.setrecursionlimit(INF)
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[INF for i in range(N+1)]
dp[1]=0
dp[2]=abs(h[1]-h[0])
print(frog(N,K,h,dp))


### FIXED CODE ###

import numpy as np
N,K=map(int,input().split())
h=list(map(int,input().split()))
h=np.array(h)
cost=np.zeros(N+1)
cost[1]=0
cost[2]=abs(h[1]-h[0])
for i in range(3,N+1):
    x=1 if i-K<=1 else i-K
    cost[i]=(cost[x:i]+abs(h[i-1]-h[x-1:i-1])).min()
print(int(cost[N]))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10000)

def calc(x,y):
    i = len(x)
    j = len(y)
    if not d[i][j] == None:
        return d[i][j]
    else:
        if x[-1] == y[-1]:
            tmp = calc(x[:-1],y[:-1])+1
            d[i][j] = tmp
            return tmp
        else:
            tmp = max(calc(x[:-1],y),calc(x,y[:-1]))
            d[i][j] = tmp
            return tmp
        
q = int(input())
for i in range(q):
    x = input()
    y = input()
    d = [[0 if i == 0 or j == 0 else None for i in range(len(y)+1)] for j in range(len(x)+1)]
    print(calc(x,y))


### FIXED CODE ###

def calc(x,y):
    n = len(x)
    m = len(y)
    dp1 = [0]*(m+1)
    for i in range(n):
        s = x[i]
        dp2 = dp1[:]
        for j in range(m):
            if s == y[j]:
                dp1[j+1] = dp2[j]+1
            elif dp1[j+1] < dp1[j]:
                dp1[j+1] = dp1[j]
    return dp1[-1]

q = int(input())
for i in range(q):
    x = input()
    y = input()
    print(calc(x,y))
### BUGGY CODE ###

# import math
n = input()
a = list(map(int,input().split()))
re = 1
for i in a :
    re = re * i
if re <= 1000000000000000000:
    print(re)
else:
    print("-1")


### FIXED CODE ###

# import numpy 
n = int(input())
a = list(map(int,input().split()))
re = 1
if 0 in a:
    print("0")
else:
    for i in a :
        re = re * i
        if re > 1000000000000000000:
            print("-1")
            quit()
    print(re)
### BUGGY CODE ###

import sys,math,copy
import numpy as np
input = sys.stdin.readline
S = [int(x) if x != '?' else -1 for x in input().strip()]
N = len(S)

dp = np.zeros((13), dtype=int)
dp_ = np.zeros((13), dtype=int)
mod13_list = [i % 13 for i in range(12 ** 2 + 1)]
dp_[0] = 1
mod = 1
for i, s in enumerate(S[::-1], start=1):
    if s == -1:
        for d in range(10):
            m = mod13_list[(d * mod)]
            for pm in range(13):
                dp[mod13_list[(pm+m)]] = (dp[mod13_list[(pm+m)]] + dp_[pm]) % (10 ** 9 + 7)

    else:
        m = mod13_list[(s * mod)]
        for pm in range(13):
            dp[mod13_list[(pm+m)]] = (dp[mod13_list[(pm+m)]] + dp_[pm]) % (10 ** 9 + 7)
    dp_ = dp
    dp = dp * 0 # np.zeros((13), dtype=int)
    mod = mod13_list[(mod * 10)]
print(dp_[5] % (10 ** 9 + 7))

### FIXED CODE ###

import sys,math,copy

def main():
    # import numpy as np
    input = sys.stdin.readline
    S = ''.join(reversed(input().strip()))

    # dp = np.zeros((13), dtype=int)
    # dp_ = np.zeros((13), dtype=int)
    dp = [0] * 13
    dp_ = [0] * 13
    mod13_list = [i % 13 for i in range(12 ** 2 + 1)]
    list10 = list(range(10))
    list13 = list(range(13))
    divisor = 10 ** 9 + 7
    dp_[0] = 1
    mul = 1
    for i in range(len(S)):
        s = S[i]
        if s == '?':
            for d in list10:
                m = mod13_list[(d * mul)]
                for pm in list13:
                    dp[mod13_list[(pm+m)]] += dp_[pm]

        else:
            si = int(s)
            m = mod13_list[(si * mul)]
            for pm in list13:
                dp[mod13_list[(pm+m)]] = dp_[pm]

        # dp_ = dp % divisor
        # dp = dp * 0 # np.zeros((13), dtype=int)
        for j in list13:
            dp_[j] = dp[j] % divisor
            dp[j] = 0
        mul = mod13_list[(mul * 10)]
    print(dp_[5])

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

import copy
N = int(input())
A = list()
for i in range(N):
    A.append(int(input()))

for j in range(len(A)):
    Ai = copy.copy(A)
    del Ai[j]
    print(max(Ai))

### FIXED CODE ###

import copy
N = int(input())
A = list()
for i in range(N):
    A.append(int(input()))
s = sorted(A)[::-1]
m1 = s[0]
m2 = s[1]

for j in A:
    if j == m1:
        print(m2)
    else:
        print(m1)
### BUGGY CODE ###

H, N = map(int, input().split())
AB = [tuple(map(int, input().split()))for _ in range(N)]
DP = [10**10] * (H+1)
DP[H] = 0
for h in range(H, 0, -1):
    for a, b in AB:
        x = max(0, h - a)
        DP[x] = min(DP[x], DP[h] + b)
print(DP[0])

### FIXED CODE ###

import sys
input=sys.stdin.readline

def main():
    H, N = map(int, input().split())
    AB = [tuple(map(int, input().split()))for _ in range(N)]
    DP = [10**10] * (H+1)
    DP[H] = 0
    for h in range(H, 0, -1):
        for a, b in AB:
            x = max(0, h - a)
            DP[x] = min(DP[x], DP[h] + b)
    print(DP[0])

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

from bisect import *
N, Q = map(int, input().split())
c = 1
B = [1]
while c < 10**9:
    B.append(c+1)
    c = c*N + 1
for q in range(Q):
    v, w = map(int, input().split())
    lv = bisect(B, v)
    lw = bisect(B, w)
    if lv < lw:
        w = (w + (B[lw-lv]-1)*(N-2)) // N**(lw-lv)
    while v != w:
        v = (v - 2 + N) // N
        w = (w - 2 + N) // N
    print(v)


### FIXED CODE ###

from bisect import *
from sys import stdin, stdout
readline = stdin.readline
N, Q = map(int, readline().split())
ans = []
if N == 1:
    for q in range(Q):
        v, w = map(int, readline().split())
        ans.append(str(v))
else:
    c = 1
    B = [1]
    while c < 10**9:
        B.append(c+1)
        c = c*N + 1
    for q in range(Q):
        v, w = map(int, readline().split())
        lv = bisect(B, v)
        lw = bisect(B, w)
        if lv < lw:
            w = (w + (B[lw-lv]-1)*(N-2)) // N**(lw-lv)
        while v != w:
            v = (v + (N - 2)) // N
            w = (w + (N - 2)) // N
        ans.append(str(v))
stdout.write("\n".join(ans))
stdout.write("\n")
### BUGGY CODE ###

from collections import Counter

n = int(input())
cnt = Counter(input().split())
c1, c2, c3 = cnt['1'], cnt['2'], cnt['3']
total = c1 + 2 * c2 + 3 * c3
dp = [[[0] * (n + 2) for _ in range(n + 2)] for _ in range(n + 2)]

for k in range(1, n + 1):
    still = n / k
    for a1 in range(k, max(-1, 2 * k - total - 1), -1):
        dpap, dpac, dpan = dp[a1 - 1], dp[a1], dp[a1 + 1]
        for a2 in range(k - a1, max(-1, 3 * k - 2 * a1 - total - 1), -1):
            a3 = k - a1 - a2
            tmp = 0
            if a1:
                tmp += dpap[a2][a3] * a1
            if a2:
                tmp += dpan[a2 - 1][a3] * a2
            if a3:
                tmp += dpac[a2 + 1][a3 - 1] * a3
            dpac[a2][a3] = tmp / k + still
print(dp[c1][c2][c3])


### FIXED CODE ###

from collections import Counter

n = int(input())
cnt = Counter(input().split())
c1, c2, c3 = cnt['1'], cnt['2'], cnt['3']
total = c1 + 2 * c2 + 3 * c3
c23 = c2 + c3
dp = [[[0.0] * (c3 + 1) for _ in range(c2 + c3 + 1)] for _ in range(n + 2)]

for k in range(1, n + 1):
    still = n / k
    for a1 in range(k, max(-1, 2 * k - total - 1, k - c23 - 1), -1):
        dpap, dpac, dpan = dp[a1 - 1], dp[a1], dp[a1 + 1]
        for a2 in range(min(k - a1, c2 + c3), max(-1, 3 * k - 2 * a1 - total - 1, k - a1 - c3 - 1), -1):
            a3 = k - a1 - a2
            tmp = 0
            if a1:
                tmp += dpap[a2][a3] * a1
            if a2:
                tmp += dpan[a2 - 1][a3] * a2
            if a3:
                tmp += dpac[a2 + 1][a3 - 1] * a3
            dpac[a2][a3] = tmp / k + still
print(dp[c1][c2][c3])
### BUGGY CODE ###

import sys
import numpy as np
import itertools

input = sys.stdin.readline

N,K = map(int, input().split())
lst_A = list(map(int, input().split()))
lst_A.sort()
lst_A = np.array(lst_A)

ans = 0
for i in list(itertools.combinations([j for j in range(N)], K)):
	S = lst_A[list(i)]
	ans += S[-1]-S[0]

print((ans)% 1000000007)

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

N,K = map(int, input().split())
lst_A = list(map(int, input().split()))
lst_A.sort()

p = 10 ** 9 + 7
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)


fmax = 0
fmin = 0
for i in range(N):
	if(K-1<=N-1-i):
		fmin += lst_A[i] * cmb(N-i-1, K-1,p)
	if(i>=K-1):
		fmax += lst_A[i] * cmb(i,K-1,p)

print((fmax-fmin)% p)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    MOD = 10**9 + 7
    
    N = int(input())
    A = list(map(int, input().split()))
    
    import numpy as np
    
    count = np.zeros((N+1, 60, 2), dtype='int')
    
    b = np.zeros(60, dtype='int')
    b[0] = 1
    for i in range(1, 60): b[i] = b[i-1] * 2 % MOD
    
    for i in range(1, N+1):
        count[i] = np.copy(count[i-1])
        a = A[i-1]
        for j in range(60):
            count[i][j][a%2] += 1
            a >>= 1
        
    ans = 0
    
    n = np.zeros(60, dtype='int')
    for i in range(1, N):
        c = count[N]-count[i]
        a = A[i-1]
        for j in range(60):
            n[j] = c[j][0] if a % 2 else c[j][1]
            a >>= 1
        ans = (ans + np.sum(n*b)) % MOD
        
    print(ans)
    
if __name__ == '__main__':
    main()    

### FIXED CODE ###

import sys
input = sys.stdin.readline
import numpy as np

def main():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    ans = 0
    MOD = 10**9+7
    k = 1
    x = np.max(A)
    n = 1 if x == 0 else int(np.log2(x))+1

    for i in range(n):
        c = np.count_nonzero(A%2)
        A >>= 1
        ans = (ans + c * (N-c) * k) % MOD
        k = (2*k) % MOD

    print(ans)

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

N=int(input())
S=list(input())
RS=S[::-1]
#print(RS)
RSS=[]
F=0
W=0
R=0
for i in range(len(RS)):
    if F==0:
        if RS[i]=="R":
            RSS.append("R")
            R+=1
            F=1
    else:
        RSS.append(RS[i])
        if RS[i]=="R":
            R+=1
        else:
            W+=1

SS=RSS[::-1]
#print(SS,R,W)

LW=[]
LR=[]
for i in range(len(SS)):
    if SS[i]=="W":
        LW.append(i)
    else:
        LR.append(i)
LR=LR[::-1]

while len(LW)!=len(LR):
    if len(LW)<len(LR):
        LW.append(10**7)
    else:
        LW.append(-1)
LW.append(10**7)
LR.append(-1)
#print(LW,LR)
for i in range(len(LR)):
    if LW[i]>LR[i]:
        cnt=i
        break
print(min(cnt,W,R))

### FIXED CODE ###

N=int(input())
S=list(input())
RS=S[::-1]
#print(RS)
RSS=[]
F=0
W=0
R=0
for i in range(len(RS)):
    if F==0:
        if RS[i]=="R":
            RSS.append("R")
            R+=1
            F=1
    else:
        RSS.append(RS[i])
        if RS[i]=="R":
            R+=1
        else:
            W+=1

SS=RSS[::-1]
#print(SS,R,W)

LW=[]
LR=[]
for i in range(len(SS)):
    if SS[i]=="W":
        LW.append(i)
    else:
        LR.append(i)
LR=LR[::-1]


LW.append(10**7)
LR.append(-1)
#print(LW,LR)
for i in range(len(LR)):
    if LW[i]>LR[i]:
        cnt=i
        break
print(min(cnt,W,R))
### BUGGY CODE ###

from collections import deque


def resolve():
    S = input()
    Q = int(input())

    ans = deque(list(S))

    for i in range(Q):
        T = list(input().split())

        if (T[0] == "1"):
            ans.reverse()
        else:
            if (T[1] == "1"):
                ans.appendleft(T[2])
            else:
                ans.append(T[2])
            pass

    print("".join(ans))


resolve()

### FIXED CODE ###

def resolve():
    S = input()
    Q = int(input())

    rev = 0
    append_front_rev = ''
    append_rear = ''

    for i in range(Q):
        T = input().split()

        if (T[0] == "1"):
            rev ^= 1
            continue

        if (T[0] == "2" and T[1] == "1"):
            if rev == 0:
                append_front_rev += T[2]
            else:
                append_rear += T[2]
            continue

        if (T[0] == "2" and T[1] == "2"):
            if rev == 0:
                append_rear += T[2]
            else:
                append_front_rev += T[2]
            continue

    ans = append_front_rev[::-1] + S + append_rear
    if rev:
        ans = ans[::-1]

    print("".join(ans))


resolve()
### BUGGY CODE ###

def main():
    dist = []
    import numpy as np
    from collections import deque
    n, x, y = map(int,input().split())
    g = [[] for _ in range(n)] 
    for i in range(n-1):

        g[i] += i+1,
        g[i+1] += i,
    g[x-1] += y-1,
    g[y-1] += x-1,
    a = [0]*n
    for start in range(n):
        d = [-1] * n
        d[start] = 0
        q = deque([start])
        add,pop=q.append,q.popleft
        while q:
            v = pop()
            for nv in g[v]:
                if d[nv] < 0:
                    d[nv] = d[v]+1
                    add(nv)
        # for i in d:
        #     a[i] += 1
        dist.append(d)
    dist = np.array(dist).flatten()
    for i in range(1,n):
        print(int(len([x for x in dist if x==i])/2))
    # for i in range(1,n):
    #     print(int(a[i]/2))
main()

### FIXED CODE ###

def main():
    from collections import deque
    n,x,y=map(int,input().split())
    e=[[]for _ in range(n)]
    for i in range(n-1):
        e[i]+=i+1,
        e[i+1]+=i,
    e[x-1]+=y-1,
    e[y-1]+=x-1,
    a=[0]*n
    for s in range(n):
        d=[-1]*n
        d[s]=0
        q=deque([s])
        add,pop=q.append,q.popleft
        while q:
            v=pop()
            for w in e[v]:
                if d[w]<0:
                    d[w]=d[v]+1
                    add(w)
        for i in d:a[i]+=1
    print(' '.join(str(i//2)for i in a[1:]))
main()
### BUGGY CODE ###

n,a,b=map(int,input().split())
p=10**9+7
x=1
for _ in range(n):
    x=(x*2)%p
x=x-1
def fact(n,p):
    x=1
    if n==0 or n==1:
        pass
    else:
        for i in range(1,n+1):
            x=x*i%p
    return x%p
def cmb(n,r,p):
    if r<0 or n<r:
        return 0
    else:
        return fact(n,p)//fact(r,p)//fact(n-r,p)
X=x-cmb(n,a,p)-cmb(n,b,p)
print(X)

### FIXED CODE ###

n,a,b=map(int,input().split())
def fact(n,p):
    a=1
    for i in range(1,n+1):
        a=(a*i)%p
    return a
def bfact(n,x,p):
    a=1
    for i in range(n-x+1,n+1):
        a=(a*i)%p
    return a
p=10**9+7
na=bfact(n,a,p)%p
nb=bfact(n,b,p)%p
aa=fact(a,p)%p
bb=fact(b,p)%p
aaa=pow(aa,-1,p)
bbb=pow(bb,-1,p)
ans=pow(2,n,p)-1
ans-=(na*aaa+nb*bbb)
print(ans%p)
### BUGGY CODE ###

n,x,m = map(int, input().split()) 
ans = 0
x_list = []

for _ in range(n):
    x_list.append(x)
    x = x**2 % m
    if x == 0:
        ans = sum(x_list)
        break
    if x_list.count(x) == 1:
        after_list = x_list[x_list.index(x):(len(x_list))]
        if x_list.index(x) == 0:
            if (n // len(x_list)) == 0:
                ans = sum(x_list) * (n // len(x_list))
            else:
                ans = sum(x_list) * (n // len(x_list)) + sum(x_list[0:((n % len(x_list)))])
        else:
            if (n-x_list.index(x)) % len(after_list) == 0:
                ans = sum(after_list) * ((n-x_list.index(x)) // len(after_list)) + sum(x_list[0:(x_list.index(x))])
            else:
                ans = sum(after_list) * ((n-x_list.index(x)) // len(after_list)) + sum(after_list[0:(((n-x_list.index(x)) % len(after_list)))]) + sum(x_list[0:(x_list.index(x))])
        break

if ans == 0 and not x == 0:
    ans = sum(x_list)

print(ans)

### FIXED CODE ###

N, X, M = map(int, input().split())
 
def next_f(a):
    return a * a % M
 
visited = [None] * M
sum_at_visit = [None] * M
loop_done = False
 
time = 1
ans = 0
x = X
while time <= N:
    if not loop_done and visited[x] is not None:
        # found cycle                                                                                                                                         
        loop_len = time - visited[x]
        loop_sum = ans + x - sum_at_visit[x]
        loops = (N-loop_len-time) // loop_len
        time += loop_len * loops
        ans += loop_sum * loops
        loop_done = True
    ans += x
    visited[x] = time
    sum_at_visit[x] = ans
    time += 1
    x = next_f(x)
print(ans)
### BUGGY CODE ###

k = int(input())

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

answer = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            ans = gcd(i, j)
            ans = gcd(ans, l)
            answer += ans
            
print(answer)

### FIXED CODE ###

import itertools

k = int(input())

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

answer = 0
nums = list(range(1, k+1))
for balls in itertools.combinations_with_replacement(nums, 3):
    i, j, l = balls[0], balls[1], balls[2]
    ans = gcd(i, j)
    ans = gcd(ans, l)
    if len(set(balls)) == 1:
        answer += ans
    elif len(set(balls)) == 2:
        answer += ans*3
    elif len(set(balls)) == 3:
        answer += ans*6
            
print(answer)
### BUGGY CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


N=int(input())
S=0
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            S+=gcd(i,j,k)
print(S)

### FIXED CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


N=int(input())
S=0
T=0
for i in range(1,N+1):
    for j in range(i+1,N+1):
        for k in range(j+1,N+1):
            S+=gcd(i,j,k)
for i in range(1,N+1):
    for j in range(i+1,N+1):
            T+=gcd(i,j,j)
            T+=gcd(i,j,j)
print(6*S+3*T+N*(N+1)//2)
### BUGGY CODE ###

from collections import*
n,u,v=map(int,input().split())
e=[[]for _ in range(n+1)]
INF=10**18
d=[INF]*(n+1)
for _ in range(n-1):
  a,b=map(int,input().split())
  e[a]+=[b]
  e[b]+=[a]
q=deque([v])
d[v]=0
while q:
  now=q.popleft()
  for to in e[now]:
    if d[to]!=INF:continue
    d[to]=d[now]+1
    q.append(to)
q=[(u,0)]
ans=0
while q:
  now,c=q.pop()
  for to in e[now]:
    if d[to]>c+1:q+=[(to,c+1)]
    elif d[to]==c+1:ans=max(c+1,ans)
    else:ans=max(c,ans)
print(ans)

### FIXED CODE ###

from collections import*
n,u,v=map(int,input().split())
e=[[]for _ in range(n+1)]
INF=10**18
d=[INF]*(n+1)
for _ in range(n-1):
  a,b=map(int,input().split())
  e[a]+=[b]
  e[b]+=[a]
q=deque([(v,0)])
while q:
  now,c=q.popleft()
  d[now]=c
  for to in e[now]:
    if d[to]!=INF:continue
    q.append((to,c+1))
q=[(u,0)]
ans=0
vis=[1]*(n+1)
while q:
  now,c=q.pop()
  vis[now]=0
  f=1
  for to in e[now]:
    if vis[to]:
      f=0
      if d[to]>c+1:q+=[(to,c+1)]
      if d[to]==c+1:ans=max(c+1,ans)
      else:ans=max(c,ans)
  if len(e[now])==1:ans=max(d[to],ans)
print(ans)
### BUGGY CODE ###

import sys

first = sys.stdin.readline().strip().split()
N = int(first[0])  # 数列の要素数
M = int(first[1])  # 数列の最大値
Q = int(first[2])

inp = list()

for _ in range(Q):
    inp.append(sys.stdin.readline().strip())


max_score = 0
As = list()


def loop(row, start, idx):

    if idx == N:
        As.append(row)
    else:
        for i in range(start, M+1):
            loop(row + [i], i, idx+1)


loop([], 1, 0)

for A in As:
    score = 0
    for item in inp:
        a, b, c, d = map(int, item.split())
        if A[b-1] - A[a-1] == c:
            score += d
    max_score = max(score, max_score)

print(max_score)


### FIXED CODE ###

import sys

first = sys.stdin.readline().strip().split()
N = int(first[0])  # 数列の要素数
M = int(first[1])  # 数列の最大値
Q = int(first[2])

inp = list()

for _ in range(Q):
    inp.append(sys.stdin.readline().strip())


max_score = 0
As = list()


def loop(row, start, idx):

    global max_score

    if idx == N:
        # As.append(row)
        score = 0
        for item in inp:
            a, b, c, d = map(int, item.split())
            if row[b - 1] - row[a - 1] == c:
                score += d
        max_score = max(score, max_score)

    else:
        for i in range(start, M+1):
            loop(row + [i], i, idx+1)


loop([], 1, 0)

print(max_score)
### BUGGY CODE ###

import math
from operator import mul
from functools import reduce

def cmb(n,r, mod):
  r = min(n-r,r)
  if r == 0: return 1
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1,r + 1))
  return (over // under) %mod

def cmb2(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


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

#print((pow(2, n, 1000000000+7) - combinations_count(n, a) - 1 - combinations_count(n, b))%(1000000000+7))
print((pow(2, n, mod) - cmb(n, a, mod) - 1 - cmb(n, b, mod)))


### FIXED CODE ###

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

def choose(n, a):
    x = 1
    y = 1
    for i in range(1, a + 1):
        x = (x * (n - i + 1)) % mod
        y = (y * i) % mod
    return (x * pow(y, mod - 2, mod)) % mod

print((pow(2, n, mod) - 1 - choose(n, a) - choose(n, b)) % mod )
### BUGGY CODE ###

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

if N < B:
  floor = int(A*N/B) - A*int(N/B)
elif N == B:
  floor = int(A*(N-1)/B) - A*int((N-1)/B)
else:
  floor = max([(int(A*(x-1)/B) - A*int((x-1)/B)) for x in range(B,N,B)])
print(floor)

### FIXED CODE ###

A,B,N = map(int, input().split())
if B == 1 or A == 1:
  floor = 0
else:
  if N < B:
    floor = int(A*N/B) - A*int(N/B)
  elif N == B:
    floor = int(A*(N-1)/B) - A*int((N-1)/B)
  else:
    floor = max([(int(A*(x-1)/B) - A*int((x-1)/B)) for x in range(B,N,B)])
    
print(floor)
### BUGGY CODE ###

n = int(input())
li = list(map(int,input().split()))
ans = 10000000000000

for i in range(1,n):
  x = abs(sum(li[:i])-sum(li[i:]))
  if x < ans:
    ans = x

print(ans)

### FIXED CODE ###

n = int(input())
li = list(map(int,input().split()))
ans = 10000000000000
x = 0
y = sum(li)

for i in range(0,n-1):
    x += li[i]
    y -= li[i]
    z = abs(x-y)
    if z < ans:
        ans = z

print(ans)