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

import collections
n = int(input())
a = [int(x) for x in input().split()]

c = collections.Counter(a)
counts = []
for i in c.keys():
    counts.append(sum([v for k, v in c.items() if abs(k-i) <= 1]))

print(max(counts))

### FIXED CODE ###

import collections
n = int(input())
a = [int(x) for x in input().split()]

c = collections.Counter(a)
max_counts = 0

for i in c.keys():
    #count = sum([v for k, v in c.items() if abs(k-i) <= 1])
    count = c[i] + c[i-1] + c[i+1]
    max_counts = count if count > max_counts else max_counts

print(max_counts)
### BUGGY CODE ###

import math
h,n = map(int,input().split())


ab = []
for i in range(n):
    ab.append([int(i) for i in input().split()])
ab.sort()

dp = []
for i in range(h + ab[n-1][0]):
    dp.append(pow(2, 31) - 1)
dp[0] = 0

for i in range(1, len(dp)):
    tmp = dp[i]
    for j in range(n):
        #print(j-ab[j][0])
        tmp = min(tmp, dp[max(0, i-ab[j][0])]+ab[j][1])
    dp[i] = tmp

#print(dp)
print(min(dp[h:]))

### FIXED CODE ###

import math
h,n = map(int,input().split())


a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
for i in range(n):
    a[i], b[i] = map(int,input().split())

dp = []
for i in range(h + max(a)):
    dp.append(pow(2, 31) - 1)
dp[0] = 0

for i in range(1, len(dp)):
    '''
    tmp = dp[i]
    for j in range(n):
        tmp = min(tmp, dp[max(0, i-a[j])] + b[j])
    dp[i] = tmp
    '''
    dp[i] = min(dp[i - A] + B for A, B in zip(a, b))

print(min(dp[h:]))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Tue Jan 21 18:19:39 2020

@author: matsui
"""


N,W=map(int,input().split())
vi,wi=[],[]
for i in range(N):
    w,v=map(int,input().split())
    wi.append(w)
    vi.append(v)
    

#L = sorted([list(map(int,input().split())) for i in range(N)])

M=int(sum(vi))
dp1=[sum(wi)+1]*(M+1)
#dp2=[sum(wi)+1]*(M+1)
dp1[0]=0
   
#L = sorted([list(map(int,input().split())) for i in range(N)])
s=0

for w, v in zip(wi,vi):
    s+=v
    for j in range(min(s,M),v-1,-1):
        if j >= v: 
            if dp1[j] > dp1[j-v]+w: dp1[j]=dp1[j-v]+w
        if dp1[j] > dp1[j]: dp1[j]=dp1[j]
    #print(dp1)
    #print(dp2)
    #dp1=[dp2[i] for i in range(M+1)]    
    
#print(max(dp))
m=0
for i in range(M+1):
    if dp1[i]<=W:
        m=i
print(m)
    


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Tue Jan 21 18:19:39 2020

@author: matsui
"""


N,W=map(int,input().split())
vi,wi=[],[]
for i in range(N):
    w,v=map(int,input().split())
    wi.append(w)
    vi.append(v)
    

#L = sorted([list(map(int,input().split())) for i in range(N)])

M=int(sum(vi))
dp=[W+1]*(M+1)
dp[0]=0
   
#L = sorted([list(map(int,input().split())) for i in range(N)])
s=0

for w, v in zip(wi,vi):
    s+=v
    for j in range(min(s,M),v-1,-1):
        if dp[j] > dp[j-v]+w: dp[j]=dp[j-v]+w
    #print(dp)

m=0
for i in range(M+1):
    if dp[i]<=W:
        m=i
print(m)
### BUGGY CODE ###

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

for i in range(len(a)):
    a[i]-=i+1

import math
#import statistics
#b=statistics.median(a)
b=math.floor(sum(a)/n)


def p(b,k):
  s=0
  t=0
  for i in a:
      s+=abs(i-b)
      t+=abs(i-b-1) 
  if s>t:
    if k==-1:
      print(t)
    else:
      return p(b+1,1)
  elif s==t:
    print(s)
  else:
    if k==1:
      print(s)
    else:
      return p(b-1,-1)
  
p(b,0)



### FIXED CODE ###

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

for i in range(len(a)):
    a[i]-=i+1

aa=sorted(a)
if n%2==0:
  b=(aa[int(n/2-1)]+aa[int(n/2)])/2
else:
  b=aa[int((n-1)/2)]

s=0
for i in aa:
  s+=abs(i-b)
print(int(s))
### BUGGY CODE ###

l,r = map(int,input().split())
r = min(r,l+4038)
ans = 2018
for i in range(l,r):
    for j in range(i+1,r+1):
        x = i*j%2019
        ans = min(ans,x)
print(ans)

### FIXED CODE ###

l,r = map(int,input().split())
r = min(r,l+2017)
ans = 2018
for i in range(l,r+1):
    for j in range(i+1,r+1):
        x = i*j%2019
        ans = min(ans,x)
print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(N)]

ans = float('inf')
for i in range(N):
  for j in range(N):
    for k in range(N):
      for l in range(N):
        x1= xy[i][0]
        x2 = xy[j][0]
        y1 = xy[k][1]
        y2 = xy[l][1]
        cnt = 0
        if x1 < x2 and y1 < y2:
          for n in range(N):
            if x1 <= xy[n][0] <= x2 and y1 <= xy[n][1] <= y2:
              cnt += 1

          if cnt >= K:
            ans = min(ans, (x2-x1)*(y2-y1))
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(N)]

ans = float('inf')
for i in range(N):
  for j in range(N):
    for k in range(N):
      for l in range(N):
        x1= xy[i][0]
        x2 = xy[j][0]
        y1 = xy[k][1]
        y2 = xy[l][1]
        cnt = 0
        if x1 < x2 and y1 < y2:
          for n in range(N):
            if x1 <= xy[n][0] <= x2 and y1 <= xy[n][1] <= y2:
              cnt += 1

          if cnt >= K:
            ans = min(ans, (x2-x1)*(y2-y1))
print(ans)
### BUGGY CODE ###

import math
mod = 10**9+7

# 素因数分解、辞書で返すやつ
# mathをimportする
def prime(n):
    factor = {}
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            if not num in factor.keys():
                factor[num] = 1
            else:
                factor[num] += 1
        if num > n:
            break
    if n != 1:
        if not n in factor.keys():
            factor[n] = 1
        else:
            factor[n] += 1
    return factor

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m=mod):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

import sys
input = sys.stdin.readline


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

dic = {}
for a in A:
    pr = prime(a)
    for num, count in pr.items():
        if not num in dic.keys():
            dic[num] = count
        else:
            if dic[num] < count:
                dic[num] = count

lcm = 1
for num, count in dic.items():
    lcm *= pow(num, count, mod)

ans = 0
for a in A:
    ans += mod_inv(a)*lcm
    ans %= mod

print(ans)

### FIXED CODE ###

import math
mod = 10**9+7

# 素因数分解、辞書で返すやつ
# mathをimportする
def prime(n):
    factor = {}
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            if not num in factor.keys():
                factor[num] = 1
            else:
                factor[num] += 1
        if num > n:
            break
    if n != 1:
        if not n in factor.keys():
            factor[n] = 1
        else:
            factor[n] += 1
    return factor

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m=mod):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

import sys
input = sys.stdin.readline


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

dic = {}
for a in A:
    pr = prime(a)
    for num, count in pr.items():
        if not num in dic.keys():
            dic[num] = count
        else:
            if dic[num] < count:
                dic[num] = count

lcm = 1
for num, count in dic.items():
    lcm *= pow(num, count, mod)
    lcm %= mod

ans = 0
for a in A:
    ans += mod_inv(a)*lcm
    ans %= mod

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

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

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

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
AC = [0] * N

for i in range(1, len(S)):
    if S[i-1] == 'A' and S[i] == 'C':
        AC[i] = AC[i-1] + 1
    else:
        AC[i] = AC[i-1]


for i in range(Q):
    start, end = map(lambda x:int(x)-1, input().split())
    print(AC[end] - AC[start])
### BUGGY CODE ###

[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
count = 0
for i in range(N-1):
    if A[i] <= A[i+1] : count += 1
if count > N * 0.9 : print(1)
ans = []
mini = min(A[0:L])
ans.append(mini)
for i in range(1,N-L+1) :
    if A[i+L-1] <= mini :
        mini = A[i+L-1]
    elif A[i-1] == mini :
        mini = min(A[i:i+L])
    ans.append(mini)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

if __name__ == '__main__':
    n = int(input())
    list =[]
    for i in range(n):
        list.append(int(input()))

    list2=[]
    count = 0
    now =1
    while True:
        if now in list2:
            print(-1)
            break
        else:
            if list[now-1] ==2:
                count+=1
                print(count)
                break
            else:
                list2.append(now)
                count+=1
                now = list[now-1]

### FIXED CODE ###

if __name__ == '__main__':
    n = int(input())
    dict={}
    for i in range(n):
        dict[i] = int(input())

    dict2={}
    count = 0
    now =1
    for i in range(n):
        if now in dict2:
            print(-1)
            break
        else:
            if dict[now-1] ==2:
                count+=1
                print(count)
                break
            else:
                dict2[now]=0
                count+=1
                now = dict[now-1]
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
n, q = map(int,input().split())
d = [[] for i in range(n)]
for i in range(n-1):
    ai, bi = map(int,input().split())
    d[ai-1].append(bi-1)
    d[bi-1].append(ai-1)
#point
px = [0 for i in range(n)]
for i in range(q):
    pi,xi = map(int,input().split())
    px[pi-1] +=xi
sp = [0 for i in range(n)]
sp[0] = px[0]
def f(v,vp,p):
    sp[v] = p + px[v]
    for di in d[v]:
        if not di == vp:
            f(di,v,sp[v])
f(0,0,0)
for i in range(n):
    print(sp[i])

### FIXED CODE ###

from collections import deque
n, q = map(int,input().split())
d = [[] for i in range(n)]
for i in range(n-1):
    ai, bi = map(int,input().split())
    d[ai-1].append(bi-1)
    d[bi-1].append(ai-1)
#point
px = [0 for i in range(n)]
for i in range(q):
    pi,xi = map(int,input().split())
    px[pi-1] += xi
sp = [0 for i in range(n)]
s = deque()
s.append(0)
visited = [False for i in range(n)]
while len(s) > 0:
    x = s.popleft()
    visited[x] = True
    sp[x] += px[x]
    for xc in d[x]:
        if not visited[xc]:
            s.append(xc)
            sp[xc] += sp[x]
for i in range(n):
    print(sp[i])
### BUGGY CODE ###

from collections import defaultdict
import heapq
import sys


        
def dijkstra(startvertex,V,graph):
    distances=[sys.maxsize]*V
    distances[startvertex]=0
    heap=[(0,startvertex)]
    while heap:
        current_distance,current_vertex=heapq.heappop(heap)
        if current_distance>distances[current_vertex]:
            continue
        for neighbor in range(len(graph[current_vertex])):
            if graph[current_vertex][neighbor]>0:
                distance=current_distance+graph[current_vertex][neighbor]
                
                
                if distance<distances[neighbor]:
                    distances[neighbor]=distance
                    heapq.heappush(heap,(distance,neighbor))
                    
    return distances
n=int(input())            
    
graph=[[0 for i in range(n)]for j in range(n)]
for i in range(n-1):
    a=map(int,raw_input().split())
    # print(a)
    graph[a[0]-1][a[1]-1]=a[2]
    graph[a[1]-1][a[0]-1]=a[2]

# print(graph)
w=map(int,raw_input().split())
m=dijkstra(w[1]-1,n,graph)
# print(m)
c=0
for i in range(w[0]):
    s=map(int,raw_input().split())
    # print(s)
    c=abs(m[s[0]-1])+abs(m[s[1]-1])
    print(c)

### FIXED CODE ###

N=int(input())
import sys
sys.setrecursionlimit(10**6)
T=[[] for _ in range(N)]
for i in range(N-1):
    a,b,c=map(int, input().split())
    T[a-1].append((b-1,c))
    T[b-1].append((a-1,c))

Q,K=map(int, input().split())
D=[-1]*N
D[K-1]=0
def dfs(start, nowd):
    to=T[start]
    for t in to:
        next_node,c=t
        if D[next_node]!=-1:
            continue
        nextd=nowd+c
        D[next_node]=nextd
        dfs(next_node, nextd)
dfs(K-1,0)
# print(D)
for i in range(Q):
    x,y=map(int, input().split())
    print(D[x-1]+D[y-1])
### BUGGY CODE ###

import collections

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

l = []
for _ in range(n):
  l.append([False] * n)

for x in range(n):
  l[x][x] = True

for a, b in ab:
  a -= 1
  b -= 1
  l[a][b] = True
  l[b][a] = True

c = [None] * n

for i in range(n):
  if c[i] is None:
    c[i] = i
  for j in range(n):
    if l[i][j]:
      if c[j] is None:
        c[j] = i

vs = []
for k, v in collections.Counter(c).items():
  vs.append(v)

print(max(vs))


### FIXED CODE ###

import collections
import sys

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

l = []
for _ in range(n):
  l.append([])

# for x in range(n):
#   l[x]

for a, b in ab:
  a -= 1
  b -= 1
  l[a].append(b)
  l[b].append(a)

# c = [None] * n

# for i in range(n):
#   if c[i] is None:
#     c[i] = i
#   for f in l[i]:
#     if c[f] is None:
#       c[f] = i


# https://algo-logic.info/connected-components-num/

color = [None] * n

sys.setrecursionlimit(3*10**5)


def dfs(i, c):
  if color[i] is not None:
    return
  color[i] = c

  for f in l[i]:
    dfs(f, c)


for i in range(n):
  if color[i] is None:
    dfs(i, i)

print(max([v for k, v in collections.Counter(color).items()]))
### BUGGY CODE ###

N=int(input())
import sys
input=sys.stdin.readline
X=[[-10**10,0]]
Y=[[-10**10,0]]

for i in range(N):
    x,y=map(int,input().split())
    X.append([x,i+1])
    Y.append([y,i+1])
X.append([10**10,N+1])
Y.append([10**10,N+1])
X.sort()
Y.sort()

#print(X,Y)

L=[[]for i in range(N+1)]
for i in range(1,N+1):
    L[X[i][1]].append([X[i][0]-X[i-1][0],X[i-1][1]])
    L[X[i][1]].append([X[i+1][0]-X[i][0],X[i+1][1]])
for i in range(1,N+1):
    L[Y[i][1]].append([Y[i][0]-Y[i-1][0],Y[i-1][1]])
    L[Y[i][1]].append([Y[i+1][0]-Y[i][0],Y[i+1][1]])
#print(L)
C=[1 for i in range(N+2)]
C[0]=0
C[-1]=0
C[1]=0
import heapq
ans=0
Q=L[1]
heapq.heapify(Q)
for i in range(10**6):
    #print(ans,Q)
    #print(C)
    if len(Q)==0:
        break
    q=heapq.heappop(Q)
    if C[q[1]]==0:
        continue
    else:
        C[q[1]]=0
        ans+=q[0]
        for j in range(4):
            if C[L[q[1]][j][1]]==1:
                heapq.heappush(Q,L[q[1]][j])
print(ans)

### FIXED CODE ###

N=int(input())
import sys
input=sys.stdin.readline
X=[(-10**10,0)]
Y=[(-10**10,0)]

for i in range(N):
    x,y=map(int,input().split())
    X.append((x,i+1))
    Y.append((y,i+1))
X.append((10**10,N+1))
Y.append((10**10,N+1))
X.sort()
Y.sort()

#print(X,Y)

L=[[]for i in range(N+1)]
for i in range(1,N+1):
    L[X[i][1]].append((X[i][0]-X[i-1][0],X[i-1][1]))
    L[X[i][1]].append((X[i+1][0]-X[i][0],X[i+1][1]))
for i in range(1,N+1):
    L[Y[i][1]].append((Y[i][0]-Y[i-1][0],Y[i-1][1]))
    L[Y[i][1]].append((Y[i+1][0]-Y[i][0],Y[i+1][1]))
#print(L)
C=[1 for i in range(N+2)]
C[0]=0
C[-1]=0
C[1]=0
import heapq
ans=0
Q=L[1]
heapq.heapify(Q)
for i in range(10**6):
    #print(ans,Q)
    #print(C)
    if len(Q)==0:
        break
    q=heapq.heappop(Q)
    if C[q[1]]==0:
        continue
    else:
        C[q[1]]=0
        ans+=q[0]
        for j in range(4):
            if C[L[q[1]][j][1]]==1:
                heapq.heappush(Q,L[q[1]][j])
print(ans)
### BUGGY CODE ###

from fractions import Fraction
n,k = map(int, input().split())
ttl = 0
res = []
for i in range(1,n+1):
  ttl = i
  cnt = 0
  while True:
    if ttl >= k:
      break
    ttl = ttl*2
    cnt+=1
  p = Fraction(1,n)*Fraction(1,2)**cnt
  res.append(p)
ans = sum(res)
print(float(ans))

### FIXED CODE ###

n,k = map(int, input().split())
ttl = 0
res = []
for i in range(1,n+1):
  ttl = i
  cnt = 0
  while True:
    if ttl >= k:
      break
    ttl = ttl*2
    cnt+=1
  p = 0.5**cnt
  res.append(p)
ans = sum(res)/n
print(float(ans))
### BUGGY CODE ###

n,k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)])

l = [0]*(n-1)
for i in range(n-1): l[i] = h[i+1]-h[i]

s = 0
t = float("inf")
for i in range(n-k+1):
  p = sum(l[i:i+k-1])
  if p < t:
    t = p
    s = i
    
print(h[s+k-1] - h[s])

### FIXED CODE ###

n,k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)])

ans = 0
t = float("inf")
for i in range(n-k+1):
  if abs(h[i+k-1] - h[i]) < t:
    t = abs(h[i+k-1] - h[i])
    ans = i

print(h[ans+k-1] - h[ans])
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
sa = []
for i in range(n+1):
    sa.append(abs(a[i]-a[i+1]))

for i in range(1, n+1):
    print(sum(sa) - sa[i-1] - sa[i] + abs(a[i-1]-a[i+1]))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
sa = 0
for i in range(n+1):
    sa += abs(a[i]-a[i+1])

for i in range(1, n+1):
    print(sa - (abs(a[i-1]-a[i]) + abs(a[i]-a[i+1])) + abs(a[i-1]-a[i+1]))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
class Node:
    def __init__(self):
        self.next=[]
    def get_data(self,new_next,weight=1):
        self.next.append(new_next)
def BFS(i,depth,K):  
    depth+=1
    tmp=i
    seki=1
    num=len(tmp)
    if depth==1:
        calc=K-1
        diff=0
        #for i in range(calc,max(1,calc-(len(tmp)-diff)),-1):
        
        for i in range(calc,calc-(num-diff),-1):
            seki*=i
        
    else:
        calc=K-2
        diff=1
        for i in range(calc,calc-(num-diff),-1):
            seki*=i
            
    for each in tmp:
        if not check_node[each]:
            check_node[each]=True
            seki*=BFS(node[each].next,depth,K)%1000000007
    return seki


N,K=list(map(int,input().split()))
node=[Node() for _ in range(N)]
check_node=[False for _ in range(N)]
check_node[0]=True
for i in range(N-1):
    p,n=list(map(int,input().split()))
    node[n-1].get_data(p-1)
    node[p-1].get_data(n-1)
start=0
d=0

com=K*BFS(node[0].next,d,K)
print(com%1000000007)

### FIXED CODE ###

import sys
import math
sys.setrecursionlimit(1000000)
mod=1000000007
class Node:
    def __init__(self):
        self.next=[]
    def get_data(self,new_next,weight=1):
        self.next.append(new_next)
def BFS(i,depth,K):  
    depth+=1
    tmp=i
    seki=1
    num=len(tmp)
    if depth==1:
        calc=K-1
        loop=range(calc,calc-num,-1)
        for i in loop:
            seki*=i%1000000007

        
    else:
        calc=K-2
        num-=1
        if calc>=num:
            seki=cache[num]
        else:
            print(0)
            exit()

            
            
    for each in tmp:
        if not check_node[each]:
            check_node[each]=True
            seki*=BFS(node[each].next,depth,K)%mod
    return seki


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

if K>2:
    cache=[0 for i in range(K-2)]
    cache[0]=1
    for i in range(1,K-2):
        cache[i]=cache[i-1]*(K-1-i)%mod
    cache.append(cache[-1])
else:
    cache=[1,1]
node=[Node() for _ in range(N)]
check_node=[False for _ in range(N)]
check_node[0]=True
for i in range(N-1):
    p,n=list(map(int,input().split()))
    node[n-1].get_data(p-1)
    node[p-1].get_data(n-1)
start=0
d=0

com=K*BFS(node[0].next,d,K)
print(int(com)%mod)
### BUGGY CODE ###

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

ans = 0
suma0 = [0 for i in range(n)]

if a[0] == 0:
    ans+=1
else:
    suma0[0] = a[0]

for i in range(1, n):
    suma0[i] = suma0[i-1] + a[i]
    if suma0[i] == 0:
        ans += 1

for i in range(1,n):
    for j in range(i, n):
        suma0[j] -= a[i-1]
        if suma0[j] == 0:
            ans += 1

print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))

ans = 0
sum = [0 for i in range(n+1)]

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

count = Counter(sum)

for values in count.values():
    if values >= 2:
        ans += values * (values-1) // 2

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

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

da = [[] for i in range(a)]
d = []
for i in range(b):
    k,kk = map(int,input().split())
    da[k-1].append(kk)
    d.append([k, kk])

for i in range(a):
    da[i].sort()

for i in range(b):
    p = da[d[i][0]-1].index(d[i][1])

    n = str(d[i][0])
    m = str(p+1)

    n = "0"*(6-len(n)) + n
    m = "0"*(6-len(m)) + m

    print(n+m)


### FIXED CODE ###

import sys
input = sys.stdin.readline

a,b = map(int,input().split())
aa = []
d = []
for i in range(b):
    k,kk = map(int,input().split())
    d.append([k, kk,i+1])

da = sorted(d)

kkk = da[0][0]
ll = 0
for i in range(b):
    kkkk = da[i][0]
    if kkk == kkkk:
        ll += 1
    else:
        kkk = kkkk
        ll = 1
    aa.append([da[i][2],da[i][0],ll])
aa.sort()

for i in aa:
    m = str(i[1])
    n = str(i[2])
    m = "0"*(6-len(m))+m
    n = "0"*(6-len(n))+n
    print(m+n)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10000)

from functools import lru_cache

def resolve():
    N, W = map(int, input().split())    
    w_v = [list(map(int, input().split())) for _ in range(N)]  # [N][0:weight, 1:value]

    dp = [[-1] * (W+1) for _ in range(N+1)] 

    #print(dp)
 
    @lru_cache(maxsize=None)
    def dfs(w, i):
        if dp[i][w] >= 0:
            return dp[i][w]
        if i >= N:
            res = 0
        elif w < w_v[i][0]:
            res = dfs(w, i+1)
        else:
            res = max(dfs(w - w_v[i][0], i+1) + w_v[i][1], dfs(w, i+1))

        dp[i][w] = res
        return res

    res = dfs(W, 0)
    print(res)
    
    
if __name__ == "__main__":
    resolve()

### FIXED CODE ###

def resolve():
    N, W = map(int, input().split())    
    w_v = [list(map(int, input().split())) for _ in range(N)]  # [N][0:weight, 1:value]

    dp = [[0] * (W+1) for _ in range(N+1)] 

    for i in range(N-1,-1,-1):
        for j in range(W+1):
            w = w_v[i][0]
            v = w_v[i][1]
            if j < w_v[i][0]:
                dp[i][j] = dp[i+1][j]
            else:
                dp[i][j] = max(dp[i+1][j], dp[i+1][j - w] + v)
 
    print(dp[0][W])
 
if __name__ == "__main__":
    resolve()
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
dlt=0
while(len(a)):
  i=a[0]
  j=a.count(i)
  if(j>i):dlt+=j-i
  elif(i>j):dlt+=j
  for k in range(j):a.remove(i)
print(dlt)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
dlt=0
push=0
a.sort()
k=0
while(1):
  i=a[k+push]
  if(i>n):
    dlt+=1
    push+=1
  else:
    j=a.count(i)
    push+=j
    if(j>i):dlt+=j-i
    elif(i>j):dlt+=j
  if(k+push>=n):break
print(dlt)