Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = list(map(int, input().split()))
S = input()
t = [1 if S[j:j+2] == "AC" else 0 for j in range(N)]
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(int(sum(t[l-1:r-1])))

Fixed submission:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
t = [0] * N
for j in range(1, N):
  t[j] = t[j-1] + 1 if S[j-1:j+1] == "AC" else t[j-1]
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
t = [1 if S[j:j+2] == "AC" else 0 for j in range(N)]
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(int(np.sum(t[l-1:r-1])))

Fixed submission:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
t = [0] * N
for j in range(1, N):
  t[j] = t[j-1] + 1 if S[j-1:j+1] == "AC" else t[j-1]
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(int(np.sum([1 for j in range(l-1, r-1) if S[j:j+2] == "AC"])))

Fixed submission:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
t = [0] * N
for j in range(1, N):
  t[j] = t[j-1] + 1 if S[j-1:j+1] == "AC" else t[j-1]
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(t[r-1]-t[l-1])

Buggy python submission (verdict: Runtime Error):
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(np.sum([1 for i in range(len(S)) if S[i:i+1] == "AC"])

Fixed submission:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
t = [0] * N
for j in range(1, N):
  t[j] = t[j-1] + 1 if S[j-1:j+1] == "AC" else t[j-1]
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(t[r-1]-t[l-1])

Buggy python submission (verdict: Runtime Error):
N, Q = list(map(int, input().split()))
S = input()
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(np.sum([1 for i in range(len(S)) if S[i:i+1] == "AC"])

Fixed submission:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
t = [0] * N
for j in range(1, N):
  t[j] = t[j-1] + 1 if S[j-1:j+1] == "AC" else t[j-1]
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(t[r-1]-t[l-1])
Buggy python submission (verdict: Runtime Error):
H, W = list(map(int, input()))
h, w = list(map(int, input()))

print(int((H-h)*(W-w)))

Fixed submission:
H, W = list(map(int, input().split()))
h, w = list(map(int, input().split()))
 
print(int((H-h)*(W-w)))
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M, C = list(map(int, input().split()))
B = np.asarray(input().split(), dtype=np.int)
A = []
for i in range(N):
  A.append(list(map(int, input().split())))
A = np.asarray(A, dtype=np.int)

np.sum(A @ B.T > (-1*C))

Fixed submission:
import numpy as np
N, M, C = list(map(int, input().split()))
B = np.asarray(input().split(), dtype=np.int)
A = []
for i in range(N):
  A.append(list(map(int, input().split())))
A = np.asarray(A, dtype=np.int)
 
print(np.sum(np.dot(A, B.T) > (-1*C)))
Buggy python submission (verdict: Runtime Error):
s = list(map(int, input()))
if list(sorted(s)) == [1, 4, 7, 9]:
  print("YES")
else:
  print("NO")  

Fixed submission:
s = list(map(int, input().split()))
if sorted(s) == [1, 4, 7, 9]:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
s = list(map(int, input()))
if sorted(s) == [1, 4, 7, 9]:
  print("YES")
else:
  print("NO")  

Fixed submission:
s = list(map(int, input().split()))
if sorted(s) == [1, 4, 7, 9]:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
s = list(map(int, input()))
if s == [1, 4, 7, 9]:
  print("YES")
else:
  print("NO")   

Fixed submission:
s = list(map(int, input().split()))
if sorted(s) == [1, 4, 7, 9]:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
s = list(map(int, input()))
t = [1, 4, 7, 9]
[t.pop() for i in sorted(s) if i in t]
if len(t) == 4:
  print("YES")
else:
  print("NO")

Fixed submission:
s = list(map(int, input().split()))
if sorted(s) == [1, 4, 7, 9]:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
K = [int(input()) for i in range(N)]
K = sorted(K)
print(min([K[i+M-1]-K[i] for i in range(N-M+1)])

Fixed submission:
N, M = list(map(int, input().split()))
K = [int(input()) for i in range(N)]
K = sorted(K)

result = 10 ** 10
for i in range(N-M+1):
  result = min([result, K[i+M-1]-K[i]])
  
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
temp = [list(map(int, input().split())) for i in range(M)]
temp = list(zip(*temp))
P, Y = temp
#print(P, Y)
data = dict()
for p, y in zip(P, Y):
  if p not in data:
    data[p] = [y]
  else:
    data[p].append(y)
    
for i in data.keys():
  data[i] = sorted(data[i])
  
for p, y in zip(P, Y):
  print("{:06}{:06}".format(p, data[p].index(y)+1))

Fixed submission:
N, M = list(map(int, input().split()))
temp = [list(map(int, input().split())) for i in range(M)]
temp = list(zip(*temp))
P, Y = temp
#print(P, Y)
data = dict()
for p, y in zip(P, Y):
  if p not in data:
    data[p] = [y]
  else:
    data[p].append(y)

data = {i:{value:j+1 for j, value in enumerate(sorted(data[i]))} for i in data.keys()}

for p, y in zip(P, Y):
  print("{:06}{:06}".format(p, data[p][y]))
Buggy python submission (verdict: Runtime Error):
K = int(input())

def calc_n(K):
  for n in range(1, int(K/2)+2):
    if n*(n+1)/2 == K:
      return n
  return "NO"

N = calc_n(K)
if not isinstance(N, int):
  print(N)
print(N+1)
all_num = {i:2 for i in range(1, K+1)}
remain = K * 2
#print(all_num)
pair = []
for i in range(1, K+1):
  if all_num[i] == 2:
    pair.append(i)
    all_num[i] -= 1
    remain -= 1
    if len(pair) == N:
      break
print(N, " ".join([str(i) for i in pair]))

while remain != N:
  pair = []
  for i in range(1, K+1):
    if all_num[i] == 1 and len(pair) == 0:
      pair.append(i)
      all_num[i] -= 1
      remain -= 1
    if all_num[i] == 2 and len(pair) != 0:
      pair.append(i)
      all_num[i] -= 1
      remain -= 1
      if len(pair) == N:
        break
  print(N, " ".join([str(i) for i in pair]))

pair = []
for i in range(1, K+1):
  if all_num[i] == 1:
    pair.append(i)
    all_num[i] -= 1
    remain -= 1
    if len(pair) == N:
      break
print(N, " ".join([str(i) for i in pair]))

Fixed submission:
K = int(input())

def calc_n(K):
  for n in range(1, int(K/2)+2):
    if n*(n+1)/2 == K:
      return n
  return "No"

N = calc_n(K)
if not isinstance(N, int):
  print(N)
else:
  print("Yes")
  print(N+1)
  last = [i for i in range(1, N+1)]
  count = 2
  first_set = [str(i) if i == 1 else str(sum(last[:i-1])+1) for i in range(1, N+1)]
  print(N, " ".join(first_set))
  last_set = [str(sum(last[:i])) for i in range(1,N+1)]
  print(N, " ".join(last_set))
  while count != N+1:
    first_number = sum(last[:count-1])+1
    other_set = [i for i in range(first_number, first_number+count)]
    other_set.extend([first_number+count*(i+1)-1+sum(last[:i-1]) for i in range(1, N-count+1)])
    count += 1
    other_set = [str(i) for i in other_set]
    print(N, " ".join(other_set))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
for i in range(int(M/N), 0, -1):
  if M % i == 0 and M >= i * N:
    print(i)
    exit()

Fixed submission:
N, M = list(map(int, input().split()))
# 範囲を絞る時は，反対の値も見るべき(M/iのこと)
print(max([j for i in range(int(M**0.5), 0, -1) for j in [i, int(M/i)] if M % j == 0 and M / N >= j]))

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

for i in range(M, 0, -1):
  if M % i == 0 and M >= i * N:
    print(i)
    exit()

Fixed submission:
N, M = list(map(int, input().split()))
# 範囲を絞る時は，反対の値も見るべき(M/iのこと)
print(max([j for i in range(int(M**0.5), 0, -1) for j in [i, int(M/i)] if M % j == 0 and M / N >= j]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
count_dict = {i:{} for i in range(2)}
#print(count_dict[0])
for i in range(2):
  for j in A[i::2]:
    if j not in count_dict[i]:
      count_dict[i][j] = 1
    else:
      count_dict[i][j] += 1

candidates = [sorted(count_dict[i].items(), key=lambda kv: kv[1]) for i in range(2)]

candidates = [i[1]+j[1] for i in candidates[0] for j in candidates[1] if i[0] != j[0]]
no_move = max(candidates) if candidates != [] else len(A) // 2
print(N-no_move)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
count_dict = {i:{} for i in range(2)}
#print(count_dict[0])
for i in range(2):
  for j in A[i::2]:
    if j not in count_dict[i]:
      count_dict[i][j] = 1
    else:
      count_dict[i][j] += 1

candidates = [sorted(count_dict[i].items(), key=lambda kv: kv[1], reverse=True)[:2] for i in range(2)]
candidates = [i[1]+j[1] for i in candidates[0] for j in candidates[1] if i[0] != j[0]]
no_move = max(candidates) if candidates != [] else len(A) // 2
print(N-no_move)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
count_dict = {i:{} for i in range(2)}
#print(count_dict[0])
for i in range(2):
  for j in A[i::2]:
    if j not in count_dict[i]:
      count_dict[i][j] = 1
    else:
      count_dict[i][j] += 1

candidates = []
for i in range(2):
  candidates.append(sorted(count_dict[i].items(), key=lambda kv: kv[1]))

candidates = [i[1]+j[1] for i in candidates[0] for j in candidates[1] if i[0] != j[0]]
no_move = max(candidates) if candidates != [] else len(A) // 2
print(N-no_move)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
count_dict = {i:{} for i in range(2)}
#print(count_dict[0])
for i in range(2):
  for j in A[i::2]:
    if j not in count_dict[i]:
      count_dict[i][j] = 1
    else:
      count_dict[i][j] += 1

candidates = [sorted(count_dict[i].items(), key=lambda kv: kv[1], reverse=True)[:2] for i in range(2)]
candidates = [i[1]+j[1] for i in candidates[0] for j in candidates[1] if i[0] != j[0]]
no_move = max(candidates) if candidates != [] else len(A) // 2
print(N-no_move)
Buggy python submission (verdict: Runtime Error):
import numpy as np
 
inp = np.asarray(input().split(), dtype=int)
inp = np.sort(inp)
print(inp[2]*10+np.sum(inp[:1])

Fixed submission:
import numpy as np
 
inp = np.asarray(input().split(), dtype=int)
inp = np.sort(inp)
print(np.sum(inp)+inp[2]*9)

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

inp = np.asarray(input().split(), dtype=int)
inp = np.sort(inp)
print(inp[0]*10+np.sum(inp[1:])

Fixed submission:
import numpy as np
 
inp = np.asarray(input().split(), dtype=int)
inp = np.sort(inp)
print(np.sum(inp)+inp[2]*9)

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

inp = list(map(input().split(), int))
inp = np.sort(inp)
print(inp[0]*10+np.sum(inp[1:])

Fixed submission:
import numpy as np
 
inp = np.asarray(input().split(), dtype=int)
inp = np.sort(inp)
print(np.sum(inp)+inp[2]*9)

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

inp = list(map(input(), int))
inp = np.sort(inp)
print(inp[0]*10+np.sum(inp[1:])

Fixed submission:
import numpy as np
 
inp = np.asarray(input().split(), dtype=int)
inp = np.sort(inp)
print(np.sum(inp)+inp[2]*9)
Buggy python submission (verdict: Runtime Error):
import numpy as np

XY = np.asarray(input().split(), dtype=int)
X = np.asarray(input().split(), dtype=int)
Y = np.asarray(input().split(), dtype=int)

if np,sum(X==XY[2]) == 1 or np,sum(Y==XY[3]) == 1:
    print("no war")
elif np.max(X) <= np.min(Y):
    print("no war")
else:
    print("war"




Fixed submission:
N, K, A, B = list(map(int, input().split()))
A_max = max(list(map(int, input().split())))
B_min = min(list(map(int, input().split())))

if A_max > A and B_min <= B and A_max < B_min:
  print("No War")
else:
  print("War")
Buggy python submission (verdict: Runtime Error):
S = input()
print(s.count("+")-s.count("-"))

Fixed submission:
S = input()
print(S.count("+")-S.count("-"))
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N >= 1000:
  print("ABD")
else:
  print("ABC)

Fixed submission:
N = int(input())
if N >= 1000:
  print("ABD")
else:
  print("ABC")
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())
bd = defaultdict(lambda: 0)
for i in range(N):
  bd[input()] += 1
N = int(input())
for i in range(N):
  bd[input()] -= 1

print(max([max(bd.values()), 0])

Fixed submission:
from collections import defaultdict
N = int(input())
bd = defaultdict(lambda: 0)
for i in range(N):
  bd[input()] += 1
N = int(input())
for i in range(N):
  bd[input()] -= 1

print(max([max(bd.values()), 0]))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
number = np.arange(10**5+1)
primes = np.ones(10**5+1)

for i in range(10**3):
  if i <= 1:
    primes[i] = 0
    continue
  if primes[i] == 1:
    primes[number%i==0]=0
    primes[i] = 1
    
N = int(input())
for i in range(N):
  s, e = list(map(int, input().split()))
  res = 0
  for j in range(s, e+1):
    if primes[j] == 1 and primes[int((j+1)/2)]:
      res += 1
  print(res)    

Fixed submission:
import numpy as np
number = np.arange(10**5+1)
primes = np.ones(10**5+1)
 
for i in range(int(np.sqrt(10**5+1))):
  if i <= 1:
    primes[i] = 0
    continue
  if primes[i] == 1:
    primes[number%i==0]=0
    primes[i] = 1
    
c = np.zeros(10**5+1)
for j in range(1, 10**5+1):
  if primes[j] == 1 and primes[int((j+1)/2)] == 1:
    c[j] = c[j-1] + 1
  else:
    c[j] = c[j-1]

N = int(input())
for i in range(N):
  s, e = list(map(int, input().split()))
  print(int(c[e]-c[s-1]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(map(int, input().split()))
X = [x//400 for x in X]
min_X = len(set([x for x in X if x < 8]))
max_X = min_X + len([x for x in X if x >= 8])
# この max は気づかないなあ
print(max([min_X, 1], max_X)


Fixed submission:
N = int(input())
X = list(map(int, input().split()))
X = [x//400 for x in X]
min_X = len(set([x for x in X if x < 8]))
max_X = min_X + len([x for x in X if x >= 8])
# この max は気づかないなあ
print(max([min_X, 1]), max_X)
Buggy python submission (verdict: Runtime Error):
s = input()
if s[3] == s[4] and s[5] == s[6]:
    print("Yes")
else:
    print("No")

Fixed submission:
s = input()
if s[2] == s[3] and s[4] == s[5]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
s=input()
if s[0]=='S':
   print('Cloudy')
else if s[0]=='C':
   print('Rainy')
else:
   print('Sunny')


Fixed submission:
s=input()
if s[0]=='S':
   print('Cloudy')
elif s[0]=='C':
   print('Rainy')
else:
   print('Sunny')
Buggy python submission (verdict: Time Limit Exceeded):
import sys 
input = sys.stdin.readline

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

ok = [i for i in range(n+1) if L<=i and i<=R]
ok2 = []

for i in range(m-1):
  l, r = map(int,input().split())
  for j in ok:
    if not(j < l or r < j):
      ok2.append(j)
  ok = ok2
  ok2 = []
      
print(len(ok))

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

n, m = map(int,input().split())
L = []
R = []

for i in range(m):
  l, r = map(int,input().split())
  L.append(l)
  R.append(r)
  
if min(R)-max(L) >= 0:
  print(min(R)-max(L)+1)
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
abs_a = []
minus = 0

for i in range(n):
  if a[i] < 0: minus += 1

if minus % 2 == 0:
  for i in range(n):
    abs_a.append(abs(a[i]))
  print(sum(abs_a))
else:
  for i in range(n):
    abs_a.append(abs(a[i]))
    min_abs_a = min(abs_a)
  print(sum(abs_a)-min_abs_a*2)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
abs_a = []
minus = 0

for i in range(n):
  if a[i] < 0: minus += 1

for i in range(n):
  abs_a.append(abs(a[i]))
  
if minus % 2 == 0:
  print(sum(abs_a))
else:
  min_abs_a = min(abs_a)
  print(sum(abs_a)-min_abs_a*2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a.sort()
abs_a = []
minus = 0

for i in range(n):
  if a[i] < 0: minus += 1
  else:break

if minus % 2 == 0:
  for i in range(n):
    if a[i] < 0:
      abs_a.append(abs(a[i]))
    else:
      abs_a.append(a[i])
  print(sum(abs_a))
else:
  for i in range(n):
    if a[i] < 0:
      abs_a.append(abs(a[i]))
    else:
      abs_a.append(a[i])
    min_abs_a = min(abs_a)
  print(sum(abs_a)-min_abs_a*2)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
abs_a = []
minus = 0

for i in range(n):
  if a[i] < 0: minus += 1

for i in range(n):
  abs_a.append(abs(a[i]))
  
if minus % 2 == 0:
  print(sum(abs_a))
else:
  min_abs_a = min(abs_a)
  print(sum(abs_a)-min_abs_a*2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a.sort()
abs_a = []
minus = 0

for i in range(n):
  if a[i] < 0: minus += 1

if minus % 2 == 0:
  for i in range(n):
    abs_a.append(abs(a[i]))
  print(sum(abs_a))
else:
  for i in range(n):
    abs_a.append(abs(a[i]))
    min_abs_a = min(abs_a)
  print(sum(abs_a)-min_abs_a*2)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
abs_a = []
minus = 0

for i in range(n):
  if a[i] < 0: minus += 1

for i in range(n):
  abs_a.append(abs(a[i]))
  
if minus % 2 == 0:
  print(sum(abs_a))
else:
  min_abs_a = min(abs_a)
  print(sum(abs_a)-min_abs_a*2)
Buggy python submission (verdict: Runtime Error):
import re
N, Q = map(int,input().split())
S = input()

for i in range(Q):
  l, r = map(int,input().split())
  Si = S[l-1:r]
  
  m = re.match('AC',Si)
  print(len(m.group())

Fixed submission:
b = input()
if b == 'A':
  print('T')
elif b == 'T':
  print('A')
elif b == 'C':
  print('G')
else:
  print('C')
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
S = input()
count = 0

for i in range(Q):
  l, r = map(int,input().split())
  Si = S[l-1:r]
  
  len_Si = len(Si)
  for i in range(len_Si-1):
    if Si[i:i+2] == 'AC':
      count += 1
  print(count)
  count = 0


Fixed submission:
N, Q = map(int,input().split())
S = input()
t=[0]*(N+1)
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())
  print(t[r-1] - t[l-1])

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

for i in range(Q):
  l, r = map(int,input().split())
  Si = S[l-1:r]
  
  len_Si = len(Si)
  for i in range(len_Si-1):
    if Si[i:i+2] == 'AC'
      count += 1
  print(count)
  count = 0


Fixed submission:
N, Q = map(int,input().split())
S = input()
t=[0]*(N+1)
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())
  print(t[r-1] - t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
S = input()
count = 0

for i in range(Q):
  l, r = map(int,input().split())
  Si = S[l-1:r]
  
  len_Si = len(Si)
  for i in range(len_Si-1):
    if Si[i] == 'A'and Si[i+1] == 'C':
      count += 1
  print(count)
  count = 0

Fixed submission:
N, Q = map(int,input().split())
S = input()
t=[0]*(N+1)
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())
  print(t[r-1] - t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import re
N, Q = map(int,input().split())
S = input()

for i in range(Q):
  l, r = map(int,input().split())
  Si = S[l-1:r]
  
  m = re.findall('AC',Si)
  if m != []:
    print(len(m))
  else:print(0)

Fixed submission:
N, Q = map(int,input().split())
S = input()
t=[0]*(N+1)
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())
  print(t[r-1] - t[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())
  Si = S[l-1:r]
  
  print(Si.count('AC'))

Fixed submission:
N, Q = map(int,input().split())
S = input()
t=[0]*(N+1)
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())
  print(t[r-1] - t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
S = input()
count = 0

for i in range(Q):
  l, r = map(int,input().split())
  Si = S[l-1:r]
  
  len_Si = len(Si)
  for i in range(len_Si-1):
    if Si[i] == 'A':
      if Si[i+1] == 'C':
        count += 1
  print(count)
  count = 0

Fixed submission:
N, Q = map(int,input().split())
S = input()
t=[0]*(N+1)
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())
  print(t[r-1] - t[l-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = int(input())
b = int(input())
if n == 1:
  print('Hello World')
else:
  print(a+b)

Fixed submission:
n = int(input())
if n == 1:
  print('Hello World')
else:
  a = int(input())
  b = int(input())
  print(a+b)
Buggy python submission (verdict: Runtime Error):
import sys 
input = sys.stdin.readline

n, m = map(int,input().split())
s = [0] #累積和
a = list(map(int,input().split()))
for i in range(n):
    s.append(s[i]+a[i])

mod = [0]*m
for i in s:
    mod[i%m] += 1

ans = 0
for i in mod:
    ans += i*(i-1)//2

print(ans)

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

n, m = map(int,input().split())
s = [0] #累積和
a = list(map(int,input().split()))
for i in range(n):
    s.append(s[i]+a[i])

mod = {} 
for i in s:
    if i%m in mod:
        mod[i%m] += 1
    else:
        mod[i%m] = 1

ans = 0
for i in mod:
    j = mod[i]
    ans += j*(j-1)//2

print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = int(intput())
if a <= 8 and b <= 8:
    print('Yay!')
else:
    print(':(')

Fixed submission:
a, b = map(int,input().split())
if a <= 8 and b <= 8:
    print('Yay!')
else:
    print(':(')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = 10**10
for i in range(n):
    l = s[:i]
    r = s[i+1:]
    ans = min(ans,l.count('W')+r.count('E'))

print(ans)

Fixed submission:
n = int(input())
s = input()
ans = 10**10
s_E = [0]
s_W = [0]
e = 0
w = 0
for i in range(n):
    if s[i] == 'E':
        e += 1
    else:
        w += 1
    s_E.append(e)
    s_W.append(w)

for i in range(n):
    ans = min(ans,s_W[i]+s_E[-1]-s_E[i+1])

print(ans)