Harryxun/stf_run huggingface dataset:
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
k_max = 5001
score = [0] * N

for i in range(N):
  exist_i = [(False, -1)] * k_max # (exist, j)
  exist_i[i] = (True, 0)
  score_i = [0] * K # iからスタートしてK回操作する場合の累積和
  score_i[0] = C[P[i]-1]
  index = P[i]-1
  for j in range(1, K):
    if exist_i[index][0] == True:
      # 既に進んだことがあるマスの場合
      
      # ループ終了インデックスからループ開始インデックスの累積和の差を確認
      loop_score = 0
      if exist_i[index][1] >= 1:
        loop_score = score_i[j-1] - score_i[exist_i[index][1] - 1] # 1ループで増えるスコア
      else:
        loop_score = score_i[j-1]
#      print("i, j, score_i", i, j, score_i)
#      print("i, j, loop_score", i, j, loop_score)
      if loop_score > 0:
        loop_num = j - exist_i[index][1] # ループする要素数
        num = K-j # 残りの操作数
        tmp_score = score_i[j-1] + num // loop_num * loop_score # ループ前までの累積和
#        print("i, j, tmp_score", i, j, tmp_score)
        tmp_array = [0] * (num % loop_num + 1)
        tmp_array[0] = tmp_score
        for l in range(1, num % loop_num + 1):
          tmp_array[l] = tmp_array[l-1] + C[P[index]-1]
          index = P[index]-1
#        print("i, j, tmp_array", i, j, tmp_array)
        score[i] = max(tmp_array)
      else:
#        print("i, j, score_i", i, j, score_i)
        score[i] = max(score_i)
#      print("i, j, score_i", i, j, score_i)
      break
    else:
      if j == K-1:
        score_i[j] = score_i[j-1] + C[P[index]-1]
        score[i] = max(score_i)
#        print("i, j, score_i", i, j, score_i)
        break   
    score_i[j] = score_i[j-1] + C[P[index]-1]
#    print("i, j, score_i", i, j, score_i)
#    print("i, j, score", i, j, score)
    exist_i[index] = (True, j)
    index = P[index]-1
print(max(score))

### FIXED CODE ###

# -*- coding: utf-8 -*-
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
k_max = 10100
score = [-10**18-1] * N

for i in range(N):
  score_i = [-10**18-1] * k_max # iからスタートしてK回操作する場合の累積和
  score_i[0] = C[P[i]-1]
  index = P[i]-1
  for k in range(1, K):
    if index == i:
      # 既に進んだことがあるマスの場合
      
      loop_score = score_i[k-1] # 1ループで増えるスコア
      if loop_score > 0:
        loop_num = k # ループする要素数はk(indexが0 ~ k-1)
        
        tmp_score = [-10**18-1] * k_max
        tmp_score[0] = (K//k -1) * loop_score
#        print("loop_score", loop_score)
#        print("tmp_score", tmp_score)
        tmp_index = index
#        print("loop_num + K%k + 1", loop_num + K%k + 1)
        for j in range (1, loop_num + K%k + 1):
          tmp_score[j] = tmp_score[j-1] + C[P[tmp_index]-1]
          tmp_index = P[tmp_index]-1
#        print("max(tmp_score)", max(tmp_score))
        score_i[k] = max(tmp_score)
      break
    score_i[k] = score_i[k-1] + C[P[index]-1]
    index = P[index]-1
  score[i] = max(score_i)
print(max(score))
N = int(input())
A = list(map(int,input().split()))
count = 0
B = []
b = 0

A.sort()
b = A[0]

while True:

    if len(A) == 1:
        break
    
    else:
        for i in range(len(A)):
            A[i] = A[i] % b
        
        A = set(A)
        A = list(A)
    
        for j in range(len(A)):
                if int(A[j]) != 0:
                    B.append(int(A[j]))
    
        B.sort()
    
        b = B[0]
        b_max = B[-1]


print(b_max)


### FIXED CODE ###

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

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b)

res = [0] * N
l = [0] * (N+1)
r = [0] * (N+1)

for i in range(N):
    l[i+1] = gcd(l[i],A[i])

for i in range(N,0,-1):
    r[i-1] = gcd(r[i],A[i-1])

for i in range(N):
    res[i] = gcd(l[i],r[i+1])

print(max(res))
n=int(input())
ct=0
for i in range(1,int(n**0.5)):
  if (n-i)%i==0:
    ct+=(n-i)//i
if (n-int(n**0.5))%int(n**0.5)==0:
  x=(n-int(n**0.5))//int(n**0.5)
  if n//x==n%x:ct+=x
print(ct)

### FIXED CODE ###

n=int(input())
if n==1:
  print(0)
else:
  ct=0
  for i in range(1,int(n**0.5)):
    if (n-i)%i==0:
      ct+=(n-i)//i
  if (n-int(n**0.5))%int(n**0.5)==0:
    x=(n-int(n**0.5))//int(n**0.5)
    if n//x==n%x:ct+=x
  print(ct)
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
ans = 0
ans = r*g*b
for i in range(1,n-1):
    m = min(i,n-i-1)
    for j in range(1,m+1):
        A,B,C = s[i],s[i-j],s[i+j]
        if A != B and A != C and B != C:
            ans -= 1
if r == 0 or g == 0 or b == 0:
    ans = 0
elif r == 1 or g == 1 or b == 1:
    ans = 1
print(ans)
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
ans = 0
ans = r*g*b
for i in range(1,n-1):
    m = min(i,n-i-1)
    for j in range(1,m+1):
        A,B,C = s[i],s[i-j],s[i+j]
        if A != B and A != C and B != C:
            ans -= 1
if r == 0 or g == 0 or b == 0:
    ans = 0
elif r == 1 or g == 1 or b == 1:
    ans = 1
print(ans)


### FIXED CODE ###

n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
ret = 0
for i in range(1,n-1):
    m = min(i,n-i-1)
    for j in range(1,m+1):
        A,B,C = s[i],s[i-j],s[i+j]
        if A != B and A != C and B != C:
            ret += 1
ans = r*g*b - ret
print(ans)
def main(a, b):
    if a>9:
        return -1
    if b>9:
        return -1
        
    return a*b

inp = input().split();
a = int(inp[0])
b = int(inp[1])
print(main(a,b))



### FIXED CODE ###

import sys
import math
import bisect
 
 
sys.setrecursionlimit(1000000000)
def input():
    return sys.stdin.readline().strip()
 
def iinput():
    return int(input())
 
def finput():
    return float(input())
 
def tinput():
    return input().split()
 
def rinput():
    return map(int, tinput())
 
def rlinput():
    return list(rinput())
 
def modst(a, s):
    res = 1
    while s:
        if s % 2:
            res *= a
        a *= a
        s //= 2
    return res

 
def main():
    a, b = rinput()
    if a >= 10 or b >= 10:
        print(-1)
    else:
        print(a * b)
main()
#157b
a=[[int(i) for i in input().split()] for _ in range(3)]
n=int(input())

for i in range(n):
	b=int(input())
	for j in range(3):
		for k in range(3):
			if a[j][k]==b:
				a[j][k]=0

ans='No'
for i in range(3):
	if a[i][0]==a[i][1]==[i][2]:
		ans='Yes'
	elif a[0][i]==a[1][i]==a[2][i]:
		ans='Yes'
	elif a[0][0]==a[1][1]==a[2][2]:
		ans='Yes'
	elif a[0][2]==a[1][1]==a[2][0]:
		ans='Yes'
print(ans)


### FIXED CODE ###

#157b
a=[[int(i) for i in input().split()] for _ in range(3)]
n=int(input())
for i in range(n):
    b=int(input())
    for j in range(3):
        for k in range(3):
            if a[j][k]==b:
               a[j][k]=0
ans='No'
for i in range(3):
    if a[i][0]==a[i][1]==a[i][2]:
        ans='Yes'
    elif a[0][i]==a[1][i]==a[2][i]:
        ans='Yes'
    elif a[0][0]==a[1][1]==a[2][2]:
        ans='Yes'
    elif a[0][2]==a[1][1]==a[2][0]:
        ans='Yes'
print(ans)
li=[]
for i in range(5):
    li.append(int(input()))

min=9

for i in range(5):
    if min> li[i]%10 >0:
        min=li[i]%10
        min_f=i

cnt=0

for i in range(5):
    if i==min_f:
        continue
    if li[i]%10==0:
        cnt+=li[i]
    else:
        cnt+=li[i]+10-li[i]%10
print(cnt+li[min_f])

### FIXED CODE ###

li=[]
for i in range(5):
    li.append(int(input()))

min=9

min_f=0

for i in range(5):
    if min> li[i]%10 >0:
        min=li[i]%10
        min_f=i

cnt=0

for i in range(5):
    if i==min_f:
        continue
    if li[i]%10==0:
        cnt+=li[i]
    else:
        cnt+=li[i]+10-li[i]%10
print(cnt+li[min_f])
s = input().strip()

def solve(s):
	for i in range(len(s)):
  		if i%2==0:
          if s[i] == "L":
          	return False
       	else:
          if s[i]=="R":
            return False
	return True
  
print("Yes" if solve(s) else "No")

### FIXED CODE ###

import sys

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

def solve(s):
	n = len(s)
	for i in range(n):
		if i%2==0:
			if s[i] == "L":
				return False
		else:
			if s[i] == "R":
				return False
	return True

print("Yes" if solve(s) else "No")
import sys
import collections

input = sorted(sys.argv[1])
a = collections.Counter(input)
if len(a) == 2 and a.most_common()[0][1] == 2:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import collections

inputstr = input()
input = sorted(inputstr)
a = collections.Counter(input)
if len(a) == 2 and a.most_common()[0][1] == 2:
    print('Yes')
else:
    print('No')
from collections import defaultdict

def counter():
    cnt = 0
    while True:
        yield cnt
        cnt += 1

def dfs(here, visited, track, count, connect):
    visited |= {here}
    for c in connect[here]:
        if c not in visited:
            dfs(c, visited, track, count, connect)
    track[here] = next(count)

def kosaraju(here, visited, track, count, connect):
    visited |= {here}
    for c in connect[here]:
        if c not in visited:
            kosaraju(c, visited, track, count, connect)
    track[here] = count

vertices, edges = (int(n) for n in input().split(" "))
connect = defaultdict(list)
reversed_connect = defaultdict(list)
for _ in range(edges):
    v1, v2 = (int(n) for n in input().split(" "))
    connect[v1].append(v2)
    reversed_connect[v2].append(v1)

visited = set()
track_gen = counter()
track = [-1 for n in range(vertices)]
for v in range(vertices):
    if v not in visited:
        dfs(v, visited, track, track_gen, connect)

visited = set()
track_gen = counter()
strongly_con = [-1 for n in range(vertices)]
for v in range(vertices - 1 ,- 1, -1):
    here = track.index(v)
    if here not in visited:
        num = next(track_gen)
        kosaraju(here, visited, strongly_con, num, reversed_connect)

q_num = int(input())
for _ in range(q_num):
    v1, v2 = (int(n) for n in input().split(" "))
    if strongly_con[v1] == strongly_con[v2]:
        print(1)
    else:
        print(0)

### FIXED CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(100000)

def counter():
    cnt = 0
    while True:
        yield cnt
        cnt += 1

def dfs(here, visited, track, count, connect):
    visited |= {here}
    for c in connect[here]:
        if c not in visited:
            dfs(c, visited, track, count, connect)
    track.append(here)

def kosaraju(here, visited, track, count, connect):
    visited |= {here}
    for c in connect[here]:
        if c not in visited:
            kosaraju(c, visited, track, count, connect)
    track[here] = count

vertices, edges = (int(n) for n in input().split(" "))
connect = defaultdict(list)
reversed_connect = defaultdict(list)
for _ in range(edges):
    v1, v2 = (int(n) for n in input().split(" "))
    connect[v1].append(v2)
    reversed_connect[v2].append(v1)

visited = set()
track_gen = counter()
track = []
for v in range(vertices):
    if v not in visited:
        dfs(v, visited, track, track_gen, connect)

visited = set()
track_gen = counter()
strongly_con = [-1 for n in range(vertices)]
for here in track[::-1]:
    if here not in visited:
        num = next(track_gen)
        kosaraju(here, visited, strongly_con, num, reversed_connect)

q_num = int(input())
for _ in range(q_num):
    v1, v2 = (int(n) for n in input().split(" "))
    if strongly_con[v1] == strongly_con[v2]:
        print(1)
    else:
        print(0)
k,n = int(input().split())

l = list(map(int, input().split()))
m = [0]*n
count = 0

for i in range(n-1):
    m[count] = l[i+1] - l[i]
    count+=1
m[n-1] = k - l(n-1) + l[0]

print(k - max(m))

### FIXED CODE ###

k,n = input().split()
k = int(k)
n = int(n)

l = list(map(int, input().split()))
m = [0]*n
count = 0

for i in range(n-1):
    m[count] = l[i+1] - l[i]
    count+=1
m[n-1] = k - l[n-1]+ l[0]

print(k - max(m))
n,m,k=map(int,input().split())
stock=[set() for i in range(n)]
ter=[0]*n
ans=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    stock[a-1].append(b-1)
    stock[b-1].append(a-1)
    ans[a-1]-=1
    ans[b-1]-=1
def dfs(j,k):
    size[k]+=1
    for next_j in stock[j]:
        if ter[next_j]==0:
            ter[next_j]=k
            dfs(next_j,k)
total=0
size=[0]*(n+1)
for i in range(n):
    if ter[i]==0:
        total+=1
        ter[i]=total
        dfs(i,total)

for i in range(n):
    ans[i]+=size[ter[i]]-1
for i in range(k):
    c, d = map(int, input().split())
    if ter[c-1]==ter[d-1]:
        ans[c-1]-=1
        ans[d-1]-=1
for i in range(n-1):
    print(ans[i],end=" ")
print(ans[n-1])

### FIXED CODE ###

class UnionFind:
    def __init__(self,n):
        self.n=n
        self.parent=[i for i in range(n)]
        self.rank=[1]*n#木の高さ
        self.size=[1]*n#size[i]はiを根とするグループのサイズ

    def find(self,x):#ｘの根（親）を返す
        if self.parent[x]==x:
            return x
        else:
            self.parent[x]=self.find(self.parent[x])#経路圧縮
            return self.parent[x]

    def unite(self,x,y):#ｘ、ｙの集合の統合
        x=self.find(x)
        y=self.find(y)
        if x!=y:
            if self.rank[x]<self.rank[y]:#ランクの比較
                self.parent[x]=y
                self.size[y]+=self.size[x]
            else:
                self.parent[y]=x
                self.size[x]+=self.size[y]
                if self.rank[x]==self.rank[y]:
                    self.rank[x]+=1
    def group_size(self,x):#ｘが属する集合の大きさ
        return self.size[self.find(x)]
    def is_same(self,x,y):#ｘ、ｙが同じ集合に属するかを判定する
        return self.find(x)==self.find(y)

n,m,k=map(int,input().split())

uf=UnionFind(n)
ans = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    uf.unite(a-1,b-1)
    ans[a - 1] -= 1
    ans[b - 1] -= 1
for i in range(k):
    c, d = map(int, input().split())
    if uf.is_same(c-1,d-1):
        ans[c-1]-=1
        ans[d-1]-=1

for i in range(n):
    ans[i]+=uf.group_size(i)-1
    print(ans[i])
class Main:

    def main(s1,s2):
        if s1 <= s2:
            print("unsafe");
        else:
            print("safe");
    main()

### FIXED CODE ###

class Main:

    s1, s2= map(int,input().split());

    if s1 <= s2:
        print("unsafe");
    else:
        print("safe");
def main():
    n = int(input())
    a = list([(int(input())) % 2 for i in range(n)])
    su = sum(a)
    xors = 0
    for i in(a):
        xors ^= i
    if(xors != 0 || sum == n):
        print('first')
    else:
        print('second')

main()

### FIXED CODE ###

def main():
    n = int(input())
    a = list([(int(input())) % 2 for i in range(n)])
    ans = sum(a)
    if(ans == 0):
        print('second')
    else:
        print('first')

main()
N = str(input())
if int(N)%9 != 0: print("No")
else:
    if int(N) == 0 :print("Yes")
    else:
        sum = 0
        for i in N:
           sum += i
        if sum%9 == 0: print("Yes")
        else: print("No")


### FIXED CODE ###

N = str(input())
if int(N)%9 != 0: print("No")
else:
    if int(N) == 0 :print("Yes")
    else:
        sum = 0
        for i in range(0,len(N)):
           sum += int(N[i])
        if sum%9 == 0: print("Yes")
        else: print("No")
n,m = list(map(int,input().split()))
ans = ['0' for i in range (n)]
fl = True

for i in range (m):
    s,c = input().split()
    s = int(s) - 1
    if (s == 0 and c == '0' and N != 1):
        fl = False
    if (ans[s] != '0'):
        if (ans[s] != c):
            fl = False
    else:
        ans[s] = c

res = ''

if (ans[0] == '0' and N != 1):
    ans[0] = '1'

for i in ans:
    res += i

print (res if fl else -1)

### FIXED CODE ###

#graph implementation
import math
n,m=map(int,input().split())
ans=['bal']*n
for i in range(m):
    s,c=map(int,input().split())
    if ans[s-1]=='bal':
      ans[s-1]=c
    else:
        if ans[s-1]!=c:
            print(-1)
            exit(0)
if ans[0]=='bal' and n>1:
    ans[0]=1
for i in range(n):
    if ans[i]=='bal':
        ans[i]=0
if ans[0]==0 and n>1:
    print(-1)
else:
    for i in ans:
        print(i,end="")
print()
A,B=input().split()
B=list(B)
N=B[1]+B[2]+B[3]
N=int(N)
C=int(A*N/100)
print(C)

### FIXED CODE ###

A,B=input().split()
A=int(A)
B=list(B)
N=B[0]+B[2]+B[3]
N=int(N)
C=int(A*N//100)
print(C)
from functools import lru_cache

@lru_cache(maxsize=1e6)
def n_th_prime(n):
    if n == 0:
        return 2
    while True:
        for i in range(n):
            if x % n_th_prime(i) == 0:
                break
        else: return(x)
        x += 1

### FIXED CODE ###

from functools import lru_cache
 
@lru_cache(maxsize=100000)
def n_th_prime(n):
    if n == 0:
        return 2
    primes = [n_th_prime(k) for k in range(n)]
    k = 1
    x = primes[-1] + 1
    while True:
        for p in primes[:k]:
            if x % p == 0:
                x += 1
                break
        else:
            if x > p**2:
                k += 1
            else:
                return x

x = int(input())

k = 0
p = 2
while True:
    for i in range(k):
        p = n_th_prime(i)
        if x % p == 0:
            x += 1
            break
    else:
        if x > p**2:
            k += 1
        else:
            print(x)
            break
n = int(input())
sum = 0

if(1 <= N <= 10 ** 6):

 for i in range(1 , n + 1 ):
    if (i % 3 == 0) and (i % 5 == 0):
        n = "FizzBuzz"
    elif (i % 3 == 0):
        n = "Fizz"
    elif (i % 5 == 0):
        n = "ZBuzz"
    else:
        sum += 1

print(sum)

### FIXED CODE ###

N = int(input())
list = []

for i in range(1, N + 1):
    if i % 3 == 0 and i % 5 == 0:
        "FizzBuzz"
    elif i % 3 == 0:
        "Fizz"
    elif i % 5 == 0:
        "Buzz"
    else:
        list.append(i)
print(sum(list))
N,M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
if N >= M: #設置できるコマが座標よりも大きければ終了
    print(0)
    exit()
diff = []
for i in range(1,len(X)):           #座標の差の最大可
    diff.append()(X[i]-X[i-1])
diff.sort(reverse=True)             
total = sum(diff)
for i in range(N-1):                #移動範囲が広い座標間をショートカット
    total -= diff[i]
print(total)

### FIXED CODE ###

N,M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
if N >= M: #設置できるコマが座標よりも大きければ終了
    print(0)
    exit()
diff = []
for i in range(1,len(X)):           #座標の差の最大可
    diff.append(X[i]-X[i-1])
diff.sort(reverse=True)
total = sum(diff)
for i in range(N-1):                #移動範囲が広い座標間をショートカット
    total -= diff[i]
print(total)
N, K = map(int, input().split())
TD = []

for _ in range(N):
  TD.append(tuple(map(int, input().split())))

TD.sort(key = lambda x:x[1], reverse=True)
TD += [(TD[-1][-1], 0)]

ans1 = 0
T1 = [0]*N
L = []
cnt1 = 0
temp = TD[0][1]

ans2 = 0
T2 = [0]*N
D2 = []
cnt2 = 0

for t, d in TD:
  if cnt1 < K:
    if temp == d and T1[t-1] == 1:
      L.append((t, d))
    elif temp == d and T1[t-1] == 0:
      T1[t-1] = 1
      ans1 += d
      cnt1 += 1
    else:
      while L:
        if cnt1 == K:
          break
        a, b = L.pop()
        ans1 += b
        cnt1 += 1
      if cnt1 < K:
        T1[t-1] = 1
        ans1 += d
        cnt1 += 1
        temp = d
  if cnt2 < K:
    if T2[t-1]:
      D2.append(d)
    else:
      T2[t-1] = 1
      ans2 += d
      cnt2 += 1

ans1 += sum(T1)**2
ans2 += sum(D2[:K-cnt2]) + sum(T2)**2

print(max(ans1, ans2))

### FIXED CODE ###

from collections import defaultdict
from heapq import heappop, heappush

N, K = map(int, input().split())
TD = []

for _ in range(N):
  TD.append(tuple(map(int, input().split())))

TD.sort(key = lambda x:x[1], reverse=True)
TD += [(TD[-1][0], 0)]

D = defaultdict(list)
T = [0]*N
H = []
ans = 0

for i in range(K):
  t, d = TD[i]
  T[t-1] += 1
  D[t].append(d)
  ans += d

cnt = sum(1 for c in T if c >= 1)
ans += cnt**2

for t in range(1, N+1):
  if T[t-1] >= 2:
    heappush(H, (D[t].pop(), t))
    T[t-1] -= 1

#print(ans, H, T, cnt)
for i in range(K, N):
  if H:
    t1, d1 = TD[i]
    d2, t2 = heappop(H)
    #print(t1, d1, t2, d2)
    if T[t1-1] == 0 and d1 - d2 + 2*cnt + 1 >= 0:
      ans += d1 - d2 + 2*cnt + 1
      cnt += 1
      T[t1-1] += 1
      if T[t2-1] >= 2:
        T[t2-1] -= 1
      if T[t2-1] >= 2:
        heappush(H, (D[t2].pop(), t2))
    else:
      heappush(H, (d2, t2))
    #print(ans, H, T, cnt)

#元のやつとの組み合わせ...？
ans2 = 0
T2 = [0]*N
D2 = []
cnt2 = 0
 
for t, d in TD:
  if cnt2 < K:
    if T2[t-1]:
      D2.append(d)
    else:
      T2[t-1] = 1
      ans2 += d
      cnt2 += 1

ans2 += sum(D2[:K-cnt2]) + sum(T2)**2

print(max(ans, ans2))
#!/usr/bin/env python3
import sys
from itertools import takewhile, count


def solve(N: int, K: int):
    return max(takewhile(lambda i: N >= (K ** i), count(1))) + 1

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    print(solve(N, K))

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from itertools import takewhile, count


def solve(N: int, K: int):
    return max(takewhile(lambda i: N >= (K ** i), count(0))) + 1

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    print(solve(N, K))

if __name__ == '__main__':
    main()
n = int(raw_input())

card = {"S":[0]*13, "H":[0]*13, "C":[0]*13, "D":[0]*13} 
 
for i in range(n):
  mark, nums = raw_input().split()
  deck[mark][nums] = 1
 
for i in ["S", "H", "C", "D"]:
  for j in range(0,13):
    if deck[i][j] == 0:
      print "%s %d" % (i, j+1)

### FIXED CODE ###

n = int(raw_input())

card = {"S":[0]*13, "H":[0]*13, "C":[0]*13, "D":[0]*13} 
 
for i in range(n):
  mark, nums = raw_input().split()
  card[mark][int(nums)-1] = 1
 
for i in ["S", "H", "C", "D"]:
  for j in range(13):
    if card[i][j] == 0:
      print "%s %d" % (i, j+1)
N = int(input())
A = list(map(int, input().split()))
a = A[int(N/2)]
b = A[int(N/2)+1]
print(b-a)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort()
a = A[int(N/2)-1]
b = A[int(N/2)]
print(b-a)
i = 1
while True:
    x = int(input())
    if x == 0:
        break
    print("Case {i}: {x}".format(i, x))
    i += 1


### FIXED CODE ###

i = 1
while True:
    x = int(input())
    if x == 0:
        break
    print("Case {0}: {1}".format(i, x))
    i += 1
i=0
H, W=map(int,input().split())
if H%2==1:
  if W%2==1:
    i+=((W+1)//2)*((H+1)//2)+(W//2)*(H//2)
  else:
    i+=(W//2)*((H+1)//2)+((W//2)*(H//2)
else:
  if W%2==1:
    i+=((W+1)//2)*(H//2)+(W//2)*(H//2)
  else:
    i+=(W//2)*(H//2)+(W//2)*(H//2)
print(i)

### FIXED CODE ###

i=0
H, W=map(int,input().split())
if H==1 or W==1:
  i=1
elif H%2==1:
  if W%2==1:
    i+=((W+1)//2)*((H+1)//2)+(W//2)*(H//2)
  elif W%2==0:
    i+=(W//2)*((H+1)//2)+(W//2)*(H//2)
elif H%2==0:
  if W%2==1:
    i+=((W+1)//2)*(H//2)+(W//2)*(H//2)
  elif W%2==0:
    i+=(W//2)*(H//2)+(W//2)*(H//2)
print(i)
n,m=map(int,input().split())
collect=[]
pen=[]
sum=0
for i in range(m):
  p,s=input().split()
  if p not in collect:
    if s=='WA':
      pen.append(p)
    else:
      collect.append(p)
      sum=sum+pen.count(p)
print(len(collect),sum-len(list))

### FIXED CODE ###

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

submit = []
for i in range(m):
    temp = [x for x in input().split()]
    submit.append(temp)

ac = [0] * (n + 1)
wa = [0] * (n + 1)

for i in range(m):
    result = submit[i][1]
    question = int(submit[i][0])

    if result == 'AC' and ac[question] == 0:
        ac[question] = 1
    elif result == 'WA' and ac[question] == 0:
        wa[question] += 1

for i in range(n + 1):
    if ac[i] != 1:
        wa[i] = 0

print(sum(ac), sum(wa))