Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = list(input())
n = len(s)
t = s + s
k = int(input())
tmp1 = 0
for i in range(n * 2 - 2):
    if t[i] == t[i + 1]:
        tmp1 += 1
        t[i + 1] = 'X'
if t[-1] == t[-2]:
    tmp1 += 1
tmp2 = 0
for i in range(n - 2):
    if s[i] == s[i + 1]:
        tmp2 += 1
        s[i + 1] = 'X'
if s[-1] == s[-2]:
    tmp2 += 1
tmp3 = tmp1 - tmp2 * 2
print(tmp3 * (k - 1) + tmp2 * k)

Fixed submission:
s = list(input())
n = len(s)
k = int(input())
flg = 1
for i in range(n - 1):
    if s[i] != s[i + 1]:
        flg = 0
if flg:
    print(n * k // 2)
    exit(0)
t = s + s
tmp1 = 0
for i in range(n * 2 - 1):
    if t[i] == t[i + 1]:
        tmp1 += 1
        t[i + 1] = 'X'
tmp2 = 0
for i in range(n - 1):
    if s[i] == s[i + 1]:
        tmp2 += 1
        s[i + 1] = 'X'
tmp3 = tmp1 - tmp2 * 2
print(tmp3 * (k - 1) + tmp2 * k)
Buggy python submission (verdict: Runtime Error):
from collections import deque
n = int(input())
s = [input() for i in range(n)]
q = deque([0])
d = [float('inf')] * n
d[0] = 0
while q:
    p = q.popleft()
    for i, c in enumerate(s[p]):
        if c == '1' and d[i] == float('inf'):
            d[i] = d[p] + 1
            q.append(i)
m = 0
for i in range(n):
    if d[m] < d[i]:
        m = i
q = deque([m])
d = [float('inf')] * n
d[m] = 0
while q:
    p = q.popleft()
    for i, c in enumerate(s[p]):
        if c == '1':
            if d[i] == float('inf'):
                d[i] = d[p] + 1
                q.append(i)
            elif d[i] != d[p] + 1 and d[i] != d[p] - 1:
                print(-1)
                exit(1)
m = 0
for i in range(n):
    m = max(m, d[i])
print(m + 1)


Fixed submission:
from collections import deque
n = int(input())
s = [input() for i in range(n)]
ans = -2
for k in range(n):
    q = deque([k])
    d = [float('inf')] * n
    d[k] = 0
    while q:
        flg = 0
        p = q.popleft()
        for i, c in enumerate(s[p]):
            if c == '1':
                if d[i] == float('inf'):
                    d[i] = d[p] + 1
                    q.append(i)
                elif d[i] != d[p] + 1 and d[i] != d[p] - 1:
                    flg = 1
                    break
        if flg:
            break
    if flg:
        continue
    for i in range(n):
        ans = max(ans, d[i])
print(ans + 1)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_right
s = input()
n = len(s)
t = input()
m = len(t)
tr = set(s)
for c in t:
  if c not in s:
    print(-1)
    exit(0)
d = {c:[] for c in 'abcdefghijklmnopqrstuvwxyz'}
for i, c in enumerate(s):
  d[c].append(i)
idx = -1
ans = 0
for c in t:
  tmp = bisect_right(d[c], idx)
  if tmp == len(d[c]):
    idx = d[c][0]
    ans += 1
  else:
    idx = d[c][tmp]
print(ans * n + idx + 1)

Fixed submission:
from bisect import bisect_right
s = input()
n = len(s)
t = input()
m = len(t)
tr = set(s)
for c in t:
  if c not in s:
    print(-1)
    exit(0)
d = {c:[] for c in 'abcdefghijklmnopqrstuvwxyz'}
for i, c in enumerate(s):
  d[c].append(i)
idx = -1
ans = 0
for c in t:
  tmp = bisect_right(d[c], idx)
  if tmp == len(d[c]):
    idx = d[c][0]
    ans += 1
  else:
    idx = d[c][tmp]
print(ans * n + idx + 1)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
m = min(s)
for p in range(k):
    u = s + s[::-1]
    l = []
    cnt = 0
    idx = 0
    for i in range(n * 2):
        if u[i] == m:
            if cnt == 0:
                idx = i
            cnt += 1
        else:
            if cnt > 0:
                l.append((cnt, idx))
                cnt = 0
    if cnt > 0:
        l.append((cnt, idx))
    a, j = max(l)
    if a >= n:
        print(m * m)
        exit(0)
    for c, i in l:
        if i <= n and c == a:
            s = min(s, u[i:i + n])
    if (k - p) % 2 == 0:
        s = s[::-1]
print(s)


Fixed submission:
n, k = map(int, input().split())
s = input()
m = min(s)
for p in range(k):
    u = s + s[::-1]
    l = []
    cnt = 0
    idx = 0
    for i in range(n * 2):
        if u[i] == m:
            if cnt == 0:
                idx = i
            cnt += 1
        else:
            if cnt > 0:
                l.append((cnt, idx))
                cnt = 0
    if cnt > 0:
        l.append((cnt, idx))
    a, j = max(l)
    if a >= n:
        print(m * n)
        exit(0)
    for c, i in l:
        if i <= n and c == a:
            s = min(s, u[i:i + n])
    s = s[::-1]
print(s[::-1])

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
m = min(s)
if k >= 20:
    print(m * n)
else:
    for p in range(k):
        u = s + s[::-1]
        l = []
        cnt = 0
        idx = 0
        for i in range(n * 2):
            if u[i] == m:
                if cnt == 0:
                    idx = i
                cnt += 1
            else:
                if cnt > 0:
                    l.append((cnt, idx))
                    cnt = 0
        a, j = max(l)
        for c, i in l:
            if i <= n and c == a:
                s = min(s, u[i:i + n])
        if (k - p) % 2 == 0:
            s = s[::-1]
    print(s)


Fixed submission:
n, k = map(int, input().split())
s = input()
m = min(s)
for p in range(k):
    u = s + s[::-1]
    l = []
    cnt = 0
    idx = 0
    for i in range(n * 2):
        if u[i] == m:
            if cnt == 0:
                idx = i
            cnt += 1
        else:
            if cnt > 0:
                l.append((cnt, idx))
                cnt = 0
    if cnt > 0:
        l.append((cnt, idx))
    a, j = max(l)
    if a >= n:
        print(m * n)
        exit(0)
    for c, i in l:
        if i <= n and c == a:
            s = min(s, u[i:i + n])
    s = s[::-1]
print(s[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
def construct_table(n, s):
    table = [-1] * (n + 1)
    j = -1
    for i in range(n):
        while j >= 0 and s[i] != s[j]:
            j = table[j]
        j += 1
        table[i + 1] = j
    return table


s = input()
t = input()
n = len(s)
m = len(t)
s2 = s * ((max(m, n) + m) // n + 1)
tb = construct_table(m, t)
l = [False] * n
i = 0
j = 0
while i < n:
    if t[j] != s2[i + j]:
        i += j - tb[j]
        if j > 0:
            j = tb[j]
    else:
        j += 1
        if j == m:
            l[i] = True
            i += j - tb[j]
            j = tb[j]
v = [0] * n
for i in range(n):
    tmp = i
    r = 0
    while l[i]:
        t = i
        i = (i - m) % n
        v[i] = v[t] + 1
        if i == tmp:
            print(-1)
            exit(0)
print(max(v))


Fixed submission:
def construct_table(n, s):
    table = [-1] * (n + 1)
    j = -1
    for i in range(n):
        while j >= 0 and s[i] != s[j]:
            j = table[j]
        j += 1
        table[i + 1] = j
    return table


s = input()
t = input()
n = len(s)
m = len(t)
s2 = s * ((max(m, n) + m) // n + 1)
tb = construct_table(m, t)
l = [False] * n
i = 0
j = 0
while i < n:
    if t[j] != s2[i + j]:
        i += j - tb[j]
        if j > 0:
            j = tb[j]
    else:
        j += 1
        if j == m:
            l[i] = True
            i += j - tb[j]
            j = tb[j]
inv = [0] * n
for i in range(n):
    if l[i]:
        t = (i + m) % n
        i = t
        inv[t] += 1
ans = 0
v = [0] * n
for i in range(n):
    if inv[i] == 0:
        v[i] = 1
        r = 0
        while l[i]:
            r += 1
            t = (i + m) % n
            v[t] = 1
            i = t
        ans = max(ans, r)
if 0 in v:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
ans = []
c = (n - 1) * (n - 2) // 2 - k
if c < k:
    print(-1)
    exit(1)
for i in range(1, n):
    ans.append((0, i))
cnt = 0
flg = 0
for i in range(1, n):
    if flg:
        break
    for j in range(1, n):
        if i == j:
            continue
        ans.append((i, j))
        cnt += 1
        if cnt >= c:
            flg = 1
            break
print(len(ans))
for a, b in ans:
    print(a, b)


Fixed submission:
n, k = map(int, input().split())
ans = []
c = (n - 1) * (n - 2) // 2 - k
if c < 0:
    print(-1)
    exit(0)
for i in range(1, n):
    ans.append((0, i))
cnt = 0
flg = 0
for i in range(1, n):
    if flg:
        break
    for j in range(i + 1, n):
        if cnt >= c:
            flg = 1
            break
        ans.append((i, j))
        cnt += 1
print(len(ans))
for a, b in ans:
    print(a + 1, b + 1)
Buggy python submission (verdict: Runtime Error):
n, a, b, MOD = map(int, input().split())


def mult(A, B, N):
    C = [[0] * n for _ in range(n)]
    for i in range(N):
        for j in range(N):
            for k in range(N):
                C[i][j] += A[i][k] * B[k][j]
            C[i][j] %= MOD
    return C


def mat_power(A, N, n):
    if n == 0:
        res = [[0] * N for _ in range(N)]
        for i in range(N):
            res[i][i] = 1
        return res
    X = mat_power(A, N, n // 2)
    X = mult(X, X, N)
    return mult(A, X, N) if n & 1 else X


li = [0]
t = 1
while li[-1] < n:
    p = pow(10, t)
    l, r = li[-1] - 1, n
    while r - l > 1:
        m = (l + r) // 2
        if a + b * m < p:
            l = m
        else:
            r = m
    li.append(r)
    t += 1
ans = 0
for i in range(len(li) - 1):
    p = pow(10, i + 1)
    t = li[i + 1] - li[i]
    am = [[p, 1, 0], [0, 1, 1], [0, 0, 1]]
    mat = mat_power(am, 3, t)
    ans *= pow(10, t * (i + 1), MOD)
    ans += mat[0][1] * ((a + b * li[i])) + mat[0][2] * b
    ans %= MOD
print(ans)


Fixed submission:
n, a, b, MOD = map(int, input().split())


def mult(A, B, N):
    C = [[0] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            for k in range(N):
                C[i][j] += A[i][k] * B[k][j]
            C[i][j] %= MOD
    return C


def mat_power(A, N, n):
    if n == 0:
        res = [[0] * N for _ in range(N)]
        for i in range(N):
            res[i][i] = 1
        return res
    X = mat_power(A, N, n // 2)
    X = mult(X, X, N)
    return mult(A, X, N) if n & 1 else X


li = [0]
t = 1
while li[-1] < n:
    p = pow(10, t)
    l, r = li[-1] - 1, n
    while r - l > 1:
        m = (l + r) // 2
        if a + b * m < p:
            l = m
        else:
            r = m
    li.append(r)
    t += 1
ans = 0
for i in range(len(li) - 1):
    p = pow(10, i + 1)
    t = li[i + 1] - li[i]
    am = [[p, 1, 0], [0, 1, 1], [0, 0, 1]]
    mat = mat_power(am, 3, t)
    ans *= pow(10, t * (i + 1), MOD)
    ans += mat[0][1] * ((a + b * li[i])) + mat[0][2] * b
    ans %= MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

s = input()
if len(s) < 3:
    print(0)
    exit(0)
l = []
for i in range(2):
    l.append(s[len(s) // 3 * i:len(s) // 3 * (i + 1)])
l.append(s[len(s) // 3 * 2:])
ans = 0
for i, s in enumerate(l):
    for i in reversed(range(int(math.log2(len(s)))+1)):
        w = 2**i
        while "A" + "BC" * w in l[i] or "A" * w + "BC" in l[i]:
            m = l[i].count("A" + "BC" * w)
            l[i] = l[i].replace("A" + "BC" * w, "BC" * w + "A")
            m += l[i].count("A" * w + "BC")
            l[i] = l[i].replace("A" * w + "BC", "BC" + "A" * w)
            ans += w * m
s = ''.join(l)
for i in reversed(range(int(math.log2(len(s)))+1)):
    w = 2**i
    while "A" + "BC" * w in s or "A" * w + "BC" in s:
        m = s.count("A" + "BC" * w)
        s = s.replace("A" + "BC" * w, "BC" * w + "A")
        m += s.count("A" * w + "BC")
        s = s.replace("A" * w + "BC", "BC" + "A" * w)
        ans += w * m
print(ans)


Fixed submission:
s = input()
n = len(s)
st = ''
i = 0
while i < n:
    if i < n - 1 and s[i] == 'B' and s[i + 1] == 'C':
        st += 'D'
        i += 1
    else:
        st += s[i]
    i += 1
ans = 0
ac = 0
for c in st:
    if c in ('B', 'C'):
        ac = 0
    elif c == 'A':
        ac += 1
    elif c == 'D':
        ans += ac
print(ans)

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

s = input()
ans = 0
for i in reversed(range(int(math.log2(len(s)))+1)):
    w = 2**i
    while "A" + "BC" * w in s or "A" * w + "BC" in s:
        m = s.count("A" + "BC" * w)
        s = s.replace("A" + "BC" * w, "BC" * w + "A")
        m += s.count("A" * w + "BC")
        s = s.replace("A" * w + "BC", "BC" + "A" * w)
        ans += w * m

print(ans)

Fixed submission:
s = input()
n = len(s)
st = ''
i = 0
while i < n:
    if i < n - 1 and s[i] == 'B' and s[i + 1] == 'C':
        st += 'D'
        i += 1
    else:
        st += s[i]
    i += 1
ans = 0
ac = 0
for c in st:
    if c in ('B', 'C'):
        ac = 0
    elif c == 'A':
        ac += 1
    elif c == 'D':
        ans += ac
print(ans)
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
a.sort(key=lambda x: x[2])
for i in range(N):
    a[i] = [a[i][0] - a[i][2], a[i][1] - a[i][2], a[i][2]]
d = [int(input()) for _ in range(Q)]
idx = 0
for p in d:
    flg = 1
    while not (a[idx][0] <= p < a[idx][1]):
        if idx + 1 >= N or a[idx][1] <= p < a[idx + 1][0]:
            flg = 0
            break
        idx += 1
    print(a[idx][2] if flg else -1)

Fixed submission:
A, P = map(int, input().split())
P += A * 3
print(P // 2)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ar = [list(map(int, input().split())) for _ in range(M)]
ar.sort(key=lambda x: x[1], reverse=True)
p = 0
for b, c in ar:
    if c <= a[p]:
        break
    for i in range(b):
        if p >= N:
            break
        a[p] = max(a[p], c)
        p += 1
print(sum(a))

Fixed submission:
N, M = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ar = [list(map(int, input().split())) for _ in range(M)]
ar.sort(key=lambda x: x[1], reverse=True)
p = 0
for b, c in ar:
    if p >= N or c <= a[p]:
        break
    for i in range(b):
        if p >= N:
            break
        a[p] = max(a[p], c)
        p += 1
print(sum(a))
Buggy python submission (verdict: Runtime Error):
N=int(input());p=[[]for _ in range(N)]
for _ in range(N-1):u,v,w=map(int,input().split());p[u].append((v,w));p[v].append((u,w))
s=[(1,0)];l=[-1]*N
while s:
 a,w=s.pop()
 l[a-1]=w%2
 for b,c in p[a]:
  if l[b-1]==-1:s.append((b,w+c))
for i in l:print(i)

Fixed submission:
def dfs(graph, start):
    stack = [(start, 0)]
    visited = set()
    li = [0] * N
    while stack:
        d = stack.pop()
        li[d[0] - 1] = d[1] % 2
        for node, w in graph[d[0]]:
            if node not in visited:
                visited.add(node)
                stack.append((node, d[1] + w))
    return li


N = int(input())
g = {i: []for i in range(1, N + 1)}
for i in range(N - 1):
    u, v, w = map(int, input().split())
    w %= 2
    g[u].append((v, w))
    g[v].append((u, w))
for c in dfs(g, 1):
    print(c)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
v = set()


def dfs(graph, start, visited):
    stack = [start]
    visited.add(start)
    while stack:
        label = stack.pop(0)
        for node in g[label]:
            if node not in visited:
                visited.add(node)
                stack.append(node)
    return visited


g = {i: [] for i in range(1, N + 1)}
for i in range(M):
    x, y, z = map(int, input().split())
    g[x].append(y)
    g[y].append(x)
ans = 0
for i in range(1, N + 1):
    if i not in v:
        ans += 1
        dfs(g, i, v)
print(ans)

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


def dfs(graph, start, visited):
    stack = [start]
    visited.add(start)
    while stack:
        label = stack.pop(0)
        for node in g[label]:
            if node not in visited:
                visited.add(node)
                stack.append(node)
    return visited


g = {i: [] for i in range(1, N + 1)}
for i in range(M):
    x, y, z = map(int, input().split())
    g[x].append(y)
    g[y].append(x)
ans = 0
for i in range(1, N + 1):
    if i not in v:
        ans += 1
        dfs(g, i, v)
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
s = [input() for _ in range(N)]
ans = 0
ac = 0
bc = 0
abc = 0
for st in s:
    ans += st.count('AB')
    if st[-1] == 'A' and st[0] == 'B':
        abc += 1
    else:
        if st[-1] == 'A':
            ac += 1
        elif st[0] == 'B':
            bc += 1
absoluteNum = abs(ac - bc)
basicCon = min(ac, bc)
ans += basicCon + min(abc, absoluteNum)

if (absoluteNum < abc):
    ans += abc - 1
print(ans)

Fixed submission:
# km + k = N
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


N = int(input())
i = 1
ans = 0
for i in make_divisors(N)[:-1]:
    m = ((N - i) // i)
    if N // m != N % m:
        break
    ans += m
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
A = list(map(int, input().split()))
L = [0] * N
R = [0] * N
for i in range(N - 1):
    L[i + 1] = math.gcd(L[i], A[i])
for i in range(N - 1, 0, -1):
    R[i - 1] = math.gcd(R[i], A[i])
ans = 0
for i in range(N):
    ans = max(math.gcd(L[i], R[i]), ans)
print(ans)

Fixed submission:
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
L = [0] * N
R = [0] * N
for i in range(N - 1):
    L[i + 1] = gcd(L[i], A[i])
for i in range(N - 1, 0, -1):
    R[i - 1] = gcd(R[i], A[i])
ans = 0
for i in range(N):
    ans = max(gcd(L[i], R[i]), ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(input())
k = int(input())
d = s[k - 1]
for i in range(n):
    if s[i] != d:
        s[i] = '*'
print(''.join(s))


Fixed submission:
a, b, c = map(int, input().split())
if a < c < b or b < c < a:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
d = n - s[::-1].find('.') - 1
c = s[:d].count('#')
d2 = s.find('#')
c2 = s[d2:].count('.')
ans = 10**9
for i in range(n + 1):
    ans = min(ans, s[:i].count('#') + s[i:].count('.'))
print(ans)

Fixed submission:
n = int(input())
s = [1 if c == '#' else 0 for c in input()]
l = [0] * (n + 1)
l2 = [0] * (n + 1)
for i in range(n):
    l[i + 1] = s[i] + l[i]
s = s[::-1]
for i in range(n):
    l2[i + 1] = 1-s[i] + l2[i]
l2 = l2[::-1]
ans = float('inf')
for i in range(n + 1):
    ans = min(ans, l[i] + l2[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = input()
t = [None] * q
d = [None] * q
for i in range(q):
    t[i], d[i] = input().split()
l, r = 0, n + 1
while r - l > 1:
    m = (l + r) // 2
    c = m - 1
    for i in range(q):
        if s[c] == t[i]:
            if d[i] == 'L':
                c -= 1
            else:
                c += 1
        if c < 0:
            l = m
            break
    else:
        r = m
a = l
l, r = 0, n + 1
while r - l > 1:
    m = (l + r) // 2
    c = m - 1
    for i in range(q):
        if s[c] == t[i]:
            if d[i] == 'L':
                c -= 1
            else:
                c += 1
        if c >= n:
            r = m
            break
    else:
        l = m
b = n - l
print(max(0, n - a - b))


Fixed submission:
A, B, C = map(int, input().split())
if A == B == C:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10 ** 9 + 7
fac = [1] * (10 ** 5 * 3)


def nCr(n, r):
    return fac[n] * pow(fac[n - r], MOD - 2, MOD) * pow(fac[r], MOD - 2, MOD) % MOD


for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD
b, w = map(int, input().split())
n = b + w
p = [0] * n
q = [0] * n
for i in range(b, n):
    p[i] = (p[i - 1] + nCr(i - 1, b - 1) *
            pow(pow(2, i, MOD), MOD - 2, MOD)) % MOD
for i in range(w, n):
    q[i] = (q[i - 1] + nCr(i - 1, w - 1) *
            pow(pow(2, i, MOD), MOD - 2, MOD)) % MOD
for i in range(n):
    print((q[i] + (1 - p[i] - q[i]) * pow(2, MOD - 2, MOD)) % MOD)


Fixed submission:
MOD = 10 ** 9 + 7
fac = [1] * (10 ** 5 * 3)


def nCr(n, r):
    return fac[n] * pow(fac[n - r], MOD - 2, MOD) * pow(fac[r], MOD - 2, MOD) % MOD


for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD
b, w = map(int, input().split())
n = b + w
p = [0] * n
q = [0] * n
for i in range(b, n):
    p[i] = (p[i - 1] + nCr(i - 1, b - 1) *
            pow(pow(2, i, MOD), MOD - 2, MOD)) % MOD
for i in range(w, n):
    q[i] = (q[i - 1] + nCr(i - 1, w - 1) *
            pow(pow(2, i, MOD), MOD - 2, MOD)) % MOD
t = pow(2, MOD - 2, MOD)
for i in range(n):
    print((q[i] + (1 - p[i] - q[i]) * t) % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, q = map(int, input().split())
s = input()
L = np.array([0]*n)
for i in range(n-1):
    if(s[i:i+2] == 'AC'):
        L[i] = 1
for i in range(q):
    l, r = map(int, input().split())
    print(np.sum(L[l-1:r-1]))

Fixed submission:
from itertools import accumulate
n, q = map(int, input().split())
s = input()
L = [0]*n
for i in range(1, n):
    if(s[i-1:i+1] == 'AC'):
        L[i] = 1
c = list(accumulate(L))
for i in range(q):
    l, r = map(int, input().split())
    print(c[r-1]-c[l-1])

Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <string>

using namespace std;

int main() {
    int n, q, l, r, count;
    string s;
    cin >> n >> q;
    cin >> s;
    int L[10100];
    for(int i = 0; i < n - 1; i++) {
        if(s[i] == 'A' && s[i + 1] == 'C') {
            L[i] = 1;
        } else {
            L[i] = 0;
        }
    }
    for(int i = 0; i < q; i++) {
        count = 0;
        cin >> l >> r;
        for(int j = l - 1; j < r - 1; j++) {
            if(L[j] == 1) {
                count++;
            }
        }
        cout << count << endl;
    }
}


Fixed submission:
from itertools import accumulate
n, q = map(int, input().split())
s = input()
L = [0]*n
for i in range(1, n):
    if(s[i-1:i+1] == 'AC'):
        L[i] = 1
c = list(accumulate(L))
for i in range(q):
    l, r = map(int, input().split())
    print(c[r-1]-c[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
L=[0]*n
for i in range(n-1):
  if(s[i:i+2]=='AC'):
    L[i] = 1
for i in range(q):
  l,r=map(int,input().split())
  print(sum(L[l-1:r-1]))

Fixed submission:
from itertools import accumulate
n, q = map(int, input().split())
s = input()
L = [0]*n
for i in range(1, n):
    if(s[i-1:i+1] == 'AC'):
        L[i] = 1
c = list(accumulate(L))
for i in range(q):
    l, r = map(int, input().split())
    print(c[r-1]-c[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:
from itertools import accumulate
n, q = map(int, input().split())
s = input()
L = [0]*n
for i in range(1, n):
    if(s[i-1:i+1] == 'AC'):
        L[i] = 1
c = list(accumulate(L))
for i in range(q):
    l, r = map(int, input().split())
    print(c[r-1]-c[l-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n % 2:
    print(((n - 1) * (n - 2) + (n - 1)) // 2)
else:
    print(n * (n - 2) // 2)
for i in range(n):
    for j in range(i + 1, n):
        if i + j != n - 2:
            print(i + 1, j + 1)
if n % 2:
    exit(1)


Fixed submission:
n = int(input())
b = list(map(int, input().split()))
ans = []
while(b != []):
    for i in range(len(b), 0, -1):
        if i not in b:
            continue
        if b[i - 1] == i:
            ans.append(i)
            del b[i - 1]
            break
    else:
        print(-1)
        exit()
for i in ans[::-1]:
    print(i)