Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02935 (python)

Fixed submission:
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))

  
def main():
    n = int(input())
    a = sorted(Input())
    while len(a) > 1:
        x, y = a[0], a[1]
        a[0:2] = [(x+y)/2]
    return a[0]


print(main())

Buggy submission (verdict: Runtime Error):
def Input():
    return mapt(int, input().split(" "))


def main():
    n = int(input())
    a = sorted(Input())
    while len(a) > 1:
        x, y = a[0], a[1]
        a[0:2] = [(x+y)/2]

    return a[0]


print(main())
Problem p03077 (python)

Fixed submission:
def main():
    n = int(input())
    data = [int(input()) for i in range(5)]
    quo, rem = divmod(n, min(data))
    quo = 5 + quo
    if rem:
        print(quo)
    else:
        print(quo - 1)

main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    data = [int(input()) for i in range(5)]
    quo, rem = divmod(n, min(data))
	print(4 + quo + bool(rem))

main()
Problem p03208 (python)

Fixed submission:
def main():
    n, k = map(int, input().split(" "))
    data = sorted(int(input()) for _ in range(n))
    print(min([data[i+k-1] - data[i] for i in range(n-k+1)]))
main()

Buggy submission (verdict: Runtime Error):
def main():
    n, k = Input()
    data = sorted(int(input()) for _ in range(n))
    print(min([data[i+k-1] - data[i] for i in range(n-k+1)]))
main()
Problem p02834 (python)

Fixed submission:
import sys
sys.setrecursionlimit(200000)

def dfs(array, current, count):
  array[current - 1] = count
  for neighbour in graph[current]:
    if array[neighbour - 1] == -1:
      array = dfs(array, neighbour, count + 1)
  else:
    return array

T = [-1 for x in range(100000)]
A = [-1 for x in range(100000)]

graph = {}

N,u,v = map(int,input().split())

for i in range(N-1):
  a,b = map(int,input().split())
  try:
    graph[a].append(b)
  except KeyError:
    graph[a] = [b]

  try:
    graph[b].append(a)
  except KeyError:
    graph[b] = [a]

T = dfs(T, u, 0)
A = dfs(A, v, 0)

ans = -1
for i in range(N):
  if T[i] < A[i]:
    ans = max(ans, A[i] - 1)
print(max(0,ans))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(200000)

def dfs(array, current, count):
  array[current - 1] = count
  for neighbour in graph[current]:
    if array[neighbour - 1] == -1:
      array = dfs(array, neighbour, count + 1)
  else:
    return array

T = [-1 for x in range(100000)]
A = [-1 for x in range(100000)]

graph = {}

N,u,v = map(int,input().split())

for i in range(N-1):
  a,b = map(int,input().split())
  try:
    graph[a].append(b)
  except KeyError:
    graph[a] = [b]

  try:
    graph[b].append(a)
  except KeyError:
    graph[b] = [a]

T = dfs(T, u, 0)
A = dfs(A, v, 0)

ans = -1
for i in range(N):
  if T[i] < A[i]:
    ans = max(ans, A[ImportError] - 1)
print(max(0,ans))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(110000)

def dfs(array, current, count):
  array[current - 1] = count
  for neighbour in graph[current]:
    if array[neighbour - 1] == -1:
      array = dfs(array, neighbour, count + 1)
  else:
    return array

T = [-1 for x in range(100000)]
A = [-1 for x in range(100000)]

graph = {}

N,u,v = map(int,input().split())

for i in range(N-1):
  a,b = map(int,input().split())
  try:
    graph[a].append(b)
  except KeyError:
    graph[a] = [b]

  try:
    graph[b].append(a)
  except KeyError:
    graph[b] = [a]

T = dfs(T, u, 0)
A = dfs(A, v, 0)

ans = -1
for i in range(N):
  if T[i+1] < A[i+1]:
    ans = max(ans, A[i+1] - 1)
print(max(0,ans))
Problem p03104 (python)

Fixed submission:
def F(N): return ((N + 1) // 2) % 2 if N & 1 else ((N // 2) % 2) ^ N
A,B = map(int,input().split())
print(F(A-1) ^ F(B))

Buggy submission (verdict: Runtime Error):
from math import log2, ceil

A,B = map(int,input().split())
N = B - A + 1

#class A
ng = N // 2
ng %= 2
ans = ng ^ (B & 1)

for i in range(2,ceil(log2(B)) + 2):
  #class B
  K = N % pow(2,i)
  A_bit = int((A & pow(2,i-1)) > 0)
  next_multiple_dist = ceil(A / pow(2,i-1)) * pow(2,i-1) - A
  if next_multiple_dist == 0:
    next_multiple_dist = pow(2,i-1)
  
  #010
  if A_bit == 0:
    if next_multiple_dist < K:
      K -= next_multiple_dist
      next_multiple_dist = pow(2,i-1)
      ans += pow(2,i-1) * (min(K,next_multiple_dist) % 2)
  #101
  else:
    if next_multiple_dist < K:
      num_1 = next_multiple_dist
      K -= next_multiple_dist
      next_multiple_dist = pow(2,i-1)

      if next_multiple_dist < K:
        num_1 += K - next_multiple_dist

      ans += pow(2,i-1) * (num_1 % 2)
    else:
      ans += pow(2,i-1) * (K % 2)  

if A == B:
  print(A)
else:
  print(ans)
Problem p03332 (python)

Fixed submission:
global MOD,facts,inv
MOD = 998244353

def nCr(n,r):
    global facts,inv
    return (facts[n] * inv[r]) % MOD * inv[n-r] % MOD

N,A,B,K = map(int,input().split())

facts = [0]*(N+10)
facts[0] = facts[1] = 1
for i in range(2,N+1):
    facts[i] = (facts[i-1] * i) % MOD
inv = [0]*(N+10)
inv[N] = pow(facts[N],MOD-2,MOD)
for i in range(N,0,-1):
    inv[i-1] = (inv[i] * i) % MOD

ans = 0
for i in range(N+1):
    bal = K - (i * A)
    m,f = bal % B,bal // B
    if m == 0 and f <= N and f >= 0:
        ans = (ans + (nCr(N,i) * nCr(N,f))) % MOD
        
print(ans)
#239423 29392 39299 394239932

Buggy submission (verdict: Runtime Error):
global MOD,facts,inv
MOD = 998244353

def nCr(n,r):
    global facts,inv
    return (facts[n] * inv[r]) % MOD * inv[n-r] % MOD

N,A,B,K = map(int,input().split())

facts = [0]*(N+10)
facts[0] = facts[1] = 1
for i in range(2,N+1):
    facts[i] = (facts[i-1] * i) % MOD
inv = [0]*(N+10)
inv[N] = pow(facts[N],MOD-2,MOD)
for i in range(N,0,-1):
    inv[i-1] = (inv[i] * i) % MOD

ans = 0
for i in range(N+1):
    bal = K - (i * A)
    m,f = bal % B,bal // B
    if m == 0 and f + i <= 2*N:
        ans = (ans + (nCr(N,i) * nCr(N,f))) % MOD
        
print(ans)

Buggy submission (verdict: Runtime Error):
global MOD,facts,inv
MOD = 998244353

def nCr(n,r):
    return ((facts[n] * inv[r]) % MOD) * (inv[n-r] % MOD)

N,A,B,K = map(int,input().split())

facts = [0]*(N+10)
facts[0] = facts[1] = 1
for i in range(2,N+1):
    facts[i] = (facts[i-1] * i) % MOD
inv = [0]*(N+10)
inv[N] = pow(facts[N],MOD-2,MOD)
for i in range(N,0,-1):
    inv[i-1] = (inv[i] * i) % MOD

ans = 0
for i in range(N+1):
    bal = K - (i * A)
    m,f = bal % B,bal // B
    if m == 0 and f + i <= 2*N:
        ans = (ans + (nCr(N,i) * nCr(N,f))) % MOD
        
print(ans)

Buggy submission (verdict: Runtime Error):
global MOD,facts,inv
MOD = 998244353

def nCr(n,r):
    return ((facts[n] * inv[r]) % MOD) * (inv[n-r] % MOD)

N,A,B,K = map(int,input().split())

facts = [0]*(N+10)
facts[0] = facts[1] = 1
for i in range(2,N+1):
    facts[i] = (facts[i-1] * i) % MOD
inv = [0]*(N+10)
inv[N] = pow(facts[N],MOD-2,MOD)
for i in range(N,0,-1):
    inv[i-1] = (inv[i] * i) % MOD


ans = 0
for i in range(N+1):
    bal = K - (i * A)
    m,f = bal % B,bal // B
    if m == 0 and f + i <= 2*N:
        ans += (nCr(N,i) * nCr(N,f)) % MOD
        
print(ans)
Problem p02594 (python)

Fixed submission:
X=int(input())
if X<30:
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
X=input()
if X<30:
  print("No")
else:
  print("Yes")
Problem p02596 (python)

Fixed submission:
import math
K=int(input())

if K%7==0:
    L=9*K//7
else:
    L=9*K

if L%2==0 or L%5==0:
    ans=-1
else:
    r=10%L
    for i in range(1,10**6+1):
        if r==1:
            ans=i
            break
        else:
            r=10*r%L
print(ans)

Buggy submission (verdict: Runtime Error):
import math
K=input()

if K%7==0:
    L=9*K/7
else:
    L=9*K

if L%2==0 or L%5==0:
    print(-1)
else:
    r=10%L
    for i in range(1,10**6+1):
        if r==1:
            ans=i
            break
        else:
            r=10*r%L

print(ans)

Buggy submission (verdict: Runtime Error):
import math
K=input()

if K%7=0:
    L=9*K/7
else:
    L=9*K

if L%2=0 or L%5=0:
    print(-1)
else:
    r=10%L
    for i in range(1,10**6+1):
        if r==1:
            ans=i
            break
        else:
            r=10*r%L

print(ans)
Problem p03041 (python)

Fixed submission:
N,K=map(int,input().split())
S=input()
T=list(S)
T[K-1]=T[K-1].lower()
S_changed="".join(T)
print(S_changed)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
S=input()
T=list(S)
T[K-1]=T[K-1].lower()
S_changed="".join(T)
print(S_changed
Problem p03250 (python)

Fixed submission:
A,B,C=map(int,input().split())
list=[A,B,C]
M=max(list)
N=A+B+C
D=9*M+N
print(D)

Buggy submission (verdict: Runtime Error):
A,B,C=map(int,input().split())
list=［A,B,C］
M=max(list)
D=9＊M+A+B+C
print(D)
Problem p02659 (python)

Fixed submission:
a, b = map(int, input().replace(".", "").split())
print(a*b//100)

Buggy submission (verdict: Runtime Error):
a, b = input().split()
ai = int(a)
bf = froat(b)
print(int(ai*bf))
Problem p02688 (python)

Fixed submission:
n, k = map(int, input().split())
sunuke = [1 for _ in range(n)]
for _ in range(k):
  d = int(input())
  for x in list(map(int, input().split())):
    sunuke[x-1] = 0
print(sum(sunuke))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
sunuke = [1 for _ in range(n)]
for _ in range(k):
  d = int(input())
  for x in list(map(int, input().split()):
    sunuke[x-1] = 0
print(sum(sunuke))
Problem p02829 (python)

Fixed submission:
wrong = [int(input()) for _ in range(2)]
for x in range(1, 4):
    if x not in wrong:
        print(x)

Buggy submission (verdict: Runtime Error):
option = [1, 2, 3]
option.pop(int(input()) - 1)
option.pop(int(input()) - 1)
for x in option:
  print(x)
Problem p02831 (python)

Fixed submission:
def gcd(a, b):
    r = a % b
    if r == 0:
        return b
    else:
	    return gcd(b, r)
def lcm(a,b):
    return a * b // gcd(a, b)
a,b = tuple(map(int,input().rstrip().split()))
print(lcm(a, b))

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

Fixed submission:
import math
def comb(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, m = [int(i) for i in input().split(" ")]
r = 0
if n > 1:
  r += comb(n, 2)
if m > 1:
  r += comb(m, 2)
print(r)

Buggy submission (verdict: Runtime Error):
import math
def comb(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, m = [int(i) for i in input().split(" ")]

print(comb(n,2) + comb(m,2))
Problem p02933 (python)

Fixed submission:
a = int(input())
s = input()
print(s if a >= 3200 else 'red')

Buggy submission (verdict: Runtime Error):
a = input()
s = int(input())
print(s if a >= 3200 else 'red')
Problem p02891 (python)

Fixed submission:
S=input()
K=int(input())
LS=len(S)

if LS==1:
    if K==1:
        print(0)
        exit()
    else:
        print(K//2)
        exit()

cnt=1
ans1=0
c=[]
for i in range(1,LS-1):
    if S[i-1]==S[i]:
        cnt+=1
    elif cnt!=1:
        ans1+=cnt//2
        c.append(cnt)
        cnt=1

if K==1:
    if S[-2]==S[-1]:
        cnt+=1
        ans1+=cnt//2
        print(ans1)
        exit()

if S[-2] == S[-1]:
    cnt += 1
    c.append(cnt)
    if cnt % 2 == 0:
        if ans1 != 0:
            ans1 += cnt // 2
            ans1 = ans1 * K
        else:
            ans1 = (cnt // 2) * K
    elif cnt % 2 == 1 and S[0] == S[-1]:
        if ans1 != 0:
            if c[0] % 2 == 0:
                ans1 += cnt // 2
                ans1 = ans1 * K
            else:
                ans1 += cnt // 2 + 1
                ans1 = ans1 * K - 1
        else:
            if ans1!=0:
                ans1 = (cnt // 2) * K + K - 1
            else:
                ans1=(cnt*K)//2
    elif cnt % 2 == 1 and S[0] != S[-1]:
        ans1 += cnt // 2
        ans1 = ans1 * K
else:
    ans1 += cnt // 2

    if S[0] == S[-1]:
        if ans1!=0 and c[0]%2==0:
            ans1=ans1*K
        else:
            ans1 = ans1*K+K - 1
    else:
        ans1 = ans1 * K


print(ans1)

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())
LS=len(S)

cnt=1
ans1=0
for i in range(1,LS-1):
    if S[i-1]==S[i]:
        cnt+=1
    elif cnt!=1:
        ans1+=cnt//2
        cnt=1

if K==1:
    if S[-2]==S[-1]:
        cnt+=1
        ans1+=cnt//2
else:
    if S[-2]==S[-1]:
        cnt+=1
        if cnt%2==0:
            ans1+=cnt//2
            ans1=ans1*K
        elif cnt%2==1 and S[0]==S[-1]:
            ans1+=cnt//2+1
            ans1=ans1*K-1
        elif cnt%2==1 and S[0]!=S[-1]:
            ans1+=cnt//2
            ans1=ans1*K
    else:
        if S[0]==S[-1]:
            ans1=ans1*K-1
        else:
            ans1=ans1*K
print(ans1)
Problem p03017 (python)

Fixed submission:
N,A,B,C,D=map(int,input().split())
A=A-1
B=B-1
C=C-1
D=D-1

s=input()

if A<B<C<D:
    if not "##" in s[B:D+1]:
        if not "##" in s[A:C+1]:
            ans="Yes"
        else:
            ans="No"
    else:
        ans="No"
elif A<B<D<C:
    if not "##" in s[A:C+1]:
        if s[B-1]!="#" and s[B+1]!="#":
            ans="Yes"
        elif "..." in s[B:D+1]:
            ans="Yes"
        elif s[D-1]!="#" and s[D+1]!="#":
            ans="Yes"
        else:
            ans="No"
    else:
        ans="No"
elif A<C<B<D:
    if "##" in s[A:C+1] or "##" in s[B:D+1]:
        ans="No"
    else:
        ans="Yes"
print(ans)

Buggy submission (verdict: Runtime Error):
N,A,B,C,D=map(int,input().split())
A=A-1
B=B-1
C=C-1
D=D-1

s=input()

if C<D:
    if not "##" in s[A:D+1]:
        ans="Yes"
    else:
        ans="No"
elif D<C:
    if not "##" in s[A:C+1]:
        if "..." in s[B-1:D+1]:
            ans="Yes"
    else:
        ans="No"

print(ans)
Problem p03053 (python)

Fixed submission:
from collections import deque

H,W=map(int,input().split())
if H==1 and W==1:
    print(0)
    exit()

A=[]
B=deque([])
C=[[-1]*W for i in range(H)]
ans=[]
for h in range(H):
    temp=list(input())
    A.append(temp)
    for w in range(W):
        if A[h][w]=="#":
            B.append([h,w,0])
            C[h][w]=0
            ans.append(0)



step=[[1,0],[-1,0],[0,1],[0,-1]]

while B:
    P=B.popleft()
    for x,y in step:
        if 0<=P[0]+y<=H-1 and 0<=P[1]+x<=W-1:
            if C[P[0]+y][P[1]+x]==-1:
                B.append([P[0]+y,P[1]+x,P[2]+1])
                C[P[0]+y][P[1]+x]=1
                ans.append(P[2]+1)


print(max(ans))

Buggy submission (verdict: Runtime Error):
from collections import deque

H,W=map(int,input().split())
if H==1 and W==1:
    print(0)
    exit()

A=[]
B=deque([])
C=[[-1]*W for i in range(H)]

for h in range(H):
    temp=list(input())
    A.append(temp)
    for w in range(W):
        if A[h][w]=="#":
            B.append([h,w,0])
            C[h][w]=0



step=[[1,0],[-1,0],[0,1],[0,-1]]
ans=[]
while B:
    P=B.popleft()
    for x,y in step:
        if 0<=P[0]+y<=H-1 and 0<=P[1]+x<=W-1:
            if C[P[0]+y][P[1]+x]==-1:
                B.append([P[0]+y,P[1]+x,P[2]+1])
                C[P[0]+y][P[1]+x]=1
                ans.append(P[2]+1)


print(max(ans))

Buggy submission (verdict: Runtime Error):
from collections import deque

H,W=map(int,input().split())
if H==1 and W==1:
    print(0)
    exit()

A=[]
B=deque([])
C=[[-1]*W for i in range(H)]
cnt=0
for h in range(H):
    temp=list(input())
    A.append(temp)
    for w in range(W):
        if A[h][w]=="#":
            B.append([h,w,0])
            C[h][w]=0
            cnt+=1


step=[[1,0],[-1,0],[0,1],[0,-1]]
ans=[]
while B:
    P=B.popleft()
    for x,y in step:
        if 0<=P[0]+y<=H-1 and 0<=P[1]+x<=W-1:
            if C[P[0]+y][P[1]+x]==-1:
                B.append([P[0]+y,P[1]+x,P[2]+1])
                C[P[0]+y][P[1]+x]=1
                ans.append(P[2]+1)
                cnt+=1
                if cnt==H*W:break

print(max(ans))

Buggy submission (verdict: Runtime Error):
from collections import deque

H,W=map(int,input().split())
A=[]
B=deque([])
C=[[-1]*W for i in range(H)]
for h in range(H):
    temp=list(input())
    A.append(temp)
    for w in range(W):
        if A[h][w]=="#":
            B.append([h,w,0])
            C[h][w]=0


step=[[1,0],[-1,0],[0,1],[0,-1]]
ans=[]
while B:
    P=B.popleft()
    for x,y in step:
        if 0<=P[0]+y<=H-1 and 0<=P[1]+x<=W-1:
            if C[P[0]+y][P[1]+x]==-1:
                B.append([P[0]+y,P[1]+x,P[2]+1])
                C[P[0]+y][P[1]+x]=1
                ans.append(P[2]+1)

print(max(ans))
Problem p03137 (python)

Fixed submission:
N,M=map(int,input().split())

X=list(map(int,input().split()))
X.sort()
di=[]

for i in range(M-1):
    di.append(X[i+1]-X[i])

di.sort(reverse=True)
print(sum(di[N-1:]))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())

X=list(map(int,input().split()))
X.sort()
di=[]


for i in range(M-1):
    di.append(X[i+1]-X[i])
if N==1:
    print(sum[di])
di.sort()
print(sum(di[:M-N]))
Problem p03426 (python)

Fixed submission:
H,W,D=map(int,input().split())
A=[]

for h in range(H):
    A.append(list(map(int,input().split())))

pos= {}
for h in range(H):
    for w in range(W):
        pos[A[h][w]]=[h,w]

S=[0]*(H*W)
for d in range(D):
    tmp=0
    now=d+1
    while now+D<=H*W:
        nowh,noww=pos[now]
        newh,neww=pos[now+D]
        tmp+=abs(nowh-newh)+abs(noww-neww)
        S[now+D-1]=tmp
        now+=D

Q=int(input())
for i in range(Q):
    L,R=map(int,input().split())
    ans=S[R-1]-S[L-1]
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**9)


H,W,D=map(int,input().split())

dic={}
A=[]
for h in range(H):
    A.append(list(map(int,input().split())))
    for w in range(W):
        dic[A[h][w]]=[h,w]

Q=int(input())

c=[-1]*(H*W+1)
def rec(n):
    if c[n]!=-1:
        return [c[n]]
    y,x=dic[n]
    ny,nx=dic[n+D]
    ret=abs(y-ny)+abs(x-nx)
    c[n]=ret
    return ret

for i in range(Q):
    L,R=map(int,input().split())
    N=(R-L)//D
    ans=0
    for j in range(N):
        ans+=rec(L+D*j)
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**5)


H,W,D=map(int,input().split())

dic={}
A=[]
for h in range(H):
    A.append(list(map(int,input().split())))
    for w in range(W):
        dic[A[h][w]]=[h,w]

Q=int(input())

c=[-1]*(H*W+1)
def rec(n):
    if c[n]!=-1:
        return [c[n]]
    y,x=dic[n]
    ny,nx=dic[n+D]
    ret=abs(y-ny)+abs(x-nx)
    c[n]=ret
    return ret

for i in range(Q):
    L,R=map(int,input().split())
    N=(R-L)//D
    ans=0
    for j in range(N):
        ans+=rec(L+D*j)
    print(ans)

Buggy submission (verdict: Runtime Error):
H,W,D=map(int,input().split())

dic={}
A=[]
for h in range(H):
    A.append(list(map(int,input().split())))
    for w in range(W):
        dic[A[h][w]]=[h,w]

Q=int(input())

c=[-1]*(H*W+1)
def rec(n):
    if c[n]!=-1:
        return [c[n]]
    y,x=dic[n]
    ny,nx=dic[n+D]
    ret=abs(y-ny)+abs(x-nx)
    c[n]=ret
    return ret

for i in range(Q):
    L,R=map(int,input().split())
    N=(R-L)//D
    ans=0
    for j in range(N):
        ans+=rec(L+D*j)
    print(ans)
Problem p03631 (python)

Fixed submission:
N = list(input())
if N[0]==N[2]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N=int(input())

R=[[] for i in range(N)]

for i in range(N-1):
    a,b,c=map(int,input().split())
    R[a-1].append([b-1,c])
    R[b-1].append([a-1,c])

Q,K=map(int,input().split())
C=[0]*N
stack=[]
for i in range(N):
    if i==K-1:
        C[i]=0
    else:
        chk = [0] * N
        stack=[[K-1,i,0]]
        f=True
        while stack:
            if f==False:
                break
            s,g,d=stack.pop()
            chk[s]=1
            for j,c in R[s]:
                if chk[j]==1:continue
                if j==g:
                    C[i]=d+c
                    f=False
                    break
                else:
                    stack.append([j,g,d+c])

for i in range(Q):
    x,y=map(int,input().split())
    print(C[x-1]+C[y-1])

Buggy submission (verdict: Runtime Error):
N=int(input())

R=[[] for i in range(N)]

for i in range(N-1):
    a,b,c=map(int,input().split())
    R[a-1].append([b-1,c])
    R[b-1].append([a-1,c])

Q,K=map(int,input().split())
C=[0]*N
stack=[]
for i in range(N):
    if i==K-1:
        C[i]=0
    else:
        chk = [0] * N
        stack=[[K-1,i,0]]
        f=True
        while stack:
            if f==False:
                break
            s,g,d=stack.pop()
            chk[s]=1
            for j,c in R[s]:
                if chk[j]==1:continue
                if j==g:
                    C[i]=d+c
                    f=False
                    break
                else:
                    stack.append([j,g,d+c])

for i in range(Q):
    x,y=map(int,input().split())
    print(C[x-1]+C[y-1])
Problem p03634 (python)

Fixed submission:
N=int(input())
G=[[] for _ in range(N)]
for i in range(N-1):
    a,b,c=map(int,input().split())
    G[a-1].append([b-1,c])
    G[b-1].append([a-1,c])

Q,K=map(int,input().split())

SD=[0]*N
seen=[0]*N
stack=[]
stack.append([K-1,0])
seen[K-1]=1
while stack:
    x,d=stack.pop()
    for y,d0 in G[x]:
        if seen[y]==0:
            SD[y]=d+d0
            stack.append([y,d+d0])
            seen[y]=1
for i in range(Q):
    x,y=map(int,input().split())
    ans=SD[x-1]+SD[y-1]
    print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
G=[[] for _ in range(N)]
for i in range(N-1):
    a,b,c=map(int,input().split())
    G[a-1].append([b-1,c])
    G[b-1].append([a-1,c])

Q,K=map(int,input().split())

SD=[0]*N
def DFS(v,p,d):
    SD[v]=d
    for i,co in G[v]:
        if i==p:continue
        DFS(i,v,d+co)
    return

DFS(K-1,-1,0)

for i in range(Q):
    x,y=map(int,input().split())
    ans=SD[x-1]+SD[y-1]
    print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())

R=[[] for i in range(N)]

for i in range(N-1):
    a,b,c=map(int,input().split())
    R[a-1].append([b-1,c])
    R[b-1].append([a-1,c])

Q,K=map(int,input().split())

def dfs(s,g,d):
    chk[s]=1
    for j,c in R[s]:
        if j==g:
            return d+c
        else:
            if chk[j]:
                continue
            else:
                temp=dfs(j,g,d+c)
                if temp!=None:
                    return temp
                else:continue

C=[0]*N
for i in range(N):
    if i==K-1:
        C[i]=0
    else:
        chk = [0] * N
        C[i]=dfs(K-1,i,0)

for i in range(Q):
    x,y=map(int,input().split())
    print(C[x-1]+C[y-1])
Problem p03745 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))

if N ==1 or N ==2:
    print(1)
    exit()
t = 0
c =1
for i in range(1,N):

    if A[i]-A[i-1]>0:
        if t == -1:
            c +=1
            t = 0
        else:
            t = 1
    elif A[i]-A[i-1]<0:
        if t == 1:
            c +=1
            t = 0
        else:
            t = -1    
print(c)

Buggy submission (verdict: Runtime Error):
N,C,K = map(int,input().split())
T = [int(input()) for i in range(N)]

T.sort()
i = 0
ans = 0

while i < N:
    t = T[i]
    x = T.count(T[i])
    ans = ans + (x-1+C)//C
    for j in range(i+((x-1+C)//C)*C-1,N):
        if T[j]>t+K:
            y = j-i
            break
        y = N-i
            
    y=min(C,y)
    i = i + y 

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

c = 0
i =2

if N ==1 or N ==2:
    print(1)
    exit()
while i<N+1:
    if (A[i-1]-A[i-2])*(A[i]-A[i-1])<0:
        c=c+1
        i = i+1
    i = i+1
print(c+1)
Problem p03986 (python)

Fixed submission:
A2=list(input())
A1=[]
L=len(A2)
A1.append(A2[0])

for i in range(1,L):
    if len(A1)>=1 and A1[-1]=="S" and A2[i]=="T":
        A1.pop(-1)
    else:
        A1.append(A2[i])

print(len(A1))

Buggy submission (verdict: Runtime Error):
X=input()

S=0

for i in range(L):
    if X[-(1+i)]=="S":
        S+=1
    else:
        break
print(2*S)