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

Fixed submission:
N,M = map(int,input().split())
m = 0
v = input().split()
for i in range(N): v[i] = int(v[i])
  
v.sort(reverse=True)
v_min = sum(v)/4/M

while len(v):
  if v.pop(0) >= v_min:
    m += 1
  else:
    break

if M <= m:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
m = 0
v = input().split()
for i in range(N): v[i] = int(v[i])
  
v.sort(reverse=True)
v_min = sum(v)/4/M

while v[0]:
  if v.pop(0) >= v_min:
    m += 1
  else:
    break

if M <= m:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
m = 0
v = input().split()
for i in range(N): v[i] = int(v[i])
  
v.sort(reverse=True)
v_min = sum(v)/4/M

while v[0]:
  if v.pop(0) >= v_min:
    m += 1

if M <= m:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
m = 0
v = input().split()
for i in range(N): v[i] = int(v[i])
  
v.sort(reverse=True)
v_min = sum(v)/4/M

while v.pop(0) >= v_min:
  m += 1

if M <= m:
  print("Yes")
else:
  print("No")
Problem p02681 (python)

Fixed submission:
s = input()
t = input()
if len(s)+1 == len(t) and s == t[:-1]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
if len(s)+1 = len(t):
  print("Yes")
else:
  print("No")
Problem p02702 (python)

Fixed submission:
s = input()
a = 0
mods = [0]*2019
mods[a] += 1
r = 1
for i in s[::-1]:
  a = (a+int(i)*r)%2019
  r = r*10%2019
  mods[a] += 1
ans = 0
for i in mods:
  ans += i*(i-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
a = int(s)%2019
mod_N = [0]*2019
mod_N[a] += 1
r = 10**(len(s)-1)
for i in s:
  a = (a-int(i)*10**d)%2019
  d = d//10
  mod_N[a] += 1
ans = 0
for i in mod_N:
  ans += i*(i-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
a = int(s)%2019
mod_N = [0]*2019
mod_N[a] += 1
r = 10**(len(s)-1)
for i in range(len(s)):
  a = (a-int(s[i])*10**d)%2019
  d = d//10
  mod_N[a] += 1
ans = 0
for i in mod_N:
  ans += i*(i-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
a = int(s)
mods = [a%2019]
for i in range(len(s)):
  a = int((a-int(s[-(i+1)]))/10)
  mods.append(a%2019)
mod_N ={}
for i in mods:
  if not i in mod_N:
    mod_N[i] = 1
  else:
    mod_N[i] += 1
ans = 0
for i in mod_N:
  ans += int(mod_N[i]*(mod_N[i]-1)/2)
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
a = int(s)
mods = [a%2019]
for i in range(len(s)):
  a = int((a-int(s[-(i+1)]))/10)
  mods.append(a%2019)
mod_N ={}
for i in mods:
  if not i in mod_N:
    mod_N[i] = 0
  else:
    mod_N[i] += 1
ans = 0
for i in mod_N:
  ans += int(mod_N[i]*(mod_N[i]-1)/2)
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
a = int(s)
mods = [a%2019]
for i in range(len(s)):
  a = int((a-int(s[-(i+1)]))10)
  mods.append(a%2019)
mod_N ={}
for i in mods:
  if not i in mod_N:
    mod_N[i] = 0
  else:
    mod_N[i] += 1
ans = 0
for i in mod_N:
  ans += int(i*(i-1)/2)
print(ans)
Problem p02714 (python)

Fixed submission:
import statistics as st
n = int(input())
s = input()
NGs = 0
r = set()
g = set()
b = set()
for i in range(n):
  if s[i] == "R":
    r.add(i)
  elif s[i] == "G":
    g.add(i)
  else:
    b.add(i)
for i in range(n-2):
  for d in range((n-i-1)//2+1):
    j = i+d
    k = j+d
    if i in r and j in g and k in b:
      NGs += 1
    elif i in r and j in b and k in g:
      NGs += 1
    elif i in g and j in r and k in b:
      NGs += 1
    elif i in g and j in b and k in r:
      NGs += 1
    elif i in b and j in r and k in g:
      NGs += 1
    elif i in b and j in g and k in r:
      NGs += 1
print(len(r)*len(g)*len(b)-NGs)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
ans = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    if s[i] != s[j]:
    for k in range(j+1, n):
      if s[j] != s[k] and s[k]!= s[i]:
        if j-i != k-j:
          ans +=1
print(ans)
Problem p02730 (python)

Fixed submission:
s = input()
t = s[:int((len(s)-1)/2)]
u = s[(int((len(s)+3)/2)-1):]
if s == s[::-1] and t == t[::-1] and u == u[::-1]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = input()
t = s[:int((len(s)-1)/2)]
u = s[(int(len(s)+3)/2-1):]
if s == s[::-1] and t == t[::-1] and u == u[::-1]:
  print("Yes")
else:
  print("No")
Problem p02732 (python)

Fixed submission:
n = int(input())
L = [int(i) for i in input().split()]
t = set(L)
dn = {}
dc = {}
All = 0
for i in t:
  dn[i] = 0
for i in L:
  dn[i] += 1
for i in t:
  dc[i] = int(dn[i]*(dn[i]-1)/2)
  All += dc[i]
for i in range(n):
  print(All-dc[L[i]] + int((dn[L[i]]-1)*(dn[L[i]]-2)/2))

Buggy submission (verdict: Runtime Error):
n = int(input())
L = [int(i) for i in input().split()]
t = set(L)
dn = {}
dc = {}
All = 0
for i in L:
  dn[i] += 1
for i in t:
  dc[i] = int(dn[i]*(dn[i]-1)/2)
  All += dc[i]
for i in range(n):
  print(All-dc[L[i]] + int((dn[L[i]]-1)*(dn[L[i]]-2)/2))

Buggy submission (verdict: Runtime Error):
n = int(input())
L = [int(i) for i in input().split()]
t = set(L)
dn = {}
dc = {}
All = 0
for i in t:
  dn[i] = L.count(i)
  dc[i] = int(dn[i]*(dn[i]-1)/2)
  All += dc[i]
for i in range(n):
  print(All-dc[L[i]] + int((dn[L[i]-1]-1)*(dn[L[i]-2])/2))
Problem p02865 (python)

Fixed submission:
print(int((int(input())-1)/2))

Buggy submission (verdict: Runtime Error):
print(round(input()/2)-1)
Problem p03469 (python)

Fixed submission:
s = input()
print("2018/01/"+s[-2:])

Buggy submission (verdict: Runtime Error):
s = input()
print("2017/01/"+s[-2:]
Problem p03543 (python)

Fixed submission:
s = input()
l = [int(s[i]) for i in range(4)]
a, b, c, d = map(int, l)
m = 100*a+10*b+c
n = 100*b+10*c+d
if m%111 == 0 or n%111 == 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split(""))
m = 100*a+10*b+c
n = 100*b+10*c+d
if m%111 == 0 or n%111 == 0:
  print("Yes")
else:
  print("No")
Problem p03826 (python)

Fixed submission:
a, b, c, d = map(int, input().split())
print(max(a*b, c*d))

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input(),split())
print(max(a*b, c*d))
Problem p03844 (python)

Fixed submission:
a, b, c = map(str, input().split())
if b == "+":
  print(int(a)+int(c))
else:
  print(int(a)-int(c))

Buggy submission (verdict: Runtime Error):
a, b, c = map(str, input().split())
if b == "+":
  print(int(a)+int(b))
else:
  print(int(a)-int(b))
Problem p03943 (python)

Fixed submission:
l = sorted([int(i) for i in input().split()])
if l[2] == l[1] + l[0]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = set([int(i) for i in input().split()])
if s.pop() == s.pop() + s.pop():
  print("Yes")
else:
  print("No")
Problem p03998 (python)

Fixed submission:
a = input()
b = input()
c = input()
Sa = [a[i] for i in range(len(a))]
Sb = [b[i] for i in range(len(b))]
Sc = [c[i] for i in range(len(c))]
turn = "a"
while True:
  if turn == "a":
    if len(Sa) == 0:
      print("A")
      break
    else:
      turn = Sa.pop(0)
  elif turn == "b":
    if len(Sb) == 0:
      print("B")
      break
    else:
      turn = Sb.pop(0)
  else:
    if len(Sc) == 0:
      print("C")
      break
    else:
      turn = Sc.pop(0)

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
c = input()
Sa = [a[i] for i in range(len(a))]
Sb = [b[i] for i in range(len(b))]
Sc = [c[i] for i in range(len(c))]
turn = "a"
while True:
  if turn == "a":
    if len(Sa) == 0:
      print("A")
      break
    else:
      turn = Sa.pop(0)
  elif turn == "b":
    if len(Sb) == 0:
      print("B")
      break
    else:
      turn = Sb.pop(0)
  elif: turn == "c":
    if len(Sc) == 0:
      print("C")
      break
    else:
      turn = Sc.pop(0)

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
c = input()
Sa = [a[i] for i in range(a)]
Sb = [b[i] for i in range(b)]
Sc = [c[i] for i in range(c)]
turn = "a"
while True:
  if turn == "a":
    if len(Sa) == 0:
      print("A")
      break
    else:
      turn = Sa.pop(0)
  elif turn == "b":
    if len(Sb) == 0:
      print("B")
      break
    else:
      turn = Sb.pop(0)
  else:
    if len(Sc) == 0:
      print("C")
      break
    else:
      turn = Sc.pop(0)
Problem p04044 (python)

Fixed submission:
N, L = map(int, input().split())
l = [input() for _ in range(N)]
l = sorted(l)
s = ""
for i in range(N):
  s += l[i]
print(s)

Buggy submission (verdict: Runtime Error):
N, L = map(int, input().split())
l = [input() for _ in range(L)]
l = sorted(l)
s = ""
for i in range(L):
  s += l[i]
print(s)

Buggy submission (verdict: Runtime Error):
N, L = map(int, input().split())
l = [input() for _ in range(L)]
l.sort()
s = ""
for i in range(L):
  s += l[i]
print(s)
Problem p02681 (python)

Fixed submission:
s = str(input())
t = str(input())
flag = True
if(len(s) == len(t)-1):
  x = len(s)
  for i in range(x):
    if s[i]!=t[i]:
      flag = False
else:
    flag = False
if(flag):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
flag = True
if(len(s) = len(t)-1):
  x = len(s)
  for i in range(x):
    if s[i]!=t[i]:
      flag = False
if(flag):
  print("Yes")
else:
  print("No")
Problem p02813 (python)

Fixed submission:
import math
import numpy as np

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

a = 1
a_list = list(np.arange(N) + 1)
for i in range(N - 1):
    a += a_list.index(P[i]) * math.factorial(N - (i + 1))
    a_list.remove(P[i])
    
b = 1
b_list = list(np.arange(N) + 1)
for j in range(N):
    b += b_list.index(Q[j]) * math.factorial(N - (j + 1))
    b_list.remove(Q[j])
    
print(abs(a - b))

Buggy submission (verdict: Runtime Error):
import fractions
import math

N, M = map(int, input().split())
a = list(map(int, input().split()))
a_uniq = list(set(a))

len_a = len(a_uniq)

# find lcm
gcd_a = a_uniq[0]
for i in range(1, len_a):
    gcd_a = fractions.gcd(gcd_a, a_uniq[i])

lcm = 1
for j in range(len_a):
    lcm *= a_uniq[j]
    
lcm = lcm / gcd_a
lcm /= 2

print(math.ceil((M / lcm) / 2), lcm, M)
Problem p02866 (python)

Fixed submission:
import collections
import operator

N = int(input())
D = list(map(int, input().split()))

D_dict = collections.Counter(D)
D_dict_sorted = sorted(D_dict.items(), key=operator.itemgetter(0))

# l = []
# for i in range(int(max(D))):
#     if D_dict_sorted[i][0] + 1 == D_dict_sorted[i+1][0]
#     l.append()

if (D[0] == 0) and (D_dict_sorted[0][1] == 1) :
    ans = 1
    for i in range(len(D_dict_sorted)-1):
        if D_dict_sorted[i][0] + 1 == D_dict_sorted[i+1][0]:
            ans *= D_dict_sorted[i][1] ** D_dict_sorted[i+1][1]
            if ans >= 998244353:
                ans = ans % 998244353
        else:
            ans = 0
else:
    ans = 0

print(ans)

Buggy submission (verdict: Runtime Error):
import collections
import operator

N = int(input())
D = list(map(int, input().split()))

D_dict = collections.Counter(D)
D_dict_sorted = sorted(D_dict.items(), key=operator.itemgetter(0))

if not D[0] != 0:
    ans = 1
    for i in range(int(max(D))):
        ans *= D_dict_sorted[i][1] ** D_dict_sorted[i+1][1]
        if ans >= 998244353:
            ans = ans % 998244353
else:
    ans = 0

print(ans)

Buggy submission (verdict: Runtime Error):
import collections
import operator

N = int(input())
D = list(map(int, input().split()))

D_dict = collections.Counter(D)
D_dict_sorted = sorted(D_dict.items(), key=operator.itemgetter(0))

if not D[0] != 0:
    ans = 1
    for i in range(int(max(D))):
        ans *= D_dict_sorted[i][1] ** D_dict_sorted[i+1][1] % 998244353
else:
    ans = 0

print(ans)

Buggy submission (verdict: Runtime Error):
import collections
import operator

N = int(input())
D = list(map(int, input().split()))

D_dict = collections.Counter(D)
D_dict_sorted = sorted(D_dict.items(), key=operator.itemgetter(0))

if not D[0] != 0:
    ans = 1
    for i in range(int(max(D))):
        ans *= D_dict_sorted[i][1] ** D_dict_sorted[i+1][1]
else:
    ans = 0

print(ans % 998244353)

Buggy submission (verdict: Runtime Error):
import collections
import operator

N = int(input())
D = list(map(int, input().split()))

D_dict = collections.Counter(D)
D_dict_sorted = sorted(D_dict.items(), key=operator.itemgetter(0))

if not D[0] != 0:
    ans = 1
    for i in range(int(max(D))):
        ans *= D_dict_sorted[i][1] ** D_dict_sorted[i+1][1]
else:
    ans = 0

print(ans)
Problem p02953 (python)

Fixed submission:
import sys

N = int(input())
H = list(map(int, input().split()))

for i in range(1, N):
    if H[i] + 1 == H[i-1]:
        H[i] += 1
    elif H[i] + 1 < H[i-1]:
        print("No")
        sys.exit()
    
print("Yes")

Buggy submission (verdict: Runtime Error):
import sys

N = int(input())
H = list(map(int, input().split()))

for i in range(1, N):
    if H[i] >= H[i-1] - 1:
        H[i-1] -= 1
    elif H[i] < H[i-1] - 1:
        print("No")
        sys.exit()

if flag == 0:
    print("Yes")
Problem p02994 (python)

Fixed submission:
import numpy as np

N, L = map(int, input().split())

aji_sum = 1 / 2 * N * (N + 2*L - 1)
aji_arr = np.ones(N) * L
aji_arr += np.arange(N)

eat_a = aji_arr[np.argmin(np.abs(aji_arr))]
    
print(int(aji_sum - eat_a))

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

aji_sum = 1 / 2 * N * (N + 2*L - 1)

if L < 0 and L + N > 0:
    eat_a = 0
elif L < 0 and L + N < 0:
    eat_a = L + N
elif L > 0 and L + N > 0:
    eat_a = L
print(int(aji_sum - eat_a))
Problem p03029 (python)

Fixed submission:
a_, p_ = input().split()
a = int(a_)
p = int(p_)

print( ((a * 3) + p) // 2)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, M = map(int, input().split())

ks_list = []
for i in range(M):
    ks = list(map(int, input().split()))
    ks_list.append(ks)
    
p = list(map(int, input().split()))
ans = 0

for x in range(2 ** N + 1):
#     print("===========", x, ans)
    for m in range(M):
        c = 0
        for k in range(1, ks_list[m][0]+1):
            ks_mk = -ks_list[m][k]
            if int(format(x,'b').zfill(10)[ks_mk]) == 1:
                c += 1
#             print(ks_list, ks_list[m][k], ks_mk, format(x,'b').zfill(10), format(x,'b').zfill(10)[ks_mk])
#         print(c, p[m])
        if c % 2 != p[m]:
#             print("break")
            break
        if m == M-1:
            ans += 1
#     print(ans, ks_list, c, p)

print(ans)
Problem p03031 (python)

Fixed submission:
N, M = map(int, input().split())
s = [list(map(lambda s: int(s) - 1, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))
# print(s)
# print(p)
ret = 0
for i in range(2 ** N):
    on = list(map(int, bin(i)[2:]))
#     print(on)
    on = ([0] * N + on)[-N:]
#     print(on)
    for si, pi in zip(s, p):
        if sum(on[sij] for sij in si) % 2 != pi:
            break
    else:
        ret += 1
print(ret)

Buggy submission (verdict: Runtime Error):
for x in range(2 ** N + 1):
#     print("===========", x, ans)
    for m in range(M):
        c = 0
        for k in range(1, ks_list[m][0]+1):
            ks_mk = -ks_list[m][k]
            if int(format(x,'b').zfill(10)[ks_mk]) == 1:
                c += 1
#             print(ks_list, ks_list[m][k], ks_mk, format(x,'b').zfill(10), format(x,'b').zfill(10)[ks_mk])
#         print(c, p[m])
        if c % 2 != p[m]:
#             print("break")
            break
        if m == M-1:
            ans += 1
#     print(ans, ks_list, c, p)

print(ans)
Problem p03037 (python)

Fixed submission:
N, M = map(int, input().split())
L = 0
R = N
for i in range(M):
    l, r = map(int, input().split())
    L = max(L, l)
    R = min(R, r)

print(max(0, R - L + 1))

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

for i in range(M):
    l, r = map(int, input().split())
    L = max(L, l)
    R = min(R, r)

print(L - R + 1)
Problem p03061 (python)

Fixed submission:
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
L = [0]
R = [0]
for i in range(N-1):
    L.append(gcd(L[i], A[i]))
    R.append(gcd(R[i], A[-i-1]))
MAX = 0
for i in range(N):
    MAX = max(MAX, gcd(L[i], R[-i-1]))
print(MAX)

Buggy submission (verdict: Runtime Error):

import fractions
N = int(input())
A = list(map(int, input().split()))
L = [0]
R = [0]
for i in range(N-1):
    L.append(gcd(L[i], A[i]))
    R.append(gcd(R[i], A[-i-1]))
MAX = 0
for i in range(N):
    MAX = max(MAX, gcd(L[i], R[-i-1]))
print(MAX)

Buggy submission (verdict: Runtime Error):

import fractions
L = [0]
R = [0]
for i in range(N-1):
    L.append(gcd(L[i], A[i]))
    R.append(gcd(R[i], A[-i-1]))
MAX = 0
for i in range(N):
    MAX = max(MAX, gcd(L[i], R[-i-1]))
print(MAX)

Buggy submission (verdict: Runtime Error):
import functools
import math
N = int(input())
A = list(map(int, input().split()))
gcd_max = 1
for i in range(N):
    gcd = functools.reduce(math.gcd, A[i+1:] + A[:i])
    if gcd > gcd_max:
        gcd_max = gcd

print(gcd_max)

Buggy submission (verdict: Runtime Error):
import functools
import math
N = int(input())
A = list(map(int, input().split()))
gcd_max = 1
for i in range(N):
    gcd = functools.reduce(math.gcd, A[i+1:] + A[:i])
    if gcd > gcd_max:
        gcd_max = gcd
        i_max = i

print(gcd_max)
Problem p03076 (python)

Fixed submission:
import sys
import numpy as np

a_t=int(input())
b_t=int(input())
c_t=int(input())
d_t=int(input())
e_t=int(input())

a_d = a_t % 10
b_d = b_t % 10
c_d = c_t % 10 
d_d = d_t % 10
e_d = e_t % 10

dish_d = np.zeros(5)
dish_d[0] = a_d
dish_d[1] = b_d
dish_d[2] = c_d
dish_d[3] = d_d
dish_d[4] = e_d

if any(dish_d) == 0:
    time = (
        a_t // 10 + np.where(a_d==0, 0, 1) \
        + b_t  // 10 + np.where(b_d==0, 0, 1) \
        + c_t // 10 + np.where(c_d==0, 0, 1) \
        + d_t // 10 + np.where(d_d==0, 0, 1) \
        + e_t // 10 + + np.where(e_d==0, 0, 1)
       ) * 10
else:
    time = (
            a_t // 10 + np.where(a_d==0, 0, 1) \
            + b_t  // 10 + np.where(b_d==0, 0, 1) \
            + c_t // 10 + np.where(c_d==0, 0, 1) \
            + d_t // 10 + np.where(d_d==0, 0, 1) \
            + e_t // 10 + + np.where(e_d==0, 0, 1)
           ) * 10 - (10 - np.min(dish_d[np.nonzero(dish_d)]))
print(int(time))

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np

a_t=int(input())
b_t=int(input())
c_t=int(input())
d_t=int(input())
e_t=int(input())

a_d = a_t % 10
b_d = b_t % 10
c_d = c_t % 10 
d_d = d_t % 10
e_d = e_t % 10

dish_d = np.zeros(5)
dish_d[0] = a_d
dish_d[1] = b_d
dish_d[2] = c_d
dish_d[3] = d_d
dish_d[4] = e_d

time = (
        a_t // 10 + np.where(a_d==0, 0, 1) \
        + b_t  // 10 + np.where(b_d==0, 0, 1) \
        + c_t // 10 + np.where(c_d==0, 0, 1) \
        + d_t // 10 + np.where(d_d==0, 0, 1) \
        + e_t // 10 + + np.where(e_d==0, 0, 1)
       ) * 10 - (10 - np.min(dish_d[np.nonzero(dish_d)]))
print(int(time))
Problem p03087 (python)

Fixed submission:
N, Q = map(int, input().split())
S = input()
t = [0] * (N+1)
ans = []

for i in range(N):
    t[i+1] += t[i] + ( 1 if S[i:i+2] == 'AC' else 0) 

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

Buggy submission (verdict: Runtime Error):
import numpy as np

N, Q = map(int, input().split())
S = input()
ac_array = np.zeros(N)
ans = []

for i in range(N):
    if S[i] == 'A' and S[i+1] == 'C':
        ac_array[i] += 1
#         ac_array[i+1] += 1
# print(ac_array)
t = []
t.append(0)
for j in range(N):
    t.append(ac_array[:j+1].sum())
#     print(ac_array[:j+1])
# q_list = np.zeros([Q, 2])
# print(ac_array, t)
for q in range(Q):
    q_l, q_r = map(int, input().split())
    ans.append(t[q_r-1]-t[max(q_l-1, 0)])
    
#     q_list[q, 0], q_list[q, 1] = map(int, input().split())
#     ans.append(ac_array[int(q_list[q, 0]-1):int(q_list[q,1]-1)].sum())   

for a in range(Q):
    print(int(ans[a]))

Buggy submission (verdict: Runtime Error):
import numpy as np

N, Q = map(int, input().split())
S = input()
ac_array = np.zeros(N)
ans = []

for i in range(N):
    if S[i] == 'A' and S[i+1] == 'C':
        ac_array[i] += 1
#         ac_array[i+1] += 1
# print(ac_array)
q_list = np.zeros([Q, 2])
for q in range(Q):
    q_list[q, 0], q_list[q, 1] = map(int, input().split())
    ans.append(ac_array[int(q_list[q, 0]-1):int(q_list[q,1]-1)].sum())

for a in range(Q):
    print(int(ans[a]))

Buggy submission (verdict: Runtime Error):
import numpy as np

N, Q = map(int, input().split())
S = input()
ac_array = np.zeros(N)
ans = []

for i in range(N):
    if S[i] == 'A' and S[i+1] == 'C':
        ac_array[i] += 1
        ac_array[i+1] += 1
#print(ac_array)
q_list = np.zeros([Q, 2])
for q in range(Q):
    q_list[q, 0], q_list[q, 1] = map(int, input().split())
    ans.append(np.trunc(ac_array[int(q_list[q, 0]-1):int(q_list[q,1])].sum()/2))

for a in range(Q):
    print(int(ans[a]))

Buggy submission (verdict: Runtime Error):
import numpy as np

N, Q = map(int, input().split())
S = input()
ac_array = np.zeros(N)
ans = []

for i in range(N):
    if S[i] == 'A' and S[i+1] == 'C':
        ac_array[i] += 1
        ac_array[i+1] += 1
print(ac_array)
q_list = np.zeros([Q, 2])
for q in range(Q):
    q_list[q, 0], q_list[q, 1] = map(int, input().split())
    ans.append(np.trunc(ac_array[int(q_list[q, 0]-1):int(q_list[q,1])].sum()/2))

for a in range(Q):
    print(int(ans[a]))

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
t = [0] * (N+1)
ans = []

for i in range(N):
    t[i+1] += t[i] + ( 1 if S[i:i+2] == 'AC' else 0) 

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

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

for i in range:
    l, r = map(int, input().split())
    print(S[l:r+1].count('AC'))
Problem p03103 (python)

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

res = M
total_p = 0
for i in range(N):
    a, b = map(int, input().split())
    p_list.append(a)
    p_list.append(b)

for price, amount in sorted(zip(p_list[::2], p_list[1::2])):
    total_p += price * min(res, amount)
    res -= amount
    if res <= 0:
        break
        
print(total_p)

Buggy submission (verdict: Runtime Error):
import operator

def get_mincost(M_left, cost, i):
    cost += sorted_d[i][0] * min(sorted_d[i][1], M_left)
    M_left -= min(sorted_d[i][1], M_left)
    i += 1
    if M_left == 0:
        return cost
    return get_mincost(M_left, cost, i)

N, M = map(int, input().split())
M_left = M
cost = 0
i = 0

#dict {A_i(price), B_i(num)}
d = dict(map(int, input().split()) for i in range(N))
global sorted_d
sorted_d = sorted(d.items(), key=operator.itemgetter(0))

print(int(get_mincost(M_left, cost, i)))

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

# for i in range(N):
#     a, b = map(int, input().split())
#     p_list.append([a, b])
    
# p_sort = sorted(p_list, key=lambda x:x[0])
# num = 0
# price = 0
# i = 0
# while num < M:
#     num += p_sort[1][i]
#     price += p_sort[1][i] * p_sort[0][i]
#     if num > M:
#         price -= (num - M) * p_sort[0][i]
#     i += 1
# print(price)
res = M
for i in range(N):
    a, b = map(int, input().split())
    p_list.append(a, b)

for price, amount in sorted(zip(p_list[::2], p_list[1::2])):
    total_p += price * min(res, amount)
    res -= amount
    if res <= 0:
        break
        
print(total_p)

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

for i in range(N):
    a, b = map(int, input().split())
    p_list.append([a, b])
    
p_sort = sorted(p_list, key=lambda x:x[0])
num = 0
price = 0
i = 0
while num < M:
    num += p_sort[1][i]
    price += p_sort[1][i] * p_sort[0][i]
    if num > M:
      price -= (num - M) * p_sort[0][i]
    i += 1
print(price)
Problem p03106 (python)

Fixed submission:
A, B, K = map(int, input().split())

div = []

for i in range(1, min(A, B)+1):
    if A % i == 0 and B % i == 0:
        div.append(i)

print(div[-K])

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

div = []

for i in range(1, min(A, B)):
    if A % i == 0 and B % i == 0:
        div.append(i)

print(div[K-1])