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

import math
import collections

def combinations_count(n, r):
 
    if n < r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

for i in a:
    res = 0
    t = a[:]
    t.remove(i)
    c = collections.Counter(t)
    for v in c.values():
        if v >= 2:
            res += combinations_count(v, 2)
    
    print(res)

### FIXED CODE ###

import collections


m = int(input())
A = list(map(int,input().split()))[:m]
c = collections.Counter(A)
 
def hoge(n):
    return n * (n - 1) // 2

full = sum([ hoge(i) for i in c.values()])

for a in A:
    print(full - hoge(c[a]) + hoge(c[a]-1))
### BUGGY CODE ###

A,B,C,D = map(int, input().split())

P=998244353

dp = [[[0 for k in range(2)] for j in range(3002)] for i in range(3002)]
dp[A][B][1] = 1

for row in range(A, C + 1):
    for col in range(B, D + 1):
        dp[row][col + 1][1] += dp[row][col][0] + row * dp[row][col][1]
        dp[row][col + 1][1] %= P
        dp[row + 1][col][0] = col * (dp[row][col][0] + dp[row][col][1])

print((dp[C][D][0]+dp[C][D][1])%P)

### FIXED CODE ###

A,B,C,D = map(int, input().split())

P=998244353

dp = [[0 for j in range(3002)] for i in range(3002)]
dp[A][B] = 1

for row in range(A, C + 1):
    for col in range(B, D + 1):
        dp[row][col] += col * dp[row - 1][col] + row * dp[row][col - 1]
        dp[row][col] -= (row - 1) * (col - 1) * dp[row - 1][col - 1]
        dp[row][col] %= P

print(dp[C][D])
### BUGGY CODE ###

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

dp = [10**10] * N

dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i+k < N:
            dp[i+k] = min(dp[i+k], dp[i] + abs(h[i]-h[i+k]))
        else:
            break
print(dp[N-1])

### FIXED CODE ###

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

dp = [10**10] * N

dp[0] = 0
for i in range(N):
    for k in range(1, K+1):
        if i+k < N:
            dp[i+k] = min(dp[i+k], dp[i] + abs(h[i]-h[i+k]))
        else:
            break
print(dp[N-1])
### BUGGY CODE ###

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

#隣接する最大の部分をとって(N+1)/2すればいい

max_part = 0
for i in range(N-K+1):
    max_part = max(sum(ps[i:i+K]),max_part)

print((max_part+K)/2)

### FIXED CODE ###

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

max_sum = sum(ps[:K])
num = sum(ps[:K])

for i in range(N-K):
    num = num - ps[i] + ps[i+K]
    max_sum = max(max_sum,num)
    

print((max_sum+K)/2)
### BUGGY CODE ###

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

n = 0

for x in range(S+1) :
        for y in range(S+1) :
                if (K >= x) and (K >= y) and (S >= x + y) and (S-x-y <= K):
                       n = n + 1

                
print(n)

### FIXED CODE ###

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

n = 0

for x in range(K+1) :
        if (S - x <= 2 * K):
                for y in range(K+1) :
                        if 0 <=S-x-y <= K:
                                n += 1

                
print(n)
### BUGGY CODE ###

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int, input().split()))
D = sorted(A)
ans_str = ""
for i in range(n):
    if i == n-1:
        ans_str += str(A.index(D[i])+1)
        print(ans_str)
        exit()
    ans_str += str(A.index(D[i])+1) + " "

### FIXED CODE ###

import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n=int(input())
A=[(e,i) for i,e in enumerate(list(map(int,input().split())))]
#print(A)
A.sort(key=lambda tup: tup[0])
#print(A)
for e,i in A:
    print(i+1)
### BUGGY CODE ###

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

result = 0
for i in range(n):
    counter = 0
    temp = 0
    for j in range(i, n):
        if a[j] ^ temp != a[j] + temp:
            temp = a[j]
            break
        else:
            temp += a[j]
            counter += 1
    result += counter


print(result)

### FIXED CODE ###

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

result = 0
counter = 1
temp = 0
for i in range(n):
    counter -= 1
    start = i + counter
    for j in range(start, n):
        if a[j] ^ temp != a[j] + temp:
            temp -= a[i]
            break
        else:
            temp += a[j]
            counter += 1
    result += counter


print(result)
### BUGGY CODE ###

r, g, b, n = [int(i) for i in input().split()]
 
ans = 0
 
for i in range(n + 1):
    for j in range(n + 1):
        if (n - (i * r + j * g)) % b == 0 and (n - (i * r + j * g)) // b >= 0:
            ans += 1
 
print(ans)

### FIXED CODE ###

r,g,b,n = (int(i) for i in input().split())
ans = 0
for i in range(n//r+1):
    for j in range((n-(i*r))//g+1):
        k = (n-r*i-j*g)//b
        if r*i+j*g+abs(k*b) == n:
            ans += 1
print(ans)
### BUGGY CODE ###

N, M, Q = map( int, input().split())
NN = [ [ 0 for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M):
    L, R = map( int, input().split())
    for i in range(L+1):
        for j in range(R,N+1):
            NN[i][j] += 1
for _ in range(Q):
    p, q = map(int, input().split())
    print(NN[p][q])

### FIXED CODE ###

N, M, Q = map( int, input().split())
NN = [ [0 for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M):
    L, R = map( int, input().split())
    NN[L][R] += 1

for i in range(1,N+1):
    for j in range(1,N+1):
        NN[i][j] += NN[i][j-1]+NN[i-1][j]-NN[i-1][j-1]
for _ in range(Q):
    p, q = map( int, input().split())
    print(NN[q][q]-NN[q][p-1]-NN[p-1][q]+NN[p-1][p-1])
### BUGGY CODE ###

def getInput():
    return [int(i) for i in input().rstrip().split(' ')]

def swap(x, K):
    return abs(x-K)

N, K = getInput()
x = N
mins = x

while(mins > 0):
    if K == 1:
        mins = 0
    x = swap(x, K)
    if  x < mins:
        mins = x
    else:
        break

print(mins)

### FIXED CODE ###

def getInput():
    return [int(i) for i in input().rstrip().split(' ')]

N, K = getInput()
t = N % K 
print(min(t, K -t))
### BUGGY CODE ###

s = input()
q = int(input())
for _ in range(q):
    a = input().split()
    if a[0] == '1':
        s = s[::-1]
    else:
        if a[1] == '1':
            s = a[2] + s
        else:
            s = s + a[2]
print(s)


### FIXED CODE ###

s = input()
d = True
f = '' # Front
b = '' # Back
q = int(input())
for _ in range(q):
    a = input().split()
    if a[0] == '1':
        d = not d
    else:
        if a[1] == '1':
            if d:
                f = ''.join([a[2], f])
            else:
                b = ''.join([b, a[2]])
        else:
            if d:
                b = ''.join([b, a[2]])
            else:
                f = ''.join([a[2], f])

if not d:
    print(''.join([b[::-1], s[::-1], f[::-1]]))
else:
    print(''.join([f, s, b]))
### BUGGY CODE ###


import sys
sys.setrecursionlimit(10**6)
def main():
    n, q = map(int, input().split())
    to = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b = map(lambda x: int(x)-1, input().split())
        to[a].append(b)
        to[b].append(a)

    node = [0 for _ in range(n)]
    for _ in range(q):
        p, x = map(int, input().split())
        p -= 1
        node[p] += x  
    def dfs(v, p=-1):
        for u in to[v]:
            if u == p:
                continue
            else:
                node[u] += node[v]
                dfs(u, v)
    dfs(0)
    for i in range(n):
        if i == n-1:
            print(node[i])
        else:
            print(node[i], end=' ')
main()


### FIXED CODE ###

#python3
from collections import deque 
def main():
    n, q = map(int, input().split())
    to = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b = map(lambda x: int(x)-1, input().split())
        to[a].append(b)
        to[b].append(a)

    node = [0 for _ in range(n)]

    for _ in range(q):
        p, x = map(int, input().split())
        node[p-1] += x

    dq = deque() 
    dq.append(0)
    done = [0 for _ in range(n)]
    done[0] = 1
    while len(dq) > 0:
        x = dq.popleft()
        for i in to[x]:
            if done[i] == 1:
                continue
            node[i] += node[x]
            done[i] = 1 
            dq.append(i)

    for i in range(n):
        print(node[i]) if i == n-1 else print(node[i], end=' ')
main()
### BUGGY CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
m=1
for i in A[:K]:m=m*i
p=m
for i in range(K,N):
    m=(m*A[i])//A[i-K]
    if K-1<i:print('Yes' if p<m else 'No')
    p=m

### FIXED CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(K,N):
    print('Yes' if A[i-K]<A[i] else 'No')
### BUGGY CODE ###

import math
import sys
A,B,N=map(int, input().split())
NUM=0
if N<B:
    NUM=math.floor(A*N/B)-A*math.floor(N/B)
    print(NUM)
    sys.exit()
else:
    if A>B:
        for x in range(N+1,math.floor(N/2),-1):
            TGT=math.floor(A*x/B)-A*math.floor(x/B)
            if TGT>NUM:
                NUM=TGT
    else:
        for x in range(1,math.floor(N/2)+1):
            TGT=math.floor(A*x/B)-A*math.floor(x/B)
            if TGT>NUM:
                NUM=TGT
print(NUM)

### FIXED CODE ###

A,B,N = (map(int , input().split()))
min(B-1,N)
x = min(B-1,N)
print(((A*x)//B - A * (x//B)))
### BUGGY CODE ###

n, m = map(int, input().split())
city_list = [[0] for _ in range(n + 1)]
city = [[]]
for _ in range(m):
    p, y = map(int, input().split())
    city_list[p].append(y)
    city.append([p, y])
for i in range(1, n + 1):
    city_list[i].sort()
for i in range(1, m + 1):
    ID = ''
    p = city[i][0]
    order = str(city_list[p].index(city[i][1]))
    p = str(p)
    ID = ID + ('0' * (6 - len(p)))
    ID += p
    ID += ('0' * (6 - len(order)))
    ID += order
    print(ID)

### FIXED CODE ###

from bisect import bisect_left
n, m = map(int, input().split())
city_list = [[0] for _ in range(n + 1)]
city = [[]]
for _ in range(m):
    p, y = map(int, input().split())
    city_list[p].append(y)
    city.append([p, y])
for i in range(1, n + 1):
    city_list[i].sort()
for i in range(1, m + 1):
    ID = ''
    p = city[i][0]
    order = str(bisect_left(city_list[p], city[i][1]))
    #order = str(city_list[p].index(city[i][1]))
    p = str(p)
    ID = ID + ('0' * (6 - len(p)))
    ID += p
    ID += ('0' * (6 - len(order)))
    ID += order
    print(ID)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(100000)

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

def uft_root(g, a):
	if g[a] < 0:
		return a
	g[a] = uft_root(g, g[a])
	return g[a]

def uft_size(g, a):
	return -g[uft_root(g, a)]

def uft_merge(g, a, b):
	a, b = uft_root(g, a), uft_root(g, b)
	if a == b:
		return
	size_a, size_b = uft_size(g, a), uft_size(g, b)
	if size_a < size_b:
		a, b = b, a
		size_a, size_b = size_b, size_a
	g[a] -= size_b
	g[b] = a

g_pq = [[] for _ in range(N)]
for p, q in PQ:
	p, q = p - 1, q - 1
	g_pq[p] += [q]
	g_pq[q] += [p]

g_rs = [[] for _ in range(N)]
for r, s in RS:
	r, s = r - 1, s - 1
	g_rs[r] += [s]
	g_rs[s] += [r]

def dfs(v, g, uft, visited):
	if visited[v]:
		return
	visited[v] = True
	for n in g[v]:
		if visited[n]:
			continue
		uft_merge(uft, v, n)
		dfs(n, g, uft, visited)

visited_pq = [False] * N
visited_rs = [False] * N
uft_pq = [-1] * N
uft_rs = [-1] * N

for n in range(N):
	dfs(n, g_pq, uft_pq, visited_pq)
	dfs(n, g_rs, uft_rs, visited_rs)

group_pq, group_rs = {}, {}
for n in range(N):
	root_pq = uft_root(uft_pq, n)
	if not root_pq in group_pq:
		group_pq[root_pq] = {n}
	else:
		group_pq[root_pq] |= {n}
	root_rs = uft_root(uft_rs, n)
	if not root_rs in group_rs:
		group_rs[root_rs] = {n}
	else:
		group_rs[root_rs] |= {n}

for n in range(N):
	print(len(group_pq[uft_root(uft_pq, n)] & group_rs[uft_root(uft_rs, n)]), "", end="")
print()


### FIXED CODE ###

from collections import defaultdict as dd

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

def uft_root(g, a):
	if g[a] < 0:
		return a
	g[a] = uft_root(g, g[a])
	return g[a]

def uft_size(g, a):
	return -g[uft_root(g, a)]

def uft_merge(g, a, b):
	a, b = uft_root(g, a), uft_root(g, b)
	if a == b:
		return
	size_a, size_b = uft_size(g, a), uft_size(g, b)
	if size_a < size_b:
		a, b = b, a
		size_a, size_b = size_b, size_a
	g[a] -= size_b
	g[b] = a

uft_pq = [-1] * N
uft_rs = [-1] * N

for p, q in PQ:
	p, q = p - 1, q - 1
	uft_merge(uft_pq, p, q)
for r, s in RS:
	r, s = r - 1, s - 1
	uft_merge(uft_rs, r, s)

group = dd(int)
for n in range(N):
	group[(uft_root(uft_pq, n), uft_root(uft_rs, n))] += 1

result = []
for n in range(N):
	result += [group[(uft_root(uft_pq, n), uft_root(uft_rs, n))]]
print(" ".join(map(str, result)))
### BUGGY CODE ###

#!/usr/bin/env python3

import sys

debug = False

def solve(ds, n, x, m):
    ds = list(ds)
    cnt_zero_in_d = 0
    for i in range(0, len(ds)):
        ds[i] %= m
        if ds[i] == 0:
            cnt_zero_in_d += 1
    a_n = x + sum(ds[0:(n - 1) % len(ds)]) + ((n - 1) // len(ds) * sum(ds)) 
    cnt_same = ds[0:(n - 1) % len(ds)].count(0) + ((n - 1) // len(ds) * cnt_zero_in_d)
    cnt_decrease = a_n // m - x // m
    return n - 1 - cnt_decrease - cnt_same


def read_int_list(sep = " "):
    return [int(s) for s in sys.stdin.readline().rstrip().split(sep)]


def dprint(*args, **kwargs):
    if debug:
        print(*args, **kwargs)
    return


def main():
    k, q = read_int_list()
    d = read_int_list()
    for _ in range(0, q):
        n, x, m = read_int_list()
        print(str(solve(d, n, x, m)))
    

if __name__ == "__main__":
    main()

### FIXED CODE ###

#!/usr/bin/env python3

import sys

debug = False

def solve(ds, n, x, m):
    ds = [d % m for d in ds]

    nr_loop = (n - 1) // len(ds)
    lastloop_remaining = (n - 1) % len(ds)
    a_n = x
    cnt_zero = 0
    for i in range(0, len(ds)):
        dmod = ds[i] % m
        a_n += (dmod) * nr_loop
        if dmod == 0:
            cnt_zero += nr_loop
        if i < lastloop_remaining:
            a_n += dmod
            if dmod == 0:
                cnt_zero += 1
    cnt_decrease = a_n // m - x // m
    return n - 1 - cnt_decrease - cnt_zero


def read_int_list(sep = " "):
    return [int(s) for s in sys.stdin.readline().split(sep)]


def dprint(*args, **kwargs):
    if debug:
        print(*args, **kwargs)
    return


def main():
    k, q = read_int_list()
    d = read_int_list()
    for _ in range(0, q):
        n, x, m = read_int_list()
        print(str(solve(d, n, x, m)))
    

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

#!/usr/bin/env python3
import sys
from itertools import accumulate
from bisect import bisect_left

N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

A2 = sorted(A, reverse=True)
A = sorted(A)


# 必要となる左右合計の下限値 X を求める

def f1(m):
    cnt = 0
    for a1 in A2:
        flg = False
        for a2 in A2:
            if cnt >= M:
                break
            if a1 + a2 < m:
                break
            else:
                flg = True
                cnt += 1
        if not flg:
            break
    return cnt >= M


l = 0
r = A2[0] * 2 + 10

while r - l > 1:
    m = (l + r) // 2
    if f1(m):
        l = m
    else:
        r = m

X = l
# print('X', X)

acc = list(accumulate(A2))  # 累積和

total_cnt = 0
ans = 0
for a in A2:
    # a を左手としたときの右手の最小値
    min_right = X - a

    # 右手の値から出す手数を算出
    idx = bisect_left(A, min_right)
    cnt = N - idx

    # それらの全合計を加算
    ans += a * cnt + acc[cnt - 1]
    total_cnt += cnt
    if total_cnt >= M:
        break
# total_cnt が大きすぎる場合は, その分だけ Xを減算. X は必要な両手合計の最小値なので, 減算すべきは必ず X*出しすぎた分 となる
if total_cnt > M:
    ans -= X * (total_cnt - M)
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from itertools import accumulate
from bisect import bisect_left

N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

A2 = sorted(A, reverse=True)
A = sorted(A)


# 必要となる左右合計の下限値 X を求める

def f1(m):
    cnt = 0
    for a1 in A2:
        tmp = bisect_left(A, m - a1)
        if tmp == N: break
        cnt += N - tmp

    return cnt >= M


l = 0
r = A2[0] * 2 + 10

while r - l > 1:
    m = (l + r) // 2
    if f1(m):
        l = m
    else:
        r = m

X = l
# print('X', X)

acc = list(accumulate(A2))  # 累積和

total_cnt = 0
ans = 0
for a in A2:
    # a を左手としたときの右手の最小値
    min_right = X - a
    if min_right > A[-1]:
        continue

    # 右手の値から出す手数を算出
    idx = bisect_left(A, min_right)
    cnt = N - idx

    # それらの全合計を加算
    ans += a * cnt + acc[cnt - 1]
    total_cnt += cnt

    # if total_cnt >= M:
    #     break
# total_cnt が大きすぎる場合は, その分だけ Xを減算. X は必要な両手合計の最小値なので, 減算すべきは必ず X*出しすぎた分 となる
if total_cnt > M:
    ans -= X * (total_cnt - M)
print(ans)
### BUGGY CODE ###

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

dp = [[] for _ in range(n)] 

for i in range(m):
    p = ls[i][0]
    y = ls[i][1]
    dp[p - 1].append(y)

for j in range(n):
    dp[j].sort()

for k in range(m):
    p = ls[k][0]
    y = ls[k][1]
    th = dp[p - 1].index(y) + 1
    print(str(p).zfill(6) + str(th).zfill(6))

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

    dp = [[] for _ in range(n)]
    ans = [0] * m

    for i in range(m):
        p, y = map(int, input().split())
        dp[p - 1].append((y, i))
    
    for j, k in enumerate(dp):
        k.sort()    
        for l, (s, t) in enumerate(k):
            ans[t] = str(j + 1).zfill(6) + str(l + 1).zfill(6)
    
    print(*ans, sep = "\n")


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

def resolve():
	S=input()
	chk=1
	cnt=0
	while chk==1:
		chk=0
		if len(S)==0:
			break
		if '10' in S:
			cnt+=S.count('10')
			S=S.replace('10','')
			chk=1
		if '01' in S:
			cnt+=S.count('01')
			S=S.replace('01','')
			chk=1
	print(cnt*2)
resolve()

### FIXED CODE ###

def resolve():
	S=input()
	print(min(S.count('1'),S.count('0'))*2)
resolve()
### BUGGY CODE ###

n = int(input())
list_a = []
for i in range(0,n):
    list_a.append(int(input()))
def search(number):
    for i in range(0,n):
        if list_a[i] == number:
            return list_a.index(number) + 1
number = 2
count = 0
while True:
    number = search(number)
    count += 1
    if number == 1:
        print(count)
        break
    if count > n:
        print(-1)
        break


### FIXED CODE ###

n = int(input())
list_a = []
for i in range(0,n):
    list_a.append(int(input()))
number = 0
count = 0
while True:
    number = list_a[number] - 1        
    count += 1
    if number == 1:
        print(count)
        break
    if count > n:
        print(-1)
        break
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(k):
    b = [0] * (n + 1)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    a[0] = b[0]
    for i in range(1, n):
        a[i] = b[i] + a[i - 1]
    if sum(a) == pow(n, 2):
        break
print(*a)

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(k):
    b = [0] * (n + 1)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    a[0] = b[0]
    for i in range(1, n):
        a[i] = b[i] + a[i - 1]
    if sum(a) == pow(n, 2):
        break
print(*a)
### BUGGY CODE ###

s = str(input())
l = []
for i in range(len(s)):
    for j in range(len(s)-1,0,-1):
        if s[i] == "A":
            if s[j] == "Z":
                l.append((j+1-i))
                break
print(max(l))

### FIXED CODE ###

s = str(input())
a = []
b = []
for i in range(len(s)):
    if s[i] == "A":
        a.append(i)
    elif s[i] == "Z":
        b.append(i)
print(max(b)-min(a)+1)
### BUGGY CODE ###

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
s=s0()

import itertools
print(len(set(itertools.combinations(s,3))))

### FIXED CODE ###

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
s=s0()

a=[0]*1000
for i in range(1000):
    num=str(i).zfill(3)
    j=0
    for x in s:
        if x==num[j]:
            j+=1
        if j==3:
            a[i]=1
            break
print(sum(a))
### BUGGY CODE ###

N, K = map(int, input().split())
S = input()
l = []
a = 0
if S[0] == '1':
	a += 1
else:
	l.append(a)
	a += 1
for i in range(1, N, 1):
	if S[i] == S[i - 1]:
		a += 1
	else:
		l.append(a)
		a = 1
l.append(a)
if S[N - 1] == '0':
	l.append(0)
if (len(l) - 1) // 2 + 1 - K < 1:
	print(N)
else:
	m = []
	for k in range((len(l) - 1) // 2 + 1 - K):
		m.append(sum(l[2 * k:2 * k + 2 * K + 1]))
	print(max(m))


### FIXED CODE ###

N, K = map(int, input().split())
S = input()
l = []
a = 0
if S[0] == '1':
	a += 1
else:
	l.append(a)
	a += 1
for i in range(1, N, 1):
	if S[i] == S[i - 1]:
		a += 1
	else:
		l.append(a)
		a = 1
l.append(a)
if S[N - 1] == '0':
	l.append(0)
if (len(l) + 1) // 2 - K < 1:
	print(N)
else:
	ans = sum(l[0:2 * K + 1])
	n_ans = ans
	for k in range((len(l) - 1) // 2 - K):
		n_ans += l[2 * k + 2 * K + 1] + l[2 * k + 2 * K + 2] - l[2 * k] - l[2 * k + 1]
		ans = max(ans, n_ans)
	print(ans)
### BUGGY CODE ###

k, s = map(int, input().split())
counter = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if x+y+z == s and z >= 0 and z <= k:
            counter += 1
print(counter)

### FIXED CODE ###

k, s = map(int, input().split())
counter = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if z >= 0 and z <= k:
            counter += 1
print(counter)
### BUGGY CODE ###

h,n = map(int,input().split())
m = []
for i in range(n):
    ai,bi = map(int,input().split())
    m.append((ai,bi))

INF = 1000100001001

dp = [[INF]* (h + 1) for i in range(n + 1)]
dp[0][0] = 0
for i in range(1, n + 1 ):
    for j in range(h + 1):
        inx = max(0, j - m[i -1 ][0])
        dp[i][j] = min(dp[i -1][j], dp[i][inx] + m[i -1 ][1])


print(dp[n ][h])

### FIXED CODE ###

h,n = map(int,input().split())
m = []
for i in range(n):
    ai,bi = map(int,input().split())
    m.append((ai,bi))

INF = 1000100001001

dp = [[INF]* (h + 1) for i in range(n + 1)]
dp[0][0] = 0
for i in range(1, n + 1 ):
    for j in range(h + 1):
        inx = max(0, j - m[i -1 ][0])
        dp[i][j] = min(dp[i -1][j], dp[i][inx] + m[i -1 ][1])


print(dp[n ][h])
### BUGGY CODE ###

import sys 
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()

def dfs(v, pv):
    global P

    for nv in G[v]:
        if nv != pv:
            P[nv] += P[v]
            dfs(nv, v)

n,q = map(int, input().split())
G = [[] for _ in range(n)]              # adjacent list
for i in range(n-1):
    a,b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

P = [0]*n                               # add list
for i in range(q):
    p,x = map(int, input().split())
    P[p-1] += x


dfs(0, 0)
print(*P)



### FIXED CODE ###

#138_D
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 6)

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

edges = [[] for _ in range(n)]
cnt = [0 for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
    
for _ in range(q):
    p, x = map(int, input().split())
    cnt[p-1] += x
    
def dfs(frm, cur):
    for to in edges[cur]:
        if to != frm:
            cnt[to] += cnt[cur]
            dfs(cur, to)
dfs(-1, 0)          
print(*cnt)