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

h, w, k = map(int, input().split())

choco = [[0] * w for _ in range(h)]

for i in range(h):
    s = input()
    for j in range(w):
        choco[i][j] = int(s[j])

ans = float("inf")
for bit in range(1 << (h - 1)):
    idx = [0] * h
    group = 0
    for i in range(h):
        idx[i] = group
        if (bit >> i) & 1:
            group += 1
    group += 1
    array = [[0] * w for _ in range(group)]
    for j in range(w):
        for i in range(h):
            array[idx[i]][j] += choco[i][j]

    cnt = group - 1
    cum = [0] * group
    canAdd = True
    for i in range(w):
        for j in range(group):
            if cum[j] > k:
                canAdd = False

        if canAdd is False:
            break

        for j in range(group):
            tmp = cum[j] + array[j][i]
            if tmp > k:
                cnt += 1
                for l in range(group):
                    cum[l] = array[l][i]
                break
            cum[j] += array[j][i]

    if canAdd:
        ans = min(ans, cnt)

print(ans)


### FIXED CODE ###

h, w, k = map(int, input().split())

choco = [[0] * w for _ in range(h)]

for i in range(h):
    s = input()
    for j in range(w):
        choco[i][j] = int(s[j])

ans = float("inf")
for bit in range(1 << (h - 1)):
    idx = [0] * h
    group = 0
    for i in range(h):
        idx[i] = group
        if (bit >> i) & 1:
            group += 1
    group += 1
    array = [[0] * w for _ in range(group)]
    for j in range(w):
        for i in range(h):
            array[idx[i]][j] += choco[i][j]

    cnt = group - 1
    cum = [0] * group
    canAdd = True
    for i in range(w):
        for j in range(group):
            if cum[j] > k:
                canAdd = False

        if ans <= cnt:
            canAdd = False

        if canAdd is False:
            break

        for j in range(group):
            tmp = cum[j] + array[j][i]
            if tmp > k:
                cnt += 1
                for l in range(group):
                    cum[l] = array[l][i]
                break
            cum[j] += array[j][i]

    if canAdd:
        ans = min(ans, cnt)

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

from bisect import bisect_left
n,m=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)
BC=[]
for _ in range(m):
    b,c=map(int,input().split())
    BC.append((b,c))
BC=sorted(BC, reverse=True, key=lambda x: x[1])

for i in range(m):
    b,c=BC[i]
    ind=bisect_left(A, c)
    x,y=min(ind, b), max(ind, b)
    A=A[x:y]+[c]*x+A[y:]
print(sum(A))

### FIXED CODE ###

import numpy as np
n,m=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)
A=np.array(A, dtype=np.int64)
BC=[]
for _ in range(m):
    b,c=map(int,input().split())
    BC.append((b,c))
BC=sorted(BC,reverse=True, key=lambda x:x[1])
D=[]
cnt=0
for i in range(m):
    b,c=BC[i]
    cnt+=b
    D+=[c]*b
    if cnt>=n:
        break
if cnt>=n:
    D=D[:n]
else:
    D+=[0]*(n-cnt)
D=np.array(D, dtype=np.int64)

A=np.maximum(A,D)
print(np.sum(A))
### BUGGY CODE ###

import math

N ,M, K = map(int,input().split())
MOD = 998244353
SUM = 0

POW = [1]

for i in range(1,N):
    a = (POW[-1] * (M-1))%MOD
    POW.append(a)

mole = 1
deno = 1
for i in range(K+1):
    if N -1 - i >= 0:
        SUM += M * POW[N-1-i] * mole * deno
        SUM %= MOD
        mole *= (N-1-i)
        deno *= pow(i+1,MOD-2,MOD)

print(SUM)

### FIXED CODE ###

import math

N ,M, K = map(int,input().split())
MOD = 998244353

def getInvs(n, MOD):
    invs = [1] * (n+1)
    for x in range(2, n+1):
        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
    return invs
invs = getInvs(N+3, MOD)

num = M
nums = []
for i in reversed(range(1,N)):
    nums.append(num)
    num *= i*(M-1)
    num *= invs[N-i]
    num %= MOD
nums.append(num)
nums.reverse()

ans = sum(nums[:K+1])
ans %= MOD
print(ans)
### BUGGY CODE ###

from collections import deque

n,m=map(int,input().split())
A=[int(input()) for _ in range(m)]
L=deque([1,1])
if 1 in A:L[1]=0
for i in range(2,n+1):
    if i in A:
        L.append(0)
    else:
        L.append(L[i-2]+L[i-1])
print(L[n]%(10**9 + 7))

### FIXED CODE ###

n,m=map(int,input().split())
A={int(input()) for _ in range(m)}
dp=[1]+[0]*(n+1)
for i in range(n):
    if i in A:
        continue
    dp[i+1] += dp[i]
    dp[i+2] += dp[i]
print(dp[n]%(10**9 + 7))
### BUGGY CODE ###

def main():
    N,M = map(int, input().split())
    A = list(map(int, input().split()))
    BC = sorted([list(map(int, input().split())) for _ in range(M)], reverse=True, key=lambda x:x[1])
    cnt = 0
    for B,C in BC:
        A += [C]*B
        cnt += B
        if B >= N:
            break
    A = sorted(A, reverse=True)
    print(sum(A[:N]))

main()

### FIXED CODE ###

n,m=map(int,input().split())
ans=list(map(int,input().split()))
arr=[list(map(int,input().split())) for _ in range(m)]
arr=sorted(arr,reverse=True,key=lambda x:x[1])
tmp=0
for cnt,val in arr:
  ans+=[val]*cnt
  tmp+=cnt
  if tmp>=n:
    break
ans=sorted(ans,reverse=True)
print(sum(ans[:n]))
### BUGGY CODE ###

N = int(input())
h = list(map(int, input().split()))
a = list(map(int, input().split()))

def base10to(n, b):
    if b <= n:
        return base10to(n//b, b) + str(n%b)
    return str(n%b)

num = 2**(len(base10to(N+1,2))+1)
seg = [0]*(2*num-1)

#update(i,x):Aiをxに更新する
def update(i,x):
    k = i + num - 1
    while k >= 0:
        seg[k] = max(x,seg[k])
        k = (k-1)//2

#query(a,b,0,0,num):[a,b)の最大値
def query(a,b,k,l,r):
    if r <= a or b <= l:
        return -1
    elif a <= l and r <= b:
        return seg[k]
    else:
        return max(query(a,b,2*k+1,l,(l+r)//2),query(a,b,2*k+2,(l+r)//2,r))


for i in range(N):
    update(h[i], query(0,h[i],0,0,num) + a[i])

print(query(0,N+2,0,0,num))

### FIXED CODE ###

N = int(input())
h = list(map(int, input().split()))
a = list(map(int, input().split()))

num = 2
while num <= N+1:
    num *= 2

seg = [0]*(2*num-1)

#update(i,x):Aiをxに更新する
def update(i,x):
    k = i + num - 1
    while k >= 0:
        seg[k] = max(x,seg[k])
        k = (k-1)//2

#query(a,b,0,0,num):[a,b)の最大値
def query(a,b,k,l,r):
    if r <= a or b <= l:
        return -1
    elif a <= l and r <= b:
        return seg[k]
    else:
        return max(query(a,b,2*k+1,l,(l+r)//2),query(a,b,2*k+2,(l+r)//2,r))


for i in range(N):
    update(h[i], query(0,h[i],0,0,num) + a[i])

print(max(seg))
### BUGGY CODE ###

def segfunc(x,y):
  return x+y

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)


N,Q = map(int,input().split())
A = list(map(int,input().split()))
Tree = SegmentTree(A, segfunc, 0)
for _ in range(Q):
  query, a,b = map(int,input().split())
  if query == 0:
    Tree.add(a,b)
  else:
    print(Tree.sum(a,b))


### FIXED CODE ###

def segfunc(x,y):
  return x+y

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)


N,Q = map(int,input().split())
A = list(map(int,input().split()))
Tree = SegmentTree(A, segfunc, 0)
for _ in range(Q):
  query, a,b = map(int,input().split())
  if query == 0:
    Tree.add(a,b)
  else:
    print(Tree.sum(a,b))
### BUGGY CODE ###

import math
step_n, max_jump = map(int, input().split())

step_list = list(map(int, input().split()))

dp_table = [math.inf] * (step_n)
dp_table[0] = 0

def jump_cost(step_a, step_b):
    return abs(step_list[step_a] - step_list[step_b])

for i in range(1, step_n):
    min_from = max(0, i - max_jump)
    min_cost = math.inf
    for j in range(min_from, i):
        cost = dp_table[j] + jump_cost(i, j)
        if min_cost > cost:
            min_cost = cost
    dp_table[i] = min_cost

print(dp_table[step_n-1])



### FIXED CODE ###

import math
step_n, max_jump = map(int, input().split())

step_list = list(map(int, input().split()))

dp_table = [math.inf] * (step_n)
dp_table[0] = 0

for i in range(1, step_n):
    min_from = max(0, i - max_jump)
    dp_table[i] = min(dp_table[j] + abs(step_list[i] - step_list[j]) for j in range(min_from, i))

print(dp_table[step_n-1])
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
for i in range(1,n+1):
  print(A.count(i))


### FIXED CODE ###

import collections

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

c = collections.Counter(A)

for i in range(1,n+1):
  print(c[i])
### BUGGY CODE ###

def calc(A,n,dp):
    if n==2:
        return A[0]+A[1]
    s=10**18
    for i in range(0,n-1):
        B=[]
        B=A[0:i]
        B.append(A[i]+A[i+1])
        B=B+A[i+2:]
        l=str(B)
        if l in dp:
            s=min(s,A[i]+A[i+1]+dp[l])
        else:
            d=calc(B,n-1,dp)
            s=min(s,A[i]+A[i+1]+d)
            dp[l]=d

    return s
n=int(input())
A=list(int(i) for i in input().split())
dp={}
print(calc(A,n,dp))
#for i in range(n):


### FIXED CODE ###

n=int(input())
A=list(int(i) for i in input().split())
prefixsum=[0 for i in range(n+1)]
for i in range(1,n+1):
    prefixsum[i]=A[i-1]+prefixsum[i-1]
#print(prefixsum)
dp=[[0 for i in range(n)] for j in range(n)]
for i in range(n-1,-1,-1):
    for j in range(i,n):
        #starting index i and ending j
        #finally we need to print first row last column
        #which represent the cost of all the elements
        if i==j:
            dp[i][j]=0
        else:
            dp[i][j]=10**18
            for k in range(i,j):
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+prefixsum[j+1]-prefixsum[i])
print(dp[0][-1])
### BUGGY CODE ###

import sys
import collections

input = sys.stdin.readline

H, W = map(int, input().split())
q = collections.deque()
grid = []
for i in range(H):
    grid.append(list(input().strip()))
    for j in range(W):
        if grid[i][j] == "#":
            q.append((i, j, 0))

maxc = 0
while q:
    i, j, c = q.popleft()
    if maxc < c:
        maxc = c
    if i > 0 and grid[i - 1][j] == ".":
        q.append((i - 1, j, c + 1))
        grid[i - 1][j] = "#"
    if i < H - 1 and grid[i + 1][j] == ".":
        q.append((i + 1, j, c + 1))
        grid[i + 1][j] = "#"
    if j > 0 and grid[i][j - 1] == ".":
        q.append((i, j - 1, c + 1))
        grid[i][j - 1] = "#"
    if j < W - 1 and grid[i][j + 1] == ".":
        q.append((i, j + 1, c + 1))
        grid[i][j + 1] = "#"

print(maxc)


### FIXED CODE ###

import sys
import collections

input = sys.stdin.readline

H, W = map(int, input().split())
q = collections.deque()
grid = []
for i in range(H):
    grid.append(list(input().strip()))
    for j in range(W):
        if grid[i][j] == "#":
            q.append((i, j, 0))

maxc = 0
while q:
    i, j, c = q.popleft()
    if maxc < c:
        maxc = c
    if i > 0 and grid[i - 1][j] == ".":
        q.append((i - 1, j, c + 1))
        grid[i - 1][j] = "#"
    if i < H - 1 and grid[i + 1][j] == ".":
        q.append((i + 1, j, c + 1))
        grid[i + 1][j] = "#"
    if j > 0 and grid[i][j - 1] == ".":
        q.append((i, j - 1, c + 1))
        grid[i][j - 1] = "#"
    if j < W - 1 and grid[i][j + 1] == ".":
        q.append((i, j + 1, c + 1))
        grid[i][j + 1] = "#"

print(maxc)
### BUGGY CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))
from itertools import accumulate
def update(a):
    ret=[0]*len(a)
    for i,x in enumerate(a):
        ret[max(i-x,0)]+=1
        r=min(n-1,i+x)
        if r==n-1:continue
        ret[r+1]-=1
    return list(accumulate(ret))
for i in range(min(50,k)):
    l=update(l)
print(*l)

### FIXED CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))
from itertools import accumulate
def update(a):
    ret=[0]*len(a)
    for i,x in enumerate(a):
        ret[max(i-x,0)]+=1
        r=min(n-1,i+x)
        if r==n-1:continue
        ret[r+1]-=1
    return list(accumulate(ret))
for i in range(min(50,k)):
    l=update(l)
print(*l)
### BUGGY CODE ###

import numpy as np

N = int(input())

P = [int(i) for i in input().split()]

loop_max = P.index(np.min(P))

count = 0
for i in range(loop_max+1):
    if P[i] == np.min(P[:i+1]):
        count += 1
print(count)

### FIXED CODE ###

import numpy as np

N = int(input())

P = [int(i) for i in input().split()]

minimum = P[0]
count = 1
for i in range(1, N):
    if P[i] <= minimum:
        count += 1
        minimum = P[i]

print(count)
### BUGGY CODE ###

n, *a = map(int, open(0).read().split())
ans = 1
for i in a:
    ans *= i
print(ans if ans <= 10**18 else -1)

### FIXED CODE ###

n, *a = map(int, open(0).read().split())
ans = 1
if 0 in a:
    ans = 0
else:
    for i in a:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
print(ans)
### BUGGY CODE ###

n = int(input())
s = str(input())

res = 0
for i in range(1000):
    t = str(i).zfill(3)
    pos = 0
    for j in s:
        if t[pos] == j:
            pos += 1
        if pos == 3:
            res += 1
            break

print(res)


### FIXED CODE ###

n = int(input())
s = input()
ans = 0
for i in range(1000):
    t = str(i).zfill(3)
    ti = 0
    for j in range(n):
        if s[j] == t[ti]:
            ti += 1
            if ti == 3:
                break
    if ti == 3:
        ans += 1
print(ans)
### BUGGY CODE ###

N,M,Q = map(int,input().split())
data = [0]*Q
for i in range(Q): data[i] = list(map(int,input().split()))

a = []
def gen_a(n,ai,cur):
    if n==0:
        for k in range(1,M+1):
            if k==10:
                k = "a"
                gen_a(1,10,str(k))
            else:
                gen_a(1,k,str(k))
    elif n==N:
        ar = list(cur)
        if ar[-1] == "a": ar[-1] = "10"
        a.append(ar)
    else:
        for k in range(ai,M+1):
            if k == 10:
                k = "a"
                gen_a(n+1,10,cur+str(k))
            else: 
                gen_a(n+1,k,cur+str(k))

gen_a(0,1,0)

ans = 0
for a_item in a:
    cnt = 0
    for d_item in data:
        nb = int(a_item[d_item[1]-1]) if a_item[d_item[1]-1] != "a" else 10
        na = int(a_item[d_item[0]-1]) if a_item[d_item[0]-1] != "a" else 10
        if nb - na == d_item[2]:
            cnt += d_item[3]
    if ans < cnt:
        ans = cnt

print(ans)

### FIXED CODE ###

N,M,Q = map(int,input().split())
data = [0]*Q
for i in range(Q): data[i] = list(map(int,input().split()))

a = []
def gen_a(n,ai,cur):
    if n==0:
        for k in range(1,M+1):
            if k==10:
                k = "a"
                gen_a(1,10,str(k))
            else:
                gen_a(1,k,str(k))
    elif n==N:
        ar = list(cur)
        if ar[-1] == "a": ar[-1] = "10"
        a.append(ar)
    else:
        for k in range(ai,M+1):
            if k == 10:
                k = "a"
                gen_a(n+1,10,cur+str(k))
            else: 
                gen_a(n+1,k,cur+str(k))

gen_a(0,1,0)

ans = 0
for a_item in a:
    cnt = 0
    for d_item in data:
        nb = int(a_item[d_item[1]-1]) if a_item[d_item[1]-1] != "a" else 10
        na = int(a_item[d_item[0]-1]) if a_item[d_item[0]-1] != "a" else 10
        if nb - na == d_item[2]:
            cnt += d_item[3]
    if ans < cnt:
        ans = cnt

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

n=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(n):
    B.append(A.index(min(A))+1)
    A[A.index(min(A))]=n+1
print(*B)

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
B=[0]*n
for i in range(n):
    B[A[i]-1]=i+1
print(*B)
### BUGGY CODE ###

n,k = map(int,input().split())
h = []
for i in range(n):
    h.append(int(input()))
h.sort()
h_max = 0
h_min = 0
r = 0
ans = []
#print(h)
for i in range(r,n-k+1):
    if n - r < k: 
        break
    h_max = max(h[r:k+r])
    #print(h[r:k])
    h_min = min(h[r:k+r])
    ans.append(h_max - h_min)
    r += 1
print(min(ans))


### FIXED CODE ###

n,k = map(int,input().split())
h = []
for i in range(n):
    h.append(int(input()))
h.sort()
h_max = 0
h_min = 0
r = 0
ans = []
#print(h)
for i in range(r,n-k+1):
    if n - r < k: 
        break
    h_max = h[r+k-1]
    #print(h[r:k])
    h_min = h[r]
    ans.append(h_max - h_min)
    r += 1
print(min(ans))
### BUGGY CODE ###

s = input()

if s == s[::-1]:
    print(0)
    exit()

t = []

for i in range(len(s)):
    if s[i] != 'x':
        t.append(s[i])

if t != t[::-1]:
    print(-1)
    exit()

central_char = t[len(t)//2]

s = list(s)
s.insert(0, '*')
s.append('*')

central_position = 0

for i in range(len(s)):
    if s[i] == central_char:
        central_position = i

left = central_position - 1
right = central_position + 1
x_cnt = 0

while left > 0 or right < len(s)-1:
    if s[max(0, left)] == s[min(len(s)-1, right)]:
        left -= 1
        right += 1
    else:
        x_cnt += 1
        if s[max(0, left)] == 'x':
            left -= 1
        else:
            right += 1

print(x_cnt)

### FIXED CODE ###

s = input()

left = 0
right = len(s) - 1
x_cnt = 0

while left < right:
    if s[left] == s[right]:
        left += 1
        right -= 1
    else:
        if s[left] == 'x':
            x_cnt += 1
            left += 1
        elif s[right] == 'x':
            x_cnt += 1
            right -= 1
        else:
            print(-1)
            exit()

print(x_cnt)
### BUGGY CODE ###

import collections
h,w = map(int,input().split())
q = collections.deque()
ans = 0
A = []
for i in range(h):
    s = input()
    L = []
    for j in range(w):
        L.append(s[j])
        if s[j] == '#':
            q.append([i,j])
    A.append(L)
dy_dx = [[1,0],[0,1],[-1,0],[0,-1]]
t = len(q)
while len(q) > 0:
    cur = q.popleft()
    for i in range(4):
        y = cur[0]+dy_dx[i][0]
        x = cur[1]+dy_dx[i][1]
        if 0 <= y < h and 0 <= x < w:
            if A[y][x] == '.':
                A[y][x] = '#'
                q.append([y,x])
    if t > 0:
        t -= 1
    else:
        t = len(q)
        ans += 1
print(ans)

### FIXED CODE ###

import collections
h,w = map(int,input().split())
q = collections.deque()
A = []
for i in range(h):
    s = input()
    L = []
    for j in range(w):
        if s[j] == '.':
            L.append(s[j])
        else:
            L.append(0)
            q.append([i,j])
    A.append(L)
dy_dx = [[1,0],[0,1],[-1,0],[0,-1]]
while len(q) > 0:
    cur = q.popleft()
    for i in range(4):
        y = cur[0]+dy_dx[i][0]
        x = cur[1]+dy_dx[i][1]
        if 0 <= y < h and 0 <= x < w:
            if A[y][x] == '.':
                A[y][x] = A[cur[0]][cur[1]]+1
                q.append([y,x])
ans = 0
for i in range(h):
    for j in range(w):
        if ans < A[i][j]:
            ans = A[i][j]
print(ans)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
N=int(input())
C=[int(input()) for i in range(N)]
C=[C[i] for i in range(N) if i ==0 or C[i-1]!=C[i]]

import collections
table=collections.defaultdict(list)
N=len(C)
dp=[0]*(N+1)
dp[N]=1
mod=10**9 + 7
for i,x in enumerate(C[::-1]):
  dp[N-1-i]=dp[N-i]
  for y in table[x]:
    dp[N-1-i]+=dp[y+1]
  dp[N-1-i]%=mod
  table[x].append(N-1-i)

print(dp[0])

### FIXED CODE ###

import sys
input=sys.stdin.readline
N=int(input())
C=[int(input())]
for i in range(N-1):
  tmp=int(input())
  if tmp != C[-1]:
    C.append(tmp)
  
import collections
table=collections.defaultdict(int)
N=len(C)
dp=[0]*(N+1)
dp[N]=1
mod=10**9 + 7
for i,x in enumerate(C[::-1]):
  dp[N-1-i]=dp[N-i] + table[x] 
  dp[N-1-i]%=mod
  table[x]+=dp[N-i]
print(dp[0])
### BUGGY CODE ###

N, M = list(map(int, input().split()))
P = []
S = []


def f(s):
  lst = s.split()
  return int(lst[0]),lst[1]

for i in range(M):
  p, s = f(input())
  P.append(p)
  S.append(s)

correct = 0
penalty = 0
q = []
p = []

for i, j in enumerate(S):
  if 'AC' in j:
    if P[i] not in q:
      q.append(P[i])
      correct += 1
    else:
      continue
  if 'WA' in j:
    p.append(P[i])
    if P[i] not in q:
        penalty += 1
    else:
      continue
for i in range(len(p)):
  if p[i] not in q:
    penalty -= 1

print(correct, penalty)

### FIXED CODE ###


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

isAC = [0] * (N+1)
isWA = [0] * (N+1)

ACnum = 0
WAnum = 0

for _ in range(M):
    p, s = input().split()
    p = int(p)

    if isAC[p] == 1: continue
    if s == 'AC':
        isAC[p] = 1
        ACnum += 1
        WAnum += isWA[p]
    elif s == 'WA':
        isWA[p] += 1

print("%d %d"%(ACnum, WAnum))
### BUGGY CODE ###

N = 2019
cnt = [0] * N
S = input()
ans = 0
for s in S:
    s = int(s)
    new = [0] * N
    for n in range(N):
        idx = (10 * n + s) % N
        new[idx] += cnt[n]
    cnt = new
    cnt[s] += 1
    ans += cnt[0]

print(ans)


### FIXED CODE ###

N = 2019
cnt = [0] * N
S = input()
ans = 0
for s in S:
    s = int(s)
    new = [0] * N
    for n in range(N):
        idx = (10 * n + s) % N
        new[idx] += cnt[n]
    cnt = new
    cnt[s] += 1
    ans += cnt[0]

print(ans)