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

N,K=map(int,input().split())
mod=1000000007
path=[[] for i in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  path[a].append(b)
  path[b].append(a)
#print(path)
  
abc=[False for i in range(N)] #0ならまだ塗ってない

abc[0]=True
cnt=0
ans=K%mod
nx=[]
for i in range(len(path[0])):
  child=path[0][i]
  if abc[child]:
    continue
  ans=ans*(K-1-cnt)
  ans=ans%mod
  cnt=cnt+1
  abc[child]=True
  nx.append(child)
while len(nx)>0:
  a=nx.pop(0)
  cnt=0
  for i in range(len(path[a])):
    child=path[a][i]
    if abc[child]:
      continue
    ans=ans*(K-2-cnt)
    ans=ans%mod
    cnt=cnt+1
    abc[child]=True
    nx.append(child)
      
print(ans%mod)
      
      
    
    


### FIXED CODE ###

N,K=map(int,input().split())
mod=1000000007
path=[[] for i in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  path[a].append(b)
  path[b].append(a)
#print(path)
  
abc=[False for i in range(N)] #0ならまだ塗ってない

abc[0]=True
cnt=0
ans=K%mod
nx=[]
for i in range(len(path[0])):
  child=path[0][i]
  if abc[child]:
    continue
  ans=ans*(K-1-cnt)
  ans=ans%mod
  cnt=cnt+1
  abc[child]=True
  nx.append(child)
while len(nx)>0:
  a=nx.pop()
  cnt=0
  for i in range(len(path[a])):
    child=path[a][i]
    if abc[child]:
      continue
    ans=ans*(K-2-cnt)
    ans=ans%mod
    cnt=cnt+1
    abc[child]=True
    nx.append(child)
      
print(ans%mod)
### BUGGY CODE ###

class LinkedList(object):
    def __init__(self):
        self.first = None
        self.last = None

    def insert(self, key):
        node = {'key':key, 'next':None, 'prev':None}
        if not self.first:
            self.first = self.last = node
        else:
            node['next'] = self.first
            self.first['prev'] = node
            self.first = node

    def delete(self, key):
        node = self.first
        if self.first['key'] == key:
            self.deleteFirst()
            return
        while node['next']:
            if node['key'] == key:
                node['prev']['next'] = node['next']
                node['next']['prev'] = node['prev']
                return
            node = node['next']
        if self.last['key'] == key:
            self.deleteLast()

    def deleteFirst(self):
        if self.first == self.last:
            self.first = self.last = None
        else:
            self.first['next']['prev'] = None
            self.first = self.first['next']

    def deleteLast(self):
        if self.first == self.last:
            self.first = self.last = None
        else:
            self.last['prev']['next'] = None
            self.last = self.last['prev']

    def show(self):
        if not self.first:
            print('')
            return
        node = self.first
        res = [node['key']]
        while node['next']:
            node = node['next']
            res.append(node['key'])
        print(' '.join(res))

def run():
    n = int(input())
    linked_list = LinkedList()
    for _ in range(n):
        order = input()
        if order.startswith('insert'):
            linked_list.insert(order.split()[1])
        elif order.startswith('deleteFirst'):
            linked_list.deleteFirst()
        elif order.startswith('deleteLast'):
            linked_list.deleteLast()
        elif order.startswith('delete'):
            linked_list.delete(order.split()[1])
    linked_list.show()

if __name__ == '__main__':
    run()




### FIXED CODE ###

from collections import deque

def run():
    n = int(input())
    dq = deque()
    for _ in range(n):
        order = input()
        if order[0] == 'i':
            dq.appendleft(order[7:])
        elif order[6] == ' ':
            key = order.split()[1]
            if not key in dq:
                continue
            for i in range(len(dq)):
                if dq[i] == key:
                    dq.remove(key)
                    break
        elif order[6] == 'F':
            dq.popleft()
        elif order[6] == 'L':
            dq.pop()

    print(' '.join(dq))

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

input = raw_input

s = input()
q = int(input())

rev = False
for i in range(q):
    elms = input().split(" ")
    t = int(elms[0])
    if t == 1:
        rev = not rev
    else:
        f = int(elms[1])
        c = elms[2]

        if f == 1:
            if rev:
                s = s + c
            else:
                s = c + s
        else:
            if rev:
                s = c +s
            else:
                s = s + c
if rev:
    s = s[::-1]
print(s)

### FIXED CODE ###

#input = raw_input

s = input()
q = int(input())

inputs = []
n_reverse = 0
for i in range(q):
    input_ = input()
    if input_[0] == "1":
        n_reverse += 1
    inputs.append(input_)

if n_reverse % 2 == 0:
    final_rev = False
else:
    final_rev = True

rev = False
mae = ""
ushiro = ""
for input_ in inputs:
    elms = input_.split(" ")
    t = int(elms[0])
    if elms[0] == "1":
        rev = not rev
    else:
        f = int(elms[1])
        c = elms[2]

        if f == 1:
            if final_rev:
                if rev:
                    mae = c + mae
                else:
                    ushiro = ushiro + c
            else:
                if rev:
                    ushiro = ushiro + c
                else:
                    mae = c + mae
        else:
            if final_rev:
                if rev:
                    ushiro = ushiro + c
                else:
                    mae = c + mae
            else:
                if rev:
                    mae = c + mae
                else:
                    ushiro = ushiro + c

if final_rev:
    s = s[::-1]

out = mae + s + ushiro
print(out)
### BUGGY CODE ###

#!/usr/bin/env python

import sys
import re

s= sys.stdin.readline().strip()
#
c= 0
p1= re.compile("ABC")
p2= re.compile("A+$")
p3= re.compile("^(BC)+")
#
while True:
    m =p1.search( s )
    if not m: break
    i= m.start() + 1
    a = len( p2.search(s[:i]).group())
    bc= len( p3.search(s[i:]).group()) // 2
    s= ("A"*a) + s[i+2*bc:]
    c+= a*bc

print( c )


### FIXED CODE ###

#!/usr/bin/env python

import sys
import re

s= sys.stdin.readline().strip()
s= s.replace("BC","D")
s= re.sub("[BC]+"," ",s).split()

t= 0
for seg in s:
    a= 0
    for c in seg:
        if c=="A": a+=1
        elif c=="D": t+= a
#
print( t )
### BUGGY CODE ###

(h, w) = map(int, input().split(" "))

ans=[]
### case1  000
ans.append(0 if h%3==0 else w)
###case 2 tate 000
ans.append(0 if w%3==0 else h)

def getmin(h, w):
    area=9999999999999
    for i in range(1, h):
        for j in range(1, w):
            areas=[ i * w, j * (h-i), (w-j)*(h-i)]
            area = max(areas)-min(areas) if area > max(areas)-min(areas) else area
    return area

ans.append(getmin(h, w))
ans.append(getmin(w, h))

print(min(ans))


### FIXED CODE ###

(h, w) = map(int, input().split(" "))

ans=[]
### case1  000
ans.append(0 if h%3==0 else w)
###case 2 tate 000
ans.append(0 if w%3==0 else h)

def getmin(h, w):
    area=9999999999999
    for i in range(h//3-3, h//3+2):
        for j in range(w//2 -3, w//2 +3):
            areas=[ i * w, j * (h-i), (w-j)*(h-i)]
            area = max(areas)-min(areas) if area > max(areas)-min(areas) else area
    return area

ans.append(getmin(h, w))
ans.append(getmin(w, h))

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

import itertools

def D():
    n = input()
    l = map(int,input().split(" "))
    temp = itertools.combinations(l,3)
    count = 0
    #print(temp)
    #res = [i for i in temp if i[0] < i[1]+i[2] and i[1] < i[0]+i[2] and i[2] < i[0]+i[1]]
    for i in temp:
        i = sorted(list(i),reverse=True)
        if i[0] < i[1]+i[2]:
            count += 1
    print(count)

if __name__ == '__main__':
    D()

### FIXED CODE ###

import itertools
import bisect

def D():
    n = input()
    l = map(int,input().split(" "))
    temp = itertools.combinations(l,3)
    count = 0
    #print(temp)
    #res = [i for i in temp if i[0] < i[1]+i[2] and i[1] < i[0]+i[2] and i[2] < i[0]+i[1]]
    for i in temp:
        i = sorted(list(i),reverse=True)
        if i[0] < i[1]+i[2]:
            count += 1
    print(count)

def D_sort():
    N = int(input())
    L = sorted([int(_) for _ in input().split()])
    #L[a] + L[b] > L[c]
    ans = 0
    for a in range(N - 2):
        for b in range(a + 1, N - 1):
            ans += bisect.bisect(L, L[a] + L[b] - 1) - b - 1
            #右挿入二分探索で得たインデックス-2つ目に長い辺のインデックス=その2辺で作れる三角形の個数
            #(この間に入っている辺を使う分には三角形成立条件が必ず満たされている)
    print(ans)
if __name__ == '__main__':
    D_sort()
### BUGGY CODE ###

R,G,B,n = map(int,input().split())

ans=0
for r in range(n//R+1):
    for g in range(n//G+1):
        tmp=n-r*R-g*G
        if tmp>=0 and tmp%B==0:
            ans+=1

print(ans)

### FIXED CODE ###

R,G,B,n = map(int,input().split())

ans=0
for r in range(n//R+1):
    for g in range(n//G+1):
        tmp=n-r*R-g*G
        if tmp%B==0 and tmp//B>=0:
            ans+=1

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

s = input()
k = int(input())
ss = ""
for _ in range(k):
    ss += s

ss_list = list(ss)
count = 0
answer = 0
prev = ""
for sss in ss_list:
    if prev == "" or sss == prev:
        count+=1
        if count == 2: 
            answer+=1
            count=0

    else:
        count=1
    prev = sss

print(answer)

### FIXED CODE ###

import sys
s = list(input())
k = int(input())

if len(set(s))==1:
	print((len(s)*k)//2)
	sys.exit()
    
def counter(string):
    count = 0
    answer = 0
    prev = ""
    for index,sss in enumerate(string):
        if prev == "" or sss == prev:
            count+=1
            if count == 2: 
                answer+=1
                count=0
                string[index] = "1"
        else:
            count=1
        prev = sss
    return answer,string

answer, string = counter(s.copy())

if string[0] != string[-1]:
    print(answer*k)
else:
    count = 0
    l = len(s)
    for i in range(l):
        if s[i] == s[0]:
            count += 1
        else:
            break
    for i in range(l):
        if s[-1-i] == s[0]:
        	count += 1
        else:
        	break

    if count % 2 ==0:
        print(answer*k + k-1)
    else:
        print(answer*k)
### BUGGY CODE ###

r,g,b,n=map(int,input().split())

x=[i*r for i in range(n//r+1)]
y=[i*g for i in range(n//g+1)]
z=[i*b for i in range(n//b+1)]
ans=0
for i in x:
    for j in y:
        A=n-i-j
        if A in z:
            ans+=1

print(ans)

### FIXED CODE ###

r,g,b,n=map(int,input().split())

ans=0
for i in [i*r for i in range(n//r+1)]:
    for j in [i*g for i in range(n//g+1)]:
        A=n-i-j
        if A%b==0 and A>=0:

            ans+=1

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

n = int(input())
a  = list(map(int, input().split()))
import numpy  as np
a = np.array(a)
for i in range(1, n+1):
  print(np.count_nonzero(a == i))

### FIXED CODE ###

n = int(input())
a  = list(map(int, input().split()))
import numpy  as np
a = np.array(a)
ans = np.zeros(n)
for i in a:
  ans[i-1] += 1
for i in ans:
  print(int(i))
### BUGGY CODE ###

mod=7+10**9
n=int(input())
c=[int(input()) for _ in [0]*n]
def dp(l):
    if not l:
        return 1
    if len(l)==1:
        return 1
    ans=0
    i=0
    while i<len(l):
        if l[i]==l[0]:
            j=i
            while j<len(l) and l[j]==l[0]:
                j+=1
            ans+=dp(l[j:])
            ans%=mod
            i=j
        i+=1
    return ans%mod
print(dp(c))

### FIXED CODE ###

mod=7+10**9
n=int(input())
c=['$']+[int(input()) for _ in [0]*n]
data=[1]+[0]*n
s={}

for i in range(1,n+1):
  if c[i] in s.keys():
    if c[i]!=c[i-1]:
      s[c[i]]+=data[i-1]
      s[c[i]]%=mod
  else:
    s[c[i]]=data[i-1]
  data[i]=s[c[i]]%mod
        
print(data[n])
### BUGGY CODE ###

s=set()
for i in range(int(input())):
    s=s^{input()}
print(len(s))

### FIXED CODE ###

n=int(input())
s=set()
for i in range(n):
    s^={input()}
print(len(s))
### BUGGY CODE ###

S = input()
ans = [0]*len(S)
tmp = [1]*len(S)
if(len(S)%2):
  for i in range(len(S)+1):
    for j in range(len(S)):
      if S[j] == 'L':
        ans[j-1] += tmp[j]
      else:
        ans[j+1] += tmp[j]
    tmp = ans
    ans = [0]*len(S)
  print(*tmp)
else:
  for i in range(len(S)):
    for j in range(len(S)):
      if S[j] == 'L':
        ans[j-1] += tmp[j]
      else:
        ans[j+1] += tmp[j]
    tmp = ans
    ans = [0]*len(S)
  print(*tmp)

### FIXED CODE ###

S = input()
ans = [0]*len(S)
tmp = []
cnt = 1;

for i in range(len(S)-1):
  if(S[i] == S[i+1]):
    cnt += 1
  else:
    tmp.append(cnt)
    cnt = 1
tmp.append(cnt)

cnt = 0
for i in range(len(tmp)-1):
  cnt += tmp[i]
  if(i % 2 == 0):
    if((tmp[i] - tmp[i+1])%2 == 0):
      ans[cnt-1] = int((tmp[i]+tmp[i+1])/2)
      ans[cnt] = int((tmp[i]+tmp[i+1])/2)
    else:
      if(min(tmp[i], tmp[i+1]) % 2):
        if(tmp[i] > tmp[i+1]):
          ans[cnt-1] = int((tmp[i] + tmp[i+1]-1)/2)
          ans[cnt] = int((tmp[i]+tmp[i+1]+1)/2)
        else:
          ans[cnt-1] = int((tmp[i] + tmp[i+1]+1)/2)
          ans[cnt] = int((tmp[i]+tmp[i+1]-1)/2)
      else:
        if(tmp[i] > tmp[i+1]):
          ans[cnt-1] = int((tmp[i] + tmp[i+1]+1)/2)
          ans[cnt] = int((tmp[i]+tmp[i+1]-1)/2)
        else:
          ans[cnt-1] = int((tmp[i] + tmp[i+1]-1)/2)
          ans[cnt] = int((tmp[i]+tmp[i+1]+1)/2)
        
print(*ans)
### BUGGY CODE ###

import math

def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない
    x_sqrt = math.sqrt(x) # 記憶させていちいち計算しない

    # エラトステネスのふるい
    for prime in primes:
        if prime == 0:
            continue # 先に処理
        if prime > x_sqrt: 
            break
        for non_prime in range(2 * prime, x, prime):
            primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

q = int(input())
l_list = []
r_list = []
for _ in range(q):
    l, r = list(map(int,input().split()))
    l_list.append(l)
    r_list.append(r)
    
maxr = max(r_list)
p_list = primes(maxr+1)

sim_list = []
for p in p_list:
    if (p+1)/2 in p_list:
        sim_list.append(p)
        
cumulation = [0 for _ in range(maxr+1)]
for s in sim_list:
    cumulation[s] = 1

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

for i in range(q):
    print(cumulation[r_list[i]]-cumulation[l_list[i]-1])

### FIXED CODE ###

# -*- coding: utf-8 -*-
import math
Q = int(input())

ls = []
rs = []
for n in range(Q):
    l, r = map(int, input().split())
    ls.append(l)
    rs.append(r)
    num = 0

max_r = max(rs)

def eratos(n):
    if n == 1:
        return set()
    primes = [1 for i in range(n+1)]
    primes[0] = 0
    primes[1] = 0
    for i in range(2,math.floor(math.sqrt(n))+1):
        if primes[i] == 1:
            j = i + i
            while j <= n:
                primes[j] = 0
                j = j + i
    return primes


def count_similar(era, n):
    count_similar = [0 for i in range(n+1)]
    for i in range(1,n+1):
        count_similar[i] = count_similar[i-1]
        if era[i] == 1 and era[int((i+1)/2)] == 1:
            count_similar[i] += 1
    return count_similar




era = eratos(max_r)
cnt = count_similar(era, max_r)

for l, r in zip(ls, rs):
    print(cnt[r] - cnt[l-1])
### BUGGY CODE ###

# import sys
# input = sys.stdin.readline

n = int(input())

A = [1 for i in range(n+1)]

F = [0] * (n+1)

for i in range(2, n+1):
    
    
    if F[i] == 0:
        for j in range(i, n+1, i):
            F[j] = 1
        # L = [0] * (n+1)
        L = {}
        m = i
        while m <= n:
            # print("m",m)
            for j in range(m, n+1, m):
                try:
                    L[j] += 1
                except:
                    L[j] = 1
            m *= i
        # print(L)
        for j in L.keys():
            A[j] *= L[j]+1
# print(A)
# print(A[24])
ans = 0
for i in range(n+1):
    ans += i * A[i]

print(ans)

### FIXED CODE ###

n = int(input())
ans = 0

for i in range(1, n+1):
    a1 = i
    d = i
    nn = n // i
    ans += (nn * (2*a1 + (nn-1)*d)) // 2
    # print(i,ans,a1,nn,d)

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

n = int(input())
ans = 0
for i in range(1,n):
  for j in range(1,int(n/i)+2):
    if i*j < n:
      ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
ans = 0
for i in range(1,n):
  if n%i == 0:
    ans += int(n/i)-1
  else:
    ans += int(n/i)
print(ans)
### BUGGY CODE ###


import sys 
input = sys.stdin.readline


n = int(input())

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

from operator import mul
from functools import reduce



    
if reduce(mul, a) > 10**18:
    print('-1')
else:
    print(reduce(mul, a)) 


### FIXED CODE ###

# import sys 
# input = sys.stdin.readline
 
 
n = int(input())
 
a= list(map(int,input().split())) 
 
def main(a):
    if 0 in a:
        print(0)
        return
     
    ans = 1
    for i in a:
        ans *= i 
        
        if ans > 1000000000000000000:
            print(-1)
            return
    
    print(ans)
    
main(a)
### BUGGY CODE ###

N=int(input())
S=str(input())
ans = 0
for i in range(N):
    for j in range(i,N):
        for k in range(j,N):
            if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k] and j-i!=k-j:
                ans += 1
print(ans)


### FIXED CODE ###

N=int(input())
S=str(input())
ans = S.count("R")*S.count("G")*S.count("B")
#print(ans)
for i in range(N-2):
    for j in range(i+1,N-1):
        k = 2*j-i
        #print(i,j,k)
        if k <= N-1:
            if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]:
                ans -= 1
print(ans)
### BUGGY CODE ###

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

ans = 0
for y in range(N +1):
    for w in range(N +1):
        for n in range(N +1):
            if y*10000+w*5000+n*1000 == Y and y+w+n ==N:
                ans = str(y)+" "+str(w)+" "+str(n)

if ans == 0:
    print(-1, -1, -1)
else:
    print(ans)

### FIXED CODE ###

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

ans = 0
for y in range(N +1):
    for w in range(N +1):
        if y*10000+w*5000+(N-y-w)*1000 == Y and N-y-w >= 0:
            ans = str(y)+" "+str(w)+" "+str(N-y-w)

if ans == 0:
    print(-1, -1, -1)
else:
    print(ans)
### BUGGY CODE ###

### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    arr.sort()
    tb=[False]*(10**6 + 10)
    ans=0
    for i in range(n):
        flg=0
        x=arr[i]
        if tb[x]==False:
            flg=1
        if i < (n-1):
            if arr[i]==arr[i+1]:
                flg=0
        ans+=flg
        for j in range(x,10**6+5,x):
            tb[j]=True
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

### FIXED CODE ###

### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
import collections

def resolve():
    readline=sys.stdin.readline
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    c=collections.Counter(arr)
    tb=[False]*(10**6 + 10)
    ans=0
    for x in c.keys():
        for j in range(x*2,10**6+5,x):
            tb[j]=True
    for x in c.keys():
        if tb[x]==0 and c[x]==1:
            ans+=1
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------
### BUGGY CODE ###

n = int(input())
d = int(input())
p = 10**9+7
if d == 1:
    print(n % p)
    exit()
N = [int(i) for i in list(str(n))]
DP0 = [0] * d
DP1 = [0] * d
DP1[0] += 1
for i in N:
    DP0_ = [0] * d
    DP1_ = [0] * d
    for r in range(d):
        for j in range(i):
            DP0_[r] += DP1[(r-j) % d]
            DP1_[r] += DP1[(r-j) % d]
        DP0_[r] += DP0[(r-i) % d]
        DP1_[r] += DP1[(r-i) % d]
        for j in range(i+1, 10):
            DP0_[r] += DP0[(r-j) % d]
            DP1_[r] += DP0[(r-j) % d]
        DP0_[r], DP1_[r] = DP0_[r] % p, DP1_[r] % p
    DP0, DP1 = DP0_, DP1_
print((DP1[0]-1+p) % p)


### FIXED CODE ###

n = int(input())
d = int(input())
p = 10**9+7
if d == 1:
    print(n % p)
    exit()
N = [int(i) for i in list(str(n))]
DP0 = [0] * d
DP1 = [0] * d
DP1[0] += 1
for i in N:
    DP0_ = [0] * d
    DP1_ = [0] * d
    for r in range(d):
        for j in range(i):
            DP0_[r] += DP1[(r-j) % d]
            DP1_[r] += DP1[(r-j) % d]
        DP0_[r] += DP0[(r-i) % d]
        DP1_[r] += DP1[(r-i) % d]
        for j in range(i+1, 10):
            DP0_[r] += DP0[(r-j) % d]
            DP1_[r] += DP0[(r-j) % d]
        DP0_[r], DP1_[r] = DP0_[r] % p, DP1_[r] % p
    DP0, DP1 = DP0_, DP1_
print((DP1[0]-1+p) % p)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
n = 0
can = True

while can:
    for i in range(N):
        if A[i]%2 == 0:
            A[i] = (A[i]/2)
            n += 1
        else:
            break

print(n)
        

### FIXED CODE ###

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

while 1:
    #すべてが偶数か確認
    for i in range(N):
        if A[i] % 2 == 0:
            continue
        else:
            F = 1
    
    if F == 1 : break 

    for i in range(N):
        A[i] = A[i]/2
    n += 1


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

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

ans = 1
for i in A:
  ans = 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:
  print("0")
else:
  for i in A:
    ans = ans * i
    if ans > 10 ** 18:
      print("-1")
      break
    else:
      continue
  else:
    print(ans)
### BUGGY CODE ###

n = int(input())
A = set()
S = input()
res = 0
for i in range(n-2) :
    for j in range(i+1,n-1) :
        for k in range(j+1,n) :
            t = S[i]+S[j]+S[k]
            if t not in A :
                A.add(t)
                res += 1
print(res)


### FIXED CODE ###

n = int(input())
S = input()
res = 0
for i in range(1000) :
    T = str(i).zfill(3)
    a = 0
    b = 0
    f1 = 0
    f2 = 0
    f = 0
    for j,t in enumerate(T) :
        if f :
            break
        for k,s in enumerate(S) :
            if t == s :
                if not f1 :
                    f1 = 1
                    a = k
                    break
                elif f1 and not f2 and a < k :
                    f2 = 1
                    b = k
                    break
                elif f1 and f2 and b < k :
                    res += 1
                    f = 1
                    break
print(res)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans=[str(a.index(i)+1) for i in range(1,n+1)]
print(" ".join(ans))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans=[0]*n
for k,i in enumerate(a):
    ans[i-1]=str(k+1)
print(" ".join(ans))
### BUGGY CODE ###

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

y = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            # print(i,j,k)
            c = str(i)
            p = 0
            l = 0
            while l < N:
                if p == 0 and S[l] == c:
                    c = str(j)
                    p = 1
                elif p == 1 and S[l] == c:
                    c = str(k)
                    p = 2
                elif p == 2 and S[l] == c:
                    y += 1
                    # print("pin")
                    break
                l += 1
print(y)

### FIXED CODE ###

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

y = 0
L = []
for i in range(10):
    for j in range(10):
        L = []
        # print(i,j,k)
        c = str(i)
        p = 0
        l = 0
        while l < N:
            if p == 0 and S[l] == c:
                c = str(j)
                p = 1
            elif p == 1 and S[l] == c:
                p = 2
            elif p == 2 and S[l] not in L:
                L.append(S[l])
            l += 1
        y += len(L)
print(y)