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

Fixed submission:
import sys

s = sys.stdin.readline().strip()

ans = 0
l = 0
r = len(s) - 1

while l < r:
    # print("left", l, "right", r)
    if s[l] == "x" and s[r] == "x":
        l += 1
        r -= 1
    # rにxを足したとみなし、lを進める
    elif s[l] == "x":
        l += 1
        ans += 1
    # lにxを足したとみなし、rを進める
    elif s[r] == "x":
        r -= 1
        ans += 1
    elif s[l] != s[r]:
        print(-1)
        sys.exit()
    else:
        l += 1
        r -= 1

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

s = sys.stdin.readline().strip()

ans = 0
l = 0
r = len(s) - 1

while l != r:
    print("left", l, "right", r)
    if s[l] == "x" and s[r] == "x":
        l += 1
        r -= 1
    # rにxを足したとみなし、lを進める
    elif s[l] == "x":
        l += 1
        ans += 1
    # lにxを足したとみなし、rを進める
    elif s[r] == "x":
        r -= 1
        ans += 1
    elif s[l] != s[r]:
        print(-1)
        sys.exit()
    else:
        l += 1
        r -= 1

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque

s = sys.stdin.readline().strip()

# (元の文字列のindex, 文字）の配列
no_x = []
for i in range(len(s)):
    if s[i] == "x":
        continue
    no_x.append((i, s[i]))

len_no_x = len(no_x)
half = len_no_x // 2
for i in range(half):
    # x以外の文字が回文になっていないので不可能
    if no_x[i][1] != no_x[len_no_x - 1 - i][1]:
        print(-1)
        sys.exit()

# initから0まで走査し、元の文字列に左右対象になっていないxがある場合はxの挿入が必要
init = no_x[half][0]
# print("init", init)

ans = 0
l = 0
r = 0
# 元の文字列が偶数の場合、比較位置がずれる
if len_no_x % 2 == 0:
    l += 1

while init - l >= 0 or init + r < len(s):
    # print("left", init - l, "right", init + r)
    if init - l >= 0 and init + r < len(s):
        if s[init-l] == "x" and s[init+r] != "x":
            l += 1
            ans += 1
        elif s[init-l] != "x" and s[init+r] == "x":
            r += 1
            ans += 1
    elif init - l >= 0 and s[init-l] == "x":
        ans += 1
    elif init + r < len(s) and s[init+r] == "x":
        ans += 1
    l += 1
    r += 1

print(ans)
Problem p03612 (python)

Fixed submission:
import sys

N = int(sys.stdin.readline())
P = list(map(int, sys.stdin.readline().split()))

ans = 0
for i, p_i in enumerate(P):
    if p_i == i + 1:
        if i + 1 == N:
            P[i], P[i-1] = P[i-1], P[i]
        else:
            P[i+1], P[i] = P[i], P[i+1]
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

N = int(sys.stdin.readline())
P = list(map(int, sys.stdin.readline().split()))

ans = 0
for i, p_i in enumerate(P):
    if p_i == i + 1:
        P[i+1], P[i] = P[i], P[i+1]
        ans += 1

print(ans)
Problem p03633 (python)

Fixed submission:
import sys
import fractions
import functools

N = int(sys.stdin.readline().rstrip())
T = []
for _ in range(N):
    T.append(int(sys.stdin.readline().rstrip()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return functools.reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return functools.reduce(lcm_base, numbers, 1)

if N == 1:
    print(T[0])
else:
    print(lcm_list(T))

Buggy submission (verdict: Runtime Error):
import sys
import math
import functools

N = int(sys.stdin.readline().rstrip())
T = []
for _ in range(N):
    T.append(int(sys.stdin.readline().rstrip()))

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return functools.reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return functools.reduce(lcm_base, numbers, 1)

if N == 1:
    print(T[0])
else:
    print(lcm_list(T))

Buggy submission (verdict: Runtime Error):
import sys
import math
import functools

N = int(sys.stdin.readline().rstrip())
T = []
for _ in range(N):
    T.append(int(sys.stdin.readline().rstrip()))

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return functools.reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return functools.reduce(lcm_base, numbers, 1)

if N == 1:
    print(T[0])
else:
    print(lcm_list(T))

Buggy submission (verdict: Runtime Error):
import sys
import math
import functools

N = int(sys.stdin.readline().rstrip())
T = []
for _ in range(N):
    T.append(int(sys.stdin.readline().rstrip()))

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return functools.reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return functools.reduce(lcm_base, numbers, 1)

print(lcm_list(T))
Problem p03910 (python)

Fixed submission:
import sys

N = int(sys.stdin.readline().strip())

A = []
t = 0
i = 1
while t <= N:
    t += i
    A.append(i)
    i += 1
# print(A) 
for i in A:
    if t - N == i:
        # print("continue", i)
        continue
    else:
        print(i)

Buggy submission (verdict: Runtime Error):
import sys

N = int(sys.stdin.readline().strip())

i = 1
for i in range(1, N):
    sum_i = i * (i + 1) // 2
    if N <= sum_i:
        break

max_i = i
sum_i = i * (i + 1) // 2
res = sum_i - N 
# print("sum", sum_i)
# print("res", res)
# print(i)
ans = set([i for i in range(1, max_i+1)])
if res:
    ans.remove(res)

for i in ans:
    print(i)
Problem p02582 (python)

Fixed submission:
S = str(input())
ans = 0
if S[1]=="R":
    ans+=1
    if S[0]=="R" or S[2]=="R":
        ans+=1
        if S[0]=="R" and S[2]=="R":
            ans+=1
elif S[0]=="R" or S[2]=="R":
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
xkd = list(map(int,input().split()))
xkd[0] = abs(xkd[0])
for i in range(xkd[0] // xkd[2]):
    xkd[0] -= xkd[2]
    xkd[1] -= 1
    if xkd[1] < 1:
      break
ans = xkd[0]
if xkd[1] % 2 != 0:
    ans -= xkd[2]
    if ans > xkd[0] + xkd[2]:
        ans += xkd[2] * 2
print(abs(ans))
Problem p03238 (python)

Fixed submission:
ipnum = input()

if ipnum == "1":
    print("Hello World")
elif ipnum =="2":
    num1 = int(input())
    num2 = int(input())
    print(num1 + num2)
else:
    print("error")

Buggy submission (verdict: Runtime Error):

N= list(map(int,input().split())) #１行目の入力

root_list = []
cost = 1001
for i in range(N[0]):
    root_list.append(list(map(int,input().split())))

    if root_list[i][1] > N[1]:
        if root_list[i][0] < cost:
            cost = root_list[i][0]


if cost == 1001:
    print("TLE")
else:
    print(cost)
Problem p03280 (python)

Fixed submission:
l = input().split()
A = int(l[0])
B = int(l[1])
print((A * B)- A -B + 1)

Buggy submission (verdict: Runtime Error):
line = input(),split(' ')
A, B = [int(i) for i in line]

S = (A-1)*(B-1)

print(S)

Buggy submission (verdict: Runtime Error):
import sys

array = input().split(' ')
a = array[0]
b = array[1]

print((a-1) * (b-1))

Buggy submission (verdict: Runtime Error):
S = input()
K = input()
flag = 0
for i in range(len(S)):
    if S[i] =="1":
        continue
    elif S[i] =="2":
        print("2")
        flag = 1
    elif S[i] =="3":
        print("3")
        flag = 1
    elif S[i] =="4":
        print("4")
        flag = 1
    elif S[i] =="5":
        print("5")
        flag = 1
    elif S[i] =="6":
        print("6")
        flag = 1
    elif S[i] =="7":
        print("7")
        flag = 1
    elif S[i] =="8":
        print("8")
        flag = 1
    elif S[i] =="9":
        print("9")
        flag = 1

    break
if flag == 0:
    print("1")

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
A = int(a)
B = int(b)
print((A*B)-A-B + 1)
Problem p03470 (python)

Fixed submission:
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    N = sc.intarr()[0]
    D = sc.intarr_ver(N)

    print(len(set(D)))


class Scan():

    def intarr(self):
        num_array = list(map(int, input().split()))
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):  # 最大公約数
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):  # 最小公倍数
    return a * b // gcd(a, b)


main()

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int ctoi(char);

struct btn
{
    int next;
    int flag;
};

int main()
{
    int N;
    cin >> N;
    vector<int> vec;
    rep(i, N)
    {
        int d;
        cin >> d;
        vec.push_back(d);
    }
    stable_sort(vec.begin(), vec.end());
    int before = -1;
    int ans = 0;
    rep(i, N)
    {
        if (before != vec[i])
        {
            ans++;
        }
        before = vec[i];
    }
    cout << ans << endl;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}
Problem p02642 (python)

Fixed submission:
from collections import Counter
import sys

def input():
    return sys.stdin.readline().strip()

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            yield i
            if i != n // i:
                yield n//i
        i += 1

n,*A = get_all_int()
A.sort()



C = dict(Counter(A))
keys = C.keys()
# log(C)

checks = [False] * (1000009)

B = []
for i,a in enumerate(A):
    if C[a] == 1:
        B.append(a)
    elif not checks[a]:
        for j in range(a, 1000009, a):
            checks[j] = True

# log(B)

ans = 0

for i,a in enumerate(B):
    if not checks[a]:
        ans += 1
        for j in range(a, 1000009, a):
            checks[j] = True

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
import sys
import sympy

def input():
    return sys.stdin.readline().strip()

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            yield i
            if i != n // i:
                yield n//i
        i += 1

n,*A = get_all_int()
A.sort()



C = dict(Counter(A))
keys = C.keys()
# log(C)

B = []
for i,a in enumerate(A):
    if C[a] == 1:
        B.append(a)

ans = 0

for i,a in enumerate(B):
    div = sympy.divisors(a)
    ok = True
    for d in div:
        if d == a:
            continue
        elif d in keys:
            ok = False
            break
    if ok:
        ans += 1

print(ans)
Problem p02760 (python)

Fixed submission:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

table = [False]*9

aaa1 = get_nums_l()
aaa2 = get_nums_l()
aaa3 = get_nums_l()
aaa = aaa1 + aaa2 + aaa3
n = int(input())
bbb = get_nums_n(n)

for b in bbb:
    for i,a in enumerate(aaa):
        if a == b:
            table[i] = True

check = [
    (0,3,6),
    (1,4,7),
    (2,5,8),
    (0,1,2),
    (3,4,5),
    (6,7,8),
    (0,4,8),
    (2,4,6)
]

for ch in check:
    for c in ch:
        if not table[c]:
            break
    else:
        print("Yes")
        exit()
print("No")

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

table = [False]*9

aaa1 = get_nums_l()
aaa2 = get_nums_l()
aaa3 = get_nums_l()
aaa = [*aaa1, *aaa2, *aaa3]
n = int(input())
bbb = get_nums_n(n)

for b in bbb:
    for i,a in enumerate(aaa):
        if a == b:
            table[i] = True

check = [
    (0,3,6),
    (1,4,7),
    (2,5,8),
    (0,1,2),
    (3,4,5),
    (6,7,8),
    (0,4,8),
    (2,4,6)
]

for ch in check:
    for c in ch:
        if not table[c]:
            break
    else:
        print("Yes")
        exit()
print("No")
Problem p02936 (python)

Fixed submission:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,q = get_nums_l()

lines = sys.stdin.readlines()
edges = list(map(lambda s:list(map(int, s.split(" "))), lines[:n-1]))
queries = list(map(lambda s:list(map(int, s.split(" "))), lines[n-1:]))

scores = [0] * (n+1)

for q in queries:
    scores[q[0]] += q[1]

queue = deque()
mark = [False] * (n+1)
mark[1] = True


childrens = [ [] for _ in range(n+1) ]
for e in edges:
    a = e[0]
    b = e[1]
    childrens[a].append(b)
    childrens[b].append(a)


queue.append(1)

while queue:
    a = queue.popleft()
    children = childrens[a]
    for b in children:
        if not mark[b]:
            scores[b] += scores[a]
            mark[b] = True
            queue.append(b)

print(" ".join(map(str,scores[1:])))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,q = get_nums_l()

lines = sys.stdin.readlines()
edges = list(map(lambda s:list(map(int, s.split(" "))), lines[:n-1]))
queries = list(map(lambda s:list(map(int, s.split(" "))), lines[n-1:]))

scores = [0] * (n+1)

for q in queries:
    scores[q[0]] += q[1]

queue = deque()
mark = [False] * (n+1)
mark[1] = True

for e in edges:
    queue.append(e)

for e in queue:
    a = e[0]
    b = e[1]
    if mark[a]:
        scores[b] += scores[a]
        mark[b] = True
    elif mark[b]:
        scores[a] += scores[b]
        mark[a] = True
    else:
        queue.append(e)

print(" ".join(map(str,scores[1:])))
Problem p02945 (python)

Fixed submission:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

a,b = get_nums_l()
print(max(a+b, a-b, a*b))

Buggy submission (verdict: Runtime Error):

import sys

def log(*args, **kwargs):
    print(*args, **kwargs, file=sys.stderr)

log("hogehoge")

a,b = map(int, input().split())

print(max(a*b, a+b, a-b))

Buggy submission (verdict: Runtime Error):

import sys

def log(*args, **kwargs):
    print(*args, **kwargs, file=sys.stderr)

log("hogehoge")

a,b = map(int, input().split())

print(max(a*b, a+b, a-b))
Problem p03044 (python)

Fixed submission:
from collections import deque
import math
from functools import reduce

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())
ans = [-1] * n
ans[0] = 0

edges = [ [] for _ in range(n)]
for i in range(n-1):
    u,v,w = get_nums_l()
    edges[u-1].append([v-1,w%2==0])
    edges[v-1].append([u-1,w%2==0])

def aaa(x):
    # xを含むエッジ

    # breakpoint()

    for edge in edges[x]:
        to = edge[0] # edgeのうちxじゃないほう
        if ans[to] != -1:
            continue
        same = edge[1]
        ans[to] = ans[x] ^ (not same)

        queue.append(to)

queue = deque()
queue.append(0)
while queue:
    aaa(queue.popleft())
for annn in ans:
    print(annn)

Buggy submission (verdict: Runtime Error):
5
2 5 2
2 3 10
1 3 8
3 4 2

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())
ans = [-1] * n
ans[0] = 0

edges = [[]]*n
for i in range(n-1):
    u,v,w = get_nums_l()
    edges[u-1].append([v-1,w%2==0])
    edges[v-1].append([u-1,w%2==0])

def aaa(x):
    # xを含むエッジ

    for edge in edges[x]:
        to = edge[0] # edgeのうちxじゃないほう
        if ans[to] != -1:
            continue
        same = edge[1]
        ans[to] = ans[x] ^ (not same)

        aaa(x)
aaa(0)
for annn in ans:
    print(annn)
Problem p03061 (python)

Fixed submission:
from functools import reduce

def gcd(m, n):
    # 入力を m, n (m ≧ n) とする。
    tmp = max(m,n)
    n = min(m,n)
    m = tmp
    # n = 0 なら、 m を出力してアルゴリズムを終了する。
    if n == 0:
        return m
    # m を n で割った余りを新たに n とし、更に 元のnを新たにm とし 2. に戻る。
    return gcd(n, m % n)

def gcda(arr, left, right):
    return reduce((lambda a,b:gcd(a,b)), arr[left:right+1], gcd(arr[left], arr[right]))

n = int(input())
nums = [ int(s) for s in input().split(" ")]

if n == 2:
    print(max(nums))
    exit()

left_n = [0 for _ in range(n)]
right_n = [0 for _ in range(n)]

left_n[0] = nums[0]
right_n[n-1] = nums[n-1]

for i in range(n-1):
    left_n[i+1] = gcd(left_n[i], nums[i+1])
    right_n[n-2-i] = gcd(right_n[n-1-i], nums[n-2-i])

# print(left_n)
# print(right_n)

maxgcd = 0
for i in range(n):
    if i == 0:
        maxgcd = max(maxgcd, right_n[1])
    if i == n-1:
        maxgcd = max(maxgcd, left_n[n-2])
    else:
        maxgcd = max(maxgcd, gcd(right_n[i+1], left_n[i-1]))

print(maxgcd)

Buggy submission (verdict: Runtime Error):
from functools import reduce

def gcd(m, n):
    # 入力を m, n (m ≧ n) とする。
    tmp = max(m,n)
    n = min(m,n)
    m = tmp
    # n = 0 なら、 m を出力してアルゴリズムを終了する。
    if n == 0:
        return m
    # m を n で割った余りを新たに n とし、更に 元のnを新たにm とし 2. に戻る。
    return gcd(n, m % n)

def gcda(arr, left, right):
    return reduce((lambda a,b:gcd(a,b)), arr[left:right+1], gcd(arr[left], arr[right]))

n = int(input())
nums = [ int(s) for s in input().split(" ")]

if n == 2:
    print(max(nums))
    exit()

allgcd = gcda(nums, 0, n-1)

found = 0
delete_kouho = -1
for i in range(1,n):
    if gcd(nums[0], nums[i]) == allgcd:
        found += 1
        delete_kouho = i

if found >= 2:
    print(gcda(nums, 1, n-1))
    exit()
else:
    print(gcd(gcda(nums, 0, delete_kouho-1), gcda(nums, delete_kouho+1, n-1)))
Problem p03071 (python)

Fixed submission:
tmp=input().split(" ")
a = int(tmp[0])
b = int(tmp[1])

if a == b:
    print (a*2)
else:
    print (max(a,b)*2-1)

Buggy submission (verdict: Runtime Error):
tmp=input().sprit(" ")
a = int(tmp[0])
b = int(tmp[1])

if a == b:
    print (a*2)
else:
    print (max(a,b)*2-1)

Buggy submission (verdict: Runtime Error):
tmp=input().sprit(" ")
a = int(tmp[0])
b = int(tmp[1])

if a = b:
    print (a*2)
else:
    print (max(a,b)*2-1)
Problem p03087 (python)

Fixed submission:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999
MOD = 10**9+7

n,q = get_nums_l()
s = input()

ruiseki_ac = [0] * (n+1)

for i in range(n-1):
    x = 0
    if s[i] == "A" and s[i+1] == "C":
        x = 1
    ruiseki_ac[i+1] = ruiseki_ac[i] + x
ruiseki_ac[n] = ruiseki_ac[n-1]

log(ruiseki_ac)

for i in range(q):

    a,b = get_nums_l()
    print(ruiseki_ac[b-1] - ruiseki_ac[a-1])

Buggy submission (verdict: Runtime Error):


tmp = input().split(" ")
n = tmp[0]
q = int(tmp[1])

s = input()

ac_indexes=[]
start=0
while True:
    ind = s.find("AC", start)
    if ind != -1:
        start=ind+2
        ac_indexes.append(ind)
    else:
        break

for i in range(q):

    if len(ac_indexes) == 0:
        print ("0")
        continue

    tmp = input().split(" ")
    a = int(tmp[0]) - 1
    b = int(tmp[1]) - 2

    left = 0
    right = len(ac_indexes)
    left_kari=-1
    left_kakutei = -1
    while left <= right:
        center = (left+right)//2
        if ac_indexes[center] > a:
            right = center-1
            left_kari = center
        elif ac_indexes[center] < a:
            left = center+1
        else:
            left_kakutei = center
            break
    if left_kakutei == -1:
        left_kakutei = left_kari
    
    left = 0
    right = len(ac_indexes)-1
    right_kari = -1
    right_kakutei = -1
    while left <= right:
        center = (left+right)//2
        #print (left, center, right)
        if ac_indexes[center] > b:
            right = center-1
        elif ac_indexes[center] < b:
            left = center+1
            right_kari = center
        else:
            right_kakutei = center
            break
    if (right_kakutei == -1):
        right_kakutei = right_kari

    if (left_kakutei > right_kakutei or left_kakutei==-1 or right_kakutei==-1):
        print ("0")
        continue

    print(str(right_kakutei - left_kakutei + 1))