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

H,W,M=map(int,input().split())
tgts=set()
for _ in range(M):
    i,j=map(int,input().split())
    tgts.add((i,j))

rows=[0]*(H+1)
cols=[0]*(W+1)

for i,j in tgts:
    rows[i]+=1
    cols[j]+=1

ii=max(rows)
jj=max(cols)

ia=[i for i in range(H+1) if rows[i]==ii]
ja=[j for j in range(W+1) if cols[j]==jj]

ans=0
for i in ia:
    for j in ja:
        k=rows[i]+cols[j]
        if (i,j) in tgts:
            k-=1
        ans=max(ans,k)

print(ans)


### FIXED CODE ###

from collections import defaultdict as ddict

ii=jj=0
ia,ja=[],[]
rows=ddict(int)
cols=ddict(int)
H,W,M=map(int,input().split())
tgts=set()
for _ in range(M):
    i,j=map(int,input().split())
    tgts.add((i,j))

    rows[i]+=1
    cols[j]+=1
    x=rows[i]
    if x>ii:
        ii=x
        ia=[i]
    elif x==ii:
        ia.append(i)
    y=cols[j]
    if y>jj:
        jj=y
        ja=[j]
    elif y==jj:
        ja.append(j)



ans=0
for i in ia:
    for j in ja:
        k=rows[i]+cols[j]
        if (i,j) in tgts:
            k-=1
        else:
            ans=k
            break
        ans=max(ans,k)

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

#!/usr/bin/env python


def pow(m, n):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return (pow(m, int(n / 2)) ** 2) % mod
    elif n % 2 == 1:
        return (pow(m, int((n - 1) * 0.5)) ** 2 * m) % mod


def conb(n, a):
    mod1 = 1
    mod2 = 1
    for i in range(a):
        mod1 *= n - i
        mod2 *= i + 1
    mod2 = pow(mod2, mod - 2)
    return (mod1 * mod2) % mod


n, a, b = (int(val) for val in input().split())


ans = 1
noa = 1
nob = 1
mod = 1000000007
ans = pow(2, n) - 1 - conb(n, a) - conb(n, b)
ans %= mod
print(ans)


### FIXED CODE ###

#!/usr/bin/env python


def pow(m, n):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return (pow(m, int(n / 2)) ** 2) % mod
    elif n % 2 == 1:
        return (pow(m, int((n - 1) * 0.5)) ** 2 * m) % mod


def conb(n, a):
    mod1 = 1
    mod2 = 1
    for i in range(a):
        mod1 *= n - i
        mod1 %= mod
        mod2 *= i + 1
        mod2 %= mod
    mod2 = pow(mod2, mod - 2)
    return (mod1 * mod2) % mod


n, a, b = (int(val) for val in input().split())


ans = 1
noa = 1
nob = 1
mod = 1000000007
ans = pow(2, n) - 1 - conb(n, a) - conb(n, b)
ans %= mod
print(ans)
### BUGGY CODE ###

x=int(input())
for i in range(x+1):
  for j in range(-abs(i)-1,x+1):
    a=i
    b=j
    if a**5-b**5==x:
      break
  else:
    continue
  break
print(a,b)

### FIXED CODE ###

x=int(input())
for a in range(150):
  for b in range(-150,150):
    if a**5-b**5==x:
      print(a,b)
      break
  else:
    continue
  break
### BUGGY CODE ###

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

B=[]
for a in A:
  B.append(a)
  B=B[::-1]
print(" ".join(map(str,B)))

### FIXED CODE ###

import collections

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

B=collections.deque([])
for i in range(N):
  if i%2==0:
    B.append(A[i])
  else:
    B.appendleft(A[i])
#print(B)
B=list(B)
#print(B)
if N%2==1:
  B=B[::-1]

print(" ".join(map(str,B)))
### BUGGY CODE ###

def prime_factorize(n):
    '''prime_factorize(12) → [2,2,3]
    '''
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())
A = list(map(int, input().split()))
from collections import Counter
c = Counter(A)
sorted_key = sorted(c.keys(),reverse=True)
res = [0]*len(sorted_key)
#print(sorted_key)
for i,key in enumerate(sorted_key):
    for j in range(i+1,len(sorted_key)):
        #print(i,key,j,sorted_key[j])
        if (key/sorted_key[j]>=1) and (key%sorted_key[j])==0:
            res[i] = 1
            #print('===========',)
            break

#print('res', res)
#print(c)
ans = 0
for i,v in enumerate(sorted_key):
    if res[i]:
        ans += c[v]
    else:
        if c[v] >1:
            ans += c[v]
print(n-ans)

### FIXED CODE ###

n = int(input())
A = sorted(list(map(int, input().split())))
from collections import Counter
c = Counter(A)

dp = [1]*(max(A)+1)
#print(dp)
for i in c.keys():
    j = i*2
    while j<len(dp):
        dp[j] = 0
        j += i
        #print(j, end=',')
ans = 0
for i in c.keys():
    if c[i] == 1:
        if dp[i] == 1:
            ans += 1
print(ans)
### BUGGY CODE ###

n, m = map(int, input().split())
data = list(map(int, input().split()))
for i in range(m):
    choice_time, num = map(int, input().split())
    for j in range(choice_time):
        if num > min(data):
            data[ data.index( min(data) ) ] = num
    
print(sum(data))


### FIXED CODE ###

n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in range(m)]
b.sort(key=lambda q: -q[1])
 
c = 0
for s in b:
	for t in [0]*s[0]:
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
	else:
		continue
	break
print(sum(a))
### BUGGY CODE ###

N, M = list(map(int, input().split()))
ABs = [0] * N

for i in range(N):
    a, b = list(map(int, input().split()))
    ABs[i] = (a, b)

ABs = sorted(ABs, reverse=True, key=lambda x: x[1])

dic = {}
for i in range(M + 1):
    dic[i] = -1

for AB in ABs:
    day, reward = AB
    if day <= M:
        r = dic[day]
        if r == -1:
            dic[day] = reward
        else:
            for i in range(day, M + 1):
                r = dic[i]
                if r == -1:
                    dic[i] = reward
                    break
result = 0
for i in range(M + 1):
    v = dic[i]
    if v != -1:
        result += v
print(result)

### FIXED CODE ###

N, M = list(map(int, input().split()))
ABs = [0] * N
day_dic = {}

for i in range(N):
    ABs[i] = list(map(int, input().split()))

ABs = sorted(ABs, reverse=True, key=lambda x: x[1])

rewards = [0] * (M + 1)

count = 0
for AB in ABs:
    day, reward = AB
    if day <= M:
        if rewards[day] == 0:
            rewards[day] = reward
            day_dic[day] = day
            count += 1
        else:
            esti = day_dic.get(day)
            if esti is None:
                esti = day
            for i in range(esti, M + 1):
                if rewards[i] == 0:
                    rewards[i] = reward
                    day_dic[day] = i
                    count += 1
                    break
    if count == M:
        break

result = sum(rewards)
print(result)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
def ta():
  l = A[0]
  A.pop(0)
  co = 0
  for s in range(1,N+1):
    t = A.count(s)
    if t >= 2:
      co += t*(t-1)/2
    else:
      co += 0
  A.append(l)
  return co
  
for k in range(1,N+1):
  print(int(ta()))

### FIXED CODE ###

from collections import deque
N = int(input())
A = list(map(int,input().split()))
balls = [[] for _ in range(N+1)]
for i in range(N):
  balls[A[i]].append(i)
  
K = 0  
for i in range(N+1):
  if len(balls[i]) < 2:
    continue
  else:
    u = len(balls[i])
    K += int(u*(u-1)/2)
  
t = 0
q = deque()
for i in range(N):
  s = A[i]
  a = len(balls[s])
  if a >=2:
    d = a-1
  else:
    d = 0
  q.append(K-d)


while q:
  v = q.popleft()
  print(v)
### BUGGY CODE ###

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

def main():
    N=int(input())  #数値入力 「N」だけの入力のとき
    H=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
    ans = 0
    a = 0
    for i in range(N):
        a = 0
        if ans > N-i-1:
            break
        else:
            for j in range(N-i):
                if i+j == N-1:
                    if a > ans:
                        ans = a
                    break
                elif H[i+j] >= H[i+j+1]:
                    a += 1
                else:
                    if a > ans:
                        ans = a
                    break
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

N = int(input())
H = [int(x) for x in input().split()]
ans = 0
cnt = 0
for ind,i in enumerate(H[:-1]):
    if(i>=H[ind+1]):
        cnt += 1
    else:
        cnt = 0
    ans = max(ans,cnt)
print(ans)
### BUGGY CODE ###

from itertools import accumulate

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

Bs = sorted(As)
M = N*(N+1)//2

def isOK(mid):
    Am = Bs[mid]
    Ss = [1 if A >= Am else -1 for A in As]
    Ss = list(accumulate([0]+Ss))

    def makeBIT(numEle):
        numPow2 = 2 ** (numEle-1).bit_length()
        data = [0] * (numPow2+1)
        return data, numPow2
    def addValue(iA, A):
        iB = iA + 1
        while iB <= numPow2:
            data[iB] += A
            iB += iB & -iB
    def getSum(iA):
        iB = iA + 1
        ans = 0
        while iB > 0:
            ans += data[iB]
            iB -= iB & -iB
        return ans

    data, numPow2 = makeBIT(N+1)
    iSs = list(range(N+1))
    iSs.sort(key=lambda iS: Ss[iS])
    odrSs = [0]*(N+1)
    for odrS, iS in enumerate(iSs):
        odrSs[iS] = odrS

    num = 0
    for odrS in odrSs:
        num += getSum(odrS)
        addValue(odrS, 1)
    return num >= (M+1)//2


ng, ok = N, -1
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(Bs[ok])


### FIXED CODE ###

from itertools import accumulate

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

Bs = sorted(As)
M = N*(N+1)//2

def isOK(mid):
    Am = Bs[mid]
    Ss = [1 if A >= Am else -1 for A in As]
    Ss = list(accumulate([0]+Ss))

    def makeBIT(numEle):
        numPow2 = 2 ** (numEle-1).bit_length()
        data = [0] * (numPow2+1)
        return data, numPow2
    def addValue(iA, A):
        iB = iA + 1
        while iB <= numPow2:
            data[iB] += A
            iB += iB & -iB
    def getSum(iA):
        iB = iA + 1
        ans = 0
        while iB > 0:
            ans += data[iB]
            iB -= iB & -iB
        return ans

    data, numPow2 = makeBIT(N+1)
    iSs = list(range(N+1))
    iSs.sort(key=lambda iS: Ss[iS])
    odrSs = [0]*(N+1)
    for odrS, iS in enumerate(iSs):
        odrSs[iS] = odrS

    num = 0
    for odrS in odrSs:
        num += getSum(odrS)
        addValue(odrS, 1)
    return num >= (M+1)//2


ng, ok = N, -1
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(Bs[ok])
### BUGGY CODE ###

n,k = map(int, input().split())
a = list(map(int, input().split()))
event = []
data = [0 for _ in range(n+1)]
for i in range(k):
    data = [0 for _ in range(n + 1)]
    for i in range(n):
        data[max(0,i-a[i])] += 1
        data[min(n,i+a[i]+1)] -= 1

    for i in range(n):
        data[i+1] += data[i]

    a = data
print(*a[:n])

### FIXED CODE ###

n,k = map(int, input().split())
a = list(map(int, input().split()))
event = []
for i in range(k):
    data = [0 for _ in range(n + 1)]
    for i in range(n):
        data[max(0,i-a[i])] += 1
        data[min(n,i+a[i]+1)] -= 1

    for i in range(n):
        data[i+1] += data[i]
    check = True
    for i in range(n):
        if data[i] != n:
            check = False
            break
    if check:
        print(*data[:n])
        exit()
    a = data
print(*a[:n])
### BUGGY CODE ###

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

a.sort()

for i in range(m):
    x = a.pop()
    x = x / 2
    bisect.insort(a, x)



print(sum(map(int, a)))


### FIXED CODE ###

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

heap = []
for i in a:
    heapq.heappush(heap, -i)


for i in range(m):
    x = - heapq.heappop(heap)
    x = x / 2
    heapq.heappush(heap, - x)



print(sum(map(lambda n: int (-n), heap)))
### BUGGY CODE ###

def main():
    n = int(input())
    arr = list(map(int, input().split()))

    i = 0
    count = 0

    while i < n:
        count += judge(i, arr, n)
        i += 1

    print(count)


def judge(i, arr, n):
    for j in range(n):
        if i != j:
            if arr[i] % arr[j] == 0:
                return 0
    return 1


main()

### FIXED CODE ###

n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
m = arr[-1]
li = [0]*(m+1)
cnt = 0
        
for i in arr:
  for j in range(i, m+1, i):
    li[j] += 1

for i in arr:
  if li[i] == 1:
    cnt += 1

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

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

def binary_search(arr, x):
    start = 0
    end = len(arr)-1
    while True:
        mid = int(start + (end-start)/2)
        if x > arr[mid]:
            start = mid + 1
        elif x < arr[mid]:
            end = mid -1
        else:
            break
    return mid + 1
for i in range(N):
    print(binary_search(H,i+1))


### FIXED CODE ###

N= int(input())
H = [int(i) for i in input().split( )]
J = [0]*N
for i in range(N):
    J[H[i]-1] = i
for j in range(N):
    print(J[j]+1)
### BUGGY CODE ###

import sys
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
N = II()
A = list(MI())
cum = {}
for i in A:
    if i in cum:
        cum[i] += 1
    else:
        cum[i] = 1
for i in A:
    ans = 0
    for k, v in cum.items():
        if k == i:
            v -= 1
        if v >= 2:
            ans += int(v*(v-1)/2)
    print(ans)

### FIXED CODE ###

import sys
from collections import defaultdict
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
N = II()
A = list(MI())
ans = 0
cum = defaultdict(int)
def couple_combination(n):
    if n >= 2:
        return int(n * (n - 1) / 2)
    else:
        return 0
for v in A:
    cum[v] += 1
for v in cum.values():
    ans += couple_combination(v)
for v in A:
    print(max(0,ans - cum[v] + 1))
### BUGGY CODE ###

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

M = {}

for h in range(H):
    A = list(map(int,input().split()))
    for w in range(len(A)):
        M[A[w]] = [h,w]
        
Q = int(input())

anslist = []
for q in range(Q):
    ans = 0
    L,R = map(int,input().split())
    now = M[L]
    for i in range(L+D,R+1,D):
        nex = M[i]
        ans += abs(nex[0]-now[0])+abs(nex[1]-now[1])
        now = nex
    anslist.append(str(ans))
        
print("\n".join(anslist))

### FIXED CODE ###

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

M = {}

for h in range(H):
    A = list(map(int,input().split()))
    for w in range(len(A)):
        M[A[w]] = [h,w]

anslist = []
for d in range(1,D+1):
    ans = 0
    sub_anslist = [ans]
    now = M[d]
    for i in range(d+D,(H*W)+1,D):
        nex = M[i]
        ans += abs(nex[0]-now[0])+abs(nex[1]-now[1])
        sub_anslist.append(ans)
        now = nex
    anslist.append(sub_anslist)

Q = int(input())
output = []
for q in range(Q):
    L,R = map(int,input().split())
    left = anslist[(L-1)%D][(L-1)//D]
    right = anslist[(R-1)%D][(R-1)//D]
    output.append(str(right-left))
        
print("\n".join(output))
### BUGGY CODE ###

import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(list(map(int, input())))
    return li

""" input template
S = input()
N = int(input())
L = list(map(int, input().split()))
a, b = list(map(int, input().split()))
SL = list(input())
"""

# --------------------------------------------

dp = None

def main():
    N, K = list(map(int, input().split()))
    A = list(input().split())

    D = collections.defaultdict(lambda: 0)

    for a in A:
        D[a] += 1

    op = 0
    while len(D) > K:
        min_key, min_value = min(D.items(), key=lambda x:x[1])

        op += min_value
        del D[min_key]

    print(op)


main()


### FIXED CODE ###

import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(list(map(int, input())))
    return li

""" input template
S = input()
N = int(input())
L = list(map(int, input().split()))
a, b = list(map(int, input().split()))
SL = list(input())
"""

# --------------------------------------------

dp = None

def main():
    N, K = list(map(int, input().split()))
    A = list(input().split())

    D = collections.defaultdict(lambda: 0)

    for a in A:
        D[a] += 1

    L = []
    for v in D.values():
        L.append(v)

    L.sort(reverse=True)

    i = 0
    S = 0
    U = min(K, len(L))
    while i < U:
        S += L[i]
        i += 1

    print(sum(L) - S)


main()
### BUGGY CODE ###

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

### FIXED CODE ###

n=int(input())
a_list = list(map(int,input().split()))
index_list = []
for i in range(n):
    tmp_list = []
    tmp_list.append(i+1)
    tmp_list.append(a_list[i])
    index_list.append(tmp_list)
index_list.sort(key=lambda x:x[1])
ans_list = []
for j in range(len(index_list)):
    ans_list.append(index_list[j][0])
print(*ans_list)
### BUGGY CODE ###

#4
#1 3 1 1
G, N = [int(_) for _ in input().split(" ")]
ret = ()
for i in range(N):
  ret += (int(input()),)

T = [0]*(G+1)

T[0] = 1
T[1] = 1

if 1 in ret:
  T[1] = 0

for i in range(2, G+1):
	if i in ret:
		T[i] = 0
		continue
	T[i] = T[i-1] + T[i-2]

print (T[G] % 1000000007)

### FIXED CODE ###

G, N = [int(_) for _ in input().split(" ")]
ret = ()
T = [-1]*(G+1)
T[0] = 1
T[1] = 1
for i in range(N):
  t = int(input())
  T[t] = 0

for i in range(2, G+1):
	if T[i] == -1:
		T[i] = (T[i-1] + T[i-2]) % 1000000007

print (T[G])
### BUGGY CODE ###

"""
解法１：
startとgoalの組み合わせの全探索で調べる。
マス目の数は最大で400なので、組み合わせの数は最大で約16000.
各組み合わせごとにBFSで最短経路を調べるので、400回ループが必要。
なので計算時間としてはO(H^3W^3)

解法２：
ワーシャルフロイドで各ノードから各ノードへの最短経路を求める。
計算量としては、O(H^3W^3となる)。

実装としては解法１のほうが楽そうなのでそちらを使う。
"""

from itertools import combinations
from copy import deepcopy
from collections import deque

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

nodeList = []
for i in range(H):
    for j in range(W):
        if MAP[i][j] == ".":
            nodeList.append((i,j))

adjecents = [(1,0),(0,1),(-1,0),(0,-1)]
ans = 0
for start,goal in list(combinations(nodeList,2)):
    copyMAP = deepcopy(MAP)
    que = deque([[start,0]])
    while que:
        node,step = que.popleft()
        if node == goal:
            ans = max(ans,step)
            break
        else:
            i,j = node
            if copyMAP[i][j] == ".":
                copyMAP[i][j] == "#"
                for a,b in adjecents:
                    x = i+a
                    y = j+b
                    if 0<=x<H and 0<=y<W:
                        que.append([(x,y),step+1])
print(ans)

### FIXED CODE ###

"""
解法１：
startとgoalの組み合わせの全探索で調べる。
マス目の数は最大で400なので、組み合わせの数は最大で約160000.
各組み合わせごとにBFSで最短経路を調べるので、400回ループが必要。
なので計算時間としてはO(H^3W^3)

解法２：
ワーシャルフロイドで各ノードから各ノードへの最短経路を求める。
計算量としては、O(H^3W^3となる)。

解法１だとなんかTLEするので、解法２で行く。
"""

H,W = map(int,input().split())
MAP = [list(input()) for _ in range(H)]
dp = [[float("INF")]*(H*W) for _ in range(H*W)]
adjecents = [(1,0),(-1,0),(0,1),(0,-1)]

for i in range(H):
    for j in range(W):
        if MAP[i][j] == ".":
            pointer = i*W + j
            dp[pointer][pointer] = 0
            for a,b in adjecents:
                x = i + a
                y = j + b
                if 0<=x<H and 0<=y<W and MAP[x][y] == ".":
                    pointer2 = x*W + y
                    dp[pointer][pointer2] = 1

for i in range(H*W):
    for j in range(H*W):
        for k in range(H*W):
            dp[j][k] = min(dp[j][k],dp[j][i]+dp[i][k])

ans = 0
for i in range(H*W):
    for j in range(H*W):
        if dp[i][j] != float("INF"):
            ans = max(ans,dp[i][j])
print(ans)
### BUGGY CODE ###

S = input()
N = len(S)
MOD = 10**9+7
dp = [[0]*(14) for i in range(100010)]
dp[0][0] = 1

for i in range(N):
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])
        
    for j in range(10):
        if c != -1 and c != j:
            continue
        else:
            for k in range(13):
                dp[i+1][(k*10+j)%13] += dp[i][k]
        
    for j in range(13):
        dp[i+1][j] %= MOD
        
print(dp[N][5])

### FIXED CODE ###

S = input()
N = len(S)
MOD = 10**9+7
dp = [[0]*(14) for i in range(100010)]
dp[0][0] = 1

for i in range(N):
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])
        
    for j in range(10):
        if c != -1 and c != j:
            continue
        else:
            for k in range(13):
                dp[i+1][(k*10+j)%13] += dp[i][k]
        
    for j in range(13):
        dp[i+1][j] %= MOD
        
print(dp[N][5])
### BUGGY CODE ###

s = [i for i in input()]
ans = 0
while s.count('B') != 0 and s.count('W') != 0:
    lim,init = len(s)-1,s[-1]
    while s[lim] == init:
        if s[lim] is 'B':   s[lim] = 'W'
        else:   s[lim] = 'B'
        lim-=1
    if init is 'B': s.append('W')
    else:   s.append('B')
    ans += 1
print(ans)


### FIXED CODE ###

s = input()
ans = 0
init = s[0]
for chr in s:
    if chr != init:
        ans += 1
        init = chr
print(ans)
### BUGGY CODE ###

import fractions

MOD = 1000000007

def lcm(x, y):
    return x * y // fractions.gcd(x, y)

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    lc = 1
    for i in A:
        lc = lcm(lc, i)
        ans = 0
    for i in A:
        ans += lc // i
    print(ans%MOD)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import fractions

def lcm(x, y):
    return x * y // fractions.gcd(x, y)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    prev_lc = 1
    ans = 0
    for i in A:
        lc = lcm(prev_lc, i)
        ans = ans * (lc // prev_lc) + lc // i
        prev_lc = lc
    print(ans % 1000000007)

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

N = int(input())
A = input()
count = 0
split = [int(i) for i in A.split(" ")]

for i in range(N):
    if split[i] == 1:
        count +=1
        break

if count != 0:
    count = 0
    for i in range(N):
        i -= count
        if i + 1 != split[i]:
            del split[i]
            count += 1
    print(count)
else:
    print(-1)

### FIXED CODE ###

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

for i in range(N):
    if A[i] == num:
        num += 1
    else:
        count += 1

if count == N:
    print(-1)
else:
    print(count)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
N, A, B, K = map(int, input().split())
mod = 998244353

def paint(i, k, memo = {}):
    if i == N-1:
        if k in [A, B, A+B, 0]: return 1
        else: return 0
    try:
        return memo[(i, k)]
    except KeyError:
        ans = 0
        for c in [A, B, A+B, 0]:
            ans += paint(i+1, k-c, memo)
            ans %= mod
        memo[(i, k)] = ans
        return ans
memo = {}
print(paint(0, K, memo))

### FIXED CODE ###

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

def pow(n, i):
    if i == 0: return 1
    elif i == 1: return n
    elif i % 2 == 0: return pow((n * n) % mod, i//2)
    else: return (pow((n * n) % mod, i//2) * n) % mod

factorial = [1] *(N+1)
revfactorial = [1] * (N+1)
for i in range(N):
    factorial[i+1] = (factorial[i] * (i+1)) % mod
revfactorial[N] = pow(factorial[N], mod-2)
for i in reversed(range(1, N)):
    revfactorial[i] = (revfactorial[i+1] * (i+1)) % mod

ans = 0
for a in range(N+1):
    if K >= A * a:
        if (K - A * a) % B == 0:
            b = (K - A * a) // B
            apatt = (factorial[N] * revfactorial[N - a] * revfactorial[a]) % mod
            if b <= N: bpatt = (factorial[N] * revfactorial[N - b] * revfactorial[b]) % mod
            else: bpatt = 0
            ans += (apatt * bpatt) % mod
            ans %= mod
print(ans)