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

pin=set()
for i in range(0,1000):
    yn=""
    stri=format(i,"03d")
    for ii in range(n-2):
        if stri[0]!=s[ii]:
            continue
        else:
            yn="yes1"
            break
    if yn!="yes1":
        yn="no"
        continue
    for iii in range(ii+1,n-1):
        if stri[1]!=s[iii]:
            continue
        else:
            yn="yes2"
            break
    if yn!="yes2":
        yn="no"
        continue
    for iiii in range(iii+1,n):
        if stri[2]!=s[iiii]:
            continue
        else:
            yn="yes3"
            break
    if yn=="yes3":
        pin.add(stri)
    else:
        continue

print(len(pin))

Solution (Python):
'''
暗証番号3桁はたかだか10**3の候補。これを全探索で調べるだけ
pythonのindex関数を使用するとオブジェクト内に要素が存在しない場合エラーになる
'''
n = int(input())
s = [int(i) for i in input()]

def my_index(l,x,ind):
    '''
    l: イテラブル(for inで取り出せる)オブジェクト
    x: 探し出す大賞
    ind: イテラブルで探し始める位置（インデックス）
    返り値: 存在する場合はそのインデックス、存在しない場合は-1
    '''
    global n 
    if ind == n: 
        return -1
    for i in range(ind, n):
        if l[i] == x:
            return i
    else:
        return -1
c = 0
for i in range(10):
    x1 = my_index(s,i,0)
    if x1 != -1:
        for j in range(10):
            x2 = my_index(s,j,x1+1)
            if x2 != -1:
                for k in range(10):
                    x3 = my_index(s,k,x2+1)
                    if x3 != -1:
                        c += 1
print(c)

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



ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    
    n = 0
    f = [False] * N
    for j in range(len(S)):
        if v[n] == S[j]:
            n += 1
        if n >= 3:
            
            ans += 1
            break

print(ans)

Solution (Python):

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

result = 0
c = [0]*3
for i in range(1000):
    count = 0
    c[0] = str(i // 100)
    c[1] = str((i % 100) // 10)
    c[2] = str(i % 10)
    for j in range(n):
        if(c[count] == s[j]):
            count += 1
        if(count == 3):
            result += 1
            break

print(result)

Solution (Python):
N = int(input())
S = input()
cnt = 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 :
                cnt += 1

print(cnt)

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

import re

count = 0
for i in range(10):
    try:
        i_ = re.search(str(i), S).start()
    except:
        continue
    for j in range(10):
        try:
            j_ = re.search(str(j), S[i_+1:]).start()
        except:
            continue
        for k in range(10):
            try:
                k_ = re.search(str(k), S[i_+1+j_+1:]).start()
            except:
                continue

            count += 1

print(count)

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

passwd = ["{:03}".format(x) for x in range(1000)]
ans = 0

for p in passwd:
    p = iter(p)
    c = next(p)
    for t in s:
        if c == t:
            try:
                c = next(p)
            except:
                ans += 1
                break

print(ans)

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

passwd = ["{:03}".format(x) for x in range(1000)]
ans = 0

for p in passwd:
    p = iter(p)
    c = next(p)
    n = 0
    for t in s:
        if c == t:
            n += 1
            if n == 3:
                ans += 1
                break
            c = next(p)

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())
sn = input().strip()

count = 0
for i in range(1000):
    lucky_num = False
    num = str(i).zfill(3)
    c = 0
    for j in range(n):
        if sn[j] == num[c]:
            c += 1
        if c >= 3:
            lucky_num = True
            break
    if lucky_num:
        count += 1

print(count)

Solution (Python):
n = int(input())
s = input()
ans = 0
A = [str(i).zfill(3) for i in range(0,1000)]

cnt = 0
for v in A:
    id_1 = s.find(v[0])
    if id_1 == -1:
        continue
    id_2 = s.find(v[1], id_1 + 1)
    if id_2 == -1:
        continue
    id_3 = s.find(v[2], id_2 + 1)
    if id_3 == -1:
        continue
    cnt += 1

print(cnt)

Solution (Python):
n = int(input())
s = input()
lst = [0] * 1000
for i in range(1000):
    if len(str(i)) == 1:
        tmp = '00' + str(i)
        lst[i] = tmp
    elif len(str(i)) == 2:
        tmp = '0' + str(i)
        lst[i] = tmp
    else:
        lst[i] = str(i)

cnt = 0
for v in lst:
    id_1 = s.find(v[0])
    if id_1 == -1:
        continue
    id_2 = s.find(v[1], id_1 + 1)
    if id_2 == -1:
        continue
    id_3 = s.find(v[2], id_2 + 1)
    if id_3 == -1:
        continue
    cnt += 1

print(cnt)

Solution (Python):

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

  ans = 0

  
  for i in range(1000):
    pin = str(i).zfill(3)
    cur = 0

    for char in S:
      if(pin[cur] == char):
        cur += 1

        if(cur == 3):
          ans += 1
          break;

  print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import re
N = int(input())
S = input()
ans = 0
tmp = [[m.start() for m in re.finditer(str(i), S)] for i in range(10)]
for i in range(10):
  if len(tmp[i]) == 0:
    continue
  for j in range(10):
    if len(tmp[j]) == 0:
      continue
    for k in range(10):
      if len(tmp[k]) == 0:
        continue
      l = tmp[i][0]
      flag = True
      for m in tmp[j]:
        if m > l:
          flag = False
          break
      if flag:
        continue
      for n in tmp[k]:
        if n > m:
          ans += 1
          break
print(ans)

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

ans = 0
for i in range(10):
    a = s.find(str(i))
    
    if 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:
                ans += 1
print(ans)

Solution (Python):
n = int(input())
s = input()
lst = [0] * 1000
for i in range(1000):
    if len(str(i)) == 1:
        tmp = '00' + str(i)
        lst[i] = tmp
    elif len(str(i)) == 2:
        tmp = '0' + str(i)
        lst[i] = tmp
    else:
        lst[i] = str(i)

cnt = 0
for v in lst:
    id_1 = s.find(v[0])
    if id_1 == -1:
        continue
    id_2 = s.find(v[1], id_1 + 1)
    if id_2 == -1:
        continue
    id_3 = s.find(v[2], id_2 + 1)
    if id_3 == -1:
        continue
    cnt += 1

print(cnt)

Solution (Python):

import itertools

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




ans = 0
for i, j, k in itertools.product(range(10),repeat=3):
    
    chk = str(i)+str(j)+str(k)
    p = S.find(chk[0])
    q = S.find(chk[1], p+1)
    r = S.find(chk[2], q+1)
    if p!=-1 and q!=-1 and r!=-1:
        ans += 1       
print(ans)

Solution (Python):


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




ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            
            chk = str(i)+str(j)+str(k)
            idx = 0
            for s in S:
                if s==chk[idx]:
                    idx += 1
                    if idx == 3:
                        ans += 1
                        break
print(ans)

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


def check(subs):
    start = 0
    for x in subs:
        index = S.find(x, start)
        if index == -1:
            return False
        start = index + 1
    return True


ans = 0
for i in range(1000):
    s = '0' * (3 - len(str(i))) + str(i)
    if check(s):
        ans += 1
print(ans)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(1000):
  t_str=str(i)
  t_len=len(t_str)
  t_str=(3-t_len)*"0"+t_str
  cur_idx=0
  ok=0
  for j,ss in enumerate(s):
    if ss==t_str[cur_idx]:
      cur_idx+=1
      ok+=1
    if cur_idx==3:break
  if cur_idx==3:
    ans+=1
print(ans)

Solution (Python):
n=int(input())
S=input()
ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            x=str(i)+str(j)+str(k)
            p=S.find(x[0])
            q=S.find(x[1],p+1)
            r=S.find(x[2],q+1)
            if p!=-1 and q!=-1 and r!=-1:
                ans+=1
print(ans)

Solution (Python):
def solve():
    N = int(input())
    S = input()
    dict = {}
    for cand in range(1000):
        cand_zero = str(cand).zfill(3)
        if cand_zero[0] in S:
            i = S.index(cand_zero[0])
            if cand_zero[1] in S[i+1:]:
                j = len(S[:i+1]) + S[i+1:].index(cand_zero[1])
                if cand_zero[2] in S[j+1:]:
                    k = len(S[:j+1]) + S[j+1:].index(cand_zero[2])
                    if cand_zero not in dict.keys():
                        dict[cand_zero] = 1
    print(len(dict.keys()))



if __name__ == "__main__":
    solve()

Solution (Python):
def solve():
    N = int(input())
    S = input()
    dict = {}
    for cand in range(1000):
        cand_zero = str(cand).zfill(3)
        if cand_zero[0] in S:
            i = S.index(cand_zero[0])
            if cand_zero[1] in S[i+1:]:
                j = len(S[:i+1]) + S[i+1:].index(cand_zero[1])
                if cand_zero[2] in S[j+1:]:
                    k = len(S[:j+1]) + S[j+1:].index(cand_zero[2])
                    if cand_zero not in dict.keys():
                        dict[cand_zero] = 1
    print(len(dict.keys()))



if __name__ == "__main__":
    solve()

Solution (Python):
from sys import stdin
import itertools

if __name__ == "__main__":
  N = int(input())
  S = input().strip()
  
  nums = "".join([str(i) for i in range(10)])
  
  cnt = 0
  
  for ds in itertools.product(nums, repeat=3):
    invalid = False
    last_index = -1
    for d in ds:
      last_index = S.find(d, last_index+1)
      if last_index < 0:
        invalid = True
        break
      
    if not invalid:
      cnt += 1
    
  print(cnt)

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

ans = set()
for i in range(10):
    i_index = S.find(str(i))
    if i_index == -1:
        continue
    for j in range(10):
        j_index = S.find(str(j), i_index+1)
        if j_index == -1:
            continue
        for k in range(10):
            k_index = S.find(str(k), j_index+1)
            if k_index == -1:
                continue
            ans.add("{}{}{}".format(i, j, k))

print(len(ans))

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

ans = 0

for i in range(10):
    if str(i) not in S:
        continue
    ind_i = S.index(str(i))
    for j in range(10):
        if str(j) not in S[ind_i+1:]:
            continue
        ind_j = S[ind_i+1:].index(str(j)) + ind_i+1
        for k in range(10):
            if str(k) in S[ind_j+1:]:
                ans += 1

print(ans)

Solution (Python):


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










ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    first = S.find(key[0])
    if first == -1 or first == N:
        continue
    second = S[first + 1:].find(key[1])
    if second == -1 or (first + second + 2) == N:
        continue
    third = S[first + second + 2:].find(key[2])
    if not third == -1:
        
        ans += 1
print(ans)

Solution (Python):


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










ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    first = S.find(key[0])
    if first == -1 or first == N:
        continue
    second = S[first + 1:].find(key[1])
    if second == -1 or (first + second + 2) == N:
        continue
    third = S[first + second + 2:].find(key[2])
    if not third == -1:
        
        ans += 1
print(ans)

Solution (Python):
import itertools

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

ans = 0


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

Solution (Python):
def test(original: list, nums: str, index: int,
         remain_count: int, results: set, results_1, results_2):
    
    if len(nums) == 1:
        if nums in results_1:
            return
        results_1.add(nums)
    if len(nums) == 2:
        if nums in results_2:
            return
        results_2.add(nums)
    if len(nums) == 3:
        
        results.add(nums)
        return
    
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        test(
            original,
            nums + original[i],
            i + 1,
            remain_count,
            results,
            results_1,
            results_2)

    
    


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

results = set()
results_1 = set()
results_2 = set()




test(S, "", 0, N - 3, results, results_1, results_2)

print(len(results))

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

result = 0

for i in range(1000):
    if i < 10:
        temp = "00" + str(i)
    elif i < 100:
        temp = "0" + str(i)
    else:
        temp = str(i)

    cur = 0
    for j in range(3):
        if temp[j] in S[cur:]:
            cur += S[cur:].index(temp[j]) + 1
            if j == 2:
                result += 1
        else:
            break

print(result)

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

    set1 = set()
    set2 = set()
    set3 = set()
    for x in s:
        for x2 in set2:
            _x2 = x2+x
            set3.add(_x2)
        for x1 in set1:
            _x1 = x1+x
            set2.add(_x1)
        set1.add(x)

    print(len(set3))


main()

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

    set1 = set()
    set2 = set()
    set3 = set()
    for x in s:
        for x2 in set2:
            _x2 = x2+x
            if x2+x not in set3:
                set3.add(_x2)
        for x1 in set1:
            _x1 = x1+x
            if x1+x not in set2:
                set2.add(_x1)
        if x not in set1:
            set1.add(x)

    print(len(set3))


main()

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

for i in range(10):
    if str(i) in S:
        p = S.index(str(i))
        Si = S[p+1 :]
        for j in range(10):
            if str(j) in Si:
                q = Si.index(str(j))
                Sj = Si[q+1 :]
                for k in range(10):
                    if str(k) in Sj:
                        ct += 1
print(ct)

Solution (Python):
n=int(input())
s=input()
ans=0
import collections
for i in range(10):
  i=str(i)
  x=s.find(i)
  st=s[x+1::]
  if x<0 or n-x<3:pass
  else:
    for j in range(10):
      j=str(j)
      y=st.find(j)
      if y<0 or len(st)-y<2:pass
      else:
        ans+=len(set(st[y+1::]))
print(ans)

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

count = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            ii = s.find(str(i))
            if ii != -1 and ii <= n-3 and str(j) in s[ii+1:]:
                ji = s.find(str(j), ii+1)
                if ji != -1 and ji <= n-2 and str(k) in s[ji+1:]:
                    count += 1

print(count)

Solution (Python):
N = int(input())
n = input()
cnt = 0
for i in range(1000):
    i = str(i).zfill(3)
    first = n.find(i[0])
    if first > -1:
        second = n[first+1 :].find(i[1]) + first + 1
        if n[first+1 :].find(i[1]) > -1:
            if len(n) >= second + 1:
                third = n[second+1 :].find(i[2]) + second + 1
                if n[second + 1 :].find(i[2]) > -1:
                    cnt += 1
    first, second, third = 0,0,0
print(cnt)

Solution (Python):
import itertools
from sys import stdin

N = list(map(int, stdin.readline().strip().split()))[0]
st = list(stdin.readline().strip())
count = 0
stt = set(st)
stt = list(stt)
num = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
num = [s for s in num if s in stt]
num_list = ["".join(i) for i in itertools.product(num, repeat=3)]
cnt = 0
for number in num_list:

    for i in range(N):
        if number[cnt] == st[i]:
            cnt += 1
            if cnt==2:
                if number[cnt] in st[i+1:]:
                    count+=1
                break
    cnt = 0

print(count)

Solution (Python):
def main():
  N = int(input())
  S = list(map(int,input()))
  ans = 0
  for i in range(10):
    for j in range(10):
      for k in range(10):
        flg = False
        flg2 = False
        for x in range(N):
          if flg2:
            break
          if not flg:
            if S[x] == i:
              flg = True
          else:
            if S[x] == j:
              flg2 = True
              if k in S[x+1:]:
                ans +=1
  print(ans)
main()

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()
memo_1 = set()
memo_2 = set()
memo_3 = set()

for i in range(N):
    for ii in memo_2:
        memo_3.add(ii + S[i])
    for j in memo_1:
        memo_2.add(j + S[i])
    memo_1.add(S[i])





print(len(memo_3))

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

count = 0

s_set = set([])
for i in range(n):
    t_set = set([])
    if (s[i] in s_set):
        continue
    t = s[i+1:]
    s_set.add(s[i])
    for j in range(n-(i+1)):
        if(t[j] in t_set):
            continue
        u = t[j+1:]
        count += len(set(u))
        t_set.add(t[j])
    
    
print(count)

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



cnt = 0
s_flgs = [[False for _ in range(10) ] for _ in range(3)]

for i1 in range(N-2):
    if s_flgs[0][int(S[i1])] == True:
        continue
    s_flgs[0][int(S[i1])] = True
    s_flgs[1] = [False for _ in range(10) ]
    for i2 in range(i1+1,N-1):
        if s_flgs[1][int(S[i2])] == True:
            continue
        s_flgs[1][int(S[i2])] = True
        s_flgs[2] = [False for _ in range(10) ]
        for i3 in range(i2+1, N):
            if s_flgs[2][int(S[i3])] == True:
                continue
            s_flgs[2][int(S[i3])] = True
            cnt = cnt + 1
            
            

print(cnt)

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

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

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

Solution (Python):
n=int(input())
s=input()
l=[[]for i in range(11)]
for i in range(n):
    d=int(s[i])
    l[d].append(i)
ans=0
le=[len(f) for f in l]
from bisect import bisect_left as bl,bisect_right as br
for i in range(0,1000):
    ss=str(i).zfill(3)

    now=-1
    for x in ss:
        c=br(l[int(x)],now)
        if c==le[int(x)]:break
        now=l[int(x)][c]
    else:

        ans+=1
print(ans)

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

count = 0
for i in range(1000):
    a = str(i)
    a = list(a.zfill(3))
    sw = 0
    for j in range(len(s)):
        if sw == 0:
            if a[0] == s[j]:
                sw = 1
        elif sw == 1:
            if a[1] == s[j]:
                sw = 2
        elif sw == 2:
            if a[2] == s[j]:
                count += 1
                break
print(count)

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

s1 = set()  
s2 = set()  
s3 = set()  


for c in S:
  for c2 in s2:
    s3.add(c2 + c)
  for c1 in s1:
    s2.add(c1 + c)
  s1.add(c)
  
print(len(s3))

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

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    s = list(input())
    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                pin = str(i) + str(j) + str(k)
                t = 0
                for x in s:
                    if pin[t] == x:
                        t += 1
                    if t == 3:
                        ans += 1
                        break
    print(ans)

Solution (Python):
import re
n=int(input())
s=input()
ans=0
for i in range(1000):
      a='00'+str(i)
      a=a[-3:]
      s0=s
      m=s0.find(a[0])
      if m<0:
            continue
      s0=s0[m+1:]
      m=s0.find(a[1])
      if m<0:
            continue
      s0=s0[m+1:]
      m=s0.find(a[2])
      if m<0:
            continue
      ans+=1
print(ans)

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

for i in range(10):
  if str(i) in S:
    p = S.index(str(i))
    S2 = S[p + 1:]
    for j in range(10):
      if str(j) in S2:
        q = S2.index(str(j))
        S3 = S2[q + 1:]
        for k in range(10):
          if str(k) in S3:
            con += 1

print(con)

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

lmemo=[-1]*10
rmemo=[-1]*10
for i in range(N-2):
    ls=int(S[i])
    rs=int(S[-(i+1)])
    if lmemo[ls]==-1:
        lmemo[ls]=i
    if rmemo[rs]==-1:
        rmemo[rs]=N-(i+1)
ans=0

for l in lmemo:
    for r in rmemo:
        if l+1<r and l>=0 and r>=0:
            ans+=len(set(S[l+1:r]))


print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    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:
                    index_i=s.index(str(i))
                    s1=s[index_i+1:]
                    if str(j) in s1:
                        index_j=s1.index(str(j))
                        s2=s1[index_j+1:]
                        if str(k) in s2:
                            ans+=1
    print(ans)

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    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:
                    index_i=s.index(str(i))
                    s1=s[index_i+1:]
                    if str(j) in s1:
                        index_j=s1.index(str(j))
                        s2=s1[index_j+1:]
                        if str(k) in s2:
                            ans+=1
    print(ans)

if __name__=='__main__':
    main()

Solution (Python):


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

    lst = [[] for _ in range(10)]
    numset = set()

    for i in range(n):
        num = int(s[i])
        lst[num].append(i)

    cnt = 0
    for i in range(10):
        if lst[i] == []:
            continue
        for k in range(10):
            if lst[k] == []:
                continue
            p_min = lst[i][0]
            p_max = lst[k][-1]
            if p_max - p_min <= 1:
                continue
            for j in range(10):
                for p in lst[j]:
                    if p_min < p < p_max:
                        cnt += 1
                        break
                    elif p >= p_max:
                        break

    print(cnt)


if __name__ == '__main__':
    main()

Solution (Python):

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

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            num = str(i) + str(j) + str(k)
            t = 0
            p = 0
            while t < 3 and p < n:
                if num[t] == s[p]:
                    t += 1
                p += 1
            if t == 3:
                ans += 1
print(ans)

Solution (Python):
n = int(input())
s = list(map(int,input()))
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            a,b,c = -1,-1,-1
            for l in range(n):
                if s[l] == i:
                    a = l
                    break
            for l in range(a+1,n):
                if s[l] == j:
                    b = l
                    break
            for l in range(b+1,n):
                if s[l] == k:
                    c = l
                    break
            if a == -1 or b == -1 or c == -1: pass
            else: ans += 1
print(ans)

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

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

c = 0

for i in a:
	for j in a:
		for k in a:
			d = s.find(i)
			if d == -1:
				continue
			e = s[d+1:].find(j)
			if e == -1:
				continue
			e += d+1
			f = s[e+1:].find(k)
			if f == -1:
				continue
			c += 1
print (c)

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

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

print(ans)

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

Solution (Python):


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

    """
    3桁の数字がijkだとして、それを作れるかを全探索で数えていく
    平均計算量は、(3750*10)*(7500*10)*(15000*10) = O(10**4 * 10**4 * 10**5) = O(10**13)
    """

    ans = 0
    for i in range(0, 10):
        idx = S.find(str(i))  
        if idx == -1:
            continue
        for j in range(0, 10):
            jdx = S[idx+1:].find(str(j))  
            if jdx == -1:
                continue
            for k in range(0, 10):
                if str(k) in S[idx+1+jdx+1:]:  
                    ans += 1

    print(ans)


if __name__ == "__main__":
    solve()

Solution (Python):
def check(num, N): 
    length = len(N)

    get_target = 0
    for i in range(length):
        if get_target == 0 and N[i] == num[0]:
            get_target = 1
            
        elif get_target == 1 and N[i] == num[1]:
            get_target = 2
            
        elif get_target == 2 and N[i] == num[2]:
            get_target = 3
            
    
    if get_target == 3:
        
        return 1
    else:
        return 0


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

counter = 0
for i in range(1000):
    str_i = str(i)
    while len(str_i) <3:
        str_i = "0" + str_i
    
    counter += check(str_i, S)
print(counter)

Solution (Python):
n=int(input())
s=input()
num=[]
for i in range(1000):
    p=str(i)
    while len(p)<3:
        p="".join(["0",p])
    num.append(p)
ans=0
for k in range(len(num)):
    q=0
    for i in range(len(s)):
        if q==3:
            break
        elif num[k][q]==s[i]:
            q+=1
    if q==3:
        ans+=1
print(ans)

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

candidates_l = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            candidates_l.append([i,j,k])

ans = 0
for c in candidates_l:
    if c[0] in s_l:
        tmp1 = s_l.index(c[0])
        if c[1] in s_l[tmp1+1:]:
            tmp2 = s_l[tmp1+1:].index(c[1])
            if c[2] in s_l[tmp1+tmp2+2:]:
                ans += 1

print(ans)

Solution (Python):
n = [int(i) for i in input().split()]
s = input()
a = set([""])
ans = set()
for i in s:
    b = a.copy()
    for j in a:
        if len(j) == 2:
            ans.add(j + i)
        else:
            b.add(j + i)
    a = b
print(len(ans))

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

def my_index(l, x, default=-1):
    if x in l:
        return l.index(x)
    else:
        return default

for i in range(10):
    indexi = my_index(s, str(i))
    if indexi >= 0:
        for j in range(10):
            indexj = my_index(s[indexi + 1:], str(j))
            if indexj >= 0:
                for k in range(10):
                    indexk = my_index(s[indexi + indexj + 2:], str(k))
                    if indexk >= 0:
                        cnt += 1
print(cnt)

Solution (Python):

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


def check(s, i, j, k):
    ii = 0
    jj = 0
    for l in range(len(s)):
        if ii == 1:
            if jj == 1:
                if s[l] == str(k):
                    return 1
            elif s[l] == str(j):
                jj = 1
        elif s[l] == str(i):
            ii = 1
    return 0


sum = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            sum += check(s, i, j, k)


print(sum)

Solution (Python):

'''
重複考えないとどうなるか
-> 単に nC3 個( N 個から 3 つ選び出す順列と同じ)
というところまで考えたが、結局わからず解説AC
重複を考えるとかなり厳しいので重複がないものに着目する。
（今回であれば 000~999 までのパスワード）
発想の転換が凄い。これ思いつくの天才だろ…。
'''
N = int(input())
S = input()
cnt = 0
for i in range(1000):
    C = [str(i//100), str(i//10%10), str(i%10)]
    f = 0
    for s in S:
        if s == C[f]:
            f += 1
        if f == 3:
           break
    if f == 3:
        cnt += 1
    if cnt ==1000:
        break
print(cnt)

Solution (Python):
N = int(input())
S = input()
  
ans = 0
for i1 in range(10):
  for i2 in range(10):
    for i3 in range(10):
      p = 1
      for f in range(N):
        if(p == 1 and S[f] == str(i1)):
          p = 2
        elif(p == 2 and S[f] == str(i2)):
          p = 3
        elif(p == 3 and S[f] == str(i3)):
          ans += 1
          break
        
print(ans)