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

from collections import deque

H, W = map(int,input().split())
A = [list(input()) for _ in range(H)]
p = deque()
for i, Ai in enumerate(A):
    for j, Aij in enumerate(Ai):
        if Aij == "#":
            p.append([i, j, 0])

while p:
    y, x, cnt = p.popleft()
    for dx, dy in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        if 0 <= y + dy < H and 0 <= x + dx < W and A[y + dy][x + dx] == ".":
            p.append([y + dy, x + dx, cnt + 1])
            A[y + dy][x + dx] = "#"
print(cnt)


### FIXED CODE ###

from collections import deque

H, W = map(int,input().split())
A = [list(input()) for _ in range(H)]
p = deque()
for i, Ai in enumerate(A):
    for j, Aij in enumerate(Ai):
        if Aij == "#":
            p.append([i, j, 0])

while p:
    y, x, cnt = p.popleft()
    for dx, dy in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        if 0 <= y + dy < H and 0 <= x + dx < W and A[y + dy][x + dx] == ".":
            p.append([y + dy, x + dx, cnt + 1])
            A[y + dy][x + dx] = "#"
print(cnt)
### BUGGY CODE ###

N = int(input())
A_i = list(map(int, input().split()))
uq_A_i = list(set(A_i))
C = ["0\n"] * N
for i in uq_A_i:
    C[i - 1] = "{}".format(A_i.count(i)) + "\n"
print("".join(C))


### FIXED CODE ###

N = int(input())
A_i = list(map(int, input().split()))
C = [0] * N
for i in A_i:
    C[i - 1] += 1
print(*C)
### BUGGY CODE ###

n,m,q=map(int,input().split())
L=[[0 for i in range(n)] for i in range(n)] 
for i in range(m):
  l,r=map(int,input().split())
  L[l-1][r-1]+=1
for i in range(q):
  p,q=map(int,input().split())
  ans=0
  for j in range(p-1,q):
    for k in range(p-1,q):
      ans+=L[j][k]
  print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
n,m,Q=map(int,input().split())
L=[[0 for i in range(n)] for i in range(n)]
LL=[[0 for i in range(n)] for i in range(n)] 
for i in range(m):
  l,r=map(int,input().split())
  L[l-1][r-1]+=1
LL[0][0]=L[0][0]
for i in range(1,n):
  LL[i][0]=LL[i-1][0]+L[i][0]
  LL[0][i]=LL[0][i-1]+L[0][i]
for i in range(1,n):
  for j in range(1,n):
    LL[i][j]=LL[i-1][j]+LL[i][j-1]+L[i][j]-LL[i-1][j-1]
for i in range(Q):
  p,q=map(int,input().split())
  if p==1:
    ans=LL[q-1][q-1]
  elif q==1:
    ans=LL[0][0]
  else:
    ans=LL[q-1][q-1]-LL[q-1][p-2]-LL[p-2][q-1]+LL[p-2][p-2]
  print(ans)
### BUGGY CODE ###

import collections

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
bcs=[list(map(int,input().split())) for i in range(Q)]
total=sum(A)
c=collections.Counter(A)
ans=[0 for i in range(Q)]




for i in range(Q):
    B=bcs[i][0]
    C=bcs[i][1]
    if c[B]!=0:
        tempcounterpl=collections.Counter([C for j in range(c[B])])
        total=total+c[B]*(C-B)
        ans[i]=total
        c[B]=0
        c=c+tempcounterpl
    else:
        ans[i]=total
for i in range(Q):
    print(ans[i])

### FIXED CODE ###

import collections

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
bcs=[list(map(int,input().split())) for i in range(Q)]
total=sum(A)
c=collections.Counter(A)
ans=[0 for i in range(Q)]


for i in range(Q):
    B=bcs[i][0]
    C=bcs[i][1]
    if c[B]!=0:
        total+=c[B]*(C-B)
        ans[i]=total
        c[C]+=c[B]
        c[B]=0
    else:
        ans[i]=total
for i in range(Q):
    print(ans[i])
### BUGGY CODE ###

def main():
    n =int( input())
    sn=[]

    for i in range(n):
        inWord = str(input())
        addFlag = True
        for s in sn:
            if s["word"] == inWord and len(sn) !=0:
                s["count"]+=1
                addFlag = False
                break
        if addFlag ==True:
            sn.append( {"word":inWord,"count":1})
    
    sn.sort(reverse=True,key=lambda x:x['count'])
    
    most = int(sn[0]["count"])
    mostWords=[]
    for elm in sn:
        if elm["count"] == most:
            mostWords.append(elm["word"])
        else:
            break
    mostWords.sort()

    for elm in mostWords:
        print(elm)
    return
main()



### FIXED CODE ###

def main():
    n =int( input())

    cnt=dict()
    
    for _ in range(n):
        s=input()
        if s in cnt:
            cnt[s]+=1
        else :
            cnt[s]=1
    #print(cnt)
    
    num = 0
    res =[]
    for key,value in cnt.items():
        #print(key,":::",value)
        if value > num:
            num=value
            res=[]
            res.append(key)

        elif value==num:
            res.append(key)

    #print("res::",res)

    
    #a = [k for k, v in cnt.items() if v == max(cnt.values())]


    #print("結果発表：：：：",len(res))
    res.sort()
    for elm in res:
        print(elm)


main()
### BUGGY CODE ###

import math

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

l = [0]

for x in range(1,n+1):
    ans = 0
    ans = math.floor(a*x/b) - a * math.floor(x/b)
    l.append(ans)
    if l[x] > ans:
        break
#print(l)
print(max(l))

### FIXED CODE ###

A,B,N=map(int,input().split())
def f(x):
  return int(A*x/B)-A*int(x/B)

print(f(min(N,B-1)))
### BUGGY CODE ###

from collections import defaultdict

N,Q=[int(x) for x in input().split()]
S=input()
A=defaultdict(list)
B=[1 for x in range(N)]
for i in range(N):
    A[S[i]].append(i)
killed=0
for q in range(Q):
    a,b=input().split()
    tmp=[]
    if b=="R":
        d=1
    else:
        d=-1
    for k in A[a]:
        if (k==0 and d==-1) or (k==N-1 and d==1):
            killed+=B[k]
        elif B[k]!=0:
            tmp.append([k,B[k],d])
        B[k]=0
    for t in tmp:
        B[t[0]+t[2]]+=t[1]
print(N-killed)

### FIXED CODE ###

from collections import defaultdict

def testkilled(p,S,qry,N):
    pi=p
    c=S[pi]
    for q in qry:
        a,b=q
        if b=="R":
            d=1
        else:
            d=-1
        if c==a:
            pi+=d
            if pi==-1:
                return 1
            if pi==N:
                return 2
            c=S[pi]
    return 0

N,Q=[int(x) for x in input().split()]
S=input()
B=[1 for x in range(N)]
qry=[]
for q in range(Q):
    qry.append(input().split())
l=0
r=N
ans=N
while(r-l>1):
    p=(l+r)//2
    k=testkilled(p,S,qry,N)
    if k==1:
        l=p
    else:
        r=p
if testkilled(0,S,qry,N)==1:
    if testkilled(p,S,qry,N)==1:
        ans-= p+1
    else:
        ans-= p
    #print ("p",p,l,r)    
l=-1
r=N-1
while(r-l>1):
    p=(l+r)//2
    k=testkilled(p,S,qry,N)
    if k==2:
        r=p
    else:
        l=p
if testkilled(N-1,S,qry,N)==2:
    if testkilled(p,S,qry,N)==2:
        ans-= (N-p)
    else:
        ans-= (N-p-1)
#print ("p",p,l,r)
print(ans)
#print(testkilled(0,S,qry,N))
#print(testkilled(1,S,qry,N))
#print(testkilled(N-1,S,qry,N))
### BUGGY CODE ###

n,q=map(int,input().split())
s=input()
l_li=[]
r_li=[]
for i in range(q):
    l,r=map(int,input().split())
    l_li.append(l)
    r_li.append(r)
    
dp =[[0 for i in range(n+2)] for j in range(n+2)]

for i in range(1):
    for j in range(i,n):
        t=0
        if s[j]=="C" and j!=i:
            if s[j-1]=="A":
                t=1
        
        dp[i][j]=dp[i][j-1]+t
        
for i in range(1,n):
    t=0
    if s[i]=="C" and s[i-1]=="A":   
        dp[i]=list(map(lambda x: x-1,dp[i-1]))
    else:
        dp[i]=dp[i-1]        
        
        
for i in range(q):
    print(dp[l_li[i]-1][r_li[i]-1])


### FIXED CODE ###

n,q=map(int,input().split())
s=input()
    
dp =[0 for j in range(n)]


for j in range(n):
    t=0
    if s[j]=="C" and j!=0:
        if s[j-1]=="A":
            t=1

    dp[j]=dp[j-1]+t
        

for i in range(q):
    l,r=map(int,input().split())
    print(dp[r-1]-dp[l-1])
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
for i in range(Q):
    l, r = map(int, input().split())
    print(S[l-1:r].count('AC'))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()

t = [0] * N
t[0] = 0
for i in range(1,N):
    if S[i-1] == 'A' and S[i] == 'C':
        t[i] = t[i-1] + 1
    else:
        t[i] = t[i-1]

ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(t[r-1] - t[l-1])

for a in ans:
    print(a)
### BUGGY CODE ###

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

import math
D = []
for x in range(1, N+1):
    D.append((A * (x % B) - A * (x % B) % B)/B)

print(int(max(D)))

### FIXED CODE ###

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

def X(x):
    return (A * (x % B) - A * (x % B) % B)/B

if N < B - 1:
    print(int(X(N)))
else:
    print(int(X(B-1)))
### BUGGY CODE ###

def factorial_mod(n, mod):
    a = 1
    for i in range(1, n + 1):
        a *= i
        a %= mod
    return a


def comb_mod(n, k, mod):
    if k > n or k < 0:
        return 0
    fact_n = factorial_mod(n, mod)
    fact_k = factorial_mod(k, mod)
    fact_n_k = factorial_mod(n - k, mod)
    return (fact_n * pow(fact_k, mod - 2, mod) * pow(fact_n_k, mod - 2, mod)) % mod


n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()

MOD = 10**9 + 7

ans_max = 0
for i in range(k - 1, n):
    ans_max += arr[i] * comb_mod(i, k - 1, MOD)
    ans_max %= MOD

arr.sort(reverse=True)

ans_min = 0
for i in range(k - 1, n):
    ans_min += arr[i] * comb_mod(i, k - 1, MOD)
    ans_min %= MOD

print((ans_max - ans_min) % MOD)

### FIXED CODE ###

def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs


n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()


MOD = 10 ** 9 + 7
facts, invs = prepare(n, MOD)

ans_max = 0
for i in range(k - 1, n):
    ans_max += (arr[i] * facts[i] * invs[k - 1] * invs[i - k + 1]) % MOD

arr.sort(reverse=True)

ans_min = 0
for i in range(k - 1, n):
    ans_min += (arr[i] * facts[i] * invs[k - 1] * invs[i - k + 1]) % MOD

print((ans_max - ans_min) % MOD)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, M, K = map(int, input().split())
friends_table = [[] for i in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    friends_table[a-1] += [b-1]
    friends_table[b-1] += [a-1]

blocks_table = [[] for i in range(N)]
for _ in range(K):
    a, b = map(int, input().split())
    blocks_table[a-1] += [b-1]
    blocks_table[b-1] += [a-1]

group_list = [i for i in range(N)]
friends_candidate = [[] for i in range(N)]

for i in range(N):
    friend = [i]
    # すでにDFS済み
    if i != group_list[i]:
        continue
    next_stack = friends_table[i][:]
    while next_stack:
        next = next_stack.pop(-1)
        # 訪問済み
        if i == group_list[next]:
            continue
        friend += [next]
        group_list[next] = i
        next_stack += friends_table[next]
    for f in friend:
        friends_candidate[f] = friend

for i in range(N):
    print(len(set(friends_candidate[i]).difference(set(friends_table[i] + blocks_table[i])))-1)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N, M, K = map(int, input().split())
friends_table = [[] for i in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    friends_table[a-1] += [b-1]
    friends_table[b-1] += [a-1]

group_list = [i for i in range(N)]
friends_candidate = [[] for i in range(N)]

for i in range(N):
    # すでにDFS済み
    if i != group_list[i]:
        continue
    next_stack = [i]
    friend = [i]
    while next_stack:
        u = next_stack.pop(-1)
        for v in friends_table[u]:
            # 訪問済み
            if i == group_list[v]:
                continue
            friend += [v]
            group_list[v] = i
            next_stack += [v]
    for f in friend:
        friends_candidate[f] = friend

blocks_table = [[] for i in range(N)]
for _ in range(K):
    a, b = map(int, input().split())
    if group_list[a-1] == group_list[b-1]:
        blocks_table[a-1] += [b-1]
        blocks_table[b-1] += [a-1]

for i in range(N):
    print(len(friends_candidate[i]) - len(friends_table[i]) - len(blocks_table[i])-1)
### BUGGY CODE ###

S = str(input())
Q = int(input())

topFlg = True

for _ in range(Q):
    query = list(map(str, input().split()))
    if query[0] == "1":
        topFlg = not (topFlg)
    else:
        if query[1] == "1":
            S = query[2] + S if topFlg else S + query[2]
        else:
            S = S + query[2] if topFlg else query[2] + S

if not topFlg:
    S = S[::-1]

print(S)


### FIXED CODE ###

S = str(input())
Q = int(input())

topFlg = True

leftStr = ""
rightStr = ""

for _ in range(Q):
    query = list(map(str, input().split()))
    if query[0] == "1":
        topFlg = not (topFlg)
    else:
        if query[1] == "1":
            if topFlg:
                leftStr = query[2] + leftStr
            else:
                rightStr += query[2]
        else:
            if topFlg:
                rightStr += query[2]
            else:
                leftStr = query[2] + leftStr

print(leftStr + S +
      rightStr if topFlg else rightStr[::-1] + S[::-1] + leftStr[::-1])
### BUGGY CODE ###

def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

N = int(input())
s = 0
for i in range(1, N):
  d = len(divisor(i))
  s += d
print(s)


### FIXED CODE ###

N = int(input())
s = 0
for i in range(1, N):
  b = (N - 1) // i
  s += b
print(s)
### BUGGY CODE ###

n=int(input())
s=input()
ans=0
for i in range(10):
  flag1=False
  for a in range(n-2):
    if s[a]==str(i):
      flag1=True
      break
  if flag1:
    for j in range(10):
      flag2=False
      for b in range(a+1,n-1):
        if s[b]==str(j):
          flag2=True
          break
      if flag2:
        for k in range(10):
          flag3=False
          for c in range(b+1,n):
            if s[c]==str(k):
              flag3=True
              break
          if flag3==1:
            ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
s=input()
ans=0
alist=[0]*10
for i in range(n):
  alist[int(s[i])]=i
for i in range(10):
  flag1=False
  for a in range(n-2):
    if s[a]==str(i):
      flag1=True
      break
  if flag1:
    for j in range(10):
      flag2=False
      for b in range(a+1,n-1):
        if s[b]==str(j):
          flag2=True
          break
      if flag2:
        for k in range(10):
          if b<alist[k]:
            ans+=1
print(ans)
### BUGGY CODE ###

n = int(input())
a = [int(i) for i in input().split(" ")]
q = int(input())

operations = [

]

for i in range(q):
    temp = input().split(" ")
    operations.append((int(temp[0]), int(temp[1])))

for op in operations:
    target, goto = op

    for i in range(len(a)):
        if a[i] == target:
            a[i] = goto

    print(sum(a))

### FIXED CODE ###

from collections import defaultdict

d = defaultdict(int)

n = int(input())
a = [int(i) for i in input().split(" ")]
q = int(input())

operations = []

for i in range(q):
    temp = input().split(" ")
    operations.append((int(temp[0]), int(temp[1])))

for hoge in a:
    d[hoge] += 1

initial_sum = 0
for key, value in d.items():
    initial_sum += key * value

for op in operations:
    target, goto = op

    before = goto * d[goto] + target * d[target]
    d[goto] += d[target]
    d[target] = 0

    after = goto * d[goto]
    diff = after - before
    
    initial_sum += diff
    print(initial_sum)
### BUGGY CODE ###

N = int(input())
ps = map(float, input().split())

dp = [0] * (N+1)
dp[0] = 1
for p in ps:
    pp = 1 - p
    for j in reversed(range(N+1)):
        dp[j] = dp[j]*pp + dp[j-1]*p

print(sum(dp[(N+1)//2:]))


### FIXED CODE ###

N = int(input())
ps = map(float, input().split())

dp = [0] * (N+1)
dp[0] = 1
for p in ps:
    pp = 1 - p
    for j in reversed(range(N+1)):
        dp[j] = dp[j]*pp + dp[j-1]*p

print(sum(dp[(N+1)//2:]))
### BUGGY CODE ###

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

for _ in range(min(K, 100)):
    lamp = [0 for i in range(N + 1)]
    for i in range(N):
        lamp[max(0, i - A[i])] += 1
        lamp[min(N, i + A[i] + 1)] -= 1

    ans = 0
    for i in range(N):
        ans += lamp[i]
        A[i] = min(ans, N)

[print(A[i], end=' ') if i != N - 1 else print(A[i]) for i in range(N)]


### FIXED CODE ###

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

for i in range(min(K, 50)):
    B = [0 for i in range(N)]
    for j in range(0, N):
        l = max(0, j - A[j])
        r = min(N - 1, j + A[j])
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1

    for j in range(1, N):
        B[j] += B[j - 1]
        
    A = B

[print(i, end=' ') for i in B]
print()
### BUGGY CODE ###

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

for i in range(N):
    ans*= A[i]

if ans > 10**18:
    ans = -1



print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
if 0 in A:
    print(0)
    exit()
ans = 1

for i in range(N):
    ans *= A[i]
    if ans > 10 ** 18:
        print(-1)
        exit()

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

n, k = map(int, input().split())
lst = list(map(int, input().split()))
cst = [float('inf')] * n
cst[0] = 0
for _ in range(0, n):
    m = min(n-(_+1),k)
    for i in range(0, m+1):   
      cst[_+i] = min(cst[_] + abs(lst[_+i] - lst[_]),cst[_+i])
print(cst[n-1])

### FIXED CODE ###

n, k = map(int, input().split())
lst = list(map(int, input().split()))
cst = [float('inf')] * n
cst[0] = 0
for _ in range(0, n):
    m = min(n-(_+1),k)
    for i in range(0, m+1):   
      cst[_+i] = min(cst[_] + abs(lst[_+i] - lst[_]),cst[_+i])
print(cst[n-1])
### BUGGY CODE ###

n, m = map(int, input().split())
a = [int(i) for i in input().split()]
for _ in range(m):
    b, c = map(int, input().split())
    a += [c] * b
a.sort()
ans = sum(a[-n:])
print(ans)

### FIXED CODE ###

import collections
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
k = collections.Counter(a)
for _ in range(m):
    b, c = map(int, input().split())
    k[c] += b
ans = 0
count = 0
for key in list(reversed(sorted(list(k.keys())))):
    ans += (min(k[key], n - count)) * key
    count += min(k[key], n - count)
    if count == n:
        break
print(ans)
### BUGGY CODE ###

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

    t = 1
    ans = [1]
    while True:
        if a[t-1] in ans:
            start = ans.index(a[t-1])
            break
        ans.append(a[t-1])
        t = a[t-1]

    if k > start:
        index = (k - start) % (len(ans) - start) + start
        t = ans[index]
    else:
        t = ans[k]
    return print(t)

if __name__ == '__main__':
    main()


### FIXED CODE ###

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

    path = [1]
    for _ in range(n-1):
        path.append(a[path[-1]-1])

    if k > n:
        start = path.index(path[-1])
        index = (k - start) % (len(path) - start - 1) + start
        t = path[index]
    else:
        t = path[k]
    return print(t)

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

# https://atcoder.jp/contests/abc168/tasks/abc168_d
# BFS

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

A = []
B = []
for i in range(M):
    _a, _b = map(int, input().split(' '))
    A.append(_a)
    B.append(_b)

# 接続している部屋のマップ
room_next = [[] for n in range(N)]

for a, b in zip(A, B):
    room_next[a - 1].append(b - 1)
    room_next[b - 1].append(a - 1)

room_depth = [None] * N
room_depth[0] = 0
room_sign = [None] * N

stack = [0]
visited = []

while stack:
    now = stack.pop()

    if now in visited:
        continue

    # print('now=', now)
    visited.append(now)
    for r in room_next[now]:
        if r not in visited:
            stack.append(r)

        if room_depth[r] is None:
            room_depth[r] = room_depth[now] + 1
            room_sign[r] = now + 1

print('Yes')
for s in room_sign[1:]:
    print(s)


### FIXED CODE ###

# https://atcoder.jp/contests/abc168/tasks/abc168_d
from collections import deque

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

A = []
B = []

# 隣接リスト
route2 = [[] for n in range(N)]

for i in range(M):
    a, b = map(int, input().split(' '))
    A.append(a)
    B.append(b)

for a, b in zip(A, B):
    route2[a - 1].append(b - 1)
    route2[b - 1].append(a - 1)

room_sign = [None] * N

queue = deque([])
visited = set()

queue.append(0)
visited.add(0)

while len(queue) > 0:
    now = queue.popleft()
    for i in route2[now]:
        if i not in visited:
            queue.append(i)
            visited.add(i)

            room_sign[i] = now + 1

print('Yes')
for s in room_sign[1:]:
    print(s)
### BUGGY CODE ###

n=int(input())
ans=1
for i in range(1,n+1):
    ans*=i
print(ans%(10**9+7))

### FIXED CODE ###

n=int(input())
ans=1
for i in range(1,n+1):
    ans*=i
    ans=ans%(10**9+7)
print(ans)
### BUGGY CODE ###

import sys
from itertools import accumulate
input=sys.stdin.buffer.readline
def main():
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    for _ in'_'*k:
        b=[0]*n
        for i,t in enumerate(a):
            if(j:=i-t)<0:j=0
            b[j]+=1
            if(j:=i-~t)<n:b[j]-=1
        a=list(accumulate(b))
        if min(a)==n:break
    print(' '.join(map(str,a)))
main()

### FIXED CODE ###

def main():
    n,k,*a=map(int,open(0).read().split())
    for _ in range(k):
        b=[0]*n
        m=10**18
        for i,t in enumerate(a):
            if t<m:m=t
            b[max(0,i-t)]+=1
            if i-~t<n:b[i-~t]-=1
        if m>=n:break
        for i in range(n-1):b[i+1]+=b[i]
        a=b
    print(' '.join(map(str,a)))
main()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)
from functools import lru_cache

@lru_cache()
def f(n):
    if n==0:
        return 0
    if n==1:
        return abs(H[1]-H[0])
    return min(f(n-1)+abs(H[n]-H[n-1]),f(n-2)+abs(H[n]-H[n-2]))

n=int(input())
H=tuple(map(int,input().split()))
print(f(n-1))

### FIXED CODE ###

import sys
input=sys.stdin.readline
n=int(input())
H=list(map(int,input().split()))
DP=[0]*n
DP[1]=abs(H[1]-H[0])
for i in range(2,n):
    DP[i]=min(DP[i-1]+abs(H[i]-H[i-1]),DP[i-2]+abs(H[i]-H[i-2]))
print(DP[-1])
### BUGGY CODE ###

import numpy as np
n = int(input())
a = np.array([int(input()) for _ in range(n)])
print(max(a[1:]))
for i in range(1, n-1):
    print(max(max(a[:i]), max(a[i+1:])))
print(max(a[:n]))


### FIXED CODE ###

import numpy as np
n = int(input())
a = [int(input()) for _ in range(n)]
t1 = max(a)
t1_idx = [i for i, v in enumerate(a) if v == t1]
a.sort()

if len(t1_idx) < 2:
    try:
        t2 = a[-1*len(t1_idx)-1]
    except:
        for i in range(n):
            print(t1)

    for i in range(n):
        if i in t1_idx:
            print(t2)
        else:
            print(t1)
else:
    for i in range(n):
        print(t1)
### BUGGY CODE ###

n=int(input())
s=input()
cnt=0
a=[]
b=[]
c=[]
for i in range(n):
  d=s[i]
  if d in b:continue
  else:b.append(d)
  for j in range(i+1,n):
    e=s[i]+s[j]
    if e in c:continue
    else:c.append(e)
    for k in range(j+1,n):
      f=s[i]+s[j]+s[k]
      if f not in a:
        a.append(f)
        cnt+=1
print(cnt)

### FIXED CODE ###

n=int(input())
s=input()
cnt=0
for m in range(1000):
  m=str(m).zfill(3)
  j=0
  for i in m:
    if i not in s[j:]:break
    j+=s[j:].index(i)+1
  else:cnt+=1
print(cnt)
### BUGGY CODE ###

N = int(input())
A = [int(input()) for i in range(N)]

lenA = len(A)
cnt = 0
chk = [0]*lenA

for i in range(lenA):
    if chk[i]:
        continue
    chk[i] = 1

    last = A[i]
    for j, v in enumerate(A[i+1:]):
        if chk[i+j+1] or v<=last:
            1 + 1
        else:
            chk[i+j+1] = 1
            last = v
    cnt += 1

print(cnt)

### FIXED CODE ###

from collections import deque
from bisect import bisect_left as bl
N = int(input())
A = [int(input()) for i in range(N)]

de = deque([])
de.append(A[0])
for a in A[1:]:
    ind = bl(de, a)
    if ind == 0:
        de.appendleft(a)
    else:
        de[ind-1] = a

print(len(de))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans =0
for i in set(a):
    if i>a.count(i):
        ans+=a.count(i)
    elif i<a.count(i):
        ans+=a.count(i)-i
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans =0
import collections
c = collections.Counter(a)
for i in c.keys():
    if c[i]>i:
        ans+=c[i]-i
    elif c[i]<i:
        ans+=c[i]
print(ans)