Problem:
 Score: 400 points    Problem Statement  AtCoder Inc. has decided to lock the door of its office with a 3 -digit PIN code.  The company has an N -digit lucky number, S . Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.  How many different PIN codes can he set this way?  Both the lucky number and the PIN code may begin with a 0 .      Constraints   4 \leq N \leq 30000  S is a string of length N consisting of digits.         Input  Input is given from Standard Input in the following format:  N  S       Output  Print the number of different PIN codes Takahashi can set.        Sample Input 1 4
0224      Sample Output 1 3  Takahashi has the following options:   Erase the first digit of S and set 224 .  Erase the second digit of S and set 024 .  Erase the third digit of S and set 024 .  Erase the fourth digit of S and set 022 .   Thus, he can set three different PIN codes: 022 , 024 , and 224 .       Sample Input 2 6
123123      Sample Output 2 17       Sample Input 3 19
3141592653589793238      Sample Output 3 329

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


def main():
    sc = Scan()
    _ = sc.intarr()[0]
    S = sc.strarr()[0]

    count = 0

    for i in range(1000):
        
        lucky = format_str(i)
        first = S.find(lucky[0])
        third = S.rfind(lucky[2])

        if first == -1 or third == -1:
            continue
        elif first < third:
            if lucky[1] in S[first + 1:third]:
                count += 1
    print(count)


def format_str(num):
    if num < 10:
        return "00" + str(num)
    elif num < 100:
        return "0" + str(num)
    else:
        return str(num)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


main()

Solution (Python):
import sys
from string import digits

def main():
    n, s = sys.stdin.read().split()

    cnt = 0
    for i in digits:
        x = s.find(i)
        if x == -1:
            continue
        for j in digits:
            y = s.find(j, x + 1)
            if y == -1:
                continue
            for k in digits:
                z = s.find(k, y + 1)
                if z == -1:
                    continue
                cnt += 1

    print(cnt)

if __name__ == '__main__':
    main()

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

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            
            fi = s.find(str(i))
            if fi < 0:
                continue
            fj = s[fi+1:].find(str(j))
            if fj < 0:
                continue
            fk = s[(fi+1)+(fj+1):].find(str(k))
            if fk < 0:
                continue
            
            ans += 1
print(ans)

Solution (Python):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    S = list(input()[:-1])
    A = [str(i) for i in range(10)]

    cnt = 0
    for P in itertools.product(A, repeat=3):
        m = 0
        for s in S:
            if s==P[m]:
                m += 1
            if m==3:
                break
        if m==3:
            cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()

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

ans = set()
for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp = str(i) + str(j) + str(k)

            f = -1
            s = -1
            t = -1
            for x in range(N):
                X = S[x]
                if f == -1 and X == str(i):
                    f = x
                if s == -1 and f != -1 and f < x and X == str(j):
                    s = x
                if t == -1 and s != -1 and s < x and X == str(k):
                    t = x
            if f < s < t:
                ans.add(tmp)
print(len(ans))

Solution (Python):
n = int(input())
s = input()
c1 = [0] * 10
c2 = [0] * 100
c3 = [0] * 1000
for i in s:
  i = int(i)
  for j in range(100):
    c3[j*10+i] = c2[j]
  for j in range(10):
    c2[j*10+i] = c1[j]
  c1[i] = 1
print(sum(c3))

Solution (Python):
import sys
from string import digits

def main():
    n, s = sys.stdin.read().split()
    n = int(n)

    place = dict((i, list()) for i in digits)
    for i in range(n):
        place[s[i]].append(i)

    l = [None] * n
    l[0] = set()
    for i in range(1, n):
        l[i] = l[i-1] | set([s[i-1]])
    
    r = [None] * n
    r[n-1] = set()
    for i in range(n-2, -1, -1):
        r[i] = r[i+1] | set([s[i+1]])

    res = set()
    for j in digits:
        p = place[j]
        if not p:
            continue
        for i in digits:
            for k in digits:
                for c in p:
                    if not k in r[c]:
                        break
                    if not i in l[c]:
                        continue
                    res.add((i, j, k))
                    break
    print(len(res))

if __name__ == '__main__':
    main()

Solution (Python):


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

count = 0
candidate = ["00" + str(i) for i in range(1000)]

for i in candidate:
    first = S.find(i[-3])
    
    third = S.rfind(i[-1])
    if first==-1 or third==-1:
        continue
    elif first<third:
        if i[-2] in S[first+1:third]:
            count+=1
print(count)

Solution (Python):
import sys
from string import digits

def main():
    n, s = sys.stdin.read().split()
    n = int(n)

    place = dict((i, set()) for i in digits)
    for i in range(n):
        place[s[i]].add(i)

    l = [None] * n
    l[0] = set()
    for i in range(1, n):
        l[i] = l[i-1] | set([s[i-1]])
    
    r = [None] * n
    r[n-1] = set()
    for i in range(n-2, -1, -1):
        r[i] = r[i+1] | set([s[i+1]])

    res = set()
    for j in digits:
        for i in digits:
            for k in digits:
                for c in place[j]:
                    if not i in l[c]:
                        continue
                    if not k in r[c]:
                        continue
                    res.add((i, j, k))
                    break
    print(len(res))


if __name__ == '__main__':
    main()

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):
            preindex = 0
            flag1 = 0
            flag2 = 0
            flag3 = 0 
            while preindex < n:
                if s[preindex] == i:
                    preindex += 1
                    flag1 = 1
                    break
                preindex += 1

            while preindex < n:
                if s[preindex] == j:
                    preindex += 1
                    flag2 = 1
                    break
                preindex += 1

            while preindex < n:
                if s[preindex] == k:
                    flag3 = 1
                    break
                preindex += 1
            if flag1 and flag2 and flag3:
                ans += 1
print(ans)

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

single_flag = [False]*10
dual_flag = {}
ans = {}
for i in range(10):
    for j in range(10):
        dual_flag[(i, j)] = False
        ans[(i, j)] = set()

for s in S:
    for i in range(10):
        for j in range(10):
            if dual_flag[i, j]:
                ans[(i, j)].add(s)
    for i in range(10):
        if single_flag[i]:
            dual_flag[(i, int(s))] = True
    single_flag[int(s)] = True

tmp = 0
for v in ans.values():
    tmp += len(v)
print(tmp)

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

single_flag = [False]*10
dual_flag = {}
ans = {}
for i in range(10):
    for j in range(10):
        dual_flag[(i, j)] = False
        ans[(i, j)] = set()

for s in S:
    for i in range(10):
        for j in range(10):
            if dual_flag[i, j]:
                ans[(i, j)].add(int(s))
    for i in range(10):
        if single_flag[i]:
            dual_flag[(i, int(s))] = True
    single_flag[int(s)] = True

tmp = 0
for v in ans.values():
    tmp += len(v)
print(tmp)

Solution (Python):
import sys
from string import digits

def main():
    n, s = sys.stdin.read().split()
    n = int(n)

    place = dict((i, set()) for i in digits)
    for i in range(n):
        place[s[i]].add(i)

    l = [None] * n
    l[0] = set()
    for i in range(1, n):
        l[i] = l[i-1] | set([s[i-1]])
    
    r = [None] * n
    r[n-1] = set()
    for i in range(n-2, -1, -1):
        r[i] = r[i+1] | set([s[i+1]])

    res = set()
    for j in digits:
        for c in place[j]:
            for i in digits:
                if i in l[c]:
                    for k in digits:
                        if k in r[c]:
                            res.add((i, j, k))
    
    print(len(res))


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(1000):
  tmp=str(i)
  while len(tmp)<3:
    tmp="0"+tmp
  j=0

  for k in range(n):
    if tmp[j]==s[k]:
      j+=1
    if j==3:
      ans+=1
      break
print(ans)

Solution (Python):
n,S,r=int(input()),input(),0
dp1=[0]*n
dp2=[0]*n
d=set()
for i, c in enumerate(S):
    dp1[i] = len(d)
    d.add(c)

cs = [0 for i in range(10)]
d=set()
for i, c in enumerate(S[::-1]):
    dp2[i] = len(d)
    r += dp1[n-i-1]*(dp2[i]-dp2[cs[int(c)]])
    d.add(c)
    cs[int(c)] = i
print(r)

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

input = sys.stdin.readline


def check_num(text):
    cnt = 0
    for i in range(10):
        index = text.find(str(i))
        if index != -1:
            cnt += 1
    return cnt


def main():
    
    
    
    S = sum(str(i) for i in range(10))
    for i in range(10):
        index = S.find(str(i))
        if index != -1:
            a = check_num(S[index:])
    
    
    
    


def hoge():
    N = int(input())
    S = input().strip()
    count = 0
    for x in range(10):
        xindex = S.find(str(x))
        if xindex == -1:
            continue
        for y in range(10):
            yindex = S[xindex + 1 :].find(str(y))
            if yindex == -1:
                continue
            for z in range(10):
                zindex = S[xindex + 1 :][yindex + 1 :].find(str(z))
                if zindex == -1:
                    continue
                count += 1
    print(count)


if __name__ == "__main__":
    hoge()

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

ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      l = 0
      for c in S:
        if l == 0 and ord(c) - ord('0') == i: l += 1
        elif l == 1 and ord(c) - ord('0') == j: l += 1
        elif l == 2 and ord(c) - ord('0') == k: l += 1
      if l == 3:
        ans += 1
print(ans)

Solution (Python):
import sys
from string import digits

def main():
    n, s = sys.stdin.read().split()

    res = []
    for i in digits:
        x = s.find(i)
        if x == -1:
            continue
        for j in digits:
            y = s.find(j, x+1)
            if y == -1:
                continue
            for k in digits:
                if k in s[y+1:]:
                    res.append((i, j, k))
                    
    print(len(res))

if __name__ == '__main__':
    main()

Solution (Python):
import sys
from string import digits

def main():
    n, s = sys.stdin.read().split()

    res = []
    for i in digits:
        x = s.find(i)
        if x == -1:
            continue
        for j in digits:
            y = s.find(j, x+1)
            if y == -1:
                continue
            for k in digits:
                z = s.find(k, y+1)
                if z == -1:
                    continue
                res.append((i, j, k))

    print(len(res))

if __name__ == '__main__':
    main()

Solution (Python):
from itertools import product

n = int(input())
S = input()

numCnt = {str(i):[] for i in range(10)}
ps = [''.join(list(s)) for s in product('0123456789',repeat=3)]


for i,s in enumerate(S):
    numCnt[s].append(i)

ans = 0
for k in ps:
    if not numCnt[k[0]] or not numCnt[k[2]] or numCnt[k[0]][0] > numCnt[k[2]][-1]: 
        continue
    
    l,r = numCnt[k[0]][0], numCnt[k[2]][-1]

    for i in numCnt[k[1]]:
        if l < i < r:
            ans += 1
            break
        
print(ans)

Solution (Python):
import copy
a=int(input())
b=int(input())
w=b
d=[0]*3
count=0
c=[int(i) for i in str(b)]
for i in range(a-len(c)):
    c.insert(0,0)
for i in range(0,1000,1):
    for j in range(2,-1,-1):
        d[j]=i%10
        i=i//10
    for x in range(a-2):
        if d[0]==c[x]:
            for y in range(x+1,a-1):
                if d[1]==c[y]:
                    for z in range(y+1,a):
                        if d[2]==c[z]:
                            count+=1
                            break
                    break
            break
print(count)

Solution (Python):
import itertools

N = int(input())
S = input()
S = [int(x) for x in S]

left_index = [[-1] * (N+1) for _ in range(10)]

for i,x in enumerate(S,1):
	for j in range(10):
		left_index[j][i] = left_index[j][i-1]
	left_index[x][i] = i


answer = 0
for a,b,c in itertools.product(range(10),repeat=3):
	i = N
	bl = True
	for x in [a,b,c]:
		i = left_index[x][i] - 1
		if i < -1:
			bl = False
			break
	if bl:
		answer += 1

print(answer)

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(10):
    fp = S.find(str(i))
    if fp == -1:
        continue

    for j in range(10):
        sp = S.find(str(j), fp + 1)
        if sp == -1:
            continue

        for k in range(10):
            if str(k) in S[sp + 1:]:
                ans += 1

print(ans)

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    ls1 = [False] * 1000
    ls2 = [False] * 1000
    ls3 = [False] * 1000
    for i in range(n):
        t = [s[i]]
        if not ls1[int("".join(t))]:
            ls1[int("".join(t))] = True
            for j in range(i + 1, n):
                t = [s[i], s[j]]
                if not ls2[int("".join(t))]:
                    ls2[int("".join(t))] = True
                    for k in range(j + 1, n):
                        t = [s[i], s[j], s[k]]
                        ls3[int("".join(t))] = True
    print(ls3.count(True))


if __name__ == '__main__':
    solve()

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    ls1 = [False] * 1000
    ls2 = [False] * 1000
    ls3 = [False] * 1000
    for i in range(n):
        t = [s[i]]
        if not ls1[int("".join(t))]:
            ls1[int("".join(t))] = True
            for j in range(i + 1, n):
                t = [s[i], s[j]]
                if not ls2[int("".join(t))]:
                    ls2[int("".join(t))] = True
                    for k in range(j + 1, n):
                        t = [s[i], s[j], s[k]]
                        ls3[int("".join(t))] = True
    print(ls3.count(True))


if __name__ == '__main__':
    solve()

Solution (Python):
N = int(input())
S = [int(i) for i in input()]
ans = 0
for i in range(10):
    fp = -1
    for tf in range(N - 2):
        if S[tf] == i:
            fp = tf
            break
    if fp == -1:
        continue

    for j in range(10):
        sp = -1
        for ts in range(fp + 1, N - 1):
            if S[ts] == j:
                sp = ts
                break
        if sp == -1:
            continue

        for k in range(10):
            for tt in range(sp + 1, N):
                if S[tt] == k:

                    ans += 1
                    break

print(ans)

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    ls1 = [0] * 1000
    ls2 = [0] * 1000
    ls3 = [0] * 1000
    for i in range(n):
        t = [s[i]]
        if not ls1[int("".join(t))]:
            ls1[int("".join(t))] = True
            for j in range(i + 1, n):
                t = [s[i], s[j]]
                if not ls2[int("".join(t))]:
                    ls2[int("".join(t))] = True
                    for k in range(j + 1, n):
                        t = [s[i], s[j], s[k]]
                        ls3[int("".join(t))] = True
    print(ls3.count(True))


if __name__ == '__main__':
    solve()

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    ls1 = [0] * 1000
    ls2 = [0] * 1000
    ls3 = [0] * 1000
    for i in range(n):
        t = [s[i]]
        if not ls1[int("".join(t))]:
            ls1[int("".join(t))] = True
            for j in range(i + 1, n):
                t = [s[i], s[j]]
                if not ls2[int("".join(t))]:
                    ls2[int("".join(t))] = True
                    for k in range(j + 1, n):
                        t = [s[i], s[j], s[k]]
                        ls3[int("".join(t))] = True
    print(ls3.count(True))


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    dict1 = collections.defaultdict(int)
    dict2 = collections.defaultdict(int)
    dict3 = collections.defaultdict(int)
    for i in range(n):
        t = [s[i]]
        if "".join(t) not in dict1:
            dict1["".join(t)]
            for j in range(i + 1, n):
                t = [s[i], s[j]]
                if "".join(t) not in dict2:
                    dict2["".join(t)]
                    for k in range(j + 1, n):
                        t = [s[i], s[j], s[k]]
                        dict3["".join(t)]
    print(len(dict3))


if __name__ == '__main__':
    solve()

Solution (Python):
from collections import Counter

x=int(input())
n=str(input())




aaa=set([])
result=0
for i in range(x-2):
    a=n[i]
    if a not in aaa:
        aaa.add(a)
        bbb=set([])
        for j in range(i+1,x-1):
            b=n[j]
            if b not in bbb:
                bbb.add(b)
                ccc=set([])
                for k in range(j+1,x):
                    c=n[k]
                    if c not in ccc:
                        ccc.add(c)
                        result+=1
                    if len(ccc)==10:
                      break
                
                if len(bbb)==10:
                  break
    if len(aaa)==10:
        break
print(result)

Solution (Python):

n = int(input())
s = input()
ans = 0
for i in range(10):
    for j in range(10):
        t1 = n-1
        u1 = n-1
        for t in range(n):
            if i == int(s[t]):
                t1 = t
                break
        for u in range(t1+1,n):
            if j == int(s[u]):
                u1 = u
                break
        if int(s[t1]) == i and int(s[u1]) == j and t1<u1:
            
            ans += len(set(s[u1+1:]))
print(ans)

Solution (Python):
INF = 100000
n=int(input())
s=input()
ls = []
ls = [int(c) for c in s]
flag = [[INF for _ in range(10)]]

ls.reverse()

for i in range(n):
    flag[i][ls[i]] = n - i
    flag.append(flag[i][:])

flag.reverse()

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            keta1 = flag[0][k]
            if keta1 != INF and keta1 != n:
                keta2 = flag[keta1+1][j]
                if keta2 != INF and keta2 != n:
                    keta3 = flag[keta2+1][i]
                    if keta3 != INF:
                        res += 1

print(res)

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

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

def Check(x):
	a = [chr(x//100%10+48),chr(x//10%10+48),chr(x%10+48)]
	p = 0
	for c in s:
		if a[p] == c:
			p += 1
			if p == 3:
				return True
	return False

ans = 0
for i in range(1000):
	if Check(i):
		ans += 1
print(ans)

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

ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            for p in range(len(s)):
                if s[p]==str(i):
                    for q in range(p+1,len(s)):
                        if s[q]==str(j):
                            for r in range(q+1,len(s)):
                                if s[r]==str(k):
                                    ans+=1
                                    break
                            break
                    break

print(ans)

Solution (Python):



n = int(input())
s = input()
ans = 0

for i in range(0, 1000):
    t = format(i, "0>3")
    idx = 0
    for c in s:
        if c == t[idx]:
            idx += 1
        if idx == 3:
            ans += 1
            break

print(ans)

Solution (Python):
from collections import*
_,s=open(0)
dp=defaultdict(bool)
d1=[str(i)for i in range(10)]
d2=[str(i).zfill(2)for i in range(100)]
for c in s[:-1]:
  for i in d2:
    dp[i+c]|=dp[i]
  for i in d1:
    dp[i+c]|=dp[i]
  dp[c]=True
print(sum(dp[str(i).zfill(3)]for i in range(1000)))

Solution (Python):
import sys
import bisect
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = list(map(int, [i for i in S()]))

ID = [[] for _ in range(10)]
for i in range(N):
  ID[s[i]].append(i)

cnt = 0
for a in range(10):
  n1 = bisect.bisect_left(ID[a], 0)
  if n1 == len(ID[a]):
    continue
  for b in range(10):
    n2 = bisect.bisect_left(ID[b], ID[a][n1]+1)
    if n2 == len(ID[b]):
      continue
    for c in range(10):
      n3 = bisect.bisect_left(ID[c], ID[b][n2]+1)
      if n3 == len(ID[c]):
        continue
      cnt += 1
      
print(cnt)

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

    for i in range(10):
        s1 = S.find(str(i), 0, -2)
        if s1 == -1:
            continue
        for j in range(10):
            s2 = S.find(str(j), s1+1, -1)
            if s2 == -1:
                continue
            ans += len(set(S[s2+1:]))
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
N = int(input())
S = input()
Pin = ['{0:03d}'.format(a) for a in range(0,1000)]
cnt = 0
for i in Pin:
  S1 = S
  A1 = S1.find(i[0])
  if A1!=-1:
    S2 = S1[(A1+1):]
    A2 = S2.find(i[1])
    if A2!=-1:
      S3 = S2[(A2+1):]
      A3 = S3.find(i[2])
      if A3!=-1:
        cnt +=1
print(cnt)

Solution (Python):
N = int(input())
S = list(map(int,list(input())))
S_riv=S[::-1]
l_lis=[0]*N
r_lis=[0]*N
mat=([0 for j in range(10)])
l_set=set([])
r_set=set([])
for i,(r,l) in enumerate(zip(S_riv,S)):
  l_lis[i]=l_set.copy()
  r_lis[i]=r_set.copy()
  l_set.add(l)
  r_set.add(r)
  
r_lis.reverse()
ans=0
for i,s in enumerate(S):
  length=len(l_lis[i])
  ans+=(length-mat[s])*len(r_lis[i])
  mat[s]=length
  
print(ans)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1000):
    key = "0" * (3 - len(str(i))) + str(i)
    j = 0
    flag = True
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[0]:
            j += 1
            break
        j += 1
    if not flag:
        continue
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[1]:
            j += 1
            break
        j += 1
    if not flag:
        continue
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[2]:
            j += 1
            break
        j += 1
    if flag:
        ans += 1
print(ans)

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

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

cnt=0
for n in N:
  n0=s.find(n[0])
  if n0==-1:
    continue
  n1=s.find(n[1],n0+1)
  if n1==-1:
    continue
  n2=s.find(n[2],n1+1)
  if n2!=-1:
    cnt+=1
print(cnt)

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

def isAvailable(pw):
    for i in range(len(s)):
        if s[i] == pw[0]:
            pw = pw[1:]
            if pw == '':
                break

    if len(pw) == 0:
        return True
    else:
        return False

for i in range(10):
    for j in range(10):
        for k in range(10):
            pw = str(i) + str(j) + str(k)
            if isAvailable(pw):
                ans += 1

print(ans)

Solution (Python):
N = int(input())
S = list(map(int,list(input())))
S_riv=S[::-1]
l_lis=[0]*N
r_lis=[0]*N
mat=([0 for j in range(10)])
l_set=set([])
r_set=set([])
for i,s in enumerate(S):
  l_lis[i]=l_set.copy()
  l_set.add(s)
  
for i,s in enumerate(S_riv):
  r_lis[i]=r_set.copy()
  r_set.add(s)
  
r_lis.reverse()
ans=0
for i,s in enumerate(S):
  length=len(l_lis[i])
  ans+=(length-mat[s])*len(r_lis[i])
  mat[s]=length
  
print(ans)

Solution (Python):
N = int(input())
S = list(map(int,list(input())))
S_riv=S[::-1]
l_lis=[0]*N
r_lis=[0]*N
mat=([set([])for j in range(10)])
l_set=set([])
r_set=set([])
for i,s in enumerate(S):
  l_lis[i]=l_set.copy()
  l_set.add(s)
  
for i,s in enumerate(S_riv):
  r_lis[i]=r_set.copy()
  r_set.add(s)
  
r_lis.reverse()
ans=0
for i,s in enumerate(S):
  ans+=len(l_lis[i]-mat[s])*len(r_lis[i])
  mat[s]=l_lis[i]
  
print(ans)

Solution (Python):
N = int(input())
S = list(map(int,list(input())))
S_riv=S[::-1]
l_lis=[0]*N
r_lis=[0]*N
mat=([set([])for j in range(10)])
l_set=set([])
r_set=set([])
for i,s in enumerate(S):
  l_lis[i]=l_set.copy()
  l_set.add(s)
  
for i,s in enumerate(S_riv):
  r_lis[i]=r_set.copy()
  r_set.add(s)
  
r_lis.reverse()
ans=0
for i,s in enumerate(S):
  ans+=len(l_lis[i]-mat[s])*len(r_lis[i])
  mat[s]=l_lis[i]
  
print(ans)

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

ans = 0

for i in range(10):
    first = s.find(str(i))
    if first!=-1 and first!=n-1:
        for g in range(10):
            second = s[first+1:].find(str(g))+first+1
            if second!=first and second!=n-1:
                for l in range(10):
                    third = s[second+1:].find(str(l))+second+1
                    if third!=second:
                        ans+=1
print(ans)

Solution (Python):
inf = float("inf")

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):
            t = 0
            for l in s:
                if t == 0:
                    if l == i:
                        t += 1
                elif t == 1:
                    if l == j:
                        t += 1
                elif t == 2:
                    if l == k:
                        t += 1
            if t == 3:
                ans += 1

print(ans)

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

l = [str(i).zfill(3) for i in range(0,1000)]

ct = 0
for i in l:
  n0 = s.find(i[0])
  if n0==-1:
    continue
  n1 = s.find(i[1], n0+1)
  if n1==-1:
    continue
  n2 = s.find(i[2], n1+1)
  if n2!=-1:
    ct += 1
   
print(ct)

Solution (Python):
dig = [set() for i in range(3)]
_ = input()
n = input().strip()
for d in list(n):
  for v in dig[1]: dig[2].add(v + d)
  for v in dig[0]: dig[1].add(v + d)
  dig[0].add(d)
print (len(dig[2]))

Solution (Python):
import sys

def solve():
  n = int(input())
  s = input()
  ans = 0
  for i in range(0,1000):
    t1,t2,t3 = 0,0,0
    c3 = str(i%10)
    c2 = str((i//10)%10)
    c1 = str(i//100)
    for t in range(n):
      if not t1:
        if s[t] == c1:
          t1 = 1
      elif not t2:
        if s[t] == c2:
          t2 = 1
      elif not t3:
        if s[t] == c3:
          t3 = 1
      
    
      if t1 and t2 and t3: 
        ans += 1
        break
  print(ans)
solve()

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

ones = set()
twos = set()
threes = set()

for a in s:
    for item in twos:
        threes.add(item+a)
    for item in ones:
        twos.add(item+a)
    ones.add(a)

print(len(threes))

Solution (Python):
N = int(input())
S = list(input())
visited = {}

count = 0

for i, s in enumerate(S):
    if s in visited:
        continue
    visited[s] = []
    for j, s2 in enumerate(S[i+1:N-1]):
        
        if s2 in visited[s]:
            continue
        count += len(set(S[i + j + 2:N]))
        visited[s].append(s2)
        
print(count)

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

def nc(n,s,i,j,k):
    c1 = -1
    for l in range(n):
        if s[l] == i:
            c1 = l
            break
    if c1 == -1:
        return 0
    c2 = -1
    for l in range(c1+1,n):
        if s[l] == j:
            c2 = l
            break
    if c2 == -1:
        return 0
    c3 = -1
    for l in range(c2+1,n):
        if s[l] == k:
            c3 = l
            break
    if c3 == -1:
        return 0
    return 1

c = 0
for i in range(10):
        for j in range(10):
            for k in range(10):
                c += nc(n,s,i,j,k)



print(c)

Solution (Python):

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

lst = [[] for i in range(10)]

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

done = []
cnt = 0
for x in range(0,1000):
    tmp = str(x).rjust(3,'0')
    c1,c2,c3 = int(tmp[0]),int(tmp[1]),int(tmp[2])
    
    mi = -1
    mx = -1
    if len(lst[c1]) != 0:
        mi = lst[c1][0]
    if len(lst[c3]) != 0:
        mx = lst[c3][-1]
    
    if mi >= 0 and mx >= 0:
        for y in lst[c2]:
            if mi < y < mx:
                done.append(tmp)
    else:
        continue
        

print(len(set(done)))

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from collections import Counter
from math import factorial

def main():
    n = int(input().strip())
    s = input().strip()
    s += 'E'
    ans = 0
    for i in range(1000):
        a = i // 100
        b = (i % 100) // 10
        c = i % 10
        k = s.find(str(a))
        l = s.find(str(b), k+1)
        m = s.find(str(c), l+1)
        if k != -1 and l != -1 and m != -1:
            
            ans += 1
    print(ans)
    

if __name__ == '__main__':
    main()