Harryxun/stf_run huggingface dataset:
import numpy as np

n, k, q = map(int, input().split())
a = np.array([int(input()) for i in range(q)])

players_score = np.array([k for i in range(n)])
for item in a:
    players_score -= 1
    players_score[item-1] += 1

for i in players_score:
    if i <= 0:
        print("No")
    else:
        print("Yes")


### FIXED CODE ###

import numpy as np

n, k, q = map(int, input().split())
a = np.array([int(input()) for i in range(q)])

players_score = np.full(n, k-q)

for item in a:
    players_score[item-1] += 1

for i in players_score:
    if i <= 0:
        print("No")
    else:
        print("Yes")
import sys
import copy
R, C, K = map(int, input().split())
item = [[0]*C for _ in range(R)] 
for s in sys.stdin.readlines():
    r, c, v = map(int, s.split())
    r -= 1
    c -= 1
    item[r][c] = v
    
dp0 = [[0] * (C+1) for r in range(R+1)]
dp1 = [[0] * (C+1) for r in range(R+1)]
dp2 = [[0] * (C+1) for r in range(R+1)]
dp3 = [[0] * (C+1) for r in range(R+1)]
 
for r in range(R):
   for c in range(C):
      dp3[r][c] = max(dp3[r][c], dp2[r][c] + item[r][c])
      dp2[r][c] = max(dp2[r][c], dp1[r][c] + item[r][c])
      dp1[r][c] = max(dp1[r][c], dp0[r][c] + item[r][c])
      dp1[r][c+1] = max(dp1[r][c], dp1[r][c+1])
      dp2[r][c+1] = max(dp2[r][c], dp2[r][c+1])
      dp3[r][c+1] = max(dp3[r][c], dp3[r][c+1])
      dp0[r+1][c] = max(dp0[r+1][c], dp1[r][c])
      dp0[r+1][c] = max(dp0[r+1][c], dp2[r][c])
      dp0[r+1][c] = max(dp0[r+1][c], dp3[r][c])
ans = max(dp0[R-1][C-1], dp1[R-1][C-1])
ans = max(ans, dp3[R-1][C-1])
ans = max(ans, dp2[R-1][C-1])
print(ans)

### FIXED CODE ###

str = input()
if 'R' in str:
   crs=1
   if 'RR' in str:
      crs=2
      if 'RRR' in str:
         crs=3
else:
    crs=0
print(crs)
S = input();
while (len(S) != 0):
  if S[0] == 'h' and S[1] == 'i':
    S = S[2:]
  else:
    break
if len(S) != 0:
  print("No")
else:
  print("Yes")


### FIXED CODE ###

S = input()
if len(S) % 2 == 1:
  print("No")
else:
  while (len(S) != 0):
    if S[0] == 'h' and S[1] == 'i':
      S = S[2:]
    else:
      break
  if len(S) != 0:
    print("No")
  else:
    print("Yes")
a,b=map(int,input().split())
if a==b: print('Draw')
elif a==1: print('Alice')
elif b==1: print('Bob')
else print('Alice' if a>b else 'Bob')

### FIXED CODE ###

a,b=map(int,input().split())
if a==b: print('Draw')
elif a==1: print('Alice')
elif b==1: print('Bob')
else: print('Alice' if a>b else 'Bob')
num_n = raw_input()
ele_n = raw_input()
num_m = raw_input()
ele_m = raw_input()

n = ele_n.split()
m = ele_m.split()

for i in range(int(num_n) - 1):
    for j in range(2 ** (int(num_m) - 1)):
        sum[j] = 0
        sum[j] += m[j]
        sum += m[j]
        if n[i] == sum:
            print "yes"
            break
    print "no" 

### FIXED CODE ###

_ = int(input())
hoge = [int(x) for x in input().split()]
_ = int(input())

def exSearch(i, m):
    if m == 0:
        return True
    if i >= len(hoge) or m > sum(hoge):
        return False
    res = exSearch(i+1, m) or exSearch(i+1, m-hoge[i])
    return res

if __name__ == '__main__':
    
    for val in (int(x) for x in input().split()):
        if exSearch(0, val):
            print ('yes')
        else:
            print ('no')
from fractions import gcd
import math
n,m = map(int,input().split())
a = list(map(int, input().split()))
a = set(a)
g = 1
for i in a:
    g *= i // gcd(g,i)
if g * 0.5 > m:
    print(0)
else:
    print(math.floor((m / (g/2) + 1) / 2))

### FIXED CODE ###

import fractions
import math
n,m = map(int,input().split())
a = list(map(int, input().split()))
s = set(a)
c = set()
l = 1
k = (a[0] // 2) % 2
for i in a:
    l = l * i // fractions.gcd(l,i)
    if l // 2 > m:
        ans = 0
        break
    count = 0
    while True:
        if (i>>count) % 2 == 0:
            count += 1
        else:
            c.add(count)
            break
    if len(c) > 1:
        ans = 0
        break
else:
    ans = (m + l // 2) // l

print(ans)
if (int(input())*int(input()))%2==0 :
    print("even")
else :
    print("odd")

### FIXED CODE ###

a,b = map(int,input().split())
if a<0 or b<0 :
    print("negative!")
elif a>10000 or b>10000 :
    print("too big!")
elif a*b%2==0 :
    print("Even")
else :
    print("Odd")
x, *y = map(int, input().split())
C= 2
T= 4
ans="No"
for i in range(x+1):
    b=x-i
    if Ci + Tb == y:
        answer = "Yes"
print(answer)

### FIXED CODE ###

X,Y = map(int,input().split()) #input number of animals and legs

crane_legs = 2
turtle_legs = 4

answer = "No"

for i in range(X+1): #X+1 because it will only consider 0,1,2
    remaining = X-i
    if crane_legs*i + turtle_legs*remaining == Y:
        answer = "Yes"
#Loop to check combinations of animals is correct

print(answer)
n = int(input())
a = int(input())

if n%500 =< a:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

n = int(input())
a = int(input())


if n % 500 <= a:
    print("Yes")
else:
    print("No")
w,h,x,y = map(int,input().split())


num = 0

if w%2 is 0 and h%2 is 0:
  if w//2 is x and h//2 is y:
  	num = 1;num = 2/0
print(w*h/2,num)


### FIXED CODE ###

w,h,x,y = map(int,input().split())


num = 0

if w/2 == x and h/2 == y:
  num = 1
print(w*h/2,num)
# -*- coding: utf-8 -*-


def main():
    h, w = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    operations = list()

    # See:
    # https://atcoder.jp/contests/abc109/submissions/3154532
    for row in range(h):
        for col in range(w - 1):
            if a[row][col] % 2 == 1:
                operations.append((row + 1, col + 1, row + 1, col + 2))
                a[row][col] -= 1
                a[row][col + 1] += 1

    for row in range(h - 1):
        if a[row][w - 1] % 2 == 1:
            operations.append((row + 1, col + 1, row + 2, col + 1))
            a[row][w - 1] -= 1
            a[row + 1][w - 1] += 1

    n = len(operations)
    print(n)

    for i in range(n):
        y, x, y_dash, x_dash = operations[i]
        print(y, x, y_dash, x_dash)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-


def main():
    h, w = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    operations = list()
    row = 0
    prev_x, prev_y = 0, 0
    odd_count = 0

    while row < h:
        if row % 2 == 0:
            for col in range(w):
                if a[row][col] % 2 == 1:
                    if odd_count == 0:
                        prev_x, prev_y = col + 1, row + 1
                        odd_count = 1
                    else:
                        cur_x, cur_y = col + 1, row + 1
                        operations.append((prev_y, prev_x, cur_y, cur_x))
                        prev_x, prev_y = cur_x, cur_y
                        odd_count = 0
                else:
                    if odd_count == 1:
                        cur_x, cur_y = col + 1, row + 1
                        operations.append((prev_y, prev_x, cur_y, cur_x))
                        prev_x, prev_y = cur_x, cur_y
        else:
            for col in range(w - 1, -1, -1):
                if a[row][col] % 2 == 1:
                    if odd_count == 0:
                        prev_x, prev_y = col + 1, row + 1
                        odd_count = 1
                    else:
                        cur_x, cur_y = col + 1, row + 1
                        operations.append((prev_y, prev_x, cur_y, cur_x))
                        prev_x, prev_y = cur_x, cur_y
                        odd_count = 0
                else:
                    if odd_count == 1:
                        cur_x, cur_y = col + 1, row + 1
                        operations.append((prev_y, prev_x, cur_y, cur_x))
                        prev_x, prev_y = cur_x, cur_y

        row += 1

    n = len(operations)
    print(n)

    for i in range(n):
        y, x, y_dash, x_dash = operations[i]
        print(y, x, y_dash, x_dash)


if __name__ == '__main__':
    main()
a = 20
b = map(int, input().split())
print("Odd" if a % b == 0)

### FIXED CODE ###

a, b = map(int, input().split())
if (a*b) % 2:
  print('Odd')
else:
  print('Even')
n = int(input())

ans = n

i = 1

while i*i<=n :
  if n%i == 0 :
    d = n/i
    if ans > i*d-2 : ans = i*d-2
  i++
      
print(ans)

### FIXED CODE ###

n = int(input())
ans = n
i = 1
while i*i<=n :
  if n%i == 0 :
    d = n//i
    if ans > i+d-2 : ans = i+d-2
  i+=1
print(int(ans))
n, m = map(int, input().split())
List1 = [[0 for i in range(m)] for i in range(n)]
for x in range(n):
    List1[x] = list(map(int, input().split()))
List2 = [int(input()) for _ in range(n)]
sum = [0 for i in range(n)]
for x in range(n):
    for y in range(m):
        sum[x] += List1[x][y] * List2[y]
for x in range(n):
    print(sum[x])


### FIXED CODE ###

n, m = map(int, input().split())
List1 = [[0 for i in range(m)] for i in range(n)]
for x in range(n):
    List1[x] = list(map(int, input().split()))
List2 = [int(input()) for i in range(m)]
sum = [0 for i in range(n)]
for x in range(n):
    for y in range(m):
        sum[x] += List1[x][y] * List2[y]
for x in range(n):
    print(sum[x])
n=int(input())
l=list(map(int,input().split()))
print(" ".join(map(str,[l.index(i)+1 for i in range(1,n+1)]))

### FIXED CODE ###

def main():
  n=int(input())
  l=list(map(int,input().split()))
  k=[0]*n
  for i in range(1,n+1):
    k[l[i-1]-1]=str(i)
  print(" ".join(k))


if __name__ == '__main__':
    main()
s = list(input())
k = int(input())
z_asc = ord('z')
for i in range(len(s)):
    tmp = ord(s[i])
    if 1 + z_asc - tmp <= k and s[i] != 'a':
        k -= 1 + z_asc - tmp
        s[i] = 'a'
if k % 26 != 0:
    s[-1] = chr(ord(s[-1]) + k)
ans = "".join(s)
print(ans)



### FIXED CODE ###

s = list(input())
k = int(input())
z_asc = ord('z')
for i in range(len(s)):
    tmp = ord(s[i])
    if 1 + z_asc - tmp <= k and s[i] != 'a':
        k -= 1 + z_asc - tmp
        s[i] = 'a'
if k % 26 != 0:
    s[-1] = chr(ord(s[-1]) + k%26)
ans = "".join(s)
print(ans)
N=int(input())
A= [int(a) for a in input().split()]
minusnum=sum(a<0 for a in A)
ans=sum(abs(a) for a in A)
if minusnum%2:
    plusmin=min(a for a in A if a>=0)
    minusmin=min(-a for a in A if a<0)
    if minusmin>plusmin:
        ans=ans-2*plusmin
    else:
        ans=ans-2*minusmin
print(ans)

### FIXED CODE ###

N=int(input())
A= [int(a) for a in input().split()]
minusnum=sum(a<0 for a in A)
ablist=[abs(a) for a in A]
ans=sum(ablist)
if minusnum%2:
    ans=ans-2*min(ablist)

print(ans)
l = raw_input().split()

x1 = int(l[0])
y1 = int(l[1])
x2 = int(l[2])
y2 = int(l[3])

a = max(abs(x1-x2), abs(y1-y2))

if x1 < x2:
  x3 = x2
  y3 = y1 + a
  x4 = x1
  y4 = y1 + a
elif x1 == x2:
  if y1 > y2:
    x3 = x2 + a
    y3 = y2
    x4 = x2 + a
    y4 = y1
  else:
    x3 = x2 - a
    y3 = y2
    x4 = x2 - a
    y4 = y1
elif x1 > x2:
  x3 = x2
  y3 = y1 - a
  x4 = x1
  y4 = y1 - a
  
print(str(x3)+' '+str(y3)+' '+str(x4)+' '+str(y4))

### FIXED CODE ###

import math
l = input().split()

x1 = int(l[0])
y1 = int(l[1])
x2 = int(l[2])
y2 = int(l[3])

yoko = x2-x1
tate = y2-y1

x3 = x2 - tate
y3 = y2 + yoko
x4 = x1 - tate
y4 = y1 + yoko

  
print(str(x3)+' '+str(y3)+' '+str(x4)+' '+str(y4))
a,b=map(int,input().split())
if a%2 == b%2:
  if ((b-a)%2)%2 == 0:
    print(b)
  else:
    if b%2 == 1:
      print(b-1)
    else:
      print(b+1)
else:
  c=b
  bits=[]
  perfect=False
  while b>0:
    bits.append(b%2)
    b= b//2
  if bits.count(1)==1 and bits[-1]==1:
    perfect=True
    b=c-1
    bits=[]
  while b>0:
    bits.append(b%2)
    b= b//2
  for i in range(len(bits)):
    if (bits[i]==1 and a%2==1) or (bits[i]==0 and a%2==0):
      bits[i]=0
    else:
      bits[i]=1
    a= a//2
    ans=0
  for i in range(len(bits)):
    ans+= bits[i]*(2**i)
  if perfect:
    print(ans+c)
  else:
    print(ans)


### FIXED CODE ###

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

def xor(p):
  if p%4 == 0:
    return p
  elif p%4 == 1:
    return 1
  elif p%4 == 2:
    return p+1
  elif p%4 == 3:
    return 0

if a==0:
  print(xor(b))
elif a == b:
  print(a)
else:
  s=max(xor(b),xor(a-1))
  t=min(xor(a-1),xor(b))
  data=[]
  while s>0:
    data.append(s%2)
    s=s//2
  for i in range(len(data)):
    if (data[i] == t%2):
      data[i] = 0
    else:
      data[i] = 1
    t = t//2
  sum=0
  for i in range(len(data)):
    sum+= data[i]*(2**i)
  print(sum)
def input_from_console():
    n = int(input())
    a_list, b_list = [], []
    for i in range(n-1):
        data = input()
        a, b = map(int, data.split())
        if b > a:
            a, b = b, a  # swap smaller one.
        a_list.append(a)
        b_list.append(b)
    c_list = []
    c_list = list(map(int, input().split()))
    lr_list = []
    return n, a_list, b_list, c_list


def solve(n, a_list, b_list, c_list):
    total = 0
    c_list = sorted(c_list, reverse=True) # Because maximum number is not selected at all.
    import itertools
    current_max = 0
    current_list = []

    c_list_new = [c_list[item-1] for item in set(a_list + b_list)]
    for new_list in itertools.permutations(c_list_new, n):
        total = 0
        for i in range(n - 1):
            total += min(new_list[a_list[i]-1], new_list[b_list[i]-1])
        if total >= current_max:
            current_max = total
            current_list = new_list

    return f"{current_max}\n" + " ".join(map(str, current_list))


def main():
    n, a_list, b_list, c_list = input_from_console()
    print(solve(n, a_list, b_list, c_list))


### FIXED CODE ###


def input_from_console():
    n = int(input())
    a_list, b_list = [], []
    for i in range(n - 1):
        data = input()
        a, b = map(int, data.split())
        if b > a:
            a, b = b, a  # swap smaller one.
        a_list.append(a)
        b_list.append(b)
    c_list = []
    c_list = list(map(int, input().split()))
    return n, a_list, b_list, c_list


def solve(n, a_list, b_list, c_list):
    edge = [[] for i in range(n)]
    for i in range(len(a_list)):
        a, b = a_list[i] - 1, b_list[i] - 1  # convert to 0 based index.
        edge[a].append(b)
        edge[b].append(a)
    c_list_new = sorted(c_list, reverse=True)

    value = sum(c_list_new[1:])

    vertices = [None] * n
    vertices[0] = c_list_new.pop(0)

    search_path = []
    search_path.extend(edge[0])

    while search_path:
        node = search_path.pop(0)
        if vertices[node] is None:
            vertices[node] = c_list_new.pop(0)
            search_path.extend(edge[node])
    return str(value) + '\n' + ' '.join(map(str, vertices))


def main():
    n, a_list, b_list, c_list = input_from_console()
    print(solve(n, a_list, b_list, c_list))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()
N = int(input())
A = list(map(int, input().split()))
money = 1000
stock = 0
for i in range(N-1):
    if A[i+1] > A[i]:
        stock = money // A[i]
        money = money % A[i]
        money = stock * A[i+1]
print(money)


### FIXED CODE ###

X = int(input())
a = X // 200
print(10 - a)
s = input()
a = 0
for i in range(3):
	if s[i:i+1] != 'x':
      a += 100
print(700 + a)

### FIXED CODE ###

s = input()
a = 0
for i in range(3):
	if s[i:i+1] != 'x':
		a += 100
print(700 + a)
N = int(input())
monster = list(map(int, input().split()))
if 1 in monster:
  print(1)
else:
  monster.sort()
  min1, min2 = monster[0], monster[1]
  while min1 >= 0 and min2 > 0:
    if min1 <= min2:
      min2 = min2 % min1
    else:
      min1 = min1 % min2
  print(max(min1, min2))

### FIXED CODE ###

from functools import reduce
from fractions import gcd
N = int(input())
monster = list(map(int, input().split()))
print(reduce(gcd, monster))
K=4000
S=[input()for i in R(3)]
A,B,C=S
la,lb,lc=len(A),len(B),len(C)
def F(S,T):
 R=[1]*(K*2+1)
 for i in R(-len(T),len(S)):
  for j in range(max(i,0),min(len(S),len(T)+i)):
   if S[j]!=T[j-i]and S[j]!="?"and T[j-i]!="?":
    R[i]=0
    break
 return R
AB=F(A,B)
AC=F(A,C)
BC=F(B,C)
mi=K*3
for ib in range(-K,K+1):
 if AB[ib]!=0:
  for ic in range(-K, K+1):
   if AC[ic]==0 or BC[ic-ib]==0:
    mi=min(mi,max(ib+lb,ic+lc,la)-min(ib,ic,0))
print(mi)


### FIXED CODE ###

print('YNeos'[1-(input()in['hi'*i for i in range(11)])::2])
def muri(k, c, s):
  for j in range(len(s)):
    if s[j] == "o":
      return muri(k-1, c, s[j+c+1:])
    elif j == len(s) -1 and k > 0:
      return True
  return False

n, k, c = map(int, input().split())
s = input()
s += "x"*c

for i in range(len(s)):
  if s[i] == "o":
    if muri(k, c, s[:i]+"x"+s[i+1:]):
      print(i+1)

### FIXED CODE ###

n, k, c = map(int, input().split())
s = input()
s2 = s
s += "x"*c
s2 = "x"*c+s2
k2 = k
kans = k
left = []
i = 0
while i < n:
  if s[i] == "o":
    left.append(i+1)
    i += c
  i += 1

right = []
i = len(s2)-1
while i >= c:
  if k2 == 0:
    break
  if s2[i] == "o":
    right.append(i+1-c)
    k2 -= 1
    i -= c
  i -= 1
if len(left) == kans:
  ans = sorted(list(set(left) & set(right)))
  for i in ans:
    print(i)
else:
  exit()
from collections import deque

H, W = map(int, input().split())

G = []
for i in range(H):
    G.append(list(input()))


move = [[0, 1], [0, -1], [0, 1], [1, 0]]
saidai = 0
for sy in range(H):
    for sx in range(W):
        if G[sy][sx] == "#":
            break
        queue = deque([[sy, sx]])
        G[sy][sx] = 0
        visited = [[0]*W for i in range(H)]
        while queue:
            y, x = queue.popleft()
            for i in move:
                iy, ix = i[0], i[1]
                if 0<=iy+y<H and 0<=ix+x<W and G[iy+y][ix+x] =="." and visited[iy+y][ix+x] == 0:
                    visited[iy+y][ix+x] = 1
                    G[iy+y][ix+x] = G[y][x] + 1
                    queue.append([iy+y, ix+x])
 
        for i in range(H):
            for j in range(W):
                if G[i][j] == "#":
                    continue
                else:
                    saidai = max(saidai, G[i][j])

print(saidai)

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())

G = []
for i in range(H):
    G.append(list(input()))


move = [[0, 1], [0, -1], [-1, 0], [1, 0]]
saidai = 0
for sy in range(H):
    for sx in range(W):
        if G[sy][sx] == ".":
            queue = deque([[sy, sx]])
            visited = [[-1]*W for i in range(H)]
            visited[sy][sx] = 0
            while queue:
                y, x = queue.popleft()
                for i in move:
                    iy, ix = i[0], i[1]
                    if 0<=iy+y<H and 0<=ix+x<W and G[iy+y][ix+x] =="." and visited[iy+y][ix+x] == -1:
                        visited[iy+y][ix+x] = visited[y][x] + 1
                        queue.append([iy+y, ix+x])
        
            for i in range(H):
                for j in range(W):
                        saidai = max(saidai, visited[i][j])
            queue = []
            visited = [[0]*W for i in range(H)]
print(saidai)
S, W = map(lambda: x, input().split())
if S>W:
  print('safe')
else:
  print('unsafe')

### FIXED CODE ###

S, W = map(lambda x: int(x), input().split())
if S > W:
  print('safe')
else:
  print('unsafe')
A=B=int(input())
N = list(int,input().split())

c=0

for i in range(A):
  if N[i] >= B:
    c+=1
  else:
    pass
  i+=1
print(c)

### FIXED CODE ###

A,B=map(int,input().split())
N = list(map(int,input().split()))

c=0

for i in range(A):
  if N[i] >= B:
    c+=1
  else:
    pass
  i+=1
print(c)
n = int(input())
l = []
for i in range(n):
    x,y = map(int,input().split())
    l.append((x,y))

d = dict()
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        x1,y1 = l[i]
        x2,y2 = l[j]
        if d.__contains__((x2-x1,y2-y1)):
            d[(x2-x1,y2-y1)] += 1
        else:
            d[(x2-x1,y2-y1)] = 1
maxV = max(list(d.values()))

print(n-maxV)


### FIXED CODE ###

n = int(input())
l = []
for i in range(n):
    x,y = map(int,input().split())
    l.append((x,y))

d = dict()
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        x1,y1 = l[i]
        x2,y2 = l[j]
        if d.__contains__((x2-x1,y2-y1)):
            d[(x2-x1,y2-y1)] += 1
        else:
            d[(x2-x1,y2-y1)] = 1

ll = list(d.values())
if ll == []:
    maxV = 0
else:
    maxV = max(list(d.values()))

print(n-maxV)
N = input()

if N%2 == 0:
  ans = N//2
else:
  ans = N//2 + 1

return(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Tue Mar  3 19:08:31 2020

@author: Kanaru Sato
"""

N = int(input())

ans = N//2 + N%2

print(ans)
a,b=map(int,input().split())print(('P','Imp')[a*b*(a+b)%3>0]+'ossible')

### FIXED CODE ###

a,b=map(int,input().split());print(['P','Imp'][a*b*(a+b)%3>0]+'ossible')
from collections import deque

N, K = [int(x) for x in input().split()]
r, s, p = [int(x) for x in input().split()]

win_point = {
    'r': r,
    's': s,
    'p': p,
}

next_hands = {
    'r': ['s', 'p'],
    's': ['r', 'p'],
    'p': ['r', 's'],
}

enemy_hands = input()


def can_win(enemy_hand, my_hands):
    # 勝てる場合にはTrueと勝てる手を教えてくれる
    if enemy_hand == 'r' and 'p' in my_hands:
        return True, 'p'
    if enemy_hand == 's' and 'r' in my_hands:
        return True, 'r'
    if enemy_hand == 'p' and 's' in my_hands:
        return True, 's'

    # 勝てる手がない場合
    return False, None


def choose_hand(enemy_hand, next_enemy_hand, now_hands):
    # 次の手に勝てるようにその手以外を選択する
    if next_enemy_hand == enemy_hand:
        # 次回も同じ手ならどっちでも良い
        return now_hands[0]

    win, hand = can_win(next_enemy_hand, enemy_hand)

    # 次の手と今の相手の手を戦わせる
    # 後の手が勝ったら今の手と同じものを出す
    # 今の手が勝ったら後の手と同じものと出す
    if win:
        return now_hands[enemy_hand]
    else:
        return now_hands[next_enemy_hand]


point = 0

for index in range(K):
    target = index
    now_hands = ['r', 'p', 's']
    for i in range(index, N, K):
        win, hand = can_win(enemy_hands[i], now_hands)

        if win:
            point += win_point[hand]
            now_hands = next_hands[hand]
        else:
            if i + K < N:
                next_enemy_hand = enemy_hands[i+K]
                now_hands = next_hands[choose_hand(
                    enemy_hands[i], next_enemy_hand, now_hands)]

print(point)


### FIXED CODE ###

N, K = [int(x) for x in input().split()]
r, s, p = [int(x) for x in input().split()]

win_point = {
    'r': r,
    's': s,
    'p': p,
}

next_hands = {
    'r': ['s', 'p'],
    's': ['r', 'p'],
    'p': ['r', 's'],
}

enemy_hands = input()


def can_win(enemy_hand, my_hands):
    # 勝てる場合にはTrueと勝てる手を教えてくれる
    if enemy_hand == 'r' and 'p' in my_hands:
        return True, 'p'
    if enemy_hand == 's' and 'r' in my_hands:
        return True, 'r'
    if enemy_hand == 'p' and 's' in my_hands:
        return True, 's'

    # 勝てる手がない場合
    return False, None


point = 0

for index in range(K):
    now_hands = ['r', 'p', 's']
    for i in range(index, N, K):
        win, hand = can_win(enemy_hands[i], now_hands)

        if win:
            point += win_point[hand]
            now_hands = next_hands[hand]
        else:
            # 勝てない場合次似邪魔しない手を選ぶ
            # 勝てない回の次は必ず勝てるため全手出せる前提とする
            now_hands = ['r', 'p', 's']

print(point)
S = input()
question = []
for i in range(Q):
  question.append(list(map(int, input().split())))

# Sの中で、ACという部分文字列が含まれるときの（Aの）index
index = []
for i in range(N-1):
  if S[i]+S[i+1] == "AC":
    index.append(i)

for i, q in enumerate(question):
  ans = 0
  for j in range(len(index)):
    if index[j] >= q[0]-1 and index[j]+1 <= q[1]-1:
      ans +=1
  print(ans)

### FIXED CODE ###

import bisect

N, Q = map(int, input().split())
S = input()
question = []
for i in range(Q):
  question.append(list(map(int, input().split())))

# Sの中で、ACという部分文字列が含まれるときの（Aの）index
index = []
for i in range(N-1):
  if S[i]+S[i+1] == "AC":
    index.append(i)

# i番目の文字以降に存在するACという部分文字列の数
sum_index = [0]*N
sum_ac = 0
for i in range(N-1):
  if S[N-(i+2)]+S[N-(i+1)] == "AC":
    sum_ac += 1
  sum_index[N-(i+2)] = sum_ac

for i, q in enumerate(question):
  ans = sum_index[q[0]-1] - sum_index[q[1]-1]
  print(ans)