Problem:


Score: 400 points

Problem Statement

AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code.

The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.

How many different PIN codes can he set this way?

Both the lucky number and the PIN code may begin with a 0.

Constraints

4 \leq N \leq 30000

S is a string of length N consisting of digits.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of different PIN codes Takahashi can set.

Sample Input 1

4
0224

Sample Output 1

3

Takahashi has the following options:

Erase the first digit of S and set 224.

Erase the second digit of S and set 024.

Erase the third digit of S and set 024.

Erase the fourth digit of S and set 022.

Thus, he can set three different PIN codes: 022, 024, and 224.

Sample Input 2

6
123123

Sample Output 2

17

Sample Input 3

19
3141592653589793238

Sample Output 3

329



Sample input:
4
0224


Sample output:
3

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(0,1000):
    pin = str(i).zfill(3)
    #print(pin)
    first = False
    second = False
    for s in S:
        if (not first) and s == pin[0]:
            first = True
        elif first and (not second) and s == pin[1]:
            second = True
        elif second and s == pin[2]:
            ans += 1
            break
print(ans)

Submission status: Accepted

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

num1, num2, num3 = set([]), set([]), set([])
for i in range(n):
    if s[i] in num1:
        continue
    num1.add(s[i])
    for j in range(i + 1, n):
        tmp2 = s[i] + s[j]
        if tmp2 in num2:
            continue
        num2.add(tmp2)
        for k in range(j + 1, n):
            num3.add(tmp2 + s[k])
print(len(num3))

Submission status: Accepted

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

num1, num2, num3 = set([]), set([]), set([])
for i in range(n):
    if s[i] in num1:
        continue
    num1.add(s[i])
    for j in range(i + 1, n):
        tmp2 = s[i] + s[j]
        if tmp2 in num2:
            continue
        num2.add(tmp2)
        for k in range(j + 1, n):
            tmp3 = tmp2 + s[k]
            if tmp3 in num3:
                continue
            num3.add(tmp3)
print(len(num3))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
c = 0
for i in range(1000):
  num = str(i).zfill(3)
  if num[0] in s:
    k = s[(s.find(num[0])+1):]
    if num[1] in k:
      d = k[(k.find(num[1])+1):]
      if num[2] in d:
        c += 1
print(c)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
number = [n for n in range(10)]
ans = 0
for i in number:
    try:
        j = s.index(str(i))
        for k in number:
            try:
                l = s[j+1:].index(str(k))
                ans += len(set(s[l+j+2:]))
            except:
                continue
    except:
        continue
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
number = [n for n in range(10)]
ans = 0
for i in number:
    try:
        j = s.index(str(i))
        for k in number:
            try:
                l = s[j+1:].index(str(k))
                exist = [0]*10
                for m in s[l+j+2:]:
                    exist[int(m)] = 1
                #print(exist)
                ans += sum(exist)
            except:
                continue
    except:
        continue
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
number = [n for n in range(10)]
ans = set([])
for i in number:
    try:
        j = s.index(str(i))
        for k in number:
            try:
                l = s[j+1:].index(str(k))
                for m in s[l+j+2:]:
                    ans.add(str(i)+str(k)+m)
            except:
                continue
    except:
        continue
print(len(ans))

Submission status: Accepted

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

ans = set()
for x in range(10):
    if str(x) in S:
        idx = S.index(str(x))
        for y in range(10):
            if str(y) in S[idx+1:]:
                idx2 = S[idx+1:].index(str(y)) + idx + 1
                for z in range(10):
                    if str(z) in S[idx2+1:]:
                        idx3 = S[idx2 + 1:].index(str(z)) + idx2 + 1
                        ans.add((x,y,z))
print(len(ans))

Submission status: Accepted

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

cnt = 0
for i in range(10):
    p1 = s.find(str(i))
    if p1 == -1:
        continue
    
    for j in range(10):
        p2 = s.find(str(j),p1+1)
        if p2 == -1:
            continue

        for k in range(10):
            p3 = s.find(str(k),p2+1)
            if p3 != -1:
                cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import collections

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

already = []
ans = 0

for i in range(N-2):
    tmp = []
    point = 1
    if S[i] not in already:
        already.append(S[i])
        while True:
            # print(S[i])
            # print(ans)
            # print(tmp)
            # print(S[i+point])
            if S[i+point] not in tmp:
                # print('aa')
                ans += len(set(S[i+point+1:]))
                # print(str(S[i])+str(S[i+point]))
                # print(set(S[i+point+1:]))
                # print(len(set(S[i+point+1:])))
                tmp.append(S[i+point])
            point += 1
            if i + point == N-1:
                break

print(ans)

Submission status: Accepted

Solution code:
import bisect

N = int(input())
S = input().strip()

A = [[] for j in range(10)]


for i, s in enumerate(S):
    A[int(s)].append(i)

v = set()


ans = 0
for i in range(10):
    if A[i]:
        for j in range(10):
            if A[j]:
                x = bisect.bisect_right(A[j], A[i][0])
                if x != len(A[j]):
                    for k in range(10):
                        if A[k]:
                            y = bisect.bisect_right(A[k], A[j][x])
                            if y != len(A[k]):
                                ans += 1

print(ans)

Submission status: Accepted

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

lcs = [0]
rcs = [0]
for c in S:
    c = int(c)
    lcs.append(lcs[-1] | (1<<c))
for c in S[::-1]:
    c = int(c)
    rcs.append(rcs[-1] | (1<<c))
rcs.reverse()

ss = set()
for i,c in enumerate(S):
    c = int(c)
    ls = []
    for l in range(10):
        if lcs[i]&(1<<l):
            ls.append(l)
    rs = []
    for r in range(10):
        if rcs[i+1]&(1<<r):
            rs.append(r)
    for l in ls:
        for r in rs:
            ss.add(l*100 + c*10 + r)
print(len(ss))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
l = [[False]*10 for i in range(n)]
r = [[False] * 10 for i in range(n)]
total = set()
for i in range(1, n):
    l[i] = l[i - 1][:]
    l[i][int(s[i-1])] = True
for i in range(n-2, -1, -1):
    r[i] = r[i + 1][:]
    r[i][int(s[i+1])] = True
for i in range(1, n - 1):
    for j in range(10):
        if not l[i][j]:
            continue
        for k in range(10):
            if not r[i][k]:
                continue
            total.add((j, int(s[i]), k))
print(len(total))

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

def check(num,s):
    curr = 0
    for k in range(len(s)):
        if num[curr] == s[k]:
            curr += 1
            if curr == 3:
                return True
    return False

def main():
    N = int(input())
    S = input()
    ans = 0
    for k in range(1000):
        t = str(k).zfill(3)
        if check(t,S) == True:
            ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
import itertools
state = itertools.product(list(range(10)),repeat = 3)
#print(list(state))
def lucky_pin(i):
    spot = -1
    for j in i:
        
        if str(j) in s[spot +1 : ]:
            spot = s[spot +1 : ].find(str(j)) +spot +1
            
        else:
            return 0
    return 1
      
counter = 0
for i in state:
    counter += lucky_pin(i)
        
print(counter)

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

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    s = input()
    ans = 0
    for i1 in range(10):
        for i2 in range(10):
            for i3 in range(10):
                ii1 = s.find(str(i1))
                if ii1 == -1:
                    continue
                ii2 = s[ii1+1::].find(str(i2))
                if ii2 == -1:
                    continue
                ii3 = s[ii1+1+ii2+1::].find(str(i3))
                if not ii3 == -1:
                    ans += 1
    print(ans)


    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    s = input()
    ans = 0
    for i1 in range(10):
        for i2 in range(10):
            for i3 in range(10):
                ii1 = s.find(str(i1))
                if ii1 == -1 or ii1 >= n-2:
                    continue
                ii2 = s[ii1+1::].find(str(i2))
                if ii2 == -1 or ii2 >= n-1:
                    continue
                ii3 = s[ii1+1+ii2+1::].find(str(i3))
                if not ii3 == -1:
                    ans += 1
    print(ans)


    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
s=str(input())
ans=0
i=0
while i<1000:
  temp=i//100
  cnt=0
  k=0
  for j in range(0,n):
    if temp==int(s[j]):
      cnt=cnt+1
      k=j
      break
  if cnt==0:
    i=i+100
  else:
    temp=(i-(i//100)*100)//10
    for j in range(k+1,n):      
      if temp==int(s[j]):
        cnt=cnt+1
        k=j
        break
    if cnt==1:
      i=i+10
    else:
      temp=i%10
      i=i+1
      for j in range(k+1,n):
        if temp==int(s[j]):
          ans=ans+1
          break
print(ans)

Submission status: Accepted

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

digit1 =[1,1,1,1,1,1,1,1,1,1]
digit2 =[1,1,1,1,1,1,1,1,1,1]
digit3 =[1,1,1,1,1,1,1,1,1,1]

array_code = []

for i in range(len(S)):
    if 1 in digit1:
        if digit1[int(S[i])]==1:
            for j in range(i+1,len(S)):
                if 1 in digit2:
                    if digit2[int(S[j])]==1:
                        for k in range(j+1,len(S)):
                            #print(S[i]+S[j]+S[k])
                            if 1 in digit3:
                                if digit3[int(S[k])] ==1:
                                    array_code.append(S[i]+S[j]+S[k])
                                    digit3[int(S[k])] = 0
                            else:
                                for l in range(10):
                                    digit3[l]=1
                                break
                        digit2[int(S[j])]=0
                else:
                    for l in range(10):
                        digit2[l]=1
                    break
                for l in range(10):
                    digit3[l] = 1
            digit1[int(S[i])]=0
    else:
        break
    for l in range(10):
        digit2[l] = 1

#print(array_code)
print(len(array_code))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools


N = int(readline())
S = [x - ord('0') for x in read().rstrip()]
left_index = [[-1] * (N+1) for _ in range(10)]
for i,x in enumerate(S,1):
    for j in range(10):
        left_index[j][i] = left_index[j][i-1]
    left_index[x][i] = i
ans = 0
for a,b,c in itertools.product(range(10),repeat=3):
    i = N
    bl = True
    for x in [a,b,c]:
        i = left_index[x][i] - 1
        if i < -1:
            bl = False
            break
    if bl:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import product
import bisect
N = int(sys.stdin.readline().rstrip())
S = sys.stdin.readline().rstrip()

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

ans = 0
for a, b, c in product(range(10), repeat=3):
    x = -1
    for i in [a, b, c]:
        if i not in d:
            break
        y = bisect.bisect_right(d[i], x)
        if y == len(d[i]):
            break
        x = d[i][y]
    else:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,S = read().decode('utf-8').split()
count = 0
for i in range(1000):
  s = str(i).zfill(3)
  index_all = 0
  for j in range(3):
    index = S[index_all:].find(s[j])
    if index == -1:
      break
    index_all += index+1
    if j ==2:
      count += 1
print(count)

Submission status: Accepted

Solution code:
from itertools import product

N=int(input())
S=list(input())
t=["0","1","2","3","4","5","6","7","8","9"]

u=product(t,repeat=3)
ans=0
for com in u:
  x=com[0]
  y=com[1]
  z=com[2]
  
  if x in set(S):
    idx_x = S.index(x)
    tmp1 = S[idx_x+1:]
    if y in set(tmp1):
      idx_y = tmp1.index(y)
      tmp2 = tmp1[idx_y+1:]
      if z in set(tmp2):
        ans+=1
        continue
        
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:
    for j in range(10):
      y=s.find(str(j),x+1,n)
      if y!=-1:
        for k in range(10):
          z=s.find(str(k),y+1,n)
          if z!=-1:
            ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for num in range(0, 1000):
    n0, n1, n2 = list(str(num).zfill(3))
    if n0 in S_set and n1 in S_set and n2 in S_set:
        idx0 = S.index(n0)
        idx2 = N - S[::-1].index(n2) - 1
        if idx0 < idx2:
            if n1 in S[idx0 + 1: idx2]:
                ans += 1
print(ans)

Submission status: Accepted

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

species_S_list = set(S)
ans = 0
for num in range(0, 1000):
    cnt = 0
    num_str = str(num).zfill(3)
    n0, n1, n2 = list(num_str)
    if n0 in species_S_list and n1 in species_S_list and n2 in species_S_list:
        index0 = S.index(n0)
        index2 = N - S[::-1].index(n2) - 1
        if index0 < index2:
            if n1 in S[index0 + 1: index2]:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
first = set([])
ans = 0
for i in range(n - 2):
    if s[i] not in first:
        first.add(s[i])
        second = set([])
        for j in range(i + 1, n - 1):
            if s[j] not in second:
                second.add(s[j])
                ans += len(set(list(s[j + 1:])))
print(ans)

Submission status: Accepted

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

n=int(n)
sec_set = set()

for i in range(10):
    first = ln.find(str(i))
    if first == -1:
        continue
    for j in range(10):
        second = ln[(first+1):].find(str(j))
        if second == -1:
            continue
        for k in range(10):
            third = ln[(first + second+2):].find(str(k))
            if third == -1:
                continue
            else:
                sec_set.add(str(i)+str(j)+str(k))
print(len(sec_set))

Submission status: Accepted

Solution code:
N = int(input())
S = [int(x) for x in list(input())]
li = []
lj = []
lk = []
count = 0
for i_id, i in enumerate(S[0:N-2]):
  if i not in li:
    for j_id, j in enumerate(S[i_id+1:N-1]):
      if j not in lj:
        for k in S[i_id+j_id+2:N]:
          if k not in lk:
            count += 1
            lk.append(k)
        lj.append(j)
        lk.clear()
    li.append(i)
    lj.clear()
print(count)

Submission status: Accepted

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = int(input())
a = input()
ans = 0
for i in range(1000):
    i = str(i).zfill(3)
    x = a.find(i[0])
    y = a.find(i[1], x+1)
    z = a.find(i[2], y+1)
    if x != -1 and y != -1 and z != -1:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#三井住友2019 D
def main():
    import sys
    N = int(sys.stdin.readline())
    S = sys.stdin.readline().rstrip()
    cnt = 0
    for i in range(0, 10):
        for j in range(0, 10):
            for k in range(0, 10):
                st1 = S.find(str(i))
                if st1 ==-1:
                    continue
                
                st2 = S[st1+1:].find(str(j))
                if st2 ==-1:
                    continue
              
                st3 = S[st1+st2+2:].find(str(k))
                if st3 ==-1:
                    continue
                #print(st1,st2,st3, i,j,k)
                cnt +=1
    print(cnt)


                    
    
   
    
if __name__=='__main__':
    main()

Submission status: Accepted

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

count = 0
for i in range(10):
    p1 = s.find(str(i))
    if p1 == -1:
        continue
    for j in range(10):
        p2 = s.find(str(j), p1 + 1)
        if p2 == -1:
            continue
        for k in range(10):
            p3 = s.find(str(k), p2+1)
            if p3 != -1:
                count += 1

print(count)

Submission status: Accepted

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

count = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            p1 = s.find(str(i))
            if p1 != -1:
                p2 = s.find(str(j), p1+1)
                if p2 != -1:
                    p3 = s.find(str(k), p2+1)
                    if p3 != -1:
                        count += 1

print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
memo = []
for i in range(10):
  for j in range(10):
    for k in range(10):
      memo.append(str(i) + str(j) + str(k))
ans = 0
for i in memo:
  x = 0
  for j in range(n):
    if i[x] == s[j]:
      x += 1
      if x == 3:
        ans += 1
        break

print(ans)

Submission status: Accepted

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

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

cntset=set()
for i in range(1000):
    s=str(i)
    if i <10:
        s="00"+s
    if 10<=i<100:
        s="0"+s
    if S.find(s[0])==-1:
        continue
    if S[S.find(s[0])+1:].find(s[1])==-1:
        continue
    g=S.find(s[0])+S[S.find(s[0])+1:].find(s[1])
    if S[g+2:].find(s[2])==-1:
        continue
    cntset.add(s)
    
print(len(cntset))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def indexes(s, i):
  if i in s:
    return s.index(i)
  return -1

def check(s, num):
  for i in num:
    if indexes(s, i) < 0:
      return False
    index=indexes(s, i)
    s=s[index+1:]
  return True

l=int(input())
s=input()
pin=[]
cand=[str(i)[1:] for i in range(1000, 2000)]
for i in cand:
  if check(s, i):
    pin.append(i)
print(len(pin))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
counter = 0
#N文字から3文字を拾いあげ、暗証番号のリストを作って検討していくと、
#5000^3の計算量となり、時間内には終わらない。
#暗証番号の候補となる３桁までの整数1000通りが
#Sの中にこの順番で存在するかどうかを確認すればよい。
for i in range(1000):
    #000から999までの文字列を作る
    num = "0"*(3-len(str(i))) + str(i)
    first = S.find(num[0])
    if first != -1:
        #間違い例：second = S.find(num[1],first)
        #求めたい文字が、相異なる三か所に見つかる必要がある。
        #つまり、first<second<thirdである必要がある
        second = S.find(num[1],first+1)
        if second != -1:
            third = S.find(num[2],second+1)
            if third != -1:
                #print(first,second,third)
                counter+=1
print(counter)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
cnt = 0
for i in range(1000):
    x = str(i).zfill(3)
    i1 = s.find(x[0])
    i2 = s[i1+1:].find(x[1])
    i3 = s[i1+i2+2:].find(x[2])
    if -1 not in (i1, i2, i3):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import itertools
N=int(input())
S=list(input())
SS=set(S)
SS=list(SS)
num = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
num=[x for x in num if x in SS]
number=["".join(i) for i in itertools.product(num,repeat=3)]

ans=0
for i in number:
    count=0

    for s in range(N):
        if i[count]==S[s]:
            count+=1
            if count==2:
                if i[2] in S[s+1:]:
                    ans+=1
                break


print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1000):
    key = '{:03d}'.format(i)

    for j in range(n):
        if s[j] == key[0]: break
    else: continue

    for k in range(j+1, n):
        if s[k] == key[1]: break
    else: continue

    for l in range(k+1, n):
        if s[l] == key[2]: break
    else: continue

    ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ss = input()
li = []
li1 = []
li2 = []
ans = 0
for i in range(n-2):
    f = ss[i]
    if f in li:
        continue
    li.append(f)
    for j in range(i+1,n-1):
        s = ss[j]
        if f+s in li1:
            continue
        li1.append(f+s)
        li2 = []
        for k in range(j+1,n):
            if len(li2) == 10:
                break
            t = ss[k]
            if t in li2:
                continue
            ans += 1
            li2.append(t)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
res = 0
pos = []
for i in range(10):
    pos.append([])

for i in range(len(s)):
    c = int(s[i])
    pos[c].append(i)
import bisect
# 0010
# print(format(10, '04d'))
res = 0
for num in range(0, 1000):
    numstr = format(num, '03d')
    iscan = True
    curpos = -2
    for i in range(3):
        curpos += 1
        val = int(numstr[i])
        ind = bisect.bisect_left(pos[val], curpos)
        if ind == len(pos[val]):
            iscan = False
            break
        curpos = pos[val][ind]

    if iscan:
        res += 1
print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Jun  1 16:47:45 2020

@author: NEC-PCuser
"""

N = int(input())
S = input()
count = 0
for i in range(0, 1000):
    j = 0
    a = str(i).zfill(3)
    b = S.find(a[0])
    if b == -1:
        continue
    c = S[b+1:].find(a[1])
    if c == -1:
        continue
    d= S[b+c+2:].find(a[2])
    if d != -1:
        count += 1
    
            
print(count)

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):
            if str(k) in s[b+1::]:
                cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
S = input()
l = set()
for i in range(1000):
    num = str(i).zfill(3)
    s = S
    if s.find(num[0]) == -1:
        continue
    s = s[s.index(num[0]) + 1:]
    if s.find(num[1]) == -1:
        continue
    s = s[s.index(num[1]) + 1:]
    if s.find(num[2]) == -1:
        continue
    l.add(num)
print(len(l))

Submission status: Accepted

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

num = []
for i in range(10):
    num.append(str(i))
#print(num)

cnt = 0
for i in num:
    for k in num:
        for j in num:
            for a in range(len(S)):
                if i == S[a]:
                    for b in range(a+1,len(S)):
                        if k == S[b]:
                            for c in range(b+1,len(S)):
                                if j == S[c]:
                                    cnt += 1
                                    break
                            break
                    break
print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
S=input()
l=[]
for i in range(10**3):
    num=str(i).zfill(3)
    s=S
    if s.find(num[0])==-1: continue
    s=s[s.index(num[0])+1:]
    if s.find(num[1])==-1: continue
    s=s[s.index(num[1])+1:]
    if s.find(num[2])==-1: continue
    l.append(num)
print(len(set(l)))

Submission status: Accepted

Solution code:
_,s=open(0)
c=0
for i in range(1000):
 p=0;F=1
 for j in str(i).zfill(3):
  q=s[p:].find(j)
  if q<0:F=0;break
  p+=q+1
 c+=F
print(c)

Submission status: Accepted

Solution code:
_, s = open(0)
c = 0
for i in range(1000):
    p = 0
    F = 1
    for j in str(i).zfill(3):
        q = s[p:].find(j)
        if q < 0:
            F = 0
            break
        p += q + 1
    c += F
print(c)

Submission status: Accepted

Solution code:
n=int(input())
S=input()
l=[]
for i in range(10**3):
    num=str(i).zfill(3)
    s=S
    if s.find(num[0])==-1: continue
    s=s[s.index(num[0])+1:]
    if s.find(num[1])==-1: continue
    s=s[s.index(num[1])+1:]
    if s.find(num[2])==-1: continue
    l.append(num)
print(len(set(l)))

Submission status: Accepted

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

ans = 0

for i in range(10):
    if i in S[:N - 2]:
        i_index = S.index(i)
        for j in range(10):
            if j in S[i_index + 1: N - 1]:
                j_index = i_index + S[i_index + 1: N - 1].index(j) + 1
                for k in range(10):
                    if k in S[j_index + 1:]:
                        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int, list(input())))
numbers = [0 for _i in range(1000)]
right, left = [[0 for _j in range(10)] for _i in range(n)], [[0 for _j in range(10)] for _i in range(n)]
for i in range(1, n):
    left[i] = left[i-1].copy()
    left[i][s[i-1]] += 1
for i in range(2, n+1):
    right[-i] = right[-i+1].copy()
    right[-i][s[-i+1]] += 1

for i in range(n):
    for x in range(10):
        for y in range(10):
            if right[i][x]>0 and left[i][y]>0:
                numbers[100*x+10*s[i]+y] = 1
print(sum(numbers))

Submission status: Accepted

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

ans = 0
for i in range(10):
    if i in s[: n - 2]:
        x = s.index(i)
        for j in range(10):
            if j in s[x + 1: n - 1]:
                y = x + 1 + s[x + 1: n - 1].index(j)
                for k in range(10):
                    if k in s[y + 1:]:
                        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = [int(x) for x in input()]

dp_1 = [False] * 10
dp_2 = [False] * 100
dp_3 = [False] * 1000

for x in s:
    for i in range(100):
        if dp_2[i]:
            dp_3[i * 10 + x] = True
    for j in range(10):
        if dp_1[j]:
            dp_2[j * 10 + x] = True
    dp_1[x] = True

print(sum(dp_3))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
count = 0
for a in range(10):
  for b in range(10):
    for c in range(10):
      check_1 = False
      check_2 = False
      check_3 = False
      for i in range(n):
          if s[i] == str(a):
            check_1 = True
            nex = i
            break
      if check_1 == True:
          for j in range(nex + 1,n):
            if s[j] == str(b):
              check_2 = True
              ne = j
              break
      if check_2 == True:
          for t in range(ne+1,n):
            if s[t] == str(c):
              count += 1
              break
print(count)

Submission status: Accepted

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

ans = 0
for i in range(10):
    if i in s[:n - 2]:
        x = s.index(i)

        for j in range(10):
            if j in s[x + 1:n - 1]:
                y = x + s[x + 1:n - 1].index(j) + 1

                for k in range(10):
                    if k in s[y + 1:]:
                        ans += 1

print(ans)

Submission status: Accepted

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

count = 0

for a in [str(a) for a in range(10)]:
    pos_a = S.find(a)
    if pos_a >= 0:
        for b in [str(b) for b in range(10)]:
            pos_b = S.find(b, pos_a+1)
            if pos_b >= 0:
                for c in [str(c) for c in range(10)]:
                    if S.find(c, pos_b+1) >= 0:
                        count += 1

print(count)

Submission status: Accepted

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

ans = 0

for i in range(1000):
    t = str(i).zfill(3)
    t_index = 0
    for s_index in range(n):
        if s[s_index] == t[t_index]:
            t_index += 1
            if t_index == 3:
                break
    if t_index == 3:
        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):
            flag_i = False
            flag_j = False
            flag_k = False
            for t in range(N):
                if not flag_i and S[t] == str(i):
                    flag_i = True
                elif flag_i and not flag_j and S[t] == str(j):
                    flag_j = True
                elif flag_i and flag_j and not flag_k and S[t] == str(k):
                    flag_k = True
            if flag_i and flag_j and flag_k:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                flag_i = False
                flag_j = False
                flag_k = False
                for t in range(N):
                    if not flag_i and S[t] == str(i):
                        flag_i = True
                    elif flag_i and not flag_j and S[t] == str(j):
                        flag_j = True                           
                    elif flag_i and flag_j and not flag_k and S[t] == str(k):
                        flag_k = True
                if flag_i and flag_j and flag_k:
                    ans += 1
    print(ans)


if __name__ == '__main__':
    main()