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

def chk_substr(s, t):
    p = -1
    for i in t:
        p = s.find(i, p + 1)
        if p == -1:
            return False
    return True

ans = 0
for i in range(1000):
    t = str(i).zfill(3)
    if chk_substr(s, t):
        ans += 1
print(ans)

Solution (Python):
n = int(input())
s = list(map(int, list(input())))
idx = [[] for _ in range(10)]
for i, v in enumerate(s):
    idx[v].append(i)

ans = 0
for i in range(1000):
    c = 0
    p = -1
    chk = True
    while c < 3 and chk:
        chk = False
        for j in idx[i // 100]:
            if j > p:
                c += 1
                p = j
                chk = True
                i = i % 100 * 10
                break
    if c == 3:
        ans += 1
print(ans)

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

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            x = S.find(str(i))
            y = S.find(str(j), x + 1)
            z = S.find(str(k), y + 1)

            if -1 < x < y < z:
                res += 1

print(res)

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

Solution (Python):
N=int(input())
S=input()
s=[int(c) for c in(S)]
a=0
for i in range(10):
  flag1=-1
  f1=0
  for p in range(N):
    if flag1==-1 and s[p]==i:
      flag1=p
      f1=1
      break
  for j in range(10):
    flag2=0
    f2=0
    for q in range(flag1+1,N):
      if f1==0:
        break
      if flag2==0 and s[q]==j:
        flag2=q
        f2=1
        break
    for h in range(10):
      for r in range(flag2+1,N):
        if f2==0:
          break
        if s[r]==h:
          if f1*f2!=0:
            a+=1
          break
print(a)

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

n = int(input().replace("\n",""))
s = input().replace("\n","")

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

Solution (Python):
import sys


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


def main():
    N = int(input())
    S = list(input())
    ans = 0

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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import math
def split(word):
    return [int(char) for char in word]

input1 = int(input())
input2 = split(str(input()))
def indexEverything(input2):
    whereDict = dict()
    for index in range(len(input2)):
        try:
            whereDict[input2[index]].append(index)
        except:
            whereDict[input2[index]] = [index]
    return whereDict

def doesCodeExist(n, whereDict):
    
    
    
    try:
        firstLoc = whereDict[int(n[0])][0]
    except:
        
        return False
    
    found2 = False
    counter2 = 0
    
    while not found2:
        
        try:
            
            
            if (whereDict[int(n[1])][counter2] > firstLoc):
                secondLoc = whereDict[int(n[1])][counter2]
                
                
                found2 = True
            
            counter2 += 1

            
        except:
            return False
    
    found3 = False
    counter3 = 0
    while not found3:
        try:
            if (whereDict[int(n[2])][counter3] > secondLoc):
                
                return True
            counter3 += 1
            
        except:
            return False

whereDict = indexEverything(input2)
counter = 0



for index in range(0, 1000):
    if (index < 100):
        if (index < 10):
            index = "00" + str(index)
        else:
            index = "0" + str(index)
    if (doesCodeExist(split(str(index)), whereDict)):
        
        counter += 1
print(counter)

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

    ans = 0
    for i in range(1000):
        num = str(i).zfill(3)
        idx = 0
        for digit in S:
            if digit == num[idx]:
                idx += 1
            if idx == 3:
                ans += 1
                break
    
    print(ans)

if __name__ == '__main__':
    solve()

Solution (Python):
def main():
    N = int(input())
    S = input()
    
    cnt = 0
    for i in range(10):
        idx_i = S.find(str(i))
        if(idx_i == -1):
            continue
        for j in range(10):
            idx_j = S.find(str(j), idx_i+1)
            if(idx_j == -1):
                continue
            for k in range(10):
                idx_k = S.find(str(k), idx_j+1)
                if(idx_k == -1):
                    continue
                cnt += 1
    print(cnt)
main()

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

ans = 0
for i in range(1000):
    num = str(i).zfill(3)
    flag2 = True
    start = 0
    for j in range(3):
        flag = False
        for k in range(start, N):
            if(num[j] == S[k]):
                flag = True
                start = k+1
                break
        if flag == False:
            flag2 = False
            break
    if flag2:
        ans += 1

print(ans)

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(1000):
    num = str(i).zfill(3)
    flag2 = True
    start = 0
    for j in range(3):
        flag = False
        for k in range(start,N):
            if num[j] == S[k]:
                flag = True
                start = k+1
                break
        if flag == False:
            flag2 = False
            break    
    if flag2:
        ans+=1
    
print(ans)

Solution (Python):
import itertools
import collections

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

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

c = 0
for password in password_l:
    idx = 0
    ok = 0
    while idx != n:
        if s[idx] == password[ok]:
            ok += 1
        
        if ok == 3:
            c += 1
            break
        
        idx += 1

print(c)

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

ans = 0
for num in nums:
    index = 0
    for s in S:
        if s==num[index]:
            index+=1
        if index==3:
            ans+=1
            break
print(ans)

Solution (Python):


def main():
    n = int(input())
    s = input()
    cnt = 0
    for i in range(10):
        ind_i = s.find(str(i))    
        if ind_i == -1:
            continue
        for j in range(10):
            ind_j = s.find(str(j), ind_i+1)
            if ind_j == -1:
                continue
            for k in range(10):
                ind_k = s.find(str(k), ind_j+1)   
                if ind_k == -1:
                    continue
                cnt += 1
    print(cnt) 
main()

Solution (Python):
n = int(input())
s = input()
ans =0
for i in range(10):
    if str(i) in s:
        t = s[s.index(str(i))+1:]
        for j in range(10):
            if str(j) in t:
                u = t[t.index(str(j))+1:]
                for k in range(10):
                    if str(k) in u:
                        ans += 1
print(ans)

Solution (Python):

n = int(input())
s = input()
ans = 0
for i in range(10):
    if str(i) in s:
        t = s[s.index(str(i))+1:]
        for j in range(10):
            if str(j) in t:
                u = t[t.index(str(j))+1:]
                for k in range(10):
                    if str(k) in u:
                        ans +=1
print(ans)

Solution (Python):
def f(s,l=3):
  if l==1:
    return len(set(s))
  a=0
  for i in set(s):
    a+=f(s[s.index(i)+1:],l-1)
  return a

n=int(input())
s=input()
print(f(s))

Solution (Python):
int(input())
n=input()
answer=0
for i in range(10):
    if str(i) in n:
        T=n[n.index(str(i))+1:]
        for j in range(10):
            if str(j) in T:
                U=T[T.index(str(j))+1:]
                for k in range(10):
                    if str(k) in U:
                        answer+=1
print(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):
            flag = 0
            for c in s:
                p = flag == 0 and c == str(i)
                q = flag == 1 and c == str(j)
                r = flag == 2 and c == str(k)
                if p or q or r:
                    flag += 1
            if flag == 3:
                ans += 1
print(ans)

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 = cnt+1
print(cnt)

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

for i in range(1000):
	t = str(i).zfill(3)
	t_idx = 0
	for s_idx in range(n):
		if s[s_idx] == t[t_idx]:
			t_idx += 1
			if t_idx == 3:
				break
	if t_idx == 3:
		cnt += 1

print(cnt)

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

d = [[] for _ in range(10)]
for i in range(n):
    d[int(s[i])].append(i)

def lower_bound(al,k):
    if len(al)==0:
        return -1
    ng = -1
    ok = len(al)
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if al[mid]>k:
            ok = mid
        else:
            ng = mid
    if ok==len(al):
        return -1
    return ok

def check(pl):
    pos = -1
    res = []
    for i in range(3):
        pos = lower_bound(d[pl[i]], pos)
        if pos<0:
            return False
        pos = d[pl[i]][pos]
        res.append(pos)
    return True

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if check([i,j,k]):
                res += 1

print(res)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = input()
ans = 0
for l in range(10):
    for i in range(n):
        if int(s[i]) == l:
            break
    else:
        continue
    for r in range(10):
        for j in range(i+1,n):
            if int(s[j]) == r:
                break
        else:
            continue
        num = [True]*10
        for k in range(j+1,n):
            if num[int(s[k])]:
                ans += 1
                num[int(s[k])] = False
print(ans)

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

def judge(A,B,C):
    s = S
    a = s.find(A)
    if a < 0:
        return False

    s = s[a+1:]
    b = s.find(B)
    if b < 0:
        return False

    s = s[b+1:]
    c = s.find(C)
    if c < 0:
        return False
    return True

l = '0123456789'
print(sum([int(bool(judge(a,b,c))) for a in l for b in l for c in l]))

Solution (Python):
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    S = readline().strip()

    ans = 0
    for p in range(1000):
        pattern = str(p).zfill(3)
        cnt = 0
        T = S
        for n in pattern:
            i = T.find(n)
            if i != -1:
                T = T[i+1:]
                cnt += 1
        if cnt == 3:
            ans += 1
    
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import math,time
N = int(input())
S = input()

ans = 0
for i in range(1000):
    locknum = str(i).zfill(3)
    a = S.find(locknum[0])
    b = S.find(locknum[1],a+1)
    c = S.find(locknum[2],b+1)
    if a!=-1 and b!=-1 and c!=-1:
        
        ans +=1


             
print(ans)

Solution (Python):
n = int(input())
s = input()
ans=[set(),set(),set()]
for i in s:
  for l in ans[1]:
      ans[2].add(l+i)
  for j in ans[0]:
        ans[1].add(j+i)
  ans[0].add(i)
print(len(ans[2]))

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
s = input()
ans = 0
for i in range(1000):
  chk = str(i).zfill(3)
  a = s.find(chk[0])
  b = s.find(chk[1],a+1)
  c = s.find(chk[2],b+1)
  if a!=-1 and b!=-1 and c!=-1:
    ans += 1
print(ans)

Solution (Python):
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    S = readline().strip()

    ans = 0
    for p in range(1000):
        pattern = str(p).zfill(3)
        key = 0
        cnt = 0
        for n in pattern:
            for i in range(key,N):
                if S[i] == n:
                    key = i+1
                    cnt += 1
                    break
        if cnt == 3:
            ans += 1
    
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
s = input()
def multi_index(l,x):
  return tuple([i for i,_x in enumerate(l) if _x == x])

ans = 0
for i in range(10):
  e = 0
  if str(i) in s:
    c = multi_index(s,str(i))[0]
    for j in range(10):
      if str(j) in s and i!=j and c<=len(s)-2:
        for q in range(c+1,len(s)-1):
          if str(j) == s[q]:
            d = q
            break
        else:
          d = -1
      elif str(j) in s and i==j and len(multi_index(s,str(i)))>=2:
        d = multi_index(s,str(i))[1]
      else:
        d = -1
      if d > c:
        for l in range(10):
          if str(l) in s and i!=j and j!=l and i!=l:
            e = multi_index(s,str(l))[-1]
            if e > d:
              ans += 1
          if str(l) in s and i!=j and j==l:
            e = multi_index(s,str(l))[-1]
            if e > d:
              ans += 1
          if str(l) in s and i==j and j!=l:
            e = multi_index(s,str(l))[-1]
            if e > d:
              ans += 1
          if str(l) in s and i==j and j==l:
            e = multi_index(s,str(l))[-1]
            if e > d:
              ans += 1
          if str(l) in s and i==l and j!=l:
            e = multi_index(s,str(l))[-1]
            if e > d:
              ans += 1
print(ans)

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

alr_1 = []
ans = []
for i in range(N-2):
    if not S[i] in alr_1:
        start_1 = S[i]
        alr_1.append(start_1)
        alr_2 = []
        for j in range(i+1, N-1):
            if not S[j] in alr_2:
                start_2 = S[j]
                alr_2.append(start_2)
                alr_3 = []
                for k in range(j+1, N):
                    if not S[k] in alr_3:
                        goal = S[k]
                        ans.append([start_1, start_2, goal])
                        alr_3.append(goal)
print(len(ans))

Solution (Python):
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
import time
from bisect import bisect_left, insort_left, bisect_right
import sys
import random
import itertools

input = sys.stdin.readline
_NUMINT_ALL = list(range(10))
_START_TIME = time.time()


def main():
    ans = solve()

    if ans is True or ans is False:
        YesNo(ans)
    elif ans is not None:
        print(ans)


def solve():

    _ = iip()
    S = input()

    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                n = 0

                for s in S:
                    if n == 0 and str(i) == s:
                        n =1
                    elif n == 1 and str(j) == s:
                        n = 2
                    elif n == 2 and str(k) == s:
                        ans += 1
                        break

    print(ans)








def kiriage_warizan(a, b):
    return -(-a//b)


def iip(listed=True):  
    d = input().rstrip("\n").split()
    try:
        ret = [int(i) for i in d]
    except:
        ret = [int(i) if i in _NUMINT_ALL else i for i in d]
        if len(ret) == 1 and listed is False:
            return ret[0]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iipt(l, listed=True, num_only=True):  
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed))
    return ret


def saidai_kouyakusuu(A):  
    l = len(A)
    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m

def time_debug_10percent():
    a = random.randint(0, 9)
    if a == 9:
        sys.exit()

def time_debug(t):
    time.sleep(_START_TIME + t - time.time())
    sys.exit()


def make_graph_edge_flat(N):  
    ret = []
    for i in range(N-1):
        a, b, c = iip()
        a -= 1
        b -= 1
        ret[a].append((b, c))
        ret[b].append((a, c))
    return ret


def sort_tuples(l, index):  
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  
    if index >= len(l):                      
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def sortstr(s):  
    return "".join(sorted(s))


def iip_ord(startcode="a"):  
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  
    for i in s:
        print(i)


def bitall(N):  
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        
        pass
    return ret


def inv(n, mod):  
    return power(n, mod - 2)


def power(n, p, mod_=mod):  
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


def nibutan_func(func, target, left, right, side="left"): 
    l = left
    r = right
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if func(x) == target:
            return x
        elif func(x) > target:
            r = x
        else:
            l = x

    if side == "left" or func(x) == target:
        return l
    else:
        return r


def nibutan_list(list_, target, side="left"):  
    if not isinstance(list_, list):
        list_ = list(list_)

    l = 0
    r = len(list_)
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if list_[x] == target:
            return x
        elif list_[x] > target:
            r = x
        else:
            l = x

    if side == "left" or list_[x] == target:
        return l
    else:
        return r


class UfTree():
    def __init__(self, maxnum):
        self.parent = list(range(maxnum))
        self._size = [1] * maxnum
        self.rank = [0] * maxnum

    def size(self, a):
        return self._size[self.root(a)]

    def root(self, a):
        rank = 0
        cur = a
        while True:
            if self.parent[cur] == cur:
                
                
                return cur
            else:
                self.parent[cur] = self.parent[self.parent[cur]]
                cur = self.parent[cur]
                rank += 1

    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb:
            return self

        self._size[ra] += self._size[rb]
        self.parent[rb] = ra
        return self

if __name__ == "__main__":
    main()

Solution (Python):
import itertools
import bisect
N=int(input())
S=input()
l=[[] for i in range(10)]
for i in range(N):
    l[int(S[i])].append(i)
cnt=0
for x in itertools.product(list(range(10)),repeat=3):
    if(not l[x[0]] or not l[x[1]] or not l[x[2]]):
        continue
    zero=l[x[0]][0]
    t=bisect.bisect_left(l[x[1]],zero+1)
    if(t>=len(l[x[1]])):
        continue
    one=l[x[1]][t]
    m=bisect.bisect_left(l[x[2]],one+1)
    if(m>=len(l[x[2]])):
        continue
    cnt+=1
print(cnt)

Solution (Python):
import itertools
N=int(input())
S=input()
cnt=0
for x in itertools.product(list(range(10)),repeat=3):
    li=list(x)
    zero=S.find(str(li[0]))
    one=S.find(str(li[1]),zero+1)
    two=S.find(str(li[2]),one+1)
    if(not(zero==-1 or one==-1 or two==-1)):
        cnt+=1
print(cnt)

Solution (Python):
N = int(input())
S = [s for s in input()]
lis = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
ans = 0
from collections import defaultdict
d = defaultdict(list)
for i,s in enumerate(S):
    d[s].append(i)

for s in lis:
    if d[s[0]]:
        i = min(d[s[0]])
        if d[s[1]]:
            for j in d[s[1]]:
                if j > i:
                    if d[s[2]]:
                        if max(d[s[2]]) > j:
                            ans += 1
                            break
                    break
        else:continue
    else:continue
                            
print(ans)

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

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(1000):
    pw = str(i).zfill(3)
    ok1 = False
    ok2 = False
    ok3 = False
    for j in range(N):
        if S[j] == pw[0] and not ok1:
            ok1 = True
            continue
        if ok1 and not ok2:
            if S[j] == pw[1]:
                ok2 = True
                continue
        if ok2:
            if S[j] == pw[2]:
                ok3 = True
                
                break
    if ok3:
        ans += 1

print(ans)

Solution (Python):
import math,time
N = int(input())
S = input()

ans = 0
t1 = time.time()
for i in range(1000):
    locknum = str(i).zfill(3)
    a = S.find(locknum[0])
    b = S.find(locknum[1],a+1)
    c = S.find(locknum[2],b+1)
    if a!=-1 and b!=-1 and c!=-1:
        
        ans +=1

t2 = time.time()

print(ans)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1000):
    x = str(i)
    if len(x) == 1: x = '0'*2+x
    elif len(x) == 2:x = '0'+x
    res = 0
    mae = -1
    for e in x:
        for i in range(n):
            if s[i] == e and i > mae:
                res+=1
                mae = i
                break
    if res == 3:
        ans+=1
        
print(ans)

Solution (Python):
N=int(input())
S=input()
Nd=[[] for i in range(10)]
Ns=[0 for i in range(10)]
Nl=[-1 for i in range(10)]
Nr=[-1 for i in range(10)]
for i,s in enumerate(S):
  if Ns[int(s)]==0:
    Nl[int(s)]=i
  
  Ns[int(s)]+=1
  Nr[int(s)]=i
  for j in range(10):
    Nd[j].append(Ns[j])



    
ans=0    
for i in range(10):
  if Nl[i]==-1:
    continue
  for j in range(10):
    if Nl[j]==-1:
      continue
    for k in range(10):
      if Nl[k]==-1:
        continue
      a=Nl[i]
      c=Nr[k]
      if Nd[j][max(c-1,0)]-Nd[j][a]>0:
        ans+=1
print(ans)

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

res = 0
for i in range(1000):
    one = str(i//100)
    two = str(i%100//10)
    three = str(i%10)
    
    flg1 = False
    flg2 = False
    flg3 = False
    
    ptr = 0
    for j in range(ptr, n-2):
        if(s[j] == one):
            flg1 = True
            ptr = j+1
            break
    
    for j in range(ptr, n-1):
        if(s[j] == two):
            flg2 = True
            ptr = j+1
            break
    
    for j in range(ptr, n):
        if(s[j] == three):
            flg3 = True
            break
    
    if(flg1 and flg2 and flg3): res += 1

print(res)

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

td = [[[0 for i in range(10)] for j in range(10)]  for j in range(10)]
sd = [[0 for i in range(10)] for i in range(10)]
fd = [0 for i in range(10)]

for i in range(N):
  s = int(S[i])
  
  for q in range(10):
    for r in range(10):
      if sd[q][r] == 1:
        td[q][r][s] = 1
  
  for p in range(10):
    if fd[p] == 1:
      sd[p][s] = 1           
  
  if fd[s] == 0:
    fd[s] = 1

 

c = 0
for i in range(10):
  for j in range(10):
    c += td[i][j].count(1)  
print(c)

Solution (Python):
import collections

N = int(input())
S = [int(i) for i in list(input())]

count = 0
for i in range(10):
    for num,j in enumerate(S):
        if j == i:
            T = S[num+1::]
            for k in list(set(T)):
                for num2, l in enumerate(T):
                    if k == l:
                        U = T[num2+1::]
                        count += len(set(U))
                        break
            
            break
            
print(count)

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

result_dic = {}

before_words = {i:0 for i in range(10)}
after_words = {i:0 for i in range(10)}
for s in S:
    after_words[int(s)] += 1

for  i, s in enumerate(S[:-1]):
    if i == 0:
        before_words[int(s)] += 1
        after_words[int(s)] -= 1
        continue
    after_words[int(s)] -= 1

    before =  [x for x, y in before_words.items() if y > 0]
    after =  [x for x, y in after_words.items() if y > 0]
    for b in before:
        for a in after:
            result_dic[str(b) + s + str(a)] = 1

    before_words[int(s)] += 1

print(len(result_dic))

Solution (Python):




N = int(input())
*S, = map(int, input())




dp = [[-1]*10 for _ in [0]*(N+1)]
for i, s in enumerate(S):
    for j in range(10):
        dp[i+1][j] = dp[i][j]
    dp[i+1][s] = i

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

    ci = dp[N][c]
    if ci != -1:
        bi = dp[ci][b]
        if bi != -1:
            ai = dp[bi][a]
            if ai != -1:
                cnt += 1

print(cnt)

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

cnt = 0
for i in range(1000):
    
    t = str(i)
    u = '0'*(3-len(t))+t
    
    j = 0
    p = u[0]
    for x in s:
        if x == p:
            j += 1
            if j == 3:
                cnt += 1
                break
            p = u[j]
            
print(cnt)

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

ans=0
for i in range(1000):
  t=str(i)
  u="0"*(3-len(t))+t
  j=0
  p=u[0]
  for x in s:
    if x==p:
      j+=1
      if j==3:
        ans+=1
        break
      p=u[j]
    
print(ans)

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

ans=0
for i in range(1000):
  t=str(i)
  u="0"*(3-len(t))+t
  j=0
  exi=0
  p=u[0]
  for x in s:
    if x==p:
      j+=1
      if j==3:
        ans+=1
        break
      p=u[j]
    
print(ans)

Solution (Python):
n=int(input())
s=input()
list=["" for _ in range(1000)]
ans=0
for i in range(1000):
  t=str(i)
  u="0"*(3-len(t))+t
  j=0
  exi=0
  p=u[0]
  for x in s:
    if x==p:
      j+=1
      if j==3:
        ans+=1
        break
      p=u[j]
    
print(ans)

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

candidates = set([""])
keys = set()

for s in S:
    new_candidate = set()
    for cand in candidates:
        new = cand + s
        if len(new) == 3:
            keys.add(new)
        else:
            new_candidate.add(new)
    candidates = candidates.union(new_candidate)

print(len(keys))

Solution (Python):


n = int(input())
s = list(input())
s = [int(i) for i in s]


def is_valid(s, pin):
    i, j, k = pin
    s_tmp = s[:]
    if i not in s_tmp:
        return False
    i_idx = s_tmp.index(i)
    s_tmp = s_tmp[i_idx + 1:]
    if j not in s_tmp:
        return False
    j_idx = s_tmp.index(j)
    s_tmp = s_tmp[j_idx + 1:]
    if k not in s_tmp:
        return False
    return True


num = 10
res = 0
for i in range(num):
    for j in range(num):
        for k in range(num):
            pin = [i, j, k]
            if is_valid(s, pin):
                
                res += 1

print(res)

Solution (Python):
N = int(input())
S = input()
ans = set()
for first in range(10):
    for second in range(10):
        f_flag = False
        s_flag = False
        for i in S:
            if f_flag is False:
                if int(i) == first:
                    f_flag = True
            elif s_flag is False:
                if int(i) == second:
                    s_flag = True
            else:
                ans.add(str(first)+str(second)+i)

print(len(ans))

Solution (Python):
N = int(input())
S = input()
ans = set()
for first in range(10):
    for second in range(10):
        f_flag = False
        s_flag = False
        for i in S:
            if f_flag is False:
                if int(i) == first:
                    f_flag = True
            elif s_flag is False:
                if int(i) == second:
                    s_flag = True
            else:
                ans.add(str(first)+str(second)+i)

print(len(ans))