Problem:
 Score: 400 points    Problem Statement  AtCoder Inc. has decided to lock the door of its office with a 3 -digit PIN code.  The company has an N -digit lucky number, S . Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.  How many different PIN codes can he set this way?  Both the lucky number and the PIN code may begin with a 0 .      Constraints   4 \leq N \leq 30000  S is a string of length N consisting of digits.         Input  Input is given from Standard Input in the following format:  N  S       Output  Print the number of different PIN codes Takahashi can set.        Sample Input 1 4
0224      Sample Output 1 3  Takahashi has the following options:   Erase the first digit of S and set 224 .  Erase the second digit of S and set 024 .  Erase the third digit of S and set 024 .  Erase the fourth digit of S and set 022 .   Thus, he can set three different PIN codes: 022 , 024 , and 224 .       Sample Input 2 6
123123      Sample Output 2 17       Sample Input 3 19
3141592653589793238      Sample Output 3 329

Solution (Python):

n = int(input())
s = input()

imemo = [0]*10
memo = [0]*100
counter = 0

for i in range(n):
    if imemo[int(s[i])] == 0:
        imemo[int(s[i])] = 1
    else:
        continue
        
    for j in range(i+1,n):
        if memo[int(s[i])*10+int(s[j])] == 0:
                memo[int(s[i])*10+int(s[j])] = 1
                counter += len(set(s[j+1:]))
print(counter)

Solution (Python):
def can_set(num, string):
    d0, d1, d2 = num

    ind0 = string.find(d0)
    if ind0 == -1 or ind0 == len(string) - 1:
        return False

    string = string[ind0 + 1:]

    ind1 = string.find(d1)
    if ind1 == -1 or ind1 == len(string) - 1:
        return False

    string = string[ind1 + 1:]

    ind2 = string.find(d2)

    if ind2 == -1:
        return False

    return True


n = int(input())
s = input().strip()

count = 0
for i in range(1000):
    num = str(i).zfill(3)
    if can_set(num, s):
        count += 1

print(count)

Solution (Python):
N = int(input())
S = input()

a = dict()

for i in range(N):
    s = S[i]
    for j in range(100):
        if ("0" + str(j))[-2:] in a:
            a[("0" + str(j) + s)[-3:]] = 1
    if (N - i) >= 2:
        for j in range(10):
            if str(j) in a:
                a[str(j) + s] = 1
    if (N - i) >= 3:
        a[str(s)] = 1

ans = 0
for k in a.keys():
    if len(k) == 3:
        ans += 1
print(ans)

Solution (Python):
N = int(input())
S = input()
S_list = list(S)

numbers = []

for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            numbers.append( str(i) + str(j) + str(k))

result = 0
for number in numbers:
    first = number[0]
    second = number[1]
    third = number[2]

    if first in S_list:
        first_index = S_list.index(first)

        if second in S_list[(first_index+1):]:
            second_index = (S_list[(first_index+1):]).index(second) + first_index + 1

            if third in S_list[(second_index+1):]:
                result += 1

    else:
        continue

print(result)

Solution (Python):
n = int(input())
code = input()
f = 0
total = 0
for i in range(0,1000):
  s = str(i)
  if i< 10:
    s = '00' + s
  elif i < 100:
    s = '0' + s
  idx = -1
  for dig in range(3):
    idx = code.find(s[dig], idx+1) 
    if idx == -1:
      break
  if idx != -1:
    total += 1
print(total)

Solution (Python):
N = int(input())
S = list(input())
S = [int(s) for s in S]

left = [[0]*10 for _ in range(N)]
right = [[0]*10 for _ in range(N+1)]

ans = [0]*1000 

for i,s in enumerate(S):
  for j in range(10):
    left[i][j] = left[i-1][j]
  left[i][s] = 1
  
for i,s in enumerate(S[::-1]):
  for j in range(10):
    right[N-i-1][j] = right[N-i][j]
  right[N-i-1][s] = 1
  
for i,s in enumerate(S):
  if 0<i<N-1:
    for l in range(10):
      for r in range(10):
        if left[i-1][l] and right[i+1][r]:
          
          ans[100*l+10*s+r]=1
          
print(sum(ans))

Solution (Python):
import collections

n = int(input())
s = input()





dic_forward = {}
for i in range(n-2):
    if int(s[i]) not in dic_forward.keys():
        
        dic_forward[int(s[i])] = i

dic_backward = {}
for i in range(n-1,1,-1):
    if int(s[i]) not in dic_backward.keys():
        dic_backward[int(s[i])] = i

for i in range(10):
    if i not in dic_forward.keys():
        dic_forward[i] = -1
for i in range(10):
    if i not in dic_backward.keys():
        dic_backward[i] = -1



ans = 0

for i in range(10):
    for j in range(10):
        if dic_forward[i] >= 0 and dic_backward[j] >= 0:
            if dic_backward[j] - dic_forward[i] > 1:
                
                
                
                ans += len(collections.Counter(s[dic_forward[i]+1:dic_backward[j]]))
print(ans)

Solution (Python):
N = int(input())
S = input()
keta = 10
count = 0
for i in range(keta):
    for j in range(keta):
        for k in range(keta):
            nnn = str(i) + str(j) + str(k)
            now = 0
            nownnn = nnn[now]
            flag = False
            for l in range(N):
                if S[l] == nownnn:
                    if now == 2:
                        flag = True
                        break
                    else:
                        now += 1
                        nownnn = nnn[now]
            if flag:
                count += 1
print(count)

Solution (Python):
from collections import Counter

x=int(input())
n=str(input())




aaa=set([])
result=0
for i in range(x-2):
    a=n[i]
    if a not in aaa:
        aaa.add(a)
        bbb=set([])
        for j in range(i+1,x-1):
            b=n[j]
            if b not in bbb:
                bbb.add(b)
                ccc=set([])
                for k in range(j+1,x):
                    c=n[k]
                    if c not in ccc:
                        ccc.add(c)
                        result+=1
    if len(aaa)==10:
        break
print(result)

Solution (Python):
n = int(input())
s = input()

kind = 0

first = []
for i in range(n-2):
  if s[i] not in first:
    first.append(s[i])
    second = []
    for j in range(i+1, n-1):
      if s[j] not in second:
        second.append(s[j])
        third = []
        for k in range(j+1, n):
          if s[k] not in third:
            third.append(s[k])
        kind += len(third)
print(kind)

Solution (Python):
import bisect
n=int(input())
s=input()
t=[[] for i in range(10)]
for i in range(n):
    t[int(s[i])].append(i)
c=0
for i in range(10):
    if len(t[i])==0:
        continue
    for j in range(10):
        if len(t[j]) == 0:
            continue
        m=bisect.bisect(t[j],t[i][0])
        if len(t[j])==m:
            continue
        for k in range(10):
            if len(t[k]) == 0:
                continue
            n=bisect.bisect(t[k],t[j][m])
            if len(t[k])==n:
                continue
            else:
                c+=1
print(c)

Solution (Python):
from collections import defaultdict

n = int(input())
s = list(map(int, input()))

a = [0] * n
tmp = set()
for i in range(n)[::-1]:
    a[i] = len(tmp)
    tmp.add(s[i])

b = [0] * n
tmp = defaultdict(int)
for i in range(n)[::-1]:
    for x in tmp.values():
        b[i] += a[x]
    tmp[s[i]] = i

ans = 0
tmp = set()
for i in range(n):
    if s[i] in tmp: continue
    ans += b[i]
    tmp.add(s[i])

print(ans)

Solution (Python):
def examD():
    N = I();  S = SI()
    dp = [[0]*10 for _ in range(N+1)]
    for i in range(N):
        for j in range(10):
            dp[i+1][j] = dp[i][j]
        dp[i+1][int(S[i])] +=1
    left = [-1]*10; right = [-1]*10
    for i in range(N):
        if left[int(S[i])]==-1:
            left[int(S[i])] = i
    for i in range(N-1,-1,-1):
        if right[int(S[i])]==-1:
            right[int(S[i])] = i
    ans = 0


    for i in left:
        if i>=0:
            for j in right:
                if j>=0:
                    for k in range(10):
                        if dp[j][k]>0 and dp[j][k] - dp[i+1][k] > 0:
                            ans += 1

    print(ans)
    return
def examE(mod):
    N = I()
    A = LI()
    a =[0,0,0]
    cur = 1
    for i in A:
        if a[0]==i:
            if a[0]==a[1]:
                if a[1]==a[2]:
                    cur *= 3
                else:
                    cur *=2
            a[0]+=1
        elif a[1]==i:
            if a[1] == a[2]:
                cur *= 2
            a[1] +=1
        elif a[2]==i:
            a[2]+=1
        else:
            cur *=0
        a.sort(reverse=True)
        cur %=mod
    print(cur)
    return

def examF():
    T = LI()
    A = LI()
    B = LI()
    loop1 = T[0]*(A[0]-B[0])
    loop2 = T[1]*(A[1]-B[1])
    if loop1>0 and loop2>0:
        ans = 0
    elif loop1<0 and loop2<0:
        ans = 0
    else:
        now = loop1
        cur = loop1+loop2

        if cur!=0:
            ans = abs(now)//abs(cur)*2
            if abs(now)%abs(cur)!=0:
                judge = now + cur*ans//2
                if (now>0 and judge+loop1>0) or (now<0 and judge+loop1<0):
                    ans +=1
        else:
            ans = "infinity"
    print(ans)
    return

import sys,copy,bisect,itertools,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Solution (Python):
n = int(input())
s = str(input())
s_rev = s[::-1]

ans = 1000

can = [i for i in range(0,1000)]
can_str = []

for c in can:
    can_s = str(c)
    if len(can_s) == 1:
        can_s = '00' + can_s
    elif len(can_s) == 2:
        can_s = '0' + can_s
    can_str.append(can_s)

for c in can_str:
    try:
        i = s.index(c[0])
        k = s_rev.index(c[2])
        ind = n - k -1
        if i >= ind:
            raise ValueError
        if s[i+1:ind].count(c[1]) == 0:
            raise ValueError
    except:
        ans -= 1

print(ans)

Solution (Python):
from bisect import bisect_right as br

def main():
    N = int(input())
    S = input()
    P = [[ ] for _ in range(10)]
    for s,index in zip(S,range(N)):
        P[int(s)].append(index)
    ans = 0 
    for i in range(0,1000):
        
        a = i // 100
        b = (i % 100) // 10
        c = i % 10
        try:
            if len(P[a]) > 0:
                point = P[a][0]
                if len(P[b]) > 0:
                    tmp = br(P[b],point)
                    if P[b][tmp] > point:
                        point = P[b][tmp]
                        if len(P[c]) > 0:
                            neko = br(P[c],point)
                            if P[c][neko] > point:
                                ans += 1
        except:
            ans = ans
    print(ans)
    return 

main()

Solution (Python):
n = int(input())
s = input()
s2 = [int(v) for v in s]

cnt = 0

for i in range(0, 10):
    if i in s2:
        ad1 = s.find(str(i))
        for j in range(0, 10):
            if j in s2[ad1 + 1:]:
                ad2 = s.find(str(j), ad1 + 1)
                for k in range(0, 10):
                    if k in s2[ad2 + 1:]:
                        cnt += 1

print(cnt)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            flag=[0,0,0]
            for index in range(n):
                if flag[0]==0 and flag[1]==0 and  s[index]==str(i):
                    flag[0]=1
                elif flag[0]==1 and flag[1]==0 and s[index]==str(j):
                    flag[1]=1
                elif flag[0]==1 and flag[1]==1 and s[index]==str(k):
                    ans+=1

                    break
                else:
                    continue
print(ans)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1000):
  i1 = str(i)
  i2 = i1.zfill(3)
  index1 = s.find(i2[0])
  if (index1 == -1) or (index1 == n-1):
    continue
  else:
    index1 += 1
    index2 = s.find(i2[1],index1)
    if (index2 == -1) or (index2 == n-1):
      continue
    else:
      index2 += 1
      index3 = s.find(i2[2],index2)
      if index3 != -1:
        ans += 1
print(ans)

Solution (Python):
n = int(input())
s = input()

ans = 0

for i in range(1000):
  num = '{:03}'.format(i)
  num_i = 0
  for j in range(n):
    if num[num_i] == s[j]:
      num_i += 1
      if num_i > 2:
        
        ans += 1
        break

print(ans)

Solution (Python):
from bisect import bisect_right

N=int(input())
S=input()
pos=[[] for _ in range(10)]
ans=0
for i in range(N):
  pos[int(S[i])].append(i)
for i in range(10**3):
  digit1, digit2, digit3=i//100, (i%100)//10, i%10
  if not pos[digit1] or not pos[digit2] or not pos[digit3]:
    continue
  pos1=pos[digit1][0]
  if pos1>=pos[digit2][-1]:
    continue
  idx2=bisect_right(pos[digit2], pos1)
  if idx2>=len(pos[digit2]):
    continue
  pos2=pos[digit2][idx2]
  if pos2>=pos[digit3][-1]:
    continue
  idx3=bisect_right(pos[digit3], pos2)
  if idx3>len(pos[digit3]):
    continue
  else:
    ans+=1
print(ans)

Solution (Python):
from bisect import bisect_right

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

nums = {i:[] for i in range(10)}

for idx, s in enumerate(S):
    nums[int(s)].append(idx+1)
    
length = {i:len(nums[i]) for i in range(10)}
ans = 0
for i in range(1000):
    idx = 0   
    
    for j in str(i).zfill(3):
        n = int(j)
        x = bisect_right(nums[n], idx)
        if length[n] == x: break
        idx = nums[n][x]
    else: 
        ans += 1

print(ans)

Solution (Python):
import collections

n = int(input())
s = str(input())

ans = 0
for i in range(10):
  i_bannme = s.find(str(i))
  if i_bannme == -1:
    continue
  else:
    for j in range(10):
      j_bannme = s.find(str(j), i_bannme+1)
      if j_bannme== -1:
        continue
      else:
        ans += len(collections.Counter(s[j_bannme+1:]))

print(ans)

Solution (Python):
n = int(input())
s = input()
dp1 = {}
for i in range(10):
    dp1[str(i)] = -1
dp2 = {}
for i in range(10):
    for j in range(10):
        dp2[str(i) + str(j)] = -1

for i in range(n):
    if dp1[s[i]] == -1:
        dp1[s[i]] = i

for i in range(10):
    if dp1[str(i)] != -1:
        for j in range(dp1[str(i)]+1, n):
            if dp2[str(i)+str(s[j])] == -1:
                dp2[str(i)+str(s[j])] = j

dp3 = {}
for i in range(10):
    dp3[i] = [0] * (n+1)
for i in range(n):
    dp3[int(s[i])][i+1] = 1
for i in range(10):
    for j in range(n):
        dp3[i][j+1] += dp3[i][j]


ans = 0
for i in range(10):
    for j in range(10):
        t = dp2[str(i)+str(j)]
        for k in range(10):
            if t != -1: 
                if dp3[k][n] - dp3[k][t+1] >= 1:
                     ans += 1
print(ans)

Solution (Python):
input()
S=list(input())
ans=0

def index(x,l):
    if x in l:
        return l.index(x)
    else:
        return -1

for i in range(1000):
    Si=0
    s=list(str(i).zfill(3))
    si=0
    if index(s[0],S) != -1:
        if index(s[1],S[S.index(s[0])+1:]) != -1:
            if index(s[2],S[S.index(s[0])+1:][S[S.index(s[0])+1:].index(s[1])+1:]) != -1:
                ans += 1
print(ans)

Solution (Python):

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

count = 0
for i in range(10):
  n1 = S.find(str(i))
  if not(n1 == -1 or n1 >= N-2):
    S2 = S[n1+1:]
    for j in range(10):
      n2 = S2.find(str(j))
      if not(n2 == -1 or n2 >= N-1):
        S3 = S2[n2+1:]
        for k in range(10):
          n3 = S3.find(str(k))
          if(n3 != -1):
            count += 1

print(count)

Solution (Python):
n = int(input())
s = input()
list_s = [[] for _ in range(10)]
exist = []
a_c = []
count = 0


for index, num_str in enumerate(s):
    list_s[int(num_str)].append(index)


for i in range(10):
    if list_s[i]:
        exist.append(i)


for a in exist:
    for c in exist:
        a_c.append((a, c))

for b in exist:  
    for a, c in a_c:  
        for b_index in list_s[b]:  
            if list_s[a][0] < b_index < list_s[c][-1]:
                count += 1
                break

print(count)

Solution (Python):
words = lambda t : list(map(t, input().split()))
n = int(input())
a = input()

d = {}
r_nums = [0] * 10
for i in range(1,n):
    r_nums[int(a[i])] += 1
l_nums = [0] * 10

for i in range(1,n-1):
    center = int(a[i])
    r_nums[int(a[i])] -= 1
    l_nums[int(a[i-1])] += 1
    
    for j in range(10):
        for k in range(10):
            if r_nums[j] > 0 and l_nums[k] > 0:
                d[k*100 + center*10 + j] = 1
    
print(len(d))

Solution (Python):
N = int(input())
S = input()

pins = []
for i in range(10):
  for j in range(10):
    for k in range(10):
      pins.append(str(i) + str(j) + str(k))

ans = 0
for p in pins:
  i = S.find(p[0])
  if i >= 0:
    j = S[i + 1 :].find(p[1])
    if j >= 0:
      k = S[i + j + 2 :].find(p[2])
      if k >= 0:
        ans += 1
print(ans)

Solution (Python):
N = int(input())
S = input()
count = 0
for i in range(1000):
    j = i
    if(j<10):
        first = S.find('0')    
        if(first >= 0 and first < N):
            second = S[first+1:].find('0')    
            if(second >= 0 and first+second+2 < N):
                third = S[first+second+2:].find(str(j))
                if(third>=0):
                    count += 1
    elif(j<100):
        first = S.find('0')
        if(first >= 0 and first < N):
            second = S[first+1:].find(str((j%100)//10))
            if(second >= 0 and first+second+2 < N):
                third = S[first+second+2:].find(str(j%10))
                if(third>=0):
                    count += 1
    else:
        first = S.find(str(j//100))    
        if(first >= 0 and first < N):
            second = S[first+1:].find(str((j%100)//10))    
            if(second >= 0 and first+second+2 < N):
                third = S[first+second+2:].find(str(j%10))
                if(third>=0 ):
                    count += 1  
print(count)

Solution (Python):
import sys

readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    S = readline()
    S = S.decode("UTF-8")
    S = list(S[0:-1])

    cnt = 0
    for i in range(10):
        if str(i) in S:
            ind_i = S.index(str(i))
        else:
            continue
        for j in range(10):
            if str(j) in S[ind_i + 1:]:
                ind_j = S[ind_i + 1:].index(str(j))
                ind_j += ind_i + 1
            else:
                continue
            for k in range(10):
                if str(k) in S[ind_j + 1:]:
                    cnt += 1
                else:
                    continue

    print(cnt)


main()

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) 

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
S = list(str(input()))

ans = 0
for i in range(1000):
    nums = list(str(i).zfill(3))
    fir = 0
    cnt = 0
    for num in nums:
        try:
            fir = S[fir:].index(num) + fir + 1
            cnt += 1
        except:
            break
    if cnt == 3:
        
        ans += 1

print(ans)

Solution (Python):
N=int(input())
S=list(input())
L=[str(i)+str(j) for i in range(10) for j in range(10)]
n=0
for l in L:
  I=N
  for i in range(N):
    if S[i]==l[0]:
      I=i
      break
  J=N
  for j in range(I+1,N):
    if S[j]==l[1]:
      J=j
      break
  n+=len(list(set(S[J+1:N])))
print(n)

Solution (Python):
N = int(input())
S = input()
NEX = [[float("inf")]*10 for i in range(N+1)]
for i in range(N):
    j = N-1-i
    for k in range(10):
        NEX[j][k] = NEX[j+1][k]
    NEX[j][int(S[j])] = j
from collections import defaultdict
dp = defaultdict(int)
for i in range(1000):
    j = "0"*(3-len(str(i))) + str(i)
    dp[i] = 0
ans = 0    
for i in range(10):
    idx1 = NEX[0][i]
    if idx1 != float("inf"):
        for j in range(10):
            idx2 = NEX[idx1+1][j]
            if idx2 != float("inf"):
                for k in range(10):
                    idx3 = NEX[idx2+1][k]
                    if idx3 != float("inf"):
                        ans += 1
                        
print(ans)

Solution (Python):
N = int(input())
S = input()
data = set()
xd,yd = set(),set()
for i in range(N-2):
  x = S[i]
  if x in xd:
    continue
  else:
    xd.add(x)
    yd = set()
  for j in range(i+1,N-1):
    y = S[j]
    if y in yd:
      continue
    else:
      yd.add(y)
    for k in range(j+1,N):
      z = S[k]
      data.add(x+y+z)
print(len(data))

Solution (Python):
def main():
    N = int(input())
    S = input()

    count = 0

    for i in range(10):
        a = S.find(str(i))
        if a == -1:
            continue

        for j in range(10):
            b = S[a+1:].find(str(j))
            if b == -1:
                continue

            for k in range(10):
                if str(k) in S[a+b+2:]:
                    
                    count += 1

    print(count)


if __name__ == '__main__':
    main()

Solution (Python):


''' 
------------------------
author : iiou16
------------------------
'''

def main():
    N = int(input())
    S = input()

    fst_num = []
    scd_num = []
    count = 0
    for i in range(len(S)-2):
        if len(fst_num) == 10:
            break
        if S[i] not in fst_num:
            fst_num.append(S[i])
            scd_num = []
            for j in range(i+1, len(S) - 1):
                if len(scd_num) == 10:
                    break
                if S[j] not in scd_num:
                    scd_num.append(S[j])
                    for k in range(10):
                        if str(k) in S[j+1:]:
                            
                            count += 1
    print(count)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
s=list(input())

memo=[0]*1000

sudeni1=set() 
sudeni2=set() 
sudeni3=set()

sudeni1.add(str(s[0]))
sudeni1.add(str(s[1]))
sudeni2.add(str(s[0])+str(s[1]))

for i in range(2,n):
  temp1=list(sudeni1)
  temp2=list(sudeni2)
  for j in temp2: 
    sudeni3.add(j+str(s[i]))
  for j in temp1: 
    sudeni2.add(j+str(s[i]))
  sudeni1.add(str(s[i]))

print(len(sudeni3))

Solution (Python):
N=int(input())
S=input()
L1=[0]*10

count=0
for idx1 in range(len(S) -2):
    C1 = S[idx1]
    if L1[int(C1)] == 1:
        continue
    L1[int(C1)] = 1
    L2=[0]*10
    for idx2 in range(len(S) -1)[idx1 + 1:]:
        C2 = S[idx2]
        if L2[int(C2)] == 1:
            continue
        L2[int(C2)] = 1
        L3=[0]*10
        for idx3 in range(len(S))[idx2 + 1:]:
            C3 = S[idx3]
            if L3[int(C3)] == 1:
                continue            
            L3[int(C3)] = 1
            count += 1
print(count)

Solution (Python):
N = int(input())
S = input()


pins = set()
pins_check = set()

def bfs():    
    from collections import deque
    queue = deque([(S, '', 0)])
    while queue:
        tmp_s, tmp_pin, tmp_cnt = queue.popleft()
        if tmp_cnt == 3:
            pins.add(tmp_pin)
            continue
        
        for i in range(len(tmp_s)):
            if tmp_pin+tmp_s[i] in pins_check:
                continue
            pins_check.add(tmp_pin+tmp_s[i])
            queue.append((tmp_s[i+1:], tmp_pin+tmp_s[i], tmp_cnt+1))

ans = bfs()

print(len(pins))

Solution (Python):
n=int(input())
s=list(input())
s=[int(i) for i in s]
res=[[0 for i in range(10)]for i in range(n)]
for i in range(n-1,0,-1):
    for j in range(10):
        res[i-1][j]=res[i][j]
    res[i-1][s[i]]+=1
cnt=0

a=[0]*10
for i in range(n-2):
    if a[s[i]]!=0:
        continue
    a[s[i]]+=1
    b=[0]*10
    for j in range(i+1,n-1):
        if b[s[j]]==0:
            b[s[j]]+=1
            cnt+=10-res[j].count(0)

print(cnt)

Solution (Python):
import itertools
N=int(input())
S=[int(thing) for thing in list(input())]
kes=N-3
pass_set=set([])
def passkosu(k):
    num = 0

    if k in S[0:N-1]:
        l_left=S.index(k)
        for l in range(0,10):
            if l in S[l_left+1:N-1]:
                l_center=S[l_left+1:].index(l)+l_left+1
                dif=len(set(S[l_center+1:]))
                num=num+dif
    return num

print(sum([passkosu(i) for i in range(0,10)]))

Solution (Python):
N=int(input())
S=input()
PIN=[]
b1=[]
for i in range(N-2):
    Ein=S[i]
    b2=[]
    if Ein in b1:
        continue
    else:
        b1.append(Ein)
    for j in range(i+1,N-1):
        b3=[]
        Zwei=S[j]
        if Zwei in b2:
            continue
        else:
            b2.append(Zwei)
        for k in range(j+1,N):
            Drei=S[k]
            if Drei in b3:
                continue
            else:
                b3.append(Drei)
                cand=Ein+Zwei+Drei
            if cand in PIN:
                continue
            else:
                PIN.append(cand)
print(len(PIN))

Solution (Python):
import sys
input = sys.stdin.readline

_n = int(input())
_s = input()[:-1]


def chker(n, s):
    flg = [0] * 1000
    for i in range(1000):
        password = str(i).zfill(3)
        digit = 0
        for num in s:
            if password[digit] == num:
                digit += 1

            if digit == 3:
                flg[i] = 1
                break

    print(sum(flg))


chker(_n, _s)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = list(input())


al = set()

dp = [[[0 for k in range(10)] for i in range(10)] for j in range(10)]


kkk = [[0 for j in range(10)]for i in range(n)]
count = 0
for i in range(n):
    k = int(a[i])
    if i == 0:
        kkk[i][k] += 1
    else:
        for j in range(10):
            if k == j:
                kkk[i][j] += kkk[i-1][j] + 1
            else:
                kkk[i][j] += kkk[i-1][j]

for i in range(1,n-1):
    e = int(a[i])
    ae = []
    for pl in range(10):
        if kkk[i-1][pl] > 0:
            ae.append(pl)
    for pl in range(10):
        if kkk[-1][pl] - kkk[i][pl] > 0:
            for pp in ae:
                if not dp[pp][e][pl]:
                    count += 1
                    dp[pp][e][pl] += 1
                    


print(count)

Solution (Python):

"""
AtCoder A
"""

import sys, math, random
import numpy as np
import itertools
from functools import reduce
from itertools import chain







inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    N=I()
    X=S()
    OUT=np.array([[[0]*10]*10]*10)

    for i in range(10):
        x=(X.find(str(i)))
        if x>-1:
            X2=X[x+1:]
            for j in range(10):
                y=(X2.find(str(j)))
                if y>-1:
                    X3=X2[y+1:]
                    for k in range(10):
                        z=(X3.find(str(k)))
                        if z>-1:
                            OUT[i][j][k]=1

    print(OUT.sum())


        
        
        
        
        

        
        
        
        
        
        
        
        
        
        



    
    

if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())
S=input()

count=0
for i in range(1000):
    W=str(i).rjust(3,'0')
    a,b,c=W[0],W[1],W[2]
    t=0
    while S[t]!=a and t<N-1:
        t+=1
    t+=1
    if t>N-1:
        continue
    while S[t]!=b and t<N-1:
        t+=1
    t+=1
    if t>N-1:
        continue
    while S[t]!=c and t<N-1:
        t+=1
    if t<N:
        if S[t]==c:

            count+=1

print(count)

Solution (Python):


n = int(input())
l = [d for d in input()]
k = set(l[:-2])
c = 0
for kk in list(k):
    i = l[:-2].index(kk)
    o = set(l[i + 1:-1])
    for oo in list(o):
        ii = l[i + 1:-1].index(oo) + (i + 1)
        p = set(l[ii + 1:])
        c += len(p)
print(c)

Solution (Python):
N = int(input())
S = list(input())
for i,s in enumerate(S):
    S[i] = int(s)

res = 0
first_index = [-1 for i in range(10)]
second_index = [[-1 for i in range(10)] for j in range(10)]

first_map = set()
second_map = [set() for i in range(10)]
third_map = [[set() for i in range(10)] for j in range(10)]

for i,s in enumerate(S):
    if(first_index[s] == -1):
        first_index[s] = i
        first_map.add(s)
    if(len(first_map) == 10):
        break
for first in first_map:
    for i,s in enumerate(S[first_index[first]+1:]):
        if(second_index[first][s] == -1):
            second_index[first][s] = first_index[first]+1+i
            second_map[first].add(s)
        if(len(second_map[first]) == 10):
            break
for first in first_map:
    for second in second_map[first]:
        for i,s in enumerate(S[second_index[first][second] + 1:]):
            if(s not in third_map[first][second]):
                res += 1
                third_map[first][second].add(s)
            if(len(third_map[first][second]) == 10):
                break
print(res)

Solution (Python):
N = int(input())
s = input()

cnt = 0
for i in range(1000):
    num = str(i).zfill(3)
    j = 0
    for t in s:
        if num[j] == t:
            j += 1
            if j == 3:
                cnt += 1
                break
print(cnt)

Solution (Python):
N = int(input())
S = input()

numlist = [""]
dp = [False] * 1000
for s in S:
    tmp = []
    for n in numlist:
        if len(n+s) == 3:
            dp[int(n+s)] = True
        if len(n+s) < 3:
            tmp.append(n+s)
    numlist.extend(tmp)
    numlist = list(set(numlist))
print(sum(dp))

Solution (Python):

def main():
    N=int(input())
    strvar = input()
    
    
    
    

    possible = 0
    for i in range(10):
        iind = strvar.find(str(i))
        if iind == -1:
            continue
        for j in range(10):
            jind =strvar[iind+1:].find(str(j))
            if jind==-1:
                continue
            for k in range(10):
                if str(k) in strvar[iind+1+jind+1:]:
                    possible += 1

    print(possible)


if __name__=="__main__":
    main()

Solution (Python):
import bisect

n = int(input())
s = input()

idx = [[] for i in range(10)]

for i in range(n):
  idx[ord(s[i]) - ord('0')].append(i)

ans = 0
for i in range(1000):
  flag = True
  i_str = format(i, "03d")
  _idx = -1
  for j in range(3):
    if not flag or len(idx[ord(i_str[j]) - ord('0')]) == 0:
      flag = False
      break
    __idx = bisect.bisect_left(idx[ord(i_str[j]) - ord('0')], _idx + 1)
    if __idx == len(idx[ord(i_str[j]) - ord('0')]):
      flag = False
      break
    else:
      _idx = idx[ord(i_str[j]) - ord('0')][__idx]
  if flag:
    ans += 1
print(ans)