Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
w, v = [0]*N, [0]*N
for i in range(N):
  w[i], v[i] = map(int, input().split())

dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(1, N+1):
  for w_sum in range(1, W+1):
    if w_sum >= w[i-1]:
      dp[i][w_sum] = max(dp[i-1][w_sum-w[i-1]] + v[i-1], dp[i-1][w_sum])
    else:
      dp[i][w_sum] = dp[i-1][w_sum]
      
print(dp[N][W])

Fixed submission:
N, W = map(int, input().split())
w, v = [0]*(N+1), [0]*(N+1)
for i in range(N):
  w[i+1], v[i+1] = map(int, input().split())
  
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(1,N+1):
  for j in range(W+1):
    if j < w[i]:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = max(dp[i-1][j-w[i]]+v[i], dp[i-1][j])
print(dp[N][W])

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
w, v = [0]*(N+1), [0]*(N+1)
for i in range(N):
  w[i+1], v[i+1] = map(int, input().split())
  
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(1,N+1):
  for j in range(W+1):
    if j < w[i]:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = max(dp[i-1][j-w[i]]+v[i], dp[i-1][j])
print(dp[N][W])

Fixed submission:
N, W = map(int, input().split())
w, v = [0]*(N+1), [0]*(N+1)
for i in range(N):
  w[i+1], v[i+1] = map(int, input().split())
  
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(1,N+1):
  for j in range(W+1):
    if j < w[i]:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = max(dp[i-1][j-w[i]]+v[i], dp[i-1][j])
print(dp[N][W])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
V = N * 1000
w, v = [0]*N, [0]*N
for i in range(N):
  w[i], v[i] = map(int, input().split())

dp = [[float("INF")]*(V+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(1, N+1):
  for v_sum in range(V+1):
    if v_sum >= v[i-1]:
      dp[i][v_sum] = min(dp[i-1][v_sum - v[i-1]] + w[i-1], dp[i-1][v_sum])
    else:
      dp[i][v_sum] = dp[i-1][v_sum]

ans = 0
for v_sum in range(V+1):
  if dp[N][v_sum] <= W:
    ans = v_sum
print(ans)

Fixed submission:
N, W = map(int, input().split())
V = N * 1000
w, v = [0]*N, [0]*N
for i in range(N):
  w[i], v[i] = map(int, input().split())

dp = [[float("INF")]*(V+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(1, N+1):
  for v_sum in range(V+1):
    if v_sum >= v[i-1]:
      dp[i][v_sum] = min(dp[i-1][v_sum - v[i-1]] + w[i-1], dp[i-1][v_sum])
    else:
      dp[i][v_sum] = dp[i-1][v_sum]

ans = 0
for v_sum in range(V+1):
  if dp[N][v_sum] <= W:
    ans = v_sum
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

dp = [[0]*(len(s)+1) for _ in range(len(t)+1)]

for i in range(len(t)):
  for j in range(len(s)):
    if t[i] == s[j]:
      dp[i+1][j+1] = dp[i][j] + 1
    else:
      dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])

i = len(t)
j = len(s)
ans = ''
while i >= 0 and j >= 0:
  if dp[i][j] == dp[i-1][j]:
    i -= 1
  elif dp[i][j] == dp[i][j-1]:
    j -= 1
  else:
    i -= 1
    j -= 1
    ans = ans + t[i]
print(ans[::-1])

Fixed submission:
s = input()
t = input()

dp = [[0]*(len(s)+1) for _ in range(len(t)+1)]

for i in range(len(t)):
  for j in range(len(s)):
    if t[i] == s[j]:
      dp[i+1][j+1] = dp[i][j] + 1
    else:
      dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])

i = len(t)
j = len(s)
ans = ''
while i >= 0 and j >= 0:
  if dp[i][j] == dp[i-1][j]:
    i -= 1
  elif dp[i][j] == dp[i][j-1]:
    j -= 1
  else:
    i -= 1
    j -= 1
    ans = ans + t[i]
print(ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(float, input().split()))

# コインをi枚使い、表がj枚である確率
dp = [[0]*(N+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(1, N+1):
    for j in range(i+1):
        if j-1 >= 0:
            dp[i][j] = dp[i-1][j-1]*A[i-1] + dp[i-1][j]*(1 - A[i-1])
        else:
            dp[i][j] = dp[i-1][j]*(1 - A[i-1])

print(sum([dp[N][i] for i in range(N//2+1, N+1)]))

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

# コインをi枚使い、表がj枚である確率
dp = [[0]*(N+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(1, N+1):
    for j in range(i+1):
        if j-1 >= 0:
            dp[i][j] = dp[i-1][j-1]*A[i-1] + dp[i-1][j]*(1 - A[i-1])
        else:
            dp[i][j] = dp[i-1][j]*(1 - A[i-1])

print(sum([dp[N][i] for i in range(N//2+1, N+1)]))
Buggy python submission (verdict: Runtime Error):
H, W = map(int,input().split())
S = [list(input()) for _ in range(W)]
for i in range(H):
  for j in range(W):
    up = down = left = right = "#"
    if S[i][j] == "#":
      if i-1 >= 0:
        up = S[i-1][j]
      if j-1 >= 0:
        left = S[i][j-1]
      if i+1 <= H-1:
        down = S[i+1][j]
      if j+1 <= W-1:
        right = S[i][j+1]
      if up == down == left == right == ".":
        print("No")
        exit()
print("Yes")

Fixed submission:
H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]
for i in range(H):
  for j in range(W):
    up = down = left = right = "."
    if S[i][j] == "#":
      if i-1 >= 0:
        up = S[i-1][j]
      if j-1 >= 0:
        left = S[i][j-1]
      if i+1 <= H-1:
        down = S[i+1][j]
      if j+1 <= W-1:
        right = S[i][j+1]
      if up == down == left == right == ".":
        print("No")
        exit()
print("Yes")
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
m = [int(input()) for _ in range(N)]
print(N + (X - m) // min(m))

Fixed submission:
N, X = map(int, input().split())
m = [int(input()) for _ in range(N)]
print(N + (X - sum(m)) // min(m))
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for i in range(A):
  for j in range(B):
    for k in range(C):
    if 500*i + 100*j + 50*k == X:
      cnt += 1
print(cnt)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if 500*i + 100*j + 50*k == X:
        cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
Q = int(input())
query = [list(map(int, input().split())) for _ in range(Q)]

def is_prime(n):
  if n <= 1:
    return False
  if n == 2:
    return True
  i = 2
  while i * i <= n:
    if n % i == 0:
      return False
    i += 1
  return True

prime = []
ans = [0]*10001
sum_a = [0]*10001
for n in range(1, 10000+1):
  if is_prime(n) and is_prime((n+1)//2):
    if n != 2:
      prime.append(n)
      ans[n] = 1
  sum_a[n] = sum_a[n-1] + ans[n]

for l, r in query:
  print(sum_a[r] - sum_a[l-1])

Fixed submission:
Q = int(input())
query = [list(map(int, input().split())) for _ in range(Q)]

def is_prime(n):
  if n <= 1:
    return False
  if n == 2:
    return True
  i = 2
  while i * i <= n:
    if n % i == 0:
      return False
    i += 1
  return True

prime = []
ans = [0]*100001
sum_a = [0]*100001
for n in range(1, 100000+1):
  if is_prime(n) and is_prime((n+1)//2):
    if n != 2:
      prime.append(n)
      ans[n] = 1
  sum_a[n] = sum_a[n-1] + ans[n]

for l, r in query:
  print(sum_a[r] - sum_a[l-1])

Buggy python submission (verdict: Runtime Error):
Q = int(input())
query = [list(map(int, input().split())) for _ in range(Q)]

def is_prime(n):
  if n <= 1:
    return False
  if n == 2:
    return True
  i = 2
  while i * i <= n:
    if n % i == 0:
      return False
    i += 1
  return True

prime = []
ans = [0]*10001
sum_a = [0]*10001
for n in range(3, 10000):
  if is_prime(n) and is_prime((n+1)//2):
    prime.append(n)
    ans[n] = 1
  sum_a[n] = sum_a[n-1] + ans[n]

for l, r in query:
  print(sum_a[r] - sum_a[l-1])

Fixed submission:
Q = int(input())
query = [list(map(int, input().split())) for _ in range(Q)]

def is_prime(n):
  if n <= 1:
    return False
  if n == 2:
    return True
  i = 2
  while i * i <= n:
    if n % i == 0:
      return False
    i += 1
  return True

prime = []
ans = [0]*100001
sum_a = [0]*100001
for n in range(1, 100000+1):
  if is_prime(n) and is_prime((n+1)//2):
    if n != 2:
      prime.append(n)
      ans[n] = 1
  sum_a[n] = sum_a[n-1] + ans[n]

for l, r in query:
  print(sum_a[r] - sum_a[l-1])
Buggy python submission (verdict: Runtime Error):
s = input()
ans = "No"
if s[0] == S[1] == s[2]:
  ans = "Yes"
elif s[1] == s[2] == s[3]:
  ans = "Yes"
print(ans)

Fixed submission:
s = input()
ans = "No"
if s[0] == s[1] == s[2]:
  ans = "Yes"
elif s[1] == s[2] == s[3]:
  ans = "Yes"
print(ans)
Buggy python submission (verdict: Runtime Error):
# ABC79 D - Wall
from scipy.sparse.csgraph import floyd_warshall
from itertools import permutations

H, W = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split()))　for _ in range(H)]

C = floyd_warshall(C)  

cost = 0
for i in range(H):
    for a in A[i]:
        if a != -1:
            cost += C[a][1]

print(int(cost))

Fixed submission:
from scipy.sparse.csgraph import floyd_warshall
from itertools import permutations

H, W = map(int, input().split())
C = [[0]*10 for _ in range(10)]
A = [[0]*W for _ in range(H)]

for i in range(10):
  C[i] = list(map(int, input().split()))

C = floyd_warshall(C)  

cost = 0
for i in range(H):
  A[i] = list(map(int, input().split()))
  for a in A[i]:
    if a != -1:
      cost += C[a][1]

print(int(cost))
Buggy python submission (verdict: Runtime Error):
A = list(map(int,input().split()))
B = list(map(int,input().split()))
if A[0] == B[2] and A[1] == B[1] and A[2] == B[0]:
  print("YES")
else:
  print("NO")

Fixed submission:
A = input()
B = input()
if A[0] == B[2] and A[1] == B[1] and A[2] == B[0]:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
# ABC77 C - Snuke Festival
from bisect import bisect_left
from bisect import bisect_right
import numpy as np

N = int(input())
A = np.array(sorted(list(map(int, input().split()))))
B = np.array(sorted(list(map(int, input().split()))))
C = np.array(sorted(list(map(int, input().split()))))

ans = 0
for i in range(N):
#    ans += bisect_left(A, B[i]) * (N - bisect_right(C, B[i]))
    ans += np.count_nonzero(A < B[i]) * np.count_nonzero(C > B[i])
print(ans)

Fixed submission:
# ABC77 C - Snuke Festival
from bisect import bisect_left
from bisect import bisect_right
from bisect import bisect

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for i in range(N):
    ans += bisect_left(A, B[i]) * (N - bisect_right(C, B[i]))

print(ans)
Buggy python submission (verdict: Runtime Error):
R, G = map(int, input().split())
print(2*G - R)

Fixed submission:
R = int(input())
G = int(input())
print(2*G - R)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

for h in range(1, 3500+1):
  for n in range(1, 3500+1):
    if 4*h*n - N*n - N*h == 0:
      continue
    w = (N*h*n) // (4*h*n - N*n - N*h)
    if w < 1 or w > 3500:
      continue
    if 4*h*n*w == N*(n*w + h*w + n*h):
      print(h, n, w)
      exit()

Fixed submission:
N = int(input())

for h in range(1, 3500+1):
  for n in range(1, 3500+1):
    if 4*h*n - N*n - N*h == 0:
      continue
    w = (N*h*n) // (4*h*n - N*n - N*h)
    if w < 1 or w > 3500:
      continue
    if 4*h*n*w == N*(n*w + h*w + n*h):
      print(h, n, w)
      exit()
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, D, E, F = map(int, input().split())

density = -1
s_water = -1
sugar = -1
for a in range(31):
    for b in range(31):
        for c in range(101):
            for d in range(101):
                w = (100*A)*a + (100*B)*b
                s = C*c + D*d
                if w == 0:
                    continue
                if w + s > F:
                    continue
                if w/100 * E >= s:
                    tmp = 100*s / (w + s)
                    if tmp > density:
                        density = tmp
                        s_water = max(w + s, 100*A)
                        sugar = s
print(s_water, sugar)

Fixed submission:
A, B, C, D, E, F = map(int, input().split())

density = -1
s_water = -1
sugar = -1
for a in range(31):
    for b in range(31):
        for c in range(101):
            for d in range(101):
                w = (100*A)*a + (100*B)*b
                s = C*c + D*d
                if w == 0:
                    continue
                if w + s > F:
                    continue
                if w/100 * E >= s:
                    tmp = 100*s / (w + s)
                    if tmp > density:
                        density = tmp
                        s_water = max(w + s, 100*A)
                        sugar = s
print(s_water, sugar)

Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, D, E, F = map(int, input().split())

density = 0
s_water = 0
sugar = 0
for a in range(31):
    for b in range(31):
        for c in range(101):
            for d in range(101):
                w = (100*A)*a + (100*B)*b
                s = C*c + D*d
                if w == 0:
                    continue
                if w + s > F:
                    continue
                if w/100 * E >= s:
                    tmp = 100*s / (w + s)
                    if tmp > density:
                        density = tmp
                        s_water = w + s
                        sugar = s
print(s_water, sugar)

Fixed submission:
A, B, C, D, E, F = map(int, input().split())

density = -1
s_water = -1
sugar = -1
for a in range(31):
    for b in range(31):
        for c in range(101):
            for d in range(101):
                w = (100*A)*a + (100*B)*b
                s = C*c + D*d
                if w == 0:
                    continue
                if w + s > F:
                    continue
                if w/100 * E >= s:
                    tmp = 100*s / (w + s)
                    if tmp > density:
                        density = tmp
                        s_water = max(w + s, 100*A)
                        sugar = s
print(s_water, sugar)
Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(int,input().split()))
cnt = 0
for i in range(1, N+1):
  if P[i-1] == i:
    tmp = P[i-1]
    P[i-1] = P[i]
    P[i] = tmp
    cnt += 1
print(cnt)

Fixed submission:
N = int(input())
P = list(map(int,input().split()))
cnt = 0
for i in range(1, N):
  if P[i-1] == i:
    tmp = P[i-1]
    P[i-1] = P[i]
    P[i] = tmp
    cnt += 1
if P[N-1] == N:
  tmp = P[N-1]
  P[N-1] = P[N-2]
  P[N-2] = tmp
  cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
S = input()
for i in range(ord(a), ord(z)+1):
  if chr(i) not in S:
    print(chr(i))
    exit()
    

Fixed submission:
S = input()
for i in range(ord("a"), ord("z")+1):
  if chr(i) not in S:
    print(chr(i))
    exit()
print("None")
Buggy python submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())
print(max(min(B,D) - max(A,C) 0))


Fixed submission:
A, B, C, D = map(int, input().split())
print(max(min(B,D) - max(A,C), 0))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(M):
  a, b = map(lambda x: int(x)-1, input().split())
  G[a].append(b)

for v in G[0]:
  if nv in G[v]:
    print("POSSIBLE")
    exit()
print("IMPOSSIBLE")


Fixed submission:
N, M = map(int, input().split())
edges = [[] for i in range(N)]

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

for i in edges[0]:
  if N-1 in edges[i]:
    print("POSSIBLE")
    exit()
print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
a = [0]*M
b = [0]*M
for i in range(M):
  a[i], b[i] = map(int, input().split())
c = []
for i in range(M):
  if b[i] == N:
    c.append(a[i])
if len(c) != 0:
  for i in range(M):
    if a[i] == 1:
      for j in range(len(c)):
        if b[i] == c[j]:
          print("POSSIBLE")
          exit()
print("IMPOSSIBLE")

Fixed submission:
N, M = map(int, input().split())
edges = [[] for i in range(N)]

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

for i in edges[0]:
  if N-1 in edges[i]:
    print("POSSIBLE")
    exit()
print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
print(sum(a, b, c) - max(a, b, c))

Fixed submission:
a, b, c = map(int, input().split())
print((a + b + c) - max(a, b, c))
Buggy python submission (verdict: Runtime Error):
X, A, B = map(int, input().split())
if B - A <= 0:
  print("delicious")
elif:
  0 < B - A and B - A <= X:
  print("safe")
else:
  print("dangerous")

Fixed submission:
X, A, B = map(int, input().split())
if B - A <= 0:
  print("delicious")
elif 0 < B - A <= X:
  print("safe")
else:
  print("dangerous")

Buggy python submission (verdict: Runtime Error):
X, A, B = map(int, input().split())
if B - A <= 0:
  print("delicious")
elif:
  0 < B - A < X:
  print("safe")
else:
  print("dangerous")

Fixed submission:
X, A, B = map(int, input().split())
if B - A <= 0:
  print("delicious")
elif 0 < B - A <= X:
  print("safe")
else:
  print("dangerous")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for _ in range(N)]

nb = 0
for i in range(N):
  nb = A[nb]
  if nb == 2:
    print(i+1)
    exit()

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]

nb = 1
for i in range(N):
  nb = A[nb-1]
  if nb == 2:
    print(i+1)
    exit()
print(-1)
Buggy python submission (verdict: Runtime Error):
S = input()
A = [0]*len(S)
for i in range(len(S)):
  A[S[i]] += 1
if max(A) == 1:
  print("yes")
else:
  print("no")

Fixed submission:
from collections import defaultdict
S = input()
d = defaultdict(int)
for i in range(len(S)):
  d[S[i]] += 1
for val in d.values():
  if val != 1:
    print("no")
    exit()
print("yes")
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A, B = [0]*N, [0]*N
s = ""
for i in range(N):
  A[i], B[i] = input().split()
  s += A[i] * int(B[i])
print(s[K-1])

Fixed submission:
from collections import defaultdict
N, K = map(int, input().split())
d = defaultdict(int)
for _ in range(N):
  a, b = map(int, input().split())
  d[a] += b
d = sorted(d.items(), key=lambda x:x[0])
s = 0
for i in range(len(d)):
  s += d[i][1]
  if K <= s:
    print(d[i][0])
    exit()
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
if A[-1] == B[0] and B[-1] == C[0]:
  print("YES")
else:
  print("NO")

Fixed submission:
A, B, C = input().split()
if A[-1] == B[0] and B[-1] == C[0]:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int, input().split())
print((a[0]+b[0]+c[0]).upper())

Fixed submission:
a,b,c=input().split()
print((a[0]+b[0]+c[0]).upper())
Buggy python submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
S = [input() for _ in range(N)
cl = [Counter(s) for s in S]

ans = ""
for i in range(26):
  s = chr(ord("a")+i)
  val = min([c[s] for c in cl])
  ans += s*val
print(ans)

Fixed submission:
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]
cl = [Counter(s) for s in S]

ans = ""
for i in range(26):
  s = chr(ord("a")+i)
  val = min([c[s] for c in cl])
  ans += s*val
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = 0
while len(A) > 0:
  ans += A[1]
  A = A[2:-1]
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = 0
for i in range(1, 2*N, 2):
  ans += A[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def F(A, B):
  return max(len(str(A)), len(str(B)))

ans = 100
for i in range(1, N+1):
  if N % i == 0:
    ans = min(ans, F(i, N//i))

print(ans)

Fixed submission:
import math

N = int(input())

def F(A, B):
  return max(len(str(A)), len(str(B)))

ans = 10**10
for i in range(1, math.ceil(math.sqrt(N+1))+1):
  if N % i == 0:
    ans = min(ans, F(i, N//i))

print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a == "H":
  print(b)
else:
  print("H") if b == "D" else print("D")

Fixed submission:
a, b = input().split()
if a == "H":
  print(b)
else:
  print("H") if b == "D" else print("D")
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
print("A"+B+"C")

Fixed submission:
A, B, C = input().split()
print("A"+B[0]+"C")
Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int, input().split())
cnt = 0
for i in range(a, b+1):
  if i % x == 0:
    cnt += 1
print(cnt)

Fixed submission:
a, b, x = map(int, input().split())
def f(n, x):
  if n == -1:
    return 0
  return n//x+1
print(f(b, x) - f(a-1, x))
Buggy python submission (verdict: Time Limit Exceeded):
X = input()
while X.count("ST") > 0:
  X = X.replace("ST", "")
print(len(X))

Fixed submission:
X = input()
s_cnt, t_cnt = 0, 0
for i in range(len(X)):
  if X[i] == "S":
    s_cnt += 1
  elif s_cnt != 0:
    s_cnt -= 1
    t_cnt += 1
print(len(X) - 2*t_cnt)
Buggy python submission (verdict: Runtime Error):
S = input()
st = set(S)
for i in range(len(st)):
  if S.count(st[i]) % 2 != 0:
    print("No")
    exit()
print("Yes")

Fixed submission:
S = input()
st = list(set(S))
for i in range(len(st)):
  if S.count(st[i]) % 2 != 0:
    print("No")
    exit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
N, A = map(int, input().split())
X = list(map(int, input().split()))

dp = [[[0]*(50*(N+1)+1) for _ in range(N+1)] for _ in range(N+1)]
dp[0][0][0] = 1

for i in range(N):
    for k in range(N):
        for s in range(50*N+1):
            dp[i+1][k][s] += dp[i][k][s]
            dp[i+1][k+1][s+X[i]] += dp[i][k][s]

ans = 0
for k in range(1, N+1):
    ans += dp[N][k][A*k]

print(ans)

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

dp = [[[0]*(50*(N+1)+1) for _ in range(N+1)] for _ in range(N+1)]
dp[0][0][0] = 1

for i in range(N):
    for k in range(N):
        for s in range(50*N+1):
            dp[i+1][k][s] += dp[i][k][s]
            dp[i+1][k+1][s+X[i]] += dp[i][k][s]

ans = 0
for k in range(1, N+1):
    ans += dp[N][k][A*k]

print(ans)
Buggy python submission (verdict: Runtime Error):
print(sum[i for i in range(1, int(input())+1)]

Fixed submission:
print(sum([i for i in range(1, int(input())+1)]))

Buggy python submission (verdict: Runtime Error):
print(sum[for i in range(1, int(input())+1)]

Fixed submission:
print(sum([i for i in range(1, int(input())+1)]))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
ad_list = {}
for i in range(M):
  a, b = map(int, input().split())
  if a in ad_list:
    ad_list[a].add(b)
  else:
    ad_list[a] = {b}
  if b in ad_list:
    ad_list[b].add(a)
  else:
    ad_list[b] = {a}

#BFS
ans = 0
done = [True for i in range(N+1)]

def dfs(x):
  global done
  global tmp
  for y in ad_list[x]:
    if done[y]:
      done[y] = False
      tmp += 1
      dfs(y)
      
for i in range(1, N+1):
  if done[i]:
    done[i] = False
    tmp = 1
    if i in ad_list:
        dfs(i)
    ans = max(ans, tmp)

print(ans)

Fixed submission:
N, M = map(int, input().split())
ad_list = {}
for i in range(M):
  a, b = map(int, input().split())
  if a in ad_list:
    ad_list[a].add(b)
  else:
    ad_list[a] = {b}
  if b in ad_list:
    ad_list[b].add(a)
  else:
    ad_list[b] = {a}

#BFS
ans = 0
done = [True for i in range(N+1)]

import queue
q = queue.Queue()

for i in range(1, N+1):
  if done[i]:
    done[i] = False
    tmp = 1
    if i in ad_list:
      q.put(i)
      while not q.empty():
        x = q.get()
        for y in ad_list[x]:
          if done[y]:
            tmp += 1
            done[y] = False
            q.put(y)
    ans = max(ans, tmp)

print(ans)