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, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()
S = input()

s = set([""])
for n in S:
	s |= set(x+n for x in s if len(x) != 3)

print(len([x for x in s if len(x) == 3]))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()
S = input()

s = set([""])
for n in S[::-1]:
	s |= set(x+n for x in s if len(x) != 3)

print(len([x for x in s if len(x) == 3]))

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

import itertools

d = list()
for d1, d2, d3 in itertools.product(range(10), range(10), range(10)):
    d.append(str(d1) + str(d2) + str(d3))

ret = 0
for di in d:
    ls = list(s)
    try:
        idx1 = ls.index(di[0])
        idx2 = ls[idx1+1:].index(di[1])
        idx3 = ls[idx1+1:][idx2+1:].index(di[2])
        ret += 1
    except:
        continue

print(ret)

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()
ans=0
inS=set()
for s in S:
  inS.add(s)
inS=list(inS)

def searcher(num,S):
  for i in range(len(S)):
    if num==S[i]:
      return i
  return -1

for i in inS:
  x=searcher(i,S)
  for j in inS:
    y=searcher(j,S[x+1:])
    if y==-1: continue
    for k in inS:
      z=searcher(k,S[x+y+2:])
      if z==-1: continue
      
      ans+=1
print(ans)

Solution (Python):
import collections
import copy

N = int(input().split()[0])
S = input()

counter = collections.Counter(S)
total = 0
done_list = []

for i, ch in enumerate(S[::-1]):  
    if ch in done_list:
        counter[ch] = counter[ch] - 1
        if counter[ch] < 1:
            del counter[ch]
        continue
    sub_done_list = []
    counter[ch] = counter[ch] - 1
    if counter[ch] < 1:
        del counter[ch]
    sub_counter = copy.copy(counter)

    for ch_2 in S[N - (i + 1) - 1 :: -1]:  
        if ch_2 in sub_done_list:
            sub_counter[ch_2] = sub_counter[ch_2] - 1
            if sub_counter[ch_2] < 1:
                del sub_counter[ch_2]
            continue
        sub_done_list.append(ch_2)
        sub_counter[ch_2] = sub_counter[ch_2] - 1
        if sub_counter[ch_2] < 1:
            del sub_counter[ch_2]
        total += len(sub_counter.keys())

    done_list.append(ch)

ans = total

print(ans)

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

l = [set({})] * n
r = [set({})] * n
for i in range(1, n):
    l[i] = copy.copy(l[i-1])
    l[i].add(s[i-1])

for i in range(1, n):
    r[n-i-1] = copy.copy(r[n-i])
    r[n-i-1].add(s[n-i])

ok = set()

for i in range(1, n-1):
    for x in l[i]:
        for y in r[i]:
            ok.add(x + s[i] + y)

print(len(ok))

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()
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):
N = int(input())
S = input()

check = ["0","1","2","3","4","5","6","7","8","9"]

sum = 0
for a in check:
    for b in check:
        for c in check:
            A = S.find(a)
            B = S.find(b)
            C = S.find(c)
            if A == -1 or B == -1 or C== -1:
                continue
            else:
                B2 = S.find(b,A+1)
                if B2 == -1:
                    continue
                else:
                    C3 = S.find(c,B2+1)
                    if C3 != -1:
                        sum +=1

print(sum)

Solution (Python):
N = int(input())
S = input()
k = [0]*10
now = S[0]
ren = 1
ls1 = [S[0]]
ans = 0

for i in range(1,N):
    if S[i] == now:
        ren += 1
        if ren <= 3:
            ls1.append(S[i])
    else:
        now = S[i]
        ren = 1
        ls1.append(S[i])
pless = ''.join(ls1)

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

Solution (Python):

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
S = readline()
count = 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: count +=1
print(count)

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):
            if s.find(str(k), b + 1) != -1:
                ans += 1
print(ans)

Solution (Python):

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

ans = 0
for i in range(1000):
    t = list(str(i).zfill(3))
    ti = 0
    for j in range(n):
        if s[j] == t[ti]:
            ti += 1
            if ti == 3: break
    else:
        continue
    ans += 1

print(ans)

Solution (Python):
def main():
    N = int(input())
    S = list(map(int,list(input())))
    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                cnt = 0
                for n in range(N):
                    if cnt == 0 and S[n] == i:
                        cnt += 1
                    elif cnt == 1 and S[n] == j:
                        cnt += 1
                    elif cnt == 2 and S[n] == k:
                        cnt += 1
                    
                    if cnt == 3:
                        ans += 1
                        break
    print(ans)
    
if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(10**3):
    s = str(i).zfill(3)
    flag = 0
    for j in range(N):
        if s[flag]==S[j]:
            flag += 1
            if flag == 3:
                break
    if flag==3:
        ans += 1
print(ans)

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

pin = [[[False] * 11 for _ in range(11)] for _ in range(11)]

for i in range(0, N):
    c = int(S[i])
    for a in range(10):
        for b in range(10):
            if pin[a][b][-1]:
                pin[a][b][c] = True
        if pin[a][-1][-1]:
            pin[a][c][-1] = True
    pin[c][-1][-1] = True

ans = 0
for a in range(10):
    for b in range(10):
        for c in range(10):
            ans += int(pin[a][b][c])

print(ans)

Solution (Python):
import math  
import bisect  
import queue  


if __name__ == '__main__':
    
    N = int(input())
    S = [int(s) for s in input()]

    ans = 0
    for i in range(0, 10):
        for j in range(0, 10):
            for k in range(0, 10):
                find_i = False
                find_j = False
                find_k = False
                for s in S:
                    if not find_i:
                        if i == s:
                            find_i = True
                    elif not find_j:
                        if j == s:
                            find_j = True
                    elif not find_k:
                        if k == s:
                            find_k = True
                            ans += 1
                            break
    print(ans)

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
















N = int(input())
S = input()
c = 0
for i in range(1000):
    if 0 <= i and i <= 9:
        s0 = "0"
        s1 = "0"
        s2 = str(i)
    elif 10 <= i and i <= 99:
        s0 = "0"
        s = str(i)
        s1 = s[0]
        s2 = s[1]
    else:
        s = str(i)
        s0 = s[0]
        s1 = s[1]
        s2 = s[2]
    i0 = -1
    i1 = -1
    i2 = -1
    for k in range(N-2):
        if S[k] == s0:
            i0 = k
            break
    if i0 == -1:
        continue
    for j in range(i0+1,N-1):
        if S[j] == s1:
            i1 = j
            break
    if i1 == -1:
        continue
    for l in range(i1+1,N):
        if S[l] == s2:
            i2 = l
            break
    if i2 != -1:
        c +=1
print(c)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = input()
res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            x = [str(i),str(j),str(k)]
            ok = False
            ind = 0
            for _,t in enumerate(s):
                if x[ind] == t:
                    ind += 1
                    if ind == 3:
                        ok = True
                        break
            if ok: res += 1
print(res)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(0,10):
    a=s.find(str(i))    
    if a==-1:
        continue
    for j in range(0,10):
        b=s.find(str(j),a+1)
        if b==-1:
            continue
        for k in range(10):
            if s.find(str(k),b+1) != -1:
                ans+=1

print(ans)

Solution (Python):

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

    cnd = set()
    for i in range(10):
        idx_i = s.find(str(i))
        if idx_i == -1:
            continue
        for j in range(10):
            idx_j = s.find(str(j), idx_i+1)
            if idx_j == -1:
                continue
            for k in range(10):
                idx_k = s.find(str(k), idx_j+1)
                if idx_k == -1:
                    continue
                st = str(i)+str(j)+str(k)
                cnd.add(str(i)+str(j)+str(k))

    print(len(cnd))
main()

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

def search(s, c, left):
  for idx in range(left, len(s)):
    if s[idx] == c:
      return idx
  return -1

total = 0
for keta1 in range(10):
  first_keta1 = search(s, str(keta1), 0)
  if first_keta1 == -1 or first_keta1 >= n-2:
    continue
  for keta2 in range(10):
    first_keta2 = search(s, str(keta2), first_keta1 + 1)
    if first_keta2 == -1 or first_keta2 >= n-1:
      continue
    for keta3 in range(10):
      first_keta3 = search(s, str(keta3), first_keta2 + 1)
      if first_keta3 != -1:
        total += 1
print(total)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            p=0
            for f in range(n):
                if p == 0 and s[f] == str(i):
                    p = 1
                elif p == 1 and s[f] == str(j):
                    p = 2
                elif p == 2 and s[f] == str(k):
                    ans += 1
                    break
print(ans)

Solution (Python):
def I(): return int(input())
def S(): return input()
N = I()
S = S()
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()

ans=0

for i in range(10):
  if str(i) in S:
    a = S.find(str(i))
    for j in range(10):
      if str(j) in S[a+1:]:
      	b = S[a+1:].find(str(j))
      	for k in range(10):
          if str(k) in S[a+b+2:]:
            ans+=1

print(ans)

Solution (Python):
N = input().split()
S = list(input())

Slist = list(S)



ans = 0
for i in range(0, 1000):
  a = i // 100
  b = (i % 100) // 10
  c = i % 10
  
  if(str(a) in Slist):
    nextList = Slist[Slist.index(str(a))+1:]
    if(str(b) in nextList):
      finalList = nextList[nextList.index(str(b))+1:]

      if(str(c) in finalList):
        ans += 1

print(ans)

Solution (Python):




import sys
inf = 10**9+7
mod = 10**9+7

n = int(input())
s = input()
judge = [[[True for k in range(10)]for j in range(10)]for i in range(10)]
judge_first = [True for i in range(10)]
judge_second = [[True for j in range(10)] for i in range(10)]
ans = 0
for i in range(n-2):
    fir = int(s[i])
    if judge_first[fir]:
        for j in range(i+1,n-1):
            sec = int(s[j])
            if judge_second[fir][sec]:
                for k in range(j+1,n):
                    thr = int(s[k])
                    if judge[fir][sec][thr]:
                        ans+=1
                        judge[fir][sec][thr] = False
                judge_second[fir][sec] = False
        judge_first[fir] = False
print(ans)

Solution (Python):
N = int(input())
S = input()
hitoketa = set()
futaketa = set()
ans = set()
for s in S:
    for n in futaketa:
        ans.add(n+s)
    for n in hitoketa:
        futaketa.add(n+s)
    hitoketa.add("1"+s)
print(len(ans))

Solution (Python):
def I(): return int(input())
def S(): return input()
N = I()
S = S()
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()

before = [[-1] * 10]

for i in range(n):
  c = s[i]
  num = int(c)
  hoge = before[-1][::]
  hoge[num] = i
  before.append(hoge)

ans = 0
for i in range(10):
  now = before[-1][i]
  if now == -1:
    continue
  for j in range(10):
    now2 = before[now][j]
    if now2 == -1:
      continue
    for k in range(10):
      now3 = before[now2][k]
      if now3 == -1:
        continue
      ans += 1
print(ans)

Solution (Python):
def I(): return int(input())
def S(): return input()
N = I()
S = S()
ans = 0
for i in range(1000):
    z = str(i).zfill(3)
    if S.find(z[0])==-1:
        continue
    S1 = S[S.find(z[0])+1:]
    if S1.find(z[1])==-1:
        continue
    S2 = S1[S1.find(z[1])+1:]
    if S2.find(z[2])==-1:
        continue
    ans += 1
print(ans)

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

before = [[-1] * 10]

for i in range(n):
  c = s[i]
  num = int(c)
  hoge = before[-1][::]
  hoge[num] = i
  before.append(hoge)
ans = 0
for i in range(10):
  now = before[-1][i]
  if now == -1:
    continue
  for j in range(10):
    now2 = before[now][j]
    if now2 == -1:
      continue
    for k in range(10):
      now3 = before[now2][k]
      if now3 == -1:
        continue
      ans += 1
print(ans)

Solution (Python):
def solve():
    N = int(input())
    S = input()
    count = 0
    for i in range(0,1000):
        num = str(i).zfill(3)
        digit = 0
        for j in range(N):
            if S[j] == num[digit]:
                digit += 1
            if digit == 3:
                break
        if digit ==3:
            count += 1

    print(count)

if __name__ == '__main__':
    solve()

Solution (Python):
def I(): return int(input())
def S(): return input()
N = I()
S = S()
s1,s2,s3 = set(),set(),set()
for x in S:
    for z in s2:
        s3.add(z+x)
    for y in s1:
        s2.add(y+x)
    s1.add(x)
print(len(s3))

Solution (Python):
N = int(input())
S = input()
numbers=[str(i).zfill(3) for i in range(1000)]
 
count=0
for num in numbers:
  j=0
  for i in range(N):
    if num[j]==S[i]:
      j+=1
      if j==3:
        count+=1
        break
print(count)

Solution (Python):


from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    n = ii()
    s = input()
    anslist = [0 for i in range(1005)]
    anslist1 = [0 for i in range(105)]
    anslist2 = [0 for i in range(15)]

    for _ in range(n):
        i = n-1-_
        tmp = int(s[i])

        for j in range(100):
            if anslist1[j]:
                anslist[tmp*100+j] = 1
        for j in range(10):
            if anslist2[j]:
                anslist1[tmp*10+j] = 1
        anslist2[tmp] = 1

    print(sum(anslist))



main()

Solution (Python):
num = int(input())
key = input()
count = 0
for i in range(10):
  if key.find(str(i)) == -1:
    continue;
  else:
    a = key.find(str(i))
    for j in range(10):
      if key.find(str(j), a+1) == -1:
        continue;
      else:
        b = key.find(str(j), a+1)
        for k in range(10):
          if key.find(str(k), b+1) == -1:
            continue;
          else:
            count += 1
    
print(count)

Solution (Python):
N = input()
S = input()
dic={i:str(i) for i in range(0,10)}
lenS=len(S)
cnt=0
for i in range(0, 1000):
    index=S.find(dic[i // 100])
    if index == -1:
        continue
    elif index + 2 <= lenS:
        index=S.find(dic[(i-(i//100)*100) // 10],index+1)
        if index == -1:
            continue
        elif index+1<=lenS:
            index=S.find(dic[i-(i//10)*10],index+1)
            if index != -1 and index < lenS:
                
                cnt+=1
print(cnt)

Solution (Python):
N = int(input())
S = [int(x) for x in list(input())]
total = 0
for a in range(1000):
  tmp = [a//100,a//10%10,a%10]
  i = 0
  for x in range(N):
    if tmp[i] == S[x]:
      i+=1
    if i==3:
      total+=1
      break
print(total)

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

bucket = [[] for _ in range(11)]
for i, num in enumerate(S):
    num = int(num)
    bucket[num].append(i)


def binsearch(threshold, lst):
    left, right = -1, len(lst)
    while right - left > 1:
        mid = (right + left) // 2
        if lst[mid] > threshold:
            right = mid
        else:
            left = mid
    return right

cnt = 0
for i in range(10):
    if bucket[i]:
        for j in range(10):
            if bucket[j]:
                for k in range(10):
                    if bucket[k]:
                        b_index = binsearch(bucket[i][0], bucket[j])
                        if b_index < len(bucket[j]):
                            c_index = binsearch(bucket[j][b_index], bucket[k])
                            if c_index < len(bucket[k]):
                                
                                cnt += 1
print(cnt)

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):
            if S.find(str(k), b + 1) != -1:
                ans += 1

print(ans)

Solution (Python):
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip() 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

def sumitrust2019_d(a,b,c,s):
    abc = list(map(str,[a,b,c]))
    now = 0
    for i in range(len(s)):
        if s[i] == abc[now]:
            now += 1
            if now == 3:
            	return True
    return False

def main():
    n = ni()
    s = ns()
    ans = 0
    for a in range(10):
        for b in range(10):
            for c in range(10):
                if sumitrust2019_d(a,b,c,s):
                    ans += 1
    print(ans)
    return

if __name__ == '__main__':
    main()

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


dp1 = [False]*10
dp2 = [[False]*10 for _ in range(10)]
dp3 = [[[False]*10 for _ in range(10)] for _ in range(10)]


for i in range(N):
    num = int(S[i])
    for j in range(10):
        for k in range(10):
            if dp1[j] == True and dp2[j][k] == True and dp3[j][k][num] == False:
                dp3[j][k][num] = True
        if dp1[j] == True and dp2[j][num] == False:
            dp2[j][num] = True
    if dp1[num] == False:
        dp1[num] = True

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            res += dp3[i][j][k] 
print(res)

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

cnt=0
for i in range(1000):
    num=str(i).zfill(3)
    x=s.find(num[0])
    y=s.find(num[1],x+1)
    z=s.find(num[2],y+1)
    if x!=-1 and y!=-1 and z!=-1:
        cnt +=1

print(cnt)

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

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

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

X = []
for i in range(10):
    X.append(str(i))

ans = 0
for i in X:
    if i in S:
        T = S[S.index(i) + 1:]
        for j in X:
            if j in T:
                U = T[T.index(j) + 1:]
                for k in X:
                    if k in U:
                        ans += 1

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)
        if b == -1: continue
        for k in range(10):
            if s.find(str(k), b + 1) != -1:
                ans += 1
print(ans)

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









def get_idx(array, val, tmp):
    for i in range(tmp + 1, len(array)):
        if val == array[i]:
            return i
    return -1

V = []
for i in range(1000):
    if i < 10: V.append("00" + str(i))
    elif i < 100: V.append("0" + str(i))
    else: V.append(str(i))

for v in V:
    tmp = -1
    flag = True
    for i in range(3):
        if v[i] in S:
            idx = get_idx(S, v[i], tmp)
            if idx != -1:
                tmp = idx
            else:
                flag = False
                break
        else:
            flag = False
            break
    if flag:
        count += 1

print(count)

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

X = []
for i in range(10):
    X.append(str(i))

ans = 0
for i in X:
    if i in S:
        T = S[S.index(i) + 1:]
        for j in X:
            if j in T:
                U = T[T.index(j) + 1:]
                for k in X:
                    if k in U:
                        ans += 1

print(ans)

Solution (Python):
import sys


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


sys.setrecursionlimit(10 ** 9)


def main():
    N = int(input())
    S = list(input())
    left_index = [[-1] * (N + 1) for _ in range(10)]
    for i, x in enumerate(S, 1):
        for j in range(10):
            left_index[j][i] = left_index[j][i - 1]
        left_index[ord(x) - ord("0")][i] = i
    answer = 0
    for i in range(1000):
        a = i // 100
        b = (i % 100) // 10
        c = i % 10
        j = N
        bl = True
        for x in [c, b, a]:
            j = left_index[x][j] - 1
            if j < -1:
                bl = False
                break
        if bl:
            answer += 1
    print(answer)


if __name__ == "__main__":
    main()

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

def solve():
    t1, t2, t3 = set(), set(), set()
    for i in range(N):
        z = S[i]
        for x, y in t2:
            t3.add((x, y, z))
        for x in t1:
            t2.add((x, z))
        t1.add(z)
    return len(t3)

if __name__ == "__main__":
    print(solve())

Solution (Python):
N = int(input())
S = input()
t = ["{:03d}".format(i) for i in range(0, 1000)]

c = 0
for i in t:
    a = 0
    b = 0
    if S.count(i[0]):
        a = S.index(i[0])
        if S[a + 1:].count(i[1]):
            b = S[a + 1:].index(i[1]) + a + 1
            if S[b + 1:].count(i[2]):
                c += 1

print(c)

Solution (Python):

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

Solution (Python):
n=int(input())
s=input()
l=set()
r=set()

for i in range(0,n-2):
    a=set()
    if s[i] in r:
        continue
    else:
        r.add(s[i])
    for j in range(i+1,n-1):
        b=set()
        if s[j] in a:
            continue
        else:
            a.add(s[j])
        for k in range(j+1,n):
            if s[k] in b:
                continue
            else:
                b.add(s[k])
            m=s[i]+s[j]+s[k]
            l.add(m)
print(len(l))

Solution (Python):
n=int(input())
s=input()
l=set()
r=set()

for i in range(0,n-2):
    a=set()
    if s[i] in r:
        continue
    else:
        r.add(s[i])
    for j in range(i+1,n-1):
        b=set()
        if s[j] in a:
            continue
        else:
            a.add(s[j])
        for k in range(j+1,n):
            if s[k] in b:
                continue
            else:
                b.add(s[k])
            m=s[i]+s[j]+s[k]
            l.add(m)
print(len(l))

Solution (Python):
n=int(input())
s=input()
l=set()
r=set()

for i in range(0,n-2):
    a=set()
    if s[i] in r:
        continue
    else:
        r.add(s[i])
    for j in range(i+1,n-1):
        if s[j] in a:
            continue
        else:
            a.add(s[j])
        for k in range(j+1,n):
            if j==1 and k>=3 and s[k]==s[2]:
                continue
            m=s[i]+s[j]+s[k]
            l.add(m)
print(len(l))

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

ans = 0

k1s = set()
for i in range(n-2):
    if s[i] in k1s: continue
    k1s.add(s[i])
    k2s = set()
    for i2 in range(i+1, n-1):
        if s[i2] in k2s: continue
        k2s.add(s[i2])
        k3s = set()
        for i3 in range(i2+1, n):
            if s[i3] in k3s: continue
            k3s.add(s[i3])
            ans += 1

print(ans)

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

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

Solution (Python):
n = int(input())
s = input()
a = set()
aa = set()
aaa = set()
for i in range(n):
    x = s[i]
    for yy in aa:
        aaa.add(yy+x)
    for y in a:
        aa.add(y+x)
    a.add(x)
print(len(aaa))

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1000):
    index = 0
    i = str(i)
    if len(i) < 2:
        i = "00"+i
    elif len(i) < 3:
        i = "0"+i
    for j in s:
        if i[index] == j:
            index += 1
        if index == 3:
            ans += 1
            break
print(ans)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1000):
    count = 0
    index = 0
    i = str(i)
    if len(i) < 2:
        i = "00"+i
    elif len(i) < 3:
        i = "0"+i
    for j in i:
        for k in range(index, n):
            if j == s[k]:
                index = k+1
                count += 1
                break
    if count == 3:
        ans += 1
print(ans)

Solution (Python):
N = int(input())
S = input()
f = [-1]*10
l = [-1]*10
c = 0

for i in range(N):
  if f[int(S[i])] == -1:
    f[int(S[i])] = i
  l[int(S[i])] = i

for i in range(10):
  p = f[i]
  if p == -1:
    continue
  for j in range(10):
    q = l[j]
    if q == -1:
      continue
    for k in range(10):
      for h in range(p+1,q):
        if int(S[h]) == k:
          c += 1
          break
      
print(c)

Solution (Python):
def main():
    n = int(input())
    s = list(map(int, list(input())))
    ans = 0
    for i in range(1000):
        c = 0
        for j in s:
            if i % 10 == j:
                if c == 2:
                    ans += 1
                    break
                c += 1
                i //= 10
    print(ans)

main()

Solution (Python):
def main():
    n = int(input())
    s = list(map(int, list(input())))
    ans = 0
    for i in range(1000):
        c = 0
        for j in s:
            if i % 10 == j:
                if c == 2:
                    ans += 1
                    break
                c += 1
                i //= 10
    print(ans)

main()

Solution (Python):
def main():
    n = int(input())
    s = list(map(int, list(input())))
    idx = [[] for _ in range(10)]
    for i, v in enumerate(s):
        idx[v].append(i)
    ans = 0
    for i in range(1000):
        c = 0
        p = -1
        chk = True
        while c < 3 and chk:
            chk = False
            for j in idx[i // 100]:
                if j > p:
                    c += 1
                    p = j
                    chk = True
                    i = i % 100 * 10
                    break
        if c == 3:
            ans += 1
    print(ans)

main()