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
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left

#======================================================#

def main():
    n = II()
    s = IS()
    c = [str(i).zfill(3) for i in range(1000)]
    cnt = 0
    for ci in c:
        id_1 = s.find(ci[0])
        if id_1 == -1: continue
        id_2 = s.find(ci[1], id_1+1)
        if id_2 == -1: continue
        id_3 = s.find(ci[2], id_2+1)
        if id_3 == -1: continue
        cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
s=[int(c) for c in input()]
count=0
for p in range(10):
        if p in s[:n-2]:
            inp=s.index(p)
            for q in range(10):
                if q in s[inp+1:n-1]:
                    inq=s[inp+1:n-1].index(q)+inp+1
                    for r in range(10):
                        if r in s[inq+1:]:
                            count+=1
print(count)

Submission status: Accepted

Solution code:
n=int(input())
s=[int(c) for c in input()]
count=0
for p in range(10):
    for q in range(10):
        for r in range(10):
            if p in s[:n-2]:
                inp=s.index(p)
                if q in s[inp+1:n-1]:
                    inq=s[inp+1:n-1].index(q)+inp+1
                    if r in s[inq+1:]:
                        count+=1
print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = [int(c) for c in input()]

count = 0

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

Submission status: Accepted

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

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

yn=""
icnt=0
for i in range(0,1000):
    yn=""
    stri=format(i,"03d")
    stri=list(map(int,stri))
    if len(m[stri[0]])>0:
        m01=m[stri[0]][0]
    else:
        continue

    for ii in m[stri[1]]:
        if m01<ii:
            m02=ii
            yn="yes2"
            break
    if yn!="yes2":
        continue

    for ii in m[stri[2]]:
        if m02<ii:
            icnt+=1
            break

print(icnt)

Submission status: Accepted

Solution code:

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

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

yn=""
icnt=0
for i in range(0,1000):
    yn=""
    stri=format(i,"03d")
    stri=list(map(int,stri))
    if len(m[stri[0]])>0:
        m01=m[stri[0]][0]
    else:
        continue

    if len(m[stri[1]])>0:
        for ii in m[stri[1]]:
            if m01<ii:
                m02=ii
                yn="yes2"
                break
    if yn!="yes2":
        continue

    if len(m[stri[2]])>0:
        for ii in m[stri[2]]:
            if m02<ii:
                yn="yes3"
                break
    if yn!="yes3":
        continue
    else:
        icnt+=1

print(icnt)

Submission status: Accepted

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

pin=set()

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

    yn=""
for i in range(0,1000):
    yn=""
    stri=format(i,"03d")
    mo=[0]*10
    if len(m[int(stri[0])])>0:
        m01=m[int(stri[0])][0]
    else:
        continue
    if len(m[int(stri[1])])>0:
        for ii in range(len(m[int(stri[1])])):
            if m01<m[int(stri[1])][ii]:
                m02=m[int(stri[1])][ii]
                yn="yes2"
                break
    if yn!="yes2":
        continue

    if len(m[int(stri[2])])>0:
        for ii in range(len(m[int(stri[2])])):
            if m02<m[int(stri[2])][ii]:
                m03=m[int(stri[2])][ii]
                yn="yes3"
                break
    if yn!="yes3":
        continue
    else:
        pin.add(stri)

print(len(pin))

Submission status: Accepted

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

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

for s in S[::-1]:
  for _s in s2:
    s3.add(s+_s)
  for _s in s1:
    s2.add(s+_s)
  s1.add(s)

print(len(s3))

Submission status: Accepted

Solution code:
'''
暗証番号3桁はたかだか10**3の候補。これを全探索で調べるだけ
pythonのindex関数を使用するとオブジェクト内に要素が存在しない場合エラーになる
'''
n = int(input())
s = [int(i) for i in input()]

def my_index(l,x,ind):
    '''
    l: イテラブル(for inで取り出せる)オブジェクト
    x: 探し出す大賞
    ind: イテラブルで探し始める位置（インデックス）
    返り値: 存在する場合はそのインデックス、存在しない場合は-1
    '''
    global n #入力のnと同一のものであるという意味
    if ind == n: #探索するものがない場合
        return -1
    for i in range(ind, n):
        if l[i] == x:
            return i
    else:
        return -1
c = 0
for i in range(10):
    x1 = my_index(s,i,0)
    if x1 != -1:
        for j in range(10):
            x2 = my_index(s,j,x1+1)
            if x2 != -1:
                for k in range(10):
                    x3 = my_index(s,k,x2+1)
                    if x3 != -1:
                        c += 1
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

result = 0
c = [0]*3
for i in range(1000):
    count = 0
    c[0] = str(i // 100)
    c[1] = str((i % 100) // 10)
    c[2] = str(i % 10)
    for j in range(n):
        if(c[count] == s[j]):
            count += 1
        if(count == 3):
            result += 1
            break

print(result)

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:
N = int(input())
S = input()

import re

count = 0
for i in range(10):
    try:
        i_ = re.search(str(i), S).start()
    except:
        continue
    for j in range(10):
        try:
            j_ = re.search(str(j), S[i_+1:]).start()
        except:
            continue
        for k in range(10):
            try:
                k_ = re.search(str(k), S[i_+1+j_+1:]).start()
            except:
                continue

            count += 1

print(count)

Submission status: Accepted

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

passwd = ["{:03}".format(x) for x in range(1000)]
ans = 0

for p in passwd:
    p = iter(p)
    c = next(p)
    for t in s:
        if c == t:
            try:
                c = next(p)
            except:
                ans += 1
                break

print(ans)

Submission status: Accepted

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

passwd = ["{:03}".format(x) for x in range(1000)]
ans = 0

for p in passwd:
    p = iter(p)
    c = next(p)
    n = 0
    for t in s:
        if c == t:
            n += 1
            if n == 3:
                ans += 1
                break
            c = next(p)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
sn = input().strip()

count = 0
for i in range(1000):
    lucky_num = False
    num = str(i).zfill(3)
    c = 0
    for j in range(n):
        if sn[j] == num[c]:
            c += 1
        if c >= 3:
            lucky_num = True
            break
    if lucky_num:
        count += 1

print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
A = [str(i).zfill(3) for i in range(0,1000)]

cnt = 0
for v in A:
    id_1 = s.find(v[0])
    if id_1 == -1:
        continue
    id_2 = s.find(v[1], id_1 + 1)
    if id_2 == -1:
        continue
    id_3 = s.find(v[2], id_2 + 1)
    if id_3 == -1:
        continue
    cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
lst = [0] * 1000
for i in range(1000):
    if len(str(i)) == 1:
        tmp = '00' + str(i)
        lst[i] = tmp
    elif len(str(i)) == 2:
        tmp = '0' + str(i)
        lst[i] = tmp
    else:
        lst[i] = str(i)

cnt = 0
for v in lst:
    id_1 = s.find(v[0])
    if id_1 == -1:
        continue
    id_2 = s.find(v[1], id_1 + 1)
    if id_2 == -1:
        continue
    id_3 = s.find(v[2], id_2 + 1)
    if id_3 == -1:
        continue
    cnt += 1

print(cnt)

Submission status: Accepted

Solution code:

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

  ans = 0

  # PINの方のパターンが少ないので、PINが文字列から再現できるか全探索する
  for i in range(1000):
    pin = str(i).zfill(3)
    cur = 0

    for char in S:
      if(pin[cur] == char):
        cur += 1

        if(cur == 3):
          ans += 1
          break;

  print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import re
N = int(input())
S = input()
ans = 0
tmp = [[m.start() for m in re.finditer(str(i), S)] for i in range(10)]
for i in range(10):
  if len(tmp[i]) == 0:
    continue
  for j in range(10):
    if len(tmp[j]) == 0:
      continue
    for k in range(10):
      if len(tmp[k]) == 0:
        continue
      l = tmp[i][0]
      flag = True
      for m in tmp[j]:
        if m > l:
          flag = False
          break
      if flag:
        continue
      for n in tmp[k]:
        if n > m:
          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))
    # find()は見つからなかったら-1を返す
    if a == -1:
        continue
    for j in range(10):
        # find(探すもの, どこから探すか(, どこまで探すか))
        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:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
lst = [0] * 1000
for i in range(1000):
    if len(str(i)) == 1:
        tmp = '00' + str(i)
        lst[i] = tmp
    elif len(str(i)) == 2:
        tmp = '0' + str(i)
        lst[i] = tmp
    else:
        lst[i] = str(i)

cnt = 0
for v in lst:
    id_1 = s.find(v[0])
    if id_1 == -1:
        continue
    id_2 = s.find(v[1], id_1 + 1)
    if id_2 == -1:
        continue
    id_3 = s.find(v[2], id_2 + 1)
    if id_3 == -1:
        continue
    cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
# D - Lucky PIN
import itertools

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

# 文字列Sから3文字選ぶ組み合わせを数え上げるとTLE
# 暗証番号の組み合わせが高々1,000通りしかないので、
# それごとに条件に該当するかをチェックしてカウントする。
ans = 0
for i, j, k in itertools.product(range(10),repeat=3):
    # i, j, kの組み合わせが起き得るか
    chk = str(i)+str(j)+str(k)
    p = S.find(chk[0])
    q = S.find(chk[1], p+1)
    r = S.find(chk[2], q+1)
    if p!=-1 and q!=-1 and r!=-1:
        ans += 1       
print(ans)

Submission status: Accepted

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


def check(subs):
    start = 0
    for x in subs:
        index = S.find(x, start)
        if index == -1:
            return False
        start = index + 1
    return True


ans = 0
for i in range(1000):
    s = '0' * (3 - len(str(i))) + str(i)
    if check(s):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
S=input()
ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            x=str(i)+str(j)+str(k)
            p=S.find(x[0])
            q=S.find(x[1],p+1)
            r=S.find(x[2],q+1)
            if p!=-1 and q!=-1 and r!=-1:
                ans+=1
print(ans)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    S = input()
    dict = {}
    for cand in range(1000):
        cand_zero = str(cand).zfill(3)
        if cand_zero[0] in S:
            i = S.index(cand_zero[0])
            if cand_zero[1] in S[i+1:]:
                j = len(S[:i+1]) + S[i+1:].index(cand_zero[1])
                if cand_zero[2] in S[j+1:]:
                    k = len(S[:j+1]) + S[j+1:].index(cand_zero[2])
                    if cand_zero not in dict.keys():
                        dict[cand_zero] = 1
    print(len(dict.keys()))



if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from sys import stdin
import itertools

if __name__ == "__main__":
  N = int(input())
  S = input().strip()
  
  nums = "".join([str(i) for i in range(10)])
  
  cnt = 0
  
  for ds in itertools.product(nums, repeat=3):
    invalid = False
    last_index = -1
    for d in ds:
      last_index = S.find(d, last_index+1)
      if last_index < 0:
        invalid = True
        break
      
    if not invalid:
      cnt += 1
    
  print(cnt)

Submission status: Accepted

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

ans = set()
for i in range(10):
    i_index = S.find(str(i))
    if i_index == -1:
        continue
    for j in range(10):
        j_index = S.find(str(j), i_index+1)
        if j_index == -1:
            continue
        for k in range(10):
            k_index = S.find(str(k), j_index+1)
            if k_index == -1:
                continue
            ans.add("{}{}{}".format(i, j, k))

print(len(ans))

Submission status: Accepted

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

ans = 0

for i in range(10):
    if str(i) not in S:
        continue
    ind_i = S.index(str(i))
    for j in range(10):
        if str(j) not in S[ind_i+1:]:
            continue
        ind_j = S[ind_i+1:].index(str(j)) + ind_i+1
        for k in range(10):
            if str(k) in S[ind_j+1:]:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d

N = int(input())
S = input()
#
# ans = 0
# pattern = []
# for x in range(N):
#     for y in range(x + 1, N):
#         if (S[x] + S[y]) not in pattern:
#             ans += len(set(S[y + 1:]))
#             pattern.append(S[x] + S[y])
#
# print(ans)
ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    first = S.find(key[0])
    if first == -1 or first == N:
        continue
    second = S[first + 1:].find(key[1])
    if second == -1 or (first + second + 2) == N:
        continue
    third = S[first + second + 2:].find(key[2])
    if not third == -1:
        # print(first, first + second + 1, first + second + third + 2, key)
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
def test(original: list, nums: str, index: int,
         remain_count: int, results: set, results_1, results_2):
    # 3桁抽出したら終了
    if len(nums) == 1:
        if nums in results_1:
            return
        results_1.add(nums)
    if len(nums) == 2:
        if nums in results_2:
            return
        results_2.add(nums)
    if len(nums) == 3:
        # print("".join(array))
        results.add(nums)
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        test(
            original,
            nums + original[i],
            i + 1,
            remain_count,
            results,
            results_1,
            results_2)

    # この桁を抽出対象としないパターン
    # test(original, array[:], index + 1, remain_count - 1, results)


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

results = set()
results_1 = set()
results_2 = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, "", 0, N - 3, results, results_1, results_2)

print(len(results))

Submission status: Accepted

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

result = 0

for i in range(1000):
    if i < 10:
        temp = "00" + str(i)
    elif i < 100:
        temp = "0" + str(i)
    else:
        temp = str(i)

    cur = 0
    for j in range(3):
        if temp[j] in S[cur:]:
            cur += S[cur:].index(temp[j]) + 1
            if j == 2:
                result += 1
        else:
            break

print(result)

Submission status: Accepted

Solution code:
def main():
    # 入力
    n = int(input())
    s = input()

    set1 = set()
    set2 = set()
    set3 = set()
    for x in s:
        for x2 in set2:
            _x2 = x2+x
            set3.add(_x2)
        for x1 in set1:
            _x1 = x1+x
            set2.add(_x1)
        set1.add(x)

    print(len(set3))


main()

Submission status: Accepted

Solution code:
def main():
    # 入力
    n = int(input())
    s = input()

    set1 = set()
    set2 = set()
    set3 = set()
    for x in s:
        for x2 in set2:
            _x2 = x2+x
            if x2+x not in set3:
                set3.add(_x2)
        for x1 in set1:
            _x1 = x1+x
            if x1+x not in set2:
                set2.add(_x1)
        if x not in set1:
            set1.add(x)

    print(len(set3))


main()

Submission status: Accepted

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

for i in range(10):
    if str(i) in S:
        p = S.index(str(i))
        Si = S[p+1 :]
        for j in range(10):
            if str(j) in Si:
                q = Si.index(str(j))
                Sj = Si[q+1 :]
                for k in range(10):
                    if str(k) in Sj:
                        ct += 1
print(ct)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
import collections
for i in range(10):
  i=str(i)
  x=s.find(i)
  st=s[x+1::]
  if x<0 or n-x<3:pass
  else:
    for j in range(10):
      j=str(j)
      y=st.find(j)
      if y<0 or len(st)-y<2:pass
      else:
        ans+=len(set(st[y+1::]))
print(ans)

Submission status: Accepted

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

count = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            ii = s.find(str(i))
            if ii != -1 and ii <= n-3 and str(j) in s[ii+1:]:
                ji = s.find(str(j), ii+1)
                if ji != -1 and ji <= n-2 and str(k) in s[ji+1:]:
                    count += 1

print(count)

Submission status: Accepted

Solution code:
N = int(input())
n = input()
cnt = 0
for i in range(1000):
    i = str(i).zfill(3)
    first = n.find(i[0])
    if first > -1:
        second = n[first+1 :].find(i[1]) + first + 1
        if n[first+1 :].find(i[1]) > -1:
            if len(n) >= second + 1:
                third = n[second+1 :].find(i[2]) + second + 1
                if n[second + 1 :].find(i[2]) > -1:
                    cnt += 1
    first, second, third = 0,0,0
print(cnt)

Submission status: Accepted

Solution code:
import itertools
from sys import stdin

N = list(map(int, stdin.readline().strip().split()))[0]
st = list(stdin.readline().strip())
count = 0
stt = set(st)
stt = list(stt)
num = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
num = [s for s in num if s in stt]
num_list = ["".join(i) for i in itertools.product(num, repeat=3)]
cnt = 0
for number in num_list:

    for i in range(N):
        if number[cnt] == st[i]:
            cnt += 1
            if cnt==2:
                if number[cnt] in st[i+1:]:
                    count+=1
                break
    cnt = 0

print(count)

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  S = list(map(int,input()))
  ans = 0
  for i in range(10):
    for j in range(10):
      for k in range(10):
        flg = False
        flg2 = False
        for x in range(N):
          if flg2:
            break
          if not flg:
            if S[x] == i:
              flg = True
          else:
            if S[x] == j:
              flg2 = True
              if k in S[x+1:]:
                ans +=1
  print(ans)
main()

Submission status: Accepted

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

cnt=0
for i in range(1000):
    num=str(i).zfill(3)
    add=0
    for j in s:
        if num[add]==j:add +=1
        if add==3:
            cnt +=1
            break
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
memo_1 = set()
memo_2 = set()
memo_3 = set()

for i in range(N):
    for ii in memo_2:
        memo_3.add(ii + S[i])
    for j in memo_1:
        memo_2.add(j + S[i])
    memo_1.add(S[i])


#print(memo_1)
#print(memo_2)
#print(memo_3)
print(len(memo_3))

Submission status: Accepted

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

count = 0

s_set = set([])
for i in range(n):
    t_set = set([])
    if (s[i] in s_set):
        continue
    t = s[i+1:]
    s_set.add(s[i])
    for j in range(n-(i+1)):
        if(t[j] in t_set):
            continue
        u = t[j+1:]
        count += len(set(u))
        t_set.add(t[j])
    
    
print(count)

Submission status: Accepted

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

#print( N,S )   

cnt = 0
s_flgs = [[False for _ in range(10) ] for _ in range(3)]

for i1 in range(N-2):
    if s_flgs[0][int(S[i1])] == True:
        continue
    s_flgs[0][int(S[i1])] = True
    s_flgs[1] = [False for _ in range(10) ]
    for i2 in range(i1+1,N-1):
        if s_flgs[1][int(S[i2])] == True:
            continue
        s_flgs[1][int(S[i2])] = True
        s_flgs[2] = [False for _ in range(10) ]
        for i3 in range(i2+1, N):
            if s_flgs[2][int(S[i3])] == True:
                continue
            s_flgs[2][int(S[i3])] = True
            cnt = cnt + 1
            #ppp = S[i1]+S[i2]+S[i3]
            #print(i1,i2,i3, ppp)

print(cnt)

Submission status: Accepted

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

def check(v):
    now = 0
    for i in S:
        if i == v[now]:
            now += 1
        if now >= 3:
            return True
    return False

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            t = str(i) + str(j) + str(k)
            if check(t):
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
l=[[]for i in range(11)]
for i in range(n):
    d=int(s[i])
    l[d].append(i)
ans=0
le=[len(f) for f in l]
from bisect import bisect_left as bl,bisect_right as br
for i in range(0,1000):
    ss=str(i).zfill(3)

    now=-1
    for x in ss:
        c=br(l[int(x)],now)
        if c==le[int(x)]:break
        now=l[int(x)][c]
    else:

        ans+=1
print(ans)

Submission status: Accepted

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

s1 = set()  # 一桁の文字集合
s2 = set()  # 二桁の文字集合
s3 = set()  # 三桁の文字集合

# 30,000 * 100
for c in S:
  for c2 in s2:
    s3.add(c2 + c)
  for c1 in s1:
    s2.add(c1 + c)
  s1.add(c)
  
print(len(s3))

Submission status: Accepted

Solution code:
import re
n=int(input())
s=input()
ans=0
for i in range(1000):
      a='00'+str(i)
      a=a[-3:]
      s0=s
      m=s0.find(a[0])
      if m<0:
            continue
      s0=s0[m+1:]
      m=s0.find(a[1])
      if m<0:
            continue
      s0=s0[m+1:]
      m=s0.find(a[2])
      if m<0:
            continue
      ans+=1
print(ans)

Submission status: Accepted

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

for i in range(10):
  if str(i) in S:
    p = S.index(str(i))
    S2 = S[p + 1:]
    for j in range(10):
      if str(j) in S2:
        q = S2.index(str(j))
        S3 = S2[q + 1:]
        for k in range(10):
          if str(k) in S3:
            con += 1

print(con)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
#初めて出てきたときのインデックスをめも
lmemo=[-1]*10
rmemo=[-1]*10
for i in range(N-2):
    ls=int(S[i])
    rs=int(S[-(i+1)])
    if lmemo[ls]==-1:
        lmemo[ls]=i
    if rmemo[rs]==-1:
        rmemo[rs]=N-(i+1)
ans=0
#print(lmemo,rmemo)
for l in lmemo:
    for r in rmemo:
        if l+1<r and l>=0 and r>=0:
            ans+=len(set(S[l+1:r]))


print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    s=input()
    ans=0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                if str(i) in s:
                    index_i=s.index(str(i))
                    s1=s[index_i+1:]
                    if str(j) in s1:
                        index_j=s1.index(str(j))
                        s2=s1[index_j+1:]
                        if str(k) in s2:
                            ans+=1
    print(ans)

if __name__=='__main__':
    main()

Submission status: Accepted

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

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

    lst = [[] for _ in range(10)]
    numset = set()

    for i in range(n):
        num = int(s[i])
        lst[num].append(i)

    cnt = 0
    for i in range(10):
        if lst[i] == []:
            continue
        for k in range(10):
            if lst[k] == []:
                continue
            p_min = lst[i][0]
            p_max = lst[k][-1]
            if p_max - p_min <= 1:
                continue
            for j in range(10):
                for p in lst[j]:
                    if p_min < p < p_max:
                        cnt += 1
                        break
                    elif p >= p_max:
                        break

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d
n = int(input())
s = input()

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            num = str(i) + str(j) + str(k)
            t = 0
            p = 0
            while t < 3 and p < n:
                if num[t] == s[p]:
                    t += 1
                p += 1
            if t == 3:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int,input()))
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            a,b,c = -1,-1,-1
            for l in range(n):
                if s[l] == i:
                    a = l
                    break
            for l in range(a+1,n):
                if s[l] == j:
                    b = l
                    break
            for l in range(b+1,n):
                if s[l] == k:
                    c = l
                    break
            if a == -1 or b == -1 or c == -1: pass
            else: ans += 1
print(ans)

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

a = ["0","1","2","3","4","5","6","7","8","9"]

c = 0

for i in a:
	for j in a:
		for k in a:
			d = s.find(i)
			if d == -1:
				continue
			e = s[d+1:].find(j)
			if e == -1:
				continue
			e += d+1
			f = s[e+1:].find(k)
			if f == -1:
				continue
			c += 1
print (c)

Submission status: Accepted

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

Submission status: Accepted

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

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

    """
    3桁の数字がijkだとして、それを作れるかを全探索で数えていく
    平均計算量は、(3750*10)*(7500*10)*(15000*10) = O(10**4 * 10**4 * 10**5) = O(10**13)
    """

    ans = 0
    for i in range(0, 10):
        idx = S.find(str(i))  # 平均計算量15000
        if idx == -1:
            continue
        for j in range(0, 10):
            jdx = S[idx+1:].find(str(j))  # 平均計算量7500
            if jdx == -1:
                continue
            for k in range(0, 10):
                if str(k) in S[idx+1+jdx+1:]:  # 平均計算量3750
                    ans += 1

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n=int(input())
s=input()
num=[]
for i in range(1000):
    p=str(i)
    while len(p)<3:
        p="".join(["0",p])
    num.append(p)
ans=0
for k in range(len(num)):
    q=0
    for i in range(len(s)):
        if q==3:
            break
        elif num[k][q]==s[i]:
            q+=1
    if q==3:
        ans+=1
print(ans)

Submission status: Accepted

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

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

ans = 0
for c in candidates_l:
    if c[0] in s_l:
        tmp1 = s_l.index(c[0])
        if c[1] in s_l[tmp1+1:]:
            tmp2 = s_l[tmp1+1:].index(c[1])
            if c[2] in s_l[tmp1+tmp2+2:]:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = [int(i) for i in input().split()]
s = input()
a = set([""])
ans = set()
for i in s:
    b = a.copy()
    for j in a:
        if len(j) == 2:
            ans.add(j + i)
        else:
            b.add(j + i)
    a = b
print(len(ans))