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()
ans = 0

for pin in range(0,1000):
  counter = 0
  for index in range(0, N):
    if str(pin).zfill(3)[counter] == S[index]:
      counter += 1
    if counter == 3:
      ans += 1
      break
    
print(ans)

Solution (Python):
n = int(input())
s = input()
num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
m = n - 3
l = []

for i in num:
    for j in num:
        for k in num:
            if i in s:
                a = s.index(i)
                if j in s[a+1:]:
                    b = s[a+1:].index(j)
                    if k in s[a+1:][b+1:]:
                        l.append(i+j+k)

print(len(set(l)))

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

ans = 0
for i in range(1000):
    code = str(i).zfill(3)
    j = 0
    for s in S:
        if s == code[j]:
            j += 1
            if j == 3:
                ans += 1
                break
print(ans)

Solution (Python):
n = int(input())
s = input()
pins = ['0' * (3-len(str(i))) + str(i) for i in range(1000)]
ans = 0
for p in pins:
    a, b, c, = p
    if a not in s:
        continue
    p1 = s.index(a)
    if b not in s[p1+1:]:
        continue
    p2 = s[p1+1:].index(b) + len(s[:p1+1])
    if c not in s[p2+1:]:
        continue
    ans += 1
print(ans)

Solution (Python):
N = int(input())
S = input()
count = 0
for i in range(0,1000):
  if i >= 100:
    t = str(i)
  elif i >= 10:
    t = "0"+str(i)
  else:
    t = "00"+str(i)
  ti = 0
  for j in range(N):
    if S[j] == t[ti]:
      ti += 1
      if ti == 3:
        count += 1
        break
print(count)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



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


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


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


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


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


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


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




N = I()
A = S()

dic = DD(list)
for i in range(N):
  a = int(A[i])
  dic[a].append(i)
  
ans = 0
for i in range(10):
  if dic[i]:
    x = dic[i][0]
    for j in range(10):
      if dic[j]:
        p = bisect.bisect(dic[j],x)
        if p < len(dic[j]):
          y = dic[j][p]
          for k in range(10):
            p = bisect.bisect(dic[k],y)
            if p < len(dic[k]):
              ans += 1
print(ans)

Solution (Python):
import bisect
from collections import defaultdict
n = int(input())
s = input()

cnt = defaultdict(list)
for i, c in enumerate(s):
    cnt[c].append(i)


def is_Lucky(x):
    x = '{:03d}'.format(x)
    if not cnt[x[0]]:
        return False
    idx = cnt[x[0]][0]
    for c in x[1:]:
        i = bisect.bisect_right(cnt[c], idx)
        if len(cnt[c]) == i:
            return False
        idx = cnt[c][i]
    else:
        return True


ans = 0
for i in range(1000):
    if is_Lucky(i):
        ans += 1
print(ans)

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


def is_Lucky(x):
    x = tuple(map(int, '{:03d}'.format(x)))
    idx = 0
    for c in s:
        if x[idx] == c:
            idx += 1
            if idx == 3:
                return True
    else:
        return False


ans = 0
for i in range(1000):
    if is_Lucky(i):
        ans += 1
print(ans)

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


def is_Lucky(x):
    x = tuple(map(int, '{:03d}'.format(x)))
    idx = 0
    for c in s:
        if x[idx] == c:
            idx += 1
            if idx == 3:
                return True
    else:
        return False


ans = 0
for i in range(1000):
    if is_Lucky(i):
        ans += 1
print(ans)

Solution (Python):
def resolve():
    n=int(input())
    s=list(input())
    chk1=[0]*10
    chk2=[0]*100
    l=[]
    ans=0
    for i in range(n-2):
        if chk1[int(s[i])]==0:
            chk1[int(s[i])]=1
            for j in range(i+1,n-1):
                x=s[i]+s[j]
                if chk2[int(x)]==0:
                    chk2[int(x)]=1
                    if x in l:
                        continue
                    else:
                        l.append(x)
                        ans+=len(set(s[j+1:]))
    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
n=int(input())
s=input()
cnt = 0
for i in range(10):
  if str(i) not in s[:-2]: continue
  i1 = s[:-2].index(str(i))
  for j in range(10):
    if str(j) not in s[i1+1:-1]: continue
    j1 = s[i1+1:-1].index(str(j))
    for k in range(10):
      if str(k) not in s[i1+1+j1+1:]: continue
      k1 = s[i1+1+j1+1:].index(str(k))
      
      cnt += 1
print(cnt)

Solution (Python):
import sys
import itertools

import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

ans = 0
for i in range(1000):
    secret = ('0' * 2 + str(i))[-3:]
    j = 0
    for c in S:
        if c == secret[j]:
            j += 1
        if j >= 3:
            ans += 1
            break
print(ans)

Solution (Python):
def main():
    _ = int(input())
    s = input()

    ans = 0

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


if __name__ == "__main__":
    main()

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

    ans = 0

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


if __name__ == "__main__":
    main()

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

    ans = 0

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


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
s = input()
p = 0
for i in range(10):
    pi = s.find(str(i))
    if pi == -1:
        continue
    for j in range(10):
        pj = s.find(str(j), pi + 1)
        if pj == -1:
            continue
        for k in range(10):
            pk = s.find(str(k), pj + 1)
            if pk == -1:
                continue
            p = p + 1
print(p)

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

    ans = 0

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


if __name__ == "__main__":
    main()

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

ans = 0

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

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

ans = []

for i in range(10):
    if i in s:
        a = s.index(i)
        for j in range(10):
            if j in s[a + 1 :]:
                b = a + s[a + 1 :].index(j) + 1
                for k in range(10):
                    if k in s[b + 1 :]:
                        ans.append(f"{i}{j}{k}")
print(len(ans))

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

ans = []

for i in range(10):
    if i in s:
        a = s.index(i)
        for j in range(10):
            if j in s[a + 1 :]:
                b = [x for x, y in enumerate(s) if x > a and y == j][0]
                for k in range(10):
                    if k in s[b + 1 :]:
                        ans.append(f"{i}{j}{k}")
print(len(ans))

Solution (Python):
n=int(input())
s=input()
sm=0
for x in [(x,y,z) for x in range(10) for y in range(10) for z in range(10)]:
    token=0
    for i in range(n):
        if x[token]==int(s[i]):
            token+=1
            if token==3 : break
    if token==3 : sm+=1
print(sm)

Solution (Python):


n = int(input())
s = list(input())
st = [set() for i in range(3)]
for a in s:
    for pre in st[1]:
        st[2].add(pre + a)
    for pre in st[0]:
        st[1].add(pre + a)
    st[0].add(a)

print(len(st[2]))

Solution (Python):
import sys
from collections import deque
from itertools import *


def I(): return int(sys.stdin.readline().rstrip())


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


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


n = I()
s = S()

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)

Solution (Python):
n=int(input())
s=str(input())
ans=0
for _ in range(1000):
  t=str(_).zfill(3)
  
  if s.find(t[0])==-1:
    continue
  check=s[s.find(t[0])+1:]
  if check.find(t[1])==-1:
    continue
  fin=check[check.find(t[1])+1:]
  if fin.find(t[2])==-1:
    continue
  ans+=1
print(ans)

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

    c = 0
    l1 = set()
    for i in range(n)[:-2]:
        if s[i] in l1:
            continue
        l1.add(s[i])
        l2 = set()
        for j in range(n)[i + 1:-1]:
            if s[j] in l2:
                continue
            l2.add(s[j])
            c += len(set(list(s[j + 1:])))

    print(c)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s = input()
a = set()
a1 = []
for i in range(n-2):
  if s[i] in a1:
    continue
  a1.append(s[i])
  a2 = []
  for j in range(i+1,n-1):
    if s[j] in a2:
      continue
    a2.append(s[j])
    a = a|set([s[i]+s[j]+k for k in set(list(s[j+1:]))])
print(len(a))

Solution (Python):



import itertools
import copy
from collections import deque

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

ans = 0
iter = itertools.product("0123456789", repeat=3)

for it in iter:
    _s = copy.deepcopy(s)
    for i in it:
        try:
            _idx = _s.index(i)
            _s = _s[_idx+1:]
        except:
            break
    else:
        ans += 1
    
print(ans)

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


for i in range(10):
    
    str_i = str(i)
    for a in range(n-2):
        if s[a] == str_i:
            now_i = a
            break
    
    else:
        continue
    
    for j in range(10):
        str_j = str(j)
        for b in range(now_i+1,n-1):
            if s[b] == str_j:
                now_j = b
                break
        else:
            continue
        
        for k in range(10):
            str_k = str(k)
            for c in range(now_j+1,n):
                
                if s[c] == str_k:
                    point += 1
                    break

print(point)

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


for i in range(10):
    
    now_i = -1
    str_i = str(i)
    for a in range(n-2):
        if s[a] == str_i:
            now_i = a
            break
    
    if now_i == -1:
        continue
    
    for j in range(10):
        now_j = -1
        str_j = str(j)
        for b in range(now_i+1,n-1):
            if s[b] == str_j:
                now_j = b
                break
        if now_j == -1:
            continue
        
        for k in range(10):
            str_k = str(k)
            for c in range(now_j+1,n):
                
                if s[c] == str_k:
                    point += 1
                    break

print(point)

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


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

print(point)

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

ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    k = 0
    t = key[k]
    for s in s_list:
        if t == s:
            k += 1
            if k == 3:
                ans += 1
                break
            t = key[k]
print(ans)

Solution (Python):
N = int(input())
S = input()
divide = 0
count = 0
for i in range(1000):
    num = str(i)
    while(len(num)<3):
        num = "0"+num
    flag = [0,0,0]
    for j in range(3):
        for k in range(divide,N):
            if num[j] == S[k]:
                flag[j] = 1
                divide = k+1
                break
    divide = 0      
    if(flag == [1,1,1]):
        count +=1
print(count)

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


for i in range(10):
    first = 0
    while S[first] != str(i) and first < N-1:
        first += 1
    if first > N-3:
        continue
    for j in range(10):
        second = first+1
        while S[second] != str(j) and second < N-1:
            second += 1
        if second > N-2:
            continue
        
        ans += len(set(S[second+1:]))
print(ans)

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


for i in range(10):
    first = 0
    while S[first] != str(i) and first < N-1:
        first += 1
    if first > N-3:
        continue
    for j in range(10):
        second = first+1
        while S[second] != str(j) and second < N-1:
            second += 1
        if second > N-2:
            continue
        
        ans += len(set(S[second+1:]))
print(ans)

Solution (Python):
N=int(input())
S=input()
re_list=[]
ele = list(map(str, S))
v_list=[]
vi_list=[]
flag = 0
count = 0
for i in range(1000):
    if i < 10:
        v_list.append("00"+str(i))
    elif i < 100:
        v_list.append("0" + str(i))
    else:
        v_list.append(str(i))

for i in range(1000):
    for j in range(N):
        if ele[j] == v_list[i][0] and flag == 0:
            flag = 1
            continue
        if ele[j] == v_list[i][1] and flag == 1:
            flag = 2
            continue
        if ele[j] == v_list[i][2] and flag == 2:
            count += 1
            break
    flag = 0
print(count)

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

ans = 0
for p in range(1000):
  s = '{:03}'.format(p)
  i = 0
  for j in range(N):
    if i < 3 and S[j] == s[i]:
      i += 1
  if i == 3:
    ans += 1
print(ans)

Solution (Python):
import string
N = int(input())
S = input()
L = []
for i in string.digits:
    for j in string.digits:
        for k in string.digits:
            L.append((i,j,k))
count = 0
for l in L:
    if l[0] not in S:
        continue
    S2 = S[S.index(l[0])+1:]
    if l[1] not in S2:
        continue
    S3 = S2[S2.index(l[1])+1:]
    if l[2] not in S3:
        continue
    count += 1
print(count)

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):
n=int(input())
k=list(input())

kk=0
for i in range(1000):
  if i<10:
    p=['0','0',str(i)]
  elif i<100:
    p=['0',str(i)[0],str(i)[1]]
  else:
    p=list(str(i))
    
  flag=0
  for w in k:
    if w==p[flag]:
      flag+=1
    if flag==3:
      break
  
  if flag==3:
    
    kk+=1
  else:pass

print(kk)

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

cnt = 0
for x in range(10):
    x_ = str(x)
    for i in range(n-2):
        if s[i] == x_:
            break
    else:
        continue
    for y in range(10):
        y_ = str(y)
        for j in range(i+1, n-1):
            if s[j] == y_:
                break
        else:
            continue
        for z in range(10):
            z_ = str(z)
            for k in range(j+1, n):
                if s[k] == z_:
                    cnt += 1
                    break

print(cnt)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    idx = 0
    target = key[idx]
    for ii in s:
        if target == ii:
            idx += 1
            if idx > 2:
                ans += 1
                break
            target = key[idx]
print(ans)

Solution (Python):
N = int(input())
S = input()
ans = 0
d = [set() for _ in range(3)]
for i in range(N - 2):
    if S[i] in d[0]:
        continue
    d[0].add(S[i])
    for j in range(i + 1, N - 1):
        if S[i] + S[j] in d[1]:
            continue
        d[1].add(S[i] + S[j])
        for k in range(j + 1, N):
            if S[i] + S[j] + S[k] in d[2]:
                continue
            d[2].add(S[i] + S[j] + S[k])
print(len(d[2]))

Solution (Python):
N = int(input())
S = input()
ans = 0
d = [set() for _ in range(3)]
for i in range(N - 2):
    if S[i] in d[0]:
        continue
    d[0].add(S[i])
    for j in range(i + 1, N - 1):
        if S[i] + S[j] in d[1]:
            continue
        d[1].add(S[i] + S[j])
        for k in range(j + 1, N):
            if S[i] + S[j] + S[k] in d[2]:
                continue
            d[2].add(S[i] + S[j] + S[k])
            ans += 1
print(ans)

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

num1, num2, num3 = set([]), set([]), set([])



for i in range(n):
    if s[i] in num1:
        continue
    num1.add(s[i])
    for j in range(i+1, n):
        word2 = s[i] + s[j]
        if word2 in num2:
            continue
        num2.add(word2)
        for k in range(j+1, n):
            word3 = word2 + s[k]
            if word3 in num3:
                continue
            num3.add(word3)

print(len(num3))

Solution (Python):
from itertools import combinations

def readinput():
    n=int(input())
    s=input()

    return n,s

def main(n,s):
    count=0
    s1=s[:]
    for i in range(10):
        index1=s1.find(str(i))
        if index1 == -1:
            continue
        s2=s1[index1+1:]
        if(len(s2)<2):
            continue
        
        for j in range(10):
            index2=s2.find(str(j))
            if index2 == -1:
                continue
            s3=s2[index2+1:]
            if(len(s3)<1):
                continue
            
            for k in range(10):
                
                index3=s3.find(str(k))
                if index3 == -1:
                    continue
                count+=1
                
    return count

if __name__=='__main__':
    n,s=readinput()
    ans=main(n,s)
    print(ans)

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

ans = 0

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

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(0,1000):
    pin = str(i).zfill(3)
    
    first = False
    second = False
    for s in S:
        if (not first) and s == pin[0]:
            first = True
        elif first and (not second) and s == pin[1]:
            second = True
        elif second and s == pin[2]:
            ans += 1
            break
print(ans)

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

num1, num2, num3 = set([]), set([]), set([])
for i in range(n):
    if s[i] in num1:
        continue
    num1.add(s[i])
    for j in range(i + 1, n):
        tmp2 = s[i] + s[j]
        if tmp2 in num2:
            continue
        num2.add(tmp2)
        for k in range(j + 1, n):
            num3.add(tmp2 + s[k])
print(len(num3))

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

num1, num2, num3 = set([]), set([]), set([])
for i in range(n):
    if s[i] in num1:
        continue
    num1.add(s[i])
    for j in range(i + 1, n):
        tmp2 = s[i] + s[j]
        if tmp2 in num2:
            continue
        num2.add(tmp2)
        for k in range(j + 1, n):
            tmp3 = tmp2 + s[k]
            if tmp3 in num3:
                continue
            num3.add(tmp3)
print(len(num3))

Solution (Python):
n = int(input())
s = input()
c = 0
for i in range(1000):
  num = str(i).zfill(3)
  if num[0] in s:
    k = s[(s.find(num[0])+1):]
    if num[1] in k:
      d = k[(k.find(num[1])+1):]
      if num[2] in d:
        c += 1
print(c)

Solution (Python):
n = int(input())
s = input()
number = [n for n in range(10)]
ans = 0
for i in number:
    try:
        j = s.index(str(i))
        for k in number:
            try:
                l = s[j+1:].index(str(k))
                ans += len(set(s[l+j+2:]))
            except:
                continue
    except:
        continue
print(ans)

Solution (Python):
n = int(input())
s = input()
number = [n for n in range(10)]
ans = 0
for i in number:
    try:
        j = s.index(str(i))
        for k in number:
            try:
                l = s[j+1:].index(str(k))
                exist = [0]*10
                for m in s[l+j+2:]:
                    exist[int(m)] = 1
                
                ans += sum(exist)
            except:
                continue
    except:
        continue
print(ans)

Solution (Python):
n = int(input())
s = input()
number = [n for n in range(10)]
ans = set([])
for i in number:
    try:
        j = s.index(str(i))
        for k in number:
            try:
                l = s[j+1:].index(str(k))
                for m in s[l+j+2:]:
                    ans.add(str(i)+str(k)+m)
            except:
                continue
    except:
        continue
print(len(ans))

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

ans = set()
for x in range(10):
    if str(x) in S:
        idx = S.index(str(x))
        for y in range(10):
            if str(y) in S[idx+1:]:
                idx2 = S[idx+1:].index(str(y)) + idx + 1
                for z in range(10):
                    if str(z) in S[idx2+1:]:
                        idx3 = S[idx2 + 1:].index(str(z)) + idx2 + 1
                        ans.add((x,y,z))
print(len(ans))

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

cnt = 0
for i in range(10):
    p1 = s.find(str(i))
    if p1 == -1:
        continue
    
    for j in range(10):
        p2 = s.find(str(j),p1+1)
        if p2 == -1:
            continue

        for k in range(10):
            p3 = s.find(str(k),p2+1)
            if p3 != -1:
                cnt += 1

print(cnt)

Solution (Python):
import collections

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

already = []
ans = 0

for i in range(N-2):
    tmp = []
    point = 1
    if S[i] not in already:
        already.append(S[i])
        while True:
            
            
            
            
            if S[i+point] not in tmp:
                
                ans += len(set(S[i+point+1:]))
                
                
                
                tmp.append(S[i+point])
            point += 1
            if i + point == N-1:
                break

print(ans)

Solution (Python):
import bisect

N = int(input())
S = input().strip()

A = [[] for j in range(10)]


for i, s in enumerate(S):
    A[int(s)].append(i)

v = set()


ans = 0
for i in range(10):
    if A[i]:
        for j in range(10):
            if A[j]:
                x = bisect.bisect_right(A[j], A[i][0])
                if x != len(A[j]):
                    for k in range(10):
                        if A[k]:
                            y = bisect.bisect_right(A[k], A[j][x])
                            if y != len(A[k]):
                                ans += 1

print(ans)

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

lcs = [0]
rcs = [0]
for c in S:
    c = int(c)
    lcs.append(lcs[-1] | (1<<c))
for c in S[::-1]:
    c = int(c)
    rcs.append(rcs[-1] | (1<<c))
rcs.reverse()

ss = set()
for i,c in enumerate(S):
    c = int(c)
    ls = []
    for l in range(10):
        if lcs[i]&(1<<l):
            ls.append(l)
    rs = []
    for r in range(10):
        if rcs[i+1]&(1<<r):
            rs.append(r)
    for l in ls:
        for r in rs:
            ss.add(l*100 + c*10 + r)
print(len(ss))

Solution (Python):
n = int(input())
s = input()
l = [[False]*10 for i in range(n)]
r = [[False] * 10 for i in range(n)]
total = set()
for i in range(1, n):
    l[i] = l[i - 1][:]
    l[i][int(s[i-1])] = True
for i in range(n-2, -1, -1):
    r[i] = r[i + 1][:]
    r[i][int(s[i+1])] = True
for i in range(1, n - 1):
    for j in range(10):
        if not l[i][j]:
            continue
        for k in range(10):
            if not r[i][k]:
                continue
            total.add((j, int(s[i]), k))
print(len(total))

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]

def check(num,s):
    curr = 0
    for k in range(len(s)):
        if num[curr] == s[k]:
            curr += 1
            if curr == 3:
                return True
    return False

def main():
    N = int(input())
    S = input()
    ans = 0
    for k in range(1000):
        t = str(k).zfill(3)
        if check(t,S) == True:
            ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s = input()
import itertools
state = itertools.product(list(range(10)),repeat = 3)

def lucky_pin(i):
    spot = -1
    for j in i:
        
        if str(j) in s[spot +1 : ]:
            spot = s[spot +1 : ].find(str(j)) +spot +1
            
        else:
            return 0
    return 1
      
counter = 0
for i in state:
    counter += lucky_pin(i)
        
print(counter)

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

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

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    s = input()
    ans = 0
    for i1 in range(10):
        for i2 in range(10):
            for i3 in range(10):
                ii1 = s.find(str(i1))
                if ii1 == -1:
                    continue
                ii2 = s[ii1+1::].find(str(i2))
                if ii2 == -1:
                    continue
                ii3 = s[ii1+1+ii2+1::].find(str(i3))
                if not ii3 == -1:
                    ans += 1
    print(ans)


    return

if __name__ == '__main__':
    main()

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    s = input()
    ans = 0
    for i1 in range(10):
        for i2 in range(10):
            for i3 in range(10):
                ii1 = s.find(str(i1))
                if ii1 == -1 or ii1 >= n-2:
                    continue
                ii2 = s[ii1+1::].find(str(i2))
                if ii2 == -1 or ii2 >= n-1:
                    continue
                ii3 = s[ii1+1+ii2+1::].find(str(i3))
                if not ii3 == -1:
                    ans += 1
    print(ans)


    return

if __name__ == '__main__':
    main()