Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import deque
s = deque(input())
print(s)
le = len(s)
cnt = 0
while le:
  if s[0] == s[-1]:
    s.pop()
    s.popleft()
    le -= 2
  elif s[0] == "x":
    s.popleft()
    cnt += 1
    le -= 1
  elif s[-1] == "x":
    s.pop()
    cnt += 1
    le -= 1
  else:
    print(-1)
    break
  print(s)
else:
  print(cnt)


Fixed submission:
from collections import deque
s = deque(input())
le = len(s)
cnt = 0
while le>1:
  if s[0] == s[-1]:
    s.pop()
    s.popleft()
    le -= 2
  elif s[0] == "x":
    s.popleft()
    cnt += 1
    le -= 1
  elif s[-1] == "x":
    s.pop()
    cnt += 1
    le -= 1
  else:
    print(-1)
    break
else:
  print(cnt)

Buggy python submission (verdict: Runtime Error):
from collections import deque
s = deque(input())
le = len(s)-1
cnt = 0
while le:
  if s[0] == s[-1]:
    s.pop()
    s.popleft()
    le -= 2
  elif s[0] == "x":
    s.popleft()
    cnt += 1
    le -= 1
  elif s[-1] == "x":
    s.pop()
    cnt += 1
    le -= 1
  else:
    print(-1)
    break
else:
  print(cnt)

Fixed submission:
from collections import deque
s = deque(input())
le = len(s)
cnt = 0
while le>1:
  if s[0] == s[-1]:
    s.pop()
    s.popleft()
    le -= 2
  elif s[0] == "x":
    s.popleft()
    cnt += 1
    le -= 1
  elif s[-1] == "x":
    s.pop()
    cnt += 1
    le -= 1
  else:
    print(-1)
    break
else:
  print(cnt)

Buggy python submission (verdict: Runtime Error):
from collections import deque
s = deque(input())
cnt = 0
while s:
  if s[0] == s[-1] == "x":
    s.pop()
    s.popleft()
  elif s[0] == "x":
    s.popleft()
    cnt += 1
  elif s[-1] == "x":
    s.pop()
    cnt += 1
  else:
    print(-1)
    break
else:
  print(cnt)

Fixed submission:
from collections import deque
s = deque(input())
le = len(s)
cnt = 0
while le>1:
  if s[0] == s[-1]:
    s.pop()
    s.popleft()
    le -= 2
  elif s[0] == "x":
    s.popleft()
    cnt += 1
    le -= 1
  elif s[-1] == "x":
    s.pop()
    cnt += 1
    le -= 1
  else:
    print(-1)
    break
else:
  print(cnt)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict as dd
n,m = map(int, input().split())
dic = dd(list)
l = []
cnt = 0
for _ in range(m):
  a,b = map(int, input().split())
  l.append(a,b)
  dic[a].add(b)
  dic[b].add(a)
def con(x):
  visit.add(x)
  for i in [j for j in dic[x] if j not in visited]:
    con(i)
  return visit == set(range(1,n+1))
for x,y in l:
  dic[x].remove(y)
  dic[y].remove(x)
  visit = set()
  if not con(x):
    cnt += 1
  dic[x].add(y)
  dic[y].add(x)
print(cnt)

Fixed submission:
from collections import defaultdict as dd
n,m = map(int, input().split())
dic = dd(list)
l = []
cnt = 0
for _ in range(m):
  a,b = map(int, input().split())
  l.append((a,b))
  dic[a].append(b)
  dic[b].append(a)
def con(x):
  visit.add(x)
  for i in dic[x]:
    if i in visit:
      continue
    con(i)
  return visit == set(range(1,n+1))
for x,y in l:
  dic[x].remove(y)
  dic[y].remove(x)
  visit = set()
  if not con(x):
    cnt += 1
  dic[x].append(y)
  dic[y].append(x)
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations as cc
l = []
n,k = map(int, input().split())
xs,ys = set(),set()
t = 10**24
for _ in range(n):
  x,y = map(int, input().split())
  xs.add(x)
  ys.add(y)
  l.append((x,y))
xs = sorted(list(xs))
ys = sorted(list(ys))
for xl,xr in cc(xs,2):
  for yl,yr in cc(ys,2):
    cnt = 0
    for x,y in l:
      if xl<=x<=xr and yl<=y<=yr:
        cnt += 1
      if cnt >= k:
        s = (xr-xl)*(yr-yl)
        if t > s:
          t = s
print(t)

Fixed submission:
from itertools import combinations as cc
l = []
n,k = map(int, input().split())
xs,ys = set(),set()
t = 10**24
for _ in range(n):
  x,y = map(int, input().split())
  xs.add(x)
  ys.add(y)
  l.append((x,y))
xs = sorted(list(xs))
ys = sorted(list(ys))
for xl,xr in cc(xs,2):
  for yl,yr in cc(ys,2):
    cnt = 0
    for x,y in l:
      if xl<=x<=xr and yl<=y<=yr:
        cnt += 1
      if cnt >= k:
        s = (xr-xl)*(yr-yl)
        if t > s:
          t = s
print(t)

Buggy python submission (verdict: Runtime Error):
from itertools import combinations as cc
l = []
n,k = map(int, input().split())
xs,ys = set(),set()
t = 10**24
for _ in range(n):
  x,y = map(int, input().split())
  xs.add(x)
  ys.add(y)
  l.append((x,y))
xs = sorted(list(xs))
ys = sorted(list(ys))
for xl,xr in cc(xs,2):
  foe yl,yr in cc(ys,2):
    cnt = 0
    for x,y in l:
      if xl<=x<=xr and yl<=y<=yr:
        cnt += 1
      if cnt >= k:
        s = (xr-xl)*(yr-yl)
        if t > s:
          t = s
print(t)

Fixed submission:
from itertools import combinations as cc
l = []
n,k = map(int, input().split())
xs,ys = set(),set()
t = 10**24
for _ in range(n):
  x,y = map(int, input().split())
  xs.add(x)
  ys.add(y)
  l.append((x,y))
xs = sorted(list(xs))
ys = sorted(list(ys))
for xl,xr in cc(xs,2):
  for yl,yr in cc(ys,2):
    cnt = 0
    for x,y in l:
      if xl<=x<=xr and yl<=y<=yr:
        cnt += 1
      if cnt >= k:
        s = (xr-xl)*(yr-yl)
        if t > s:
          t = s
print(t)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
for i in t:
  if i in d:
    d.remove(i)
  else:
    print("NO")
    exit()
print("YES")

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
dict = {}
for i in d:
  if i in dict:
    dict[i] += 1
  else:
    dict[i] = 1
for i in t:
  if dict.get(i, 0) > 0:
    dict[i] -= 1
  else:
    print("NO")
    exit()
print("YES")
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n%2 == 0:
  print(n,n,n//2)
else:
  for h in range(2,3501):
    for l in range(2,3501):
      w =  n*h*l // (4*h*l - n*(h+l))
      if 4*h*l*w == n*(h*w+h*l+l*w):
        print(h,l,w)
        break

Fixed submission:
from itertools import product
n = int(input())
if n%2 == 0:
  print(n,n,n//2)
else:
  for h,l in product(range(max(2, n//4),3501),repeat=2):
    m = n*h*l
    c = 4*h*l - n*(h+l)
    if c > 0 and m%c == 0:
      w = m//c
      break
  print(h,l,w)

Buggy python submission (verdict: Runtime Error):
from itertools import product
n = int(input())
if n%2 == 0:
  print(n,n,n//2)
else:
  for h,l in product(range(2,3501),repeat=2):
    m = n*h*l
    c = 4*h*l - n*(h+l)
    if c >= 0 and m%c == 0:
      w = m//c
      break
  print(h,l,w)

Fixed submission:
from itertools import product
n = int(input())
if n%2 == 0:
  print(n,n,n//2)
else:
  for h,l in product(range(max(2, n//4),3501),repeat=2):
    m = n*h*l
    c = 4*h*l - n*(h+l)
    if c > 0 and m%c == 0:
      w = m//c
      break
  print(h,l,w)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
l.sort(key=lambda x:x[1])
print(x[0][0]+x[0][1])

Fixed submission:
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
l.sort(reverse=True)
print(l[0][0]+l[0][1])
Buggy python submission (verdict: Runtime Error):
a,b,c,d,e,f = map(int, input().split())
ans = 0
for i in range(f//(a*100)+1):
  for j in range((f-a*100*i)//(b*100)+1):
    for k in range((f-a*i*100-b*j*100)//c+1):
      for l in range((f-a*i*100-b*j*100-c*k)//d+1):
        w = i+j
        s = k+l
        if w*e >= k:
          ans = max(ans,s/(w*100+s))
print(ans)

Fixed submission:
a,b,c,d,e,f = map(int, input().split())
ans = [-1,0,0]
for i in range(f//(a*100)+1):
  for j in range((f-a*100*i)//(b*100)+1):
    for k in range((f-a*i*100-b*j*100)//c+1):
      for l in range((f-a*i*100-b*j*100-c*k)//d+1):
        w = i*a+j*b
        s = k*c+l*d
        if w == 0:
          continue
        if w*e >= s and ans[0] < s/(w*100+s):
          ans = [s/(w*100+s),w*100+s,s]
print(ans[1],ans[2])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
cnt = 0
for k in range(n):
  for i in range(n-1):
    for j in range(i+1,n):
      if a[i][j] > a[i][k] + a[k][j]:
        print(-1); exit(0)

for i in range(n-1):
  for j in range(i+1,n):
    for k in range(n):
      if k == i or k == j: continue
      elif a[i][j] == a[i][k] + a[k][j]:
        cnt += a[i][j]
tot = sum(sum(x) for x in a)//2
print(tot-cnt)

Fixed submission:
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
cnt = 0
for k in range(n):
  for i in range(n-1):
    for j in range(i+1,n):
      if a[i][j] > a[i][k] + a[k][j]:
        print(-1); exit(0)

for i in range(n-1):
  for j in range(i+1,n):
    for k in range(n):
      if k == i or k == j: continue
      elif a[i][j] == a[i][k] + a[k][j]:
        cnt += a[i][j]
        break
tot = sum(sum(x) for x in a)//2
print(tot-cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [input() for i in range(n)]
b = []
for i in range(n):
  if a[i] in b:
    b.remove(a[i])
  else:
    b.append(a[i])
print(len(b))

Fixed submission:
n = int(input())
a = [input() for i in range(n)]
d = {}
ans = 0
for i in a:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1
for i in d.keys():
  if d[i] % 2 == 1:
    ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [input() for i in range(n)]
b = []
for i in range(n):
  if a[i] in b:
    b.pop(a[i])
  else:
    b.append(a[i])
print(len(b))

Fixed submission:
n = int(input())
a = [input() for i in range(n)]
d = {}
ans = 0
for i in a:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1
for i in d.keys():
  if d[i] % 2 == 1:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import permutations as per

n,m,r = map(int,input().split())
rlist = list(map(int,input().split()))
ans = 10**9
A = [[10**8]*n for _ in range(n)]
for _ in range(n):
  a,b,c = map(int,input().split())
  A[a-1][b-1] = c
  A[b-1][a-1] = c

for i in range(n-1):
  for j in range(i+1,n):
    for k in range(n):
      newd = A[i][k] + A[k][j]
      if A[i][j] > newd:
        A[i][j] = newd
        A[j][i] = newd
for x in per(rlist):
  cost = 0
  for i in range(r-1):
    cost += A[x[i]-1][x[i+1]-1]
  if cost < ans:
    ans = cost
print(ans)

Fixed submission:
n,m,r = map(int,input().split())
l = list(map(int,input().split()))
g = [[10**10]*(n+1) for _ in range(n+1)]
for i in range(n+1):
  g[i][i] = 0
for _ in range(m):
  a,b,c = map(int,input().split())
  g[a][b] = c
  g[b][a] = c
for k in range(1,n+1):
  for i in range(1,n):
    for j in range(i+1,n+1):
      if g[i][j] >= g[i][k] + g[k][j]:
        g[i][j] = g[i][k] + g[k][j]
        g[j][i] = g[i][j]
g[0] = [0]*(n+1)
def dfs(cur,res,dis,use):
  if res == 0:
    return dis
  ans = 10**10
  for i in range(r):
    if not use[i]:
      use[i] = 1
      ans = min(ans, dfs(l[i],res-1,dis+g[cur][l[i]],use))
      use[i] = 0
  return ans
print(dfs(0,r,0,[0]*r))

Buggy python submission (verdict: Runtime Error):
from itertools import permutation as per

n,m,r = map(int,input().split())
rlist = list(map(int,input().split()))
ans = 10**9
A = [[10**8]*n for _ in range(n)]
for _ in range(n):
  a,b,c = map(int,input().split())
  A[a-1][b-1] = c
  A[b-1][a-1] = c

for i in range(n-1):
  for j in range(i+1,n):
    for k in range(n):
      newd = A[i][k] + A[k][j]
      if A[i][j] > newd:
        A[i][j] = newd
        A[j][i] = newd
for x in per(rlist):
  cost = 0
  for i in range(r-1):
    cost += A[x[i]-1][x[i+1]-1]
  if cost < ans:
    ans = cost
print(ans)

Fixed submission:
n,m,r = map(int,input().split())
l = list(map(int,input().split()))
g = [[10**10]*(n+1) for _ in range(n+1)]
for i in range(n+1):
  g[i][i] = 0
for _ in range(m):
  a,b,c = map(int,input().split())
  g[a][b] = c
  g[b][a] = c
for k in range(1,n+1):
  for i in range(1,n):
    for j in range(i+1,n+1):
      if g[i][j] >= g[i][k] + g[k][j]:
        g[i][j] = g[i][k] + g[k][j]
        g[j][i] = g[i][j]
g[0] = [0]*(n+1)
def dfs(cur,res,dis,use):
  if res == 0:
    return dis
  ans = 10**10
  for i in range(r):
    if not use[i]:
      use[i] = 1
      ans = min(ans, dfs(l[i],res-1,dis+g[cur][l[i]],use))
      use[i] = 0
  return ans
print(dfs(0,r,0,[0]*r))
Buggy python submission (verdict: Runtime Error):
q,h,s,d = map(int,input().split())
r = [q,h,s,d]
n = int(input())*4
l = [q,h/2,s/4,d/8]
v = [1,2,4,8]
cost = 0
while n:
  now = l2.index(min(l))
  cost += n//v[now] * r[now]
  n %= v[now]
  v.pop(now)
  r.pop(now)
  l.pop(now)
print(cost)


Fixed submission:
q,h,s,d = map(int,input().split())
r = [q,h,s,d]
n = int(input())*4
l = [q,h/2,s/4,d/8]
v = [1,2,4,8]
cost = 0
while n:
  now = l.index(min(l))
  cost += n//v[now] * r[now]
  n %= v[now]
  v.pop(now)
  r.pop(now)
  l.pop(now)
print(cost)

Buggy python submission (verdict: Runtime Error):
q,h,s,d = map(int,input().split())
r = [q,h,s,d]
n = int(input())
l = [q,h/2,s/4,d/8]
cost = 0
while n:
  now = l2.index(min(l))
  cost += n//r[now]
  n %= r[now]
  r.pop(now)
  l.pop(now)
print(cost)

Fixed submission:
q,h,s,d = map(int,input().split())
r = [q,h,s,d]
n = int(input())*4
l = [q,h/2,s/4,d/8]
v = [1,2,4,8]
cost = 0
while n:
  now = l.index(min(l))
  cost += n//v[now] * r[now]
  n %= v[now]
  v.pop(now)
  r.pop(now)
  l.pop(now)
print(cost)
Buggy python submission (verdict: Runtime Error):
from collections import Count
s = input()
n = len(s)
d = Count(s)
c = 0
for x in d:
  c += d[x]*(d[x]-1)//2
print(n*(n-1)//2 - c)

Fixed submission:
from collections import Counter
s = input()
n = len(s)
d = Counter(s)
c = 0
for x in d:
  c += d[x]*(d[x]-1)//2
print(1 + n*(n-1)//2 - c)
Buggy python submission (verdict: Runtime Error):
s = set(input())
on = {a, b, c, d, e, f, g, h ,i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z}
if s == on:
  print("None")
print(min(on-s))

Fixed submission:
s = set(input())
on = set("abcdefghijklmnopqrstuvwxyz")
try:
  print(min(on-s))
except ValueError:
  print("None")
Buggy python submission (verdict: Runtime Error):
n = int(input())
s1 = input()
s2 = input()
mod = 10**9+7
b = 0
2did = 0
ans = 0
if s1[0] == s2[0]:
  b = 1
  ans += 3
else:
  2did = 1
  ans = 6
for i in range(1,n):
  if s1[i] == s2[i]:
    if b:
      ans = ans*2%mod
    b = 1
  elif not 2did:
    if b:
      ans = ans*2%mod
    else:
      ans = ans*3%mod
    2did = 1
    b = 0
  else:
    2did = 0
print(ans)

Fixed submission:
n = int(input())
s1 = input()
s2 = input()
mod = 10**9+7
b = 0
did = 0
ans = 0
if s1[0] == s2[0]:
  b = 1
  ans += 3
else:
  did = 1
  ans = 6
for i in range(1,n):
  if s1[i] == s2[i]:
    if b:
      ans = ans*2%mod
    b = 1
  elif not did:
    if b:
      ans = ans*2%mod
    else:
      ans = ans*3%mod
    did = 1
    b = 0
  else:
    did = 0
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
inf = float("inf")
road = [dict() for _ in range(n+1)]
for _ in range(n-1):
  a,b,c = map(int, input().split())
  road[a][b] = c
  road[b][a] = c
q,k = map(int, input().split())
dfs = [inf]*(n+1)
dfs[k] = 0
def dodfs(x):
  for i in road[x]:
    if dfs[i] == inf:
      dfs[i] = dfs[x] + road[x][i]
      dodfs(i)
  return   
dodfs(k)
for _ in range(q):
  x,y = map(int, input().split())
  print(dfs[x] + dfs[y])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n = int(input())
inf = float("inf")
road = [dict() for _ in range(n+1)]
for _ in range(n-1):
  a,b,c = map(int, input().split())
  road[a][b] = c
  road[b][a] = c
q,k = map(int, input().split())
dfs = [inf]*(n+1)
dfs[k] = 0
def dodfs(x):
  for i in road[x]:
    if dfs[i] == inf:
      dfs[i] = dfs[x] + road[x][i]
      dodfs(i)
  return   
dodfs(k)
for _ in range(q):
  x,y = map(int, input().split())
  print(dfs[x] + dfs[y])

Buggy python submission (verdict: Runtime Error):
n = int(input())
inf = float("inf")
road = [dict() for _ in range(n)]
for _ in range(n-1):
  a,b,c = map(int, input().split())
  road[a-1][b-1] = c
  road[b-1][a-1] = c
q,k = map(int, input().split())
dfs = [inf]*n
dfs[k-1] = 0

def dodfs(x):
  for i in road[x-1]:
    if dfs[i] == inf:
      dfs[i] = dfs[x-1] + road[x-1][i]
      dodfs(i)
  return
      
dodfs(k)
for _ in range(q):
  x,y = map(int, input().split())
  print(dfs[x-1] + dfs[y-1])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n = int(input())
inf = float("inf")
road = [dict() for _ in range(n+1)]
for _ in range(n-1):
  a,b,c = map(int, input().split())
  road[a][b] = c
  road[b][a] = c
q,k = map(int, input().split())
dfs = [inf]*(n+1)
dfs[k] = 0
def dodfs(x):
  for i in road[x]:
    if dfs[i] == inf:
      dfs[i] = dfs[x] + road[x][i]
      dodfs(i)
  return   
dodfs(k)
for _ in range(q):
  x,y = map(int, input().split())
  print(dfs[x] + dfs[y])
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
d = {1:0, 2:0, 4:0}
for i in a:
  if i % 4 == 0:
    d[4] += 1
  elif i % 2 == 0:
    d[2] += 1
  else:
    d[1] += 1
if d.get(2, 0) >= 1:
  d[1] += 1
if d.get(1, 0) <= d.get(4, 0)+1:
  print("Yes")
else:
  print("No")


Fixed submission:
n, m = map(int, input().split())
print((n-1)*(m-1))
Buggy python submission (verdict: Runtime Error):
h,w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
s = []
l = []
for x in range(n):
  s += [x+1]*a[x+1]
for i in range(h):
  l.append(s[w*i:w*(i+1)])
  if i%2:
    l[i] = l[i][::-1]
for x in l:
  print(" ".join(map(str,x)))

Fixed submission:
h,w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
s = []
l = []
for x in range(n):
  s += [x+1]*a[x]
for i in range(h):
  l.append(s[w*i:w*(i+1)])
  if i%2:
    l[i] = l[i][::-1]
for x in l:
  print(" ".join(map(str,x)))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(m)]
b = [x[1] for x in l if x[0]==1]
a = [x[0] for x in l if x[1]==n]
for i in b:
    if i in a:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

Fixed submission:
n, m = map(int, input().split())
l = [tuple(map(int, input().split())) for i in range(m)]
c = [[] for _ in range(n+1)]
for x in l:
    c[x[0]].append(x[1])
    c[x[1]].append(x[0])
if set(c[1])&set(c[n]):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
ans = float("inf")
for i in range(1,n):
  x = sum(a[:i])*2
  if ans > abs(x - s):
    ans = abs(x - s)
print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
d = [s - a[0]*2,] + [0 for _ in range(n-2)]
for i in range(1,n-1):
    d[i] = d[i-1] - a[i]*2
print(min([abs(i) for i in d]))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
ans = float("inf")
for i in range(1,n):
  x = sum(s[:i])*2
  if ans > abs(x - s):
    ans = abs(x - s)
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
d = [s - a[0]*2,] + [0 for _ in range(n-2)]
for i in range(1,n-1):
    d[i] = d[i-1] - a[i]*2
print(min([abs(i) for i in d]))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = float("inf")
s = sum(a)
for i in range(1,n):
  if ans > abs(sum(a[:i])*2 - s):
    ans = abs(sum(a[:i])*2 - s)
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
d = [s - a[0]*2,] + [0 for _ in range(n-2)]
for i in range(1,n-1):
    d[i] = d[i-1] - a[i]*2
print(min([abs(i) for i in d]))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = float("inf")
for i in range(1,n):
  if ans > abs(sum(a[:i]) - sum(a[i:])):
    ans = abs(sum(a[:i]) - sum(a[i:]))
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
d = [s - a[0]*2,] + [0 for _ in range(n-2)]
for i in range(1,n-1):
    d[i] = d[i-1] - a[i]*2
print(min([abs(i) for i in d]))
Buggy python submission (verdict: Runtime Error):
t = list(input())
del s [-2:]
a = 2
while s[:len(s)//2] != s[len(s)//2:]:
    s = s[:-2]
    a += 2
print(a)

Fixed submission:
s = list(input())
l = len(s) - 2
while s[:l//2] != s[l//2:l]:
    l -= 2
print(l)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [0] + [int(input()) for i in range(n)]
c = a[1]
p = 1
while c > 2:
    c = a[c]
    p += 1

if c == 2:
    print(p)
else:
    print(-1)


Fixed submission:
n = int(input())
a = [0] + [int(input()) for i in range(n)]
c = a[1]
p = 1
while c > 2:
    d = a[c]
    a[c] = 0
    c = d
    p += 1

if c == 2:
    print(p)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
c = 0
p = 0
while True:
    c = a[c]
    p += 1
    if c == 1:
        print(p)
        exit()
    elif c == 0 and p > 1:
        print(-1)
        exit()


Fixed submission:
n = int(input())
a = [0] + [int(input()) for i in range(n)]
c = a[1]
p = 1
while c > 2:
    d = a[c]
    a[c] = 0
    c = d
    p += 1

if c == 2:
    print(p)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
c = 0
p = 0
while True:
    c = s[c]
    p += 1
    if c == 1:
        print(p)
        exit()
    elif c == 0 and p > 1:
        print(-1)
        exit()


Fixed submission:
n = int(input())
a = [0] + [int(input()) for i in range(n)]
c = a[1]
p = 1
while c > 2:
    d = a[c]
    a[c] = 0
    c = d
    p += 1

if c == 2:
    print(p)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
from math import factorial as f
print(max(0,2-abs(n-m))*f(n)*f(m) % (10**9+7))

Fixed submission:
import math

n, m = map(int, input().split())
if abs(n-m) == 0:
    print(2*math.factorial(n)*math.factorial(m) % 1000000007)
elif abs(n-m) == 1:
    print(math.factorial(n)*math.factorial(m) % 1000000007)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
def a(n):
    if n < 2:
        return 1
    return a(n-1) * n

n, m = map(int, input().split())
if abs(n-m) > 1:
    print(0)
elif abs(n-m) == 1:
    print(a(n) * a(m) % 1000000007)
else:
    print(2 * a(n) * a(m) % 1000000007)

Fixed submission:
import math

n, m = map(int, input().split())
if abs(n-m) == 0:
    print(2*math.factorial(n)*math.factorial(m) % 1000000007)
elif abs(n-m) == 1:
    print(math.factorial(n)*math.factorial(m) % 1000000007)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
s = input().split()
int(''.join(s)) % 4 == 0:
  print("YES")
else:
  print("NO")

Fixed submission:
s = input().split()
if int(''.join(s)) % 4 == 0:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
color = [0]*8
for i in a:
  color[min(8,i//400)] += 1
kind = 0
for i in color[:7]:
  if i:
    kind += 1
if kind == 0 and color[7]:
  color[7] -= 1
  kind += 1
print(kind,kind+color[7])

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
color = [0]*9
for i in a:
  color[min(8,i//400)] += 1
kind = 0
for i in color[:8]:
  if i:
    kind += 1
if kind == 0 and color[8]:
  color[8] -= 1
  kind += 1
print(kind,kind+color[8])
Buggy python submission (verdict: Runtime Error):
s = [[1, 3, 5, 7, 8, 10, 12][4, 6, 9, 11][2]]
x, y = map(int, input().split())
for i in range(3):
  if x in s[i] and y in s[i]:
    print("Yes")
    exit()
print("No")

Fixed submission:
s = [[1, 3, 5, 7, 8, 10, 12],[4, 6, 9, 11],[2]]
x, y = map(int, input().split())
for i in range(3):
  if x in s[i] and y in s[i]:
    print("Yes")
    exit()
print("No")
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = [list(input()) for i in range(h)]
a = ['#' for i in range(w)] + a + ['#' for i in range(w)]
for i in a:
    i = '#'+ i +'#'
    print(i)

Fixed submission:
h, w = map(int, input().split())
a = [list(input()) for i in range(h)]
a = [['#' for i in range(w)]] + a + [['#' for i in range(w)]]
for i in range(h+2):
    a[i] = ['#']+ a[i] +['#']
    print(''.join(a[i]))