Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
a_list = list(map(int, input().split()))
n_operation = 0
for i in range(n):
    even_len = len([a for a in a_list if a % 2 == 0])
    if len(a_list) != even_len:
        print(n_operation)
        exit()
    else:
        a_list = [a / 2 for a in a_list]
        n_operation += 1

print(n_operation)

Fixed submission:
print(input().count("1"))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a_list = list(map(int, input().split())) # list()を忘れずに

def odd_detector(a_list):
    is_odd = 0
    for a_i in a_list:
        if a_i % 2 == 1:
            is_odd = 1
            break
    return is_odd

n_division = 0
while odd_detector(a_list) == 0:
    a_list = [a / 2 for a in a_list]
    n_division += 1

print(n_division)


Fixed submission:
print(input().count("1"))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a_list = list(map(int, input().split())) # list()を忘れずに

n_division = 0

def odd_detector(a_list):
    is_odd = 0
    for a_i in a_list:
        if a_i % 2 == 1:
            is_odd = 1
            break
    return is_odd

while odd_detector(a_list) == 0:
    a_list = [int(a/2) for a in a_list]
    n_division += 1

print(n_division)


Fixed submission:
print(input().count("1"))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a_list = list(map(int, input().split())) # list()を忘れずに

n_division = 0

def odd_detector(a_list):
    is_odd = 0
    for a_i in a_list:
        if a_i % 2 == 1:
            is_odd = 1
            break
    return is_odd

while odd_detector(a_list) == 0:
    a_list = [int(a/2) for a in a_list]
    n_division += 1

print(n_division)


Fixed submission:
print(input().count("1"))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a_list = list(map(int, input().split())) # list()を忘れずに

n_division = 0

def odd_detector(a_list):
    is_odd = 0
    for a_i in a_list:
        if a_i % 2 == 1:
            is_odd = 1
            break
    return is_odd

while odd_detector(a_list) == 0:
    a_list = [a/2 for a in a_list]
    n_division += 1

print(n_division)

Fixed submission:
print(input().count("1"))

Buggy python submission (verdict: Runtime Error):
# 初見不正解：RE (Runtime Error)
n = int(input())
a_list = list(map(int, input().split())) # list()を忘れずに

n_division = 0
is_odd = 0

def odd_detector(a_list):
    for a_i in a_list:
        if a_i % 2 == 1:
            is_odd = 1
            break
    return is_odd

while odd_detector(a_list) == 0:
    a_list = [a/2 for a in a_list]
    n_division += 1

print(n_division)

Fixed submission:
print(input().count("1"))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a_list = list(map(int, input().split())) # list()を忘れずに

n_division = 0
is_odd = 0

def odd_detector(a_list):
    for a_i in a_list:
        if a_i % 2 == 1:
            is_odd = 1
            break
    return is_odd

while odd_detector(a_list) == 0:
    alist = [a/2 for a in a_list]
    n_division += 1
    
print(n_division)

Fixed submission:
print(input().count("1"))
Buggy python submission (verdict: Runtime Error):
def get_new_lucas(l_i_1, l_i_2):
    """
    get a new Lucas number L_i

    l_i_1: L_(i-1),
    l_i_2: L_(i-2)
    """
    return l_i_1 + l_i_2


def main():
    n = int(input())
    tmp_l_i_1 = 1
    tmp_l_i_2 = 2
    for i in range(1, n):
        if i == 1:
            new_lucas_num = get_new_lucas(tmp_l_i_1, tmp_l_i_2)
        else:
            new_lucas_num = get_new_lucas(tmp_l_i_1, tmp_l_i_2)
        tmp_l_i_2 = tmp_l_i_1
        tmp_l_i_1 = new_lucas_num
        
    print(new_lucas_num)


if __name__ == '__main__':
    main()

Fixed submission:
def get_new_lucas(l_i_1, l_i_2):
    """
    get a new Lucas number L_i

    l_i_1: L_(i-1),
    l_i_2: L_(i-2)
    """
    return l_i_1 + l_i_2


def main():
    n = int(input())
    tmp_l_i_1 = 1
    tmp_l_i_2 = 2
    for i in range(n):
        if i == 0:
            new_lucas_num = 1
        if i >= 1:
            new_lucas_num = get_new_lucas(tmp_l_i_1, tmp_l_i_2)
            tmp_l_i_2 = tmp_l_i_1
            tmp_l_i_1 = new_lucas_num
        
    print(new_lucas_num)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#D
N, K = map(int, input().split())
p= [int(x) for x in input().split()]
ap = p
ans = 0
for i in range(N):
    ap[i] = (p[i]+1)/2
for i in range(N-K+1):
    now = 0
    for j in range(K):
        now += ap[i+j]
    ans = max(ans, now)

print (ans)

Fixed submission:
#D
N, K = map(int, input().split())
p= [int(x) for x in input().split()]
ap = p
ans = 0
for i in range(N):
    if i == 0:
        ap[i] = (p[i]+1)/2
    else:
        ap[i] = (p[i]+1)/2 + ap[i-1]
for i in range(N-K+1):
    now = 0
    if i == 0:
        now = ap[K-1]
    else:
        now = ap[K+i-1]-ap[i-1]
    ans = max(ans, now)

print (ans)
Buggy python submission (verdict: Time Limit Exceeded):
#E re
H, N = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
DP = [float('inf')] * (H+1)
DP[0] = 0

for i in range(N):
    for j in range(H):
        nj = min(j+A[i], H)
        DP[nj] = min(DP[nj], DP[j]+B[i])

print(int(DP[H]))


Fixed submission:
#E re
H, N = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
DP = [float('inf')] * (H+1)
DP[0] = 0

for i in range(N):
    for j in range(H):
        nj = min(j+A[i], H)
        DP[nj] = min(DP[nj], DP[j]+B[i])

print(int(DP[H]))

Buggy python submission (verdict: Time Limit Exceeded):
#E re
H, N = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
DP = [0] * H

for i in range(H):
    minM = float('inf')
    for j in range(N):
        if i+1 - A[j] >= 0:
            M = DP[i-A[j]] + B[j]
        else:
            M = B[j]
        if minM > M:
            minM = M
    DP[i] = minM

print(int(DP[H-1]))

Fixed submission:
#E re
H, N = map(int, input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
DP = [float('inf')] * (H+1)
DP[0] = 0

for i in range(N):
    for j in range(H):
        nj = min(j+A[i], H)
        DP[nj] = min(DP[nj], DP[j]+B[i])

print(int(DP[H]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A =[int(x) for x in input().split()]
ans = []

for i in range(N):
  for j in range(N):
    if i+1 == A[j]:
      ans.append(str(j+1))
      break;
L = ' '.join(ans)
print(L)


Fixed submission:
N = int(input())
A =[int(x) for x in input().split()]
ans = [0]*N

for i in range(N):
  ans[A[i]-1] = i+1
  
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
#B
N, K = map(int, input().split())
h = [int(x) for x in input().split()]
c = [float('inf')] * N

for i in range(N):
    if i == 0:
        c[i] = 0
    elif i == 1:
        c[i] = abs(h[1]-h[0])
    else:
        j = 1
        while j <= K and i-j >= 0:
            now = abs(h[i]-h[i-j])+c[i-j]
            c[i] = min(c[i], now)
            j += 1
print(int(c[N-1]))

Fixed submission:
#B
N, K = map(int, input().split())
h = [int(x) for x in input().split()]
c = [float('inf')] * N

for i in range(N):
    if i == 0:
        c[i] = 0
    elif i == 1:
        c[i] = abs(h[1]-h[0])
    else:
        j = 1
        while j <= K and i-j >= 0:
            now = abs(h[i]-h[i-j])+c[i-j]
            c[i] = min(c[i], now)
            j += 1
print(int(c[N-1]))
Buggy python submission (verdict: Runtime Error):
N, Y = map(int, input().split())
for i in range(N + 1):
    for j in range(N - i + 1):
        if i * 10000 + j * 5000 + (N - i - j) * 1000 == y:
            print(i, j, N - i - j)
            exit()
print("-1 -1 -1")

Fixed submission:
N, Y = map(int, input().split())
for i in range(N + 1):
    for j in range(N - i + 1):
        if i * 10000 + j * 5000 + (N - i - j) * 1000 == Y:
            print(i, j, N - i - j)
            exit()
print("-1 -1 -1")
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

ans = 0
count = 1

while(True):
  if K**count <= N < K**(count+1):
    ans = count
    break

  count += 1

print(ans+1)

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

if N >= 10:
  print(R)
else:
  print(R + (10-N) * 100)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

ans = 0
count = 1

while(True):
  if K**count <= N < K**(count+1):
    ans = count
    break

  count += 1

print(ans+1)

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

ans = 0
count = 0

while(True):
  if K**count <= N < K**(count+1):
    ans = count
    break

  count += 1

print(ans+1)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

ans = 0
count = 1

while(True):
  if K**count <= N < K**(count+1):
    ans = count
    break

  count += 1

print(ans+1)

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

ans = 0
count = 0

while(True):
  if K**count <= N < K**(count+1):
    ans = count
    break

  count += 1

print(ans+1)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

count = 1
li = []

for index, a in enumerate(A):
  for b in range(count, len(A)):
    li.append(a * A[b])

  count += 1

li.sort()

print(li[K-1])

Fixed submission:
import sys

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

ans = 'Yes'

a = [A, B, C]

if len(set(a)) == 2:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
d = defaultdict(int)

N, K = map(int, input().split())
li = list(map(int, input().split()))

for i in range(1, 1000+1):
  t = 0
  for s in range(1, i+1):
    t += s * (1 / i)

  d[i] = t

ans = 0

for index, i in enumerate(li):
  if index + K > N:
    break

  t = 0
  for k in range(K):
    t += d[li[index+k]]

  if ans < t:
    ans = t

print(ans)

Fixed submission:
from collections import defaultdict
d = defaultdict(int)

N, K = map(int, input().split())
li = list(map(int, input().split()))

for i in range(1, 1000+1):
  t = 0
  for s in range(1, i+1):
    t += s * (1 / i)

  d[i] = t

ans = 0
t = 0

for index, i in enumerate(li):
  t += d[i]

  if index > K-1:
    t -= d[li[index-K]]

  if ans < t:
    ans = t

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
d = defaultdict(int)

N, K = map(int, input().split())
li = list(map(int, input().split()))

for i in range(1, 1000+1):
  t = 0
  for s in range(1, i+1):
    t += s * (1 / i)

  d[i] = t

ans = 0

for index, i in enumerate(li):
  if index + K > N:
    break

  t = 0
  for k in range(K):
    t += d[li[index+k]]

  if ans < t:
    ans = t

print(ans)

Fixed submission:
from collections import defaultdict
d = defaultdict(int)

N, K = map(int, input().split())
li = list(map(int, input().split()))

for i in range(1, 1000+1):
  t = 0
  for s in range(1, i+1):
    t += s * (1 / i)

  d[i] = t

ans = 0
t = 0

for index, i in enumerate(li):
  t += d[i]

  if index > K-1:
    t -= d[li[index-K]]

  if ans < t:
    ans = t

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))

ans = 0

for index, p in enumerate(P):
  flag = 0

  for i in range(index):
    if p > P[i]:
      flag = 1

  if flag == 0:
    ans += 1

print(ans)

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

ans = 0
min = 10000000

for p in P:
  if min > p:
    ans += 1
    min = p

print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
li = []
for m in range(M):
  li.append(input().split())

ac = 0
wa = 0

for n in range(N + 1):
  if n == 0:
    continue

  for index, i in enumerate(li):
    if int(i[0]) == n and i[1] == 'AC':
      ac += 1
      for indexs, x in enumerate(li):
        if indexs >= index:
          break
        if int(x[0]) == n and x[1] == 'WA':
          wa += 1
      break

print('{0} {1}'.format(ac, wa))

Fixed submission:
s=input()

li = [chr(i) for i in range(97, 97+26)]
ans = 0

for index, i in enumerate(li):
  if i == s:
    ans = index

print(li[ans + 1])
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
li = []
sets = set()
for m in range(M):
  x,y = input().split()
  li.append([int(x), y])
  if y == 'AC':
    sets.add(int(x))

ac = len(sets)
wa = 0

for s in sets:
  for i in li:
    if i[0] == s and i[1] == 'WA':
      wa += 1
    if i[0] == s and i[1] == 'AC':
      break

print('{0} {1}'.format(ac, wa))

Fixed submission:
from collections import defaultdict
d = defaultdict(int)

N,M = map(int,input().split())
li = []
for m in range(M):
  x,y = input().split()
  li.append([int(x), y])

sets = set()

ac = 0
wa = 0

for i in li:
  if i[1] == 'AC':
    if i[0] not in sets:
      sets.add(i[0])
      ac += 1
      wa += d[i[0]]

  else:
    if i[0] not in sets:
      d[i[0]] += 1

print('{} {}'.format(ac, wa))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
li = []
for m in range(M):
  li.append(input().split())

ac = 0
wa = 0

for n in range(N + 1):
  if n == 0:
    continue

  for index, i in enumerate(li):
    if int(i[0]) == n and i[1] == 'AC':
      ac += 1
      for indexs, x in enumerate(li):
        if indexs >= index:
          break
        if int(x[0]) == n and x[1] == 'WA':
          wa += 1
      break

print('{0} {1}'.format(ac, wa))

Fixed submission:
from collections import defaultdict
d = defaultdict(int)

N,M = map(int,input().split())
li = []
for m in range(M):
  x,y = input().split()
  li.append([int(x), y])

sets = set()

ac = 0
wa = 0

for i in li:
  if i[1] == 'AC':
    if i[0] not in sets:
      sets.add(i[0])
      ac += 1
      wa += d[i[0]]

  else:
    if i[0] not in sets:
      d[i[0]] += 1

print('{} {}'.format(ac, wa))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
li = []
for m in range(M):
  li.append(input().split())

ac = 0
wa = 0

for n in range(N + 1):
  if n == 0:
    continue

  for index, i in enumerate(li):
    if int(i[0]) == n and i[1] == 'AC':
      ac += 1
      for indexs, x in enumerate(li):
        if indexs >= index:
          break
        if int(x[0]) == n and x[1] == 'WA':
          wa += 1
      break

print('{0} {1}'.format(ac, wa))

Fixed submission:
from collections import defaultdict
d = defaultdict(int)

N,M = map(int,input().split())
li = []
for m in range(M):
  x,y = input().split()
  li.append([int(x), y])

sets = set()

ac = 0
wa = 0

for i in li:
  if i[1] == 'AC':
    if i[0] not in sets:
      sets.add(i[0])
      ac += 1
      wa += d[i[0]]

  else:
    if i[0] not in sets:
      d[i[0]] += 1

print('{} {}'.format(ac, wa))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N = int(input())
li = list(map(int, input().split()))
t = []

max = 0

for i in itertools.permutations(range(N)):
  t.append(i)

for i in t:
  count = 0
  for n in range(N-1):
    if n == 0:
      count = (li[i[n]] + li[i[n+1]]) / 2
    else:
      count = (count + li[i[n+1]]) / 2

  if max < count:
    max = count

print(max)

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

t = sorted(li)
ans = 0

for i in range(N-1):
  if i == 0:
    ans = (t[i] + t[i+1]) / 2
  else:
    ans = (ans + t[i+1]) / 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
li = []
for i in range(N):
  s = int(input())
  li.append(s)
  
  new = sorted(li, reverse=True)

s = max(li)
for index, i in enumerate(li):
  if s == li[index]:
    print(new[1])
  else:
    print(new[0])

Fixed submission:
N = int(input())
li = []
for i in range(N):
  s = int(input())
  li.append(s)
  
new = sorted(li, reverse=True)

s = max(li)
for index, i in enumerate(li):
  if s == li[index]:
    print(new[1])
  else:
    print(new[0])

Buggy python submission (verdict: Time Limit Exceeded):
import copy

N = int(input())
li = [int(input()) for i in range(N)]

for index, i in enumerate(li):
  tmp = copy.copy(li)

  ans = max(tmp)

  if ans == tmp[index]:
    tmp.pop(index)
    print(max(tmp))
  else:
    print(ans)

Fixed submission:
N = int(input())
li = []
for i in range(N):
  s = int(input())
  li.append(s)
  
new = sorted(li, reverse=True)

s = max(li)
for index, i in enumerate(li):
  if s == li[index]:
    print(new[1])
  else:
    print(new[0])
Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

if L - R >= 2020:
  print(0)
  sys.exit()

m = 10**9

for i in range(L, R+1):
  for n in range(i+1, R+1):
    s = i * n % 2019

    if m > s:
      m = s

print(m)

Fixed submission:
import sys

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

if R - L >= 2020:
  print(0)
  sys.exit()

m = 10**9

for i in range(L, R+1):
  for n in range(i+1, R+1):
    s = i * n % 2019

    if m > s:
      m = s

print(m)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

if L - R >= 3000:
  print(0)
  sys.exit()

m = 10**9

for i in range(L, R+1):
  for n in range(i+1, R+1):
    s = i * n % 2019

    if m > s:
      m = s

print(m)

Fixed submission:
import sys

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

if R - L >= 2020:
  print(0)
  sys.exit()

m = 10**9

for i in range(L, R+1):
  for n in range(i+1, R+1):
    s = i * n % 2019

    if m > s:
      m = s

print(m)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

if L - R >= 3000:
  print(0)
  sys.exit()

m = 10**9

for i in range(L, R+1):
  for n in range(i+1, R+1):
    s = i * n % 2019

    if m > s:
      m = s

print(m)

Fixed submission:
import sys

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

if R - L >= 2020:
  print(0)
  sys.exit()

m = 10**9

for i in range(L, R+1):
  for n in range(i+1, R+1):
    s = i * n % 2019

    if m > s:
      m = s

print(m)
Buggy python submission (verdict: Runtime Error):
ans = 0
way = 0

if x == 0 and y == 0:
  ans = 0
  way = 0
elif x == 0:
  if H == y:
    ans = 0
    way = 0
  elif H - y > y:
    ans = W * y
    way = 0
  elif H - y < y:
    ans = W * (H-y)
    way = 0
  elif H - y == y:
    ans = W * (H-y)
    way = 0
elif y == 0:
  if W == x:
    ans = 0
    way = 0
  elif W - x > x:
    ans = x * H
    way = 0
  elif W - x < x:
    ans = (W-x) * H
    way = 0
  elif W - x == x:
    ans = (W-x) * H
    way = 0
elif x != 0 and y != 0:
  mi = 0

  s = (W-x) * H
  t = x * H

  if s > t:
    mi = t
  else:
    mi = s

  si = 0
  s = W * (H-y)
  t = W * y

  if s > t:
    si = t
  else:
    si = s

  if mi > si:
    ans = mi
    way = 0
  elif mi < si:
    ans = si
    way = 0
  elif mi == si:
    ans = mi
    way = 1

print("{} {}".format(ans, way))

Fixed submission:
import sys
W,H,x,y = map(int, input().split())

ans = W * H / 2

if W / 2 == x and H / 2 == y:
  print("{} {}".format(ans, 1))
else:
  print("{} {}".format(ans, 0))
Buggy python submission (verdict: Time Limit Exceeded):
import re

N, Q = map(int, input().split())
S = input()
li = [list(map(int, input().split())) for n in range(Q)]

pattern = "AC"

for i in li:
  s = S[i[0]-1:i[1]]
  count = 0
  
  for index, k in enumerate(s):
    if index == len(s) - 1:
      break

    if k == 'A' and s[index+1] == 'C':
      count += 1

  print(count)

Fixed submission:
N, Q = map(int, input().split())
S = input()
li = [list(map(int, input().split())) for n in range(Q)]

t = [0] * len(S)

for index, s in enumerate(S):
  if index+1 > len(S)-1:
    break

  if s == 'A' and S[index+1] == 'C':
    t[index+1] = t[index] + 1
    
  else:
    t[index+1] = t[index]

for i in li:
  print(t[i[1]-1] - t[i[0] - 1])

Buggy python submission (verdict: Time Limit Exceeded):
import re

N, Q = map(int, input().split())
S = input()
li = [list(map(int, input().split())) for n in range(Q)]

pattern = "AC"

for i in li:
  s = S[i[0]-1:i[1]]
  count = 0
  
  for index, k in enumerate(s):
    if index == len(s) - 1:
      break

    if k == 'A' and s[index+1] == 'C':
      count += 1

  print(count)

Fixed submission:
N, Q = map(int, input().split())
S = input()
li = [list(map(int, input().split())) for n in range(Q)]

t = [0] * len(S)

for index, s in enumerate(S):
  if index+1 > len(S)-1:
    break

  if s == 'A' and S[index+1] == 'C':
    t[index+1] = t[index] + 1
    
  else:
    t[index+1] = t[index]

for i in li:
  print(t[i[1]-1] - t[i[0] - 1])

Buggy python submission (verdict: Time Limit Exceeded):
import re

N, Q = map(int, input().split())
S = input()
li = [list(map(int, input().split())) for n in range(Q)]

pattern = "AC"

for i in li:
  s = S[i[0]-1:i[1]]
  result = re.findall(pattern, s, re.S)
  print(len(result))

Fixed submission:
N, Q = map(int, input().split())
S = input()
li = [list(map(int, input().split())) for n in range(Q)]

t = [0] * len(S)

for index, s in enumerate(S):
  if index+1 > len(S)-1:
    break

  if s == 'A' and S[index+1] == 'C':
    t[index+1] = t[index] + 1
    
  else:
    t[index+1] = t[index]

for i in li:
  print(t[i[1]-1] - t[i[0] - 1])

Buggy python submission (verdict: Time Limit Exceeded):
import re

N, Q = map(int, input().split())
S = input()
li = [list(map(int, input().split())) for n in range(Q)]

pattern = "AC"

for i in li:
  s = S[i[0]-1:i[1]]
  result = re.findall(pattern, s, re.S)
  print(len(result))

Fixed submission:
N, Q = map(int, input().split())
S = input()
li = [list(map(int, input().split())) for n in range(Q)]

t = [0] * len(S)

for index, s in enumerate(S):
  if index+1 > len(S)-1:
    break

  if s == 'A' and S[index+1] == 'C':
    t[index+1] = t[index] + 1
    
  else:
    t[index+1] = t[index]

for i in li:
  print(t[i[1]-1] - t[i[0] - 1])
Buggy python submission (verdict: Time Limit Exceeded):
def chmin(a, b):
  if (a > b):
    return b

  return a

def chmax(a, b):
  if (a < b):
    a = b
    return True

  return False

N,K = map(int, input().split())
li = list(map(int, input().split()))

dp = [10**9] * N

for n in range(N):
  if n == 0:
    dp[n] = 0
    continue
  if n == 1:
    dp[n] = abs(li[n] - li[n-1])
    continue

  for k in range(1, K+1):
    if k > n:
      break

    dp[n] = chmin(dp[n], dp[n-k] + abs(li[n] - li[n-k]))

print(dp[-1])

Fixed submission:
def chmin(a, b):
  if (a > b):
    return b

  return a

def chmax(a, b):
  if (a < b):
    a = b
    return True

  return False

N,K = map(int, input().split())
li = list(map(int, input().split()))

dp = [10**9] * N

for n in range(N):
  if n == 0:
    dp[n] = 0
    continue
  if n == 1:
    dp[n] = abs(li[n] - li[n-1])
    continue

  for k in range(1, K+1):
    if k > n:
      break

    dp[n] = chmin(dp[n], dp[n-k] + abs(li[n] - li[n-k]))

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
def chmin(a, b):
  if (a > b):
    return b

  return a

def chmax(a, b):
  if (a < b):
    return b

  return a

N,W = map(int, input().split())
li = [list(map(int, input().split())) for i in range(N)]

dp = [[0] * 10**5 for i in [0] * (N+1)]

for n in range(N):
  for w in range(1, W+1):
    if (w - li[n][0] >= 0):
      dp[n+1][w] = chmax(dp[n+1][w], dp[n][w - li[n][0]] + li[n][1])

    dp[n+1][w] = chmax(dp[n+1][w], dp[n][w])


print(max(max(dp)))

Fixed submission:
def chmin(a, b):
  if (a > b):
    return b

  return a

def chmax(a, b):
  if (a < b):
    return b

  return a

N,W = map(int, input().split())
li = [list(map(int, input().split())) for i in range(N)]

dp = [[0] * (10**5+10) for i in [0] * (N+1)]

for n in range(N):
  for w in range(1, W+1):
    if (w - li[n][0] >= 0):
      dp[n+1][w] = chmax(dp[n+1][w], dp[n][w - li[n][0]] + li[n][1])

    dp[n+1][w] = chmax(dp[n+1][w], dp[n][w])


print(max(max(dp)))