Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6) #for deep recursion

N,Q = map(int,input().split())
graph = [[False for i in range(N)] for j in range(N)]
visited = [False for i in range(N)]
ans = [0 for i in range(N)]

for i in range(N-1):
  v,u = map(int,input().split())
  v -= 1
  u -= 1
  graph[v][u] = True
  graph[u][v] = True

for i in range(Q):
  node,value = map(int,input().split())
  node -= 1
  ans[node] += value

def dfs(v):
  queue = [v]
  while queue != []:
    now = queue.pop()
    visited[now] = True
    for next in range(N):
      if visited[next]:continue
      if not graph[now][next]:continue
      queue.append(next)
      ans[next] += ans[now]
      
dfs(0)
print(*ans)

Fixed submission:
import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6) #for deep recursion
n, q = map(int, input().split())

tree_index = [[] for _ in range(n)]
for i in range(n-1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  tree_index[a].append(b) # a<bとは限らないため、双方向にする
  tree_index[b].append(a)
ans = [0] * n
for i in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
def dfs(cur, par):
    for chl in tree_index[cur]:
      if chl == par: #parentとchildが等しい時はスキップ
        continue
      ans[chl] += ans[cur] 
      dfs(chl, cur)
dfs(0, -1)
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

j = 0
ans = 0

while j < len(t):
  ok=0
  for i in range(len(s)):
    ans += 1
    if t[j]==s[i]:
      ok=1
      j+=1
    if j >= len(t):
      break
  if not ok:
    print('-1')
    break
    
if ok:print(ans)

Fixed submission:
import collections
import bisect
S = input()
T = input()
N = len(S)
 
d = collections.defaultdict(list)
for i, s in enumerate(S):
  d[s].append(i + 1)

ans = 0
end = 0
isOK = True
i = 0

for t in T:
  if len(d[t])==0: # 存在しない文字ならFalse
    isOK = False
    break
  dic = d[t]
  idx = bisect.bisect_right(dic, i) # i番目以降におけるtの出現位置を取得(O(logN))
  if len(dic) == idx:
    i = dic[0]  # iをtのあるところに動かす
    end += 1    # 端に到達したら，繰り返し数を増やす
  else:
    i = dic[idx]# iをtのあるところに動かす

if isOK:
  ans = N * end + i
else:
  ans = -1
    
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
s.sort()
if s[0]==s[1] and s[2]==s[3]:
  print("Yes")
else:
  print("No")

Fixed submission:
s = [i for i in input()]
s.sort()
if s[0]==s[1] and s[2]==s[3] and len(set(s)) != 1:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
a = [int(input()) for i in range(M)]
dp = [0 for i in range(N+1)]
dp[0] = 1
dp[1] = 1
for i in range(2,N+1):
  if (i-2 in a) and (i-1 in a):
    dp[-1] = 0
    break
  elif i-2 in a:
    dp[i] = dp[i-1]
  elif i-1 in a:
    dp[i] = dp[i-2]
  else:
    dp[i] = dp[i-1] + dp[i-2]

print(dp[-1]%(7+10**9))

Fixed submission:
p,q,r = map(int,input().split())
print(min(p+q,p+r,q+r))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
a = [int(input()) for i in range(M)]
dp = [0 for i in range(N+1)]
dp[0] = 1
dp[1] = 1
for i in range(2,N+1):
  if (i-2 in a) and (i-1 in a):
    dp[-1] = 0
    break
  elif i-2 in a:
    dp[i] = dp[i-1]
  elif i-1 in a:
    dp[i] = dp[i-2]
  else:
    dp[i] = dp[i-1] + dp[i-2]

print(dp[-1]%(7+10**9))

Fixed submission:
N, M = map(int,input().split())
a = set([int(input()) for i in range(M)])
dp = [0 for i in range(N+1)]
dp[0] = 1
dp[1] = 1
for i in range(2,N+1):
  if (i-2 in a) and (i-1 in a):
    dp[-1] = 0
    break
  elif i-2 in a:
    dp[i] = dp[i-1]
  elif i-1 in a:
    dp[i] = dp[i-2]
  else:
    dp[i] = dp[i-1] + dp[i-2]

print(dp[-1]%(7+10**9))

Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
a = [int(input()) for i in range(M)]
dp = [0 for i in range(N+1)]
dp[0] = 1
dp[1] = 1
for i in range(2,N+1)
  if (i-2 in a) and (i-1 in a):
    dp[-1] = 0
    break
  elif i-2 in a:
    dp[i] = dp[i-1]
  elif i-1 in a:
    dp[i] = dp[i-2]
  else:
    dp[i] = dp[i-1] + dp[i-2]

print(dp[-1]%(7+10**9))

Fixed submission:
N, M = map(int,input().split())
a = set([int(input()) for i in range(M)])
dp = [0 for i in range(N+1)]
dp[0] = 1
dp[1] = 1
for i in range(2,N+1):
  if (i-2 in a) and (i-1 in a):
    dp[-1] = 0
    break
  elif i-2 in a:
    dp[i] = dp[i-1]
  elif i-1 in a:
    dp[i] = dp[i-2]
  else:
    dp[i] = dp[i-1] + dp[i-2]

print(dp[-1]%(7+10**9))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
a = [int(input()) for i in range(M)]
dp = [0 for i in range(N+1)]
dp[0] = 1
dp[1] = 1
i = 2
while i <= N:
  if (i-2 in a) and (i-1 in a):
    dp[-1] = 0
    break
  elif i-2 in a:
    dp[i] = dp[i-1]
  elif i-1 in a:
    dp[i] = dp[i-2]
  else:
    dp[i] = dp[i-1] + dp[i-2]
  i+=1

print(dp[-1]%(7+10**9))
    

Fixed submission:
N, M = map(int,input().split())
a = set([int(input()) for i in range(M)])
dp = [0 for i in range(N+1)]
dp[0] = 1
dp[1] = 1
for i in range(2,N+1):
  if (i-2 in a) and (i-1 in a):
    dp[-1] = 0
    break
  elif i-2 in a:
    dp[i] = dp[i-1]
  elif i-1 in a:
    dp[i] = dp[i-2]
  else:
    dp[i] = dp[i-1] + dp[i-2]

print(dp[-1]%(7+10**9))
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = [i for i in map(int,input().split())]
bc = [[i for i in map(int,input().split())] for j in range(m)]

a.sort(reverse=True)
bc.sort(key=lambda x: x[1], reverse=True)
arr = []
j = 0
for i in range(n):
  arr.append(bc[j][1])
  bc[j][0]-=1
  if bc[j][0]==0:
    j += 1
  if j >= m:
    break

while len(arr) < n:
  arr.append(a.pop(0))
arr.sort()

for i in range(len(a)):
  if arr[0] < a[0]:
    arr[0] = a.pop(0)
  arr.sort()
  
print(sum(arr))

Fixed submission:
N, M = map(int,input().split())
A = [i for i in map(int,input().split())]
BC = [[i for i in map(int,input().split())] for j in range(M)]
A.sort()
BC.sort(reverse=True, key=lambda x:x[1])

ans_arr = [0 for i in range(N)]

j = 0
for i in range(N):
  if j < M:
    if A[i] < BC[j][1]:
      ans_arr[i] = BC[j][1]
      BC[j][0] -= 1
      if BC[j][0] == 0:
        j+=1
    else:
      ans_arr[i] = A[i]
  else:
    ans_arr[i] = A[i]
      
print(sum(ans_arr))
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = [i for i in input()]
questions = [[i-1 for i in map(int,input().split())] for j in range(Q)]
for i in range(len(S)-1):
  if S[i]=='A' and S[i+1]=='C':
    S[i]='a'
    
for q in questions:
  part_S = S[q[0]:q[1]+1]
  ans = part_S.count('a')
  if part_S[-1]=='a':
    ans -= 1
  print(ans)

Fixed submission:
N,Q = map(int,input().split())
S = input()
questions = [[i for i in map(int,input().split())] for j in range(Q)]
t = [0]*(N+1)
for i in range(N):
  t[i+1] = t[i] + (1 if S[i:i+2]=='AC' else 0)  

for q in questions:
  print(t[q[1]-1] - t[q[0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
questions = [[i for i in map(int,input().split())] for j in range(Q)]
import re
for question in questions:
  Sp = S[question[0]-1:question[1]]
  print(len(re.findall('AC', Sp)))

Fixed submission:
N,Q = map(int,input().split())
S = input()
questions = [[i for i in map(int,input().split())] for j in range(Q)]
t = [0]*(N+1)
for i in range(N):
  t[i+1] = t[i] + (1 if S[i:i+2]=='AC' else 0)  

for q in questions:
  print(t[q[1]-1] - t[q[0]-1])
Buggy python submission (verdict: Time Limit Exceeded):
part = set()
S = input()
K = int(input())

part.add(S)
for i in range(len(S)):
  for j in range(i,len(S)):
    part.add(S[i:j+1])
    
part = list(part)
part.sort()
print(part[K-1])

Fixed submission:
part = set()
S = input()
K = int(input())

part.add(S)
for i in range(len(S)):
  for j in range(i,i+K):
    part.add(S[i:j+1])
    
part = list(part)
part.sort()
print(part[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
from numpy import abs
from copy import deepcopy
import numpy as np
N = int(input())
A = [0]+list(map(int,input().split()))+[0]
dist = []

for i in range(N):
  A_cancelled = deepcopy(A)
  A_cancelled.pop(i+1)
  
  from_arr = np.array(A_cancelled[:-1])
  to_arr = np.array(A_cancelled[1:])
  
  dist.append(sum(abs(from_arr - to_arr)))
  
for i in dist:
  print(i)

Fixed submission:
N=int(input())
A=[0]+list(map(int,input().split()))+[0]
cost=sum(abs(A[i+1]-A[i]) for i in range(N+1))
for i in range(1,N+1):
    print(cost-abs(A[i+1]-A[i])-abs(A[i]-A[i-1])+abs(A[i+1]-A[i-1]))

Buggy python submission (verdict: Time Limit Exceeded):
from numpy import abs
from copy import deepcopy
import numpy as np
N = int(input())
A = list(map(int,input().split()))
dist = []

for i in range(N):
  A_cancelled = deepcopy(A)
  A_cancelled.pop(i)
  
  A_cancelled.append(0)
  A_cancelled.insert(0,0)
  
  from_arr = np.array(A_cancelled[:-1])
  to_arr = np.array(A_cancelled[1:])
  
  dist.append(sum(abs(from_arr - to_arr)))
  
for i in dist:
  print(i)

Fixed submission:
N=int(input())
A=[0]+list(map(int,input().split()))+[0]
cost=sum(abs(A[i+1]-A[i]) for i in range(N+1))
for i in range(1,N+1):
    print(cost-abs(A[i+1]-A[i])-abs(A[i]-A[i-1])+abs(A[i+1]-A[i-1]))
Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int, input().split())
print(sum([1 for k in range(0,K+1) for j in range(0,K+1) for i in range(0,K+1) if i+j+k == S]))

Fixed submission:
K,S = map(int, input().split())
print(sum([1 for j in range(0,K+1) for i in range(0,K+1) if 0 <= S-i-j <= K ]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ratios = [[i for i in map(int,input().split())] for j in range(N)]

ans_a = 0
ans_t = 0
ratio = ratios.pop(0)
ans_a = ratio[0]
ans_t = ratio[1]

for ratio in ratios:
  
  i = min(ans_a // ratio[0], ans_t // ratio[1])
  
  while True:
    temp_a = ratio[0]*i
    temp_t = ratio[1]*i
    if temp_a >= ans_a and temp_t >= ans_t:
      ans_a = temp_a
      ans_t = temp_t
      break
    i += 1
    
print(ans_a + ans_t)

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

ans_a = 0
ans_t = 0
ratio = ratios.pop(0)
ans_a = ratio[0]
ans_t = ratio[1]

for ratio in ratios:
  i = max(ans_a // ratio[0], ans_t // ratio[1])
  while True:
    temp_a = ratio[0]*i
    temp_t = ratio[1]*i
    if temp_a >= ans_a and temp_t >= ans_t:
      ans_a = temp_a
      ans_t = temp_t
      break
    i += 1
    
print(ans_a + ans_t)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ratios = [[i for i in map(int,input().split())] for j in range(N)]

ans_a = 0
ans_t = 0
ratio = ratios.pop(0)
ans_a = ratio[0]
ans_t = ratio[1]

for ratio in ratios:
  i = 1
  while True:
    temp_a = ratio[0]*i
    temp_t = ratio[1]*i
    if temp_a >= ans_a and temp_t >= ans_t:
      ans_a = temp_a
      ans_t = temp_t
      break
    i += 1
    
print(ans_a + ans_t)

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

ans_a = 0
ans_t = 0
ratio = ratios.pop(0)
ans_a = ratio[0]
ans_t = ratio[1]

for ratio in ratios:
  i = max(ans_a // ratio[0], ans_t // ratio[1])
  while True:
    temp_a = ratio[0]*i
    temp_t = ratio[1]*i
    if temp_a >= ans_a and temp_t >= ans_t:
      ans_a = temp_a
      ans_t = temp_t
      break
    i += 1
    
print(ans_a + ans_t)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
X, Y, A, B, C = map(int, input().split())
P = sorted(list(map(int, input().split())))
Q = sorted(list(map(int, input().split())))
R = sorted(list(map(int, input().split())))

A = P[-X:]
G = Q[-Y:]

for r in R[::-1]:
    if r - min(A[-X], G[-Y]) < 0:
        break

    if A[-X] <= G[-Y]:
        bisect.insort(A, r)
    else:
        bisect.insort(G, r)

# print(A[-X:], G[-Y:])
# print(A[:], G[:])
print(sum(A[-X:]) + sum(G[-Y:]))


Fixed submission:
X, Y, A, B, C = map(int, input().split())
P = sorted(list(map(int, input().split())))
Q = sorted(list(map(int, input().split())))
R = list(map(int, input().split()))

A = sorted(P[-X:] + Q[-Y:] + R)
print(sum(A[-(X+Y):]))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
is_lookforward = True
for i in range(Q):
    query = input()
    if query[0] == '1':
        is_lookforward = not is_lookforward
    else:
        F = int(query[2])
        C = query[4]
        if (F == 1 and is_lookforward) or (F == 2 and not is_lookforward):
            S = C + S
        else:
            S = S + C

print(S if is_lookforward else S[::-1])


Fixed submission:
from collections import deque
S = input()
L = deque()
L.append(S)
Q = int(input())
is_lookforward = True
for i in range(Q):
    query = input()
    if query[0] == '1':
        is_lookforward = not is_lookforward
    else:
        F = int(query[2])
        C = query[4]
        if (F == 1 and is_lookforward) or (F == 2 and not is_lookforward):
            L.appendleft(C)

        else:
            L.append(C)
ans = ''.join(L)
print(ans if is_lookforward else ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = list(map(int, input().split()))
# print(P)
E = [(p*(p+1))/(2*p) for p in P]
# print([sum(E[i:i+K]) for i in range(N-K+1)])
print(max([sum(E[i:i+K]) for i in range(N-K+1)]))


Fixed submission:
N, K = map(int, input().split())
P = list(map(int, input().split()))
# print(P)
E = [(p*(p+1))/(2*p) for p in P]
# print([sum(E[i:i+K]) for i in range(N-K+1)])
S = [0]
for i in range(N):
    S.append(S[i] + E[i])
print(max([S[i+K] - S[i] for i in range(N-K+1)]))

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
P = list(map(int, input().split()))
# print(P)
E = [(p*(p+1))/(2*p) for p in P]
print(max([sum(E[i:i+K]) for i in range(N-K)]))


Fixed submission:
N, K = map(int, input().split())
P = list(map(int, input().split()))
# print(P)
E = [(p*(p+1))/(2*p) for p in P]
# print([sum(E[i:i+K]) for i in range(N-K+1)])
S = [0]
for i in range(N):
    S.append(S[i] + E[i])
print(max([S[i+K] - S[i] for i in range(N-K+1)]))
Buggy python submission (verdict: Runtime Error):
S = input()
print(len([True for s in range(len(S)//2) if S[i] != S[-1-i]]))

Fixed submission:
S = input()
print(len([True for i in range(len(S)//2) if S[i] != S[-1-i]]))
Buggy python submission (verdict: Runtime Error):
X = int(input())
dp = [False] * (X+100)
for i in range(6):
    dp[100+i] = True
for i in range(X+10):
    for k in range(6):
        if i - 100 - k > 0:
            dp[i] = dp[i] or dp[i-100-k]
print(1 if dp[X] else 0)


Fixed submission:
X = int(input())
dp = [0] * (X+1000)
for i in range(6):
    dp[100+i] = 1
for i in range(X+10):
    for k in range(6):
        if i - 100 - k > 0:
            dp[i] = dp[i] | dp[i-100-k]
print(dp[X])

Buggy python submission (verdict: Runtime Error):
X = int(input())
dp = [False] * (X+100)
for i in range(6):
    dp[100+i] = True
for i in range(107, X+10):
    for k in range(6):
        dp[i] = dp[i] or dp[i-100-k]
print(1 if dp[X] else 0)


Fixed submission:
X = int(input())
dp = [0] * (X+1000)
for i in range(6):
    dp[100+i] = 1
for i in range(X+10):
    for k in range(6):
        if i - 100 - k > 0:
            dp[i] = dp[i] | dp[i-100-k]
print(dp[X])

Buggy python submission (verdict: Runtime Error):
X = int(input())
dp = [False] * (X+100)
for i in range(6):
    dp[100+i] = True
for i in range(107, X+100):
    for k in range(6):
        dp[i] = dp[i] or dp[i-100-k]
print(1 if dp[X] else 0)


Fixed submission:
X = int(input())
dp = [0] * (X+1000)
for i in range(6):
    dp[100+i] = 1
for i in range(X+10):
    for k in range(6):
        if i - 100 - k > 0:
            dp[i] = dp[i] | dp[i-100-k]
print(dp[X])

Buggy python submission (verdict: Runtime Error):
X = int(input())
dp = [False] * (X+100)
for i in range(6):
    dp[100+i] = True
for i in range(107, X+100):
    for k in range(6):
        dp[i] = dp[i] or dp[i-100-k]
print(1 if dp[X] else 0)


Fixed submission:
X = int(input())
dp = [0] * (X+1000)
for i in range(6):
    dp[100+i] = 1
for i in range(X+10):
    for k in range(6):
        if i - 100 - k > 0:
            dp[i] = dp[i] | dp[i-100-k]
print(dp[X])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
S = input()
ansset = set()
counts = np.zeros((N+1, 10))
for i in range(N):
    for j in range(10):
        counts[i+1, j] = counts[i, j] + (j == int(S[i]))
for i in range(1, N-1):
    for j in range(10):
        if counts[i, j] == 0:
            continue

        for k in range(10):
            if counts[N, k] - counts[i+1, k] == 0:
                continue

            ansset.add(100*j + 10*int(S[i]) + k)

print(len(ansset))


Fixed submission:
def ok(target, S):
    for t in target:
        if t in S:
            S = S[S.index(t)+1:]
        else:
            return False
    return True


N = int(input())
S = input()
ans = 0

for i in range(0, 999+1):
    target = str(i).zfill(3)
    ans += ok(target, S)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
S = input()

# dp = [[[False]*1009 for _ in range(4)] for _ in range(30009)]
dp = np.zeros((N+9, 4, 1009))
# dp[0][0][0] = True
dp[0, 0, 0] = 1

for i in range(N):
    for j in range(4):
        for k in range(1000):
            # jif not dp[i][j][k]:
            if not dp[i, j, k]:
                continue

            dp[i + 1, j, k] = 1
            if j <= 2:
                dp[i+1, j+1, k*10 + int(S[i])] = 1

print(int(np.sum(dp[N, 3, :])))


Fixed submission:
def ok(target, S):
    for t in target:
        if t in S:
            S = S[S.index(t)+1:]
        else:
            return False
    return True


N = int(input())
S = input()
ans = 0

for i in range(0, 999+1):
    target = str(i).zfill(3)
    ans += ok(target, S)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

dp = [[[False]*1009 for _ in range(4)] for _ in range(30009)]
dp[0][0][0] = True

for i in range(N):
    for j in range(4):
        for k in range(1000):
            if not dp[i][j][k]:
                continue

            dp[i + 1][j][k] = True
            if j <= 2:
                dp[i+1][j+1][k*10 + int(S[i])] = True

print(sum(dp[N][3]))


Fixed submission:
def ok(target, S):
    for t in target:
        if t in S:
            S = S[S.index(t)+1:]
        else:
            return False
    return True


N = int(input())
S = input()
ans = 0

for i in range(0, 999+1):
    target = str(i).zfill(3)
    ans += ok(target, S)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
print(sum([i for i in range(1, N)]))


Fixed submission:
N = int(input())
print(N*(N-1)//2)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
A, B, C, D = map(int, input().split())
sc = B//C - (A-1)//C
sd = B//D - (A-1)//D
scd = B//gcd(C, D) - (A-1)//math.gcd(C, D)
print(sc, sd, scd, B-A+1)
print(B-A+1 - sc - sd + scd)


Fixed submission:
from fractions import gcd


def lcm(a, b):
    return (a*b)//gcd(a, b)


A, B, C, D = map(int, input().split())
sc = B//C - (A-1)//C
sd = B//D - (A-1)//D
scd = B//lcm(C, D) - (A-1)//lcm(C, D)
#print(B//lcm(C, D), (A-1)//lcm(C, D))
#print(sc, sd, scd, B-A+1)
print(B-A+1 - sc - sd + scd)

Buggy python submission (verdict: Runtime Error):
import math
A, B, C, D = map(int, input().split())
sc = B//C - (A-1)//C
sd = B//D - (A-1)//D
scd = B//math.gcd(C, D) - (A-1)//math.gcd(C, D)
print(sc, sd, scd, B-A+1)
print(B-A+1 - sc - sd + scd)


Fixed submission:
from fractions import gcd


def lcm(a, b):
    return (a*b)//gcd(a, b)


A, B, C, D = map(int, input().split())
sc = B//C - (A-1)//C
sd = B//D - (A-1)//D
scd = B//lcm(C, D) - (A-1)//lcm(C, D)
#print(B//lcm(C, D), (A-1)//lcm(C, D))
#print(sc, sd, scd, B-A+1)
print(B-A+1 - sc - sd + scd)

Buggy python submission (verdict: Runtime Error):
import math
A, B, C, D = map(int, input().split())
sc = B//C - (A-1)//C
sd = B//D - (A-1)//D
scd = B//math.gcd(C, D) - (A-1)//math.gcd(C, D)
print(sc, sd, scd, B-A+1)
print(B-A+1 - sc - sd + scd)


Fixed submission:
from fractions import gcd


def lcm(a, b):
    return (a*b)//gcd(a, b)


A, B, C, D = map(int, input().split())
sc = B//C - (A-1)//C
sd = B//D - (A-1)//D
scd = B//lcm(C, D) - (A-1)//lcm(C, D)
#print(B//lcm(C, D), (A-1)//lcm(C, D))
#print(sc, sd, scd, B-A+1)
print(B-A+1 - sc - sd + scd)

Buggy python submission (verdict: Runtime Error):
import math
A, B, C, D = map(int, input().split())
sc = B//C - (A-1)//C
sd = B//D - (A-1)//D
scd = B//(math.gcdC, D) - (A-1)//math.gcd(C, D)
print(sc, sd, scd, B-A+1)
print(B-A+1 - sc - sd + scd)


Fixed submission:
from fractions import gcd


def lcm(a, b):
    return (a*b)//gcd(a, b)


A, B, C, D = map(int, input().split())
sc = B//C - (A-1)//C
sd = B//D - (A-1)//D
scd = B//lcm(C, D) - (A-1)//lcm(C, D)
#print(B//lcm(C, D), (A-1)//lcm(C, D))
#print(sc, sd, scd, B-A+1)
print(B-A+1 - sc - sd + scd)
Buggy python submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())
print(W*H//2, 1 int(x == y == W/2))


Fixed submission:
W, H, x, y = map(int, input().split())
print(W*H/2, int(2*x == W and 2*y == H))
Buggy python submission (verdict: Runtime Error):
N = input()
W = list(map(int, input().split()))
print(min([abs(sum(W[:i]) - sum(W[i:])) for i in range(N)]))


Fixed submission:
N = int(input())
W = list(map(int, input().split()))
print(min([abs(sum(W[:i]) - sum(W[i:])) for i in range(N)]))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = []
for _ in range(M):
    S.append(list(map(int, input().split()))[1:])
p = map(int, input().split())
ans = 0
for bit in range(1 << N):
    for m in range(M):
        if p[m] != ([str(bit).zfill(N)[s-1] for s in S[m]].count('1') % 2):
            break
    else:
        ans += 1
print(ans)


Fixed submission:
N, M = map(int, input().split())
S = []
for _ in range(M):
    S.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
    for m in range(M):
        if p[m] != ([bin(bit)[2:].zfill(N)[s-1] for s in S[m]].count('1') % 2):
            break
    else:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B = map(int, input().split())
print(max(2*a-1, 2*b-1, a+b))

Fixed submission:
a,b = map(int, input().split())
print(max(2*a-1, 2*b-1, a+b))
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
acc = [0] * (N+1)
for i in range(0, N):
    acc[i+1] = acc[i] + (S[i+1] == "C" and S[i] == "A")
for i in range(Q):
    l, r = map(int, input().split())
    print(acc[r-1] - acc[l-1])


Fixed submission:
N, Q = map(int, input().split())
S = input()
acc = [0] * (N+1)
for i in range(0, N):
    acc[i+1] = acc[i] + (i+1 < N and S[i+1] == "C" and S[i] == "A")
for i in range(Q):
    l, r = map(int, input().split())
    print(acc[r-1] - acc[l-1])

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
acc = []
for i in range(1, Q+2):
    acc.append(S[0:i].count("AC"))

for i in range(Q):
    l, r = map(int, input().split())
    print(acc[r] - acc[l-1])


Fixed submission:
N, Q = map(int, input().split())
S = input()
acc = [0] * (N+1)
for i in range(0, N):
    acc[i+1] = acc[i] + (i+1 < N and S[i+1] == "C" and S[i] == "A")
for i in range(Q):
    l, r = map(int, input().split())
    print(acc[r-1] - acc[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
for i in range(Q):
    l, r = map(int, input().split())
    print(S[l-1: r].count("AC"))


Fixed submission:
N, Q = map(int, input().split())
S = input()
acc = [0] * (N+1)
for i in range(0, N):
    acc[i+1] = acc[i] + (i+1 < N and S[i+1] == "C" and S[i] == "A")
for i in range(Q):
    l, r = map(int, input().split())
    print(acc[r-1] - acc[l-1])

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
for i in range(Q):
    l, r = map(int, input().split())
    print(S[l-1, r].count("AC"))


Fixed submission:
N, Q = map(int, input().split())
S = input()
acc = [0] * (N+1)
for i in range(0, N):
    acc[i+1] = acc[i] + (i+1 < N and S[i+1] == "C" and S[i] == "A")
for i in range(Q):
    l, r = map(int, input().split())
    print(acc[r-1] - acc[l-1])