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):
from itertools import product

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

cnt = 0
for i, j, k in product("0123456789", repeat=3):
    T = [i, j, k]
    cur = 0
    for s in S:
        if s == T[cur]:
            cur += 1
            if cur == 3:
                cnt += 1
                break

print(cnt)

Solution (Python):
n = int(input())
s = input()
cnt = 0
for i in range(1000):
  num = '{:03}'.format(i)
  t=0
  for j in range(n):
    if s[j] == num[t]:
      t += 1
      if t > 2:
        cnt += 1
        break
print(cnt)

Solution (Python):
N = int(input())
S = input()
nums = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            nums.append(str(i) + str(j) + str(k))

cnt = 0
for num in nums:
    j = 0
    for i in range(N):
        if S[i] == num[j]:
            j += 1
        if j > 2:
            cnt += 1
            break

print(cnt)

Solution (Python):
n = int(input())
s = input()
ans = 0
for a in range(10):
  for b in range(10):
    for c in range(10):
      a, b, c = str(a), str(b), str(c)
      a_find = s.find(a)
      if a_find == -1:
        continue
      b_find = s.find(b, a_find + 1)
      if b_find == -1:
        continue
      c_find = s.find(c, b_find + 1)
      if c_find == -1:
        continue
      ans += 1
print(ans)

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

for i in range(1000):
    j = 0
    flag1 = False
    flag2 = False
    flag3 = False
    istr = str(i)
    istr = istr.rjust(3, '0')
    
    while j < N:
        if not flag1 and S[j] == istr[0]:
            flag1 = True
        elif flag1 and (not flag2) and S[j] == istr[1]:
            flag2 = True
        elif flag1 and flag2 and S[j] == istr[2]:
            flag3 = True
            
            break
        j += 1
    if flag1 and flag2 and flag3:
        cnt += 1
print(cnt)

Solution (Python):
N=int(input())
s=list(map(lambda c:ord(c)-48,input()))
cnt=0
for x in range(10):
    idx=0
    while idx<N and s[idx]!=x:
        idx+=1
    if idx==N:continue
    for y in range(10):
        idy=idx+1
        while idy<N and s[idy]!=y:
            idy+=1
        if idy==N:continue
        for z in range(10):
            idz=idy+1
            while idz<N and s[idz]!=z:
                idz+=1
            if idz<N:cnt+=1
print(cnt)

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

ans = 0
for i in range(1000):
    n = "{:03}".format(i)
    index = 0
    c = 0
    for k in n:
        for j in range(index, N):
            if S[j] == k:
                index = j+1
                c+=1
                break
    if c == 3:
        ans += 1
print(ans)

Solution (Python):
from collections import defaultdict, deque

def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                a = 0
                password = str(i) + str(j) + str(k)
                for s in S:
                    if s == password[a]:
                        a += 1
                    if a == 3:
                        ans += 1
                        break

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict, deque

def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(1000):
        password = str(i).zfill(3)
        j = 0
        for s in S:
            if s == password[j]:
                j += 1
            if j == 3:
                ans += 1
                break

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
input()
a, b, c = set(), set(), set()
for x in input():
  c.update(y + x for y in b)
  b.update(y + x for y in a)
  a.add(x)
print(len(c))

Solution (Python):
input()
a = set(), set(), set(), ('',)
for x in input():
  for s, t in zip(a, a[1:]):
    s.update(y + x for y in t)
print(len(a[0]))

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 = str(input())

first_num_list  = []
second_num_list = []
third_num_list  = []

count = 0

for s_first in range(len(S)):
  second_num_list = []
  if S[s_first] not in first_num_list:
    first_num_list.append(S[s_first])
    for s_second in range(s_first+1,len(S)):
      third_num_list = []
      if S[s_second] not in second_num_list:
        second_num_list.append(S[s_second])
        for s_third in range(s_second+1,len(S)):
          if S[s_third] not in third_num_list:
            third_num_list.append(S[s_third])
            count += 1

print(count)

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

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


count=0


for n1 in range(10):
 cond=0
 for i in range(N-2):
   if n1==int(S[i]):
      p1=i
      cond=1
      break
 if cond==1:
  for n2 in range(10):
    for j in range(p1+1,N-1):
      if n2==int(S[j]):
        p2=j
        cond=2
        break
    if cond==2:
     for n3 in range(10):
       
       if str(n3) in S[p2+1:]:
        
        count+=1
        cond=0
      
              
print(count)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    S=input()
    ans=0

    for p in range(1000):
        p=str(p).zfill(3)
        now=0
        for i,d in enumerate(p):
            while(now<n and S[now]!=d):
                now+=1
            if(i<=1):
                now+=1
        ans+=(now<n)
    print(ans)
resolve()

Solution (Python):
def match(S,pat):
    i = 0
    for s in S:
        if s == pat[i]:
            i += 1
        if i == 3:
            return True
    return False

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

for n in range(1000):
    s = str(n)
    if len(s) == 1:
        s = '00'+s
    elif len(s) == 2:
        s = '0'+s
    else:
        pass
    if  match(S,s):
        ans += 1
    
print(ans)

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

v1 = [100]*10
v2 = [0]*10
v3 = [0]*10

out = 0

for i in range(len(s)):
  idx = int(s[i])
  if v3[idx] > 0:
    out += v3[idx]
    v3[idx] = 0
  if v2[idx] > 0:
    for j in range(len(v2)):
      v3[j] += v2[idx]//10
    v2[idx] = 0
  if v1[idx] > 0:
    for j in range(len(v2)):
      v2[j] += v1[idx]//10
    v1[idx] = 0

print(out)

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

count = 0

for i in range(10):
    if i in S[:N-2]:
        a = S.index(i)
        for j in range(10):
            if j in S[a+1:N-1]:
                b = S[a+1:N-1].index(j) +a+1
                for k in range(10):
                    if k in S[b+1:]:
                        count +=1
print(count)

Solution (Python):
_,s=open(0)
x,y,z=eval('set(),'*3)
for c in s[:-1]:
  z|={t+c for t in y}
  y|={t+c for t in x}
  x|={c}
print(len(z))

Solution (Python):
_,s=open(0)
x,y,z=eval('set(),'*3)
for c in s[:-1]:
  z|={t+c for t in y}
  y|={t+c for t in x}
  x|={c}
print(len(z))

Solution (Python):
_,s=open(0)
x,y,z=eval('set(),'*3)
for c in s[:-1]:
  for t in y:z.add(t+c)
  for t in x:y.add(t+c)
  x.add(c)
print(len(z))

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

    a = ['{:03d}'.format(i) for i in range(1000)]
    count = 0
    for i in range(len(a)):
        m,n,o = 0,1,2
        s = list(a[i])
        while m < n < o < len(lst) :
            if s[0] != lst[m]:
                m += 1
                n += 1
                o += 1
            elif s[1] != lst[n]:
                n += 1
                o += 1
            elif s[2] != lst[o]:
                o += 1
            else:
                count += 1
                break

    print(count)

if __name__ == "__main__":
    main()

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()

def check(x):
    i = 0
    for a in S:
        if a == x[i]:
            i += 1
            if i == 3:
                return True
    return False

cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            x = str(i)+str(j)+str(k)
            if check(x):
                cnt += 1
print(cnt)

Solution (Python):
def d():
	from bisect import bisect_left
	N = int(input())
	S = input()
	chars_at = {}
	for i in range(N):
		try:
			chars_at[S[i]].append(i)
		except KeyError:
			chars_at[S[i]] = [i]
	ans = 0
	for i in range(1000):
		s = str(i).zfill(3)
		cur = -1
		for j in range(3):
			try:
				p = bisect_left(chars_at[s[j]],cur)
			except KeyError:
				break

			if p < len(chars_at[s[j]]):
				cur = chars_at[s[j]][p] + 1
			else:
				break
		else:
			ans += 1
	print(ans)
d()

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

    
    ans = 0
    for v in range(1000):
        pin = '{0:03}'.format(v)
        current_index = 0
        current_searching = pin[current_index]

        for ch in S:
            if ch == current_searching:
                current_index += 1
                if current_index == 3:
                    ans += 1
                    break
                current_searching = pin[current_index]
    return ans

print(d_lucky_pin())

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

    
    ans = 0
    for v in range(1000):
        pin = '{0:03}'.format(v)
        current_searching = 0

        for ch in S:
            if ch == pin[current_searching]:
                current_searching += 1
            if current_searching == 3:
                ans += 1
                break
    return ans

print(d_lucky_pin())

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def main():
    N=int(input())
    S=input()[:-1]
    
    can = set([""]) 
    ans = set() 
    for s in S: 
        for c in can.copy(): 
            res = c+s 
            if len(res) == 3: 
                ans.add(res)
            elif len(res) < 3: 
                can.add(res)
    print(len(ans))

    """
    copyする回数 = N * len(can) <= 10^3 * N
    for文の走査回数 = N * len(can) <= 10^3 * N
    
    全体で  2 * (10^3 * N)
    N<=3*10^4なので
    2*3* 10^3 * 10^4 = 6 * 10^7 -> 間に合わない？んですか・・・？
    """

if __name__ == '__main__':
    main()

Solution (Python):
from bisect import bisect_right
n=int(input())
s=input()
ind=[[] for i in range(10)]
i=0
for c in s:
    ind[ord(c)-48].append(i)
    i+=1
cnt=0
for i in range(1000):
    j=i//100
    k=i//10-j*10
    l=i%10
    if len(ind[j])*len(ind[k])*len(ind[l])==0:
        continue
    if ind[j][0]<ind[k][-1]:
        if ind[k][bisect_right(ind[k],ind[j][0])]<ind[l][-1]:
            cnt+=1
print(cnt)

Solution (Python):
n = int(input())
s = input()
p = [set() for _ in range(100)]
sp = [set() for _ in range(n)]
k = int(s[-1])
sp[-1].add(k)
ful = False
for j in range(n-2,1,-1):
    if ful:
        sp[j] = {0,1,2,3,4,5,6,7,8,9}
    tmp = set(sp[j+1])
    if len(tmp) == 10:
        ful = True
    tmp.add(int(s[j]))
    sp[j] = tmp

s10 = [[99999 for _ in range(2)] for _ in range(10)]
for i,d in enumerate(s):
    c = int(d)
    if s10[c][0] == 99999:
        s10[c][0] = i
    elif s10[c][1] == 99999:
        s10[c][1] = i
g = 0
for i in range(10):
    for j in range(10):
        ans = 0
        nexid = min(s10[i])
        if nexid != 99999:
            for r in range(nexid+1,n-1):
                if int(s[r]) == j:
                    ans = len(sp[r+1])
                    break
            g += ans
print(g)

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

ans=0
for i in range(1000):
    j="0"*(3-len(str(i)))+str(i)
    flag1=False
    flag2=False
    flag3=False
    for i in range(n):
        if not flag1 and S[i]==j[0]:
            flag1=True
            continue
        if flag1 and not flag2:
            if S[i]==j[1]:
                flag2=True
                continue
        if flag2 and not flag3:
            if S[i]==j[2]:
                flag3=True
                break
    if flag3:
        ans+=1
print(ans)

Solution (Python):

import sys

def solve(N: int, S: str):
    answer = 0
    for i in range(0,1000):
        i = str(i).zfill(3)
        x = S.find(i[0])
        if x == -1:
            continue

        y = S.find(i[1],x+1)
        if y == -1:
            continue

        z = S.find(i[2],y+1)
        if z == -1:
            continue
        
        answer +=1
    print(answer)
    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):
N = int(input())
S = list(input())
PIN = []
b1 = []
for i in range(N-2):
    b2 = []
    if S[i] in b1:
        continue
    else:
        b1.append(S[i])
    for j in range(i+1, N-1):
        b3 = []
        if S[j] in b2:
            continue
        else:
            b2.append(S[j])
        for k in range(j+1, N):
            if S[k] in b3:
                continue
            else:
                b3.append(S[k])
            cand = S[i] + S[j] + S[k]
            PIN.append(cand)

print(len(set(PIN)))

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

ctr = [0] * 1000
ans = 0
for i in range(1000):
    v1 = i // 100
    v2 = i // 10 - v1 * 10
    v3 = i - v1 * 100 - v2 * 10
    
    p1 = S.find(str(v1))
    if p1 < 0:
        continue
        
    p2 = S[p1+1:].find(str(v2))
    if p2 < 0:
        continue
        
    p3 = S[p1+p2+2:].find(str(v3))
    ans += int(p3 >= 0)
    
print(ans)

Solution (Python):
from itertools import product
 
N = int(input())
S = input()
 
cnt = 0
for i, j, k in product("0123456789", repeat=3):
    try:
        x = S.index(i)
        y = S.index(j, x + 1)
        z = S.index(k, y + 1)
    except:
        continue
    cnt += 1
 
print(cnt)

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

d1 = defaultdict(int)
d2 = defaultdict(int)
d3 = defaultdict(int)

for s in S:
    for x in d2:
        d3[x+s]+=1
    for y in d1:
        d2[y+s]+=1
    d1[s]+=1

print(len(d3))

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

nsl=['{:03}'.format(i) for i in range(1000)]

res=0
for ns in nsl:
  idx=0
  for char in s:
    if char == ns[idx]:
      idx+=1
      if idx == 3:
        res+=1
        break
print(res)

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

def my_index(LIST, VALUE,START):
    if VALUE in LIST[START:]:
        return LIST.index(VALUE,START)
    else:
        return float("inf")

answer = 0

for i in range(1000):
    PIN = str(i).rjust(3,"0")
    if PIN[0] in S:
        one_digit = S.index(PIN[0])
    else:
        continue
    if PIN[1] in S:
        two_digit = my_index(S,PIN[1],one_digit+1)
        if two_digit == float("inf"):
            continue
    else:
        continue
    if PIN[2] in S:
        three_digit = my_index(S,PIN[2],two_digit+1)
        if three_digit == float("inf"):
            continue
    else:
        continue
    answer += 1

print(answer)

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

dp = tuple([0] * 1000 for _ in range(4))
dp[0][0] = 1


for x in s:
    for incomplete_key in range(100):
        dp[3][incomplete_key * 10 + x] |= dp[2][incomplete_key]
    for incomplete_key in range(10):
        dp[2][incomplete_key * 10 + x] |= dp[1][incomplete_key]
    dp[1][x] = 1

print(sum(dp[3]))

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

count = 0 
for i in range(1000):
        key = str(i)
        if len(key) == 1:
                key = '00' + key 
        elif len(key) == 2:
                key = '0' + key 
        position_first = s.find(key[0]) 
        if position_first != -1 and position_first < n - 2:
                position_first += 1
                position_second = s[position_first:].find(key[1])
                if position_second != -1 and position_second + position_first < n - 1:
                        position_second += 1
                        position_third = s[position_first + position_second:].find(key[2])
                        if position_third != -1: 
                                count += 1
print(count)

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

total = 0

for i in range(1000):
    query = str(i)
    query = "0"*(3-len(query)) + query

    current_query = query[0]
    current_query_index = 0
    for s in S:
        if s == current_query:
            current_query_index += 1
            if current_query_index == 3:
                break
            current_query = query[current_query_index]
    if current_query_index == 3:
        total += 1

print(total)

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

dp = tuple(set() for _ in range(4))
dp[0].add('')


for c in s:
    for k in range(2, -1, -1):
        for incomplete_key in dp[k]:
            dp[k + 1].add(incomplete_key + c)

print(len(dp[3]))

Solution (Python):
N = int(input())
S = str(input())
V = []
f=0
s=set()
for i in range(10):
    for j in range(10):
        for k in range(10):
            V.append(str(i)+str(j)+str(k))

for v in V:
    for a in range(N):
        if S[a]==v[0]:
            for b in range(a+1, N):
                if S[b]==v[1]:
                    for c in range(b+1, N):
                        if S[c]==v[2]:
                            s.add(v)
                            break
                    break
            break
print(len(s))

Solution (Python):
N = int(input())
S = input()
S_uniquie = ''.join(set(S))
answer = 0
for left_s in S_uniquie:
    for i in range(N):
        if S[i] == left_s:
            left_pos = i
            break
    for right_s in S_uniquie:
        for i in range(N - 1, -1, -1):
            if S[i] == right_s:
                right_pos = i
                if left_pos + 2 <= right_pos:
                    answer += len(''.join(set(S[left_pos + 1:right_pos])))
                break

print(answer)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(1000):
  v=str(i)
  v=v.zfill(3)
  ss=s
  if not v[0] in ss:
    continue  
  ss=ss[ss.index(v[0])+1:]
  if not v[1] in ss:
    continue
  ss=ss[ss.index(v[1])+1:]
  if not v[2] in ss:
    continue
  ans+=1
print(ans)

Solution (Python):
n = int(input())
s= input()
ans=0
for x in range(1000):
    num=str("{0:03d}".format(x))
    s1=s.find(num[0])
    if(s1!=-1):
        s2=s.find(num[1],s1+1)
        if(s2!=-1):
            s3=s.find(num[2],s2+1)
            if(s3!=-1):
                ans+=1
print(ans)

Solution (Python):
from itertools import product
from string import digits


def is_producible(s, digit3):
    curr = 0
    for c in s:
        if c == digit3[curr]:
            curr += 1
            if curr == 3:
                return True
    return False


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

ret = 0
for digit3 in product(digits, repeat=3):
    if is_producible(s, digit3):
        ret += 1
print(ret)

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

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


N = 0
number1 = list(range(10))


for i in range(0,n-2):
    if int(s[i]) in number1:
        number1.remove(int(s[i]))
        number2 = list(range(10))
        for j in range(i + 1,n - 1):
            
            if int(s[j]) in number2:
                number2.remove(int(s[j]))
                number3 = list(range(10))
                for k in range(j + 1,n):
                    if int(s[k]) in number3:
                        number3.remove(int(s[k]))
                        N += 1
                        if N == 1000:
                            break
"""
                        print(s[i]+s[j]+s[k])
                        print("{}{}{}".format(i,j,k))
"""
                        

print(N)

Solution (Python):
def main():
    import itertools
    import re

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

    cnt = 0
    for key in itertools.product('0123456789', repeat=3):
        key1, key2, key3 = map(str, key)
        if key1 in s:
            key1_idx = s.find(key1)
            if key2 in s[key1_idx+1:]:
                key2_idx = key1_idx + s[key1_idx+1:].find(key2) + 1
                if key3 in s[key2_idx+1:]:
                    cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()

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

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


N = 0
number1 = list(range(10))


for i in range(0,n-2):
    if int(s[i]) in number1:
        number1.remove(int(s[i]))
        number2 = list(range(10))
        for j in range(i + 1,n - 1):
            
            if int(s[j]) in number2:
                number2.remove(int(s[j]))
                number3 = list(range(10))
                for k in range(j + 1,n):
                    if int(s[k]) in number3:
                        number3.remove(int(s[k]))
                        N += 1
                        if N == 1000:
                            break
"""
                        print(s[i]+s[j]+s[k])
                        print("{}{}{}".format(i,j,k))
"""
                        

print(N)

Solution (Python):
input()
S=list(input())
ans=0
 
def index(x,l):
    if x in l:
        return l.index(x)
    else:
        return -1
 
for i in range(1000):
    s=list(str(i).zfill(3))
    if index(s[0],S) != -1:
        if index(s[1],S[S.index(s[0])+1:]) != -1:
            if index(s[2],S[S.index(s[0])+1:][S[S.index(s[0])+1:].index(s[1])+1:]) != -1:
                ans += 1
print(ans)

Solution (Python):



def dfs(p, cur):
    sz = len(cur)
    if sz == 3:
        return
    for i in range(p + 1, n):
        nxt = cur + s[i]
        if nxt in used[sz]:
            continue
        used[sz][nxt] = True
        dfs(i, nxt)


n = int(input())
s = input()
used = [{} for _ in range(3)]

dfs(-1, "")

print(len(used[2]))

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

        if cnt == 3:
            ans += 1
            break

print(ans)

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

cnt = 0
for i in range(1000):
    c = list(str(i).zfill(3).strip())
    f = 0
    for j in range(N):
        if S[j] == c[f]:
            f += 1
        if f == 3:
            break
    if f == 3:
        cnt += 1
        
print(cnt)

Solution (Python):
N = int(input())
S = input()
L = [str(i).zfill(3) for i in range(1000)]
count = 0
for l in L:
    try:
        i = S.index(l[0])
        j = S.index(l[1], i + 1)
        k = S.index(l[2], j + 1)
        count += 1
    except:
        continue
print(count)

Solution (Python):
_ = input()
S = input()
counter = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            idxi = S.find(str(i))
            if idxi ==-1:
                continue
            idxj = S.find(str(j),idxi+1)
            if idxj == -1:
                continue
            idxk = S.find(str(k),idxj+1)
            if idxk == -1:
                continue
            counter+=1
print(counter)

Solution (Python):
N = int(input())
S = input()
ans = 0
snumber = [str(i) for i in range(10)]
for i in snumber:
    for j in snumber:
        for k in snumber:
            a = S.find(i)
            if a == -1:
                break
            b = S.find(j,a+1)
            if b == -1:
                break
            c = S.find(k,b+1)
            if c != -1:
                ans += 1
print(ans)

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

res = 0

for i in range(10):
    p1 = S.find(str(i))
    if p1 == -1:
        continue
    elif p1 > N-3:
        continue
    for j in range(10):
        p2 = S[p1+1:N].find(str(j))
        if p2 == -1:
            continue
        elif p2 > N-p1-3:
            continue
        for k in range(10):
            p3 = S[p1+p2+2:N].find(str(k))
            if p3 == -1:
                continue
            res += 1


print(res)

Solution (Python):
N = int(input())
S = input()
ans = 0
snumber = [str(i) for i in range(10)]
for i in snumber:
    for j in snumber:
        for k in snumber:
            a = S.find(i)
            if a == -1:
                break
            b = S.find(j,a+1)
            if b == -1:
                break
            c = S.find(k,b+1)
            if c != -1:
                ans += 1
print(ans)

Solution (Python):
import collections
def main():

    N = int(input())
    S = input()
    d = collections.defaultdict(set)
    for i in range(N):
        for v in d[2]:
            d[3].add(v + S[i])
        for v in d[1]:
            d[2].add(v + S[i])
        d[1].add(S[i])
        
        
        
    return len(d[3])

if __name__ == '__main__':
    print(main())

Solution (Python):

import itertools
N=int(input())
S=str(input())
count=0
for i,j,k in itertools.product(range(10),repeat=3):
  try:
    x = S.index(str(i))
    y = S.index(str(j),x+1)
    z = S.index(str(k),y+1)
    count +=1
  except:
    continue

print(count)

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






def check_match(word,str_cnt):
    global S
    ret = -1

    for i in range(str_cnt,len(S)):
        if S[i] == word:
            ret = i
            break

    return ret


password = [0]*3
ans_cnt = 0
for num in range(1000):
    ret = 0
    password = str(num)
    password = password.zfill(3)

    ret = check_match(password[0],ret)
    if ret != -1:
        ret = check_match(password[1],ret+1)
        if ret != -1:
            ret= check_match(password[2],ret+1)
            if ret != -1:
                ans_cnt = ans_cnt + 1

print (ans_cnt)

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

cnt = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            pin = [i, j, k]
            x = 0

            for a in S:
                if a == pin[x]:
                    x += 1
                    if x == 3:
                        cnt += 1
                        break

print(cnt)

Solution (Python):
n = int(input())
S = input()
cnt = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      i_pos = S.find(str(i))
      if i_pos == -1:
        continue
      j_pos = S.find(str(j),i_pos+1)
      if j_pos == -1:
        continue
      k_pos = S.find(str(k),j_pos+1)
      if k_pos == -1:
        continue
      cnt += 1
print(cnt)

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            
            if str(i) in S:
                x = S.index(str(i))
                if str(j) in S[x+1:]:
                    y = S[x+1:].index(str(j))+x+1
                    if str(k) in S[y+1:]:
                        ans+=1
           

print(ans)

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

list=list(S)

count=0
for a in range(10):
    find1=S.find(str(a))
    if find1==-1:
        continue
    for b in range(10):
        find2=S[find1+1:].find(str(b))
        if find2==-1:
            continue
        for c in range(10):
            find3=S[find1+1+find2+1:].find(str(c))
            if find3==-1:
                continue
            count+=1
print(count)

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

ans = 0
for x in X:
    now = 0
    for s in S:
        if s == x[now]:
            now += 1
        if now == 3:
            ans += 1
            break
print(ans)