Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
a = input()
n = int(input())
b = 1
for i in range(n):
    q = input()
    if q == "1":
        b = (b+1)%2
    else:
        q,f,c = q.split()
        if int(f)%2 == b:
            a = c+a
        else:
            a = a+c
if b == 0:
    a = a[::-1]
print(a)

Fixed submission:
a = input()
n = int(input())
rev = False
front = []
back = []
q = [input() for i in range(n)]
for i in q:
    if i == "1":
        rev = not rev
    else:
        i,f,c = i.split()
        if rev == False:
            if f == "1":
                front.append(c)
            else:
                back.append(c)
        else:
            if f == "1":
                back.append(c)
            else:
                front.append(c)
if rev == False:
    print("".join(list(reversed(front))+[a]+back))
else:
    print("".join(list(reversed(back))+[a[::-1]]+front))

Buggy python submission (verdict: Time Limit Exceeded):
a = input()
n = int(input())
for i in range(n):
    q = input()
    if q == "1":
        a = a[::-1]
    else:
        q,f,c = q.split()
        if f == "1":
            a = c+a
        else:
            a = a+c
print(a)

Fixed submission:
a = input()
n = int(input())
rev = False
front = []
back = []
q = [input() for i in range(n)]
for i in q:
    if i == "1":
        rev = not rev
    else:
        i,f,c = i.split()
        if rev == False:
            if f == "1":
                front.append(c)
            else:
                back.append(c)
        else:
            if f == "1":
                back.append(c)
            else:
                front.append(c)
if rev == False:
    print("".join(list(reversed(front))+[a]+back))
else:
    print("".join(list(reversed(back))+[a[::-1]]+front))

Buggy python submission (verdict: Time Limit Exceeded):
a = input()
n = int(input())
for i in range(n):
    q = input()
    if q == "1":
        a = a[::-1]
    else:
        q,f,c = q.split()
        if f == "1":
            a = c+a
        else:
            a = a+c
print(a)

Fixed submission:
a = input()
n = int(input())
rev = False
front = []
back = []
q = [input() for i in range(n)]
for i in q:
    if i == "1":
        rev = not rev
    else:
        i,f,c = i.split()
        if rev == False:
            if f == "1":
                front.append(c)
            else:
                back.append(c)
        else:
            if f == "1":
                back.append(c)
            else:
                front.append(c)
if rev == False:
    print("".join(list(reversed(front))+[a]+back))
else:
    print("".join(list(reversed(back))+[a[::-1]]+front))
Buggy python submission (verdict: Runtime Error):
print(int(input)+1//2)

Fixed submission:
print((int(input())+1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
n,*a = map(int,open(0).read().split())
mod = 10**9+7
ans = 0
for i in range(61):
  b = sum(map(lambda x:x>>i&1,a))
  ans += b*(n-b)*1<<i
print(ans%mod)

Fixed submission:
import numpy as np
n,*a = map(int,open(0).read().split())
a = np.array(a)
mod = 10**9+7
ans = 0
for i in range(61):
  b = np.count_nonzero(a>>i&1)
  ans += b*(n-b)*1<<i
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n,*a = map(int,open(0).read().split())
mod = 10**9+7
print(sum([sum([a[i]^j for j in a[i+1:]]) for i in range(n-1)])%mod)

Fixed submission:
import numpy as np
n,*a = map(int,open(0).read().split())
a = np.array(a)
mod = 10**9+7
ans = 0
for i in range(61):
  b = np.count_nonzero(a>>i&1)
  ans += b*(n-b)*1<<i
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
a = set()
for i in range(n-2):
  for j in range(i+1,n-1):
    a = a|set([s[i]+s[j]+k for k in set(list(s[j+1:]))])
print(len(a))

Fixed submission:
n = int(input())
s = input()
a = set()
a1 = []
for i in range(n-2):
  if s[i] in a1:
    continue
  a1.append(s[i])
  a2 = []
  for j in range(i+1,n-1):
    if s[j] in a2:
      continue
    a2.append(s[j])
    a = a|set([s[i]+s[j]+k for k in set(list(s[j+1:]))])
print(len(a))
Buggy python submission (verdict: Runtime Error):
n,*a = map(int,open(0).read().split())
cnt = [3]+[0]*(n-2)
ans = 1
mod = 10**9+7
for i in a:
  ans = ans * cnt[i] % mod
  cnt[i] -= 1
  cnt[i+1] += 1
print(ans)

Fixed submission:
n,*a = map(int,open(0).read().split())
cnt = [3]+[0]*n
ans = 1
mod = 10**9+7
for i in a:
  ans = ans * cnt[i] % mod
  cnt[i] -= 1
  cnt[i+1] += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n,*a = map(int,open(0).read().split())
b = [0,0,0]
ans = 1
mod = 10**9+7
for i in a:
  ans = (ans * b.count(i)) % mod
  b.remove(i)
  b.append(i + 1)
print(ans)

Fixed submission:
n,*a = map(int,open(0).read().split())
cnt = [3]+[0]*n
ans = 1
mod = 10**9+7
for i in a:
  ans = ans * cnt[i] % mod
  cnt[i] -= 1
  cnt[i+1] += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
n,q = map(int,sys.stdin.readline().rstrip().split())
t = {}
for i in range(n-1):
    a,b = map(int,sys.stdin.readline().rstrip().split())
    if a in t:
        t[a].append(b)
    else:
        t[a] = [b]
ans = [0 for i in range(n)]

def search(j):
    if j in t:
        l = [j]
        for k in t[j]:
            l = l + search(k)
    else:
        l = [j]
    return l

for i in range(q):
    p,x = map(int,sys.stdin.readline().rstrip().split())
    s = search(p)
    for i in s:
        ans[i-1] += x
print(" ".join(map(str,ans)))

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
n,q = map(int,input().split())
tree = [[] for i in range(n)]
ans = [0]*n
for i in range(n-1):
    a,b = map(lambda x:int(x)-1,input().split())
    tree[a].append(b)
    tree[b].append(a)

for i in range(q):
    p,x = map(int, input().split())
    ans[p - 1] += x

d = deque([[0,0]])
c = [False]*n
c[0] = True
while d:
    x,s = d.pop()
    s += ans[x]
    ans[x] = s
    for e in tree[x]:
        if not c[e]:
            c[e] = True
            d.append([e,s])

print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
a = [1]*n
b = [0]*n
for i in range(10**6):
  if a == b:
    break
  b = list(a)
  for _ in range(2):
    da = [0]*n
    for j in range(n):
      if s[j] == "R":
        da[j+1] += a[j]
      else:
        da[j-1] += a[j]
    a = list(da)
print(*a)

Fixed submission:
s = input()
n = len(s)
rl = []
ll = []
c = 0
b = "R"
for i in range(n):
  if s[i] == b:
    c += 1
  else:
    if b == "R":
      rl.append(c)
      b = "L"
    else:
      ll.append(c)
      b = "R"
    c = 1
ll.append(c)
ans = []
for i,j in zip(rl,ll):
  ans += [0]*(i-1) + [i-i//2+j//2] + [i//2+j-j//2] + [0] *(j-1)
print(*ans)
Buggy python submission (verdict: Runtime Error):
n= int(input())
ab = [list(map(int,input().split())) for _ in range(n)]
pq = {}
for i in range(n-1):
  for j in range(i+1,n):
    a1,b1 = ab[i]
    a2,b2 = ab[j]
    p = a1-a2
    q = b1-b2
    if p<0:
      p = -p
      q = -q
    if (p,q) in pq:
      pq[(p,q)] += 1
    else:
      pq[(p,q)] = 1
print(n-max(pq.values()))

Fixed submission:
n= int(input())
if n == 1:
  print(1)
  exit()
ab = [list(map(int,input().split())) for _ in range(n)]
pq = {}
for i in range(n-1):
  for j in range(i+1,n):
    a1,b1 = ab[i]
    a2,b2 = ab[j]
    p = a1-a2
    q = b1-b2
    if p<0 or p==0 and q<0:
      p = -p
      q = -q
    if (p,q) in pq:
      pq[(p,q)] += 1
    else:
      pq[(p,q)] = 1
print(n-max(pq.values()))

Buggy python submission (verdict: Runtime Error):
from collections import Counter
n= int(input())
ab = [list(map(int,input().split())) for _ in range(n)]
pq = []
for i in range(n-1):
  for j in range(i+1,n):
    a1,b1 = ab[i]
    a2,b2 = ab[j]
    p = a1-a2
    q = b1-b2
    if p<0:
      p = -p
      q = -q
    pq.append((p,q))
c = Counter(pq)
print(n-c.most_common()[0][1])

Fixed submission:
n= int(input())
if n == 1:
  print(1)
  exit()
ab = [list(map(int,input().split())) for _ in range(n)]
pq = {}
for i in range(n-1):
  for j in range(i+1,n):
    a1,b1 = ab[i]
    a2,b2 = ab[j]
    p = a1-a2
    q = b1-b2
    if p<0 or p==0 and q<0:
      p = -p
      q = -q
    if (p,q) in pq:
      pq[(p,q)] += 1
    else:
      pq[(p,q)] = 1
print(n-max(pq.values()))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
h,w = map(int,input().split())
s = [list(input().strip()) for _ in range(h)]
l = [[0]*w for _ in range(h)]
r = [[0]*w for _ in range(h)]
u = [[0]*w for _ in range(h)]
d = [[0]*w for _ in range(h)]
for i in range(h):
  c1 = 0
  c2 = 0
  for j in range(w):
    if s[i][j] == "#":
      c1 = 0
    else:
      c1 += 1
      l[i][j] = c1
    if s[i][w-j-1] == "#":
      c2 = 0
    else:
      c2 += 1
      r[i][w-j-1] = c2
for j in range(w):
  c1 = 0
  c2 = 0
  for i in range(h):
    if s[i][j] == "#":
      c1 = 0
    else:
      c1 += 1
      u[i][j] = c1
    if s[h-i-1][j] == "#":
      c2 = 0
    else:
      c2 += 1
      d[h-i-1][j] = c2
ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)
print(ans)

Fixed submission:
import sys
import numpy as np
input = sys.stdin.readline
h,w = map(int,input().split())
s = (np.array([list(input().strip()) for _ in range(h)])==".").astype(np.int)
l,r,u,d = s.copy(),s.copy(),s.copy(),s.copy()
for i in range(1,w):
  l[:,i] *= l[:,i-1] + 1
  r[:,w-i-1] *= r[:,w-i] + 1

for i in range(1,h):
  u[i] *= u[i-1] + 1
  d[h-i-1] *= d[h-i] + 1
print(max([max(i) for i in l+r+u+d-3]))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  from collections import Counter
  n = int(input())
  s = input()
  mod = 10**9+7
  c = Counter(s)
  cv = list(c.values())
  cl = len(cv)
  ans = 0
  for i in range(1,1<<cl):
    da =1
    for j in range(cl):
      if (i>>j)%2:
        da *= cv[j]
    ans += da%mod
  print(ans%mod)
main()

Fixed submission:
def main():
  from collections import Counter
  n = int(input())
  s = input()
  mod = 10**9+7
  c = Counter(s)
  cv = list(c.values())
  cl = len(cv)
  ans = 1
  for i in range(cl):
    ans *= (cv[i]+1)
  print((ans-1)%mod)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  from collections import Counter
  n = int(input())
  s = input()
  mod = 10**9+7
  c = Counter(s)
  cv = list(c.values())
  cl = len(cv)
  ans = 0
  for i in range(1,1<<cl):
    da =1
    for j in range(cl):
      if (i>>j)%2:
        da *= cv[j]
    ans += da%mod
  print(ans%mod)
main()

Fixed submission:
def main():
  from collections import Counter
  n = int(input())
  s = input()
  mod = 10**9+7
  c = Counter(s)
  cv = list(c.values())
  cl = len(cv)
  ans = 1
  for i in range(cl):
    ans *= (cv[i]+1)
  print((ans-1)%mod)
main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
s = input()
mod = 10**9+7
c = Counter(s)
cv = list(c.values())
cl = len(cv)
ans = 0
for i in range(1,1<<cl):
  da =1
  for j in range(cl):
    if (i>>j)%2:
      da *= cv[j]
  ans += da%mod
print(ans%mod)

Fixed submission:
def main():
  from collections import Counter
  n = int(input())
  s = input()
  mod = 10**9+7
  c = Counter(s)
  cv = list(c.values())
  cl = len(cv)
  ans = 1
  for i in range(cl):
    ans *= (cv[i]+1)
  print((ans-1)%mod)
main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
a = sorted(list(set(a)))
while len(a) > 1:
  b = a.pop()
  d = []
  for i in a:
    c = b%i
    if c != 0:
      d.append(c)
  a = sorted(list(set(d+a)))
print(a[0])

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
a = sorted(list(set(a)))
while len(a) > 1:
  b = a.pop(0)
  d = []
  for i in a:
    c = i%b
    if c != 0:
      d.append(c)
  a = sorted(list(set(d+[b])))
print(a[0])
Buggy python submission (verdict: Runtime Error):
n,m,*x = map(int,open(0).read().split())
x.sort()
if m == 1:
  print(0)
  exit()
a = sorted([x[i+1]-x[i] for i in range(m-1)],reverse=True)
ans = x[-1]-x[0]
for i in range(n-1):
  ans -= a[i]
print(ans)

Fixed submission:
n,m,*x = map(int,open(0).read().split())
x.sort()
if n >= m:
  print(0)
  exit()
a = sorted([x[i+1]-x[i] for i in range(m-1)],reverse=True)
ans = x[-1]-x[0]
for i in range(n-1):
  ans -= a[i]
print(ans)

Buggy python submission (verdict: Runtime Error):
n,m,*x = map(int,open(0).read().split())
x.sort()
a = sorted([x[i+1]-x[i] for i in range(m-1)],reverse=True)
ans = x[-1]-x[0]
for i in range(n-1):
  ans -= a[i]
print(ans)

Fixed submission:
n,m,*x = map(int,open(0).read().split())
x.sort()
if n >= m:
  print(0)
  exit()
a = sorted([x[i+1]-x[i] for i in range(m-1)],reverse=True)
ans = x[-1]-x[0]
for i in range(n-1):
  ans -= a[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
n,m=map(int,input().split())
s = input()
t = input()
g = gcd(n,m)
ng = n//g
mg = m//g
for i in range(g):
    if s[ng*i]!=t[mg*i]):
        print("-1")
        break
else:
    print(n*m//g)

Fixed submission:
from fractions import gcd
n,m=map(int,input().split())
s = input()
t = input()
g = gcd(n,m)
ng = n//g
mg = m//g
for i in range(g):
    if s[ng*i]!=t[mg*i]:
        print("-1")
        break
else:
    print(n*m//g)
Buggy python submission (verdict: Time Limit Exceeded):
n,*v = map(int,open(0).read().split())
v1 = v[::2]
v2 = v[1::2]
v1 = sorted([(i,v1.count(i)) for i in set(v1)],key =lambda x:x[1],reverse=True)
v2 = sorted([(i,v2.count(i)) for i in set(v2)],key =lambda x:x[1],reverse=True)
if len(v1) == 1:
  if len(v2) == 1:
    if v1[0][0] != v2[0][0]:
      print(0)
    else:
      print(n//2)
  else:
    if v1[0][0] != v2[0][0]:
      print(n//2-v2[0][1])
    else:
      print(n//2-v2[1][1])
else:
  if len(v2) == 1:
    if v1[0][0] != v2[0][0]:
      print(n//2-v1[0][1])
    else:
      print(n//2-v1[1][1])
  else:
    if v1[0][0] != v2[0][0]:
      print(n-v1[0][1]-v2[0][1])
    else:
      print(min(n-v1[0][1]-v2[1][1],n-v1[1][1]-v2[0][1]))

Fixed submission:
from collections import Counter
n,*v = map(int,open(0).read().split())
v1 = Counter(v[::2])
v2 = Counter(v[1::2])
v1 = sorted([(i,v1[i]) for i in v1.keys()],key =lambda x:x[1],reverse=True)
v2 = sorted([(i,v2[i]) for i in v2.keys()],key =lambda x:x[1],reverse=True)
if v1[0][0] != v2[0][0]:
  print(n-v1[0][1]-v2[0][1])
else:
  e1 = n-v2[0][1] if len(v1) == 1 else n-v1[1][1]-v2[0][1]
  e2 = n-v1[0][1] if len(v2) == 1 else n-v1[0][1]-v2[1][1]
  print(min(e1,e2))
Buggy python submission (verdict: Runtime Error):
n,*a = map(int,open(0).read().split())
a = [a[i] -i -1 for i in range(n)]
a.sort()
if n % 2 == 0:
  b = a[n//2]
  c = b + 1
else:
  b = (a[n//2]+a[n//2+1])//2
  c = b + 2
ans = min([sum([abs(i - j) for i in a]) for j in range(b,c)])
print(ans)

Fixed submission:
n,*a = map(int,open(0).read().split())
a = sorted([a[i] -i for i in range(n)])
print(sum([abs(i - a[n//2]) for i in a]))

Buggy python submission (verdict: Runtime Error):
n,*a = map(int,open(0).read().split())
a = [a[i] -i -1 for i in range(n)]
a.sort()
b = a[n//2]
if n % 2 == 0:
  c = b + 1
else:
  c = a[n//2+1]+1
ans = min([sum([abs(i - j) for i in a]) for j in range(b,c)])
print(ans)

Fixed submission:
n,*a = map(int,open(0).read().split())
a = sorted([a[i] -i for i in range(n)])
print(sum([abs(i - a[n//2]) for i in a]))

Buggy python submission (verdict: Runtime Error):
n,*a = map(int,open(0).read().split())
a = [a[i] -i -1 for i in range(n)]
a.sort()
print(a)
b = a[n//2]
if n % 2 == 0:
  c = b + 1
else:
  c = a[n//2+1]+1
ans = min([sum([abs(i - j) for i in a]) for j in range(b,c)])
print(ans)

Fixed submission:
n,*a = map(int,open(0).read().split())
a = sorted([a[i] -i for i in range(n)])
print(sum([abs(i - a[n//2]) for i in a]))

Buggy python submission (verdict: Runtime Error):
n,*a = map(int,open(0).read().split())
a = [a[i] -i -1 for i in range(n)]
a.sort()
print(a)
b = a[n//2]
if n % 2 == 0:
  c = b + 1
else:
  c = a[n//2+1]+1
ans = min([sum([abs(i - j) for i in a]) for j in range(b,c)])
print(ans)

Fixed submission:
n,*a = map(int,open(0).read().split())
a = sorted([a[i] -i for i in range(n)])
print(sum([abs(i - a[n//2]) for i in a]))
Buggy python submission (verdict: Time Limit Exceeded):
h,w,d = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(h)]
q = int(input())
lr = [list(map(int,input().split())) for _ in range(q)]
b = [0]*(h*w+1)
for i in range(h):
  for j in range(w):
    b[a[i][j]] = (i,j)
for l,r in lr:
  ans = 0
  while(l!=r):
    i,j = b[l]
    l += d
    x,y = b[l]
    ans += abs(x-i)+abs(y-j)
    x += d
  print(ans)

Fixed submission:
h,w,d = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(h)]
q = int(input())
lr = [list(map(int,input().split())) for _ in range(q)]
b = [0]*(h*w+1)
for i in range(h):
  for j in range(w):
    b[a[i][j]] = (i,j)
c = [0]*(h*w+1)
for i in range(d+1,h*w+1):
  c[i] = c[i-d] + abs(b[i][0]-b[i-d][0])+abs(b[i][1]-b[i-d][1])
for l,r in lr:
  print(c[r]-c[l])
Buggy python submission (verdict: Runtime Error):
def main():
  h,w = map(int,input().split())
  s = [input() for _ in range(h)]
  c = [[10**5]*w for _ in range(h)]
  #print(sum([i.count(".") for i in s]))
  
  def func(dh,dw,step):
    if dh<0 or dw<0 or dh>=h or dw>=w:
      return
    step += 1
    if s[dh][dw] == ".":
      if c[dh][dw] > step:
        c[dh][dw] = step
        for i,j in ((1,0),(0,1),(-1,0),(0,-1)):
          func(dh+i,dw+j,step)
  
  func(0,0,0)
  if c[h-1][w-1] == 10**5:
    return -1
  else:
    return sum([i.count(".") for i in s])-c[h-1][w-1]

print(main())

Fixed submission:
from collections import deque
def main():
  h,w = map(int,input().split())
  s = [input() for _ in range(h)]
  #print(sum([i.count(".") for i in s]))
  
  def bfs(st):
    que = deque([st])
    c = [[0]*w for _ in range(h)]
    while que:
      ph,pw = que.popleft()
      step = c[ph][pw] + 1
      for dh,dw in ((1,0),(0,1),(-1,0),(0,-1)):
        nh = ph+dh
        nw = pw+dw
        if nh<0 or nw<0 or nh>=h or nw>=w:
          continue
        if s[nh][nw]=="#" or c[nh][nw] != 0:
          continue
        c[nh][nw] = step
        if (nh,nw) == (h-1,w-1):
          return step
        que.append((nh,nw))
  
  result = bfs((0,0))
  if result:
    return sum([i.count(".") for i in s])-result-1
  else:
    return -1

print(main())
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  from collections import Counter
  n,k,*a = map(int,open(0).read().split())
  a = Counter(a)
  ans = 0
  for i in range(max(0,len(a)-k)):
    ans += a.most_common()[-1-i][1]
  print(ans)
main()

Fixed submission:
n,k,*a = map(int,open(0).read().split())
b = {}
for i in a:
  if i in b:
    b[i] += 1
  else:
    b[i] = 1
ans = 0
a = sorted(list(b.values()))
for i in range(max(0,len(a)-k)):
  ans += a[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  from collections import Counter
  n,k,*a = map(int,open(0).read().split())
  a = Counter(a)
  ans = 0
  for i in range(max(0,len(a)-k)):
    ans += a.most_common()[-1-i][1]
  print(ans)
main()

Fixed submission:
n,k,*a = map(int,open(0).read().split())
b = {}
for i in a:
  if i in b:
    b[i] += 1
  else:
    b[i] = 1
ans = 0
a = sorted(list(b.values()))
for i in range(max(0,len(a)-k)):
  ans += a[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n,k,*a = map(int,open(0).read().split())
a = Counter(a)
ans = 0
for i in range(max(0,len(a)-k)):
  ans += a.most_common()[-1-i][1]
print(ans)

Fixed submission:
n,k,*a = map(int,open(0).read().split())
b = {}
for i in a:
  if i in b:
    b[i] += 1
  else:
    b[i] = 1
ans = 0
a = sorted(list(b.values()))
for i in range(max(0,len(a)-k)):
  ans += a[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
t = [[] for _ in range(n)]
for i in range(n-1):
  a,b,c = map(int,input().split())
  t[a-1].append((b-1,c))
  t[b-1].append((a-1,c))
q,k = map(int,input().split())
k -= 1
l = [0]*n
def dfs(a,b,c):
  for i,j in t[b]:
    if i != a:
      l[i] = c+j
      dfs(b,i,c+j)
dfs(-1,k,0)
for _ in range(q):
  x,y = map(lambda x:int(x)-1,input().split())
  print(l[x]+l[y])

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
n = int(input())
t = [[] for _ in range(n)]
for i in range(n-1):
  a,b,c = map(int,input().split())
  t[a-1].append((b-1,c))
  t[b-1].append((a-1,c))
q,k = map(int,input().split())
k -= 1
l = [0]*n
def dfs(a,b,c):
  for i,j in t[b]:
    if i != a:
      l[i] = c+j
      dfs(b,i,c+j)
dfs(-1,k,0)
for _ in range(q):
  x,y = map(lambda x:int(x)-1,input().split())
  print(l[x]+l[y])
Buggy python submission (verdict: Runtime Error):
import numpy as np
w,h,n = map(int,input().split())
d = np.zeros(w-1,h-1)
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        d[:w] = 1
    elif a == 2:
        d[w:] = 1
    elif a ==3:
        d[:,:h] = 1
    else:
        d[:,h:] = 1
print(np.count_nonzero(d==0))

Fixed submission:
w,h,n = map(int,input().split())
d = [0,w,0,h]
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1 :
        d[0] = max(d[0],x)
    elif a == 2:
        d[1] = min(d[1],x)
    elif a == 3:
        d[2] = max(d[2],y)
    else:
        d[3] = min(d[3],y)
print(max(0,(d[1]-d[0]))*max(0,(d[3]-d[2])))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
WPrefix = [0]
RSuffix = [0]
for elem in S:
    if elem == "R":
        RSuffix += 1
for elem in S:
    if elem == "R":
        RSuffix.append(RSuffix[-1] - 1)
        WPrefix.append(WPrefix[-1])
    else:
        RSuffix.append(RSuffix[-1])
        WPrefix.append(WPrefix[-1] + 1)
minSwap = len(S)
for index in range(len(RSuffix)):
    if max(RSuffix[index],WPrefix[index]) < minSwap:
        minSwap = max(RSuffix[index],WPrefix[index])
print(minSwap)


Fixed submission:
N = int(input())
S = input()
WPrefix = [0]
RSuffix = [0]
for elem in S:
    if elem == "R":
        RSuffix[0] += 1
for elem in S:
    if elem == "R":
        RSuffix.append(RSuffix[-1] - 1)
        WPrefix.append(WPrefix[-1])
    else:
        RSuffix.append(RSuffix[-1])
        WPrefix.append(WPrefix[-1] + 1)
minSwap = len(S)
for index in range(len(RSuffix)):
    if max(RSuffix[index],WPrefix[index]) < minSwap:
        minSwap = max(RSuffix[index],WPrefix[index])
print(minSwap)