Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

# floor(Ax/B) - A floor(x/B) の最大値Mを求める
# xはN以下の非負整数
# floor(Ax / B) = M + A floor(x / B)
# x / B = k + r
# Ax / B = Ak + Ar

# floor(Ak + Ar) = M + A floor(k + r)
# Ak + floor(Ar) = M + Ak + A floor(r)
# floor(Ar) = M

# r = x / B - k
# M = floor(A * (x / B - k))
#   = floor(A * x /B) - Ak
#   = floor(A/B * x) - Ak
#   = floor(A/B * x) - A * (x // B) 

# A B N
# 5 7 4

# M = floor(5/7 * x) - 5 * (x // 7)


# A B N 
# 11 10 9
# M = floor(11 / 10 * x) - 11 * (x // 10)

import math

def calcM(A, B, x):
        return math.floor(A / B * x) - A * math.floor(x / B)    

def resolve_v1(A, B, N):
    maxM = 0
    for x in range(N+1): # O(N)
        M = calcM(A, B, x)
        maxM = max(maxM, M)

    return maxM

# def resolve_v2(A, B, N):
#     if B < N:
#         return max(calcM(A, B, N+1), calcM(A, B, N))

if __name__ == '__main__':
    A, B, N = map(int, input().split())
    M = resolve_v1(A, B, N)
    print(M)




### FIXED CODE ###

# floor(Ax/B) - A floor(x/B) の最大値Mを求める
# xはN以下の非負整数
# floor(Ax / B) = M + A floor(x / B)
# x / B = k + r
# Ax / B = Ak + Ar

# floor(Ak + Ar) = M + A floor(k + r)
# Ak + floor(Ar) = M + Ak + A floor(r)
# floor(Ar) = M

# r = x / B - k
# M = floor(A * (x / B - k))
#   = floor(A * x /B) - Ak
#   = floor(A/B * x) - Ak
#   = floor(A/B * x) - A * (x // B) 

# A B N
# 5 7 4

# M = floor(5/7 * x) - 5 * (x // 7)


# A B N 
# 11 10 9
# M = floor(11 / 10 * x) - 11 * (x // 10)

import math

def calcM(A, B, x):
        return math.floor(A / B * x) - A * math.floor(x / B)    

def resolve_v1(A, B, N):
    maxM = 0
    for x in range(N+1): # O(N)
        M = calcM(A, B, x)
        maxM = max(maxM, M)

    return maxM

def resolve_v2(A, B, N):
    # x == kB - 1
    maxM = calcM(A, B, N)

    for x in filter(lambda x: (x + 1) % B == 0, range(N+1)): # O(N/B)
        maxM = max(maxM, calcM(A, B, x))
    return maxM


def resolve_v3(A, B, N):
    maxM = calcM(A, B, N)

    k, r = divmod(N, B)
    if k and B * k -1 <= N:
        # k * B - 1で調査
        maxM = max(maxM, calcM(A, B, k * B - 1))
    # if r == 0:
    #     maxM = max(maxM, calcM(A, B, N - 1))

    maxM = calcM(A, B, min(N, B - 1))


    return maxM

if __name__ == '__main__':
    A, B, N = map(int, input().split())
    M = resolve_v3(A, B, N)
    print(M)
### BUGGY CODE ###

import sys


def my_input(): return sys.stdin.readline().rstrip()


def main():

    N = int(my_input())
    S = my_input()

    ans = 0
    for i in range(1000):
        d1 = (i // 100) % 10
        d2 = (i // 10) % 10
        d3 = i % 10
        d1_flag = True
        d2_flag = True

        for j in S:

            now = int(j)
            if d1_flag:
                if d1 == now:
                    d1_flag = False
                continue

            if d2_flag:
                if d2 == now:
                    d2_flag = False
                continue

            if d3 == now:
                ans += 1
                break

    print(ans)


if __name__ == '__main__':

    main()


### FIXED CODE ###

n = int(input())
s = list(input())

ans = 0


for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = 0
            flag2 = 0
            
            for l in range(n):
                if flag1 == 0 and s[l] == str(i):
                    flag1 = 1
                    continue
                
                if flag1 == 1 and flag2 == 0 and s[l] == str(j):
                    flag2 = 1
                    continue
                
                if flag1 == 1 and flag2 == 1 and s[l] == str(k):
                    ans += 1
                    break
                
print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))

calRes = 0
calIndex = 0
expectedList = []
expectedCorList = []
Counter = 0

for i in range(N):
    cal = list(range(1, p[i] + 1))
    Counter += 1
    expectedList.append(sum(cal) * (1 / len(cal)))

for o in range(N - 2):
    calTemp = sum(expectedList[o:o + K])
    if calRes < calTemp:
       calRes = calTemp
       calIndex = o

for l in range(K):
    expectedCorList.append(expectedList[calIndex + l])

calCor = sum(expectedCorList)
print(calCor)

### FIXED CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))

expectedList = [(1 + s) /  2 for s in p]
cumsum = sum(expectedList[:K])
confirm_cumsum = cumsum

for i in range(K, N):
    cumsum += expectedList[i]
    cumsum -= expectedList[i - K]
    if cumsum > confirm_cumsum:
        confirm_cumsum = cumsum

print(confirm_cumsum)
### BUGGY CODE ###

K=int(input())

memo={}
def gcd(a,b):
    if a<b:
        a,b=b,a

    aa=a
    bb=b
    if (a,b) in memo.keys():
        return memo[a,b]
    while b != 0:
        a,b, = b, a%b
    memo[aa,bb]=a
    return a





memo3={}

def gcd3(a,b,c):
    if a>b:
        a,b = b,a
    if a>c:
        a,c = c,a
    if b>c:
        b,c = c,b
    if (a,b,c) in memo3.keys():
        return memo3[(a,b,c)]
    
    g = gcd(gcd(a,b),c)
    memo3[(a,b,c)]=g
    return g


sum=0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            
            if i==j & j==k:
                sum += gcd3(i,j,k)
                continue
            if i==j & j!=k:
                sum += gcd3(i,j,k)*3
                continue
            if i!=j & j==k:
                sum += gcd3(i,j,k)*3
                continue
            sum += gcd3(i,j,k)*6
print(sum)





### FIXED CODE ###

K=int(input())

memo={}
def gcd(a,b):
    if a<b:
        a,b=b,a

    aa=a
    bb=b
    if (a,b) in memo.keys():
        return memo[a,b]
    while b != 0:
        a,b, = b, a%b
    memo[aa,bb]=a
    return a





memo3={}

def gcd3(a,b,c):
    if a>b:
        a,b = b,a
    if a>c:
        a,c = c,a
    if b>c:
        b,c = c,b
    if (a,b,c) in memo3.keys():
        return memo3[(a,b,c)]
    
    g = gcd(gcd(a,b),c)
    memo3[(a,b,c)]=g
    return g


sum=0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            
            if i==j & j==k:
                sum += gcd3(i,j,k)
                continue
            if i==j & j!=k:
                sum += gcd3(i,j,k)*3
                continue
            if i!=j & j==k:
                sum += gcd3(i,j,k)*3
                continue
            sum += gcd3(i,j,k)*6
print(sum)
### BUGGY CODE ###

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

for i in range(N):
  for a in A:
    if a == i + 1:
      count += 1
  print(count)
  count = 0
      

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
R = [0] * N

for i in A:
  R[i - 1] += 1

for i in range(N):
  print(R[i])
### BUGGY CODE ###

import bisect
import random

def test(L):
    lst = []
    N = len(L)
    for a in range(N):
        for b in range(a):
            for c in range(b):
                if L[a] < L[b] + L[c]:
                    lst.append((c, b, a))
    return lst

def test_len(L):
    return len(test(L))

def test2(L):
    return len(set((l[0], l[2]) for l in test(L)))

N = int(input())
L = sorted(map(int, input().split()))
# L = [1, 1, 1000]
# L = [218, 233, 389, 645, 704, 728, 786]
# N = 10
# L = sorted([random.randint(0, 1000) for _ in range(N)])
# L = [150, 190, 192, 281, 294, 374, 501, 686, 769, 954]
# print(L)
# N = len(L)
S = 0
for a in range(2, N):
    for b in range(1, a):
        c = bisect.bisect_left(L, L[a] - L[b])
        c = min(b - 1, c)
        # assert L[a] < L[b] + L[c] or c == 0, (c, b, a)
        while not(L[a] < L[b] + L[c]):
            c += 1
        assert L[a] < L[b] + L[c]
        if b <= c:
            continue
        else:
            S += b - c
# print(test_len(L))
print(S)

### FIXED CODE ###

import bisect
import random

def test(L):
    lst = []
    N = len(L)
    for a in range(N):
        for b in range(a):
            for c in range(b):
                if L[a] < L[b] + L[c]:
                    lst.append((c, b, a))
    return lst

def test_len(L):
    return len(test(L))

def test2(L):
    return len(set((l[0], l[2]) for l in test(L)))

N = int(input())
L = sorted(map(int, input().split()))
# L = [1, 1, 1000]
# L = [218, 233, 389, 645, 704, 728, 786]
# N = 10
# L = sorted([random.randint(0, 1000) for _ in range(N)])
# L = [150, 190, 192, 281, 294, 374, 501, 686, 769, 954]
# print(L)
# N = len(L)
S = 0
for a in range(2, N):
    c = bisect.bisect_left(L, (L[a] + 2) // 2)
    while c >= 0:
        if L[a] < L[c] * 2:
            c -= 1
        else:
            break
    b = c + 1
    assert L[a] < L[b] * 2
    if b == 0:
        # print("b0", b, a, (a - 1) * (a) // 2)
        S += (a - 1) * (a) // 2
        continue
    if c >= a - 1:
        continue
    assert L[a] < L[b] + L[b]
    assert L[a] >= L[c] + L[c], (a, c)
    S += (a - b) * (a - b - 1) // 2
    while c >= 0:
        while L[a] >= L[b] + L[c]:
            b += 1
        assert L[a] < L[b] + L[c]
        assert L[a] >= L[b - 1] + L[c]
        # print(c, b, a)
        S += a - b
        c -= 1
print(S)
# print(test_len(L))
### BUGGY CODE ###

import math

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

ans = 0

for i in range(N+1):
    ans=max(ans, math.floor(A*i/B)-A*math.floor(i/B))

print(ans)


### FIXED CODE ###

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

x = N

if (N >= B-1): x = B-1
ans = A*(x%B)//B

print(ans)
### BUGGY CODE ###

from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
res = 1
for i in range(1,n+1):
    res *= i%mod
print(res%mod) 

### FIXED CODE ###

from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

def main():
    n = inp()
    res = 1
    for i in range(1,n+1):
        res = res * i % mod
    print(res%mod) 
if __name__ == '__main__':
    main()
### BUGGY CODE ###

n,w=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]

dp=[[0]*(w+1) for _ in range(n+1)]
#dp:=i番目以降の商品から重さの総和がj以下となるように選んだ時の価値の総和の最大

#初期条件 dpｗｐ0で作ってるのでいらない
for j in range(w):dp[n][j] = 0

#漸化式
#dp[i][j] = dp[i+1][j] (j < w[i])
#           max(dp[i+1][j] , dp[i+1][j-w[i]]+v[i]) (otherwise)
for i in reversed(range(n)):
    for  j in range(w+1):
        if j < l[i][0]:
            dp[i][j] = dp[i+1][j]
        else:
            dp[i][j] = max(dp[i+1][j] , dp[i+1][j - l[i][0]] + l[i][1] )

print(dp[0][w])

### FIXED CODE ###

n,w=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]

dp=[[0]*(w+1) for _ in range(n+1)]
#dp:=i番目以降の商品から重さの総和がj以下となるように選んだ時の価値の総和の最大

#初期条件 dpｗｐ0で作ってるのでいらない
for j in range(w):dp[n][j] = 0

#漸化式
#dp[i][j] = dp[i+1][j] (j < w[i])
#           max(dp[i+1][j] , dp[i+1][j-w[i]]+v[i]) (otherwise)
for i in reversed(range(n)):
    for  j in range(w+1):
        if j < l[i][0]:
            dp[i][j] = dp[i+1][j]
        else:
            dp[i][j] = max(dp[i+1][j] , dp[i+1][j - l[i][0]] + l[i][1] )

print(dp[0][w])
### BUGGY CODE ###

import sys
import queue

input = sys.stdin.buffer.readline
INF = 10 ** 9

N = int(input())
path = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    path[a-1].append(b-1)
    path[b-1].append(a-1)

#find the longest path by trying BFS twice.
q = queue.Queue()
depth = [INF] * N
q.put(0)
depth[0] = 1
while not q.empty():
    node = q.get()
    for next_node in path[node]:
        if depth[next_node] > depth[node] + 1:
            depth[next_node] = depth[node] + 1
            q.put(next_node)

#The 'node' gives one end of the longest path.
q = queue.Queue()
depth = [INF] * N
q.put(node)
depth[node] = 1
while not q.empty():
    node = q.get()
    for next_node in path[node]:
        if depth[next_node] > depth[node] + 1:
            depth[next_node] = depth[node] + 1
            q.put(next_node)

length = depth[node]

if length % 3 == 2:
    print("Second")
else:
    print("First")

### FIXED CODE ###

import sys
import queue

input = sys.stdin.buffer.readline
INF = 10 ** 9

N = int(input())
path = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    path[a-1].append(b-1)
    path[b-1].append(a-1)

#find the longest path by trying BFS twice.
q = queue.Queue()
depth = [INF] * N
q.put(0)
depth[0] = 1
while not q.empty():
    node = q.get()
    for next_node in path[node]:
        if depth[next_node] > depth[node] + 1:
            depth[next_node] = depth[node] + 1
            q.put(next_node)

#The 'node' gives one end of the longest path.
q = queue.Queue()
depth = [INF] * N
q.put(node)
depth[node] = 1
while not q.empty():
    node = q.get()
    for next_node in path[node]:
        if depth[next_node] > depth[node] + 1:
            depth[next_node] = depth[node] + 1
            q.put(next_node)

length = depth[node]

if length % 3 == 2:
    print("Second")
else:
    print("First")
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(n):
    ans.append(a.index(i+1)+1)
print(" ".join([str(x) for x in ans]))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(n):
    ans.append([a[i], i+1])
ans.sort()
for i in ans:
    print(i[1], end=" ")
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)

def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    a.insert(0, 0)
    b.insert(0, 0)

    a_sum = [0]*(n+1)
    a_sum[0] = a[0]
    for i in range(1, n+1):
        a_sum[i] = a_sum[i-1] + a[i]

    b_sum = [0]*(m+1)
    b_sum[0] = b[0]
    for i in range(1, m+1):
        b_sum[i] = b_sum[i-1] + b[i]

    ans = 0
    for i_a in range(n+1):
        for j_b in range(m+1):
            if a_sum[i_a]+b_sum[j_b] <= k:
                ans = max(ans, i_a + j_b)
            else:
                break

    print(ans)
    return


if __name__ == "__main__":
    main()
    sys.exit(0)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    a.insert(0, 0)
    b.insert(0, 0)

    a_sum = [0]*(n+1)
    a_sum[0] = a[0]
    for i in range(1, n+1):
        a_sum[i] = a_sum[i-1] + a[i]

    b_sum = [0]*(m+1)
    b_sum[0] = b[0]
    for i in range(1, m+1):
        b_sum[i] = b_sum[i-1] + b[i]

    b_sum = b_sum[::-1]

    i_b = 0
    ans = 0
    for i_a in range(n+1):
        while i_b <= m:
            if k < a_sum[i_a] + b_sum[i_b]:
                i_b += 1
                continue
            else:
                ans = max(ans, i_a+(m-i_b))
                break

    print(ans)
    return


if __name__ == "__main__":
    main()
    sys.exit(0)
### BUGGY CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
#print(a)
#dist =[0]*n
d2 = []
cur = 1
d2.append(1)
st_idx = 0
rp_lgt = 0
for i in range(n):
  cur = a[cur-1]
  #dist[i] = cur
  #print(cur)
  for j in range(len(d2)):
    if cur == d2[j] :
      st_idx = j - 1 
      rp_lgt = i - j + 1
      #print(cur)
      break
  d2.append(cur)
wk = k - st_idx
md = wk % rp_lgt
if k < st_idx:
  ans = d2[k]
else:
  ans = d2[md+st_idx]
print(ans)


### FIXED CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
d2 = []
hist=[-1]*(n+1)
hist[0] = 0
cur = 1
d2.append(1)
st_idx = 0
rp_lgt = 1
for i in range(n):
  cur = a[cur-1]
  if hist[cur-1] >= 0 :
     d2.append(cur)
     st_idx = hist[cur-1]
     rp_lgt = i - st_idx + 1 
     break
  else:
    d2.append(cur)
    hist[cur-1] = i + 1
wk = k - st_idx
md = wk % rp_lgt
if k < st_idx:
  ans = d2[k]
else:
  ans = d2[md+st_idx]
print(ans)
### BUGGY CODE ###

n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
if n == 1:
    for _ in range(m):
        a[0] //= 2
    print(a[0])
else:
    while m > 0:
        for i in range(0,n-1):
            if a[i] < a[i+1]:
                tmp = a[i]
                a[i] = a[i+1]
                a[i+1] = tmp
            else:
                break
        while a[0] >= a[1] and m > 0:
            a[0] //= 2
            m -= 1
    print(sum(a))


### FIXED CODE ###

import heapq
n,m = map(int,input().split())
a = list(map(lambda x:int(x)*(-1),input().split()))

heapq.heapify(a)
for _ in range(m):
    val = heapq.heappop(a) * (-1)
    heapq.heappush(a, (val // 2) * (-1))
print(-sum(a))
### BUGGY CODE ###

N, M = [int(n) for n in input().split()]
A = sorted([int(n) for n in input().split()], reverse=True)
for _ in range(M):
    A[0] //= 2
    if len(A)!=1:
        if A[0] < A[1]:
            A = sorted(A, reverse=True)
print(sum(A))


### FIXED CODE ###

import heapq

N, M = [int(n) for n in input().split()]
A = [-1*int(n) for n in input().split()]
hq = []
[heapq.heappush(hq, v) for v in A]
for _ in range(M):
   heapq.heappush(hq, -1*(-1*heapq.heappop(hq)//2))
print(-1*sum(hq))
### BUGGY CODE ###

S = input()

rem = {}
rem[0] = 1

moji = ''
MOD = 2019
cnt = 0

for s in S[::-1]:
    moji = s + moji

    r = int(moji) % 2019
    if r in rem:
        cnt += rem[r]

    if r not in rem:
        rem[r] = 1
    else:
        rem[r] += 1

print(cnt)


### FIXED CODE ###

S = input()

num = 0

r_lst = [0] * 2019
r_lst[0] = 1
cnt = 0
for i, s in enumerate(S[::-1]):
    num = (num + pow(10, i, 2019) * int(s)) % 2019
    cnt += r_lst[num]

    r_lst[num] += 1


print(cnt)
### BUGGY CODE ###

from collections import deque
import copy
def solve(maze, start):
  memo = []
  q = deque()
  q.append([start,0])
  ans = 0
  while q:
    cur, cnt = q.popleft()
    if cur in memo:
      continue
    else:
      ans = max(ans, cnt)
      memo.append(cur)
      for y, x in zip((0,0,1,-1),(1,-1,0,0)):
        if maze[cur[0]+y][cur[1]+x] == ".":
          q.append([[cur[0]+y,cur[1]+x],cnt+1])
  return ans


H, W = map(int, input().split())
Maze = [["#"]*(W+2)]+[["#"]+list(input())+["#"] for _ in range(H)] + [["#"]*(W+2)]
Ans = 0
for sy in range(1, H+1):
  for sx in range(1, W+1):
    if Maze[sy][sx] == "#":
      continue
    else:
      Ans = max(Ans, solve(Maze, [sy, sx]))
print(Ans)

### FIXED CODE ###

H, W = map(int, input().split())
S = [input() for _ in range(H)]


def f(i, j):
    t = [[-1] * W for _ in range(H)]
    t[i][j] = 0
    q = [(i, j)]
    while q:
        y, x = q.pop(0)
        if y - 1 >= 0 and S[y - 1][x] != '#' and t[y - 1][x] == -1:
            t[y - 1][x] = t[y][x] + 1
            q.append((y - 1, x))
        if y + 1 < H and S[y + 1][x] != '#' and t[y + 1][x] == -1:
            t[y + 1][x] = t[y][x] + 1
            q.append((y + 1, x))
        if x - 1 >= 0 and S[y][x - 1] != '#' and t[y][x - 1] == -1:
            t[y][x - 1] = t[y][x] + 1
            q.append((y, x - 1))
        if x + 1 < W and S[y][x + 1] != '#' and t[y][x + 1] == -1:
            t[y][x + 1] = t[y][x] + 1
            q.append((y, x + 1))
    return max(max(tt) for tt in t)


result = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            result = max(result, f(i, j))
print(result)
### BUGGY CODE ###

from fractions import gcd
def lcm(a,b): return abs(a * b)/gcd(a,b) if a and b else 0

n = input()

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

from functools import reduce

mlcm = int(reduce(lcm, xs))

mlcm -= 1
print(sum([ mlcm%x for x in xs]))

### FIXED CODE ###

n = input()
xs = [int(x)-1 for x in input().split()]
print(sum(xs))
### BUGGY CODE ###

import sys

def dp_all(dp):
  length = len(dp)
  for i in range(length):
    print(dp[i])

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

a = []
b = []

for i in range(N):
  a_dash,b_dash = map(int,input().split())
  a.append(a_dash)
  b.append(b_dash)

#dp[i+1][j] = i番目までの魔法で体力jのモンスターに
#勝つことができる、魔力の最小値
INF = 10**9
dp = [[INF for _ in range(H+1)] for _ in range(N+1)]

for i in range(N+1):
  dp[i][0] = 0

for i in range(N):
  for j in range(H+1):
    if a[i] > j:
      dp[i+1][j] = min(dp[i][j],b[i])
    else:
      dp[i+1][j] = min(dp[i][j],dp[i+1][j-a[i]]+ b[i])

print(dp[N][H])


### FIXED CODE ###

import sys

def dp_all(dp):
  length = len(dp)
  for i in range(length):
    print(dp[i])

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

a = []
b = []

for i in range(N):
  a_dash,b_dash = map(int,input().split())
  a.append(a_dash)
  b.append(b_dash)

#dp[i+1][j] = i番目までの魔法で体力jのモンスターに
#勝つことができる、魔力の最小値
INF = 10**9
dp = [[INF for _ in range(H+1)] for _ in range(N+1)]

for i in range(N+1):
  dp[i][0] = 0

for i in range(N):
  for j in range(H+1):
    if a[i] > j:
      dp[i+1][j] = min(dp[i][j],b[i])
    else:
      dp[i+1][j] = min(dp[i][j],dp[i+1][j-a[i]]+ b[i])

print(dp[N][H])
### BUGGY CODE ###

sS = input().rstrip()
sT = input().rstrip()
iS = len(sS)
iT = len(sT)

dp = [[""]*(iT+1) for _ in range(iS+1)]

for i in range(iS):
    for j in range(iT):
        if sS[i] == sT[j]:
            dp[i+1][j+1] = dp[i][j] + sS[i]
        else:
            s1 = dp[i+1][j]
            s2 = dp[i][j+1]
            if len(s1) > len(s2):
                dp[i+1][j+1] = s1
            else:
                dp[i+1][j+1] = s2
print(dp[iS][iT])


### FIXED CODE ###

def 解():
    sS = input().rstrip()
    sT = input().rstrip()
    iS = len(sS)
    iT = len(sT)

    dp = [[0]*(iT+1) for _ in range(iS+1)]
    for i in range(iS):
        for j in range(iT):
            if sS[i] == sT[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])
    iC = dp[iS][iT]
    aR = [""]*iC
    i = iS
    j = iT
    while 0 < i and 0 < j:
        if sS[i-1] == sT[j-1]:
            aR[dp[i][j]-1]=sS[i-1]
            i -= 1
            j -= 1
        else:
            if dp[i][j] == dp[i][j-1] :
                j -= 1
            elif dp[i][j] == dp[i-1][j] :
                i -= 1
            else:
                break

    print("".join(aR))
    exit()

    def findS(i,j):
        iC = dp[i][j]
        if iC == 0 or aR[iC-1] != "":
            return False
        if dp[i][j] == dp[i-1][j] + 1 == dp[i][j-1] +1 :
            t = dp[i][j]
            aR[t-1] = sS[i-1]
            findS(i-1,j-1)
        else:
            findS(i-1,j)
            findS(i,j-1)
    findS(i,j)
    print("".join(aR))
解()
### BUGGY CODE ###

N=input()
A = list(map(int, input().split()))
T=True
sucl =[]
for i in range(0,int(N)):
  T=True
  for j in range(0,int(N)):
    if T== False:
      break
    if A[i]>=A[j]:
      if A[i] % A[j]==0:
        if i==j:
          pass
        else:
          T=False
  if T==True:
    sucl.append(i)
print(len(sucl))


### FIXED CODE ###

N = input()
A = list(map(int, input().split()))
N = int(N)
MA = max(A)
s=0
LS = [0 for i in range(0,MA)]
for i in range(0,N):
  k=1
  while A[i]*k<=MA:
    LS[A[i]*k-1] +=1
    k +=1
for j in range(0,N):
  if LS[A[j]-1]==1:
    s+=1
print(s)
### BUGGY CODE ###

tmp = input().split()
N = int(tmp[0])
M = int(tmp[1])

quiz_dict = {}
wa_dict = {}
 
for i in range(M):
  tmp = input().split()
  
  quiz = tmp[0]
  res = tmp[1]
  
  if quiz not in quiz_dict:
    quiz_dict[quiz] = 0
  
  if quiz not in wa_dict: 
    wa_dict[quiz] = 0
  
  if res == "AC":
    quiz_dict[quiz] = 1
  if res == "WA":
    if quiz_dict[quiz] == 0:
      wa_dict[quiz] += 1



tmp_list = [k for k, v in quiz_dict.items() if v > 0] 


def filter_dict(f, d):
  return {k:v for k,v in d.items() if f(k,v)}

a = len(filter_dict(lambda k,v: v==1, quiz_dict))
tmp = filter_dict(lambda k,v: k in tmp_list, wa_dict)
wa_n = sum(tmp.values())

print(a, wa_n)

### FIXED CODE ###

def main():
    N, M = map(int, input().split())
    ans = [False for _ in range(N)]
    wa_list = [0 for _ in range(N)]
    ac = 0
    wa = 0
    for _ in range(M):
        i, result = input().split()
        i = int(i)
        if result == "AC":
            if ans[i-1] == False:
                ac += 1
                ans[i - 1] = True
                wa += wa_list[i-1]
        else:
            if ans[i - 1] == False:
                wa_list[i - 1] += 1
    if sum(ans) == 0:
        wa = 0
    print(ac, wa)
    return 0
if __name__ == '__main__':
    main()