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



Sample input:
4
0224


Sample output:
3

Submission status: Accepted

Solution code:
n = input()
s = input()

count = 0
for i in range(10):
  try:
    ii = s.index(str(i))
  except:
    continue
  for j in range(10):
    try:
      ji = s[ii + 1:].index(str(j))
    except:
      continue
    for k in range(10):
      try:
        ki = s[ii + ji + 2:].index(str(k))
        count += 1
      except:
        continue
print(count)

Submission status: Accepted

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

a = 0
for i in range(1000):
    i = '%03d' % i
    ss = s
    for c in i:
        p = ss.find(c)
        if p == -1:
            break
        ss = ss[p + 1:]
    else:
        a += 1

print(a)

Submission status: Accepted

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

ans = 0
for i in range(1000):
    flag = [False, False, False]
    st = str(i).zfill(3)
    a = s.find(st[0])
    if a != -1:
        b = s.find(st[1],a+1)
        if b != -1:
            c =s.find(st[2],b+1)
            if c != -1:
                ans += 1
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1000):
    temp = [str(i // 100), str((i // 10) % 10), str(i % 10)]
    count = 0
    for j in range(n):
        if temp[count] == s[j]:
            count += 1
        if count == 3:
            ans += 1
            break
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = input()


import collections, bisect
n_indices_dict = [[] for _ in range(10)]
for i, n in enumerate(S):
    n_indices_dict[int(n)].append(i)

candidates = [(n1, n2, n3)
                for n1 in range(10)
                   for n2 in range(10)
                       for n3 in range(10)]


# print(n_indices_dict)
# exit()

# candidates = [(2, 2, 4)]

ret = 0
for n1, n2, n3 in candidates:
    if n_indices_dict[n1]:
        v1 = n_indices_dict[n1][0]

        if n_indices_dict[n2]:
            i2 = bisect.bisect_right(n_indices_dict[n2], v1)
            if i2 == len(n_indices_dict[n2]):
                continue

            v2 = n_indices_dict[n2][i2]
            if v1 >= v2:
                continue


            if n_indices_dict[n3]:
                i3 = bisect.bisect_right(n_indices_dict[n3], v2)
                if i3 == len(n_indices_dict[n3]):
                    continue

                v3 = n_indices_dict[n3][i3]
                if v2 >= v3:
                    continue

                ret += 1
                # print(v1, v2, v3, n1, n2, n3)


print(ret)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
 
cnt = [0]*11
i = 0
T = ''
for s in S:
  cnt[int(s)]+=1
  if min(cnt)<=3:
    T += s
#print(T)
ans = 0
P = []
for a in range(10):
  A = str(a)
  k = 0
  ind1 = -1
  while k < len(T)-2:
    t = T[k]
    if A == t:
      ind1 = k
      break
    k += 1
  if ind1 == -1:
    continue
  for b in range(10):
    B = str(b)
    l = ind1+1
    ind2 = -1
    while l < len(T)-1:
      t = T[l]
      if B == t:
        ind2 = l
        break
      l += 1
    #print(a,b,ind1,ind2)
    if ind2 == -1:
      continue
    for c in range(10):
      C = str(c)
      m = ind2+1
      while m < len(T):
        t = T[m]
        if C == t:
          ans += 1
          break
        m += 1
print(ans)

Submission status: Accepted

Solution code:
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))
            if x!=-1:
                y=s.find(str(j),x+1)
                if y!=-1:
                    z=s.find(str(k),y+1)
                    if z!=-1:
                        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int, input()))
cnt = 0
for i1 in range(10):
    for i2 in range(10):
        for i3 in range(10):
            for i in range(n):
                if s[i]==i1: 
                    for j in range(i+1, n):
                        if s[j]==i2:
                            for k in range(j+1, n):
                                if s[k]==i3:
                                    cnt += 1
                                    #print(i1, i2, i3)
                                    break
                            break
                    break

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    key = str(i)
    key = "0"*(3-len(key)) + key

    cur = 0
    for s in S:
        if s == key[cur]:
            cur += 1
        if cur >= 3:
            ans += 1
            break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1000):
    seq = "{:03d}".format(i)
    cnt = 0
    for j in s:
        if seq[cnt] == j:
            cnt += 1
            if cnt == 3:
                break
    if cnt == 3:
        ans += 1
print(ans)

Submission status: Accepted

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

left = [set() for _ in range(n)]
right = [set() for _ in range(n)]

for i in range(1, n):
    x = left[i - 1].copy()
    x.add(s[i - 1])
    left[i] = x

for i in range(n - 2, -1, -1):
    x = right[i + 1].copy()
    x.add(s[i + 1])
    right[i] = x

t = [False for _ in range(1000)]
for i in range(1, n - 1):
    for c in left[i]:
        for d in right[i]:
            t[int(c + s[i] + d)] = True

print(t.count(True))

Submission status: Accepted

Solution code:
import glob
import numpy as np
import sys
import time


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'smbc2019\\D'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'


class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):
        start_time = time.time()

        N = int(self.input_data())
        S = self.input_data()
        lucky_nums = [int(s) for s in S]

        array_first = [0 for i in range(10)]
        array_last =[0 for i in range(10)]

        for i in range(10):
            index = S.find(str(i))
            array_first[i] = index
            index = S.rfind(str(i))
            array_last[i] = index

        count = 0
        for i in range(10):
            if array_first[i] == -1:
                continue
            for j in range(10):
                if array_first[i]+1 >= array_last[j]:
                    continue
                for k in range(10):
                    if k in lucky_nums[array_first[i]+1:array_last[j]]:
                        count += 1

        print(str(count))

solver = Solver(REL_PATH)
solver.exec_resolve()

Submission status: Accepted

Solution code:
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))
            if x!=-1:
                y=s.find(str(j),x+1)
                if y!=-1:
                    z=s.find(str(k),y+1)
                    if z!=-1:
                        ans+=1

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(1000):
        target = str(i).zfill(3)
        pointer = 0
        subS = S
        for digit in target:
            pointer = subS.find(digit)
            if pointer == -1:
                break
            else:
                subS = subS[pointer+1:]
        if pointer != -1:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math
import heapq
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#######ここから天ぷら########
n=int(input())
s=list(input())
s=list(map(int,s))

ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if i in s:
                ci=s.index(i)
                if j in s[ci+1:]:
                    cj=s[ci+1:].index(j)
                    if k in s[ci+1:][cj+1:]:
                        ans+=1
print(ans)

Submission status: Accepted

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

answer=0
for i in range(1000):
  i0=i//100
  i1=(i//10)%10
  i2=i%10

  flag_num=0
  for s in S:
    if flag_num==0 and s==i0:
      flag_num+=1
    elif flag_num==1 and s==i1:
      flag_num+=1
    elif flag_num==2 and s==i2:
      answer+=1
      break
      
print(answer)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
ans = 0
for i in range(1000):
  s = str(i).zfill(3)
  idx = -1
  Count = True
  for j in range(3):
    idx = S.find(s[j], idx+1)
    if idx==-1:
      Count = False
      break
  if Count:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
count=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            num=str(i)+str(j)+str(k)
            a=s.find(num[0])
            if (a==-1):
                continue
            b=s[a+1::].find(num[1])
            if (b==-1):
                continue
            c=s[a+b+2::].find(num[2])
            if (c==-1):
                continue
            count+=1
            #print(num,a,b,c)
        ##
    ##
##
print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
# st = set()
# for i in range(n-2):
#     for j in range(i+1, n-1):
#         for k in range(j+1, n):
#             pin = s[i] + s[j] + s[k]
#             st.add(pin)
# print(st)
count = 0
# for i in range(1000):
#     if len(str(i)) == 1:
#         v = "00" + str(i)
#     elif len(str(i)) == 2:
#         v = "0" + str(i)
#     else:
#         v = str(i)
#     k = 0
#     for j in range(len(v)):
#         while k < len(s):
#             if s[k] == v[j]:
#                 k += 1
#                 break
#             k += 1
#         else:
#             break
#     else:
#         count += 1
for i in range(1000):
    v = [i // 100, (i // 10) % 10, i % 10]
    first = s[:-2].find(str(v[0]))
    if first == -1:
        continue
    second = s[first + 1:-1].find(str(v[1]))
    if second == -1:
        continue
    third = s[first + 1 + second + 1:].find(str(v[2]))
    if third == -1:
        continue
    # print(v, first, second, third, first + second +1)
    count += 1
print(count)

Submission status: Accepted

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

count=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp_number=str(i) + str(j) + str(k)
            a = S.find(tmp_number[0])
            if a == -1:
                continue
            b = S[(a+1):].find(tmp_number[1])
            # print(S[a:])
            if b == -1:
                continue
            c = S[(a+b+2):].find(tmp_number[2])
            # print(S[(a+b):])
            if c == -1:
                continue
            count+=1
            # print(a,b,c)
            # print(tmp_number)
print(count)

Submission status: Accepted

Solution code:
def main():
    length = int(input())
    lucky_num = input()
    answer = 0
    for i in range(1000):
        target = str(i).zfill(3)
        index = [-1, -1, -1]
        index[0] = lucky_num.find(target[0])
        if index[0] >= 0:
            index[1] = lucky_num.find(target[1], index[0] + 1)
            if index[1] > index[0]:
                index[2] = lucky_num.find(target[2], index[1] + 1)
                if index[2] > index[1]:
                    answer += 1
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
for i in range(10):
    a = s.find(str(i))
    if a == -1:
        continue

    for j in range(10):
        b = s.find(str(j), a+1)
        if b == -1:
            continue

        for k in range(10):
            if s.find(str(k), b+1) != -1:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(str(input()))
s = [int(c) for c in s]

d = {}
for i, c in enumerate(s):
    if c not in d:
        d[c] = [i]
    else:
        d[c].append(i)
#print(d)

ans = 0
import bisect
for i in range(10):
    for j in range(10):
        for k in range(10):
            if i not in d or j not in d or k not in d:
                continue
            a = min(d[i])
            b = max(d[k])
            p = bisect.bisect_right(d[j], a)
            q = bisect.bisect_left(d[j], b)
            if q-p >= 1:
                ans += 1
                #print(i, j, k)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
ans = set()
for i in range(10):
    if str(i) in s:
        for j in range(10):
            if str(j) in s[s.find(str(i))+1:]:
                for k in range(10):
                    if str(k) in s[s.find(str(j), s.find(str(i))+1)+1:]:
                        ans.add((i,j,k))
print(len(ans))

Submission status: Accepted

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

candidates = [0 for i in range(10 ** 3)]

count = 0
for i in range(1000):
    tmp_pass = '{:03}'.format(i)

    index_0 = s.find(tmp_pass[0])
    if index_0 != -1 and index_0 < len(s) - 2:
        s_1 = s[index_0 + 1:]
        index_1 = s_1.find(tmp_pass[1])
        if index_1 != -1 and index_1 < len(s_1) - 1:
            s_2 = s_1[index_1 + 1:]
            # print(tmp_pass)
            # print(s_2)
            # index_2 = s_2.find(tmp_pass[2])
            # print(index_2)
            if s_2.find(tmp_pass[2]) != -1:
                count += 1

print(count)

Submission status: Accepted

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

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

    first = s.find(i[0])
    if first == -1:
        continue

    second = s.find(i[1], first+1)
    if second == -1:
        continue

    third = s.find(i[2], second+1)

    if third != -1:
        ans += 1

print(ans)

Submission status: Accepted

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

for i in range(1000):
    str_i = '{:03}'.format(i)
    found = 0
    for s in S:
        if(s==str_i[found]):
            found += 1
            if(found == 3):
                cnt += 1
                break
print(cnt)

Submission status: Accepted

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

cnt = 0

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

    head = S.find(pin[0])
    middle = S.find(pin[1], head + 1)
    tail = S.find(pin[2], middle + 1)

    if head != -1 and middle != -1 and tail != -1:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
first_check = [0] * 10
ans = 0
for i in range(N):
    if first_check[int(S[i])] == 1:
        continue
    second_check = [0] * 10
    for k in range(i+1,N):
        if second_check[int(S[k])] == 1:
            continue
        ans += len(set(list(S[k+1:])))
        second_check[int(S[k])] = 1
    first_check[int(S[i])] = 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
d=dict()
for i in range(1000):
  num='0'*(3-len(str(i)))+str(i)
  if num[0] in s:
    j=s.index(num[0])
    if num[1] in s[j+1:]:
      k=s[j+1:].index(num[1])
      if num[2] in s[j+2+k:]:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
N = input()
S = input()
count = 0
for i in range(1000):
    n = "{:03d}".format(i)
    n1, n2, n3 = n[0], n[1], n[2]
    i1 = S.find(n1)
    if -1 < i1 < len(S) - 2:
        i2 = S.find(n2, i1 + 1)
        if -1 < i2 < len(S) - 1:
            i3 = S.find(n3, i2 + 1)
            if -1 < i3:
                count += 1
                continue
print(count)

Submission status: Accepted

Solution code:
N = input()
S = input()
count = 0
for i in range(1000):
    n = "{:03d}".format(i)
    n1, n2, n3 = n[0], n[1], n[2]
    i1 = S.find(n1)
    if -1 < i1 < len(S) - 2:
        S1 = S[i1 + 1:]
        i2 = S1.find(n2)
        if -1 < i2 < len(S1) - 1:
            S2 = S1[i2 + 1:]
            i3 = S2.find(n3)
            if -1 < i3:
                count += 1
                continue
print(count)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    s = list(input())
    ans = 0
    for i in range(1000):
        k = str(i)
        while len(k) < 3:
            k = "0"+k
        l = 0
        for j in range(n):
            if k[l] == s[j]:
                l += 1
                if l == 3:
                    ans += 1
                    break
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N  = int (input())
S = input()
s = set()
s.add("")
for c in S:
    new = []
    for c2 in s:
        if len(c2) < 3:
            new.append(c2 + c)
    for temp in new:
        s.add(temp)
ans = 0
for temp in s:
    if len(temp) == 3:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:

N = int(input())
S = input()
cnt = 0
pin = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            pin.append(str(i) + str(j) + str(k))

for i in range(1000):
    one = S.find(pin[i][0])
    two = S.find(pin[i][1], one + 1)
    three = S.find(pin[i][2], two + 1)
    if one != -1 and two != -1 and three != -1:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
def password():
    for i in range(10):
        for j in range(10):
            for k in range(10):
                yield [str(i), str(j), str(k)]


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

ans = 0
for perm in password():
    if perm[0] in s:
        a = s.find(perm[0])
        if perm[1] in s[a + 1 :]:
            b = s[a + 1 :].find(perm[1])
            if perm[2] in s[a + 1 :][b + 1 :]:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    S = input()
    
    ans = 0
    memo1 = set()
    for i in range(N - 2):
        si = int(S[i])
        if si in memo1:
            continue
        memo1.add(si)
        memo2 = set()
        for j in range(i + 1, N - 1):
            sj = int(S[j])
            if sj in memo2:
                continue
            memo2.add(sj)
            ans += len(set(S[j + 1:]))
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
cnt=0
number=[str(i) for i in range(10)]
for i in range(10):
    try:
        first=S.index(number[i])
        if first>=N-2:
            continue
        for k in range(10):
            try:
                second=S[first+1:].index(number[k])
                if second>=len(S[first+1:])-1:
                    continue
                for l in range(10):
                    if number[l] in S[first+1:][second+1:]:
                        cnt+=1
            except:
                continue
    except:
        continue
print(cnt)

Submission status: Accepted

Solution code:
import copy
n = int(input())
s = input()
slist = list(s)
# list
def search(slist, plist):
    s2 = copy.copy(slist)
    for k in plist:
        if k in s2:
            start = s2.index(k)+1
            s2 = s2[start:]
        else:
            return False
    return True

# print(search(slist, ["2","2","4"]))
count = 0
for i in range(1000):
    # 1000
    p = format(i, "03")
    plist = list(str(p))
    if search(slist, plist):
        count += 1
print(count)

Submission status: Accepted

Solution code:
def str_find(S, target, start):
    for i in range(start, len(S)):
        if S[i] == target:
            return i

    return 10**9+7

N = int(raw_input())
S = str(raw_input())

candidates = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            candi = str(i)+str(j)+str(k)
            candidates.append(candi)


ans = 0
for candi in candidates:
    x = candi[0]
    i = str_find(S, x, 0)

    y = candi[1]
    j = str_find(S, y, i+1)

    z = candi[2]
    k = str_find(S, z, j+1)

    if i+j+k< 10**8:
        ans = ans + 1

print ans

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    S = stdin.readline().rstrip()
    count = 0
    for i in range(1000):
        left = 0
        not_found = False
        for c in '{:03}'.format(i):
            for j in range(left, N):
                if S[j] == c:
                    left = j + 1
                    break
            else:
                not_found = True
                break
            if not_found:
                break
        if not not_found:
            count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = []

for i in range(0,1000):
    v = str(i).zfill(3)
    p1 = s.find(v[0],0)
    p2 = s.find(v[1],p1+1)
    p3 = s.find(v[2],p2+1)
    if p1 != -1 and p2 != -1 and p3 != -1:
        ans.append(v)

print(len(ans))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import itertools

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

# 暗証番号Vを000から999まで決め打ちすると、次の問題を1000回解けば良いことになる。
# SからN-3桁を消して、Vを作ることができるか。
# この問題は貪欲法で解くことができる。
# - 1. S_i = V_1であるようなiのうち、最小のiをp_1とする。そのようなiが存在しなければ、Vを作ることはできない。
# - 2. S_i = V_2であるようなiのうち、p_1より大きい、かつ最も小さいiをp_2とする。そのようなiが存在しなければ、Vを作ることはできない。
# - 3. S_i = V_3であるようなiのうち、p_2より大きい、かつ最も小さいiをp_3とする。そのようなiが存在しなければ、Vを作ることはできない。
# e.g., S = 869120, V = 812
# - V_1 = 8より、p_1 = 0
# - V_2 = 1, p_1 = 0より、p_2 = 3
# - V_3 = 2, p_2 = 3より、p_3 = 4

def can_make_pw(S, password):
    # step1
    v1 = password[0]
    p1 = S.find(v1)
    if p1 == -1:
        return False
    # step2
    v2 = password[1]
    p2 = S.find(v2, p1+1)
    if p2 == -1:
        return False
    # step3
    v3 = password[2]
    p3 = S.find(v3, p2+1)
    if p3 == -1:
        return False
    return True

passwords = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            password = str(i) + str(j) + str(k)
            passwords.append(password)
# print(passwords)

count = 0
for password in passwords:
    if can_make_pw(S, password):
        # print(f"You can make {password} from {S}")
        count += 1

print(count)

# 全探索はTLE
# l_pw = []
# if N-3 == 1:
#     for i in range(N):
#         l_S = list(S)
#         l_S.pop(i)
#         l_pw.append(','.join(l_S))
# else:
#     combs = list(itertools.combinations(range(N), N-3))
#     for comb in combs:
#         l_S = list(S)
#         for i in sorted(comb, reverse=True):
#             l_S.pop(i)
#         l_pw.append(','.join(l_S))
# print(len(set(l_pw)))

Submission status: Accepted

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

cnt = 0
for i in range(10):
    s_ = s
    if str(0) in s_:
        s_ = s_[s_.index(str(0))+1:]
        if str(0) in s_:
            s_ = s_[s_.index(str(0))+1:]
            if str(i) in s_:
                cnt += 1

for i in range(10,100):
    s_ = s
    if str(0) in s_:
        s_ = s_[s_.index(str(0))+1:]
        if str(i)[0] in s_:
            s_ = s_[s_.index(str(i)[0])+1:]
            if str(i)[1] in s_:
                cnt += 1

for i in range(100,1000):
    s_ = s
    if str(i)[0] in s_:
        s_ = s_[s_.index(str(i)[0])+1:]
        if str(i)[1] in s_:
            s_ = s_[s_.index(str(i)[1])+1:]
            if str(i)[2] in s_:
                cnt += 1  

print(cnt)

Submission status: Accepted

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

ans = 0
for i in range(1000):
    
    if len(str(i)) != 3:
        V = "0" * (3- len(str(i))) + str(i)
    else:
        V = str(i)
    
    cnt = 0
    for j in S:
        if V[cnt] == j:
            cnt += 1
            
        if cnt == 3:
            ans += 1
            break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(10):
    a = s.find(str(i))
    if a != -1:
        for j in range(10):
            b = s[a+1:].find(str(j))
            if b != -1:
                for k in range(10):
                    c = s[a+1:][b+1:].find(str(k))
                    if c != -1:
                        ans += 1
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

d = [defaultdict(int) for i in range(3)]
for s in S:
    for x in d[1]:
        d[2][x+s]+=1
    for x in d[0]:
        d[1][x+s]+=1
    d[0][s]+=1
print(len(d[2]))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
dp = {}
si = set()
for i in range(N-2):
  if S[i] in si:
    continue
  si.add(S[i])
  for j in range(i+1, N-1):
    if dp.get(S[i] + S[j], 0) > 0:
      continue
    dp[S[i] + S[j]] = len(set(S[j+1:]))
print(sum(dp.values()))

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(int,input()))
count = 0

for x100 in range(10):
    if x100 in S[:N-2]:
        ind_100 = S.index(x100)
        
        for x10 in range(10):
            if x10 in S[ind_100+1:N-1]:
                ind_10 = S[ind_100+1:N-1].index(x10) + ind_100 + 1
                
                for x1 in range(10):
                    if x1 in S[ind_10 + 1:]:
                        count += 1
print(count)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

for i in range(1000):
    cnt = 0
    if i < 100:
        if i < 10:
            match = '00' + str(i)
        else:
            match = '0' + str(i)
    else:
        match = str(i)

    for S in s:
        if S == match[cnt]:
            cnt += 1

        if cnt == 3:
            ans += 1
            break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1000):
    tg = str(i + 1000)[1:]
    if tg[0] not in s:
        continue
    else:
        x2 = s[s.index(tg[0]) + 1:]
        if tg[1] not in x2:
            continue
        else:
            x3 = x2[x2.index(tg[1]) + 1:]
            if tg[2] not in x3:
                continue
            else:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0

for i in range(0, 1000):
    i = str(i).zfill(3)
    idx = 0
    for j in range(3):
        if i[j] in S[idx:]:
            idx += S[idx:].index(i[j])+1
            continue
        else:
            break
    else:
        ans += 1

    


print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
st = set()
nums = [str(i) for i in range(10)]
for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = False
            flag2 = False
            for l in range(N):
                if not flag1 and S[l] == nums[i]:
                    flag1 = True
                elif flag1 and not flag2 and S[l] == nums[j]:
                    flag2 = True
                elif flag1 and flag2 and S[l] == nums[k]:
                    st.add(nums[i] + nums[j] + nums[k])
                
print(len(st))

Submission status: Accepted

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

ans = 0
for i in range(0, 1000):
    i = str(i).zfill(3)

    try:
        id1 = s.index(i[0])
        id2 = s.index(i[1], id1+1)
        id3 = s.index(i[2], id2+1)
        ans += 1
    except ValueError:
        continue

print(ans)

Submission status: Accepted

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

# 3桁の数値の総当り
count = 0
for n in range(0, 1000):
    password = "{:03d}".format(n)
    p1, p2, p3 = password

    i1 = S.find(str(p1))
    if i1 < 0:
        continue
    i2 = S[i1+1:].find(str(p2))
    if i2 < 0:
        continue
    i3 = S[i1+1:][i2+1:].find(str(p3))
    if i3 < 0:
        continue
    count += 1
print(count)

Submission status: Accepted

Solution code:
from itertools import combinations


n = int(input())
s = input()
ans = 0
for i in range(1000):
    num = '{:0=3}'.format(i)
    inds = 0
    indnum = 0
    while inds < len(s) and indnum < 3:
        if s[inds] == num[indnum]:
            indnum += 1
        inds += 1
    if indnum == 3:
        ans += 1
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(0, 1000):
    x = str(i).zfill(3)

    try:
        id1 = s.index(x[0])
        id2 = s.index(x[1], id1+1)
        id3 = s.index(x[2], id2+1)
        ans += 1
    except ValueError:
        continue

print(ans)

Submission status: Accepted

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

nums = tuple(str(i) for i in range(10))

ans = 0
for i in nums:
    pi = s.find(i)
    if pi == -1:
        continue

    for j in nums:
        pj = s.find(j, pi + 1)
        if pj == -1:
            continue

        for k in nums:
            pk = s.find(k, pj + 1)
            if pk == -1:
                continue

            ans += 1

print(ans)