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):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

n = int(input())
s = input()
cnt = 0
for i in range(1000):
    c = str(i)
    one,two,three = -1,-1,-1
    if len(c)<3:
        while True:
            if len(c) == 3:
                break
            c = "0" + c
    for j in range(n):
        if s[j] == c[0]:
            one = j
            break
    if one != -1:
        for j in range(one+1,n):
            if s[j] == c[1]:
                two = j
                break
    if two != -1:
        for j in range(two+1,n):
            if s[j] == c[2]:
                three = j
                break
    if three != -1:
        cnt+=1
print(cnt)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    S = readline().strip()

    ans = 0
    for n in range(1000):
        n = str(n).zfill(3)
        idx = 0
        for s in S:
            if s == n[idx]:
                idx += 1
                if idx == 3:
                    ans += 1
                    break

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    S = readline().strip()

    ans = 0
    for n in range(1000):
        n = str(n).zfill(3)
        idx = 0
        for s in S:
            if s == n[idx]:
                idx += 1
                if idx == 3:
                    ans += 1
                    break

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import itertools

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

candi = list(itertools.product(range(10),repeat=3))

cnt = 0

for i in candi:
    if str(i[0]) in S:
        T = S[S.find(str(i[0]))+1:]
        if str(i[1]) in T:
            U = T[T.find(str(i[1]))+1:]
            if str(i[2]) in U:
                cnt += 1

print(cnt)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    n = II()
    S = list(map(int, list(input())))

    ans = 0
    for v in range(0, 1000):
        V = list(str(v))
        if len(V) == 2:
            V.insert(0, '0')
        elif len(V) == 1:
            V.insert(0, '0')
            V.insert(0, '0')
        elif len(V) == 0:
            V.insert(0, '0')
            V.insert(0, '0')
            V.insert(0, '0')
        

        
        cnt = 0
        for s in S:
            
            if V[cnt] == str(s):
                cnt += 1
                if cnt == 3:
                    
                    break
        
        
        if cnt == 3:
           ans += 1
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
N = int(input())
S = input()
 
res = 0
for i in range(10):
    if str(i) in S:
        T = S[S.index(str(i))+1:]
        
        for j in range(10):
            if str(j) in T:
                U = T[T.index(str(j))+1:]
                
                for k in range(10):
                    if str(k) in U:
                        res += 1
                
print(res)

Solution (Python):
def solve():
    N = int(input())
    s = input()
    ans = 0
    for i in range(1000):
        t = str(i).zfill(3)
        t_index = 0 
        for s_index in range(N):
            if s[s_index] == t[t_index]:
                t_index += 1
                if t_index == 3:
                    break
        if t_index == 3:
            ans += 1
    print(ans)
solve()

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


n = int(input())
s = input()
ans = 0
for i in range(1000):
    t = str(i).zfill(3)
    ti = 0
    for si in range(n):
        if s[si] == t[ti]:
            ti += 1
            if ti == 3:
                break
    if ti == 3:
        ans += 1
print(ans)

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

for i in range(10):
    for j in range(10):
        for k in range(10):
            current = 0
            require = [str(i), str(j), str(k)]
            for v in s:
                if v == require[current]:
                    current += 1
                    if current == 3:
                        res += 1
                        break
print(res)

Solution (Python):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd 
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) 







n = int(input())
s = input()
cnt = 0
q = s[0]
t = s[0]
for x in s[1:]:
    if x == q:
        cnt += 1
        if cnt < 3:
            t += x
    else:
        cnt = 0
        t += x
        q = x
ans = 0
for i in range(10):
    x = t.find(str(i)) + 1
    if not x: continue
    for j in range(10):
        y = t[x:].find(str(j)) + 1
        if not y: continue
        for k in range(10):
            z = t[x + y:].find(str(k)) + 1
            if not z: continue
            
            ans += 1
print(ans)

Solution (Python):
import numpy as np

n = int(input())
s = input()
ar = [[0 for i in range(3)] for j in range(1000)]
kakunin = [0 for i in range(1000)]
index = 0
res = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            a = s.find(str(i))

            if a == -1:
                continue

            b = s[a+1:len(s)].find(str(j))
            if b == -1:
                continue
            c = s[a+b+2:len(s)].find(str(k))
            if c != -1:
                
                
                
                res += 1
print(res)

Solution (Python):
n = int(input())
s = input()
cnt = 0
for i in range(1000):
    p = '{:03}'.format(i)
    s2 = s
    for j in range(3):
        if s2.find(p[j]) == -1:
            break
        s2 = s2[s2.find(p[j]) + 1:]
    else:
        cnt += 1
print(cnt)

Solution (Python):
import itertools
n=(int)(input())
moji = list('0123456789')
s=input()
count = 0

for i in itertools.product(moji, repeat=3):
  sousa = list(s)
  try:
    
    n1 = sousa.index(i[0])
    n2 = sousa[n1+1:].index(i[1])+n1+1
    n3 = sousa[n2+1:].index(i[2])+n2+1
    
    count += 1
  except ValueError:
    continue
  
  
  
  
print(count)

Solution (Python):
from itertools import product

N = int(input())
S = input()
S = [int(s) for s in S]


res = 0
for q in product(range(10), repeat=3):
    i = 0
    for s in S:
        if s==q[i]:
            if i==2:
                res += 1
                break
            else:
                i+=1
print (res)

Solution (Python):
import bisect
N = int(input())
S = input()
where = {str(s):[] for s in range(10)}
for i, s in enumerate(S):
    where[s].append(i)
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    
    s = v[0]
    if len(where[s]) > 0:
        before_index = where[s][0]
        
        c = 1
        for j in range(1, 3):
            s = v[j]
            if len(where[s]) > 0:
                next_index = bisect.bisect_left(where[s], before_index+1)
                if next_index == len(where[s]):
                    break
                
                next_index = where[s][next_index]
                
                if next_index > before_index:
                    before_index = next_index
                    c += 1
            else:
                break
        if c == 3:
            
            ans += 1
print(ans)

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

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

count = 0
for i in range(1000):
    password = '{:03}'.format(i)
    s = S
    for j in range(3):
        index = s.find(password[j])
        if index == -1:
            break
        s = s[index + 1:]
    else:
        count += 1

print(count)

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

count = 0
for i in range(1000):
    num = "{:03}".format(i)
    cursor = -1
    ok = True
    for c in num:
        slice = S[cursor + 1:]
        if c not in slice:
            ok = False
            break
        cursor += slice.index(c) + 1
    if ok:
        count += 1

print(count)

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

count =0
for i in range(10):
    first =0
    if i in s:
        first = s.index(i)
        for j in range(10):
            second = 0
            if j in s[first+1:n+1]:
                second = s[first+1:n+1].index(j)+first+1
                for k in range(10):
                    if k in s[second+1:n+1]:
                        count += 1
                    else:
                        continue
            else:
                continue
    else:
        continue

print(count)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(1000):
  t=str(i).zfill(3)
  j=0
  for s_i in s:
    if j<3 and t[j]==s_i:
      j+=1
  if j==3:
    ans+=1
print(ans)

Solution (Python):
n=int(input())
s=list(input())
ans=0
for i in range(10):
    if str(i) in s:
        first=s.index(str(i))
        for j in range(10):
            if str(j) in s[first+1:]:
                second=first+1+s[first+1:].index(str(j))
                for k in range(10):
                    if str(k) in s[second+1:]:
                        ans+=1
print(ans)

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

T=[]
c=0
for i in range(10):
  T=S
  i=str(i)
  if i in T[:N-2]:
    indx_i=T.index(i) 
    for j in range(10):
      j=str(j)
      if j in T[indx_i+1:N-1]:
        indx_j=indx_i+T[indx_i+1:].index(j)+1
        for k in range(10):
          k=str(k)
          if k in T[indx_j+1:]:
            c+=1

print(c)

Solution (Python):
N = int(input())
S = list((input()))
L = [str(i) for i in range(0,10)]
ALL =[]
for i in L:
    for j in L:
        for k in L:
            ALL.append(i+j+k)
cnt=0    
for a in ALL:
    try:
        
        I1 = S.index(a[0])
        I2 = S[I1+1:].index(a[1])+len(S[:I1+1])
        I3 = S[I2+1:].index(a[2])+len(S[:I2+1])

        if I1<I2 and I2<I3:
            cnt+=1
    except:
        continue
print(cnt)

Solution (Python):
import re
def main():
    S = input()
    S = input()
    l = len(S)
    cnt = 0


    for i in range(10):
        iti = 0
        iti = S.find(str(i))
        if iti == -1 :
            continue
        for j in range(10):
            s = S[iti+1:]
            itj = s.find(str(j))
            if itj == -1 :
                continue
            for k in range(10):
                t = s[itj+1:]
                itk = t.find(str(k))
                if itk != -1 :
                    cnt += 1

    print(cnt)



if __name__ == '__main__':
    main()

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

ans = 0


for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = 0
            flag2 = 0
            
            for l in range(n):
                if flag1 == 0 and s[l] == str(i):
                    flag1 = 1
                    continue
                
                if flag1 == 1 and flag2 == 0 and s[l] == str(j):
                    flag2 = 1
                    continue
                
                if flag1 == 1 and flag2 == 1 and s[l] == str(k):
                    ans += 1
                    break
                
print(ans)

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

ans = 0

for i in range(10):
    a = S.find(str(i))
    if -1 == a:
        continue
    for j in range(10):
        b = S.find(str(j), a + 1)
        if -1 == b:
            continue
        for k in range(10):
            c = S.find(str(k), b + 1)
            if -1 == c:
                continue
            ans += 1
            

print(ans)

Solution (Python):
N = int(input())
S = str(input())
cnt = 0

for i in range(10):
  l = S.find(str(i))
  if l == -1:
    continue
  for j in range(10):
    m = S.find(str(j), l + 1)
    if m == -1:
      continue
    for k in range(10):
      n = S.find(str(k), m + 1)
      if n == -1:
        continue
      cnt += 1
print(cnt)

Solution (Python):
N = int(input())
S = list(map(int,input()))

cnt = 0
for i in range(10):
    if i in S:
        k = S.index(i)
        for j in range(10):
            if j in S[k+1:]:
                l = S[k+1:].index(j)
                cnt += len(set(S[k+l+2:]))

print(cnt)

Solution (Python):
def Meg_nib(ng,border,lists):
    ng = -1
    ok = len(lists) - 1
    if len(lists) == 0 or border >= lists[ok]:
        return -1
    while(abs(ng - ok) > 1):
        mid = (ok + ng) // 2
        if lists[mid] > border:
            ok = mid
        else:
            ng = mid
    return lists[ok]

N = input()
S = input()
ans = 0
k = 0
k2 = 0
k3 = 0
find = [[]for _ in range(10)]
for i in range(len(S)):
    find[int(S[i])].append(i)
for i in range(10):
    for i2 in range(10):
        for i3 in range(10):
            k = Meg_nib(0,-1,find[i])
            if k == -1:
                break
            k2 = Meg_nib(0,k,find[i2])
            if k2 == -1:
                break
            k3 = Meg_nib(0,k2,find[i3])
            if k3 != -1:
                ans += 1
print(ans)

Solution (Python):
from bisect import bisect_left

def main():
    N = int(input())
    S = tuple(map(int, tuple(input())))
    place = [[] for _ in range(10)]
    for i, c in enumerate(S):
        place[c].append(i)
    ans = 0
    for i in range(10):
        temp = bisect_left(place[i], 0)
        if temp == len(place[i]):
            continue
        idx_1 = place[i][temp]

        for j in range(10):
            temp = bisect_left(place[j], idx_1+1)
            if temp == len(place[j]):
                continue
            idx_2 = place[j][temp]
            
            for k in range(10):
                temp = bisect_left(place[k], idx_2+1)
                if temp == len(place[k]):
                    continue
                ans += 1
    print(ans)

if __name__ == "__main__":
    main()

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

ans = 0

for a in range(10):
  if str(a) in S:
    b = S[S.index(str(a))+1:]
    for j in range(10):
      if str(j) in b:
        c = b[b.index(str(j))+1:]
        for k in range(10):
          if str(k) in c:
            ans +=1
print(ans)

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

ans = 0
for i in range(1000):
    temp = '00' + str(i)
    temp = list(temp[-3:])

    check_num = temp.pop(0)
    cnt = 0
    for string in s:
        if check_num == string:
            cnt += 1
            if cnt == 3:
                ans += 1
                break
            check_num = temp.pop(0)
print(ans)

Solution (Python):
N = int(input())
S = input()
count = 0
D = 3


def find_number(digits, series):
    global count
    if digits > 1:
        for i in range(0, 10):
            if str(i) in series:
                idx = series.index(str(i))
                find_number(digits - 1, series[idx+1:])
    elif digits == 1:
        for j in range(0, 10):
            if str(j) in series:
                count += 1
    return count


print(find_number(D, S))

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

for i in range(0, 10):
    if str(i) in S:
        idx = S.index(str(i))
        for j in range(0, 10):
            if str(j) in S[idx+1:]:
                idx2 = S[idx+1:].index(str(j)) + idx + 1
                for k in range(0, 10):
                    if str(k) in S[idx2+1:]:
                        count += 1

print(count)

Solution (Python):
N = int(input())
S = input()
Ans = set([])

for i in range(10):
    if str(i) in S:
        a = S.index(str(i))
        S1 = S[a+1:]
        for j in range(10):
            if str(j) in S1:
                b = S1.index(str(j))
                S2 = S1[b+1:]
                for k in range(10):
                    if str(k) in S2:
                        Ans.add(str(100*i + 10*j + k))

print(len(Ans))

Solution (Python):
n = int(input())
s = input()
se = set()
for i in range(1000):
    se.add(str(i).zfill(3))

ans = 0
for i in se:
    t1=s.find(i[0])
    if t1!=-1:
        t2=s.find(i[1],t1+1,)
        if t2!=-1:
            t3=s.find(i[2],t2+1,)
            if t3!=-1:
                ans+=1
print(ans)

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

cnt=0
for i in range(1000):
  num=str(i).zfill(3)
  if num[0] in s:
    inx1=s.index(num[0])
    s2=s[inx1+1:]
    if num[1] in s2:
      inx2=s2.index(num[1])
      s3=s2[inx2+1:]
      if num[2] in s3:
        cnt+=1
print(cnt)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

    ans = 0
    for p in range(1000):
        p = str(p).zfill(3)

        i = 0
        for j in range(N):
            if S[j] == p[i]:
                i += 1

                if i == 3:
                    ans += 1
                    break

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
S = input()
cnt = 0
for i in range(1000):
    num = ''
    num += str(i // 100)
    num += str((i // 10) % 10)
    num += str(i % 10)
    j = 0
    for n in range(N):
        if S[n] == num[j]:
            j += 1
        if j == 3:
            break
    if j == 3:
        cnt += 1
print(cnt)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    S = readline().decode('utf-8').strip()
    ans = 0
    for i in range(10):
        x = S.find(str(i), 0, N-2)
        if x != -1:
            for j in range(10):
                y = S.find(str(j), x+1, N-1)
                if y != -1:
                    for k in range(10):
                        z = S.find(str(k), y+1, N)
                        if z != -1:
                            ans += 1
    print(ans)
if __name__ == '__main__':
    main()

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

passwords = [str(i).zfill(3) for i in range(1000)]
ans = 0

for pw in passwords:
    S_copy = S
    FLG = True
    for digit in pw:
        if digit not in S_copy:
            FLG = False
            break
        else:
            index = S_copy.find(digit)
            S_copy = S_copy[index+1:]
    if FLG:
        ans += 1

print(ans)

Solution (Python):
val1=input()
s=input()
n=int(val1)
count=0
for i in range(0,1000):
    a=str(i).zfill(3) 
    p=0
    for j in range(0,n):
        if a[p]==s[j]:
            p+=1
            if p==3:
                count+=1
                break
print(count)

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()


def resolve():
    n = int(input())
    s = input()
    cnt = 0
    for i in range(10):
        x = s.find(str(i))
        if x == -1:
            continue
        else:
            for j in range(10):
                y = s.find(str(j), x + 1)
                if y == -1:
                    continue
                else:
                    for k in range(10):
                        z = s.find(str(k), y + 1)
                        if z == -1:
                            continue
                        else:
                            cnt += 1

    print(cnt)


resolve()

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



psw=[]
ilist=[]
jlist=[]
klist=[]
for i in range(n-2):
    jlist=[]
    if s[i] in ilist:
        continue
    else:
        ilist.append(s[i])
        for j in range(i+1, n-1):
            klist=[]
            
            if s[j] in jlist:
                continue
            else:
                jlist.append(s[j])    
                for k in range(j+1, n):
                    if s[k] in klist:
                        continue
                    else:
                        
                        klist.append(s[k])
                        p=s[i]+s[j]+s[k]
                        psw.append(p)
print(len(psw))

Solution (Python):
N = int(input())
S = input()
cnt = 0
for i in range(1000):
    num = ''
    num += str(i // 100)
    num += str((i // 10) % 10)
    num += str(i % 10)
    j = 0
    for n in range(N):
        if S[n] == num[j]:
            j += 1
        if j == 3:
            break
    if j == 3:
        cnt += 1
print(cnt)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(1000):
    num=str(i).zfill(3)
    if s.find(num[0])==-1:
        continue
    s1=s[s.find(num[0])+1:]
    if s1.find(num[1])==-1:
        continue
    s2=s1[s1.find(num[1])+1:]
    if s2.find(num[2])==-1:
        continue
    ans+=1
print(ans)

Solution (Python):
N = int(input())
S = input()
cnt = 0
for i in range(1000):
    num = ''
    num += str(i // 100)
    num += str((i // 10) % 10)
    num += str(i % 10)
    j = 0
    for n in range(N):
        if S[n] == num[j]:
            j += 1
        if j == 3:
            break
    if j == 3:
        cnt += 1
print(cnt)

Solution (Python):
n=int(input())
s=[str(x) for x in input()]
exi=[]
for i in range(n):
    if s[i] not in exi:
        exi.append(s[i])
    if len(exi)==10:
        break
ans=0
for i in exi:
    star=s.index(i)
    lex=[]
    for j in range(star+1,n):
        if s[j] not in lex:
            lex.append(s[j])
        if len(lex)==10:
            break
    for k in lex:
        start=s[star+1:n].index(k)+star+1
        ele=[]
        for l in range(start+1,n):
            if s[l] not in ele:
                ele.append(s[l])
        ans += len(ele)

print(ans)

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

ans=0
for i in range(1000):
    si = str(i).zfill(3)
    now=0
    for ss in s:
        if si[now]==ss:
            now+=1
            if now==3:
                ans+=1
                break
print(ans)

Solution (Python):
N = int(input())
S = input()
nums = '1234567890'
lst=[]
res = 0
for i,si in enumerate(S):
  if si in lst: continue
  lst.append(si)
  lst2=[]
  for j,sj in enumerate(S[i+1:N]):
    j+=i+1
    if sj in lst2: continue
    lst2.append(sj)
    res += sum(_ in S[j+1:N]\
 for _ in nums)
print(res)

Solution (Python):
n=int(input())
s=list(input())
cnt=0
for i in range (10):
  i=str(i)
  for j in range (10):
    j=str(j)
    for k in range (10):
      k=str(k)
      if s.count(i)!=0:
        a=s.index(i)
        x=s[(a+1):]
        if x.count(j)!=0:
          b=x.index(j)
          y=x[(b+1):]
          if y.count(k)!=0:
            cnt+=1
 
print(cnt)

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

pins = []
for i in range(1000):
    i = str(i)
    if len(i) == 1:
        pins.append(str('00')+i)
    elif len(i) == 2:
        pins.append(str('0')+i)
    else:
        pins.append(i)

ans = 0
for pin in pins:
    c = 0
    for i in s:
        if pin[c] == i:
            c += 1
        if c == 3:
            ans += 1
            break

print(ans)

Solution (Python):
n = int(input())
S = input()
cnt=0
for i in range(10):
    x=S.find(str(i),0,n-2)
    if x!=-1:
        for j in range(10):
            y=S.find(str(j),x+1,n-1)
            if y!=-1:
                for k in range(10):
                    z=S.find(str(k),y+1,n)
                    if z!=-1:
                        cnt+=1
print(cnt)

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

K = set()
K.add(S[0:3])
K2 = set()
K2.add(S[0]+S[1])
K2.add(S[0]+S[2])
K2.add(S[1]+S[2])


for i in range(3,N):   
    c = S[i]
    tmp = set()
    tmp2 = set()
    for k in K2:
        tmp.add(k+c)
        tmp2.add(k[0]+c)
        tmp2.add(k[1]+c)
    K = K.union(tmp)
    K2 = K2.union(tmp2)

print(len(K))

Solution (Python):
from itertools import product
N = int(input())
S = input()

st = [set() for _ in range(3)]

for s in S:
    for pre in st[1]:
        st[2].add(pre+s)
    for pre in st[0]:
        st[1].add(pre+s)
    st[0].add(s)
        
print (len(st[2]))

Solution (Python):
from itertools import product
N = int(input())
S = input()
S = [int(s) for s in S]
ans = 0
for q in product(range(10),repeat=3):
    i = 0
    for s in S:
        if s==q[i]:
            if i==2:
                ans += 1
                break
            else:
                i+=1
print (ans)

Solution (Python):
from itertools import product
N = int(input())
S = input()
S = [int(s) for s in S]
ans = 0
for q in product(range(10),repeat=3):
    qi = q[0] 
    i = 0
    for s in S:
        if s==qi:
            if i==2:
                ans += 1
                break
            else:
                i+=1
                qi = q[i] 
print (ans)

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

def f(n):
    n = str(n).zfill(3)
    
    found = False
    for i in range(len(S)):
        if S[i] == n[0]:
            found = True
            break
    if found == False:
        return 0
    
    found = False
    for j in range(i+1, len(S)):
        if S[j] == n[1]:
            found = True
            break
    if found == False:
        return 0

    found = False
    for k in range(j+1, len(S)):
        if S[k] == n[2]:
            found = True
            break
    if found:
        return 1
    return 0

ans = 0
for i in range(1000):
    ans += f(i)

print(ans)

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

s = input()

A = []
for i in range(10):
    A.append([])
for i in range(n):
    A[int(s[i])].append(i)

total = 0
for i in range(1000):
    a = "{0:03d}".format(i)
    B = []
    for j in a:
        B.append(int(j))
    c = -1
    check = 0
    for j in B:
        check = 0
        if len(A[j]) > 0:
            for k in A[j]:
                if k > c:
                    c = k
                    check = 1
                    break
        else:
            break
        if check == 0:
            break
    if check == 1:
        total += 1
print(total)

Solution (Python):
N = int(input())
S = input()
count = 0
for i in range(1000):
    pas = format(i).zfill(3)
    a = S[:-2].find(pas[0])
    if a >= 0:
        b = S[a+1:-1].find(pas[1])
        if b >= 0:
            if pas[2] in S[a+b+2:]:
                count += 1
print(count)

Solution (Python):
n=int(input())
s=list(input())
cnt=0
for i in range (10):
  i=str(i)
  for j in range (10):
    j=str(j)
    for k in range (10):
      k=str(k)
      if s.count(i)!=0:
        a=s.index(i)
        x=s[(a+1):]
        if x.count(j)!=0:
          b=x.index(j)
          y=x[(b+1):]
          if y.count(k)!=0:
            cnt+=1

print(cnt)

Solution (Python):
from collections import deque
def main():
    N = int(input())
    S = input()
    c = [0] * N
    a = [deque() for _ in range(10)]
    b = [deque() for _ in range(10)]
    for i in range(N):
        a[int(S[i])].append(i)
        b[int(S[i])].append(i)
    for i in range(N):
        x = b[int(S[i])].popleft()
        cc = 0
        for j in range(10):
            if b[j]: cc += 1
        c[i] = cc
    output = 0
    visited = [0] * 10
    for i in range(N):
        a[int(S[i])].popleft()
        if visited[int(S[i])]: continue
        visited[int(S[i])] = 1
        for j in range(10):
            if a[j]:
                x = a[j][0]
                output += c[x]
    print(output)
    return

if __name__ == '__main__':
    main()

Solution (Python):
from bisect import bisect_left
n = int(input())
s = input()
idxs = [[] for _ in range(10)]
for i, j in enumerate(s):
    idxs[int(j)].append(i)
ans = 0
for i in range(10):
    if len(idxs[i])==0:
        continue
    b = idxs[i][0]+1
    for j in range(10):
        if len(idxs[j])==0:
            continue
        m = bisect_left(idxs[j], b)
        if len(idxs[j])==m:
            continue
        m = idxs[j][m]+1
        for k in range(10):
            if bisect_left(idxs[k], m)<len(idxs[k]):
                ans += 1
print(ans)

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

for i in range(10):
  x=S.find(str(i),0)
  if x!=-1:
    for j in range(10):
      y=S.find(str(j),x+1)
      if y!=-1:
        for k in range(10):
          z=S.find(str(k),y+1)
          if z!=-1:
            ans+=1

print(ans)

Solution (Python):

def main():
    import sys
    N = int(sys.stdin.readline())
    S = sys.stdin.readline().rstrip()
    ans = 0
    for i in range(1000):
        num = str(i).zfill(3)
        L = []
        k = 0
        for j in range(N):
            
            if int(S[j])==int(num[k]):
                
                L.append(S[j])
                k+=1
            if len(L)==3:
                
                ans +=1
                break
                
    print(ans)
        
    
if __name__=='__main__':
    main()

Solution (Python):
import bisect

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

L=[[] for index1 in range(10)]
Set=set()
for index in range(N):
    L[int(S[index])].append(index)
    Set.add(int(S[index]))

ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if i in Set and j in Set and k in Set:
                wi=L[i][0]
                wj_index=bisect.bisect(L[j],wi)
                if wj_index==len(L[j]):
                    continue
                else:
                    wj=L[j][wj_index]
                    wk_index=bisect.bisect(L[k],wj)
                    if wk_index==len(L[k]):
                        continue
                    else:
                        ans+=1

print(ans)

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

left = [0] * 10
right = [0] * 10
zero = ord("0")

l_set = set([])
r_set = set([])
center = S[0]
for s in S[1:]:
    right[ord(s) - zero] += 1
    r_set.add(s)

res = set([])
for s in S[1:]:
    l_set.add(center)
    left[ord(center)-zero] += 1
    
    center = s
    right[ord(center)-zero] -= 1
    if right[ord(center)-zero] == 0:
        r_set.remove(center)
    
    for r in r_set:
        for l in l_set:
            res.add(r+center+l)
    
    
print(len(res))