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

N = int(input())
S = input()
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    for j in range(N):
        if v[idx] == S[j]:
            idx += 1
            if idx == 3:
                ans += 1
                break
print(ans)

### FIXED CODE ###

N = int(input())
S = input()
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    c = 0
    idx_now = 0
    for j in range(3):
        idx = S[idx_now:].find(v[j])
        if idx == -1:
            break
        else:
            idx_now += idx + 1
            c += 1
    if c == 3:
        ans += 1
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
kind = len(set(a))
kind_num = []

if kind < k:
    print(0)
    exit()

for num in set(a):
    one = a.count(num)
    kind_num.append(one)

kind_num.sort()
ans = sum(kind_num[:-k])
print(ans)

### FIXED CODE ###

from collections import Counter

n, k = map(int, input().split())
ary = Counter(list(map(int, input().split())))

if len(ary.keys()) <= k:
    print(0)
    exit()

print(sum(sorted(ary.values())[:len(ary.keys())-k]))
### BUGGY CODE ###

N,K = map(int,input().split())
XY = [tuple(map(int,input().split())) for i in range(N)]
xs = []
ys = []
for x,y in XY:
    xs.append(x)
    ys.append(y)
xs.sort()
ys.sort()

def is_ok(l,r,d,u):
    k = 0
    for x,y in XY:
        if l <= x <= r and d <= y <= u:
            k += 1
            if k >= K:
                return True
    return False

ans = float('inf')
for i in range(N-1):
    for j in range(i+1,N):
        for k in range(N-1):
            for l in range(k+1,N):
                l,r,d,u = xs[i],xs[j],ys[k],ys[l]
                if (r-l)*(u-d) >= ans: continue
                if is_ok(l,r,d,u):
                    ans = (r-l)*(u-d)
print(ans)

### FIXED CODE ###

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

xs = []
ys = []
for i in range(N):
    x,y = map(int,input().split())
    xs.append((x,y,i))
    ys.append((y,x,i))
xs.sort()
ys.sort()

x_order = {}
for xo,p in enumerate(xs):
    x,y,i = p
    x_order[i] = xo

cums = [[0 for j in range(N+1)] for i in range(N+1)]
for i in range(N):
    y,x,pi = ys[i]
    xo = x_order[pi]
    for j in range(N+1):
        cums[i+1][j] = cums[i][j] + (1 if j > xo else 0)

ans = float('inf')
for x1 in range(N-1):
    for x2 in range(x1+1,N):
        for y1 in range(N-1):
            for y2 in range(y1+1,N):
                if cums[y2+1][x2+1] - cums[y2+1][x1] - cums[y1][x2+1] + cums[y1][x1] < K:
                    continue
                area = (xs[x2][0] - xs[x1][0]) * (ys[y2][0] - ys[y1][0])
                ans = min(ans, area)
print(ans)
### BUGGY CODE ###

s = input()
mod = 10**9 + 7

dp = [[0] * 13 for _ in range(len(s)+1)]
for i in range(10):
    if s[0] == "?":
        dp[1][i] += 1
    else:
        dp[1][int(s[0])] = 1
        break

for i, v in enumerate(s):
    if i == 0:
        continue
    for j in range(13):
        if v != "?":
            dp[i + 1][(10 * j + int(v)) % 13] += dp[i][j]
            dp[i + 1][(10 * j + int(v)) % 13] %= mod
            continue
        for k in range(10):
            x = (10 * j + k) % 13
            dp[i + 1][x] += dp[i][j]
            dp[i + 1][x] %= mod

print(dp[-1][5])


### FIXED CODE ###

s = input()
mod = 10**9 + 7

dp = [[0] * 13 for _ in range(len(s)+1)]
for i in range(10):
    if s[0] == "?":
        dp[1][i] += 1
    else:
        dp[1][int(s[0])] = 1
        break

for i, v in enumerate(s):
    if i == 0:
        continue
    for j in range(13):
        for k in range(10):
            x = (10 * j + k) % 13
            if v != "?":
                if int(v) == k:
                    dp[i + 1][x] += dp[i][j]
                    dp[i + 1][x] %= mod
                else:
                    dp[i + 1][x] += 0
            else:
                dp[i + 1][x] += dp[i][j]
                dp[i + 1][x] %= mod

print(dp[-1][5])
### BUGGY CODE ###

#D 400

def devide(n):
    tmp = 0
    if 3<=n:
        tmp += 1
    for i in range(3,n+1):
        if n-i>=3:
            tmp += devide(n-i)
    return tmp
    
s = int(input())
print(devide(s)%(10**9+7))



### FIXED CODE ###

#D 400

def devide(n):
    if memo[n]!=-1:
        return memo[n]
    tmp = 0
    if 3<=n:
        tmp += 1
    for i in range(3,n+1):
        if n-i>=3:
            tmp += devide(n-i)
    memo[n] = tmp
    return tmp
    
s = int(input())
memo = [-1 for i in range(s+1)]
print(devide(s)%(10**9+7))
### BUGGY CODE ###

n, money = map(int, input().split())

x = 0 #10000yen
y = 0 #5000yen
z = 0 #1000yen
check = 0

for x in range (n + 1) :
  for y in range (n + 1 - x) :
    for z in range (n + 1 - x - y ) :
      if check == 1 :
        check = 1
      elif x + y + z == n :
        if 10000 * x + 5000 * y + 1000 * z == money :
          check += 1
          print(x,y,z)

if check == 0 :
  print ("-1 -1 -1")

### FIXED CODE ###

n, money = map(int, input().split())

x = 0 #10000yen
y = 0 #5000yen
z = 0 #1000yen
check = 0

for x in range (n + 1) :
  for y in range (n + 1 - x) :
    z = n - x - y
    if check == 1 :
      check = 1
    elif 10000 * x + 5000 * y + 1000 * z == money :
      check += 1
      print(x,y,z)

if check == 0 :
  print ("-1 -1 -1")
### BUGGY CODE ###

N, K = map(int,input().split())
A = sorted(map(int,input().split()))
F = sorted(map(int,input().split()),reverse=True)
low,high = -1, max(map(lambda x,y:x*y, A,F))
while high-low>1:
  mid = (high+low)//2
  k = sum(map(lambda x,y:x-y,A,map(lambda x,y:min(x,y),map(lambda x: mid//x,F), A)))
  if k>K: low = mid
  else: high = mid
print(high)

### FIXED CODE ###

import numpy as np
N, K = map(int,input().split())
A = np.array(sorted(map(int,input().split())))
F = np.array(sorted(map(int,input().split()) ,reverse=True))
low,high = -1, int(1e12)
while high-low>1:
  mid = (high+low)//2
  k = (A-np.minimum(A,mid//F)).sum()
  if k>K: low = mid
  else: high = mid
print(high)
### BUGGY CODE ###

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

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

def calc(i, j, k):
    if i < 0 or j < 0 or k < 0:
        return 0
    if dp[k][j][i] != -1:
        return dp[k][j][i]
    if i == j == k == 0:
        dp[i][j][k] = 0
        return 0
    if i > N or j > J + K or k > K:
        dp[k][i][j] = 0
        return 0
    tmp = N / (i + j + k)
    tmp += i / (i + j + k) * calc(i - 1, j, k)
    tmp += j / (i + j + k) * calc(i + 1, j - 1, k)
    tmp += k / (i + j + k) * calc(i, j + 1, k - 1)
    dp[k][j][i] = tmp
    return tmp

I = 0
J = 0
K = 0
for a in A:
    if a == 1:
        I += 1
    elif a == 2:
        J += 1
    else:
        K += 1

# print (i, j , k)
print (calc(I, J , K))

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = tuple(map(int, input().split()))

    I = A.count(1)
    J = A.count(2)
    K = A.count(3)
    # for a in A:
    #     if a == 1:
    #         I += 1
    #     elif a == 2:
    #         J += 1
    #     else:
    #         K += 1

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

    # def output(lst):
    #     for tmp in lst:
    #         print (tmp)

    for k in range(K + 1):
        for j in range(K + J + 1 - k):
            for i in range(N + 1 - k  - j):
                if i == j == k == 0:
                    continue
                tmp = N
                if i > 0:
                    tmp += i * dp[k][j][i - 1]
                if j > 0:
                    tmp += j * dp[k][j - 1][i + 1]
                if k > 0:
                    tmp += k * dp[k - 1][j + 1][i]
                dp[k][j][i] = tmp / (i + j + k)

    print (dp[K][J][I])

    # output(dp)

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

import math
N=int(input())
C=0

for l in range(N):
    for n in range(N):
        for m in range(N):
            if l==0 or m==0 or n==0:
                C+=1
            else:
                C+=math.gcd(math.gcd(l+1,m+1),n+1)

print(C)

### FIXED CODE ###

import math
N=int(input())
C=0
 
for l in range(N):
    for n in range(N):
        for m in range(N):
            if l==0 or m==0 or n==0:
                C+=1
            else:
                C+=math.gcd(math.gcd(l+1,m+1),n+1)
 
print(C)
### BUGGY CODE ###

#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    A = list(map(int, input().split()))
    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a % b)
    
    def gcd_group(arr):
        g = gcd(arr[0], arr[1])
        for i in range(2, len(arr)):
            g = gcd(g, arr[i])
        return g
    
    def lcm(a, b):
        g = gcd(a, b)
        return (a*b)//g
    
    def lcm_group(arr):
        l = lcm(arr[0], arr[1])
        for i in range(2, len(arr)):
            l = lcm(l, arr[i])
        return l
    
    if len(A) == 2:
        print(max(A))
        exit()
    res = 0
    for i in range(N):
        arr = A[:i] + A[i+1:]
        res = max(res, gcd_group(arr))
    print(res)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter
    #inf = 10**17
    #mod = 10**9 + 7

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

    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a % b)
    
    def gcd_group(arr):
        g = gcd(arr[0], arr[1])
        for i in range(2, len(arr)):
            g = gcd(g, arr[i])
        return g
    
    def lcm(a, b):
        g = gcd(a, b)
        return (a*b)//g
    
    def lcm_group(arr):
        l = lcm(arr[0], arr[1])
        for i in range(2, len(arr)):
            l = lcm(l, arr[i])
        return l
    
    l = [0]
    for i in range(N-1):
        l.append(gcd(l[-1], A[i]))
    r = [0]
    for i in range(N-1, 0, -1):
        r.append(gcd(r[-1], A[i]))
    
    res = 0
    for i in range(N):
        res = max(res, gcd(l[i], r[-(i+1)]))
    print(res)


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

H,W,D = [int(n) for n in raw_input().split(" ")]
A = [[None] * (W + 1)] * (H + 1)
Location = {}
for h in range(1,H + 1):
	A[h][1:W+1] = [int(n) for n in raw_input().split(" ")]
	for w, a in enumerate(A[h]):
		Location[a] = (h, w)
Q = int(raw_input())
L = [None] * (Q+1)
R = [None] * (Q+1)
for q in range(1,Q+1):
	L[q], R[q] = [int(n) for n in raw_input().split(" ")]



C = {}
for l in L:
	C[l,l] = 0
for q in range(1,Q+1):
	l = L[q]
	r = R[q]
	cur_dist = 0
	for x1 in range(l, r, D):
		x2 = x1 + D
		if (x1,x2) not in C:
			h1, w1 = Location[x1]
			h2, w2 = Location[x2]
			C[(x1, x2)] = abs(h1 - h2) + abs(w1 - w2)
		cur_dist = cur_dist + C[(x1,x2)]
		C[(l,x2)] = cur_dist
	print C[(l,r)]


### FIXED CODE ###

H,W,D = [int(n) for n in raw_input().split(" ")]
Location = {}
for h in range(1,H + 1):
	A = [int(n) for n in raw_input().split(" ")]
	for w, a in enumerate(A):
		Location[a] = (h, w+1)
Q = int(raw_input())
L = [None] * (Q+1)
R = [None] * (Q+1)
for q in range(1,Q+1):
	L[q], R[q] = [int(n) for n in raw_input().split(" ")]



C = {}
for d in range(1,D+1):
	C[d,d] = 0
	cur_dist = 0
	for x1 in range(d, H * W + 1, D):
		x2 = x1 + D
		if x2 > H * W: 
			break
		h1, w1 = Location[x1]
		h2, w2 = Location[x2]
		#C[(x1, x2)] = abs(h1 - h2) + abs(w1 - w2)
		cur_dist = cur_dist + abs(h1 - h2) + abs(w1 - w2)
		C[(d,x2)] = cur_dist
	
for q in range(1,Q+1):
	l, r = L[q], R[q]
	d = l % D
	if d == 0: 
		d = D
	print (C[(d,r)] - C[(d,l)])
### BUGGY CODE ###

n, x = map(int, input().split())
a_list = list(map(int, input().split()))
minimum = 10000000000
dist_list = []
for i,a in enumerate(a_list):
  minimum = min(abs(a - x), minimum)
  if i == 0:
    continue
  dist_list.append(abs(a_list[i-1] - a))

while minimum != 1:
  flag = 0
  for d in dist_list:
    if d % minimum != 0:
      flag = 1
  if flag == 0:
    break
  else:
    minimum -= 1

print(minimum)



### FIXED CODE ###

import fractions
from functools import reduce

def gcd(a, b):
  while b:
    a, b = b, a % b
    return a

def gcds(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n, x = map(int, input().split())
a_list = list(map(int, input().split()))
minimum = 10000000000
dist_list = []
for i,a in enumerate(a_list):
  minimum = min(abs(a - x), minimum)
  if i == 0:
    continue
  dist_list.append(abs(a_list[i-1] - a))

dist_list.append(minimum)

print(gcd_list(dist_list))
### BUGGY CODE ###

from collections import Counter

n = int(input())
aL = [set(Counter(input()).most_common()) for i in range(n)]
count = 0

for i in range(n-1):
    for j in range(i+1, n):
        if aL[i] == aL[j]:
            count +=1

print(count)

### FIXED CODE ###

from collections import Counter
N = int(input())
S = [input() for i in range(N)]
counter = Counter()
ans = 0
for s in S:
    a = ''.join(sorted(list(s)))
    if a in counter:
        ans += counter[a]
    counter[a] += 1
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from bisect import bisect_left
from sys import stdin
from heapq import heappush, heappop



readl = stdin.readline

## input
N,Q = map(int, readl().rstrip().split())
STX = [list(map(int, readl().rstrip().split())) for _ in range(N)]
Dn = [None for _ in range(Q+1)]
for i in range(Q):
  Dn[i] = int(readl().rstrip())
Dn[Q] = 10**10
ans = []

for s,t,x in sorted(STX,key=lambda x:x[2]):
  l = r = bisect_left(Dn,s-x)
  t -= x
  while Dn[r] < t:
    heappush(ans, (Dn[r],x))
    r += 1
  del Dn[l:r]

for d in Dn[:-1]:
  heappush(ans, (d,-1))

[print(heappop(ans)[1]) for _ in range(Q)]  


### FIXED CODE ###

import sys
from bisect import bisect_left



N,Q = map(int, input().split())
lines = sys.stdin.readlines()
kkk = []
for line in lines[:N]:
  s, t, x = map(int, line.split())
  kkk.append((x, s, t))
kkk.sort()
ddd = list(map(int, lines[N:]))

ans = [-1] * Q
skip = [-1] * Q
for x, s, t in kkk:
  ss = bisect_left(ddd, s - x)
  tt = bisect_left(ddd, t - x)
  while ss < tt:
    sk = skip[ss]
    if sk == -1:
      ans[ss] = x
      skip[ss] = tt
      ss += 1
    else:
      ss = sk

print('\n'.join(map(str, ans)))
### BUGGY CODE ###

import bisect

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A.sort()
B.sort()
C.sort()

up_mid = [N - bisect.bisect_right(B, x) for x in A]
mid_down = [N - bisect.bisect_right(C, x) for x in B]

ans = 0
for i in up_mid:
    ans += sum(mid_down[::-1][:i])
print(ans)

### FIXED CODE ###

import bisect

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A.sort()
B.sort()
C.sort()

ans = 0
for b in B:
    ans += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b))
print(ans)
### BUGGY CODE ###

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

### FIXED CODE ###

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

N = int(input())
A = list(map(int, input().split()))
f = [[a] for a in A]
l = 1<<N
for i in range(N):
    b = 1<<i
    j = 0
    while j < l:
        j |= b
        f[j] = sorted(f[j]+f[j^b], reverse=True)[:2]
        j += 1
Ans = [sum(f[1])]
for a, b in f[2:]:
    Ans.append(max(Ans[-1], a+b))
print("\n".join(map(str, Ans)))


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
f = [[a] for a in A]
for i in range(N):
    for j in range(1<<N):
        if j & 1<<i:
            f[j] = sorted(f[j]+f[j^1<<i], reverse=True)[:2]
Ans = [sum(f[1])]
for a, b in f[2:]:
    Ans.append(max(Ans[-1], a+b))
print("\n".join(map(str, Ans)))
### BUGGY CODE ###

def resolve():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    grid = []
    for i in range(M):
        array = list(map(int, input().strip().split()))
        grid.append(array)

    totals = []
    res = 10000 + 10000
    for i in range(A):
        total = []
        for j in range(B):
            value = a[i]+b[j]
            total.append(value)
            if value < res:
                res = value
        
        totals.append(total)

    for m in grid:
        if m[0]-1 < A and m[1]-1 < B:
            tmp = totals[m[0]-1][m[1]-1] - m[2]
    
            if tmp < res:
                res = tmp

    print(res)
    
resolve()

### FIXED CODE ###

def resolve():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    grid=[list(map(int,input().split())) for i in range(M)]

    res = min(a) + min(b)
    for m in grid:
        if m[0]-1 < A and m[1]-1 < B:
            tmp = a[m[0]-1] + b[m[1]-1] - m[2]
        
            if tmp < res:
                res = tmp

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

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

K = set(range(1, N + 1))
for i in range(M):
    l, r = map(int, input().split())
    K = K & set(range(l, r + 1))

print(len(K))

### FIXED CODE ###

N, M = map(int, input().split())
L = 1
R = N

for i in range(M):
    l, r = map(int, input().split())
    
    if l > L:
        L = l
#        print('L ' + str(L))
    if r < R:
        R = r
#        print('R ' + str(R))
        
if L > R:
    print(0)
else:
    print(R - L + 1)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import defaultdict

def empty_list():
    return [0] * 26

class RollingHash():
    def __init__(self, s):
        length = len(s)
        base = 1009
        self.mod = (1 << 61) - 1
        self.hash = [0] * (length + 2)
        self.pow = [1] * (length + 2)

        for i in range(length):
            self.hash[i+1] = (self.hash[i] + s[i]) * base % self.mod
            self.pow[i+1] = self.pow[i] * base % self.mod
        self.pow[length+1] = self.pow[length] * base % self.mod 

    def get(self, l, r):
        t = self.hash[r] - self.hash[l] * self.pow[r-l] % self.mod
        return t % self.mod

ss = []
n = int(input())
for _ in range(n):
    ss.append([ord(item) for item in input().rstrip()])
ss.sort(key=lambda x: len(x), reverse=True)

orda = ord("a")
words = defaultdict(empty_list)
ans = 0
for s in ss:
    word_len = len(s)
    s_rev = s[::-1]
    RH = RollingHash(s_rev)
    rh = RH.get(0, word_len-1)
    ans += words[rh][s_rev[-1] - orda]
    initial = [0] * 26 
    for i, ch in enumerate(s):
        initial[ch - orda] = 1
        for j, is_initial in enumerate(initial):
            if is_initial:
                rh = RH.get(0, word_len-i-1)
                words[rh][j] += 1
print(ans)

### FIXED CODE ###

#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import defaultdict

def empty_list():
    return [0] * 26

class RollingHash():
    def __init__(self, s):
        length = len(s)
        base = 1009
        # self.mod = (1 << 61) - 1
        self.mod = 67280421310721
        self.hash = [0] * (length + 2)
        self.pow = [1] * (length + 2)

        for i in range(length):
            self.hash[i+1] = (self.hash[i] + s[i]) * base % self.mod
            self.pow[i+1] = self.pow[i] * base % self.mod
        self.pow[length+1] = self.pow[length] * base % self.mod 

    def get(self, l, r):
        t = self.hash[r] - self.hash[l] * self.pow[r-l] % self.mod
        return t % self.mod

ss = []
n = int(input())
for _ in range(n):
    ss.append([ord(item) for item in input().rstrip()])
ss.sort(key=lambda x: len(x), reverse=True)

orda = ord("a")
words = defaultdict(empty_list)
ans = 0
for s in ss:
    word_len = len(s)
    s_rev = s[::-1]
    RH = RollingHash(s_rev)
    rh = RH.get(0, word_len-1)
    ans += words[rh][s_rev[-1] - orda]
    initial = [0] * 26 
    for i, ch in enumerate(s):
        initial[ch - orda] = 1
        for j, is_initial in enumerate(initial):
            if is_initial:
                rh = RH.get(0, word_len-i-1)
                words[rh][j] += 1
print(ans)
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding:utf-8 -*-

from queue import deque

# def main():
#   h, w = map(int, input().split())
#   grids = [list(input().strip()) for _ in range(h)]
#   dq = deque()
#   for i in range(h):
#     for j in range(w):
#       if grids[i][j] == '#':
#         dq.append((0, i, j))
  
#   mcnt = -1
#   while dq:
#     cnt, i, j = dq.popleft()
#     for dx, dy in zip([-1, 0, 1, 0], [0, -1, 0, 1]):
#       if 0 <= i+dx < h and 0 <= j+dy < w and grids[i+dx][j+dy] == '.':
#         grids[i+dx][j+dy] = '#'
#         dq.append((cnt+1, i+dx, j+dy))
#   print(cnt)
def main():
  h, w = map(int, input().split())
  grids = [list(map(lambda x: 1 if x=='#' else 0, input().strip())) for _ in range(h)]
  dq = deque()
  for i in range(h):
    for j in range(w):
      if grids[i][j] == 1:
        dq.append((0, i, j))
  
  mcnt = -1
  while dq:
    cnt, i, j = dq.popleft()
    for dx, dy in zip([-1, 0, 1, 0], [0, -1, 0, 1]):
      if 0 <= i+dx < h and 0 <= j+dy < w and grids[i+dx][j+dy] == 0:
        grids[i+dx][j+dy] = 1
        dq.append((cnt+1, i+dx, j+dy))
  print(cnt)
  
if __name__=='__main__':
  main()



### FIXED CODE ###

#!/usr/bin/python3
# -*- coding:utf-8 -*-

from queue import deque

def main():
  h, w = map(int, input().split())
  grids = [False] * (w * h)
  dq = deque()
  for i in range(h):
    for j, c in enumerate(list(input().strip())):
      if c == '#':
        grids[i*w + j] = True
        dq.append((0, i, j))
  
  while dq:
    cnt, i, j = dq.popleft()
    for dx, dy in zip([-1, 0, 1, 0], [0, -1, 0, 1]):
      if 0 <= i+dx < h and 0 <= j+dy < w and not grids[(i+dx)*w + (j+dy)]:
        grids[(i+dx)*w + (j+dy)] = True
        dq.append((cnt+1, i+dx, j+dy))
  print(cnt)
  
if __name__=='__main__':
  main()
### BUGGY CODE ###

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

ans = []
start = 0
for i in range(1, N+1):
    cnt = 0
    if i > max(A) :
        ans.append(0)
        continue
    for a in range(start, N-1):
        if A[a] == i:
            cnt += 1
        if A[a] > i:
            start = a
            ans.append(cnt)
            break
    else:
        ans.append(cnt)

print(*ans, sep='\n')


### FIXED CODE ###

import collections

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

ans = collections.Counter(A)

for n in range(N):
    print(ans[n+1])
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
if 0 in a :
    ans = 0
else:
    for i in a :
        ans *= i

if ans > 10**18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
if 0 in a :
    ans = 0
    print(0)
else:
    for i in a :
        ans *= i
        if ans > 10**18:
            print(-1)
            break
    else:
        print(ans)