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

    ans = 0
    tmp = list(map(str, range(0,10)))

    def myindex(Stringlist, Checkstr, default = -1):
        if Checkstr in Stringlist:
            return Stringlist.index(Checkstr)
        else:
            return default


    for V1 in tmp:
        C1 = myindex(S[:N-2], V1, default = -1)
        if C1 == -1:
            continue
        for V2 in tmp:
            C2 = myindex(S[C1+1:N-1], V2, default = -1)
            if C2 == -1:
                continue
            for V3 in tmp:
                C3 = myindex(S[C1+C2+2:], V3, default = -1)
                if C3 == -1:
                    continue
                #print("str:{}, index:{}/{}/{}".format(V1+V2+V3,C1, C1+1+C2, C1+1+C2+1+C3))
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
S = input()
ans = 0
for v in range(1000):
    used = [False for _ in range(len(S))]
    v = str(v).zfill(3)
    flag = [False for _ in range(3)]
    idx = 0
    for i in range(len(S)):
        if not flag[0] and v[0] == S[i] and not used[i]:
            used[i] = True
            flag[0] = True
            continue
        if not flag[1] and v[1] == S[i] and not used[i] and flag[0]:
            used[i] = True
            flag[1] = True
            continue
        if not flag[2] and v[2] == S[i] and not used[i] and flag[1]:
            used[i] = True
            flag[2] = True
            break
    if sum(flag) == 3:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
count=0
for i in range(0,10):
    for j in range(0,10):
        for k in range(0,10):
            look=0
            check=0
            while N-1>=look:
                if check==0:
                    if S[look]==str(i):
                        check=1
                elif check==1:
                    if S[look]==str(j):
                        check=2
                elif check==2:
                    if S[look]==str(k):
                        check=3
                look+=1
            if check==3:
                count+=1

print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 31 13:15:15 2020

@author: liang
"""

"""
1.全探索 i,j,kを固定してそれぞれの番号を調べる => O(N^3)
2.全探索3桁の暗証番号000~999が文字列Sにあるか調べる =>O(N)
"""
"""
解1.コード　=> TLE
#使用済みリストを用意することで枝刈り
N = int(input())
S = list(map(int,input().split()))
num_used = [list() for i in range(10)]
numbers = list()
for i in range(N):
    for j in range(i+1, N):
        if S[j] in num_used[S[i]]:
            continue
        else:
            num_used[S[i]].append(S[j])
            for k in range(j+1,N):
                number = str(S[i]) + str(S[j]) + str(S[k])
                if number not in numbers:
                    numbers.append(number)
print(len(numbers))
"""
#解2コード => O(N)
N = int(input())
S = input()
ans = 0
for i in range(1000):
#0で埋めるプログラム
#    a = i//100
#    b = i%100//10 ###400//10 = 40
#    c = i%10
#    num = str(a) + str(b) + str(c) 
    t = str(i).zfill(3) #0で埋めるメソッド
#フラグを立てて探す => O(N)    
#    flag = 0
#    for j in range(N) :
#        if S[j] == t[flag]:
#            flag += 1
#        if flag == 3:
#            ans += 1
    a = S.find(t[0])
    b = S.find(t[1],a+1)
    c = S.find(t[2],b+1)
    if a != -1 and b != -1 and c != -1:
        ans += 1
print(ans)

Submission status: Accepted

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


def canMakeNumber(k, s):
    k = str(k).zfill(3)
    dic = {0: False, 1: False, 2: False}
    for t in s:
        if dic[0] is False:
            if t == k[0]:
                dic[0] = True
        else:
            if dic[1] is False:
                if t == k[1]:
                    dic[1] = True
            else:
                if dic[2] is False:
                    if t == k[2]:
                        dic[2] = True
                        return True
                else:
                    return True
    return False


N = int(input())
S = input()
ans = 0
for i in range(0, 1000):
    if canMakeNumber(i, str(S)):
        ans += 1
print(ans)

Submission status: Accepted

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

N = int(input())
S = input()
ans = 0
for i in range(0, 1000):
    k = str(i).zfill(3)
    dic = {0: False, 1: False, 2: False}
    for t in str(S):
        if dic[0] is False:
            if t == k[0]:
                dic[0] = True
        else:
            if dic[1] is False:
                if t == k[1]:
                    dic[1] = True
            else:
                if dic[2] is False:
                    if t == k[2]:
                        dic[2] = True
                        ans += 1
                        break
                else:
                    ans += 1
                    break

print(ans)

Submission status: Accepted

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

def canMakeNumber(k, s):
    k = str(k).zfill(3)
    dic = {0: False, 1: False, 2: False}
    for t in s:
        if dic[0] is False:
            if t == k[0]:
                dic[0] = True
        else:
            if dic[1] is False:
                if t == k[1]:
                    dic[1] = True
            else:
                if dic[2] is False:
                    if t == k[2]:
                        dic[2] = True
                        return True
                else:
                    return True
    return False


N = int(input())
S = input()
ans = 0
for i in range(0, 1000):
    if canMakeNumber(i, str(S)):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = input()
ans = 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:
                        ans += 1
print(ans)

Submission status: Accepted

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

ret=0

for i in range(1000):
    pin="{:0>3}".format(i)
    
    pos=0
    begin=0
    while pos<3:
        begin=S.find(pin[pos],begin)+1
        if begin==0:
            break

        pos+=1
    else:
        ret+=1

print(ret)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=0
for i in range(1000):
    t=str(i).zfill(3)
    a=S.find(t[0])
    b=S.find(t[1],a+1)
    c=S.find(t[2],b+1)
    if a!=-1 and b!=-1 and c!=-1:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=[set(),set(),set()]
for i in S:
    for j in ans[1]:
        ans[2].add(j+i)
    for j in ans[0]:
        ans[1].add(j+i)
    ans[0].add(i)
print(len(ans[2]))

Submission status: Accepted

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

for i in range(10):
    first = False
    second = False
    for j in range(N):
        if not first:
            if S[j] == 0:
                first = True
                continue
        elif not second:
            if S[j] == 0:
                second = True
                continue
        else:
            if S[j] == i:
                ans += 1
                break

for i in range(10, 100):
    first = False
    second = False
    second_v = i // 10
    third_v = i % 10
    for j in range(N):
        if not first:
            if S[j] == 0:
                first = True
                continue
        elif not second:
            if S[j] == second_v:
                second = True
                continue
        else:
            if S[j] == third_v:
                ans += 1
                break

for i in range(100, 1000):
    first = False
    second = False
    first_v = i // 100
    second_v = i // 10 % 10
    third_v = i % 10
    for j in range(N):
        if not first:
            if S[j] == first_v:
                first = True
                continue
        elif not second:
            if S[j] == second_v:
                second = True
                continue
        else:
            if S[j] == third_v:
                ans += 1
                break

print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N = int(input())
    S = input()

    ans = 0
    for i in range(1000):
        s = str(i).zfill(3)
        i0 = S.find(s[0])
        if i0 != -1:
            i1 = S[i0+1:].find(s[1])
            if i1 != -1:
                i2 = S[i0+i1+2:].find(s[2])
                if i2 != -1:
                    ans += 1

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt = 0
for i in range(10):
    if str(i) in s:
        idx_i = s.index(str(i)) + 1
        t = s[idx_i:]
        
        for j in range(10):
            if str(j) in t:
                idx_j = t.index(str(j)) + 1
                u = t[idx_j:]
                
                for k in range(10):
                    if str(k) in u:
                        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N = input()
S = input()
all = "0123456789"
result = 0
for i in all:
    Si = S.find(i)
    if Si != -1:
        for j in all:
            Sj = S[Si+1:].find(j)
            if Sj != -1:
                for k in all:
                    Sk = S[Si+Sj+2:].find(k)
                    if Sk != -1:
                        result += 1

print(result)

Submission status: Accepted

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools
from operator import mul

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

N = int(input())
s = input()

items_list = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp = [str(i), str(j), str(k)]
            items_list.append(tmp)

ans = 0
for pin in items_list:
    cnt = 0
    for i in range(0, len(s), 1):
        if s[i] == pin[cnt]:
            cnt += 1
            if cnt == 3:
                ans += 1
                break

print(ans)

Submission status: Accepted

Solution code:
import bisect
n=int(input())
s=list(str(input()))
cnt=0
index={}
for i in range(n):
  v=s[i]
  if v not in index.keys():
    index[v]=[]
  index[v].append(i)
for i in range(1000):
  i_str='0'*(3-len(str(i)))+str(i)
  x,y,z=i_str[0],i_str[1],i_str[2]
  if x in index.keys() and y in index.keys() and z in index.keys():
    a=index[x][0]
    v=bisect.bisect_left(index[y],a+1)
    if v<len(index[y]):
      b=index[y][v]
      if b<=a or b>=n:
        pass
      else:
        v=bisect.bisect_left(index[z],b+1)
        if v<len(index[z]):
          c=index[z][v]
          if c<=b or c>=n:
            pass
          else:
            cnt+=1
print(cnt)

Submission status: Accepted

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

ans = 0
for n in range(1000):
    c = [n // 100, (n // 10) % 10, n % 10]
    f = 0
    for i in range(N):
        if S[i] == str(c[f]):
            f += 1
        if f == 3:
            break
    
    if f == 3:
        ans += 1
        
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
from itertools import product
n = int(input())
s = input()

ans = 0
for x, y, z in product(range(10), repeat=3):
    index_1 = s.find(str(x))
    index_2 = s.find(str(y), index_1+1)
    index_3 = s.find(str(z), index_2+1)
    if index_1 != -1 and index_2 != -1 and index_3 != -1:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
li = []
b_li1 = []
b_li2 = []
for i in range(0, n-2):
    if s[i] in b_li1:
        continue
    b_li1.append(s[i])
    for j in range(i+1, n-1):
        if s[i]+s[j] in b_li2:
            continue
        b_li2.append(s[i]+s[j])
        for k in range(j+1, n):
            li.append(s[i]+s[j]+s[k])
print(len(set(li)))

Submission status: Accepted

Solution code:
import itertools

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

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

for i in range(0,10):
    for j in range(0,10):
        for k in range(0,10):
            a = 0
            b = 0
            
            if len(li[i]) > 0:
                a = li[i][0]
                
                for d in li[j]:
                    if d > a:
                        b = d
                        break
                else:
                    break
                
                for e in li[k]:
                    if e > b:
                        ans += 1
                        break
                    
print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()


N = i_i()
S = i_s()

ans = 0
for i in range(1000):
    s = str(i).zfill(3)
    
    i = S.find(s[0])
    if i == -1:
        continue

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

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

    ans += 1

print(ans)

Submission status: Accepted

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

def is_pin(pp):
    idx = 0
    for p in pp:
        find_idx = s[idx:].find(p)
        nxt = idx + find_idx
        if find_idx == -1:
            return False
        else:
            idx = nxt+1
    return True
        
count = 0
for pin_n in range(1000):
    pin = str(pin_n).zfill(3)
    if is_pin(pin):
        count += 1
print(count)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = str(input())
    
    res = 0
    for i in range(1000):
        t = str(i).zfill(3)
        pos = 0
        for j in s:
            if t[pos] == j:
                pos += 1
            if pos == 3:
                res += 1
                break
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N = int(input())
    S = input()

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

        cur = 0
        for c in S:
            if password[cur] == c:
                cur += 1
            if cur == 3:
                result += 1
                break

    print(result)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
#先頭から見て行って、000~999を含むかを確かめる
# strに直して、あったら次の文字にいく
ans = 0
for i in range(1000):
  num = str(i).zfill(3)
  pos = 0
  for j in range(n):
    if num[pos] == s[j]:
      pos += 1
      if pos == 3: 
        ans += 1
        break
print(ans)

Submission status: Accepted

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

for i in range(1000):
    t = str(i).zfill(3)
    isExists = [False]*3
    pos = 0
    for (p,j) in enumerate(t):
        while pos<n:
            if s[pos]==j:
                pos += 1
                isExists[p] = True
                break
            pos += 1
    if all(isExists):
        ans += 1

print(ans)

Submission status: Accepted

Solution code:

def resolve():

    N=int(input())
    s = str(input())


    l=['%03d'%(p) for p in range(0,10**3)]
    ans=[]
    for i in l:
        if i[0] in s:
            s0=s.index(i[0])
            if i[1] in s[s0+1:]:
                s1=s[s0+1:].index(i[1])
                if i[2] in s[s0+1:][s1+1:]:
                    ans.append(i)



    print(len(set(ans)))


resolve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import defaultdict
mod = 10**9+7

N = int(input())
S = [int(x) for x in input()[:-1]]
left = defaultdict(lambda : [10**9]*10)
right = defaultdict(lambda : [-10**9]*10)
cnt = [0]*10
flg = [0]*10
for i, x in enumerate(S):
    if flg[x] == 0:
        flg[x] = 1
        left[x] = cnt[:]
    right[x] = cnt[:]
    cnt[x] += 1
ans = 0
for i in range(1000):
    a, b, c = i%1000//100, i%100//10, i%10
    if a == b:
        if right[c][b]-left[a][b] > 1:
            ans += 1
    elif right[c][b]-left[a][b] > 0:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
list=["" for _ in range(1000)]
ans=0
for i in range(1000):
  t=str(i)
  u="0"*(3-len(t))+t
  j=0
  exi=0
  p=u[0]
  for x in s:
    if x==p:
      j+=1
      if j==3:
        ans+=1
        break
      p=u[j]
    

  









print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
list=["" for _ in range(1000)]
ans=0
for i in range(1000):
  t=str(i)
  u="0"*(3-len(t))+t
  j=0
  exi=0
  p=u[0]
  for x in s:
    if x==p:
      j+=1
      if j==3:
        ans+=1
        break
      p=u[j]
    

  









print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
r=[[] for i in range(10)]
for i in range(N):
    r[int(S[i])].append(i)
#print(r)
ans=0
import bisect
for i in range(0,10):
    for j in range(0,10):
        for k in range(0,10):
            #print(r[i],r[j],r[k])
            if (len(r[i])*len(r[j])*len(r[k]))>0:
                le=bisect.bisect_right(r[j],r[i][0])
                ri=bisect.bisect_left(r[j],r[k][-1])
                if le<ri:
                    ans+=1
                    #print(i,j,k)
print(ans)

Submission status: Accepted

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


def solve(N: int, S: str):
    counter = 0
    for i in range(1000):
        c = i % 10
        b = (i // 10) % 10
        a = (i // 100) % 10
        aa = S.find(str(a))
        if aa != -1 and aa < N - 2:
            bb = S[aa+1:].find(str(b))
            if bb != -1 and bb < N - 1:
                cc = S[aa+bb+2:].find(str(c))
                if cc != -1:
                    counter += 1
    print(counter)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: int
    solve(N, S)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n,s=int(input()),input()

cnt=0
flag1=[]
ans=[]
for i in range(n-2):
    flag2=[]
    if s[i] in flag1:continue
    flag1.append(s[i])
    for j in range(i+1,n-1):
        if s[j] in flag2:continue
        flag2.append(s[j])
        for k in range(j+1,n):
            ans.append(s[i]+s[j]+s[k])
#print(ans,flag1,flag2)
print(len(set(ans)))

Submission status: Accepted

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

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

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
mya = [0]*3
       
ans = 0
for i in range(1000):
    q = '{:0=3}'.format(i)

    keta = 0
    for j in range(n):
        if s[j] == q[keta]:
            keta += 1
            if keta == 3:
                break
    if keta == 3:
        ans += 1
            
print(ans)

Submission status: Accepted

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

    for i in range(10):
        idx1 = S.find(str(i))
        if idx1 < 0:
            continue
        for j in range(0, 10):
            idx2 = S.find(str(j), idx1+1)
            if idx2 < 0:
                continue
            for k in range(0, 10):
                idx3 = S.find(str(k), idx2+1)
                if idx3 < 0:
                    continue
                ans += 1
    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
from collections import Counter


def inpl():
    return list(map(int, input().split()))


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

cS = Counter(S)

for i in range(10):
    cS[str(i)] = cS.get(str(i), 0)

ans_1 = {}
ans_2 = {}
ans_3 = {}
for s in S:
    for v in ans_2.keys():
        ans_3[v + s] = True
    for v in ans_1.keys():
        ans_2[v + s] = True
    ans_1[s] = True

print(len(ans_3))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
for aim in range(100):
  sa=str(aim)
  if aim<=9:sa="0"+sa
  cnt=0;k=-1
  for i in range(n):
    if sa[cnt]==s[i]:cnt+=1
    if cnt==2:k=i;break
  else:continue
  ans+=len(set(list(s[k+1:])))
print(ans)

Submission status: Accepted

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

res = 0
for i in range(10):
  idx_1 = S.find(str(i))
  if (idx_1 == -1) or (idx_1 > N-3):
    continue
  for j in range(10):
    idx_2 = S[idx_1+1:].find(str(j))
    if (idx_2 == -1) or (idx_2 > N-2):
      continue
    for k in range(10):
      idx_3 = S[idx_1+1+idx_2+1:].find(str(k))
      if idx_3 != -1:
        res += 1

print(res)

Submission status: Accepted

Solution code:
import re

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

res = 0
fmt = "[0-9]*{}[0-9]*{}[0-9]*{}[0-9]*"
for i in range(10):
  idx_1 = S.find(str(i))
  if (idx_1 == -1) or (idx_1 > N-3):
    continue
  for j in range(10):
    idx_2 = S[idx_1+1:].find(str(j))
    if (idx_2 == -1) or (idx_2 > N-2):
      continue
    for k in range(10):
      idx_3 = S[idx_1+1+idx_2+1:].find(str(k))
      if idx_3 != -1:
        res += 1

print(res)

Submission status: Accepted

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

import collections as co
d=co.defaultdict(list)
for x,i in enumerate(a):
    d[i].append(x)

se=set()
for i in d.keys():
    se.add(i)

for pin in range(1000):
    pin=str(pin)
    pin=pin.zfill(3)
    now=-1
    cnt=0
    flag=True
    
    for num in pin:
        if num not in se:
            flag=False
    
        for i in d[num]:
            if i>now:
                now=i
                cnt+=1
                break

    if cnt==3 and flag==True:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
result = 0
for i in range(1000):
    x = format(i, "03")
    indx = s.find(x[0],0)
    indx1 = s.find(x[1], indx+1)
    indx2 = s.find(x[2], indx1+1)
    if indx>=0 and indx1>0 and indx2>0:
        result += 1

print(result)

Submission status: Accepted

Solution code:
N = int(input())

s1 = set()
s2 = set()
s3 = set()

for s in input():
  if s2:
    for s2_sub in s2:
      s3 |= {s2_sub+s}
  if s1:
    for s1_sub in s1:
      s2 |= {s1_sub+s}
  s1 |= {s}
  
print(len(s3))

Submission status: Accepted

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

    ans = set()
    for i in range(1000):
        str_i = str(i).zfill(3)
        idx1 = S.find(str_i[0], 0)
        idx2 = S.find(str_i[1], idx1 + 1)
        idx3 = S.find(str_i[2], idx2 + 1)
        if idx1 != -1 and idx2 != -1 and idx3 != -1:
            ans.add(str_i)


    return print(len(ans))

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

    return print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N = int(input())
S = input()
anss = []
for i in range(1000):
    str_i = str(i).zfill(3)
    idx1 = S.find(str_i[0], 0)
    idx2 = S.find(str_i[1], idx1 + 1)
    idx3 = S.find(str_i[2], idx2 + 1)
    if idx1 != -1 and idx2 != -1 and idx3 != -1:
        anss.append(str_i)

print(len(set(anss)))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
A=[0]*N
for i in range(N):
 A[i]=int(S[i])
b=0
for i in range(1000):
 i1=int(i/100)
 i2=int((i-i1*100)/10)
 i3=i%10
 a=0
 for j in range(N):
  if a==0:
   if A[j]==i1:
    a+=1
  elif a==1:
   if A[j]==i2:
    a+=1
  else:
   if A[j]==i3:
    b+=1
    break
print(b)

Submission status: Accepted

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

for i in range(1000):
  num = str(i).zfill(3)
  check1 = S.find(num[0])
  check2 = S.find(num[1], check1+1)
  check3 = S.find(num[2], check2+1)
  if check1 != -1 and check2 != -1 and check3 != -1:
    cnt += 1
print(cnt)

Submission status: Accepted

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

for i in range(1000):
    num = str(i).zfill(3)
    check1 = S.find(num[0])
    check2 = S.find(num[1],check1+1)
    check3 = S.find(num[2],check2+1)
    if check1 != -1 and check2 != -1 and check3 != -1:
        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)
    x = s.find(num[0])
    y = s.find(num[1], x+1)
    z = s.find(num[2], y+1)
    if x != -1 and y != -1 and z != -1:
            ans += 1
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1000):
    pin = str(i).zfill(3)
    p = s.find(pin[0])
    if p == -1 or p >= n - 1:
        continue
    q = s.find(pin[1], p+1)
    if q == -1 or q == n - 1:
        continue
    r = s.find(pin[2], q+1)
    if r == -1:
        continue
    ans += 1

print(ans)

Submission status: Accepted

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

done_1 = set()
done_2 = set()
done_3 = set()
for i in range(n):
    if s[i] in done_1:
        continue
    for j in range(i+1, n):
        if s[i] + s[j] in done_2:
            continue
        for k in range(j+1, n):
            pin = s[i] + s[j] + s[k]
            done_3.add(pin)
        done_2.add(pin[:2])
    done_1.add(pin[0])
print(len(done_3))

Submission status: Accepted

Solution code:
#!/usr/bin/env pytho3
n = int(input())
s = input()
# D - Lucky PIN
# N桁の数字から３桁だけを残して、左から読む時何種類できるか？
# 存在しうる数字は10**3なのでそれぞれの文字に対してO(n)ならいける
# 左から順番に目的の数字が出てくるまで操作すれば良い
ans = 0
for i in range(0,1000):
    number = str(i).zfill(3)
    digit = 0
    for j in s:
        if number[digit] == j:
            digit += 1
            if digit == 3:
                ans += 1
                break

print(ans)
"""
pos = [[0 for i in range(4)] for j in range(10)] # 0..9に対して、1,2,3番目に出現するposと何回出現しているか？
#print(pos)
for i in range(n):
    #print(pos)
    current_em = pos[int(s[i])][3]
    if current_em < 3:
        pos[int(s[i])][current_em] = i
        pos[int(s[i])][3] += 1
print(pos)
current_pos = -1
ans = 0
for i in range(10):
    if len([x for x in pos[i] if x > current_pos]) == 0:break
    current_pos = min([x for x in pos[i] if x > current_pos])
    for j in range(10):
        if len([x for x in pos[j] if x > current_pos]) == 0:break
        current_pos = min([x for x in pos[j] if x > current_pos])
        for k in range(10):
            if len([x for x in pos[k] if x > current_pos]) == 0:break
            ans += 1
print(ans)"""

Submission status: Accepted

Solution code:
from bisect import bisect
N = int(input())
S = input()
A = [[] for i in range(10)]
for i in range(N):
    s = S[i]
    A[int(s)].append(i)
for i in range(10):A[i].append(float("inf"))
ans = 0
for i in range(1000):
    s = str(i).zfill(3)
    a = A[int(s[0])][0]
    if a==float("inf"):continue
    b = A[int(s[1])][bisect(A[int(s[1])],a)]
    if b==float("inf"):continue
    c = A[int(s[2])][bisect(A[int(s[2])],b)]
    if c==float("inf"):continue
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
import math
from collections import deque
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()

ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      num = str(i) + str(j) + str(k)
      st = 0
      for n in num:
        for x in range(st, N):
          if s[x] == n:
            st = x+1
            break
        else:
          break
      else:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
cnt=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:
            cnt+=1
print(cnt)

Submission status: Accepted

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

for i in range(100):
    num_set = set()
    target = str(i).zfill(2)
    j = 0
    for s in S:
        if j<2 and s == target[j]:
            j += 1
        elif j==2:
            num_set.add(s)
    cnt += len(num_set)
print(cnt)

Submission status: Accepted

Solution code:
def search_substr(S, subs):
    idx = 0
    ret = False
    for s in S:
        if s == subs[idx]:
            idx += 1
            if idx == len(subs):
                ret = True
                break
                
    return ret

def solve():
    N = int(input())
    S = input()
    
    # 愚直にやると↓だが、まあ間に合わないだろう
    # ret = len(set(for s in combination(S, 3)))
    ret = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                subs = '{0}{1}{2}'.format(i,j,k)
                if search_substr(S, subs):
                    ret += 1
                    
    print(ret)
    
solve()