Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
A = list(map(int, input().split()))
M = max(A)
S = sum(A)
M += M % 2 != S % 2
print((3 * M - sum) // 2)

Fixed submission:
A = list(map(int, input().split()))
M = max(A)
S = sum(A)
M += M % 2 != S % 2
print((3 * M - S) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
for i in range(N):
    B=A[:i]+A[i+1:]
    print(sum(abs(x-y)for x,y in zip([0]+B,B+[0])))

Fixed submission:
N=int(input())
A=[0]+list(map(int,input().split()))+[0]
S=sum(abs(x-y)for x,y in zip(A,A[1:]))
for i in range(1,N+1):
    print(S-abs(A[i]-A[i-1])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]))
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
print(sum(p*(b-K)+max(r-K+1,0)for p,r,b in map(lambda b:(*divmod(N,b),b),range(K+1,N+1)))if K else N*N)

Fixed submission:
N, K = map(int, input().split())
if K == 0:
    print(N * N)
    exit()
cnt = 0
for b in range(K + 1, N + 1):
    p, r = divmod(N, b)
    cnt += p * (b - K) + max(r - K + 1, 0)
print(cnt)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
if K % 2:
    print((N // K) ** 3)
else:
    print((N // K) ** 3 + ((N + K // 2) // K) ** 3)

Fixed submission:
A,B,C,X=[int(input())for _ in[0]*4]
ans=sum(a*500+b*100+c*50==X for a in range(A+1)for b in range(B+1)for c in range(C+1))
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input()
e = [[0, 0, 0]] + [list(map(int, e.split())) for e in sys.stdin]
for (t0, a0, b0), (t1, a1, b1) in zip(e, e[1:]):
    d = (t1 - t0) - abs(a1 - a0) - abs(b1 - b0)
    if d < 0 or t % 2 == 1:
        print('No')
        exit()
print('Yes')

Fixed submission:
can = True
e = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(int(input()))]
for a, b in zip(e[1:], e):
    dt = a[0] - b[0]
    dist = abs(a[1] - b[1]) + abs(a[2] - b[2])
    if dt < dist: can = False; break
    if dt % 2 != dist % 2: can = False; break
print(['No', 'Yes'][can])
Buggy python submission (verdict: Time Limit Exceeded):
input()
S=list(map(int,input().split()))
ans=0
for x in set(S):
    cnt=S.count(x)
    ans+=cnt-x*(cnt>=x)
print(ans)

Fixed submission:
from collections import Counter
N, *A = map(int, open(0).read().split())
print(sum(c - x * (c >= x) for x, c in Counter(A).items()))
Buggy python submission (verdict: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; ++i)
using namespace std;

int main() {
  int N, K;
	cin >> N >> K;
  vector<int> c(N);
	REP(i,N) {
		int a; cin >> a; c[--a]++;
	}
	sort(c.begin(), c.end(), greater<int>());
	int s = N;
	REP(i,K) s -= c[i];
	cout << s << endl;
	return 0;
}

Fixed submission:
N,K=map(int,input().split())
B=[0]*N
for i in map(int,input().split()):B[~-i]+=1
print(sum(sorted(B)[:-K]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        tmp = 4*n*h - N*n - N*h
        if tmp > 0:
            if N * h * n % tmp == 0:
                print(h, n, N * h * n // tmp)
                exit()

Fixed submission:
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        if 4*n*h - N*n - N*h > 0:
            if N * h * n % (4*n*h - N*n - N*h) == 0:
                print(h, n, N * h * n // (4*n*h - N*n - N*h))
                exit()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        tmp = 4*n*h - N*n - N*h
        if tmp <= 0:
            continue
        w = N * h * n / tmp
        if w % 1 == 0:
            print(h, n, int(w))
            exit()

Fixed submission:
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        if 4*n*h - N*n - N*h > 0:
            if N * h * n % (4*n*h - N*n - N*h) == 0:
                print(h, n, N * h * n // (4*n*h - N*n - N*h))
                exit()
Buggy python submission (verdict: Runtime Error):
numbers = set()
for _ in [0] * int(input()):
    A = int(input())
    if A in numbers:
        arr.remove(A)
    else:
        arr.add(A)
print(len(numbers))

Fixed submission:
numbers = {}
for _ in [0] * int(input()):
    A = int(input())
    numbers[A] = numbers.get(A, 0) ^ 1
print(sum(numbers.values()))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int,input().split()))
count = lambda x: a.count(x-1)+a.count(x)+a.count(x+1)
print(max(count(x) for x in range(min(a),max(a)+1)))

Fixed submission:
cnt = [0]*10**5; input()
a = list(map(int,input().split()))
for x in a:cnt[x]+=1
print(max(sum(cnt[i:i+3])for i in range(min(a),max(a)+1)))
Buggy python submission (verdict: Runtime Error):
x,a,b=map(int,input())
print('AB'[abs(a-x)>abs(b-x)])

Fixed submission:
x,a,b=map(int,input().split())
print('AB'[abs(a-x)>abs(b-x)])
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return b

ans = 1
for _ in range(int(input())):
    t = int(input())
    ans = ans * t // gcd(ans, t)
print(ans)

Fixed submission:
import fractions
import functools
lcm=lambda x,y:x*y//fractions.gcd(x,y)
print(functools.reduce(lcm,[int(input())for _ in[0]*int(input())]))

Buggy python submission (verdict: Runtime Error):
import math
import functools
lcm=lambda x,y:x*y//math.gcd(x,y)
print(functools.reduce(lcm,[int(input())for _ in[0]*int(input())]))

Fixed submission:
import fractions
import functools
lcm=lambda x,y:x*y//fractions.gcd(x,y)
print(functools.reduce(lcm,[int(input())for _ in[0]*int(input())]))
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from operator import itemgetter

def sub(prefers, canceled):
    res = Counter()
    for pref in prefers:
       p = pref[-1]
        while p in canceled:
            pref.pop()
            p = pref[-1]
        res[p] += 1
    return max(res.items(), key=itemgetter(1))

def solve(m, prefers):
    canceled = set()
    ans = float('inf')
    for _ in [0] * m:
        s, c = sub(prefers, canceled)
        canceled.add(s)
        ans = min(ans, c)
    return ans

if __name__ == '__main__':
    N, M = map(int, input().split())
    A = [list(map(int, input().split()))[::-1] for _ in [0] * N]
    print(solve(M, A))

Fixed submission:
from collections import Counter
from operator import itemgetter

def sub(prefers, canceled):
    res = Counter()
    for pref in prefers:
        pt = -1
        while pref[pt] in canceled:
            pt -= 1
        res[pref[pt]] += 1
    return max(res.items(), key=itemgetter(1))

def solve(m, prefers):
    canceled = set()
    ans = float('inf')
    for _ in [0] * m:
        s, c = sub(prefers, canceled)
        canceled.add(s)
        ans = min(ans, c)
    return ans

if __name__ == '__main__':
    N, M = map(int, input().split())
    A = [list(map(int, input().split()))[::-1] for _ in [0] * N]
    print(solve(M, A))
Buggy python submission (verdict: Time Limit Exceeded):
input()
b=[]
for a in map(int,input().split()):
    b+=[a]
    b=b[::-1]
print(*b)

Fixed submission:
n=int(input())
b=[0]*n
for i,a in enumerate(map(int,input().split())):
    if n%2:
        b[n//2+-~i//2*[-1,1][i%2]]=a
    else:
        b[n//2+-~i//2*[1,-1][i%2]]=a
print(*b)
Buggy python submission (verdict: Runtime Error):
S = input()
ans = min(max(map(len, S.split(c)))
          for c in [chr(i + 97) for i in range(26)]
          if c not in S)
print(ans)

Fixed submission:
S = input()
ans = len(S)
for tgt in set(S):
    T = S
    while len(T) != T.count(tgt):
        U = ''
        for ab in zip(T, T[1:]):
            U += tgt if tgt in ab else ab[0]
        T = U
    ans = min(ans, len(S) - len(T))
print(ans)

Buggy python submission (verdict: Runtime Error):
S = input()
ans = min(max(map(len, S.split(c)))
          for c in [chr(i + 97) for i in range(26)]
          if c not in S))
print(ans)

Fixed submission:
S = input()
ans = len(S)
for tgt in set(S):
    T = S
    while len(T) != T.count(tgt):
        U = ''
        for ab in zip(T, T[1:]):
            U += tgt if tgt in ab else ab[0]
        T = U
    ans = min(ans, len(S) - len(T))
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
*S, C = map(int, input().split())
print(["NO", "YES"][C % math.gcd(*S) == 0])

Fixed submission:
A, B, C = map(int, input().split())
r = [(A * k) % B for k in range(B)]
print(["NO", "YES"][C in r])
Buggy python submission (verdict: Time Limit Exceeded):
S,T=input(),input()
for _ in[0]*int(input()):
    a,b,c,d=map(int,input().split())
    S_sub,T_sub=S[a-1:b],T[c-1:d]
    r=S_sub.count('A')+2*S_sub.count('B')-T_sub.count('A')-2*T_sub.count('B')
    print(['YES','NO'][r%3>0])

Fixed submission:
S,T=[0],[0]
for k,c in enumerate(input()):S+=[S[-1]+(c=='A')]
for k,c in enumerate(input()):T+=[T[-1]+(c=='A')]
for _ in[0]*int(input()):
    a,b,c,d=map(int,input().split())
    print(['YES','NO'][(2*(b-a-d+c)+T[d]-T[c-1]-S[b]+S[a-1])%3>0])
Buggy python submission (verdict: Runtime Error):
F=lambda*m:max(len(str(x))for x in m);print(m)
N=int(input())
print(min(F(x,N//x)for x in range(1,int(N**.5)+1)if N%x==0))

Fixed submission:
F=lambda*m:max(len(str(x))for x in m)
N=int(input())
print(min(F(x,N//x)for x in range(1,int(N**.5)+1)if N%x==0))

Buggy python submission (verdict: Runtime Error):
F=lambda*m:max(len(str(x))for x in m)
N=int(input())
print(min(F(x,N//x)for x in range(1,int(N**.5)+1)if N%x))

Fixed submission:
F=lambda*m:max(len(str(x))for x in m)
N=int(input())
print(min(F(x,N//x)for x in range(1,int(N**.5)+1)if N%x==0))
Buggy python submission (verdict: Runtime Error):
W,H,N = map(int,input().split())
w=h=0
for _ in[0]*N:
    x,y,a = map(int,input().split())
    if a == 1:
        w = max(w,x)
    elif a == 2:
        W = min(W,x)
    elif a == 3:
        h = max(h,y)
    elhe:
        H = min(H,y)
print((W-w)*(H-h)*(W>w)*(H>h))

Fixed submission:
e,n,N = map(int,input().split())
w=s=0
for _ in[0]*N:
    x,y,a = map(int,input().split())
    if a == 1:
        w = max(w,x)
    elif a == 2:
        e = min(e,x)
    elif a == 3:
        s = max(s,y)
    else:
        n = min(n,y)
print((e-w)*(n-s)*(e>w)*(n>s))
Buggy python submission (verdict: Time Limit Exceeded):
S = 1
for c in input():
    if c == 'S':
        S = S << 1 | 1
    else:
        if S > 1 and S & 1:
            S >>= 1
        else:
            S = S << 1 | 0
print(len(bin(S)) - 3)

Fixed submission:
T, S = 0, 0
for c in input():
    if c == 'S':
        S += 1
    else:
        if S:
            S -= 1
        else:
            T += 1
print(T + S)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
a = [0 for i in range(n)]
b = a
a_i = 0
b_i = 0
for i in l:
  if i%2 == 0:
    a[i]+=1
    if(a[a_i]<=a[i]):
      a_i=i
  else:
    b[i]+=1
    if(b[b_i]<=b[i]):
      b_i=i
a.sort()
a.reverse()
b.sort()
b.reverse()
if a_i == b_i:
  print(n-a[0]-b[0])
else:
  print(n-max(a[0]+b[1],a[1]+b[0]))

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
a = [0 for i in range(10**6)]
b = [0 for i in range(10**6)]
a_i = 0
b_i = 0
i = 0
for e in l:
    if i%2 == 0:
        a[e]+=1
        if(a[a_i]<=a[e]):
            a_i=e
    else:
        b[e]+=1
        if(b[b_i]<=b[e]):
            b_i=e
    i+=1
a.sort()
a.reverse()
b.sort()
b.reverse()
if a_i != b_i:
    print(n-a[0]-b[0])
else:
    print(n-max(a[0]+b[1],a[1]+b[0]))
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())
S = input()
L = list(range(10))
flag = True
for i in range(A+B+1):
    if ( i == A ):
        if (S[i] != "-"):
            flag = False
    else:
        if (not (int(S[i]) in L)):
            flag = False
if flag:
    print("Yes")
else:
    print("No")

Fixed submission:
A,B = map(int,input().split())
S = input()
L = list(map(str,list(range(10))))
flag = True
for i in range(A+B+1):
    if ( i == A ):
        if (S[i] != "-"):
            flag = False
    else:
        if (not (S[i] in L)):
            flag = False
if flag:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N,A,B=map(int,input.split())
#the max
print(min(A,B))
print(max(0,A+B-N))

Fixed submission:
N,A,B=map(int,input().split())
#the max
print(min(A,B),max(0,A+B-N))

Buggy python submission (verdict: Runtime Error):
sumu,x,y=(map(int,input.split()))
minum=max(x+y-sumu,0)
maxim=min(x,y)
print(maxim,minum)

Fixed submission:
N,A,B=map(int,input().split())
#the max
print(min(A,B),max(0,A+B-N))
Buggy python submission (verdict: Runtime Error):
print(f"{T}{S}")


Fixed submission:
a = input().split()
print(f"{a[1]}{a[0]}")

Buggy python submission (verdict: Runtime Error):
f"{T}{S}"

Fixed submission:
a = input().split()
print(f"{a[1]}{a[0]}")
Buggy python submission (verdict: Runtime Error):
from typing import List


def main() -> None:
    ab, bc, _ = get_params()
    print(area(ab, bc))


def get_params() -> List[int]:
    return [int(s) for s in input().split()]


def area(ab: int, bc: int) -> int:
    return ab * bc // 2


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    ab, bc, _ = get_params()
    print(area(ab, bc))


def get_params():
    return [int(s) for s in input().split()]


def area(ab, bc):
    return ab * bc // 2


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  int num=753, min=999;
  string s;
  cin >> s;

  for (int i=0; i<s.size()-2; i++) {
    int dif=abs(num-stoi(s.substr(i, 3)));

    if (dif<min) min=dif;
  }

  cout << min;
}

Fixed submission:
num=753; mindif=753
s=input()

for i in range(len(s)-2):
    dif=abs(int(s[i:i+3])-num)
    
    if (dif<mindif):
        mindif=dif

print(mindif)
Buggy python submission (verdict: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  string s;
  cin >> s;

  for (int i=0; i<s.size(); i++) {
    if (i==4) cout << ' ';
    else cout << s[i];
  }
}

Fixed submission:
s=input()

for i, j in enumerate(s):
    if i==4:
        print(" ", end="")
    print(j, end="")
print("")
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
D - Xor Sum 4
https://atcoder.jp/contests/abc147/tasks/abc147_d

"""
import sys


def solve(N, A):
    MOD = 10**9 + 7
    bit_len = max(map(int.bit_length, A))
    ans = 0
    for i in range(bit_len):
        zeros, ones = 0, 0
        for a in A:
            if (a & 1<<i):
                ones += 1
            else:
                zeros += 1
        ans = (ans + (ones * zeros * 2**i)) % MOD
    return ans % MOD


def main(args):
    N = int(input())
    A = list(map(int, input().split()))
    ans = solve(N, A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Fixed submission:
# -*- coding: utf-8 -*-
"""
D - Xor Sum 4
https://atcoder.jp/contests/abc147/tasks/abc147_d

"""
import sys


def solve(N, A):
    MOD = 10**9 + 7
    bit_len = max(map(int.bit_length, A))
    ans = 0
    for i in range(bit_len):
        zeros, ones = 0, 0
        for a in A:
            if (a & 1<<i):
                ones += 1
            else:
                zeros += 1
        ans = (ans + (ones * zeros * 2**i)) % MOD
    return ans % MOD


def main(args):
    N = int(input())
    A = list(map(int, input().split()))
    ans = solve(N, A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
D - Xor Sum 4
https://atcoder.jp/contests/abc147/tasks/abc147_d

"""
import sys


def solve(N, A):
    MOD = 10**9 + 7
    bit_len = max(map(int.bit_length, A))
    ans = 0
    for i in range(bit_len):
        zeros, ones = 0, 0
        for a in A:
            if (a & 1<<i):
                ones += 1
            else:
                zeros += 1
        ans += (ones * zeros * 2**i)
    return ans % MOD


def main(args):
    N = int(input())
    A = list(map(int, input().split()))
    ans = solve(N, A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Fixed submission:
# -*- coding: utf-8 -*-
"""
D - Xor Sum 4
https://atcoder.jp/contests/abc147/tasks/abc147_d

"""
import sys


def solve(N, A):
    MOD = 10**9 + 7
    bit_len = max(map(int.bit_length, A))
    ans = 0
    for i in range(bit_len):
        zeros, ones = 0, 0
        for a in A:
            if (a & 1<<i):
                ones += 1
            else:
                zeros += 1
        ans = (ans + (ones * zeros * 2**i)) % MOD
    return ans % MOD


def main(args):
    N = int(input())
    A = list(map(int, input().split()))
    ans = solve(N, A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
D - Coloring Edges on Tree
https://atcoder.jp/contests/abc146/tasks/abc146_d

"""
import sys


from collections import OrderedDict, deque

def main(args):
    N = int(input())
    G = [[] for _ in range(N+1)]
    res = OrderedDict()
    for _ in range(N-1):
        a, b = map(int, input().split())
        res[(a, b)] = -1
        G[a].append(b)
        G[b].append(a)

    k = max(len(g) for g in G)
    colors = [set(range(1, k+1)) for _ in range(N+1)]
    q = deque([1])
    visited = set([1])
    while q:
        cn = q.popleft()
        for nn in G[cn]:
            if nn not in visited:
                visited.add(nn)
                q.append(nn)
                c = min(colors[cn])
                colors[cn].discard(c)
                colors[nn].discard(c)
                if (cn, nn) in res:
                    res[(cn, nn)] = c
                if (nn, cn) in res:
                    res[(nn, cn)] = c
    print(k)
    for v in res.values():
        print(v)


if __name__ == '__main__':
    main(sys.argv[1:])


Fixed submission:
# -*- coding: utf-8 -*-
"""
D - Coloring Edges on Tree
https://atcoder.jp/contests/abc146/tasks/abc146_d

"""
import sys


from collections import OrderedDict, deque

def main(args):
    N = int(input())
    G = [[] for _ in range(N+1)]
    res = OrderedDict()
    for _ in range(N-1):
        a, b = map(int, input().split())
        res[(a, b)] = -1
        G[a].append(b)
        G[b].append(a)

    k = max(len(g) for g in G)
    colors = [0 for _ in range(N+1)]
    q = deque([1])
    visited = set([1])
    while q:
        cn = q.popleft()
        color = 1
        for nn in G[cn]:
            if nn not in visited:
                if color == colors[cn]:
                    color += 1
                visited.add(nn)
                q.append(nn)
                c = color
                colors[nn] = color
                color += 1
                if (cn, nn) in res:
                    res[(cn, nn)] = c
                if (nn, cn) in res:
                    res[(nn, cn)] = c
    print(k)
    for v in res.values():
        print(v)


if __name__ == '__main__':
    main(sys.argv[1:])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
D - Triangles
https://atcoder.jp/contests/abc143/tasks/abc143_d

"""
import sys

from itertools import combinations
from bisect import bisect_left, bisect_right

def solve(N, lines):
    ans = 0
    for c in range(N-1, -1, -1):
        for b in range(c-1, -1, -1):
            i = bisect_right(lines[:b], lines[c] - lines[b])
            ans += max(0, (b-i))
    return ans


def main(args):
    N = int(input())
    lines = map(int, input().split())
    ans = solve(N, sorted(lines))
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Fixed submission:
# -*- coding: utf-8 -*-
"""
D - Triangles
https://atcoder.jp/contests/abc143/tasks/abc143_d

"""
import sys

from itertools import combinations
from bisect import bisect_left, bisect_right

def solve(N, lines):
    ans = 0
    for c in range(N-1, -1, -1):
        for b in range(c-1, -1, -1):
            i = bisect_right(lines[:b], lines[c] - lines[b])
            ans += max(0, (b-i))
    return ans


def main(args):
    N = int(input())
    lines = map(int, input().split())
    ans = solve(N, sorted(lines))
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
D - Summer Vacation
https://atcoder.jp/contests/abc137/tasks/abc137_d

"""
import sys


from heapq import heapify, heappop
from bisect import bisect_left

def solve(N, M, jobs):
    days = [d for d in range(1, M+1)]
    heapify(jobs)
    ans = 0
    while jobs:
        B, A = heappop(jobs)
        i = bisect_left(days, -A)
        if i != len(days):
            days.pop(i)
            ans -= B
    return ans


def main(args):
    N, M = map(int, input().split())
    jobs = []
    for _ in range(N):
        A, B = map(int, input().split())
        jobs.append([-B, -A])
    ans = solve(N, M, jobs)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Fixed submission:
# -*- coding: utf-8 -*-
"""
D - Summer Vacation
https://atcoder.jp/contests/abc137/tasks/abc137_d

"""
import sys


from heapq import heapify, heappop, heappush

def solve(N, M, jobs):
    heapify(jobs)
    availables = []
    ans = 0
    for day in range(1, M+1):
        while jobs and jobs[0][0] <= day:
            A, B = heappop(jobs)
            heappush(availables, (-B))
        if availables:
            ans -= heappop(availables)
    return ans


def main(args):
    N, M = map(int, input().split())
    jobs = []
    for _ in range(N):
        A, B = map(int, input().split())
        jobs.append((A, B))
    ans = solve(N, M, jobs)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
D - Digits Parade
https://atcoder.jp/contests/abc135/tasks/abc135_d

"""
import sys


def solve(S):
    dp = [[0] * 13 for _ in range(len(S)+1)]
    dp[0][0] = 1
    for i, ch in enumerate(S):
        c = -1 if ch == '?' else int(ch)
        for j in range(10):
            if (c != -1 and c != j):
                continue
            for ki in range(13):
                dp[i+1][(ki*10 + j) % 13] += dp[i][ki]
        for j in range(13):
            dp[i+1][j] %= (10**9 + 7)
    return dp[len(S)][5]


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Fixed submission:
# -*- coding: utf-8 -*-
"""
D - Digits Parade
https://atcoder.jp/contests/abc135/tasks/abc135_d

"""
import sys


def solve(S):
    dp = [[0] * 13 for _ in range(len(S)+1)]
    dp[0][0] = 1
    for i, ch in enumerate(S):
        c = -1 if ch == '?' else int(ch)
        for j in range(10):
            if (c != -1 and c != j):
                continue
            for ki in range(13):
                dp[i+1][(ki*10 + j) % 13] += dp[i][ki]
        for j in range(13):
            dp[i+1][j] %= (10**9 + 7)
    return dp[len(S)][5]


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""



"""
import sys


def solve(N, W):
    left, right = 0, sum(W)
    ans = [abs(right-left)]
    for w in W:
        left += w
        right -= w
        ans.append(abs(right-left))
    return min(ans)


def main(args):
    N = int(input())
    W = [int(w) for w in input().split()]
    ans = solve(N, W)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
h

Fixed submission:
def solve(N, W):
    left, right = 0, sum(W)
    ans = [abs(right-left)]
    for w in W:
        left += w
        right -= w
        ans.append(abs(right-left))
    return min(ans)


N = int(input())
W = [int(w) for w in input().split()]
ans = solve(N, W)
print(ans)