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

from collections import defaultdict as dd
from collections import deque

n,m=map(int,input().split())
dic=dd(list)
for i in range(1,m+1):
    dic[i]=[0]


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


for k,v in dic.items():
    dic[k]=deque(sorted(dic[k],reverse=True))

#print(dic)

ans=0
max2nd=[0]
for i in reversed(range(m)):
    d=m-i
    a=dic[d][0]
    max2nd=deque(sorted(max2nd,reverse=True))
    b=max2nd[0]
    if a>=b:
        ans+=dic[d].popleft()
        if len(dic[d])==0: dic[d]=[0];
    else:
        ans+=max2nd.popleft()
        if len(max2nd)==0: max2nd=[0];
    max2nd+=dic[d]
        

print(ans)


### FIXED CODE ###

import heapq

n,m=map(int,input().split())
mm=10**5+5
c=[[0] for i in range(mm)]

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

#print(c)

ans=0
h=[]
for i in reversed(range(m)):
  d=m-i
  for j in c[d]:
    heapq.heappush(h,-j)
  #heapq.heapify(h)
  ans+=-heapq.heappop(h)

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

MOD = 10 ** 9 + 7

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


def prime_factorization(n):
    pmax = int(n ** 0.5 // 1) + 1

    factors = {}
    for p in range(2, pmax + 1):
        while n % p == 0:
            factors[p] = factors.get(p, 0) + 1
            n //= p
    if n != 1:
        factors[n] = factors.get(n, 0) + 1

    return factors

lf = [prime_factorization(a) for a in la]


lcm_factors = {}

for factors in lf:
    for p, m in factors.items():
        lcm_factors[p] = max(lcm_factors.get(p, 0), m)

s = 0
for factors in lf:
    b = 1
    for p, m in lcm_factors.items():
        b *= p ** (m - factors.get(p, 0))
        b %= MOD
    s += b
    s %= MOD

print(s)


### FIXED CODE ###

from functools import reduce
from math import gcd

MOD = 10 ** 9 + 7

_ = int(input())
la = list(map(int, input().split()))


def inv(a):
    return pow(a, MOD - 2, MOD)


def lcm(a, b):
    return a * b // gcd(a, b)


def addmod(a, b):
    return (a + b) % MOD


l = reduce(lcm, la) % MOD
answer = reduce(addmod, (l * inv(a) for a in la), 0)
print(answer)
### BUGGY CODE ###

import sys 
sys.setrecursionlimit(10 ** 6)

p=[100,101,102,103,104,105]
x=int(input())

def dfs(sum):
    ans=False
    if sum>=x:
        return sum==x
    for i in p:
        ans|=dfs(sum+i)
    return ans 

if x>=2000:
    print(1)
elif dfs(0):
    print(1)
else:
    print(0)



    

### FIXED CODE ###

x=int(input())
p=[100,101,102,103,104,105]
ans=[False]*2001
ans[0]=True
for i in range(2000):
    if ans[i]:
        for j in p:
            if i+j>2000:
                continue
            else:
                ans[i+j]=True
if x>2000:
    print(1)
elif ans[x]:
    print(1)
else:
    print(0)
### BUGGY CODE ###

T = int(input())
a = []
for i in range(T):
    a.append(list(map(int, input().split())))
for r in a:
    s, b, c, d = r[0], r[1], r[2], r[3]
    s_list = []
    while True:
        if (s < b) or (b>d):
            print('No')
            break
        s = s%b
        s_list.append(s)
        if c < s < b:
            print('No')
            break

        s = s+d
        if s in s_list:
            print('Yes')
            break
        s_list.append(s)


### FIXED CODE ###

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


T = int(input())
a = []
for i in range(T):
    a.append(list(map(int, input().split())))
for r in a:
    s, b, c, d = r[0], r[1], r[2], r[3]
    mod_list = []
    if (s < b) or (b>d):
        print('No')
        continue
    if (c>b):
        print('Yes')
        continue

    g = gcd(b,d)

    if b- g + s%g > c:
        print('No')
    else:
        print('Yes')
### BUGGY CODE ###

import sys
from operator import itemgetter
import numpy as np
read = sys.stdin.read

N, M, *LRC = map(int, read().split())
dp = np.full(N + 1, np.inf)
dp[1] = 0

for L, R, C in sorted(list(zip(*[iter(LRC)] * 3)), key=itemgetter(0, 1)):
    dp[L + 1:R + 1] = np.minimum(dp[L + 1:R + 1], np.minimum.accumulate(dp[L:R + 1] + C)[1:])

if dp[N] == np.inf:
    print(-1)
else:
    print(int(dp[N]))

### FIXED CODE ###

import sys
from heapq import heapify, heappush, heappop
read = sys.stdin.read


def main():
    N, M, *LRC = map(int, read().split())
    graph = [[(0, i - 1)] for i in range(N + 1)]
    graph[1] = []

    for L, R, C in zip(*[iter(LRC)] * 3):
        graph[L].append((C, R))

    distance = [-1] * (N + 1)
    queue = []
    heapify(queue)
    heappush(queue, (0, 1))

    while queue:
        cost, node = heappop(queue)
        if distance[node] == -1:
            distance[node] = cost
            for add_cost, next_node in graph[node]:
                if distance[next_node] == -1:
                    heappush(queue, (cost + add_cost, next_node))

    print(distance[-1])


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

a,b,x=[int(x) for x in input().split()]
ans=0
for i in range(a,b+1):
    if i%x==0:
        ans+=1
print(ans)

### FIXED CODE ###

a,b,x=[int(x) for x in input().split()]
print(b//x-(a-1)//x)
### BUGGY CODE ###

l = list(map(int, input().split()))
prices = list(map(int, input().split()))

for i in range(l[1]):
    x = prices.index(max(prices))
    prices[x] = int(prices[x] / 2)

print(sum(prices))


### FIXED CODE ###

import heapq

N, M = map(int, input().split())
values = list(map(int, input().split()))
sortedValues = []

for v in values:
    heapq.heappush(sortedValues, (-1)*v)

for i in range(M):
    heapq.heappush(sortedValues, int((heapq.heappop(sortedValues) * 1/2)))

print((-1) * sum([heapq.heappop(sortedValues) for i in range(len(sortedValues))]))
### BUGGY CODE ###

N,X,Y = map(int,input().split())

G = [[] for _ in range(N)]
# print(G)
# ぐらふの作成
for i in range(N-1):
    G[i].append(i+1)
    G[i+1].append(i)
G[X-1].append(Y-1)
G[Y-1].append(X-1)

# print(G)

from collections import deque
def bfs(G,v):
    que = deque([v])
    dist[v] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for w in G[v]:
            if dist[w] > -1:
                continue
            dist[w] = d + 1
            que.append(w)

D = [0]*(N-1)
for i in range(N):
    dist = [-1]*N
    bfs(G,i)
    # print(dist)
    for d in dist:
        if d>0:
            D[d-1] += 1
# print(D)
for d in D:
    print(d//2)




### FIXED CODE ###

N,X,Y = map(int,input().split())
D= [0]*(N-1)

# print(X,Y)
for i in range(1,N+1):
    for j in range(i+1,N+1): # i<j
        # print((i,j))
        # ver 1
        if j<=X or Y<=i:
            d = j-i
            
        # ver 2
        elif i<=X and Y<=j:
            d = X-i + 1 + j-Y
            
        # ver 3
        else:
            d = min(j-i,abs(X-i)+abs(Y-j)+1)
        # print(d)
        D[d-1] += 1
# print(D)

for d in D:
    print(d)
### BUGGY CODE ###

# coding: utf-8
N=int(input())
A=list(map(int,input().split()))
INF=10**9
dp=[[-INF for i in range(N+1)] for j in range(N+1)]
dp[0][0]=0
AI=[]

for i in range(N):
    AI.append([A[i],i+1])
    
AI.sort()
AI.reverse()

for i in range(1,N+1):
    a=AI[i-1][0]
    I=AI[i-1][1]
    for j in range(N+1):
        if j==0:
            dp[i][j]=dp[i-1][j]+abs(I-(N+1-i))*a
        elif j==i:
            dp[i][j]=dp[i-1][j-1]+abs(I-j)*a
        else:
            dp[i][j]=max(dp[i-1][j-1]+abs(I-j)*a,dp[i-1][j]+abs(I-(N+1-(i-j)))*a)
ans=0
for i in range(N+1):
    ans=max(ans,dp[N][i])

print(ans)

### FIXED CODE ###

# coding: utf-8
N=int(input())
A=list(map(int,input().split()))
INF=10**9
dp=[[-INF for i in range(N+1)] for j in range(N+1)]
dp[0][0]=0
AI=[]

for i in range(N):
    AI.append([A[i],i+1])
    
AI.sort()
AI.reverse()

for i in range(1,N+1):
    a=AI[i-1][0]
    I=AI[i-1][1]
    for j in range(N+1):
        if j==0:
            dp[i][j]=dp[i-1][j]+abs(I-(N+1-i))*a
        elif j==i:
            dp[i][j]=dp[i-1][j-1]+abs(I-j)*a
        else:
            dp[i][j]=max(dp[i-1][j-1]+abs(I-j)*a,dp[i-1][j]+abs(I-(N+1-(i-j)))*a)
ans=0
for i in range(N+1):
    ans=max(ans,dp[N][i])

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

import bisect

N, M = map(int, input().split())
A = sorted([int(i) for i in input().split()])

min_A = A[0]

i = 0

for _ in range(M) :
    B, C = map(int, input().split())
    if C > min_A :
        for _ in range(B) :
            bisect.insort_left(A, C)
        i += B
        min_A = A[i]

print(sum(A[i:]))


### FIXED CODE ###

N, M = map(int, input().split())
A = [[1, int(i)] for i in input().split()]
BC = A + [[int(i) for i in input().split()] for _ in range(M)]

BC.sort(key=lambda x: x[1], reverse=True)

i = 0
res = 0

for B, C in BC :
    if i + B <= N :
        res += C * B
        i += B
    else :
        res += C * (N - i)
        break

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

I=lambda:list(map(int,input().split()))
n,m=I()
e=[(I()[0],[2**(n-i)for i in I()])for _ in'_'*m]
I=9**9
dp=[I]*2**n
dp[0]=0
for i,d in enumerate(dp):
    if d==I:continue
    for a,c in e:
        b,x=i,d+a
        for j in c:b|=j
        if dp[b]>x:dp[b]=x
print(-(dp[-1]==I)or dp[-1])

### FIXED CODE ###

import sys
input=sys.stdin.readline
n,m=map(int,input().split())
e=[(int(input().split()[0]),list(map(int,input().split())))for _ in range(m)]
INF=10**18
dp=[INF]*2**n
dp[0]=0
for i in range(2**n):
    if dp[i]>=INF:continue
    for a,c in e:
        bit=i
        for j in c:
            bit|=2**(n-j)
        dp[bit]=min(dp[bit],dp[i]+a)
a=dp[-1]
if a>=INF:
    print(-1)
else:
    print(dp[-1])
### BUGGY CODE ###

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

max_reg = 0
for i in range(n - k + 1):
  max_reg = max(max_reg, (sum(p[i:i+k])+k)/2)
  
print(max_reg)

### FIXED CODE ###

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

sum_reg = (sum(p[0:k])+k)/2
max_reg = sum_reg
for i in range(k, n):
  sum_reg = sum_reg + (p[i]-p[i-k])/2
  max_reg = max(max_reg, sum_reg)
  
print(max_reg)
### BUGGY CODE ###

n, k = list(map(int, input().split()))
hhh = [int(input()) for _ in range(n)]
hhh.sort()
ans = float("inf")
for i in range(n-k+1):
  ans = min(ans, max(hhh[i:i+k]) - min(hhh[i:i+k]))
print(ans)

### FIXED CODE ###

n, k = list(map(int, input().split()))
hhh = [int(input()) for _ in range(n)]
hhh.sort()
ans = float("inf")
for i in range(n-k+1):
  ans = min(ans, hhh[i+k-1] - hhh[i])
print(ans)
### BUGGY CODE ###

from bisect import bisect_left, bisect_right, insort_left

n = int(input())
s = list(input())
q = int(input())
qs = [list(input().split()) for _ in range(q)]

abc = [[-1, n] for _ in range(26)]
for i, e in enumerate(s):
    j = ord(e) - ord("a")
    abc[j].append(i)

for i in range(26):
    abc[i].sort()

for t, e1, e2 in qs:
    if t == "1":
        i = int(e1) - 1
        c = e2

        let = s[i]

        idx = ord(let) - ord("a")
        popi = bisect_left(abc[idx], i)
        abc[idx].pop(popi)

        idx = ord(c) - ord("a")
        insort_left(abc[idx], i)

        s[i] = c

    else:
        l = int(e1) - 1
        r = int(e2) - 1

        cnt = 0
        for i in range(26):
            li = bisect_left(abc[i], l)
            ri = bisect_right(abc[i], r)
            if li != ri:
                cnt += 1

        print(cnt)


### FIXED CODE ###

from bisect import bisect_left, insort_left


def main():
    n = int(input())
    s = list(input())
    q = int(input())
    qs = [input().split() for _ in range(q)]

    abc = [[] for _ in range(26)]
    for i, e in enumerate(s):
        j = ord(e) - ord("a")
        abc[j].append(i)

    for t, e1, e2 in qs:
        if t == "1":
            i = int(e1) - 1
            c = e2

            let = s[i]

            if let == c:
                continue

            idx = ord(let) - ord("a")
            popi = bisect_left(abc[idx], i)
            abc[idx].pop(popi)

            idx = ord(c) - ord("a")
            insort_left(abc[idx], i)

            s[i] = c

        else:
            l = int(e1) - 1
            r = int(e2) - 1

            cnt = 0
            for i in range(26):
                li = bisect_left(abc[i], l)
                if li >= len(abc[i]):
                    continue
                if abc[i][li] <= r:
                    cnt += 1

            print(cnt)


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

if __name__ == '__main__':
    n = int(input())
    s = list(input())
    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                pin = str(i) + str(j) + str(k)
                t = 0
                for x in s:
                    if pin[t] == x:
                        t += 1
                    if t == 3:
                        ans += 1
                        break
    print(ans)


### FIXED CODE ###

n = int(input())
s = list(input())
ans = 0
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            t = str(i) + str(j) + str(k)
            tmp = []
            for z in s:
                if t[len(tmp)] == z:
                    tmp.append(0)
                if len(tmp) == 3:
                    ans += 1
                    break
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n, m = map(int,input().split())
a = list(map(int,input().split()))
for k in [0]*m:
  s, t = map(int,input().split())
  b = [t]*s
  a.extend(b)
ans = 0
a.sort()
for v in range(n):
  ans += a[-v-1]
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [list(map(int,input().split())) for p in [0]*m]
b.sort(key=lambda q: -q[1])
#print(a)
#print(b)

c = 0
for s in b:
	for t in [0]*s[0]:
		#print(s)
		if c + 1 > n:
			break
		if s[1] <= a[c]:
			break
		a[c] = s[1]
		c += 1
		#print(a)
	else:
		continue
	break
print(sum(a))
### BUGGY CODE ###

import math

def eratosthenes(n):
    p_list = []
    root_n = math.sqrt(n)
    data = [i + 1 for i in range(1, n)] 
    while True:
        p = data [0]
        if root_n <= p:
            return p_list + data 
        p_list.append(p)
        data = [e for e in data if e % p != 0]

def make_divisors(n):
    divisors = []
    for i in range(int(n**0.5)+1, 1, -1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
        if len(divisors) == 2:
            break
        
    # divisors.sort()
    return divisors

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

    if n in eratosthenes(n):
        print(n-1)
    else:
        a, b = make_divisors(n)
        a -= 1
        b -= 1
        print(a+b)
        
        
if __name__ == "__main__":
    main()


### FIXED CODE ###

import math


def main():
    n = int(input())
    a = 1
    b = n
    
    ans = n - 1 
    
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            a = int(i)
            b = int(n / i)
            ans = min(ans, a+b-2)
    print(ans)
        
        
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import bisect
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
res = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        tgt = L[i]+L[j] - 0.1
        res += bisect.bisect_right(L, tgt)-(j+1)
print(res)


### FIXED CODE ###

import bisect
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
res = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        tgt = L[i]+L[j]
        res += bisect.bisect_left(L, tgt)-(j+1)
print(res)
### BUGGY CODE ###

N = int(input())
S = input()

def main(N,S):
    count=0
    for i in range(1,N-2 +1):
        for j in range(i+1, N-1 +1):
            for k in range(j+1, N +1):
                if S[i-1]!=S[j-1]!=S[k-1]!=S[i-1]:
                    if j-i != k-j:
                        count += 1
    print(count)

if __name__=='__main__':
    main(N,S)

### FIXED CODE ###


N=int(input())
S=input()

#(RGB)になる組み合わせをカウント
count= S.count("R")*S.count("G")*S.count("B")
count0=0

#条件を満たさないものを引いていく
for i in range(1,N-2 +1):
    for j in range(i+1,(N+i)//2 +1):
        k=2*j-i
        if S[k-1]!=S[i-1] and S[k-1]!=S[j-1] and S[i-1]!=S[j-1]:
            count0 += 1
print(count-count0)
### BUGGY CODE ###

from collections import deque


H, W = map(int, input().split())
black_cells = []
for h in range(H):
    line = list(input())
    for w in range(W):
        if line[w] == '#':
            black_cells.append(h*W+w)
def r(p):
    q_list = []
    h = p // W
    w = p % W
    if h != 0:
        q_list.append(p-W)
    if h != H-1:
        q_list.append(p+W)
    if w != 0:
        q_list.append(p-1)
    if w != W-1:
        q_list.append(p+1)
    return q_list


queue = deque(black_cells)
d = [10000]*H*W
for i in black_cells:
    d[i] = 0
while len(queue) > 0:
    p = queue.popleft()
    for q in r(p):
        if d[q] > d[p]+1:
            d[q] = d[p] + 1
            queue.append(q)
print(max(d))

### FIXED CODE ###

from scipy.ndimage import distance_transform_cdt


h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
n = [[1 if x == '.' else 0 for x in row] for row in a]
cnt = distance_transform_cdt(n, metric='taxicab')
print(cnt.max())
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
c = 0
for i in range(n):
    c = a.count(i+1)
    print(c)
    if c > 0:
        a.remove(i+1)

### FIXED CODE ###

import collections

n = int(input())
a = list(map(int, input().split()))
l = collections.Counter(a)
for i in range(n):
    print(l[i+1])
### BUGGY CODE ###

s=input()


i=0
c=0
while True:
	if i>len(s)-3: break
	if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C":
		s=s[:i]+"B"+s[i+1:]
		s=s[:i+1]+"C"+s[i+2:]
		s=s[:i+2]+"A"+s[i+3:]
		c+=1
		if i>0: i-=1
		continue
	else: i+=1

print(c)

### FIXED CODE ###

s=input()


i=0
c=0
flag=0
while True:
	if i>len(s)-2: break
	if s[i]=="A":
		flag+=1
		i+=1
	elif flag and s[i:i+2]=="BC":
		c+=flag
		i+=2
	else:
		flag=0
		i+=1

print(c)
### BUGGY CODE ###

from itertools import combinations
N=int(input())
L=sorted(list(map(int,input().split())))
cmb=list(combinations(L,3))
cnt=0
for i in range(len(cmb)):
  if cmb[i][0]+cmb[i][1]>cmb[i][2]:
    cnt+=1
print(cnt)

### FIXED CODE ###

from bisect import bisect_left
n=int(input())
l=sorted(list(map(int,input().split())))
cnt=0
for i in range(n-2):
  for j in range(i+1,n-1):
    cnt+=bisect_left(l,l[i]+l[j])-j-1
print(cnt)
### BUGGY CODE ###

def abc177_c():
    n = int(input())
    a = list(map(int, input().split(' ')))

    mod = 10 ** 9 + 7
    ans = 0

    for i in range(n - 1):
        for j in range(i + 1, n):
            ans += ((a[i] % mod) * (a[j] % mod)) % mod
            ans %= mod

    print(ans)

if __name__ == '__main__':
    abc177_c()

### FIXED CODE ###

def abc177_c_2():
    n = int(input())
    a = list(map(int, input().split(' ')))

    mod = 10 ** 9 + 7
    ans = 0
    x = 0

    for i in range(n):
        ans = (ans + a[i] * x) % mod
        x = (x + a[i]) % mod

    print(ans)

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

def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n= int(arr_data[0][0])

arr=[int(arr_data[1][x]) for x in range(n)]

cnt=0

while any(x % 2 == 0 for x in arr):

    if any(x % 4 == 0 for x in arr):

        val=max(list(filter(lambda x : x%4 ==0, arr)))        
        idx=arr.index(val)
        
        arr=[x*3 for x in arr]
        arr[idx]//=6
               
        cnt+=1
    
    elif any(x % 2 == 0 for x in arr):
    
        val=max(list(filter(lambda x : x%2 ==0, arr)))        
        idx=arr.index(val)
        
        arr=[x*3 for x in arr]
        arr[idx]//=6
        
        cnt+=1
    
print(cnt)      

### FIXED CODE ###

def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n= int(arr_data[0][0])

arr=[int(arr_data[1][x]) for x in range(n)]
arr01 = [x for x in arr if x % 4 ==0] 
arr02 = [x for x in arr if x % 4 !=0 and x % 2==0] 

cnt=0
if len(arr)>0:

    for i in arr01:

        while i % 2==0:

            i//=2
        
            cnt+=1
    
    cnt+=len(arr02)
   
print(cnt)
### BUGGY CODE ###

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

ans = 0
for x in range(n+1):
    tmp = a*x//b - a*(x//b)
    if tmp > ans:
        ans = tmp

print(ans)


### FIXED CODE ###

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

x = n
if n >= b-1:
    x = b-1

ans = (a*(x%b))//b
print(ans)
### BUGGY CODE ###

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

one, two, three = 0, 0, 0
for a in a_list:
    if a == 1:
        one += 1
    if a == 2:
        two += 1
    if a == 3:
        three += 1

dp = [[[0.0] * 301 for _ in range(301)] for _ in range(301)]
for k in range(three+1):
    for j in range(two+three+1-k):
        for i in range(one+two+three+1-k-j):
            if i == 0 and j == 0 and k == 0:
                continue
            tmp = N * 1.0
            if i != 0:
                tmp += i * dp[i - 1][j][k]
            if j != 0:
                tmp += j * dp[i + 1][j - 1][k]
            if k != 0:
                tmp += k * dp[i][j + 1][k - 1]

            dp[i][j][k] = tmp / (i + j + k)
print(dp[one][two][three])


### FIXED CODE ###

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

one, two, three = 0, 0, 0
for a in a_list:
    if a == 1:
        one += 1
    if a == 2:
        two += 1
    if a == 3:
        three += 1

dp = [[[0.0] * 301 for _ in range(301)] for _ in range(301)]
for k in range(three+1):
    for j in range(two+three+1-k):
        for i in range(one+two+three+1-k-j):
            if i == 0 and j == 0 and k == 0:
                continue
            tmp = N * 1.0
            if i != 0:
                tmp += i * dp[i - 1][j][k]
            if j != 0:
                tmp += j * dp[i + 1][j - 1][k]
            if k != 0:
                tmp += k * dp[i][j + 1][k - 1]

            dp[i][j][k] = tmp / (i + j + k)
print(dp[one][two][three])
### BUGGY CODE ###

N = int(input())
S = input()

cnt = 0
chk = [0]*1000
for j in range(1000):
    j = str(j).zfill(3)
    for i, s in enumerate(S):
        if chk[int(j)] == 1:
            continue
        if s == j[0]:
            for ii, ss in enumerate(S[i+1:]):
                if ss == j[1]:
                    if chk[int(j)] == 1:
                        continue
                    for iii, sss in enumerate(S[i+ii+2:]):
                        if sss == j[2]:
                            if chk[int(j)] == 1:
                                continue
                            chk[int(j)] = 1
                            cnt += 1
print(cnt)


### FIXED CODE ###

# import numpy as np
import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

N = int(input())
S = input()

cnt = 0
for num in range(1000):
    snum = str(num).zfill(3)
    # print("snum", snum)
    ind = 0
    chkind = 0
    # while ind < len(S):
    for s in S:
        if chkind >= 3:
            break
        if s == snum[chkind]:
            chkind += 1
    if chkind == 3:
        cnt += 1
print(cnt)