Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
n = list(map(int, input().split()))
d = max(m)-min(m)
if d:
  cnt = 0
  while d%2 == 0:
    d //= 2
    cnt += 1
  print(cnt)
elif n[0]%2:
  print(0)
else:
  print(-1)

Fixed submission:
a,b,c = map(int, input().split())
if a==b==c:
  if a%2:
    print(0)
  else:
    print(-1)
else:
  cnt = 0
  while a%2 == b%2 == c%2 == 0:
    a,b,c = (b+c)//2,(a+c)//2,(a+b)//2
    cnt += 1
  print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h,w,k = map(int, input().split())
g = [list(input()) for _ in range(h)]
ans = h*w
for i in range(h):
  if 'S' in g[i]:
    sx = g[i].index('S')
    sy = i
    break
g[sy][sx] = 0
q = deque()
q.append(sy*w+sx)
while q:
  v = q.popleft()
  y,x = v//w, v%w
  cur = min((y-1)//k, (x-1)//k, (h-y-2)//k, (w-x-2)//k) + 2
  if ans > cur:
    ans = cur
  if g[y][x] < k:
    for dx,dy in ((0,1),(1,0),(0,-1),(-1,0)):
      nx = x+dx; ny = y+dy
      if 0 <= nx < w and 0 <= ny < h and g[ny][nx] == '.':
        g[ny][nx] = g[y][x] + 1
        q.append(ny*w+nx)
print(ans)

Fixed submission:
from collections import deque
h,w,k = map(int, input().split())
g = [list(input()) for _ in range(h)]
ans = h*w
for i in range(h):
  if 'S' in g[i]:
    sx = g[i].index('S')
    sy = i
    break
g[sy][sx] = 0
q = deque()
q.append(sy*w+sx)
while q:
  v = q.popleft()
  y,x = v//w, v%w
  cur = min((y-1)//k, (x-1)//k, (h-y-2)//k, (w-x-2)//k) + 2
  if ans > cur:
    ans = cur
  if g[y][x] < k:
    for dx,dy in ((0,1),(1,0),(0,-1),(-1,0)):
      nx = x+dx; ny = y+dy
      if 0 <= nx < w and 0 <= ny < h and g[ny][nx] == '.':
        g[ny][nx] = g[y][x] + 1
        q.append(ny*w+nx)
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
while a != 0:
    a, b = b%a, a
if c % b = 0:
    print("YES")
else:
    print("NO")

Fixed submission:
a, b, c = map(int, input().split())
while a != 0:
    a, b = b%a, a
if c % b == 0:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
n, w = map(int, input().split())
di = dict()
m = 0
for _ in range(n):
  x,y = map(int, input().split())
  if x not in di:
    di[x] = []
  di[x].append(y)
for i in di:
  di[i].sort(reverse=True)
a,b,c,d = di.keys()
for i in range(len(di[a])):
  for j in range(len(di[b])):
    for k in range(len(di[c])):
      for l in range(len(di[d])):
        if i*a + j*b + k*c + l*d <= w:
          m = max(m, sum(di[a][:i+1] + di[b][:j+1] + di[c][:k+1] + di[d][:l+1]))
print(m)

Fixed submission:
n, w = map(int, input().split())
di = dict()
m = 0
for _ in range(n):
  x,y = map(int, input().split())
  if x not in di:
    di[x] = []
  di[x].append(y)
for i in di:
  di[i].sort(reverse=True)
a = min(di.keys())
b,c,d = a+1,a+2,a+3
for i in b,c,d:
  if i not in di:
    di[i] = []
for i in range(len(di[a])+1):
  for j in range(len(di[b])+1):
    for k in range(len(di[c])+1):
      for l in range(len(di[d])+1):
        if i*a + j*b + k*c + l*d <= w:
          m = max(m, sum(di[a][:i] + di[b][:j] + di[c][:k] + di[d][:l]))
print(m)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split())) + ["a"]
t = len(a)
cnt = 0
cur = 0
while t > 2:
  l,r = 0,1
  while a[r] != "a" and a[r] == a[l]:
    r += 1
  if a[r] == "a":
    print(cnt+1)
    exit()
  d = a[r]-a[l]
  while a[r+1] != "a" and (a[r+1]-a[r])*d>=0:
    r += 1
  cnt += 1
  d = 0
  a = a[r+1:]
  t -= r+1
if a[0] != "a":
  cnt += 1
print(cnt)
  

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
cnt,st,d = 0,-1,0
for i in range(n):
  if st < 0:
    st = i
    continue
  elif d == 0:
    if a[i]-a[st] != 0:
      r = i
      d = a[r]-a[st]
    continue
  else:
    if (a[i]-a[i-1])*d < 0:
      cnt += 1
      st,d = i,0
if st != -1:
  cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split())) + ["a"]
t = len(a)
cnt = 0
cur = 0
while t > 2:
  l,r = 0,1
  while a[r] != "a" and a[r] == a[l]:
    r += 1
  if a[r] == "a":
    print(cnt+1)
    exit()
  d = a[r]-a[l]
  while a[r+1] != "a" and (a[r+1]-a[r])*d>=0:
    r += 1
  cnt += 1
  d = 0
  a = a[r+1:]
  t -= r+1
if a[0] != "a":
  cnt += 1
print(cnt)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
cnt,st,d = 0,-1,0
for i in range(n):
  if st < 0:
    st = i
    continue
  elif d == 0:
    if a[i]-a[st] != 0:
      r = i
      d = a[r]-a[st]
    continue
  else:
    if (a[i]-a[i-1])*d < 0:
      cnt += 1
      st,d = i,0
if st != -1:
  cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
ls = len(s)
lt = len(t)
sl = [0]*(ls+1)
tl = [0]*(lt+1)
def g(x):
  if x == "A":
    return 1
  else:
    return 2
for i in range(ls):
  sl[i+1] = sl[i] + g(s[i])
for i in range(lt):
  tl[i+1] = tl[i] + g(t[i])
for _ in range(int(input())):
  a,b,c,d = map(int, input().split())
  if (sl[b]-tl[d]-sl[a-1]+tl[c-1])%3 == 0:
    print("YES")
  else:
    print("NO")
  

Fixed submission:
s = input()
t = input()
ls = len(s)
lt = len(t)
sl = [0]*(ls+1)
tl = [0]*(lt+1)
for i in range(ls):
  if s[i] == "A":
    sl[i+1] = sl[i] + 1
  else:
    sl[i+1] = sl[i] + 2
for i in range(lt):
  if t[i] == "A":
    tl[i+1] = tl[i] + 1
  else:
    tl[i+1] = tl[i] + 2
for _ in range(int(input())):
  a,b,c,d = map(int, input().split())
  if (sl[b]-tl[d]-sl[a-1]+tl[c-1])%3 == 0:
    print("YES")
  else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = sorted(list(map(int, input().split())),reverse=True)
mintot = sum(a)
cnt = 1
for i in range(n):
  tot -= a[i]
  if a[i] <= tot*2:
    break
  cnt += 1
print(cnt)

Fixed submission:
n = int(input())
a = sorted(list(map(int, input().split())),reverse=True)
tot = sum(a)
cnt = 1
for i in a:
  tot -= i
  if i > tot*2:
    break
  cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
tree = [list() for _ in  range(n+1)]
for i in range(2,n+1):
  a = int(input())
  tree[a].append(i)
win = [0]*(n+1)
  
def dfs(v,win):
  if tree[v] == []:
    win[v] = 0 
    return win[v]
  l = list()
  for x in tree[v]:
    dfs(x,win)
    l.append(win[x])
  l.sort(reverse=True)
  win[v] = max(i+1+l[i] for i in range(len(l)))
  return win[v]

print(dfs(1,win))

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
tree = [list() for _ in  range(n+1)]
for i in range(2,n+1):
  a = int(input())
  tree[a].append(i)
win = [0]*(n+1)
  
def dfs(v,win):
  if tree[v] == []:
    win[v] = 0 
    return win[v]
  l = list()
  for x in tree[v]:
    dfs(x,win)
    l.append(win[x])
  l.sort(reverse=True)
  win[v] = max(i+1+l[i] for i in range(len(l)))
  return win[v]

print(dfs(1,win))
Buggy python submission (verdict: Runtime Error):
a, op, b =[i for i in input()]
if op == "+":
  print(int(a) + int(b))
else:
  print(int(a) - int(b))

Fixed submission:
a, op, b =[i for i in input().split()]
if op == "+":
  print(int(a) + int(b))
else:
  print(int(a) - int(b))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
t = [a.count(i) for i in range(n)]
for i in range(n//2):
  if t[i*2+n%2] != 0 or t[i*2+1+n%2] != 2 or t[0] > 1:
    print(0)
    exit()
print(2**(n//2))

Fixed submission:
a, op, b =[i for i in input().split()]
if op == "+":
  print(int(a) + int(b))
else:
  print(int(a) - int(b))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
d = {}
s = 1
b = 1
m = 1 - n%2
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
for i in range(n):
    if i % 2 == m:
        if (i > 0 and d[i] != 2) or (i == 0 and d[i] != 1):
            b = 0
            break
        s *= d[i]
    elif i in d:
        b = 0
        break
if b:
    print(s)
else:
    print(0)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
d = dict()
mod = 10**9 + 7
for i in l:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1
d2 = dict()
for i in range(1+n%2,n,2):
  d2[i] = 2
if n%2:
  d2[0] = 1
if d == d2:
  print(2**(n//2)%mod)
else:
  print(0)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
t = [a.count(i) for i in range(n)]
for i in range(n//2):
  if t[i*2+n%2] != 0 or t[i*2+1+n%2] != 2 or t[0] > 1:
    print(0)
    exit()
print(2**(n//2))

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
d = dict()
mod = 10**9 + 7
for i in l:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1
d2 = dict()
for i in range(1+n%2,n,2):
  d2[i] = 2
if n%2:
  d2[0] = 1
if d == d2:
  print(2**(n//2)%mod)
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
t = [a.count(i) for i in range(n)]
for i in range(n//2):
  if t[i*2+n%2] != 0 or t[i*2+1+n%2] != 2: or t[0] > 1:
    print(0)
    exit()
print(2**(n//2))

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
d = dict()
mod = 10**9 + 7
for i in l:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1
d2 = dict()
for i in range(1+n%2,n,2):
  d2[i] = 2
if n%2:
  d2[0] = 1
if d == d2:
  print(2**(n//2)%mod)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
v = {a, e, i, o, u}
if input() in v:
  print("vowel")
else:
  print("consonant")

Fixed submission:
v = set("aeiou")
if input() in v:
  print("vowel")
else:
  print("consonant")
Buggy python submission (verdict: Runtime Error):
h, _ = map(int, input().split())
for i in range(h):
  a = input()
  print(a)*2

Fixed submission:
h, _ = map(int, input().split())
for i in range(h):
  a = input()
  print(a)
  print(a)
Buggy python submission (verdict: Runtime Error):
a, b, x = map(int, input().split())
ans = b//x - a//x
if a%x == 0:
  ans += 1
print(ans)

Fixed submission:
s = input().split()
c = [t[0] for t in s]
print("".join(c))
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
l = list(map(int, input().split()))
tot = 0
for i in range(1,n):
  if a[i-1] + a[i] > k:
    c = min(a[i],k-(a[i]+a[i-1]))
    tot += c
    a[i] -= c
    if a[i-1]+a[i] > k:
      d = k-a[i-1]
      tot += d
      a[i-1] -= d
print(tot)

Fixed submission:
n,k = map(int, input().split())
a = list(map(int, input().split()))
tot = 0
for i in range(1,n):
  if a[i-1] + a[i] > k:
    c = min(a[i],a[i]+a[i-1]-k)
    tot += c
    a[i] -= c
    if a[i-1]+a[i] > k:
      d = a[i-1]-k
      tot += d
      a[i-1] -= d
print(tot)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq as h
stdin = sys.stdin

ni = lambda: int(ns())
nl = lambda: list(map(int, stdin.readline().split()))
nm = lambda: map(int, stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

def dist(p,q):
  px,py,pr = p
  qx,qy,qr = q
  d = ((px-qx)**2 + (py-qy)**2)**.5
  return max(d-(pr+qr),0)
  
  

xs,ys,xt,yt = nm()
n = ni()
pl = [(xs,ys,0)] + [tuple(nm()) for _ in range(n)] + [(xt,yt,0)]
gr = [dict() for _ in range(n+2)]
for i in range(n+1):
  for j in range(i+1,n+2):
    gr[i][j] = dist(pl[i],pl[j])
    gr[j][i] = gr[i][j]

dis = [float("inf")]*(n+2)
q = [(0,0)]
while q:
  d,v = h.heappop(q)
  if dis[v] <= d:
    continue
  dis[v] = d
  for x in gr[v]:
    if dis[x] > dis[v]+gr[v][x]:
      h.heappush(q,(dis[v]+gr[v][x],x))
print(dis[-1])

Fixed submission:
import sys
import heapq as h
stdin = sys.stdin

ni = lambda: int(ns())
nl = lambda: list(map(int, stdin.readline().split()))
nm = lambda: map(int, stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

def dist(p,q):
  px,py,pr = p
  qx,qy,qr = q
  d = ((px-qx)**2 + (py-qy)**2)**.5
  return max(d-(pr+qr),0)
  
  

xs,ys,xt,yt = nm()
n = ni()
pl = [(xs,ys,0)] + [tuple(nm()) for _ in range(n)] + [(xt,yt,0)]
gr = [dict() for _ in range(n+2)]
for i in range(n+1):
  for j in range(i+1,n+2):
    gr[i][j] = dist(pl[i],pl[j])
    gr[j][i] = gr[i][j]

dis = [float("inf")]*(n+2)
q = [(0,0)]
while q:
  d,v = h.heappop(q)
  if dis[v] <= d:
    continue
  dis[v] = d
  for x in gr[v]:
    if dis[x] > dis[v]+gr[v][x]:
      h.heappush(q,(dis[v]+gr[v][x],x))
print(dis[-1])
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [input().split() for _ in range(h)]
al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(h):
  for j in range(w):
    if s[i][j] = "snuke":
      print("{}{}".format(al[i], j+1))
      exit()
    else:
      pass

Fixed submission:
h, w = map(int, input().split())
s = [input().split() for _ in range(h)]
al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(h):
  for j in range(w):
    if s[i][j] == "snuke":
      print("{}{}".format(al[j], i+1))
      exit()
    else:
      pass
Buggy python submission (verdict: Runtime Error):
n = int(input())
k = int((n*2)**.5)
while k*(k+1)//2 < n:
  k += 1
l = [range(1,k+1)]
if k*(k+1)//2-n:
  l.remove(k*(k+1)//2-n)
for i in l:
  print(l)

Fixed submission:
n = int(input())
k = int((n*2)**.5)
while k*(k+1)//2 < n:
  k += 1
l = list(range(1,k+1))
if k*(k+1)//2-n:
  l.remove(k*(k+1)//2-n)
for i in l:
  print(i)
Buggy python submission (verdict: Runtime Error):
s = input()
ans = 0
for i in range(len(s-1)):
  if s[i] != s[i+1]:
    ans += 1
print(ans)

Fixed submission:
s = input()
ans = 0
for i in range(len(s)-1):
  if s[i] != s[i+1]:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ts, as = map(int, input().split())
for _ in range(n-1):
  t, a = map(int, input().split())
  m = max((ts-1)//t, (as-1)//a)+1
  ts = m*t
  as = m*a
print(ts+as)

Fixed submission:
n = int(input())
t2, a2 = map(int, input().split())
for _ in range(n-1):
  t, a = map(int, input().split())
  m = max((t2-1)//t, (a2-1)//a)+1
  t2 = m*t
  a2 = m*a
print(t2+a2)
Buggy python submission (verdict: Runtime Error):
s = input()
print(n//2-s.count("p"))

Fixed submission:
s = input()
m = "gp"*(len(s)//2+1)
g = 0
for i in range(len(s)):
  if s[i] == m[i]:
    continue
  elif s[i] == "p":
    g -= 1
  else:
    g += 1
print(g)

Buggy python submission (verdict: Runtime Error):
s = input()
m = "gp"*(len(s)//2+1)
g = 0
for i in range(s):
  if s[i] == m[i]:
    continue
  elif s[i] == "p":
    g -= 1
  else:
    g += 1
print(g)

Fixed submission:
s = input()
m = "gp"*(len(s)//2+1)
g = 0
for i in range(len(s)):
  if s[i] == m[i]:
    continue
  elif s[i] == "p":
    g -= 1
  else:
    g += 1
print(g)
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
s = input()
cnt = a+b
fc = b
for i in range(n):
  if s[n] == 'a' and cnt:
    print("Yes")
    cnt -= 1
  elif s[n] == 'b' and cnt and fc:
    print("Yes")
    cnt -= 1
    fc -= 1
  else:
    print("No")

Fixed submission:
n, a, b = map(int, input().split())
s = input()
cnt = a+b
fc = b
for i in range(n):
  if s[i] == 'a' and cnt:
    print("Yes")
    cnt -= 1
  elif s[i] == 'b' and cnt and fc:
    print("Yes")
    cnt -= 1
    fc -= 1
  else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
d = dict()
for i in range(n):
  d[a[i]] = i
b = [0]*n
tot = 0
for i in range(n,0,-1):
  b[d[i]] = n
  l,r = d[i],d[i]+1
  lb = 1
  rb = 1
  while l>0 and b[l-1] > i:
    l -= 1
    lb += 1
  while r<n and b[r] > i:
    r += 1
    rb += 1
  tot += lb*rb*i
print(tot)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
p = [0]*(n+1)
ans = 0
for i in range(n):
  p[a[i]] = i+1
l = [i-1 for i in range(n+2)]
l[0] = 0
r = [i+1 for i in range(n+2)]
r[-1] = n+1
for i in range(n,0,-1):
  ans += (p[i]-l[p[i]])*(r[p[i]]-p[i])*i
  l[r[p[i]]] = l[p[i]]
  r[l[p[i]]] = r[p[i]]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
ans = 0
for i in range(1,n+1):
  l,r = i,i
  while a[l-1] > a[i]:
    l -= 1
  while a[r+1] > a[i]:
    r += 1
  ans += a[i]*(i-l+1)*(r-i+1)
print(ans)


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
p = [0]*(n+1)
ans = 0
for i in range(n):
  p[a[i]] = i+1
l = [i-1 for i in range(n+2)]
l[0] = 0
r = [i+1 for i in range(n+2)]
r[-1] = n+1
for i in range(n,0,-1):
  ans += (p[i]-l[p[i]])*(r[p[i]]-p[i])*i
  l[r[p[i]]] = l[p[i]]
  r[l[p[i]]] = r[p[i]]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
ans = 0
for i in range(1,n+1):
  l,r = i,i
  while a[l-1] > a[i]:
    l -= 1
  while a[r+1] > a[i]:
    r += 1
  ans += a[i]*(i-l+1)*(r-i+1)
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
p = [0]*(n+1)
ans = 0
for i in range(n):
  p[a[i]] = i+1
l = [i-1 for i in range(n+2)]
l[0] = 0
r = [i+1 for i in range(n+2)]
r[-1] = n+1
for i in range(n,0,-1):
  ans += (p[i]-l[p[i]])*(r[p[i]]-p[i])*i
  l[r[p[i]]] = l[p[i]]
  r[l[p[i]]] = r[p[i]]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
  l,r = 1,1
  while i-l > -1 and a[i-l] > a[i]:
    l += 1
  while i+r < n and a[i+r] > a[i]:
    r += 1
  ans += l*r*a[i]
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
p = [0]*(n+1)
ans = 0
for i in range(n):
  p[a[i]] = i+1
l = [i-1 for i in range(n+2)]
l[0] = 0
r = [i+1 for i in range(n+2)]
r[-1] = n+1
for i in range(n,0,-1):
  ans += (p[i]-l[p[i]])*(r[p[i]]-p[i])*i
  l[r[p[i]]] = l[p[i]]
  r[l[p[i]]] = r[p[i]]
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
  l,r = 1,1
  while a[i-l] > a[i] and i-l > -1:
    l += 1
  while a[i+r] > a[i] and i+r < n:
    r += 1
  ans += l*r*a[i]
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
p = [0]*(n+1)
ans = 0
for i in range(n):
  p[a[i]] = i+1
l = [i-1 for i in range(n+2)]
l[0] = 0
r = [i+1 for i in range(n+2)]
r[-1] = n+1
for i in range(n,0,-1):
  ans += (p[i]-l[p[i]])*(r[p[i]]-p[i])*i
  l[r[p[i]]] = l[p[i]]
  r[l[p[i]]] = r[p[i]]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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

def slide(a, k):
  q = deque()
  ans = 0
  for i in range(-k,0):
    while q and a[q[-1]] > a[i]: q.pop()
    q.append(i)
  for i in range(n):
    if q[0] <= i-k: q.popleft()
    while q and a[q[-1]] > a[i]: q.pop()
    q.append(i)
    ans += a[q[0]]
  return ans

print(min(slide(a,k+1) + x*k for k in range(n)))

Fixed submission:
n,x = map(int, input().split())
a = list(map(int, input().split()))
cost = a[:]
use = [i for i in range(n)]
ans = sum(a)
for k in range(1,n):
  for i in range(n):
    j = (i-k)%n
    if cost[i] > a[j]:
      cost[i] = a[j]
      use[i] = j
  cur = k*x + sum(cost)
  if ans > cur:
    ans = cur
print(ans)
Buggy python submission (verdict: Runtime Error):
n,a = map(int,input().split())
dp = [[0]*2000 for _ in range(n+1)]
dp[0][1000] = 1
x = list(map(int,input().split()))
for i in range(n):
  x[i] -= a
for i in range(1,n+1):
  for j in range(2001):
    dp[i][j] = dp[i-1][j] + dp[i-1][j-x[i-1]]
print(dp[n][1000])

Fixed submission:
n,a = map(int,input().split())
dp = [[0]*2000 for _ in range(n+1)]
dp[0][1000] = 1
x = list(map(int,input().split()))
for i in range(n):
  x[i] -= a
for i in range(n):
  for j in range(2000):
    dp[i+1][j] += dp[i][j]
    if 0<=j+x[i]<2000:
      dp[i+1][j+x[i]] += dp[i][j]
print(dp[n][1000]-1)
Buggy python submission (verdict: Runtime Error):
s = input()
if ~("N" in s ^ "S" in s) and ~("E" in s ^ "W" in s):
  print("Yes")
else:
  print("No")

Fixed submission:
s = input()
b, c = 0, 0
if "N" in s and "S" in s:
  b = 1
elif "N" not in s and "S" not in s:
  b = 1
if "E" in s and "W" in s:
  c = 1
elif "E" not in s and "W" not in s:
  c = 1
if b and c:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = len(input())
mod = 10**9+7
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
  dp[i][0] = (dp[i-1][0] + dp[i-1][1])%mod
  for j in range(1,min(n,i+1)):
    dp[i][j] = (dp[i-1][j-1]*2 + dp[i-1][j+1])%mod
  dp[i][n] = dp[i-1][n-1]*2%mod
s2 = pow(2,s,mod)
rev = pow(s2,mod-2,mod)
print(dp[n][s]*rev%mod)


Fixed submission:
n = int(input())
s = len(input())
mod = 10**9+7
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
  dp[i][0] = (dp[i-1][0] + dp[i-1][1])%mod
  for j in range(1,n):
    dp[i][j] = (dp[i-1][j-1]*2 + dp[i-1][j+1])%mod
  dp[i][n] = dp[i-1][n-1]*2%mod
s2 = pow(2,s,mod)
rev = pow(s2,mod-2,mod)
print(dp[n][s]*rev%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = len(input())
mod = 10**9+7
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
  dp[i][0] = (dp[i-1][0] + dp[i-1][1])%mod
  for j in range(1,n):
    dp[i][j] = (dp[i-1][j-1]*2 + dp[i-1][j+1])%mod
  dp[i][n] = dp[i-1][n-1]*2%mod
s2 = pow(2,s,mod)
rev = pow(s2,mod-2,mod)
print(dp[n][s]*rev%mod)

Fixed submission:
n = int(input())
s = len(input())
mod = 10**9+7
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
  dp[i][0] = (dp[i-1][0] + dp[i-1][1])%mod
  for j in range(1,n):
    dp[i][j] = (dp[i-1][j-1]*2 + dp[i-1][j+1])%mod
  dp[i][n] = dp[i-1][n-1]*2%mod
s2 = pow(2,s,mod)
rev = pow(s2,mod-2,mod)
print(dp[n][s]*rev%mod)
Buggy python submission (verdict: Runtime Error):
if sorted(input().split()) == ["5", "5", "7"]:
  print("YES")
else:
  priny("NO")

Fixed submission:
if sorted(input().split()) == ["5", "5", "7"]:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
n=int(input())
patterns = ["a"]
for _ in range(n-1):
    last_patterns = patterns.copy()
    patterns = []
    for string in last_patterns:
        useful_str = alpha[:len(set(string))+1]
        for str_ in useful_str:
            patterns.append(string + str_)

for pat in patterns:
    print(pat)

Fixed submission:
alpha = "abcdefghij"
n=int(input())
patterns = ["a"]
for _ in range(n-1):
    last_patterns = patterns.copy()
    patterns = []
    for string in last_patterns:
        useful_str = alpha[:len(set(string))+1]
        for str_ in useful_str:
            patterns.append(string + str_)

for pat in patterns:
    print(pat)
Buggy python submission (verdict: Runtime Error):
n_list = set(input().split())

if len(n_list)= 2:
  print("Yes")
else:
  print("No")

Fixed submission:
n_list = set(input().split())

if len(n_list)== 2:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n =int(input())
slist = []
for _ in range(n):
  s = input()
  slist.appemd(s)

Counter(slist)

Fixed submission:
from collections import defaultdict

n =int(input())

d = defaultdict(int)

for _ in range(n):
    s = input()
    d[s] += 1

result = sorted(d.items(), key=lambda x: -x[1])

max_val = 0
maxes = []
for r in result:
    if max_val > r[1]:
        break
    else:
        max_val = r[1]
        maxes.append(r[0])

print("\n".join(sorted(maxes)))
Buggy python submission (verdict: Runtime Error):
n =int(input())
a_n = set(map(int, inpt.split()))

if n==len(a_n):
    print("YES")
else:
    print("NO")

Fixed submission:
n =int(input())
a_n = set(map(int, input().split()))

if n==len(a_n):
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
n, k, q = list(map(int, input().split()))
score_b = [k - q]*n
for a in range(q):
    score_b[int(input())-1] += 1
for i in score_b:
    if i >0:
        print("Yes")
    else:
        print("No")

Fixed submission:
s = input()
weather = {"Sunny":"Cloudy",
          "Cloudy":"Rainy",
          "Rainy":"Sunny"}
print(weather[s])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
_, m = list(map(int, input().split()))
a = np.array(list(map(int, input().split())))

for i in range(m):
    a[np.argmax(a)] /=2

print(int(np.floor(a).sum()))

Fixed submission:
import heapq
h = []
N, M = map(int, input().split())
As = list(map(int, input().split()))
for i in As:
    heapq.heappush(h, -i)
for _ in range(M):
    i = heapq.heappop(h)
    i = -1 * (-i // 2)
    heapq.heappush(h, i)
 
print(sum([-1 * heapq.heappop(h) for i in range(len(h))]))