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:
def main():
    n = int(input())
    s = input()
    one_set = set([])
    two_set = set([])
    three_set = set([])

    count = 0
    for i in range(n):
        if i==0:
            one_set.add(s[0])
            continue

        if 2<=i:
            for two in two_set:
                if two + s[i] not in three_set:
                    three_set.add(two + s[i])
                    count+=1

        for one in one_set:
            two_set.add(one + s[i])
        one_set.add(s[i])

    print(count)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
S = input()
ans = 0
def ok(i):
    v = str(i).zfill(3)
    j = 0
    for s in S:
        if s == v[j]:
            j += 1
            if j == 3:
                return True
    else:
        return False

for i in range(1000):
    ans += ok(i)
print(ans)

Submission status: Accepted

Solution code:
import re
#import time
N = int(input())
S = input()
#start = time.time()
cnt = 0
for i in range(10):
    fir = S.find(str(i))
    if fir == -1:
        continue
    for j in range(10):
        sec = S.find(str(j), fir + 1)
        if sec == -1:
            continue
        for h in range(10):
            thi = S.find(str(h), sec + 1)
            if thi == -1:
                continue
            cnt += 1
print(cnt)
#stop = time.time()
#print(stop - start)

Submission status: Accepted

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


count = 0
for i in range(1000):
  if i < 100:
    target_1 = "0"
    if i < 10:
      target_2 = "0"
      target_3 = str(i)
    else:
      target_2 = str(i)[0]
      target_3 = str(i)[1]
  else:
    target_1 = str(i)[0]
    target_2 = str(i)[1]
    target_3 = str(i)[2]
  
  step = 1
  for j in range(N):
    if S[j] == target_1 and step == 1:
      step = 2
      pass
    
    elif S[j] == target_2 and step == 2:
      step = 3
      
    elif S[j] == target_3 and step == 3:
      count += 1
      break

print(count)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
s=list(map(int,list(SI())))
pos=[[-1,-1] for i in range(10)]
for i in range(n):
    j=n-i-1
    if pos[s[i]][0]==-1:
        pos[s[i]][0]=i
    if pos[s[j]][1]==-1:
        pos[s[j]][1]=j
#print(pos)
count=0
for i in range(10):
    for j in range(10):
        lis=[0 for i in range(10)]
        if pos[i][0]<0 or pos[j][0]<0:
            continue
        for k in range(pos[i][0]+1,pos[j][1]):
            lis[s[k]]+=1
        for l in range(10):
            if lis[l]>0:
                count+=1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
s1, s2, s3 = set(), set(), set()
for i in s:
    for j in s2:
        s3.add(j+i)
    for j in s1:
        s2.add(j+i)
    s1.add(i)
print(len(s3))

Submission status: Accepted

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

    for i in range(1000):
        # 確認するpinの数字の組み合わせと桁の初期化
        # pin = list(str(i).zfill(3))
        pin = f'{i:0>3}'

        # list+indexで書こうと思ったけど、そもそも文字列でやっているのでfindで探しちゃう
        p1 = s.find(pin[0])

        if p1 != -1:
            p2 = s.find(pin[1], p1 + 1)
            if p2 != -1:
                p3 = s.find(pin[2], p2 + 1)
                if p3 != -1:
                    ans += 1

    print(ans)

if __name__ == '__main__':
    sumitrust2019_d_01()

Submission status: Accepted

Solution code:
import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
S = input()

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
S1 = set([])
S2 = set([])
S3 = set([])
for i in S:
    for s3 in S2:
        S3.add(s3+i)
    for s2 in S1:
        S2.add(s2+i)
    S1.add(i)
print(len(S3))

Submission status: Accepted

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

    ans = 0

    for i in range(1000):
        # 確認するpinの数字の組み合わせと桁の初期化
        # pin = list(str(i).zfill(3))
        current_digit = 0
        pin = f'{i:0>3}'
        search_num = pin[current_digit]

        for num in s:
            # 見つけると桁を右に一つずらす
            # 毎回リストにアクセスするより変数に取り出しておくほうがいいかも。
            # if num == pin[current_digit]:
            if num == search_num:
                current_digit += 1

                # indexが3(桁が3→2→1→0)になったときはそのPINは作れる
                if current_digit == 3:
                    ans += 1
                    break
                # 見つけ終わるまではチェックする数字を置き換え。
                elif current_digit < 3:
                    search_num = pin[current_digit]

    print(ans)

if __name__ == '__main__':
    sumitrust2019_d()

Submission status: Accepted

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

    ans = 0

    for i in range(1000):
        # 確認するpinの数字の組み合わせと桁の初期化
        # pin = list(str(i).zfill(3))
        current_digit = 0
        pin = f'{i:0>3}'
        search_num = pin[current_digit]

        for num in s:
            # 見つけると桁を右に一つずらす
            # 毎回リストにアクセスするより変数に取り出しておくほうがいいかも。
            # if num == pin[current_digit]:
            if num == pin[current_digit]:
                current_digit += 1

                # indexが3(桁が3→2→1→0)になったときはそのPINは作れる
                if current_digit == 3:
                    ans += 1
                    break
                # 見つけ終わるまではチェックする数字を置き換え。
                elif current_digit < 3:
                    search_num = pin[current_digit]

    print(ans)

if __name__ == '__main__':
    sumitrust2019_d()

Submission status: Accepted

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

ans = 0

for i in range(1000):
    # 確認するpinの数字の組み合わせと桁の初期化
    current_digit = 0
    pin = f'{i:0>3}'
    # pin = list(str(i).zfill(3))
    k = pin[current_digit]

    for num in s:
        # 見つけると桁を右に一つずらす
        if num == k:
            current_digit += 1
            # indexが3(桁が3→2→1→0)になったときはそのPINは作れる
            if current_digit <= 2:
                k = pin[current_digit]

            elif current_digit == 3:
                ans += 1
                break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(int, input()))
ans = 0
first = [0] * 10
a = 0
for i in range(N):
  if first[S[i]] == 0:
    first[S[i]] = 1
    a += 1
    second = [0] * 10
    b = 0
    for j in range(i+1, N):
      if second[S[j]] == 0:
        second[S[j]] = 1
        b += 1
        third = [0] * 10
        c = 0
        for k in range(j+1, N):
          if third[S[k]] == 0:
            third[S[k]] = 1
            ans += 1
            c += 1
            if c == 10:
              break
        if b == 10:
          break
    if a == 10:
      break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
ans = 0
for x in range(1000) :
    X = list(str(x).zfill(3))
    i = 0
    j = 0
    if X[0] in S[:N-2] :
        i = S.index(X[0])
    else :
        continue
    if X[1] in S[i+1:N-1] :
        j = S[i+1:N-1].index(X[1])+i+1
    else :
        continue
    if X[2] in S[j+1:N] :
        ans += 1
                        
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
sumi, result = [], 0
while len(sumi)<10 and N>0:
  x = S.pop(0)
  N -= 1
  if x in sumi:
    continue
  sumi.append(x)
  sumi_2, i = [], 0
  for i in range(N-1):
      s = S[i]
      if s in sumi_2:
        continue
      sumi_2.append(s)
      result += len(set(S[i+1:]))
print(result)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    S = input()

    return N, S


def main(N: int, S: str) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 桁数(4 <= N <= 30000)
        S (str): ラッキーナンバー(半角数字からなる長さNの文字列)
    """
    # 求解処理
    ans = 0
    S_i_list = []
    for i in range(N - 2):
        S_i = S[i]
        if S_i in S_i_list:
            continue
        S_j_list = []
        for j in range(i + 1, N - 1):
            S_j = S[j]
            if S_j in S_j_list:
                continue
            ans += len(set(S[j + 1: N]))
            S_j_list.append(S_j)
        S_i_list.append(S_i)

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, S = get_input()

    # メイン処理
    main(N, S)

Submission status: Accepted

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

cnt = 0

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

Submission status: Accepted

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

for i in range(0, 1000):
    count = 0
    val = list(str(i).zfill(3))
    k = val[count]
    for j in s:
        if j == k:
            count += 1
            if count <= 2:
                k = val[count]
            elif count == 3:
                ans += 1
                break
print(ans)

Submission status: Accepted

Solution code:
import copy
import math
import time
 
# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():
 
    idx += 1
'''
 
def main():
    start = time.time()
 
    n = get_int()
    s_list = get_string_char_list()
    s_list = [int(x) for x in s_list]
 
    #n = 30000
    #s_list = [1] * 30000
 
    #ans_set = set([])
 
    #for i in range(0,n):
    #    for ii in range(i+1, n):
    #        for iii in range(ii+1, n):
    #            ans_set.add(int(s_list[i]) * 100 + int(s_list[ii]) * 10 + int(s_list[iii]) * 1)
 
    #print(len(ans_set))
 
    ans = 0
 
    for i in range(0, 1000):
        a = i // 100
        b = (i % 100) // 10
        c = i % 10
 
        find_a = False
        find_b = False
        for ii in s_list:
 
            if (find_a == False) and (ii == a):
                find_a = True
            elif (find_a == True) and (find_b == False) and (ii == b):
                find_b = True
            elif (find_b == True) and (ii == c):
 
                ans += 1
                break
    print(ans)
 
    #print(time.time() - start)
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
s = S()
ans = 0
for i in range(1000):
    num = str(i).zfill(3)
    if s.find(num[0]) == -1:
        continue
    s1 = s[s.find(num[0])+1:]
    if s1.find(num[1]) == -1:
        continue
    s2 = s1[s1.find(num[1])+1:]
    if s2.find(num[2]) == -1:
        continue
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
import copy
import math
import time

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    start = time.time()

    n = get_int()
    s_list = get_string_char_list()
    s_list = [int(x) for x in s_list]

    #n = 30000
    #s_list = [1] * 30000

    #ans_set = set([])

    #for i in range(0,n):
    #    for ii in range(i+1, n):
    #        for iii in range(ii+1, n):
    #            ans_set.add(int(s_list[i]) * 100 + int(s_list[ii]) * 10 + int(s_list[iii]) * 1)

    #print(len(ans_set))

    ans = 0

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

        find_a = False
        find_b = False
        for ii in s_list:

            if (find_a == False) and (ii == a):
                find_a = True
            elif (find_a == True) and (find_b == False) and (ii == b):
                find_b = True
            elif (find_b == True) and (ii == c):

                ans += 1
                break
    print(ans)

    #print(time.time() - start)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

def solve():     
    N = int(input())
    S = input()
    l = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    p = itertools.product(l,repeat=3)
    count = 0
    for v in p:
        S_temp = S
        dig_0_index = S_temp.find(v[0])
        if dig_0_index != -1:
            S_temp = S_temp[dig_0_index+1::]
            dig_1_index = S_temp.find(v[1])
            if dig_1_index != -1:
                S_temp = S_temp[dig_1_index+1::]
                dig_2_index = S_temp.find(v[2])
                if dig_2_index != -1:
                    count += 1
    print(count)

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

count=0

for i in range(0,10):
    if str(i) in s[:-2]:
        index_1=s.index(str(i))

        for j in range(0,10):
            if str(j) in s[index_1+1:-1]:
                index_2=s[index_1+1:-1].index(str(j))+index_1+1

                for k in range(0,10):
                    if str(k) in s[index_2+1:]:
                        count+=1
print(count)

Submission status: Accepted

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

sapp = [[0] * n for _ in range(10)]
for idx, s in enumerate(S):
    sapp[int(s)][idx] = 1

from itertools import accumulate
sacc = [list(accumulate(sa)) for sa in sapp]

pins = set()
for i in range(1, n-1):
    for lnum in range(10):
        if sacc[lnum][i-1] == 0:
            continue
        for rnum in range(10):
            # i+1から最後までで出現するか
            rnumc = sacc[rnum][-1] - sacc[rnum][i]
            if rnumc > 0:
                pins.add(100*lnum + 10*int(S[i]) + rnum)

print(len(pins))

Submission status: Accepted

Solution code:
#関数リスト
import sys
from copy import deepcopy
input = sys.stdin.readline


def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))

def main():
    d = [[]]*10
    keta = I()
    num = input().rstrip()
    for i in range(keta):
        temp = int(num[i])
        if len(d[temp]) == 0:
            d[temp] = [int(keta-i)]
        else:
            d[temp].append(int(keta-i))
    result = 0
    for j in range(1000):
        a = j // 100
        b = (j % 100) // 10
        c = ((j % 100) % 10)
        try:
            a_num = d[a][0]
        except:
            continue
        try:
            if a == b:
                b_num = d[b][1]
            else:
                index = 0
                while True:
                    b_num = d[b][index]
                    if b_num < a_num:
                        break
                    else:
                        index += 1
        except:
            continue
        try:
            if a == c and a == b:
                c_num = d[c][2]
            elif a == c or b == c:
                c_num = min(d[c][1:])
            else:
                c_num = min(d[c])
        except:
            continue
        if a_num > b_num and b_num > c_num:
            result += 1

    print(result)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

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

ans = 0
for n in range(1000):
    target = "{:03}".format(n)
    j = 0
    for i in range(N):
        if S[i] == target[j]:
            j += 1
        if j == 3:
            ans += 1
            break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = input()
ans = 0
nums = list(map(str, range(10)))
for i in nums:
    s1 = S.find(i)
    if s1 < 0:
        continue
    for j in nums:
        s2 = S.find(j, s1+1)
        if s2 < 0:
            continue
        for k in nums:
            s3 = S.find(k, s2+1)
            if s3 > 0:
                ans += 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from itertools import product

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

for i in product(range(10), repeat = 3):
    a = s.find(str(i[0]))
    if a != -1 and a != n - 1:
        b = s[a + 1:].find(str(i[1]))
        if b != -1:
            b += a + 1
            if b != n - 1:
                c = s[b + 1:].find(str(i[2]))
                if c != -1:
                    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[int(x) for x in list(input())]
ans=0
for a in range(10):
  for i in range(n):
    if s[i]==a:
      a_dx=i
      break
  else:
    continue
  for b in range(10):
    for i in range(a_dx+1,n):
      if s[i]==b:
        b_dx=i
        break
    else:
      continue
    for c in range(10):
      for i in range(b_dx+1,n):
        if s[i]==c:
          ans+=1
          break
      else:
        continue

print(ans)

Submission status: Accepted

Solution code:
def input_li():
    return list(map(int, input().split()))


def input_int():
    return int(input())


N = input_int()
S = input()
ans = 0
for i in range(1000):
    str_i = str(i)
    s = '0' * (3 - len(str_i)) + str_i
    idx = 0
    for j in range(N):
        if S[j] == s[idx]:
            idx += 1
            if idx == 3:
                ans += 1
                break
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
from collections import Counter
c=Counter(s)
for i in range(1000):
    x=str(i)
    if len(x)==1:
        x="00"+x
    elif len(x)==2:
        x="0"+x
    k=0
    for j in range(n):
        if s[j]==x[k]:
            k+=1
        if k==3:
            ans+=1
            break
        
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
code=list(set(list(S)))
ans=0
for i in code:
    for j in code:
        for k in code:
            count=0
            for s in S:
                if count==0:
                    if s==i:
                        count+=1
                elif count==1:
                    if s==j:
                        count+=1
                elif count==2:
                    if s==k:
                        count+=1
                if count==3:
                    ans+=1
                    break
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
fa=[n+1]*10
la=[-1]*10
for i in range(n):
    s[i]=int(s[i])
    if fa[s[i]]>n:
        fa[s[i]]=i
    la[s[i]]=i
ans=0
for i in range(10):
    for j in range(10):
        if fa[i]<la[j]:
            num=[0]*10
            for k in range(fa[i]+1,la[j]):
                num[s[k]]=1
            ans+=num.count(1)
print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = input()

    import re
    num_li = [False]*1000
    for i in range(10):
        first_ = S.find(str(i),0,N-2)
        if first_==-1:
            continue
        for j in range(10):
            second_ = S.find(str(j),first_+1,N-1)
            if second_==-1:
                continue
            for k in range(10):
                third_ = S.find(str(k),second_+1,N)
                if third_==-1:
                    continue
                num_li[i*100+j*10+k]=True
            
    print(sum(num_li))

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
t = []
ans = 0
for i in range(1000):
    t.append(str(i//100))
    t.append(str(i//10%10))
    t.append(str(i%10))
    k = 0
    p = 0
    for j in range(3):
        if t[j] in s[k:]:
            p = s[k:].index(t[j]) + 1
            k += p
        else:
            p = -1
            break
    if p != -1:
        ans += 1
    t.clear()
print(ans)

Submission status: Accepted

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

num = "1234567890"

ans = 0
for a in num:
    pa = S.find(a)
    if pa == -1:
        continue
    for b in num:
        pb = S.find(b, pa + 1)
        if pb == -1:
            continue
        for c in num:
            pc = S.find(c, pb + 1)
            if pc == -1:
                continue
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools

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

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

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
S = S()
after_lis = [set() for _ in range(N+1)]
i = N-1
for s in reversed(S):
    after_lis[i] = (after_lis[i] | after_lis[i+1])
    after_lis[i].add(int(s))
    i -= 1

left_index = {}
for i, s in enumerate(S):
    if s not in left_index:
        left_index[s] = i

ans_lis = np.zeros([10, 10, 10], dtype=np.int32)

for char in left_index:
    s_100 = int(char)
    for i_10 in range(left_index[char]+1, N-1):
        # print("s_10")
        s_10 = int(S[i_10])
        ans_lis[s_100, s_10, list(after_lis[i_10+1])] = 1

        # sは暗証番号の一番左
# print(ans_lis)
print(np.sum(ans_lis))

Submission status: Accepted

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

ret = 0
for x in range(10):
    for y in range(10):
        for z in range(10):
            a = S.find(str(x))
            if a != -1:
                b = S.find(str(y), a + 1)
                if b != -1:
                    c = S.find(str(z), b + 1)
                    if c != -1:
                        ret += 1
print(ret)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[8]:


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


# In[19]:


ans = 0
for i in range(10):
    str_i = str(i)
    i_index = S.find(str_i)
    if i_index == -1:
        continue
    for j in range(10):
        str_j = str(j)
        j_index = S.find(str_j, i_index+1)
        if j_index == -1:
            continue
        for k in range(10):
            str_k = str(k)
            k_index = S.find(str_k, j_index+1) 
            if k_index != -1:
                ans += 1
print(ans)


# In[ ]:

Submission status: Accepted

Solution code:
N = int(input())
S = input()
third = [[[False]*10 for _ in range(10)] for __ in range(10)]
second = [[False]*10 for _ in range(10)]
first = [False]*10
for s in S:
    s = int(s)
    for i in range(10):
        if first[i]:
            for j in range(10):
                if second[i][j]:
                    third[i][j][s] = True
            second[i][s] = True
    first[s] = True

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

Submission status: Accepted

Solution code:
N = int(input())
Stemp = str(input())
S = []
for i in range(N):
  temp = int(Stemp[i])
  S.append(temp)
ans = set([])
L = [[] for _ in range(10)]
for i in range(N):
  L[S[i]].append(i)
#print(L)
for v in range(1000):
  a = v//100
  b = (v-a*100)//10
  c = v-a*100-b*10
  if not L[a]:
    continue
  left = min(L[a])
  Flag = False
  for x in L[b]:
    if x > left:
      mid = x
      Flag = True
      break
  if not Flag:
    continue
  Flag = False
  for y in L[c]:
    if y > mid:
      right = y
      Flag = True
      break
  if not Flag:
    continue
  ans.add(v)
  #print(v,left,mid,right)
print(len(ans))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=0
for i in range(10):
  str_i = str(i)
  i_index=S.find(str_i)
  if i_index==-1:
    continue
  for j in range(10):
    str_j=str(j)
    j_index=S.find(str_j, i_index+1)
    if j_index==-1:
      continue
    for k in range(10):
      str_k=str(k)
      k_index=S.find(str_k, j_index+1) 
      if k_index!=-1:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n=input()
s=input()
ans=0
for i in range(1000):
 i=str(i).zfill(3)
 a=s.find(i[0])
 if a!=-1:
  b=s.find(i[1],a+1)
  if b!=-1:
   if s.find(i[2],b+1)!=-1:ans+=1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans,a=0,[]
for i in range(n):
    if s[i] not in a:
        a+=[s[i]]
        b=[]
        for j in range(i+1,n):
            if s[j] not in b:
                b+=[s[j]]
                c=[]
                for k in range(j+1,n):
                    if s[k] not in c:
                        c+=[s[k]]
                        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

s=list(input())

ans = 0

for i in range(1000):
    i = str(i)
    keta = len(list(i))
    code = '0'*(3-keta)+i
    code = list(code)
    index = 0
    for j in s:
        if j == code[index]:
            index += 1
        if index == 3:
            break
    if index == 3:
        #print(code)
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = input()
cnt = 0
set_ = set()
for val in range(1000):
    val = str(val).zfill(3)
    a =val[0]
    b = val[1]
    c = val[2]
    flag = False
    for i in range(n):
        if S[i]==a and flag == False:
            for j in range(i+1,n):
                if S[j]==b and flag == False:
                    for k in range(j+1,n):
                        if S[k]==c and flag == False: 
                            cnt += 1
                            flag = True
                            break
                    break
            break
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
L = [[] for _ in range(10)]
for i,s in enumerate(S):
    n = int(s)
    L[n].append(i)

count = 0
import bisect
for i in range(1000):
    s = str(i)
    s = s.zfill(3)
    if L[int(s[2])] and L[int(s[0])]:
        r = int(L[int(s[2])][-1])
        l = int(L[int(s[0])][0])
        r2 = bisect.bisect_left(L[int(s[1])], r)
        l2 = bisect.bisect_right(L[int(s[1])], l)
        if r2-l2>0:
            count+=1

print(count)

Submission status: Accepted

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

import itertools
ans=0

for num in range(1000):
	num=str(num).zfill(3)
	a0=S.find(str(num[0]))
	if a0>=0:
		S1=S[(a0+1):]
		a1=S1.find(str(num[1]))
		if a1>=0:
			S2=S1[(a1+1):]
			if str(num[2]) in S2:
				ans+=1

		



print(ans)





# 2darray [[0] * 4 for i in range(3)]