Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
s = list(S)
Q = int(input())
p = [[0 for i in range(3)]for j in range(Q)]
x = 1
for i in range(Q):
    p[i] = list(map(str,input().split()))
def add(s,x,f,c):
    if x ==1:
        if f == 1:
            s.insert(0,str(c))
        else:
            s.append(str(c))
    else:
        if f == 1:
            s.append(str(c))
        else:
            s.insert(0,str(c))
for i in range(Q):
    if int(p[i][0]) == 1:
        x = -x
    else:
        add(s,x,int(p[i][1]),p[i][2])
if x == 1:
    print(''.join(s))
else:
    s.reverse()
    print(''.join(s))

Fixed submission:
from collections import deque
S = input()
s = list(S)
d = deque()
for i in range(len(s)):
    d.append(s[i])
Q = int(input())
p = [[0 for i in range(3)]for j in range(Q)]
x = 1
for i in range(Q):
    p[i] = list(map(str,input().split()))
def add(s,x,f,c):
    if x ==1:
        if f == 1:
            s.appendleft(str(c))
        else:
            s.append(str(c))
    else:
        if f == 1:
            s.append(str(c))
        else:
            s.appendleft(str(c))
for i in range(Q):
    if int(p[i][0]) == 1:
        x = -x
    else:
        add(d,x,int(p[i][1]),p[i][2])
if x == 1:
    print(''.join(d))
else:
    d.reverse()
    print(''.join(d))
Buggy python submission (verdict: Time Limit Exceeded):
n,a,b = map(int,input().split())
def cmb(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

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
v = int(pow(2,n,10**9+7)-1-cmb(n,a,10**9+7)-cmb(n,b,10**9+7))
if v >= 0:
    print(v)
else:
    print(v+10**9+7)

Fixed submission:
n,a,b = map(int,input().split())
def cmb(n, r, mod):
    x = 1 
    y = 1
    for i in range(r):
        x = x*(n-i)%(mod)
    for i in range(1,r+1):
        y = y*i%(mod)
    return x * pow(y,mod-2,mod) %mod

v = int(pow(2,n,10**9+7)-1-cmb(n,a,10**9+7)-cmb(n,b,10**9+7))
if v >= 0:
    print(v)
else:
    if v+10**9+7 >= 0:
        print(v+10**9+7)
    else:
        print(v+2*(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n,a,b = map(int,input().split())
def kai(g):
    p = 1 
    for i in range(1,g+1):
        p = p*i
    return p
def comb(n,k):
    return kai(n)/(kai(k)*kai(n-k))
print(int(2**n-1-comb(n,a)-comb(n,b)))

Fixed submission:
n,a,b = map(int,input().split())
def cmb(n, r, mod):
    x = 1 
    y = 1
    for i in range(r):
        x = x*(n-i)%(mod)
    for i in range(1,r+1):
        y = y*i%(mod)
    return x * pow(y,mod-2,mod) %mod

v = int(pow(2,n,10**9+7)-1-cmb(n,a,10**9+7)-cmb(n,b,10**9+7))
if v >= 0:
    print(v)
else:
    if v+10**9+7 >= 0:
        print(v+10**9+7)
    else:
        print(v+2*(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
alist = list(map(int,input().split()))
p = 1
for i in range(N-1):
    for j in range(i+1,N):
        if alist[i] == alist[j]:
            p = p*0
            print('NO')
            break
if p == 1:
    print('YES')

Fixed submission:
N = int(input())
alist = list(map(int,input().split()))
alist.sort()
p = 1
for i in range(N-1):
    if alist[i] == alist[i+1]:
        p = p*0
        print('NO')
        break
if p == 1:
    print('YES')
Buggy python submission (verdict: Runtime Error):
N = [0] + list(map(int, input()))
N = [0] + list(map(int, input()))
K = int(input())
n = len(N)

DP = [[[0] * (K+2) for _ in range(2)] for _ in range(n)]

# 0桁目(0)で最大値を取っていてk=0の要素は1個。
DP[0][0][0] = 1

for i in range(1, n):
    for k in range(K+1):
        if N[i] != 0:
            DP[i][0][k+1] += DP[i-1][0][k]
            DP[i][1][k] += DP[i-1][0][k]
            DP[i][1][k+1] += DP[i-1][0][k] * (N[i] - 1)
        else:
            DP[i][0][k] += DP[i-1][0][k]
            DP[i][1][k] += DP[i-1][1][k]
            DP[i][1][k+1] += DP[i-1][1][k] * 9
print(DP[n-1][1][K] + DP[n-1][0][K])

Fixed submission:
n = input()
a = list(n)
k = int(input())
n = len(a)
for i in range(n):
    a[i] = int(a[i])
dp = [[[0 for i in range(2)] for i in range(k+2)]for i  in range(n)]
dp[0][0][0] = 1
dp[0][1][0] = a[0]-1
dp[0][1][1] = 1
for i in range(n-1):
    for j in range(k+1):
        if a[i+1] == 0:
            dp[i+1][j][1] += dp[i][j][1]
            dp[i+1][j][0] += dp[i][j][0]
            dp[i+1][j+1][0] += dp[i][j][0]*9
        else:
            dp[i+1][j][0] += dp[i][j][0]+dp[i][j][1]
            dp[i+1][j+1][0] += dp[i][j][1]*(a[i+1]-1)+dp[i][j][0]*9
            dp[i+1][j+1][1] += dp[i][j][1]
print(dp[n-1][k][0]+dp[n-1][k][1])

Buggy python submission (verdict: Runtime Error):
N = [0] + list(map(int, input()))
N = [0] + list(map(int, input()))
K = int(input())
n = len(N)

DP = [
      [[0] * (K+2) for _ in range(2)] for _ in range(n)
]

# 0桁目(0)で最大値を取っていてk=0の要素は1個。
DP[0][0][0] = 1

for i in range(1, n):
  for k in range(K+1):
    if N[i] != 0:
      DP[i][0][k+1] += DP[i-1][0][k]
      DP[i][1][k] += DP[i-1][0][k]
      DP[i][1][k+1] += DP[i-1][0][k] * (N[i] - 1)
    else:
      DP[i][0][k] += DP[i-1][0][k]
    DP[i][1][k] += DP[i-1][1][k]
    DP[i][1][k+1] += DP[i-1][1][k] * 9
print(DP[n-1][1][K] + DP[n-1][0][K])

Fixed submission:
n = input()
a = list(n)
k = int(input())
n = len(a)
for i in range(n):
    a[i] = int(a[i])
dp = [[[0 for i in range(2)] for i in range(k+2)]for i  in range(n)]
dp[0][0][0] = 1
dp[0][1][0] = a[0]-1
dp[0][1][1] = 1
for i in range(n-1):
    for j in range(k+1):
        if a[i+1] == 0:
            dp[i+1][j][1] += dp[i][j][1]
            dp[i+1][j][0] += dp[i][j][0]
            dp[i+1][j+1][0] += dp[i][j][0]*9
        else:
            dp[i+1][j][0] += dp[i][j][0]+dp[i][j][1]
            dp[i+1][j+1][0] += dp[i][j][1]*(a[i+1]-1)+dp[i][j][0]*9
            dp[i+1][j+1][1] += dp[i][j][1]
print(dp[n-1][k][0]+dp[n-1][k][1])
Buggy python submission (verdict: Time Limit Exceeded):
h,n = map(int,input().split())
p = []
inf = 10**9
for i in range(n):
    a,b = map(int,input().split())
    p.append([a,b])
m = [[0 for i in range(h)]for i in range(n+1)]
for i in range(n+1):
    for j in range(h):
        m[i][j] = inf
for i in range(n):
    for j in range(h):
        if p[i][0] >= j+1:
            m[i+1][j] = min(m[i][j],p[i][1])
        else:
            m[i+1][j] = min(m[i][j],m[i+1][j-p[i][0]]+p[i][1])
print(m[n][h-1])

Fixed submission:
h,n = map(int,input().split())
p = []
inf = 10**9
for i in range(n):
    a,b = map(int,input().split())
    p.append([a,b])
m = [[0 for i in range(h)]for i in range(n+1)]
for i in range(n+1):
    for j in range(h):
        m[i][j] = inf
for i in range(n):
    for j in range(h):
        if p[i][0] >= j+1:
            m[i+1][j] = min(m[i][j],p[i][1])
        else:
            m[i+1][j] = min(m[i][j],m[i+1][j-p[i][0]]+p[i][1])
print(m[n][h-1])
Buggy python submission (verdict: Runtime Error):
n, m = map(int,input().split())
q = [0 for i in range(n)]
alist = []
ac = 0
pe = 0
be = be
for i in range(m):
    a,b=input().split()
    alist.append((int(a), b))
for i in range(m):
    if q[alist[i][0]-1] == 0:
        if alist[i][1] == 'AC':
            ac += 1
            be = be + pe
            q[alist[i][0]-1] = 1
        else:
            pe += 1
    else:
        continue
print(ac,be)

Fixed submission:
n, m = map(int,input().split())
q = [0 for i in range(n)]
alist = []
ac = 0
pe = [0 for i in range(n)]
be = 0
for i in range(m):
    a,b=input().split()
    alist.append((int(a), b))
for i in range(m):
    if q[alist[i][0]-1] == 0:
        if alist[i][1] == 'AC':
            ac += 1
            be = be + pe[alist[i][0]-1]
            q[alist[i][0]-1] = 1
        else:
            pe[alist[i][0]-1] +=  1
    else:
        continue
print(ac,be)
Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())
from copy import deepcopy
from collections import deque
a = [input().split() for l in range(h)]
c = [[None for i in range(w)]for j in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == '.':
            c[i][j] = -1
ans = 0
g = deque()
for l in range(h):
    for k in range(w):
        b = deepcopy(c)
        if a[l][k] == '.':
            b[l][k] = 0
            g.append((l,k))
            while len(g)>0:
                i,j = g.popleft()
                dis = b[i][j] 
                for dx,dy in ((1,0),(0,1),(-1,0), (0,-1)):
                    newi = i + dx
                    newj = j +dy
                    if newi < 0 or newi > h-1 or newj < 0 or newj > w-1:
                        continue
                    if b[newi][newj] == -1:
                        b[newi][newj] = dis + 1
                        ans = max(ans,dis+1)
                        g.append((newi,newj))
print(ans)
                 

Fixed submission:
h,w = map(int,input().split())
from copy import deepcopy
from collections import deque
a = [list(input()) for l in range(h)]
c = [[None for i in range(w)]for j in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == '.':
            c[i][j] = -1
ans = 0
g = deque()
for l in range(h):
    for k in range(w):
        b = deepcopy(c)
        if a[l][k] == '.':
            b[l][k] = 0
            g.append((l,k))
            while len(g)>0:
                i,j = g.popleft()
                dis = b[i][j] 
                for dx,dy in ((1,0),(0,1),(-1,0), (0,-1)):
                    newi = i + dx
                    newj = j +dy
                    if newi < 0 or newi > h-1 or newj < 0 or newj > w-1:
                        continue
                    if b[newi][newj] == -1:
                        b[newi][newj] = dis + 1
                        ans = max(ans,dis+1)
                        g.append((newi,newj))
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
p = [1]
mod = 10**9+7
for i in range(n):
    p.append(p[-1]*(i+2)%mod)
def comb(n,k,mod):
    s = p[n-1]*pow(fac(k),mod-2,mod)%mod
    s = s*pow(fac(n-k),mod-2,mod)%mod
    return s
max_sum = 0
min_sum = 0
for i in range(n-k+1):
    max_sum += a[-(i+1)]*comb(n-1-i,k-1,mod)
    max_sum = max_sum%mod
    min_sum += a[i]*comb(n-1-i,k-1,mod)
    min_sum = min_sum%mod
ans = max_sum-min_sum
if ans < 0:
    ans += mod
print(ans)

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
p = [1]
mod = 10**9+7
for i in range(n):
    p.append(p[-1]*(i+1)%mod)
p.pop()
def comb(n,k,mod):
    s = p[n]*pow(p[k],mod-2,mod)%mod
    s = s*pow(p[n-k],mod-2,mod)%mod
    return s
max_sum = 0
min_sum = 0
for i in range(n-k+1):
    max_sum += a[-(i+1)]*comb(n-1-i,k-1,mod)
    max_sum = max_sum%mod
    min_sum += a[i]*comb(n-1-i,k-1,mod)
    min_sum = min_sum%mod
ans = max_sum-min_sum
if ans < 0:
    ans += mod
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,k = map(int,input().split())
if a-k < 0:
    b  = b + a -k
a = max(a-k,0)
print(a,max(b,0))

Fixed submission:
s,t = map(str,input().split())
print(t ,end='')
print(s)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
import fractions as fr
g = fr.gcd(a,b)
print(int(a*b/g))

Fixed submission:
a = int(input())
b = int(input())
print(6-a-b)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
import math
g = math.gcd(a,b)
print(int(a*b/g))

Fixed submission:
a,b = map(int,input().split())
import fractions as fr
g = fr.gcd(a,b)
print(int(a*b/g))

Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
import math
g = math.gcd(a,b)
print(int(a*b/g))

Fixed submission:
a,b = map(int,input().split())
import fractions as fr
g = fr.gcd(a,b)
print(int(a*b/g))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
g = []
ans = 0
for j in range(60):
    d = 0
    for i in range(n):
        d += a[i]&1
        a[i] >>= 1
    g.append(d)
for i in range(60):
    ans += g[i]*(n-g[i])*(pow(2,i,1000000007))
    ans = ans % (1000000007)
print(ans%(1000000007))

Fixed submission:
a1,a2,a3 = map(int,input().split())
if a1+a2+a3 > 21:
    print('bust')
else:
    print('win')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = list(str(input()))
ans = 0
for i in range(1000):
    q = 0
    p = list(str(i).zfill(3))
    s = p[q]
    for j in range(len(S)):
        if s == S[j]:
            q+=1
            if q == 3:
                break
            else:
                s = p[q]
        else:
            continue
    if q == 3:
        ans += 1
print(ans)

Fixed submission:
n = int(input())
S = list(str(input()))
ans = 0
for i in range(1000):
    q = 0
    p = list(str(i).zfill(3))
    s = p[q]
    for j in range(len(S)):
        if s == S[j]:
            q+=1
            if q == 3:
                break
            else:
                s = p[q]
        else:
            continue
    if q == 3:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
def pri(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
ans = 0
a,b = map(int,input().split())
for i in range(1,int(min(a,b)**0.5)+1):
    if i in pri(a) and i in pri(b):
        ans += 1
print(ans+1)

Fixed submission:
import math
def main():
    def pri(n):
        a = []
        while n % 2 == 0:
            a.append(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.append(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.append(n)
        return a
    ans = 0
    a,b = map(int,input().split())
    c = pri(a)
    d = pri(b)
    p = []
    if len(c) > 0:
        p.append(c[0])
    for i in range(len(c)-1):
        if c[i] != c[i+1]:
            p.append(c[i+1])
    for i in range(len(p)):
        if p[i] in d:
            ans += 1
    print(ans+1)
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
p = []
for k in range(m):  
    a,b = map(int,input().split())
    c = list(map(int,input().split()))
    key = 0
    for i in c:
        key += 2**(i-1)
    p.append([a,key])
inf = 10**9
dp = []
for u in range(m+1):
    dp.append([inf for i in range(2**n)])
dp[0][0] = 0
for i in range(m):
    for k in range(2**n):
        dp[i+1][k] = dp[i][k]
    for k in range(2**n):
        dp[i+1][k|p[i][1]] = min(dp[i][k|p[i][1]],dp[i][k]+p[i][0],dp[i+1][k|p[i][1]])
if dp[-1][-1] >= inf:
    print(-1)
else:
    print(dp[-1][-1])

Fixed submission:
n,m = map(int,input().split())
p = []
for k in range(m):  
    a,b = map(int,input().split())
    c = list(map(int,input().split()))
    key = 0
    for i in c:
        key += 2**(i-1)
    p.append([a,key])
inf = 10**9
dp = []
for u in range(m+1):
    dp.append([inf for i in range(2**n)])
dp[0][0] = 0
for i in range(m):
    for k in range(2**n):
        dp[i+1][k] = dp[i][k]
    for k in range(2**n):
        dp[i+1][k|p[i][1]] = min(dp[i][k|p[i][1]],dp[i][k]+p[i][0],dp[i+1][k|p[i][1]])
if dp[-1][-1] == inf:
    print(-1)
else:
    print(dp[-1][-1])
Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
s = [0 for i in range(n-1)]
for i in range(n-1):
    a,b = map(int,input().split())
    s[i] = [a,b]
s.sort()
ans = [-1 for i in range(n)]
for i in range(n-1):
    ans[s[i][1]-1] = s[i][0]-1
count = [0 for i in range(n)]
for i in range(q):
    p,x = map(int,input().split())
    count[p-1] += x
ans1 = [0 for i in range(n)]
ans1[0] = count[0]
for i in range(1,n):
    ans1[i] = ans1[ans[i]] + count[i]
for i in range(n):
    print(ans1[i])

Fixed submission:
n,m = map(int,input().split())
ans = 0
import heapq
g = [[] for i in range(100000)]
for i in range(n):
    a,b = map(int,input().split())
    a -= 1
    g[a].append(-b)
for i in range(100000):
    heapq.heapify(g[i])
p = []
heapq.heapify(p)
for i in range(m):
    if len(g[i]) != 0:
        heapq.heappush(p,[heapq.heappop(g[i]),i])
    if len(p) != 0:
        x = heapq.heappop(p)
        ans += -x[0]
        if len(g[x[1]]) != 0:
            heapq.heappush(p,[heapq.heappop(g[x[1]]),x[1]])            
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = []
mod = 10**9+7
for i in range(m):
    b = int(input())
    a.append(b)
d = [0 for i in range(n+1)]
d[0] = 0
d[1] = 1
d[2] = 2
for i in range(3,n+1):
    d[i] = d[i-1] + d[i-2]
ans = 1
if a[0] == 1:
    ans = 1
else:
    ans = ans*d[a[0]-1]%mod
for i in range(m-1):
    ans = ans*d[a[i+1]-a[i]-2]%mod
ans = ans*d[n-a[m-1]-1]%mod
print(ans)

Fixed submission:
S = input()
s = list(S)
s.sort()
if s[0] == s[1] and s[2] == s[3] and s[1] != s[2] :
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = []
mod = 10**9+7
d = [0 for i in range(n+1)]
d[0] = 1
d[1] = 1
if n >1 :
    d[2] = 2
for i in range(3,n+1):
    d[i] = d[i-1] + d[i-2]
d.append(0)
if m != 0:
    for i in range(m):
        b = int(input())
        a.append(b)
    ans = 1
    if a[0] == 1:
        ans = 1
    else:
        ans = ans*d[a[0]-1]%mod
    for i in range(m-1):
        ans = ans*d[a[i+1]-a[i]-2]%mod
    ans = ans*d[n-a[m-1]-1]%mod
else:
    ans = d[n]
print(ans)



Fixed submission:
n =  int(input())
d = list(map(int,input().split()))
d.sort()
kmin = d[n//2-1]
kmax = d[n//2]
print(kmax-kmin)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = []
mod = 10**9+7
for i in range(m):
    b = int(input())
    a.append(b)
d = [0 for i in range(n+1)]
d[0] = 0
d[1] = 1
d[2] = 2
for i in range(3,n+1):
    d[i] = d[i-1] + d[i-2]
ans = 1
if a[0] == 1:
    ans = 1
else:
    ans = ans*d[a[0]-1]%mod
for i in range(m-1):
    ans = ans*d[a[i+1]-a[i]-2]%mod
ans = ans*d[n-a[m-1]-1]%mod
print(ans)

Fixed submission:
n =  int(input())
d = list(map(int,input().split()))
d.sort()
kmin = d[n//2-1]
kmax = d[n//2]
print(kmax-kmin)
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
import fractions
s1 = b//c
s2 = (a-1)//c
p1 = b//d
p2 = (a-1)//d
e = c*d//math.gcd(c,d)
q1 = b//e
q2 = (a-1)//e
print(b-a+1-(s1+p1-s2-p2-q1+q2))

Fixed submission:
a,b,c,d = map(int,input().split())
import fractions
s1 = b//c
s2 = (a-1)//c
p1 = b//d
p2 = (a-1)//d
e = c*d//fractions.gcd(c,d)
q1 = b//e
q2 = (a-1)//e
print(b-a+1-(s1+p1-s2-p2-q1+q2))

Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
import math
s1 = b//c
s2 = (a-1)//c
p1 = b//d
p2 = (a-1)//d
e = c*d//math.gcd(c,d)
q1 = b//e
q2 = (a-1)//e
print(b-a+1-(s1+p1-s2-p2-q1+q2))

Fixed submission:
a,b,c,d = map(int,input().split())
import fractions
s1 = b//c
s2 = (a-1)//c
p1 = b//d
p2 = (a-1)//d
e = c*d//fractions.gcd(c,d)
q1 = b//e
q2 = (a-1)//e
print(b-a+1-(s1+p1-s2-p2-q1+q2))
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = []
mod = 10**9+7
d = [0 for i in range(n+1)]
    d[0] = 1
    d[1] = 1
    d[2] = 2
    for i in range(3,n+1):
        d[i] = d[i-1] + d[i-2]
    d.append(0)
if m != 0:
    for i in range(m):
        b = int(input())
        a.append(b)
    ans = 1
    if a[0] == 1:
        ans = 1
    else:
        ans = ans*d[a[0]-1]%mod
    for i in range(m-1):
        ans = ans*d[a[i+1]-a[i]-2]%mod
    ans = ans*d[n-a[m-1]-1]%mod
else:
    ans = d[n]
print(ans)



Fixed submission:
a,b,c = map(int,input().split())
print(min(a+b,b+c,c+a))
Buggy python submission (verdict: Runtime Error):
n = int(input())
w = list(map(int,input().split()))
ans = 10**9+a
p = 0
for i in range(n):
    p += w[i]
for i in range(n):
    p -= 2*w[i]
    ans = min(ans,abs(p))
print(ans)



Fixed submission:
n = int(input())
w = list(map(int,input().split()))
ans = 10**9
p = 0
for i in range(n):
    p += w[i]
for i in range(n):
    p -= 2*w[i]
    ans = min(ans,abs(p))
print(ans)
Buggy python submission (verdict: Runtime Error):
N,X = map(int,input().split())
Alist = list(map(int,input().split()))
for i in range(len(Alist)):
    Alist[i] = abs(Alist[i]-X)
Alist.sort()
p = []
q = 1
for i in range(1,len(Alist)):
    if Alist[i] % Alist[0] != 0:
        p.appnd(Alist[i] % Alist[0])
        q = q*0
p.sort()
r = 1
if p != []:
    for i in range(0,len(Alist)):
        if Alist[i] % p[0] != 0:
            r = r*0
if len(Alist) > 1:
    if q == 0 and r == 1:
        print(p[0])
    if q == 0 and r == 0:
        print(1)
    if q == 1:
        print(Alist[0])
else:
    print(Alist[0])

Fixed submission:
N,X = map(int,input().split())
Alist = list(map(int,input().split()))
for i in range(len(Alist)):
    Alist[i] = abs(Alist[i]-X)
Alist.sort()
p = []
q = 1
for i in range(1,len(Alist)):
    if Alist[i] % Alist[0] != 0:
        p.append(Alist[i] % Alist[0])
        q = q*0
p.sort()
r = 1
s = []
if p != []:
    for i in range(0,len(Alist)):
        s.append(Alist[i] % p[0])
        if Alist[i] % p[0] != 0:
            p[0] = Alist[i] % p[0]
if len(Alist) > 1:
    if q == 0 and r == 1:
        print(p[0])
    if q == 0 and r == 0:
        print(1)
    if q == 1:
        print(Alist[0])
else:
    print(Alist[0])
Buggy python submission (verdict: Runtime Error):
N, M, Q = map(int,input().split())
Mlist = []
for i in range(M):
    array = list(map(int, input().strip().split()))
    Mlist.append(array)
Qlist = []
for i in range(Q):
    array = list(map(int, input().strip().split()))
    Qlist.append(array)

r = [[0 for i in range(N)] for j in range(N)]


for i in range(len(Qlist)):
    q = 0
    for j in range(Qlist[i][0],Qlist[i][1]+1):
        q = q + r[j-1][Qlist[i][1]-1]
        if j - 1> 0:
            q = q - r[j-1][j-2]
    print(q)

Fixed submission:
A,B = map(int,input().split())
print(A*B-A-B+1)

Buggy python submission (verdict: Runtime Error):
N, M, Q = map(int,input().split())
Mlist = [input().split() for l in range(M)]
Qlist = [input().split() for l in range(Q)]
Mlist.sort()
for i in range(len(Mlist)):
    for j in range(len(Mlist[i])):
        Mlist[i][j] = int(Mlist[i][j])
for i in range(len(Qlist)):
    for j in range(len(Qlist[i])):
        Qlist[i][j] = int(Qlist[i][j])
p = [[0 for i in range(N)] for j in range(N)]
q = 0
r = [[0 for i in range(N)] for j in range(N)]
def count(k,l):
    s = k
    j = l
    p[s-1][j-1] = p[s-1][j-1] + 1
for i in range(len(Mlist)):
    count(Mlist[i][0],Mlist[i][1])
for i in range(10):
    for j in range(10):
        r[i][j] = r[i][j-1] + p[i][j]
for i in range(len(Qlist)):
    q = 0
    for j in range(Qlist[i][0],Qlist[i][1]+1):
        q = q + r[j-1][Qlist[i][1]-1]
        if j - 1> 0:
            q = q - r[j-1][j-2]
    print(q)

Fixed submission:
A,B = map(int,input().split())
print(A*B-A-B+1)

Buggy python submission (verdict: Runtime Error):
N, M, Q = map(int,input().split())
Mlist = [input().split() for l in range(M)]
Qlist = [input().split() for l in range(Q)]
Mlist.sort()
for i in range(len(Mlist)):
    for j in range(len(Mlist[i])):
        Mlist[i][j] = int(Mlist[i][j])
for i in range(len(Qlist)):
    for j in range(len(Qlist[i])):
        Qlist[i][j] = int(Qlist[i][j])
p = [[0 for i in range(N)] for j in range(N)]
q = 0
r = [[0 for i in range(N)] for j in range(N)]
def count(k,l):
    s = k
    j = l
    p[s-1][j-1] = p[s-1][j-1] + 1
for i in range(len(Mlist)):
    count(Mlist[i][0],Mlist[i][1])
for i in range(N):
    for j in range(N):
        r[i][j] = r[i][j-1] + p[i][j]
for i in range(len(Qlist)):
    q = 0
    for j in range(Qlist[i][0],Qlist[i][1]+1):
        q = q + r[j-1][Qlist[i][1]-1]
    print(q)


Fixed submission:
A,B = map(int,input().split())
print(A*B-A-B+1)