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()
l=list("0123456789")

ret=[False]*1000
for i in (l):
    for j in (l):
        for k in (l):
            flg1=flg2=False
            for s in S:
                if s==i and not flg1:
                    flg1=True
                    continue
                if flg1 and s==j and not flg2:
                    flg2=True
                    continue
                if flg2 and s==k:
                    tmp=int(i+j+k)
                    
                    ret[tmp]=True
                    break
          
print(sum(ret))

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

ans=0
for num in range(10):
    found1=-1
    for i in range(len(s)):
        if s[i] == str(num):
            found1=i
            break
    if found1==-1:
        continue

    for num2 in range(10):
        found2=-1
        for j in range(found1+1,len(s)):
            if s[j]== str(num2):
                found2=j
                break
        if found2==-1:
            continue

        for num3 in range(10):
            found3=-1
            for k in range(found2+1,len(s)):
                if s[k]== str(num3):
                    found3=k
                    break
            if found3==-1:
                continue
            ans+=1
print(ans)

Solution (Python):
import bisect
n = int(input())
s = input()
D = [[] for _ in range(10)]
for i in range(n):
  D[int(s[i])].append(i)
ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      if D[i] != []:
        l = D[i][0]
        t = bisect.bisect_right(D[j], l)
        if t < len(D[j]):
          m = D[j][t]
          q = bisect.bisect_right(D[k], m)
          if q < len(D[k]):
            ans += 1
print(ans)

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

N = int(input())
S = input()
cc = [0]*1000
ans = [0]*1000
for j in range(len(S)-1):
	p = int(S[j])
	for i in range(1000):
		if(p==i%10 and cc[i]==2):
			cc[i]+=1
			ans[i]=1
		elif(p==(i//10)%10 and cc[i]==1):
			cc[i]+=1
		elif(p==i//100 and cc[i]==0):
			cc[i]+=1
print(sum(ans))

Solution (Python):
N = int(input())
S = input()
c = [str(i) for i in range(10)]
cands = []
for c1 in c:
    for c2 in c:
        for c3 in c:
            cands.append(c1 + c2 + c3)

cnt = 0
for c in cands:
    i = 0
    for s in S:
        if i == 3:
            break
            
        if c[i] == s:
            i += 1

    if i == 3:
        
        cnt += 1
print(cnt)

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

for i in range(10):
    x = S.find(str(i))
    if x == -1 or x >= N - 2:
        continue
    for j in range(10):
        y = S.find(str(j), x + 1)
        if y == -1 or y == N - 1:
            continue
        for k in range(10):
            z = S.find(str(k), y + 1)
            if z != -1:
                count += 1
                
print(count)

Solution (Python):
a = int(input())
b = input()
ans = 0
for i in range(1000):
	T = '0'*(3-len(str(i)))
	t = T+ str(i)
	I = 0
	while I < 3:
		for j in b:
			
			if I == 3:
				break
			if t[I] == j:I+=1
			
		
		if I == 3: 
			
			ans +=1
		break
print(ans)

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(10):
  l = 0
  while(True):
    if(i == int(S[l])):
      for j in range(10):
        m = l + 1
        while(True):
          if(j == int(S[m])):
            for k in range(10):
              for n in range(m+1, N):
                if(k == int(S[n])):
                  ans += 1
                  break
          m += 1
          if(m >= N - 1 or j == int(S[m - 1])):
             break
    l += 1
    if(l >= N - 2 or i == int(S[l - 1])):
      break
print(ans)

Solution (Python):
N = int(input()) 
S = input()[::-1]




ret = 0

place1 = [True for i in range(10)]
for i, s in enumerate(S):
  if i > N - 3:
    break
  if place1[int(s)]:
    place1[int(s)] = False
    
    
    place2 = [True for j in range(10)]
    for j, t in enumerate(S[i+1:], i+1):
      if j > N - 2:
        break
      if place2[int(t)]:
        place2[int(t)] = False
      
        
        ret += len(set(S[j+1:]))
        
print(ret)

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

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

for i in range(10):
    ind_i = S.find(str(i))
    if ind_i != -1:
        S2 = S[ind_i + 1:]
        for j in range(10):
            ind_j = S2.find(str(j))
            if ind_j != -1:
                S3 = S2[ind_j + 1:]
                for k in range(10):
                    cnt_k = S3.count(str(k))
                    if cnt_k > 0:
                        ans += 1


print(ans)

Solution (Python):
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline









N, = map(int, input().split())
S = input().strip()

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

Solution (Python):
from itertools import combinations
N = int(input())
s = input()
ans = 0
for a2 in range(10):
    for b2 in range(10):
        for c2 in range(10):
            a = str(a2)
            b = str(b2)
            c = str(c2)
            count = 0
            for i in s:
                if a == i:
                    count += 1
                    if count == 1:
                        a = b
                    if count == 2:
                        a = c
            if count >= 3:
                ans += 1
print(ans)

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

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

N = int(input())
S = input()
keta = 3
count = 0
for i in range(1000):
    s = str(i).zfill(keta)
    pos = -1
    for j in range(keta):
        tmp = S[pos+1:].find(s[j])
        if tmp == -1:
            break
        pos += tmp + 1
    else:
        count += 1
print(count)

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

cnt=0
for i in range(0,1000):
  pos=0
  t="{0:03d}".format(i)
  for j in range(int(n)):
    if s[j] == t[pos]:
      pos+=1
    if pos == 3:
      cnt+=1
      break

print(cnt)

Solution (Python):
N = int(input())
S = list(str(input()))
result = 0
for i in range(len(S)):
    S[i] = int(S[i])
    
for i in range(10):
    if S.count(i) >= 1:
        val = S.index(i)
        S_2 = S[val+1:]
        for j in range(10):
            if S_2.count(j) >= 1:
                val_2 = S_2.index(j)
                S_3 = S_2[val_2+1:]
                for k in range(10):
                    if S_3.count(k) >= 1:
                        result += 1

print(result)

Solution (Python):

import sys
INF = float("inf")


def z_algorithm(S):
    N = len(S)
    Z = [0]*N

    c = 0
    for i in range(1, N):
        if i+Z[i-c] < c+Z[c]:
            Z[i] = Z[i-c]
        else:
            j = max(0, c+Z[c]-i)
            while i+j < N and S[j] == S[i+j]:
                j += 1
            Z[i] = j
            c = i
    Z[0] = len(S)
    return Z


def zfindall(text, pattern, separator="$"):
    N = len(pattern)
    conc = pattern+separator+text
    Z = z_algorithm(conc)

    umu = [i-N-1 for i in range(len(conc)) if Z[i] == N]
    return umu


def solve(N: int, S: str):

    len1 = [0]*10
    len2 = [0]*100
    len3 = [0]*1000
    for c in S:
        
        for i in range(100):
            if len2[i] > 0:
                len3[int(str(i)+c)] = 1

        
        for i in range(10):
            if len1[i] > 0:
                len2[int(str(i)+c)] = 1

        
        len1[int(c)] = 1
    counter = 0
    for i in range(1000):
        if len3[i] == 1:
            counter += 1

    print(counter)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    S = next(tokens)  
    solve(N, S)


if __name__ == '__main__':
    main()

Solution (Python):
import math
n= int(input())
s = str(input())
num = len(s)
ans = 0
for i in range(1000):
    t = (3-len(str(i))) * "0" + str(i)
    key1,key2 = 0,0
    num= len(s)
    for j in range(num):
        if s[j] == t[2] and key2:
            ans += 1
            break
        if s[j] == t[1] and key1:
            key2 = 1
        if s[j] == t[0]:
            key1 = 1
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

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

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    N = I()
    s = S()
    t = [set() for _ in range(4)]
    t[0].add("")
    for c in s:
        for i in range(2,-1,-1):
            for k in t[i]:
                t[i+1].add(k+c)

    return len(t[3])


print(main())

Solution (Python):
N = int(input())
S = list(map(int,list(input().strip())))
cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            cur = [i,j,k]
            ind = 0
            for n in range(N):
                if S[n]==cur[ind]:
                    ind += 1
                    if ind==3:
                        cnt += 1
                        break
print(cnt)

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:
			break
	if j==3:
		count+=1
print(count)

Solution (Python):
def search(num, moji):
    num2str = str(num)
    for i, n in enumerate(moji):
        if n == num2str:
            return moji[i+1:], True
    return "", False


a = int(input())
b = input()
buf = b[:]
result = 0
for i in range(10):
    buf, flag = search(i, b[:])
    if flag:
        for j in range(10):
            buf2, flag2 = search(j, buf)
            if flag2:
                for k in range(10):
                    _, flag3 = search(k, buf2)
                    if flag3:
                        result += 1
print(result)

Solution (Python):
def Lucky_PIN():
	n=int(input())
	s=input()
	ans=0
	for i in range(1000):
		p='{:03d}'.format(i)
		n1=s.find(p[0])
		if n1!=-1:
			n2=s[n1+1:].find(p[1])
			if n2!=-1:
				n3=s[n1+n2+2:].find(p[2])
				if n3!=-1:
					ans+=1
	print(ans)
if __name__=='__main__':
	Lucky_PIN()

Solution (Python):
def solve():
    ans = 1
    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):

N = int(input())
S = input()
ans = 0

possible_pass = [str(i).zfill(3) for i in range(1000)]

for password in possible_pass:
    try:
        first_num = S.index(password[0])
        S_second = S[first_num+1:]
        second_num = S_second.index(password[1])
        S_third = S_second[second_num+1:]
        third_num = S_third.index(password[2])
        ans += 1
    except:
        continue
    
print(ans)

Solution (Python):
n = int(input())
s = input()
ans = 0
password = [0, 0, 0]
for i in range(1000):
    for j in range(3):
        password[2 - j] = i // (10 ** j) % 10
    if str(password[0]) in s:
        index = s.index(str(password[0]))
        if str(password[1]) in s[index + 1:]:
            index2 = index + 1 + s[index + 1:].index(str(password[1]))
            if str(password[2]) in s[index2 + 1:]:
                ans += 1
print(ans)

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

for i in range(1000):
    pin = ("00" + str(i))[-3:]

    j = 0
    for num in S:
        if pin[j] == num:
            j += 1
        if j == 3:
            count += 1
            break

print(count)

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

ans = 0

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

Solution (Python):
n=int(input())
S=input()
ans=0
A=["0","1","2","3","4","5","6","7","8","9"]
for i in range(n-2):
  if len(A)==0:
    break
  elif S[i] in A:
    A.remove(S[i])
  else:
    continue
  B=["0","1","2","3","4","5","6","7","8","9"]
  for j in range(i+1,n-1):
    if len(B)==0:
      break
    elif S[j] in B:
      B.remove(S[j])
    else:
      continue
    C=["0","1","2","3","4","5","6","7","8","9"]
    for k in range(j+1,n):
      if len(C)==0:
        break
      elif S[k] in C:
        C.remove(S[k])
        ans=ans+1
      else:
        continue
print(ans)

Solution (Python):
from collections import defaultdict
from bisect import *

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

for i in range(N):
    idx[int(S[i])].append(i)

ans = 0

for i in range(1000):
    n1 = i//100
    n2 = (i-n1*100)//10
    n3 = (i-n1*100-n2*10)
    
    if len(idx[n1])==0:
        continue
    
    m1 = bisect_right(idx[n2], idx[n1][0])
    
    if m1==len(idx[n2]):
        continue
    
    m2 = bisect_right(idx[n3], idx[n2][m1])
    
    if m2==len(idx[n3]):
        continue
    
    ans += 1

print(ans)

Solution (Python):
n = int(input())
s = input()
c = 0
def cha_3(num_):
    d = 3 - len(num_)
    return d*"0" + num_

for i in range(1000):
    num = cha_3(str(i))
    num_c = 0
    for j in range(len(s)):
        if s[j] == num[num_c]:
            num_c += 1
            if num_c == 3:
                c += 1
                break
print(c)

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

alph = "0123456789"
next_ = [[-1] * (n + 1) for i in range(len(alph))]
for ai in range(len(alph)):
    tmp = - 1
    for si in range(n)[::-1]:
        if s[si] == alph[ai]:
            tmp = si + 1
        next_[ai][si] = tmp

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp = next_[i][0]
            tmp = next_[j][tmp]
            tmp = next_[k][tmp]
            if tmp != -1:
                ans += 1
print(ans)

Solution (Python):
N=int(input())
S=input()
indexs=[[] for i in range(10)]
for i in range(N):
  indexs[int(S[i])].append(i)

counter=0
for i in range(0, 1000):
  a=i//100
  b=(i%100)//10
  c=i%10

  if len(indexs[a])>0 and len(indexs[b])>0 and len(indexs[c])>0:
    x=min(indexs[a])
    z=max(indexs[c])
    n=len(indexs[b])
    j=0
    for i in range(n):
      if indexs[b][i]>x and indexs[b][i]<z:
        j=1
    counter+=j

print(counter)

Solution (Python):
def main():
    n=int(input())
    s=input()
    cnt=0
    for i in range(1000):
        i="".join(["00",str(i)])[-3:]
        now=0
        char=i[0]
        for c in s:
            if char==c:
                if now<2:
                    now+=1
                    char=i[now]
                else:
                    cnt+=1
                    break
    print(cnt)
main()

Solution (Python):
N=int(input())
S=input()
count=0
for i in range(1000):
    p='0'*(3-len(str(i)))+str(i)
    p1=S.find(p[0])
    if p1!=-1:
        p2=S[p1+1:].find(p[1])
        if p2!=-1:
            p3=S[p1+p2+2:].find(p[2])
            if p3!=-1:
                count+=1
print(count)

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

Solution (Python):
N = int(input())
S = input()
flag = False
ans = 0
for i in range(1000):
    p = str(i).zfill(3)
    a = [-1, -1, -1]
    for j in range(len(S)):
        if p[0] == S[j]:
            a[0] = j
            break
    if a[0] != -1:
        for k in range(a[0] + 1, len(S)):
            if p[1] == S[k]:
                a[1] = k
                break
    else:
        continue
    if a[1] != -1:
        for l in range(a[1] + 1, len(S)):
            if p[2] == S[l]:
                a[2] = l
                break
    else:
        continue
    if a[2] != -1:
        ans += 1

print(ans)

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

r = 0
for i in range(10):
  s = a.find(str(i))
  if s == -1:
    continue
  for j in range(10):
    s2 = a.find(str(j), s + 1)
    if s2 == -1:
      continue
    for k in range(10):
      if a.find(str(k), s2 + 1) != -1:
        r += 1
print(r)

Solution (Python):
N=int(input())
S=input()
L=[[0 for j in range(10)]for i in range(N+1)]
R=[[0 for j in range(10)]for i in range(N+1)]
for i in range(N):
    for j in range(10):
        L[i+1][j]=L[i][j]
    L[i+1][int(S[i])]=1
for i in range(N-1,-1,-1):
    for j in range(10):
        R[i][j]=R[i+1][j]
    R[i][int(S[i])]=1
ans=[[[0 for k in range(10)]for j in range(10)] for i in range(10)]
num=[0 for k in range(10)]
for t in range(N):
    X=[]
    Y=[]
    k=int(S[t])
    for x in range(10):
        if L[t][x]==1:
            X.append(x)
    for y in range(10):
        if R[t+1][y]==1:
            Y.append(y)
    for i in X:
        for j in Y:
            if ans[i][j][k]==0:
                ans[i][j][k]=1
                num[k]+=1
print(sum(num))

Solution (Python):
N=int(input())
S=input()
L=[[0 for j in range(10)]for i in range(N+1)]
R=[[0 for j in range(10)]for i in range(N+1)]
for i in range(N):
    for j in range(10):
        L[i+1][j]=L[i][j]
    L[i+1][int(S[i])]=1
for i in range(N-1,-1,-1):
    for j in range(10):
        R[i][j]=R[i+1][j]
    R[i][int(S[i])]=1
ans=[[[0 for k in range(10)]for j in range(10)] for i in range(10)]
num=[0 for k in range(10)]
for t in range(N):
    X=[]
    Y=[]
    k=int(S[t])
    if num[k]==100:
        continue
    for x in range(10):
        if L[t][x]==1:
            X.append(x)
    for y in range(10):
        if R[t+1][y]==1:
            Y.append(y)
    for i in X:
        for j in Y:
            if ans[i][j][k]==0:
                ans[i][j][k]=1
                num[k]+=1
print(sum(num))

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

for i in range(1000):
  kazu = (3 - len(str(i))) * '0' + str(i)
  if kazu[0] in s:
    p1 = s.index(kazu[0])
    if kazu[1] in s[p1+1:]:
      p2 = s[p1+1:].index(kazu[1])
      if kazu[2] in s[p1+p2+2:]:
        cnt+=1
print(cnt)

Solution (Python):
length = int(input())
string = input()

possible_pins = list()
for pin in [str(num) for num in range(0, 1000)]:
    if len(pin) == 1:
        pin = "00" + pin
    elif len(pin) == 2:
        pin = "0" + pin
    possible_pins.append(pin)


count = 0
for pin in possible_pins:
    start = 0
    for letter in pin:
        try:
            index = string.index(letter, start)
            start = index + 1
        except ValueError:
            break
    else:
        count += 1
print(count)

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

ans = 0
for i in range(1000):
  pin = '{:03d}'.format(i)
  p1 = s.find(pin[0])
  if p1>=0:    
    p2 = s.find(pin[1],p1+1)     
    if p2>=0:
      p3 = s.find(pin[2],p2+1)      
      if p3>=0:
        ans+=1        
    
print(ans)

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

ans = 0
for i in range(1000):
  pin = '{:03d}'.format(i)
  p1 = s.find(pin[0])
  if p1>=0:    
    p2 = s[p1+1:].find(pin[1])     
    if p2>=0:
      p3 = s[p1+p2+2:].find(pin[2])      
      if p3>=0:
        ans+=1        
    
print(ans)

Solution (Python):
import sys
N = int(input())
S = list(input())
xList = []
yList = []
zList = []
sum = 0
a = 0
while a < N-2:
    if xList.count(S[a]) == 0:
        xList.append(S[a])
        b = a+1
        a += 1
        while b < N-1:
            if yList.count(S[b]) == 0:
                yList.append(S[b])
                c = b+1
                b += 1
                while c < N:
                    if zList.count(S[c]) == 0:
                        zList.append(S[c])
                        c += 1
                        sum += 1
                    else:
                        c += 1
                print(zList,file=sys.stderr)
                zList = []
            else:
                b += 1
        yList = []
    else:
        a += 1
print(sum)

Solution (Python):
n=int(input())
s=input()
cnt=0
for i in range(1000):
  l=(3-len(str(i)))*'0'+str(i)
  
  
  if l[0] in s:
    
    
    p1=s.index(l[0])
    
    
    if l[1] in s[p1+1:]:
      
      
      p2=p1+s[p1+1:].index(l[1])+1
      
      
      if l[2] in s[p2+1:]:
        
        cnt+=1
print(cnt)

Solution (Python):
n=int(input())
s=input()
cnt=0
for i in range(1000):
  l=(3-len(str(i)))*'0'+str(i)
  if l[0] in s:
    p1=s.index(l[0])
    if l[1] in s[p1+1:]:
      p2=p1+s[p1+1:].index(l[1])+1
      if l[2] in s[p2+1:]:
        cnt+=1
print(cnt)

Solution (Python):
l = int(input())
s = input()
r = set()
cx = set(s)
for x in range(0, l - 2):
    if not cx:
        break
    if s[x] not in cx:
        continue
    cx.remove(s[x])
    cy = set(s[x+1:])
    for y in range(x + 1, l - 1):
        if not cy:
            break
        if s[y] not in cy:
            continue
        cy.remove(s[y])
        cz = set(s[y+1:])
        for z in range(y + 1, l):
            if not cz:
                break
            if s[z] not in cz:
                continue
            cz.remove(s[z])
            r.add(s[x] + s[y] + s[z])

print(len(r))

Solution (Python):
N = int(input())
S = input()
 
c = 0
for i in range(1000):
    num_str = "{0:0>3}".format(i)
    j = 0
    for s in S:
        if num_str[j] == s:
            j += 1
        if j == 3:
            c += 1
            break
 
print(c)

Solution (Python):
N = input()
S = input()
ans = 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.find(str(j), a+1)
            if b == -1:
                continue
            c = S.find(str(k), b+1)
            if c == -1:
                continue
            ans+=1

print(ans)

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

for i in range(1000):
    t = str(i).zfill(3)

    
    if t[0] in S:
        t1 = S.index(t[0])
        
        if t[1] in S[t1 + 1:]:
            
            t2 = t1 + S[t1 + 1:].index(t[1]) + 1
            if t[2] in S[t2 + 1:]:
                ans += 1

print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
s = S()
cnt = 0
ans = set()
one_digit_set = set()
two_digit_set = set()
for i in range(n):
    for two_d in two_digit_set:
        ans.add(s[i] + two_d)
    for one_d in one_digit_set:
        two_digit_set.add(s[i] + one_d)
    one_digit_set.add(s[i])


print(len(ans))

Solution (Python):
from itertools import combinations

N = int(input())
S = input()
count = 0

ans = set({})

for password in range(0, 1000):
    s = "{:03d}".format(password)
    s1, s2, s3 = s
    
    if s1 not in S:
        continue
    i1 = S.index(s1)
    if s2 not in S[i1+1:]:
        continue
    i2 = S[i1+1:].index(s2)
    if s3 not in S[i1+1:][i2+1:]:
        continue
    i3 = S[i1+1:][i2+1:].index(s3)
    
    ans.add(password)

print(len(ans))

Solution (Python):
import bisect

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

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

for i in range(n):
    mlist[int(s[i])].append(i)

answer=[]

for i in range(10):
    if len(mlist[i])>0:
        left=min(mlist[i])
        for j in range(10):
            if len(mlist[j])>0:
                center=bisect.bisect_right(mlist[j], left)
                if center!=len(mlist[j]):
                    center=mlist[j][center]
                    for k in range(10):
                        right=bisect.bisect_right(mlist[k], center)
                        if right!=len(mlist[k]):
                            answer.append([i*100+j*10+k*1])
                else:
                    pass
            else:
                pass
    else:
        pass

print(len(answer))

Solution (Python):
n = int(input())
s = input()
ans = 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.find(str(j), a+1)
      if b==-1:
        continue
      c = s.find(str(k), b+1)
      if c==-1:
        continue
      ans+=1
print(ans)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
S = input()

dp = list2d(N+1, 4, 0)
dp[0][0] = 1
msk = (1<<1000) - 1
for i in range(N):
    a = int(S[i])
    for j in range(4):
        dp[i+1][j] |= dp[i][j]
        if j == 0:
            dp[i+1][j+1] |= dp[i][j]<<a*100
            dp[i+1][j+1] &= msk
        if j == 1:
            dp[i+1][j+1] |= dp[i][j]<<a*10
            dp[i+1][j+1] &= msk
        if j == 2:
            dp[i+1][j+1] |= dp[i][j]<<a
            dp[i+1][j+1] &= msk
ans = 0
S = dp[N][3]
for k in range(1000):
    if S & 1<<k:
        ans += 1
print(ans)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
S = input()

dp = list2d(N+1, 4, 0)
dp[0][0] = 1
msk = (1<<1000) - 1
for i in range(N):
    a = int(S[i])
    for j in range(4):
        dp[i+1][j] |= dp[i][j]
        if j == 0:
            dp[i+1][j+1] |= dp[i][j]<<a*100
            dp[i+1][j+1] &= msk
        if j == 1:
            dp[i+1][j+1] |= dp[i][j]<<a*10
            dp[i+1][j+1] &= msk
        if j == 2:
            dp[i+1][j+1] |= dp[i][j]<<a
            dp[i+1][j+1] &= msk
ans = 0
S = dp[N][3]
for k in range(1000):
    if S & 1<<k:
        ans += 1
print(ans)

Solution (Python):

 
import math
import itertools
import re
 

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

 
si = ""
cnt = 0
for i in range(1000) :
  
  si = str(i).zfill(3)
  
  c = 0
  for x in range(N) :
    if S[x] == si[c] :
      c += 1
      if c == 3 :
        cnt += 1
        break    

print (cnt)

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

ans = 0
for i in range(1000):
	num=str(i).zfill(3)
	
	if num[0] in S:
		p1 = S.index(num[0])
		if num[1] in S[p1+1:]:
			p2 = p1+1+S[p1+1:].index(num[1])
			if num[2] in S[p2+1:]:
				ans += 1
				


print(ans)