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:
import sys
sys.setrecursionlimit(10000000)
import numpy as np
from heapq import heapify, heappop, heappush
import copy
from collections import deque
# queueとして使う場合 push, popleftを使う
from bisect import bisect_left, bisect_right
# bisect_left: 配列の順序関係が崩れない条件で挿入することができる一番左の点
# bisect_right: 配列の順序関係が崩れない条件で挿入することができる一番右の点
# A = [1, 1, 1, 2, 2, 2, 4]
# print(bisect_left(A, 2))  # 3
# print(bisect_right(A, 2))  # 6
# print(bisect_left(A, 3))  # 6
# print(bisect_right(A, 3))  # 6


def main():
    N = int(input())
    S = input()
    most_left = {i: -1 for i in range(10)}
    for i in range(len(S)):
        s = int(S[i])
        if most_left[s] == -1:
            most_left[s] = i
    
    wholes = [False] * 1000
    sum_ = 0
    
    for i, first_idx in most_left.items():
        if first_idx == -1:
            continue
        alreadys = [False] * 10
        for second_idx in range(first_idx + 1, N):
            if alreadys[int(S[second_idx])]:
                continue
            alreadys[int(S[second_idx])] = True
            for third_idx in range(second_idx + 1, N):
                number = int(S[first_idx] + S[second_idx] + S[third_idx])
                if wholes[number] is False:
                    wholes[number] = True
                    sum_ += 1
    print(sum_)



        




if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0

for i in range(100):
    num = str(i).zfill(2)
    k = 0
    for j in range(len(s)):
        if num[k] == s[j]:
            k += 1
        if k == 2:
            ans += len(set(s[j+1:]))
            break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = input()
ans = 0
for i in range(10):
  x = S.find(str(i))
  if x == -1:
    continue
  for j in range(10):
    y = S.find(str(j),x+1)
    if y == -1:
      continue
    for k in range(10):
      z = S.find(str(k),y+1)
      if z != -1:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1000):
    n = "000" + str(i)
    n = n[-3:]
    index = 0
    for j in range(len(s)):
        if s[j] == n[index]:
            index += 1
            if index == 3:
                break
    if index == 3:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = input()
count = 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 str(k) in S[b+1::]:
                count += 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt = 0
for i in range(1000):
    p = '{:03}'.format(i)
    s2 = s
    for j in range(3):#indexのループ
        if s2.find(p[j]) == -1:
            break
        s2 = s2[s2.find(p[j]) +1:]
    else:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
def m2():
    n = int(input())
    s = str(input())
    ALL = [str(i) for i in range(10)]
    ans = 0
    for a in ALL:
        for b in ALL:
            for c in ALL:
                flag = 0
                for i in range(n):
                    if s[i] == a and flag == 0:
                        flag = 1
                        continue
                    if s[i] == b and flag == 1:
                        flag = 2
                        continue
                    if s[i] == c and flag == 2:
                        flag = 3
                    if flag == 3:
                        ans += 1
                        break
    return ans

print(m2())

Submission status: Accepted

Solution code:
# 貪欲法による
# > 000 ~ 999の1000通りをチェックする。
n = int(input())
s = input()
'''
for i in range(1000):
    a = '{0:03d}'.format(i)
    a1 = a[0]
    a2 =
'''
ans = 0

for i in range(10):
    #temp = s

    if (str(i) not in s):
        continue
    else:
        tar1 = s.find(str(i))

    for j in range(10):
        temp = s[tar1 + 1:]
        if (str(j) not in temp):
            continue
        else:
            tar2 = temp.find(str(j))

        for k in range(10):
            temp = s[tar1 + 1:]
            temp = temp[tar2 + 1:]

            if (str(k) not in temp):
                continue
            else:
                ans += 1


print(ans)

Submission status: Accepted

Solution code:
def main():
    N_keta = int(input())
    S = input()

    total = 0

    for n in range(0, 1000):
        FLAG = True
        n_str = "{:03}".format(n)
        pos = 0
        
        for i in n_str:
            numberS = S[pos:]
            if (i not in numberS):
                FLAG = False
                break
            else:
                pos += numberS.index(i) + 1
        
        if (FLAG):
            total += 1

    print(total)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A=int(input())
l=input()
ans=0
for i in range(1000):
   s=str(i).zfill(3)
   x=l.find(s[0])
   y=l.find(s[1],x+1)
   z=l.find(s[2],y+1)
   if all([x <= y <= z,x!=-1,y!=-1,z!=-1]):
      ans+=1
print(ans)

Submission status: Accepted

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

kouho = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            kouho.append(str(i)+ str(j) + str(k))

cnt = 0
for pwd in kouho:
    point = 0
    for word in S:
        if word == pwd[point]:
            point += 1
            if point == 3:
                cnt += 1
                break

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
cnt=0
for i in range(10):
    a = S.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b=S.find(str(j),a+1)
        if b == -1:
            continue
        for k in range(10):
            c=S.find(str(k),b+1)
            if c != -1:
                cnt+=1
            

print(cnt)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

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

candi = list(itertools.product(range(10),repeat=3))

cnt = 0

for i in candi:
    if str(i[0]) in S:
        T = S[S.find(str(i[0]))+1:]
        if str(i[1]) in T:
            U = T[T.find(str(i[1]))+1:]
            if str(i[2]) in U:
                cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    n = II()
    S = list(map(int, list(input())))

    ans = 0
    for v in range(0, 1000):
        V = list(str(v))
        if len(V) == 2:
            V.insert(0, '0')
        elif len(V) == 1:
            V.insert(0, '0')
            V.insert(0, '0')
        elif len(V) == 0:
            V.insert(0, '0')
            V.insert(0, '0')
            V.insert(0, '0')
        # print(V)

        # end = [0] * 3
        cnt = 0
        for s in S:
            # print(V[cnt], str(s))
            if V[cnt] == str(s):
                cnt += 1
                if cnt == 3:
                    # print(V)
                    break
        # print(cnt)
        # input()
        if cnt == 3:
           ans += 1
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())
S = input()
 
res = 0
for i in range(10):
    if str(i) in S:
        T = S[S.index(str(i))+1:]
        
        for j in range(10):
            if str(j) in T:
                U = T[T.index(str(j))+1:]
                
                for k in range(10):
                    if str(k) in U:
                        res += 1
                
print(res)

Submission status: Accepted

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())

n = int(input())
s = input()
cnt = 0
q = s[0]
t = s[0]
for x in s[1:]:
    if x == q:
        cnt += 1
        if cnt < 3:
            t += x
    else:
        cnt = 0
        t += x
        q = x
ans = 0
for i in range(10):
    x = t.find(str(i)) + 1
    if not x: continue
    for j in range(10):
        y = t[x:].find(str(j)) + 1
        if not y: continue
        for k in range(10):
            z = t[x + y:].find(str(k)) + 1
            if not z: continue
            #print(i,j,k, ':', x,y,z)
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
s = input()
ar = [[0 for i in range(3)] for j in range(1000)]
kakunin = [0 for i in range(1000)]
index = 0
res = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            a = s.find(str(i))

            if a == -1:
                continue

            b = s[a+1:len(s)].find(str(j))
            if b == -1:
                continue
            c = s[a+b+2:len(s)].find(str(k))
            if c != -1:
                # print(str(a) + "  "+ str(b) + "  " + str(c))
                # print(str(i) + "  " + str(j) + "   "+ str(k))
                # print()
                res += 1
print(res)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt = 0
for i in range(1000):
    p = '{:03}'.format(i)
    s2 = s
    for j in range(3):
        if s2.find(p[j]) == -1:
            break
        s2 = s2[s2.find(p[j]) + 1:]
    else:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import itertools
n=(int)(input())
moji = list('0123456789')
s=input()
count = 0

for i in itertools.product(moji, repeat=3):
  sousa = list(s)
  try:
    
    n1 = sousa.index(i[0])
    n2 = sousa[n1+1:].index(i[1])+n1+1
    n3 = sousa[n2+1:].index(i[2])+n2+1
    #print(sousa, sousa[n1+1:], sousa[n1+2:])
    count += 1
  except ValueError:
    continue
  #print(i)
  #moji.append(s[i[0]] + s[i[1]] + s[i[2]])
  #print(moji)
  
print(count)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
S = input()
where = {str(s):[] for s in range(10)}
for i, s in enumerate(S):
    where[s].append(i)
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    #print(v)
    s = v[0]
    if len(where[s]) > 0:
        before_index = where[s][0]
        #print('\t', s, before_index)
        c = 1
        for j in range(1, 3):
            s = v[j]
            if len(where[s]) > 0:
                next_index = bisect.bisect_left(where[s], before_index+1)
                if next_index == len(where[s]):
                    break
                #print('\t', s, before_index, next_index)
                next_index = where[s][next_index]
                #print(s, before_index, next_index)
                if next_index > before_index:
                    before_index = next_index
                    c += 1
            else:
                break
        if c == 3:
            #print('\t ok')
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    c = 0
    idx_now = 0
    for j in range(3):
        idx = S[idx_now:].find(v[j])
        if idx == -1:
            break
        else:
            idx_now += idx + 1
            c += 1
    if c == 3:
        ans += 1
print(ans)

Submission status: Accepted

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

count = 0
for i in range(1000):
    password = '{:03}'.format(i)
    s = S
    for j in range(3):
        index = s.find(password[j])
        if index == -1:
            break
        s = s[index + 1:]
    else:
        count += 1

print(count)

Submission status: Accepted

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

count = 0
for i in range(1000):
    num = "{:03}".format(i)
    cursor = -1
    ok = True
    for c in num:
        slice = S[cursor + 1:]
        if c not in slice:
            ok = False
            break
        cursor += slice.index(c) + 1
    if ok:
        count += 1

print(count)

Submission status: Accepted

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

count =0
for i in range(10):
    first =0
    if i in s:
        first = s.index(i)
        for j in range(10):
            second = 0
            if j in s[first+1:n+1]:
                second = s[first+1:n+1].index(j)+first+1
                for k in range(10):
                    if k in s[second+1:n+1]:
                        count += 1
                    else:
                        continue
            else:
                continue
    else:
        continue

print(count)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
ans=0
for i in range(10):
    if str(i) in s:
        first=s.index(str(i))
        for j in range(10):
            if str(j) in s[first+1:]:
                second=first+1+s[first+1:].index(str(j))
                for k in range(10):
                    if str(k) in s[second+1:]:
                        ans+=1
print(ans)

Submission status: Accepted

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

T=[]
c=0
for i in range(10):
  T=S
  i=str(i)
  if i in T[:N-2]:
    indx_i=T.index(i) 
    for j in range(10):
      j=str(j)
      if j in T[indx_i+1:N-1]:
        indx_j=indx_i+T[indx_i+1:].index(j)+1
        for k in range(10):
          k=str(k)
          if k in T[indx_j+1:]:
            c+=1

print(c)

Submission status: Accepted

Solution code:
N = int(input())
S = list((input()))
L = [str(i) for i in range(0,10)]
ALL =[]
for i in L:
    for j in L:
        for k in L:
            ALL.append(i+j+k)
cnt=0    
for a in ALL:
    try:
        
        I1 = S.index(a[0])
        I2 = S[I1+1:].index(a[1])+len(S[:I1+1])
        I3 = S[I2+1:].index(a[2])+len(S[:I2+1])

        if I1<I2 and I2<I3:
            cnt+=1
    except:
        continue
print(cnt)

Submission status: Accepted

Solution code:
import re
def main():
    S = input()
    S = input()
    l = len(S)
    cnt = 0


    for i in range(10):
        iti = 0
        iti = S.find(str(i))
        if iti == -1 :
            continue
        for j in range(10):
            s = S[iti+1:]
            itj = s.find(str(j))
            if itj == -1 :
                continue
            for k in range(10):
                t = s[itj+1:]
                itk = t.find(str(k))
                if itk != -1 :
                    cnt += 1

    print(cnt)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0


for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = 0
            flag2 = 0
            
            for l in range(n):
                if flag1 == 0 and s[l] == str(i):
                    flag1 = 1
                    continue
                
                if flag1 == 1 and flag2 == 0 and s[l] == str(j):
                    flag2 = 1
                    continue
                
                if flag1 == 1 and flag2 == 1 and s[l] == str(k):
                    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 -1 == a:
        continue
    for j in range(10):
        b = S.find(str(j), a + 1)
        if -1 == b:
            continue
        for k in range(10):
            c = S.find(str(k), b + 1)
            if -1 == c:
                continue
            ans += 1
            # print(''.join(map(str, [i, j, k])))

print(ans)

Submission status: Accepted

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

for i in range(10):
  l = S.find(str(i))
  if l == -1:
    continue
  for j in range(10):
    m = S.find(str(j), l + 1)
    if m == -1:
      continue
    for k in range(10):
      n = S.find(str(k), m + 1)
      if n == -1:
        continue
      cnt += 1
print(cnt)

Submission status: Accepted

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

cnt = 0
for i in range(10):
    if i in S:
        k = S.index(i)
        for j in range(10):
            if j in S[k+1:]:
                l = S[k+1:].index(j)
                cnt += len(set(S[k+l+2:]))

print(cnt)

Submission status: Accepted

Solution code:
def Meg_nib(ng,border,lists):
    ng = -1
    ok = len(lists) - 1
    if len(lists) == 0 or border >= lists[ok]:
        return -1
    while(abs(ng - ok) > 1):
        mid = (ok + ng) // 2
        if lists[mid] > border:
            ok = mid
        else:
            ng = mid
    return lists[ok]

N = input()
S = input()
ans = 0
k = 0
k2 = 0
k3 = 0
find = [[]for _ in range(10)]
for i in range(len(S)):
    find[int(S[i])].append(i)
for i in range(10):
    for i2 in range(10):
        for i3 in range(10):
            k = Meg_nib(0,-1,find[i])
            if k == -1:
                break
            k2 = Meg_nib(0,k,find[i2])
            if k2 == -1:
                break
            k3 = Meg_nib(0,k2,find[i3])
            if k3 != -1:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left

def main():
    N = int(input())
    S = tuple(map(int, tuple(input())))
    place = [[] for _ in range(10)]
    for i, c in enumerate(S):
        place[c].append(i)
    ans = 0
    for i in range(10):
        temp = bisect_left(place[i], 0)
        if temp == len(place[i]):
            continue
        idx_1 = place[i][temp]

        for j in range(10):
            temp = bisect_left(place[j], idx_1+1)
            if temp == len(place[j]):
                continue
            idx_2 = place[j][temp]
            
            for k in range(10):
                temp = bisect_left(place[k], idx_2+1)
                if temp == len(place[k]):
                    continue
                ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = 0

for a in range(10):
  if str(a) in S:
    b = S[S.index(str(a))+1:]
    for j in range(10):
      if str(j) in b:
        c = b[b.index(str(j))+1:]
        for k in range(10):
          if str(k) in c:
            ans +=1
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1000):
    temp = '00' + str(i)
    temp = list(temp[-3:])

    check_num = temp.pop(0)
    cnt = 0
    for string in s:
        if check_num == string:
            cnt += 1
            if cnt == 3:
                ans += 1
                break
            check_num = temp.pop(0)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
count = 0
D = 3


def find_number(digits, series):
    global count
    if digits > 1:
        for i in range(0, 10):
            if str(i) in series:
                idx = series.index(str(i))
                find_number(digits - 1, series[idx+1:])
    elif digits == 1:
        for j in range(0, 10):
            if str(j) in series:
                count += 1
    return count


print(find_number(D, S))

Submission status: Accepted

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

for i in range(0, 10):
    if str(i) in S:
        idx = S.index(str(i))
        for j in range(0, 10):
            if str(j) in S[idx+1:]:
                idx2 = S[idx+1:].index(str(j)) + idx + 1
                for k in range(0, 10):
                    if str(k) in S[idx2+1:]:
                        count += 1

print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
Ans = set([])

for i in range(10):
    if str(i) in S:
        a = S.index(str(i))
        S1 = S[a+1:]
        for j in range(10):
            if str(j) in S1:
                b = S1.index(str(j))
                S2 = S1[b+1:]
                for k in range(10):
                    if str(k) in S2:
                        Ans.add(str(100*i + 10*j + k))

print(len(Ans))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
se = set()
for i in range(1000):
    se.add(str(i).zfill(3))

ans = 0
for i in se:
    t1=s.find(i[0])
    if t1!=-1:
        t2=s.find(i[1],t1+1,)
        if t2!=-1:
            t3=s.find(i[2],t2+1,)
            if t3!=-1:
                ans+=1
print(ans)

Submission status: Accepted

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

cnt=0
for i in range(1000):
  num=str(i).zfill(3)
  if num[0] in s:
    inx1=s.index(num[0])
    s2=s[inx1+1:]
    if num[1] in s2:
      inx2=s2.index(num[1])
      s3=s2[inx2+1:]
      if num[2] in s3:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    S = readline().decode('utf-8').strip()
    ans = 0
    for i in range(10):
        x = S.find(str(i), 0, N-2)
        if x != -1:
            for j in range(10):
                y = S.find(str(j), x+1, N-1)
                if y != -1:
                    for k in range(10):
                        z = S.find(str(k), y+1, N)
                        if z != -1:
                            ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for pw in passwords:
    S_copy = S
    FLG = True
    for digit in pw:
        if digit not in S_copy:
            FLG = False
            break
        else:
            index = S_copy.find(digit)
            S_copy = S_copy[index+1:]
    if FLG:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
val1=input()
s=input()
n=int(val1)
count=0
for i in range(0,1000):
    a=str(i).zfill(3) #ゼロうめ
    p=0
    for j in range(0,n):
        if a[p]==s[j]:
            p+=1
            if p==3:
                count+=1
                break
print(count)

Submission status: Accepted

Solution code:
import sys


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


def resolve():
    n = int(input())
    s = input()
    cnt = 0
    for i in range(10):
        x = s.find(str(i))
        if x == -1:
            continue
        else:
            for j in range(10):
                y = s.find(str(j), x + 1)
                if y == -1:
                    continue
                else:
                    for k in range(10):
                        z = s.find(str(k), y + 1)
                        if z == -1:
                            continue
                        else:
                            cnt += 1

    print(cnt)


resolve()

Submission status: Accepted

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

#n=19
#s='3141592653589793238'
psw=[]
ilist=[]
jlist=[]
klist=[]
for i in range(n-2):
    jlist=[]
    if s[i] in ilist:
        continue
    else:
        ilist.append(s[i])
        for j in range(i+1, n-1):
            klist=[]
            #print(j)
            if s[j] in jlist:
                continue
            else:
                jlist.append(s[j])    
                for k in range(j+1, n):
                    if s[k] in klist:
                        continue
                    else:
                        #print(i,j,k)
                        klist.append(s[k])
                        p=s[i]+s[j]+s[k]
                        psw.append(p)
print(len(psw))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
cnt = 0
for i in range(1000):
    num = ''
    num += str(i // 100)
    num += str((i // 10) % 10)
    num += str(i % 10)
    j = 0
    for n in range(N):
        if S[n] == num[j]:
            j += 1
        if j == 3:
            break
    if j == 3:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
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:
n=int(input())
s=[str(x) for x in input()]
exi=[]
for i in range(n):
    if s[i] not in exi:
        exi.append(s[i])
    if len(exi)==10:
        break
ans=0
for i in exi:
    star=s.index(i)
    lex=[]
    for j in range(star+1,n):
        if s[j] not in lex:
            lex.append(s[j])
        if len(lex)==10:
            break
    for k in lex:
        start=s[star+1:n].index(k)+star+1
        ele=[]
        for l in range(start+1,n):
            if s[l] not in ele:
                ele.append(s[l])
        ans += len(ele)

print(ans)

Submission status: Accepted

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

ans=0
for i in range(1000):
    si = str(i).zfill(3)
    now=0
    for ss in s:
        if si[now]==ss:
            now+=1
            if now==3:
                ans+=1
                break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
nums = '1234567890'
lst=[]
res = 0
for i,si in enumerate(S):
  if si in lst: continue
  lst.append(si)
  lst2=[]
  for j,sj in enumerate(S[i+1:N]):
    j+=i+1
    if sj in lst2: continue
    lst2.append(sj)
    res += sum(_ in S[j+1:N]\
 for _ in nums)
print(res)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
cnt=0
for i in range (10):
  i=str(i)
  for j in range (10):
    j=str(j)
    for k in range (10):
      k=str(k)
      if s.count(i)!=0:
        a=s.index(i)
        x=s[(a+1):]
        if x.count(j)!=0:
          b=x.index(j)
          y=x[(b+1):]
          if y.count(k)!=0:
            cnt+=1
 
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
S = input()
cnt=0
for i in range(10):
    x=S.find(str(i),0,n-2)
    if x!=-1:
        for j in range(10):
            y=S.find(str(j),x+1,n-1)
            if y!=-1:
                for k in range(10):
                    z=S.find(str(k),y+1,n)
                    if z!=-1:
                        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
S = input()

st = [set() for _ in range(3)]

for s in S:
    for pre in st[1]:
        st[2].add(pre+s)
    for pre in st[0]:
        st[1].add(pre+s)
    st[0].add(s)
        
print (len(st[2]))

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
S = input()
S = [int(s) for s in S]
ans = 0
for q in product(range(10),repeat=3):
    qi = q[0] # PyPyならこんなことしなくてもOK
    i = 0
    for s in S:
        if s==qi:
            if i==2:
                ans += 1
                break
            else:
                i+=1
                qi = q[i] # PyPyならこんなことしなくてもOK
print (ans)

Submission status: Accepted

Solution code:
n = int(input())

s = input()

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

total = 0
for i in range(1000):
    a = "{0:03d}".format(i)
    B = []
    for j in a:
        B.append(int(j))
    c = -1
    check = 0
    for j in B:
        check = 0
        if len(A[j]) > 0:
            for k in A[j]:
                if k > c:
                    c = k
                    check = 1
                    break
        else:
            break
        if check == 0:
            break
    if check == 1:
        total += 1
print(total)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
count = 0
for i in range(1000):
    pas = format(i).zfill(3)
    a = S[:-2].find(pas[0])
    if a >= 0:
        b = S[a+1:-1].find(pas[1])
        if b >= 0:
            if pas[2] in S[a+b+2:]:
                count += 1
print(count)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
cnt=0
for i in range (10):
  i=str(i)
  for j in range (10):
    j=str(j)
    for k in range (10):
      k=str(k)
      if s.count(i)!=0:
        a=s.index(i)
        x=s[(a+1):]
        if x.count(j)!=0:
          b=x.index(j)
          y=x[(b+1):]
          if y.count(k)!=0:
            cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
from collections import deque
def main():
    N = int(input())
    S = input()
    c = [0] * N
    a = [deque() for _ in range(10)]
    b = [deque() for _ in range(10)]
    for i in range(N):
        a[int(S[i])].append(i)
        b[int(S[i])].append(i)
    for i in range(N):
        x = b[int(S[i])].popleft()
        cc = 0
        for j in range(10):
            if b[j]: cc += 1
        c[i] = cc
    output = 0
    visited = [0] * 10
    for i in range(N):
        a[int(S[i])].popleft()
        if visited[int(S[i])]: continue
        visited[int(S[i])] = 1
        for j in range(10):
            if a[j]:
                x = a[j][0]
                output += c[x]
    print(output)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from bisect import bisect_left
n = int(input())
s = input()
idxs = [[] for _ in range(10)]
for i, j in enumerate(s):
    idxs[int(j)].append(i)
ans = 0
for i in range(10):
    if len(idxs[i])==0:
        continue
    b = idxs[i][0]+1
    for j in range(10):
        if len(idxs[j])==0:
            continue
        m = bisect_left(idxs[j], b)
        if len(idxs[j])==m:
            continue
        m = idxs[j][m]+1
        for k in range(10):
            if bisect_left(idxs[k], m)<len(idxs[k]):
                ans += 1
print(ans)