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

import numpy as np
H,W,K=map(int,input().split())
CO=np.array([[0]*W]*H)
DO=np.array([[0]*W]*H)
for i in range(H):
 C=input()
 for j in range(W):
  DO[i][j]=int(C[j])
F=1000000
for s in range(2**(H-1)):
 D=0
 E=0
 Sui=[0]*(H-1)
 for t in range(H-1):
  if ((s >> t) & 1):
   Sui[t]+=1
 for m in range(H-1):
  E+=Sui[m]
 CO[H-1]=DO[H-1]
 for k in range(H-1):
  if Sui[k]==0:
   CO[H-k-2]=DO[H-k-2]+CO[H-k-1]
   CO[H-k-1]=[0]*W
  else:
   CO[H-k-2]=DO[H-k-2]
 for h in range(W-1):
  if np.amax(CO[:,h])>K:
   E=1000000
   break
  elif np.amax(CO[:,h])<=K and np.amax(CO[:,h]+CO[:,h+1])>K:
   D+=1
  else:
   CO[:,h+1]=CO[:,h]+CO[:,h+1]
 if np.amax(CO[:,W-1])>K:
  E=1000000
 if D==0 and E==0:
  F=0
 elif E==0:
  continue
 else:
  F=min(F,D+E)
print(F)

### FIXED CODE ###

import sys
input = sys.stdin.readline
H,W,K=map(int,input().split())
CO=[[0 for i in [0]*W] for j in [0]*H]
DO=[[0 for i in [0]*W] for j in [0]*H]
for i in range(H):
 C=input()
 for j in range(W):
  DO[i][j]=int(C[j])
CO[H-1]=DO[H-1]
F=1000000
for s in range(2**(H-1)):
 D=0
 E=0
 Sui=[0]*(H-1)
 for t in range(H-1):
  if ((s >> t) & 1):
   Sui[t]+=1
 for m in range(H-1):
  E+=Sui[m]
 for k in range(H-1):
  if Sui[k]==0:
   for i in range(W):
    CO[H-k-2][i]=DO[H-k-2][i]+CO[H-k-1][i]
  else:
   for i in range(W):
    CO[H-k-2][i]=DO[H-k-2][i]
 lst=[0]*H
 for h in range(W):
  c=max(CO[x][h] for x in range(H))
  d=max(lst[y]+CO[y][h] for y in range(H))
  if c>K:
   E=1000000
   break
  elif d>K:
   D+=1
   lst=[0]*H
  for z in range(H):
   lst[z]+=CO[z][h]
 F=min(F,D+E)
print(F)
### BUGGY CODE ###

N = int(input())
ll = list(map(int, input().split(" ")))
# print(N)
# print(ll)


def ni(i):
    return int(bin(i)[2:])


for i in range(N):
    ll[i] = ni(ll[i])

# print(ll)

count = N
for i in range(N):
    for j in range(i+1, N):
        # print(i, j)
        sum_num = str(sum(ll[i:j+1]))
        # print(sum_num)
        if "2" not in sum_num:
            # print("yes")
            count += 1
        else:
            break

print(count)




### FIXED CODE ###

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

l, r = 0, 0
sum_a = 0
ans = 0
while r < n:
    # 右端を進める
    if sum_a & a[r] == 0:
        sum_a += a[r]
        r += 1
        ans += r - l
    # 右端と左端を進める
    elif l == r:
        l += 1
        r += 1
    # 左端を進める
    else:
        sum_a -= a[l]
        l += 1
    # print('l={}, r={}, size={}, ans={}, {}'.format(l, r, r - l, ans, a[l:r]))
print(ans)
### BUGGY CODE ###

n = int(input())
a = sorted(list(map(int, input().split())))

total = []
ans = 0
while(len(a)):
    a_min = a.pop(0)
    if len(a) == 0:
        total.append(a_min)
        break
    if a_min == a[0]:
       ans -= 1 
    a = [el for el in a if el % a_min != 0]
    total.append(a_min)
    
ans = ans + len(total)
print(ans)

### FIXED CODE ###

n = int(input())
a = sorted(list(map(int, input().split())))
max_a = a[-1]

q = [0] * (max_a + 1)
for i in a:
    if q[i] == 1 or q[i] == -1:
        q[i] = -1
        continue
    for j in range(2*i, max_a+1, i):
        q[j] = -1
    q[i] = 1

total = 0
for i in q:
    if i == 1:
        total += 1
print(total)
### BUGGY CODE ###

def solve():
  while True:
    n,m = map(int,input().split())
    if not n and not m: break
    lst = []
    lst2 = []
    lst = [int(input()) for _ in range(n)]
    lst.append(0)
    lst2 = [i + j for i in lst for j in lst if i <= j]
    #for i in lst:
    #  for j in lst:
    #    if i + j <= m:
    #      lst2.append(i + j)
    #lst2 = list(set(lst2 + lst))
    lst2.sort()
    def binary(x, left, right):
      center = (left + right) // 2
      length = right - left + 1
      v = lst2[center]
      if length == 1 or length == 2:
        if v > x:
          return center - 1
        else:
          return center
      elif v == x: return x
      elif v < x: return binary(x, center, right)
      elif v > x: return binary(x, left, center)
    A = []
    #ans = 0
    for i in lst2:
      if i + lst2[-1] <= m:
        A.append(i + lst2[-1])
        #ans = max(ans, i + lst2[-1])
      elif i <= m:
        A.append(i + lst2[binary(m - i, 0 , len(lst2) - 1)])
        #ans = max(ans, i + lst2[binary(m - i, 0, len(lst2) - 1)])
      else:
        break
    print(max(A))
    #print(ans)
solve()




### FIXED CODE ###

def solve():
  while True:
    n,m = map(int,input().split())
    if not n and not m: break
    
    lst = [int(input()) for _ in range(n)]
    lst.append(0)
    lst = sorted(lst)
    lst2 = [i + j for i in lst for j in lst if i <= j]
    lst2 = sorted(lst2)
    A = []
    index = len(lst2) - 1
    for i in lst2:
      if i + lst2[-1] <= m:
        A.append(i + lst2[-1])
      elif i <= m:
        while True:
          if i + lst2[index] <= m:
            break
          index -= 1
        A.append(i + lst2[index])
      else:
        break
    print(max(A))
solve()
### BUGGY CODE ###

import copy

S = input()

dp = [0] * 13

dp[0] = 1

mod = 10 ** 9 + 7
mul = 1
for i in range(len(S)-1, -1, -1):
    # 二次元dpの代わり
    ndp = [0] * 13
    
    if S[i] == '?':
        for k in range(10):
            for j in range(13):
                # 次の桁の余りが加わった時に、そこへ前のdp[j]の値を入れる
                # ただし、0-9までの値をその桁が取る可能性があるので、
                #　それぞれの場合全てを加算する
                ndp[(k * mul + j) % 13] += dp[j]
                ndp[(k * mul + j) % 13] %= mod
    else:
        k = int(S[i])
        for j in range(13):
            # 次の桁の余りが加わった時に、そこへ前のdp[j]の値を入れる
            ndp[(k * mul + j) % 13] += dp[j]
            ndp[(k * mul + j) % 13] %= mod

    mul *= 10
    mul %= 13
    dp = copy.deepcopy(ndp)

# 13で割って5で余るものを出力
print(dp[5])


### FIXED CODE ###

import copy

S = input()

dp = [0] * 13

dp[0] = 1

mod = 10 ** 9 + 7
mul = 1
for i in range(len(S)-1, -1, -1):
    # 二次元dpの代わり
    ndp = [0] * 13
    
    if S[i] == '?':
        for k in range(10):
            for j in range(13):
                # 次の桁の余りが加わった時に、そこへ前のdp[j]の値を入れる
                # ただし、0-9までの値をその桁が取る可能性があるので、
                #　それぞれの場合全てを加算する
                ndp[(k * mul + j) % 13] += dp[j]
                ndp[(k * mul + j) % 13] %= mod
    else:
        k = int(S[i])
        for j in range(13):
            # 次の桁の余りが加わった時に、そこへ前のdp[j]の値を入れる
            ndp[(k * mul + j) % 13] += dp[j]
            ndp[(k * mul + j) % 13] %= mod

    mul *= 10
    mul %= 13
    dp = copy.deepcopy(ndp)

# 13で割って5で余るものを出力
print(dp[5])
### BUGGY CODE ###

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

result = []
for i in range(1,n+1):
    result.append(a.index(i)+1)

print(*result)


### FIXED CODE ###

import numpy as np
n = int(input())
a = list(map(int,input().split()))

a = np.array(a)



print(*np.argsort(a)+1)
### BUGGY CODE ###

n,m = map(int,input().split())
py = []
od = [[]*1 for i in range(n)]

for i in range(0,m):
    p,y = map(int,input().split())
    py.append([p,y])
    od[p-1].append(y)

for i in range(0,n):
    od[i].sort()

for i in range(0,m):
    rank = od[py[i][0]-1].index(py[i][1]) + 1

    tmp = py[i][0]
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = py[i][0] // 10
    
    for j in range(6-digit):
        print('0',end="")
    print(py[i][0],end="")

    tmp = rank
    digit = 0
    while tmp > 0 :        
        digit += 1
        tmp = rank // 10
    
    for j in range(6-digit):
        print('0',end="")
    print(rank)


### FIXED CODE ###

import sys as sys

lines =  input().split()
n = int(lines[0])
m = int(lines[1])

py = []
od = {}

#lines = sys.stdin.readlines()

for i in range(0,m):


    #l =  lines[i].split()
    l = input().split()
    p = int(l[0])
    y = int(l[1])
    
    if p in od :
        od[p].append([i,y])
    else:
        od[p] = [[i,y]]

a = []
for p in od.keys():
    od[p].sort(key=lambda x:x[1])
    r = 1

    for o in od[p]:
        cs = ""

        tmp = p
        digit = 0
        while tmp > 0 :        
            digit += 1
            tmp = tmp // 10
        
        l = 6-digit
        for j in range(l):
            cs += '0'
        cs += str(p)

        tmp = r 
        digit = 0
        while tmp > 0 :        
            digit += 1
            tmp = tmp // 10

        l = 6-digit
        for j in range(l):
            cs += '0'
        cs += str(r)        

        a.append([o[0],cs])
        r += 1

a.sort(key=lambda x:x[0])
for aa in a:
    print(aa[1])
### BUGGY CODE ###

import sys
from collections import Counter
import random
import time
import math

def comb(n, r):
    return (math.factorial(n)//(math.factorial(n-r)*math.factorial(r)))

n=int(input())
a=list(map(int,input().split()))
S=[sum(a[:i])for i in range(n+1)]
C=Counter(S)

c=0
for k,v in C.items():
    if(v>1):c+=comb(v,2)
print(c)

### FIXED CODE ###

import sys
from collections import Counter
import random
import numpy as np
import time

n=int(input())
a=list(map(int,input().split()))
S=[0]
for i in range(n):
    S.append(S[i]+a[i])
    
S.sort()
c=0
ch=0
for i in range(len(S)-1):
    if(S[i]!=S[i+1]):
        ch+=1
        c+=(ch*(ch-1))//2
        ch=0
    else:ch+=1
if(ch!=0):
    ch+=1
    c+=(ch*(ch-1))//2
print(c)
### BUGGY CODE ###

import numpy as np
import sys
sys.setrecursionlimit(10000000)

N, M, P = map(int, input().split())
# ABC = [list(map(int, input().split())) for _ in range(M)]
ABC_d = {}
for m in range(M):
    A, B, C = map(int, input().split())
    if A in ABC_d:
        ABC_d[A].append([B, C - P])
    else:
        ABC_d[A] = [[B, C - P]]

# print (ABC_d)

cost = np.empty(N, dtype = int) - np.inf
cost[0] = 0

def solve(pos, already):
    global cost

    if not(pos in ABC_d): return
    # print (already)

    for B, C in ABC_d[pos]:
        if already[B - 1] == True:
            if cost[B - 1] == np.inf:
                pass
            elif cost[B - 1] < cost[pos - 1] + C:
                # looped = True
                cost[B - 1] = np.inf
                solve(B, already)
            # else:
            #     pass
        else:
            if cost[B - 1] < cost[pos - 1] + C:
                cost[B - 1] = cost[pos - 1] + C
                already2 = already.copy()
                already2[B - 1] = True
                solve(B, already2)
            # else:
            #     pass


already = np.zeros(N, dtype = bool)
already[0] = True
solve(1, already)

if (cost[-1] == np.inf):
    print (-1)
else:
    print (max(0, int(cost[-1])))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)

f_inf = sys.maxsize

N, M, P = map(int, input().split())
ABC_d = {}
for m in range(M):
    A, B, C = map(int, input().split())
    if A in ABC_d:
        ABC_d[A].append([B, C - P])
    else:
        ABC_d[A] = [[B, C - P]]

cost = [-f_inf] * N
cost[0] = 0

def solve(pos, cnt):
    global cost

    if not(pos in ABC_d): return
    if cnt > N: cost[pos-1] = f_inf;

    for B, C in ABC_d[pos]:
        if cost[B - 1] == f_inf or cost[B - 1] >= cost[pos - 1] + C:
            pass
        elif cost[pos-1] == f_inf:
            cost[B-1] = f_inf
            solve(B, cnt + 1)
        elif cost[B - 1] < cost[pos - 1] + C:
            cost[B - 1] = cost[pos - 1] + C
            solve(B, cnt + 1)

solve(1, 1)

if (cost[-1] == sys.maxsize):
    print (-1)
else:
    print (max(0, int(cost[-1])))
### BUGGY CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [-1]*n 
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)      
        if x==y:
            return        
        if self.par[x] > self.par[y]:
            x, y = y, x       
        self.par[x] += self.par[y]
        self.par[y] = x
    def size(self, x):
        return -self.par[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return len([i for i in range(self.n) if self.find(i) == root])
    def roots(self):
        return [i for i, x in enumerate(self.par) if x<0]

N, M = map(int, input().split())
UF = UnionFind(N)
for _ in range(M):
  a, b = map(int, input().split())
  UF.union(a-1, b-1)
Roots = UF.roots()
print(max(UF.members(R) for R in Roots))

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [-1]*n 
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)      
        if x==y:
            return        
        if self.par[x] > self.par[y]:
            x, y = y, x       
        self.par[x] += self.par[y]
        self.par[y] = x
    def size(self, x):
      if self.par[x]<0:
        return -self.par[x]
      else:
        return 0

N, M = map(int, input().split())
UF = UnionFind(N)
for _ in range(M):
  a, b = map(int, input().split())
  UF.union(a-1, b-1)
result = 0
for i in range(N):
  s = UF.size(i)
  if s>0:
    result = max(result, s)
print(result)
### BUGGY CODE ###

import collections

def intOrStr(a):
    try:
        return int(a)
    except:
        return str(a)

N = int(input())
S = list(input())
Q = int(input())
for _ in range(Q):
    Q1, Q2, Q3 = map(intOrStr, input().split())
    if Q1 == 1:
        S[Q2-1] = Q3
    else:
        print(len(collections.Counter(S[Q2-1: Q3])))

### FIXED CODE ###

import bisect

N = int(input())
S = list(str(input()))

def ordN(x):
  return ord(x) - ord('a')

li = [[] for _ in range(26)]
for i,s in enumerate(S):
  li[ordN(s)].append(i)

for i in range(int(input())):
  Q1, Q2, Q3 = input().split()
  if Q1 == "1":
    Q2 = int(Q2) - 1
    if S[Q2] != Q3:
      I = bisect.bisect_left(li[ordN(S[Q2])], Q2)
      li[ordN(S[Q2])].pop(I)
      bisect.insort(li[ordN(Q3)], Q2)
      S[Q2] = Q3
  else:
    Q2, Q3 = int(Q2)-1, int(Q3)-1
    count = 0
    for j in range(26):
      I = bisect.bisect_left(li[j], Q2)
      if I < len(li[j]) and li[j][I] <= Q3:
        count += 1
    print(count)
### BUGGY CODE ###

from collections import defaultdict
d = defaultdict(int)

N = int(input())
for _ in range(N):
  d[input()] += 1

for i in sorted([k for k, v in d.items() if v == max(d.values())]):
  print(i)


### FIXED CODE ###

import collections

N = int(input())
S = []
for _ in range(N):
  S += [input()]
d = collections.Counter(S).most_common()

for i in sorted([k for k, v in d if v == d[0][1]]):
  print(i)
### BUGGY CODE ###

from sys import stdin
# import bisect

sysin=stdin.readline

N,M,K=[int(x) for x in sysin().rstrip().split()]
a=[int(x) for x in sysin().rstrip().split()]
b=[int(x) for x in sysin().rstrip().split()]

# print(N+M,K)
# print(a)
# print(b)
# N,M=3,4
# K=240
# a=[60, 90, 120]
# b=[80, 150, 80, 150]

ans=0

accum_a=[0]
for i in a:
    _a=accum_a[-1]+i
    if _a>K:
        break
    else:
        accum_a.append(_a)
accum_a.append(K)

accum_b=[0]
for i in b:
    accum_b.append(accum_b[-1]+i)

ans=0

mountA=len(accum_a)-1

for j in range (mountA):
    Kb=K-accum_a[j]
    _accum_b=accum_b
    _accum_b.append(Kb)
    _accum_b.sort()
    bookb=_accum_b.index(Kb)-1
    if _accum_b.count(Kb)==2:
        bookb+=1
    if j+bookb>ans:
        ans=j+bookb

print(ans)


### FIXED CODE ###

import bisect


N,M,K=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

# print(K)
# print(a)
# print(b)
# N,M=3,4
# K=240
# a=[60, 90, 120]
# b=[80, 150, 80, 150]

ans=0

accum_a=[0]
for i in a:
    _a=accum_a[-1]+i
    if _a>K:
        break
    else:
        accum_a.append(_a)
accum_a.append(K)

accum_b=[0]
for i in b:
    accum_b.append(accum_b[-1]+i)

ans=0

for j in range (len(accum_a)-1):
    Kb=K-accum_a[j]
    bookB=bisect.bisect_right(accum_b,Kb)-1
    if j+bookB>ans:
        ans=j+bookB
    else:
        pass

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

n = int(input())
apple = list(map(int, input().split()))
cat = 1
for i in apple:
    cat *= i
print(cat if cat <= 10**18 else -1)

### FIXED CODE ###

n = int(input())
apple = list(map(int, input().split()))
if 0 in apple:
    print(0)
else:
    cat = 1
    for i in apple:
        cat *= i
        if cat > 10**18:
            break
        else:
            pass
    print(cat if cat <= 10**18 else -1)
### BUGGY CODE ###

from collections import deque

n = int(input())
li = deque(list(map(int,input().split())) for i in range(1,n+1))

cnt = 0
check = []
play = 0
tamel = []
s = 0

while play < n*(n-1) // 2:
    s = play
    for i in range(1,n+1):
        if i in check or len(li[i-1]) == 0:
            continue
        temp = li[i-1][0]
        if li[temp-1][0] == i:
            tamel.append(i-1)
            tamel.append(temp-1)
            play += 1
            check.append(temp)
    cnt += 1
    for i in tamel:
        del li[i][0]
    tamel = []
    check = []
    
    if s == play:
        print(-1)
        exit()

print(cnt)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
 
N = int(input())
A = [[-1] + [int(x)-1 for x in row.split()][::-1] for row in sys.stdin.readlines()]
 
A.append([-1])

def f(cand):
    cand1 = set()
    can_use = []
    for n in cand:
        if A[A[n][-1]][-1] == n:
            can_use.append(n)
    for n in can_use:
        A[n].pop()
        cand1.add(n)
        if A[n][-1] != -1:
            cand1.add(A[n][-1])
    return len(can_use), cand1
    
answer = 0
rest = N*(N-1)
cand = set(range(N))
while True:
    answer += 1
    x,cand = f(cand)
    if x == 0:
        answer = -1
        break
    rest -= x
    if rest == 0:
        break
    
print(answer)
### BUGGY CODE ###

def main():
    s = input()
    cnt = 0
    tmp = ""

    while tmp != s:
        tmp = s
        cnt += s.count("BW")
        s = s.replace("BW", "WB")

    print(cnt)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    s = input()
    length = len(s)-1
    count = s.count('B')
    init = sum([i for i in range(len(s)) if s[i] == "B"])
    processed = sum(range(length-count+1, length+1))

    print(processed-init)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def z_algo(S):
    N = len(S)
    A = [0] * N
    i = 1
    j = 0
    A[0] = l = len(S)
    while i < l:
        while i + j < l and S[j] == S[i + j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l - i > k < j - A[k]:
            A[i + k] = A[k]
            k += 1
        i += k
        j -= k

    ret = 0
    for i in range(1, N):
        ret = max(ret, min(A[i], i))

    return ret


def main():

    N = in_n()
    S = in_s()

    ans = 0
    for i in range(N):
        ans = max(ans, z_algo(S[i:]))

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def z_algo(S):
    N = len(S)
    A = [0] * N
    i = 1
    j = 0
    A[0] = l = len(S)
    while i < l:
        while i + j < l and S[j] == S[i + j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l - i > k < j - A[k]:
            A[i + k] = A[k]
            k += 1
        i += k
        j -= k

    ret = 0
    for i in range(1, N):
        ret = max(ret, min(A[i], i))

    return ret


def main():

    N = in_n()
    S = in_s()

    ans = 0
    for i in range(N):
        ans = max(ans, z_algo(S[i:]))

    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

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

dp = [0] * (W+1)
wv = [tuple(map(int, input().split())) for _ in range(N)]
for i in range(N):
    for j in range(W, wv[i][0]-1, -1):
        dp[j] = max(dp[j], dp[j-wv[i][0]]+wv[i][1])

print(dp[W])

### FIXED CODE ###

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

dp = [0] * (W+1)
for i in range(N):
    w, v = map(int, input().split())
    for j in range(W, w-1, -1):
        a = dp[j-w]+v
        if dp[j] < a:
            dp[j] = a

print(dp[W])
### BUGGY CODE ###

import sys
n,m = map(int,input().split())
d = []
a = 0
w = 0

if m == 0:
    print(0,0)
    sys.exit()
for i in range(m):
    p,s = input().split()
    if (p,"AC") not in d:
        d.append((p,s))
        if s == "AC":
            a +=1
        elif s == "WA":
            w += 1
print(a,w)

### FIXED CODE ###

n,m = map(int,input().split())
ps = [list(input().split()) for _ in range(m)]
aw = ["WA"] * n
wacnt = [0] * n
ac = 0
wa = 0
for i in ps:
    if aw[int(i[0])-1] == "WA":
        if i[1] == "AC":
            ac += 1
            wa += wacnt[int(i[0])-1]
            aw[int(i[0])-1] = "AC"
        else:
            wacnt[int(i[0])-1] += 1
    else:
        pass
print(ac,wa)
### BUGGY CODE ###

ss = input()
a,b,x = ss.split()
sum1 = 0
for i in range(int(a),int(b)+1):
    if int(i)%int(x)==0:
        sum1 += 1
print(sum1)

### FIXED CODE ###

ss = input()
a,b,x = ss.split()
ans = (int(b)//int(x)-(int(a)-1)//int(x))

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

import math
from functools import reduce

k = int(input())
ans = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for m in range(1, k+1):
            res =reduce(math.gcd, (i, j, m))
            ans += res
print(ans)

### FIXED CODE ###

from math import gcd

k = int(input())
res = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for m in range(1, k+1):
            res += gcd(gcd(i, j), m)

print(res)
### BUGGY CODE ###

import re
S = input()
#print(type(S))

s = []
for i in range(int(S) // 2019 // 5):
    s.append(str(i*2019))

count = 0
for i in s:
    S_ = S
    while re.search(i, S_):
        #print(i)
        S_ = S_[:re.search(i, S_).start()] + "," + S_[re.search(i, S_).start()+1:]
        count += 1
        
print(count)

### FIXED CODE ###

S = input()

n = len(S)
m = 2019

S_ = S[::-1]

x = 1
total = 0
modlis = [0 for i in range(m)]

ans = 0
for i in range(n):
    modlis[total] += 1
    #print("S_[i]:", S_[i])
    #print("int(S_[i])*x:", int(S_[i])*x)
    #print("total:", total)
    total += int(S_[i])*x
    #print("total:", total)
    total %= m
    #print("total:", total)
    ans += modlis[total]
    #print("x:", x)
    x = x * 10 % m
    #print("x:", x)

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

N, M = map(int, input().split())
a,b = [],[]
A, B = [],[]
X, Y = [],[]
for i in range(M):
    C, D = map(int, input().split())
    a.append(C)
    b.append(D)

for i in range(M):
    if a[i] == 1:
        A.append(a[i])
        B.append(b[i])
    elif b[i] == N:
        X.append(a[i])
        Y.append(b[i])

for i in range(len(X)):
    for j in range(len(A)): # 1
        if X[i] == B[j]: # N
            print("POSSIBLE")
            exit(0)
print("IMPOSSIBLE")

### FIXED CODE ###

N, M = map(int, input().split())
cnt = [0]*N
for i in range(M):
    A, B = map(int, input().split())
    if A == 1:
        cnt[B] += 1
    elif B == N:
        cnt[A] += 1

if 2 in cnt:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")