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()
count = 0
f0,f1 = -1,-1
for ans in range(1000):
  f0,f1 = -1,-1
  ans_str = "{0:03d}".format(ans)
  for i in range(n):
    if s[i] == ans_str[0]:
      f0 = i
      break
  if f0 == -1:
    continue
  for j in range(f0+1,n):
    if s[j] == ans_str[1]:
      f1 = j
      break
  if f1 == -1:
    continue
  for k in range(f1+1,n):
    if s[k] == ans_str[2]:
      count += 1
      break

print(count)

Solution (Python):
n=int(input())
s=list(input())
counter=0
for i in range(1000):
	while len(str(i))<3:
		i="0"+str(i)
	i=str(i)
	if i[0] in s:
		a=s.index(i[0])
		if i[1] in s[a+1:]:
			b=s[a+1:].index(i[1])+a+1
			if i[2] in s[b+1:]:
				counter+=1
print(counter)

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

key = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            key.append([i,j,k])
            
flag1 = 0
flag2 = 0
flag3 = 0
ans = 0



for i in range(len(key)):
    flag1 = 0
    flag2 = 0
    flag3 = 0
    
    flag1 = S.find(str(key[i][0]))
    
    if flag1 == -1:
        continue
        
    flag2 = S.find(str(key[i][1]),flag1+1)
    
    if flag2 == -1:
        continue
        
    flag3 = S.find(str(key[i][2]),flag2+1)
    
    if flag3 == -1:
        continue
                            
    if flag1 != -1 and flag2 != -1 and flag3 != -1:
        ans += 1
        
print(ans)

Solution (Python):
n = int(input())
s = list(input())
genkai_list = []
for i in range(0,1000):
    if 0 <= i <= 9:
        ap = "00" + str(i)
        genkai_list.append(ap)
    elif 10 <= i <= 99:
        ap = "0" + str(i)
        genkai_list.append(ap)
    else:
        genkai_list.append(str(i))
count = 0
for a in genkai_list:
    try:
        s_ = s[s.index(a[0])+1:]
        s__ = s_[s_.index(a[1])+1:]
        if a[2] in s__:
            count += 1
    except:
        continue
print(count)

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

def judge(n):
    j = 0
    for i in range(N):
        if S[i] == n[j]:
            j += 1
        if j == 3:
            return True
    return False

ans = 0

for num in range(1000):
    num = str(num)
    num = "0" * (3-len(num)) + num
    if judge(num):
        ans += 1

print(ans)

Solution (Python):

from itertools import combinations
import sys
input = sys.stdin.readline

number = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
n = int(input())
s = input().rstrip()

ans = 0
for item in number:
    if item not in s:
        continue
    a = s.index(item)
    if a >= n-2:
        continue
    for item2 in number:
        if item2 not in s[a+1:]:
            continue
        b = a + 1 + s[a+1:].index(item2)
        if b >= n-1:
            continue
        for item3 in number:
            if item3 not in s[b+1:]: 
                continue
            c = b + 1 + s[b+1:].index(item3)
            ans += 1
print(ans)

Solution (Python):
dp = [set() for i in range(4)]
dp[0].add('')
N = input()
S = input()
for c in S:
    for i in reversed(range(3)):
        for s in dp[i]:
            dp[i+1].add(s+c)
print(len(dp[3]))

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

ans = 0
for P in range(1000):
    Ds = str(P).zfill(3)
    pos = -1
    for D in Ds:
        pos = Ss.find(D, pos+1)
        if pos == -1:
            break
    else:
        ans += 1

print(ans)

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

ans = 0
for P in range(1000):
    Ds = str(P).zfill(3)
    pos = -1
    for D in Ds:
        pos = Ss.find(D, pos+1)
        if pos == -1:
            break
    else:
        ans += 1

print(ans)

Solution (Python):
from bisect import bisect

n = int(input())
s = input()
location = [[] for _ in range(10)]
for i, c in enumerate(map(int, s)):
    location[c].append(i)
location = [loc for loc in location if loc]
last_indices = [loc[-1] for loc in location]

ans = 0
for loc_x in location:
    i = loc_x[0]
    for loc_y in location:
        ji = bisect(loc_y, i)
        if ji >= len(loc_y):
            continue
        j = loc_y[ji]
        ans += sum(j < li for li in last_indices)
print(ans)

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

for i in range(1000):
    v = str(i).zfill(3)
    start=0
    f=0

    for j in range(3):
        idx=s.find(v[j],start)
        if idx > -1:
            start =idx+1
            f+=1
        else:
            break
    if f==3:
        ans+=1
print(ans)

Solution (Python):
N=int(input())
S=str(input())
X=[0]*1000
cnt=0
for i in range(10):
  a=S.find(str(i))
  if a==-1:
    continue
  else:
    for j in range(10):
      b=S[a+1:].find(str(j))
      if b==-1:
        continue
      else:
        for k in range(10):
          c=S[a+b+2:].find(str(k))
          if c==-1:
            continue
          else:
            cnt+=1
print(cnt)

Solution (Python):
N = int(input())
S = input()
C = 0
for i in range(10):
	if str(i) in S[:N-2]:
		for j in range(10):
			if str(j) in S[S.find(str(i))+1:N-1]:
				for k in range(10):
					if str(k) in S[S[S.find(str(i))+1:N-1].find(str(j))+S.find(str(i))+2:]:
						C += 1
print(C)

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

DP = [[-1] * 1001 for i in range(4)]
DP[0][0] = 0

for i in range(N):
    for j in reversed(range(3)):
        for k in reversed(range(1001)):
            if DP[j][k] != -1:
                if j == 0:
                    DP[j + 1][k + int(S[i]) * 100] = 0
                if j == 1:
                    DP[j + 1][k + int(S[i]) * 10] = 0
                if j == 2:
                    DP[j + 1][k + int(S[i]) * 1] = 0

Sum = 0
for k in range(1001):
    if DP[3][k] == 0:
        Sum += 1
print(Sum)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(10):
  for j in range(10):
    l = s.find(str(i))
    r = s.rfind(str(j))
    if l != -1 and r != -1 and l<r:
      ans += len(set(s[l+1:r]))
print(ans)

Solution (Python):



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

for i in range(0, 1000):
  i = str(i)
  S_ = S
  i = i.zfill(3)
  if i[0] in S_:
    fir = S_.find(i[0])
    S_ = S_[fir+1:]
    if i[1] in S_:
      sec = S_.find(i[1])
      S_ = S_[sec+1:]
      if i[2] in S_:
        ans += 1
        
print(ans)

Solution (Python):
N = int(input())
S = list(input())
pas = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            pas.append(str(i)+str(j)+str(k))
ans = 0
for pw in pas:
    if pw[0] in S:
        ind = S.index(pw[0])
        tmp = S[ind+1:]
    else:
        continue
    if pw[1] in tmp:
        ind = tmp.index(pw[1])
        tmp = tmp[ind+1:]
    else:
        continue
    if pw[2] in tmp:
        ans += 1
print(ans)

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

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

print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
s = input()
res = 0
a = [i for i in range(10)]
for num in itertools.product(a, repeat=3):
    p = 0
    for i,j in enumerate(s):
        if j == str(num[p]):
            p += 1
            if p == 3:
                res += 1
                break
print(res)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
s = input()
res = 0
a = [str(i) for i in range(10)]
for num in itertools.product(a, repeat=3):
    p = 0
    for i,j in enumerate(s):
        if j == num[p]:
            p += 1
            if p == 3:
                res += 1
                break
print(res)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
s = input()
res = 0
a = [str(i) for i in range(10)]
for num in itertools.product(a, repeat=3):
    p = 0
    for i,j in enumerate(s):
        if j == num[p]:
            p += 1
            if p == 3:
                break
    if p == 3:
        res += 1
print(res)

Solution (Python):
def my_index2(l, x, default=-1):
    return l.index(x) if x in l else default
n = int(input())
S = list(input())
for i in range(n):
  S[i] = int(S[i])
ans = 0
for i in range(10):
  a = my_index2(S[0:n-2],i)
  if a != -1:
    for j in range(10):
      b = my_index2(S[a+1:n-1], j) 
      if b!=-1:
        for k in range(10):
          c = my_index2(S[a+1+b+1::], k)
          if c!= -1:
            ans+=1
print(ans)

Solution (Python):
def solve():
    ans = 1
    N = int(input())
    s = input()
    ans = 0
    for i in range(1000):
    	t = str(i).zfill(3)
    	t_index = 0 
    	for s_element in s:
    		if s_element == t[t_index]:
    			t_index += 1
    			if t_index == 3:
    				break
    	if t_index == 3:
    		ans += 1
    print(ans)
solve()

Solution (Python):
def solve():
    ans = 1
    N = int(input())
    s = input()
    ans = 0
    for i in range(1000):
    	t = str(i).zfill(3)
    	t_index = 0 
    	for s_index in range(N):
    		if s[s_index] == t[t_index]:
    			t_index += 1
    			if t_index == 3:
    				break
    	if t_index == 3:
    		ans += 1
    print(ans)
solve()

Solution (Python):
n=int(input())
s=input()
ans=0
a=[0]*3
f=0

for a[0] in range(10):
    for a[1] in range(10):
        for a[2] in range(10):
            
            f=0
            for ss in s:
                
                if ss == str(a[f]):
                    f+=1
                    if f==3:
                        ans+=1
                        break
print(ans)

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

count = 0
for a in range(10):
    for b in range(10):
        for c in range(10):
            f1 = False
            f2 = False
            p1 = 0
            p2 = 0
            for i in range(0, n-2):
                if int(s[i]) == a:
                    f1 = True
                    p1 = i
                    break
            if f1:
                for j in range(p1+1, n-1):
                    if int(s[j]) == b:
                        f2 = True
                        p2 = j
                        break
            if f2:
                for k in range(p2+1, n):
                    if int(s[k]) == c:
                        count += 1
                        break
            if not f1 or not f2:
                break
        if not f1:
            break
print(count)

Solution (Python):


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

count = 0
for a in range(10):
    for b in range(10):
        for c in range(10):
            f1 = False
            f2 = False
            p1 = 0
            p2 = 0
            for i in range(0, n-2):
                if int(s[i]) == a:
                    f1 = True
                    p1 = i
                    break
            if f1:
                for j in range(p1+1, n-1):
                    if int(s[j]) == b:
                        f2 = True
                        p2 = j
                        break
            if f2:
                for k in range(p2+1, n):
                    if int(s[k]) == c:
                        count += 1
                        break
            if not f1 or not f2:
                break
print(count)

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

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

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

for ii in range(1000):
    v = str(ii).zfill(3)
    start=0
    f=0
    
    for j in range(3):
        idx=s.find(v[j],start)
        if idx > -1:
            start = idx + 1
            f+=1
        else:
            break

    if f == 3:
        ans += 1

print(ans)

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

for i in range(10):
    idx1 = S.find(str(i))
    if idx1 == -1:
        continue
    for j in range(10):
        idx2 = S.find(str(j), idx1 + 1)
        if idx2 == -1:
            continue
        for k in range(10):
            idx3 = S.find(str(k), idx2 + 1)
            if idx3 == -1:
                continue
            answer += 1

print(answer)

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

number_i = list(range(10))
ans = 0

for i in range(n-2):
    if int(s[i]) in number_i:
        number_i.remove(int(s[i]))
        number_j = list(range(10))
        

        for j in range(i+1,n-1):
            if int(s[j]) in number_j:
                number_j.remove(int(s[j]))
                number_k = list(range(10))

                for k in range(j+1,n):
                    if int(s[k]) in number_k:
                        number_k.remove(int(s[k]))
                        ans += 1
                        

print(ans)

Solution (Python):
from collections import defaultdict
from sys import stdin
N = int(stdin.readline().rstrip())
S = (stdin.readline().rstrip())
d = defaultdict(list)
for ind, i in enumerate(S):
    d[i].append(ind+1)
ans = 0

for a in range(10):
    for b in range(10):
        for c in range(10):
            if (a == b == c) and (len(d[str(a)]) < 3):
                continue
            if d[str(a)] and d[str(b)] and d[str(c)]:
                i_a = d[str(a)][0]
                i_b = -1
                i_c = -1
                for j in d[str(b)]:
                    if i_a < j:
                        i_b = j
                        break
                for k in d[str(c)]:
                    if i_b < k:
                        i_c = k
                        break
                if i_a < i_b < i_c:
                    ans += 1
            else:
                continue
print(ans)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n=int(input())
s=input()
li=[[-1]*10 for i in range(n+1)]
for i in range(n):
    li[-i-2]=li[-i-1][:]
    li[-i-2][int(s[-i-1])]=n-1-i

ans=0
for i in range(1000):
    tmp=str(i)
    while len(tmp)!=3:
        tmp= "0"+tmp
    now=0
    for j in range(3):
        if li[now][int(tmp[j])]==-1:
            break
        now=li[now][int(tmp[j])]+1
        if j==2:
            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=s.find(str(i))
            y=s.find(str(j),x+1)
            z=s.find(str(k),y+1)
            if(x!=-1 and y!=-1 and z!=-1):
                ans+=1
print(ans)

Solution (Python):

import sys

input = sys.stdin.readline
def MAP(): return [int(s) for s in input().split()]

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











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

Solution (Python):
from operator import add


class SegmentTreeClass:
    def __init__(self,
                 init_val: 'initial value: iterable',
                 segfunc: 'operation unique in case',
                 ide_ele: 'identity element corresponding init_val' = 0,
                 ):
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.size = 1 << (len(init_val) - 1).bit_length()
        self.tree = self._build(init_val)

    def _build(self, init_val) -> 'tree':
        segfunc = self.segfunc

        tree = [self.ide_ele] * (self.size * 2 - 1)

        for idx, val in enumerate(init_val, self.size - 1):  
            
            tree[idx] = val

        for idx in range(self.size - 2, -1, -1):  
            tree[idx] = segfunc(tree[idx * 2 + 1], tree[idx * 2 + 2])

        return tree

    def update(self, idx: int, val) -> None:
        tree = self.tree
        segfunc = self.segfunc

        idx += self.size - 1
        
        tree[idx] = val
        while idx > 0:
            idx = (idx - 1) // 2
            tree[idx] = segfunc(tree[idx * 2 + 1], tree[idx * 2 + 2])

    def query(self, left: int, right: int) -> 'result':
        left += self.size
        right += self.size
        ret = self.ide_ele  
        segfunc = self.segfunc
        tree = self.tree
        while left < right:  
            if left & 1:  
                ret = segfunc(ret, tree[left - 1])
                left += 1
            if right & 1:  
                right -= 1
                ret = segfunc(ret, tree[right - 1])
            left >>= 1
            right >>= 1
        return ret


L = 10
n = int(input())
s = map(int, input())

d1 = [0] * L
s1 = SegmentTreeClass(init_val=d1, segfunc=add, ide_ele=0)
d2 = [0] * L
s2 = SegmentTreeClass(init_val=d1, segfunc=add, ide_ele=0)
d3 = [0] * L
s3 = SegmentTreeClass(init_val=d1, segfunc=add, ide_ele=0)

for c in s:
    x = s2.query(0, L)
    s3.update(c, x)

    x = s1.query(0, L)
    s2.update(c, x)

    s1.update(c, 1)

print(s3.query(0, L))

Solution (Python):
from bisect import bisect_left
n = int(input())
s = input()
d = {}

for i, c in enumerate(s):
    c = int(c)
    if c in d:
        d[c].append(i)
    else:
        d[c] = [i]

l = list(d.keys())
ans = 0

for i in l:
    index_i = d[i][0]
    for j in l:
        if d[j][-1] <= index_i:
            continue
        index_index = bisect_left(d[j], index_i)
        if i == j:
            if len(d[j]) > 1:
                index_index += 1
            else:
                continue
        index_j = d[j][index_index]

        for k in l:
            if d[k][-1] > index_j:
                ans += 1
print(ans)

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

Solution (Python):

n,s = [input() for i in range(2)]
c = 0
for i in range(1000):
    v = str(i).zfill(3)
    p1 = s.find(v[0])
    if p1 >= 0:
        p2 = s.find(v[1], p1 + 1)
        if p2 >= 0:
            if s.find(v[2], p2 + 1) >= 0:
                c += 1
print(c)

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

ans = 0
for i in range(0,10):
        for j in range(0,10):
                for k in range(0,10):
                        flag1 = False
                        flag2 = False
                        for z in S:
                                if flag1 and flag2 and z == k:
                                        ans += 1
                                        break
                                if flag1 and z == j:
                                        flag2 = True
                                        continue
                                if z == i:
                                        flag1 = True
                                        continue


print(ans)

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

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = input().rstrip()

ans = 0
for i in range(1000):
    t = str(i).zfill(3)
    t1 = S.find(t[0])
    if t1 == -1:
        continue
    t2 = S.find(t[1], t1+1)
    if t2 == -1:
        continue
    t3 = S.find(t[2], t2+1)
    if t3 == -1:
        continue
    ans += 1

print(ans)

Solution (Python):
n,S,r=int(input()),input(),0
dp1=[0]*n
dp2=[0]*n
d1=set()
d2=set()
cs=[0]*10
for i in range(n):
    dp1[i] = len(d1)
    d1.add(S[i])
for i in range(n):
    j = n-i-1
    dp2[j] = len(d2)
    r += dp1[j]*(dp2[j]-dp2[cs[int(S[j])]])
    d2.add(S[j])
    cs[int(S[j])] = j
print(r)

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

for i in range(1000):
    p = str(i).zfill(3)
    p1 = s.find(p[0])
    if p1 == -1: continue
    p2 = s.find(p[1], p1 + 1)
    if p2 == -1: continue
    p3 = s.find(p[2], p2 + 1)
    if p3 == -1: continue
    cnt += 1
print(cnt)

Solution (Python):



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

V_cnt  = 0 

for i in range(10): 
    for j in range(10): 
        for k in range(10):
            check_i = S.find(str(i)) 
            if check_i != -1:   
                tmp_S = S[check_i + 1:] 
                check_j = tmp_S.find(str(j))
                if check_j != -1:  
                    tmp_T = tmp_S[check_j + 1:]
                    check_k = tmp_T.find(str(k))
                    if check_k != -1:
                        V_cnt += 1                  
print(V_cnt)

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

count = 0
for h in range(10):
  pos_h = S.find(str(h))
  if pos_h < 0:
    continue
  for i in range(10):
    pos_i = S.find(str(i), pos_h+1)
    if pos_i < 0:
      continue
    for j in range(10):
      pos_j = S.find(str(j), pos_i+1)
      if pos_j < 0:
        continue
      count += 1

print(count)

Solution (Python):
import itertools

N = int(input())
S = input() + '

ans = 0
for comb in itertools.product('0123456789', repeat=3):
    found = 0
    for s in S:
        if found == 3:
            ans += 1
            break
        elif s == comb[found]:
            found += 1

print(ans)

Solution (Python):
import sys

def main():
    

    n=int(input())
    s=list(map(int,input()))
    
    cnt=0
    for i in range(10):
        if i in s[:-2]:
            idx1=s[:-2].index(i)
            for j in range(10):
                if j in s[idx1+1:-1]:
                    idx2=s[idx1+1:-1].index(j)+idx1+1
                    for k in range(10):
                        if k in s[idx2+1:]:
                            cnt+=1
    print(cnt)

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


if __name__=='__main__':
    main()

Solution (Python):
import sys

def is_password(s, p):
    check = s.find(p[0])
    idx = check + 1
    if check == -1:
        return False
    check = s[idx:].find(p[1])
    if check == -1:
        return False
    idx = idx + check + 1
    check = s[idx:].find(p[2])
    if check == -1:
        return False
    return True

f = sys.stdin
n = int(f.readline())
s = f.readline()[:-1]

count = 0
for l1 in range(10):
    for l2 in range(10):
        for l3 in range(10):
            p = str(l1) + str(l2) + str(l3)
            if is_password(s, p):
                count += 1

print(count)

Solution (Python):
N = int(input())
S = list(map(int,input()))
count = 0
for i in range(10):
    if i in S[:-2] :
        v1 = S[:-2].index(i)
        for j in range(10):
            if j in S[v1+1:-1] :
                v2 = S[v1+1:-1].index(j) + v1 + 1
                for k in range(10):
                    if k in S[v2+1:] :
                        count += 1
print(count)

Solution (Python):
a=[[0]*10,[0]*100,[0]*1000]
n=int(input())
s=input()
for i in s:
  d=int(i)
  for j in range(100):
    if a[1][j]:
      a[2][10*j+d]=1
  for j in range(10):
    if a[0][j]:
      a[1][10*j+d]=1
  a[0][d]=1
print(sum(a[2]))

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

L = []
R = []
tmp = set()
for s in S:
    tmp.add(s)
    L.append(tmp.copy())
tmp = set()
for s in S[::-1]:
    tmp.add(s)
    R.append(tmp.copy())
R = R[::-1]

ans = set()

for i in range(1,N-1):
    b = S[i]
    for a in L[i-1]:
        for c in R[i+1]:
            ans.add((a,b,c))

print(len(ans))

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

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(0,10):
  for j in range(0,10):
    left = s.find(str(i))
    right = s.rfind(str(j))
    if left<0 or right <= left:
      continue
    for k in range(0,10):
      ans += int(str(k) in s[left+1:right])
print(ans)

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

ans=0
for x in range(1000):
  x=str(x).zfill(3)
  p1=S.find(x[0])
  if p1==-1: continue
  p2=S.find(x[1],p1+1)
  if p2==-1: continue
  p3=S.find(x[2],p2+1)
  if p3==-1: continue
  ans+=1
print(ans)

Solution (Python):
from string import digits

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

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)

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

for a in range(10): 
  for b in range(10): 
    for c in range(10): 
      flg = False
      check_a = s.find(str(a))
      if check_a != -1:
        tmp_s = s[check_a + 1:]
        check_b = tmp_s.find(str(b))
        if check_b != -1:
          tmp_t = tmp_s[check_b + 1:]
          check_c = tmp_t.find(str(c))
          if check_c != -1:
            cnt = cnt + 1            
print(cnt)

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

count = 0
for p in range(1000):
    v = format(p, '03')
    found = False
    pos1 = S.find(v[0])
    if pos1 == -1:
        continue
    pos2 = S[pos1 + 1:].find(v[1])
    if pos2 == -1:
        continue
    pos3 = S[pos1 + pos2 + 2:].find(v[2])
    if pos3 == -1:
        continue
    count += 1

print(count)

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

for x in range(10):
	for y in range(10):
		for z in range(10):
			i = s.find(str(x))
			if i != -1:
				i = s.find(str(y), i+1)
				if i != -1:
					i = s.find(str(z), i+1)
					if i != -1:
						cnt += 1
				
print(cnt)

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

D=[0]*1000

for i in range(1000):
    a=str(i//100)
    b=str((i//10)%10)
    c=str(i%10)
    f=0
    for j in S:
        if(f==2 and c==j):
            D[i]=1
            break
        elif(f==1 and b==j):
            f=2
        elif(f==0 and a==j):
            f=1
print(sum(D))

Solution (Python):

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

dp = [[False] * 1000 for i in range(4)]
for i in range(10):
    dp[0][i] = True
for c in s:
    k = int(c)
    for i in range(3)[::-1]:
        for j in range(10**i):
            dp[i + 1][10 * j + k] |= dp[i][j]
print(sum(dp[3]))

Solution (Python):
input()
a=set(),set(),set(),{''}
for s in input():
 for b,c in zip(a,a[1:]):b|={t+s for t in c}
print(len(a[0]))

Solution (Python):
_,s=open(0)
dp=[[0]*1000for _ in range(4)]
dp[0][0]=1
for c in map(int,s[:-1]):
  for i in range(3,0,-1):
    for j in range(10**(i-1)):
      dp[i][j*10+c]|=dp[i-1][j]
print(sum(dp[3][i]for i in range(1000)))

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

for i in range(10):
    for j in range(10):
        for k in range(10):
            idx = S.find(str(k))
            if idx != -1:
                idx = S.find(str(j),idx+1)
                if idx != -1:
                    idx = S.find(str(i),idx+1)
                    if idx != -1:
                        cnt += 1

print(cnt)

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

for i in range(10):
    for j in range(10):
        for k in range(10):
            idx = 0
            a = S.find(str(k),idx)
            if a != -1:
                idx = a
                b = S.find(str(j),idx+1)
                if b != -1:
                    idx = b
                    c = S.find(str(i),idx+1)
                    if c != -1:
                        cnt += 1

print(cnt)

Solution (Python):
from sys import stdin

N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()

ans = 0
num_str = [str(i).zfill(3) for i in range(1000)]

for i in num_str:
    j = 0
    k = 0
    while k < 3:
        while j < len(S):
            if S[j] == i[k]:
                k += 1
                j += 1
                break
            j += 1
        if j == len(S):
            break
    if k == 3:
        ans += 1

print(ans)

Solution (Python):
def main():
  N = int(input())
  S = tuple(input())
  ans = 0
  for i in range(1000):
    if i<10:
      cnt0= 0
      cnt1 = 0
      for j in range(N):
        if 2<=cnt0 and S[j]=="%d"%i:
          ans+=1
          break
        if S[j]=="0":
          cnt0+=1
          continue
    elif 10<=i<=99:
      cnt0=0
      cnt1=0
      cnt2=0
      i = list(str(i))
      for j in range(N):
        if 1<=cnt0 and 1<=cnt1 and S[j]=="%s"%i[1]:
          ans+=1
          break
        if S[j]=="0" and cnt0!=1:
          cnt0+=1
          continue
        if 1<=cnt0 and S[j]=="%s"%i[0]:
          cnt1 +=1
          continue
    elif 100<=i:
      cnt0=0
      cnt1=0
      cnt2=0
      i = list(str(i))
      for j in range(N):
        if 1<=cnt0 and 1<=cnt1 and S[j]=="%s"%i[2]:
          ans+=1
          
          break
        if S[j]=="%s"%i[0] and cnt0!=1:
          cnt0+=1
          continue
        if 1<=cnt0 and S[j]=="%s"%i[1]:
          cnt1 +=1
          continue
  print(ans)
main()

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

N = int(input())
S = input()
INF = float('inf')

nToD = defaultdict(list)
for d, s in enumerate(S):
    nToD[s].append(d)
for d in range(10):
    nToD[str(d)].append(INF)

ans = 0
for i in range(1000):
    P = '%03d' % i
    prev = nToD[P[0]][0]

    if prev == INF:
        continue

    for p in P[1:]:
        prev = nToD[p][bisect_right(nToD[p], prev)]
        if prev == INF:
            break
    else:
        ans += 1

print(ans)

Solution (Python):
N=int(input())
S=input()
i_lis=[]
key=0
for i in range(N-2):
  if S[i] in i_lis:continue
  else:i_lis.append(S[i])
  j_lis=[]
  for j in range(i+1,N-1):
    if S[j] in j_lis:continue
    else:j_lis.append(S[j])
    k_lis=[]
    for k in range(j+1,N):
      if S[k] in k_lis:continue
      else:k_lis.append(S[k]);key+=1
print(key)