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:
#!/usr/bin/env python3


def dfs(p, cur):
    sz = len(cur)
    if sz == 3:
        return
    for i in range(p + 1, n):
        nxt = cur + s[i]
        if nxt in used[sz]:
            continue
        used[sz][nxt] = True
        dfs(i, nxt)


n = int(input())
s = input()
used = [{} for _ in range(3)]

dfs(-1, "")

print(len(used[2]))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
L = [str(i).zfill(3) for i in range(1000)]
count = 0
for l in L:
    try:
        i = S.index(l[0])
        j = S.index(l[1], i + 1)
        k = S.index(l[2], j + 1)
        count += 1
    except:
        continue
print(count)

Submission status: Accepted

Solution code:
_ = input()
S = input()
counter = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            idxi = S.find(str(i))
            if idxi ==-1:
                continue
            idxj = S.find(str(j),idxi+1)
            if idxj == -1:
                continue
            idxk = S.find(str(k),idxj+1)
            if idxk == -1:
                continue
            counter+=1
print(counter)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
snumber = [str(i) for i in range(10)]
for i in snumber:
    for j in snumber:
        for k in snumber:
            a = S.find(i)
            if a == -1:
                break
            b = S.find(j,a+1)
            if b == -1:
                break
            c = S.find(k,b+1)
            if c != -1:
                ans += 1
print(ans)

Submission status: Accepted

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

res = 0

for i in range(10):
    p1 = S.find(str(i))
    if p1 == -1:
        continue
    elif p1 > N-3:
        continue
    for j in range(10):
        p2 = S[p1+1:N].find(str(j))
        if p2 == -1:
            continue
        elif p2 > N-p1-3:
            continue
        for k in range(10):
            p3 = S[p1+p2+2:N].find(str(k))
            if p3 == -1:
                continue
            res += 1


print(res)

Submission status: Accepted

Solution code:
import collections
def main():

    N = int(input())
    S = input()
    d = collections.defaultdict(set)
    for i in range(N):
        for v in d[2]:
            d[3].add(v + S[i])
        for v in d[1]:
            d[2].add(v + S[i])
        d[1].add(S[i])
        # print(d[1])
        # print(d[2])
        # print(d[3])
    return len(d[3])

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
#D
import itertools
N=int(input())
S=str(input())
count=0
for i,j,k in itertools.product(range(10),repeat=3):
  try:
    x = S.index(str(i))
    y = S.index(str(j),x+1)
    z = S.index(str(k),y+1)
    count +=1
  except:
    continue

print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
list = [0]*10
code_list = []

#for i in range(9):
#    for j in range(len(S)):
#        if str(i) == S[j]:
#            list[i] = list[i] + 1

def check_match(word,str_cnt):
    global S
    ret = -1

    for i in range(str_cnt,len(S)):
        if S[i] == word:
            ret = i
            break

    return ret

#貪欲法
password = [0]*3
ans_cnt = 0
for num in range(1000):
    ret = 0
    password = str(num)
    password = password.zfill(3)

    ret = check_match(password[0],ret)
    if ret != -1:
        ret = check_match(password[1],ret+1)
        if ret != -1:
            ret= check_match(password[2],ret+1)
            if ret != -1:
                ans_cnt = ans_cnt + 1

print (ans_cnt)
#print (password[1])

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):
      i_pos = S.find(str(i))
      if i_pos == -1:
        continue
      j_pos = S.find(str(j),i_pos+1)
      if j_pos == -1:
        continue
      k_pos = S.find(str(k),j_pos+1)
      if k_pos == -1:
        continue
      cnt += 1
print(cnt)

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):
            
            if str(i) in S:
                x = S.index(str(i))
                if str(j) in S[x+1:]:
                    y = S[x+1:].index(str(j))+x+1
                    if str(k) in S[y+1:]:
                        ans+=1
           

print(ans)

Submission status: Accepted

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

list=list(S)

count=0
for a in range(10):
    find1=S.find(str(a))
    if find1==-1:
        continue
    for b in range(10):
        find2=S[find1+1:].find(str(b))
        if find2==-1:
            continue
        for c in range(10):
            find3=S[find1+1+find2+1:].find(str(c))
            if find3==-1:
                continue
            count+=1
print(count)

Submission status: Accepted

Solution code:
from pprint import pprint
import sys

n = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()

count = 0
for i in range(1000):
    pin = str(i).zfill(3)
    start = 0
    flags = [False] * 3
    for i, pin_i in enumerate(pin):
        flag = False
        for j, s_j in enumerate(s):
            if j < start:
                continue
            if s_j == pin_i:
                flag = True
                start = j + 1
                break
        flags[i] = flag
    if flags[0] and flags[1] and flags[2]:
        # print(pin)
        count += 1

print(count)

Submission status: Accepted

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

l_S=list(S)

count=0
for i in range(0,1000):
    i_1=int(i/100)
    i_2=int(i/10)-i_1*10
    i_3=i%10
    if str(i_1) in l_S[:-2]:
        idx_1=l_S[:-2].index(str(i_1))
        if str(i_2) in l_S[idx_1+1:-1]:
            idx_2=l_S[idx_1+1:-1].index(str(i_2))+idx_1+1
            if str(i_3) in l_S[idx_2+1:]:
                count+=1
print(count)

Submission status: Accepted

Solution code:
from itertools import product

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

cnt = 0
for i, j, k in product("0123456789", repeat=3):
    try:
        x = S.index(i)
        y = S.index(j, x + 1)
        z = S.index(k, y + 1)
    except:
        continue
    cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
l=list(input())
ans=0
for i in range(10):
  for j in range(10):
    for k in range(10):
      now=str(i)
      count=0
      b=True
      f=1
      while count<n and b:
        if l[count]==now:
          if f==1:
            now=str(j)
            f+=1
          elif f==2:
            now=str(k)
            f+=1
          else:
            b=False
            ans+=1
        count+=1
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1000):
    i = str(i)
    i = (3-len(i)) * '0' + i
    r = 0
    for j in range(n):
        if s[j] == i[r]:
            r += 1
        if r == 3:
            break
    if r == 3:
        ans +=1

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1000):
    i = str(i)
    i = (3-len(i)) * '0' + i
    r = 0
    for j in range(n):
        if s[j] == i[r]:
            r += 1
        if r == 3:
            break
    if r == 3:
        ans +=1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            i_pos = s.find(str(i))

            if i_pos == -1:
                continue

            j_pos = s.find(str(j), i_pos+1)

            if j_pos == -1:
                continue

            k_pos = s.find(str(k), j_pos+1)

            if k_pos == -1:
                continue

            ans += 1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=str(input())
 
def isThere(suji):
    flag1=False
    flag2=False
    flag3=False
    for i in s:
        if flag2==True and suji[2]==i:
            flag3=True
            break
        if flag1==True and suji[1]==i:
            flag2=True
        if suji[0]==i:
            flag1=True
    return flag3 
 
candidate=list(range(1000))
candidate=['0'+'0'+str(candidate[i]) if candidate[i]<10 else ('0'+str(candidate[i]) if 9<candidate[i]<100 else str(candidate[i])) for i in range(1000)]
ans=0
for suji in candidate:
    if isThere(suji):
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

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

cnt = 0
for i, j, k in product(range(10), repeat=3):
    try:
        x = s.index(str(i))
        y = s.index(str(j), x+1)
        z = s.index(str(k), y+1)
        cnt += 1
    except:
        continue

print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    s = args[1]
    ret = 0

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

    for i in range(1000):
        iii = '{:03d}'.format(i)
        cur = -1
        found = False

        for e, j in enumerate(iii):
            found = False

            for k in index[int(j)]:
                if cur < k:
                    found = True
                    cur = k
                    break

            if not found:
                break

        if found:
            ret += 1

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

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):
      idxi=S.find(str(i))
      if idxi==-1:
        continue
      idxj=S.find(str(j),idxi+1)
      if idxj==-1:
        continue
      idxk=S.find(str(k),idxj+1)
      if idxk==-1:
        continue
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

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

p = product([str(i) for i in range(10)], repeat=3)

ans = 0

for i, j, k in p:
    x = s.find(i)
    if x != -1:
        y = s.find(j, x+1)
        if y != -1:
            z = s.find(k, y+1)
            if z != -1:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
# 入力
N = int(input())
A = [int(x) for x in list(input())]
ans = 0

AA = [x for x in range(10)]

for i in AA:
    for j in AA:
        for k in AA:
            v = [i, j, k]
            now=0
            temp=v[now]
            for l in A:
                if (l ==temp):
                    now += 1
                    if (now == 3):
                        # print(v)
                        break
                    temp = v[now]
            if (now == 3):
                ans += 1

print(ans)

Submission status: Accepted

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

count = 0

for i in range(1000):
  a = "{0:03d}".format(i)
  if a[0] in s:
    idx1 = s.index(a[0])
    s1 = s[idx1+1:]
    if a[1] in s1:
      idx2 = s1.index(a[1])
      s2 = s1[idx2+1:]
      if a[2] in s2:
        count += 1
print(count)

Submission status: Accepted

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

n = int(input())
s = input().split()[0]

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

Submission status: Accepted

Solution code:
import bisect
import collections

def read():
    N = int(input().strip())
    S = str(input().strip())
    return N, S

def dig(S, T, N):
    k0, k1, k2 = -1, -1, -1
    for i in range(N):
        if S[i] == T[0]:
            k0 = i
            break
    if k0 == -1:
        return False
    for i in range(k0+1, N):
        if S[i] == T[1]:
            k1 = i
            break
    if k1 == -1:
        return False
    for i in range(k1+1, N):
        if S[i] == T[2]:
            k2 = i
            break
    if k2 == -1:
        return False
    return True


def solve(N, S):
    d = [collections.deque() for i in range(10)]
    count = 0
    for p in range(1000):
        T = '{:03d}'.format(p)
        count += 1 if dig(S, T, N) else 0
    return count
    
if __name__ == '__main__':
    inputs = read()
    output = solve(*inputs)
    print("%d" % output)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
n = 0
for i in range(1000):
  ps = "%03d"%(i)
  s = S
  is_ok = True
  for j in list(ps):
    if j in s: s = s[s.index(j)+1:]
    else:
      is_ok = False
      break
  if is_ok: n+=1
print(n)

Submission status: Accepted

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

ans = 0

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

            if i_pos == -1:
                continue

            j_pos = s.find(str(j), i_pos+1)

            if j_pos == -1:
                continue

            k_pos = s.find(str(k), j_pos+1)

            if k_pos == -1:
                continue

            ans += 1

print(ans)

Submission status: Accepted

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

from itertools import product

p = product([str(i) for i in range(10)], repeat=3)

ans = 0
for i,j,k in p:
  x = S.find(i)
  if x<0:
    continue
  y = S[x+1:].find(j)
  if y<0:
    continue
  z = S[x+y+2:].find(k)
  if z<0:
    continue
  #print(i,j,k, S, S[x+1:],S[x+y+2:])
  ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
SS = S
ans = 0
an = []
for x in range(1000):
    check = True
    p = -1
    sx = str(x).zfill(3)
    a = []
    S = SS
    for y in range(3):
        idx = S.find(sx[y])
        if idx < 0:
            check = False
            break
        else:
            S = S[idx + 1:]
    if check:
        an.append(sx)
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

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

cnt = 0
for i, j, k in product(range(10), repeat=3):
    try:
        x = S.index(str(i))
        y = S.index(str(j), x + 1)
        z = S.index(str(k), y + 1)
    except:
        continue
    cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = list( input("") )
A =  set(S)
count = 0
for i in A:
    b = S.index(i) + 1
    B = set(S[b:])
    for j in B:
        c = S[b:].index(j) + 1
        C = set(S[b:][c:])
        count += len(C)
print(count)

Submission status: Accepted

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

    ans = 0
    for i in range(0, 1000):
        num = str(i)
        num = '0'*(3-len(num))+num
        index = 0
        for i in s:
            if index == 3:
                ans += 1
                break
            elif num[index]==i:
                index += 1
        else:
            if index == 3:
                ans += 1

    print(ans)

    # calc


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import product

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

cnt = 0
for i, j, k in product(range(10), repeat=3):
    x = S.find(str(i))
    if x == -1:
        continue
    y = S.find(str(j), x + 1)
    if y == -1:
        continue
    z = S.find(str(k), y + 1)
    if z == -1:
        continue
    cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
ans = 0
fl = [False] * 10
sl = [False] * 10
tl = [False] * 10

for i in range(N - 2):
    if not fl[int(S[i])]:
        fl[int(S[i])] = True
        for j in range(i + 1, N - 1):
            if not sl[int(S[j])]:
                sl[int(S[j])] = True
                for k in range(j + 1, N):
                    if not tl[int(S[k])]:
                        tl[int(S[k])] = True
                        ans += 1
                tl = [False] * 10
        sl = [False] * 10

print(ans)

Submission status: Accepted

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

def solve(N: int, S: str):
    answer = 0
    for i in range(0,1000):
        i = str(i).zfill(3)
        index = 0
        for ss in S:
            if ss == i[index]:
                index += 1
                if index >= 3:
                    answer += 1
                    break

    print(answer)
    return


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:
n = int(input())
s = input()

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
s += "_"
ans = 0
for i in range(10):
    if str(i) in s:
        x = s.index(str(i))
        for j in range(10):
            if str(j) in s[x+1:]:
                y = s[x+1:].index(str(j))
                for k in range(10):
                    if str(k) in s[x+1:][y+1:]:
                        ans += 1

print(ans)

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate as acc
    N=int(input())
    s=input()
    ind=[[0 for j in range(N)] for i in range(10)]
    first=[-1 for i in range(10)]
    last=[-1 for i in range(10)]


    for i in range(len(s)):
        k=int(s[i])
        if first[k]==-1: first[k]=i
        last[k]=i
        ind[k][i]=1
        
    for i in range(10):
        ind[i]=list(acc(ind[i]))

    ans=0
    for i in range(10):
        for j in range(10):
            f=first[i]
            l=last[j]
            if f!=-1 and f+1<l:
                for k in range(0,10):
                    if ind[k][f]<ind[k][l-1]: ans+=1
                    

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
num = [[] for _ in range(10)]
l = int(input())
s = input()
ans = []
for i in range(l):
    n = int(s[i])
    num[n].append(i)
for i in range(10):
    num[i].sort()
for i in range(10):
    if len(num[i])>0:
        start = num[i][0]
        for j in range(10):
            if len(num[j])>0:
                s=0; e = len(num[j])-1
                nd = -1
                while(s<e):
                    nx = (s+e)//2
                    if num[j][nx]<=start:
                        s= nx+1
                    elif num[j][nx]>start:
                        e = nx
                if num[j][e]>start:
                    nd = num[j][e]
                    for k in range(10):
                        if len(num[k]) > 0:
                            s = 0;
                            e = len(num[k]) - 1
                            while (s < e):
                                nx = (s + e) // 2
                                if num[k][nx] <= nd:
                                    s = nx + 1
                                elif num[k][nx] > nd:
                                    e = nx
                            if num[k][e] > nd:
                                ans.append((i,j,k))
print(len(ans))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
passwords = []

firsts = []
firsts_seconds = [[]*10 for _ in range(10)]
firsts_seconds_thirds = [[]*10 for _ in range(100)]

for i in range(n-2):
    if len(firsts) == 10:
        break
    first =  s[i]
    if first in firsts:
        continue
    firsts.append(first)
    for j in range(i+1,n-1):
        if len(firsts_seconds[int(first)]) == 10:
            break
        second = s[j]
        first_second = first + second
        if first_second in firsts_seconds[int(first)]:
            continue
        firsts_seconds[int(first)].append(first_second)
        for k in range(j+1, n):
            password = first_second + s[k]
            if password not in firsts_seconds_thirds[int(first_second)]:
                firsts_seconds_thirds[int(first_second)].append(password)
                passwords.append(password)

print(len(passwords))

Submission status: Accepted

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

ans_count =0

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

            if i_pos < 0:
                continue

            j_pos = s.find(str(j),i_pos+1)

            if j_pos < 0:
                continue

            k_pos = s.find(str(k), j_pos +1)

            if k_pos < 0:
                continue

            ans_count += 1

print(ans_count)

Submission status: Accepted

Solution code:
def main():
    N=int(input())
    s=input()
    ind=[[0 for j in range(10)] for i in range(N)]
    first=[-1 for i in range(10)]
    last=[-1 for i in range(10)]

    k=int(s[0])
    first[k]=0
    last[k]=0
    ind[0][k]=1

    for i in range(1,len(s)):
        k=int(s[i])
        if first[k]==-1: first[k]=i
        last[k]=i
        ind[i]=[ind[i-1][j] for j in range(10)]
        ind[i][k]=ind[i-1][k]+1

    ans=0
    for i in range(10):
        for j in range(10):
            f=first[i]
            l=last[j]
            if f!=-1 and f+1<l:
                for k in range(0,10):
                    if ind[f][k]<ind[l-1][k]: ans+=1
                    

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = set()
for i in range(10):
  for j in range(10):
    for k in range(10):
      iflg = False
      jflg = False
      for s in S:
        if not iflg and s == i:
          iflg = True
        elif (not jflg) and iflg and s == j:
          jflg = True
          continue
        elif iflg and jflg and s == k:
          ans.add((i,j,k))
          break
print(len(ans))

Submission status: Accepted

Solution code:

N = int(input())
S = input()
ans = 0
anslst = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            anslst.append(str(i) + str(j) + str(k))

tmp = ans
for i in anslst:
    a, b, c = i
    index1 = S.find(a)
    index2 = S.find(b, index1 + 1)
    index3 = S.find(c, index2 + 1)
    if index1 != -1 and index2 != -1 and index3 != -1:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math

#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


def main():
#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]
    n=int(input())
    s=list(map(int,input()))

    count=0
    temp=0
    keta=[0,0,0]
    for i in range(1000):
        temp = 0
        if i <10:
            keta[0]=0
            keta[1]=0
            keta[2]=i
        elif i >=10 and i<100:
            keta[0]=0
            keta[1]=int(str(i)[0])
            keta[2]=int(str(i)[1])
        else:
            keta[0] = int(str(i)[0])
            keta[1] = int(str(i)[1])
            keta[2] = int(str(i)[2])
        for j in range(n):
            if keta[temp]==s[j]:
                 if temp<=1:
                    temp+=1
                 else:
                    count+=1
                    temp=0
                    break




    print(count)

#  print(c)




            #    print(n,kingaku(a,b,x))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

a = []
for i in range(10):
    for j in range(10):
        for z in range(10):
            a.append([i,j,z])

s = list(S)
s = [int(i) for i in s]
ans = 0
for n in a:
    flag = 0
    for i,name in enumerate(s):
        if name == n[0]:
            n = n[1:]
            flag += 1
        if flag == 3:
            ans += 1
            break

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
inf=float("inf")
A=[[inf]*10 for _ in range(n+1)]
for i in reversed(range(n)):
  ss=s[i]
  for j in range(10):
    if j==int(ss):
      A[i][j]=i
    else:
      A[i][j]=A[i+1][j]
ans=0
for x in range(1000):
  x=str(x).zfill(3)
  cur=0
  for xx in x:
    xx=int(xx)
    cur=A[cur][xx]+1
    if cur==inf:
      break
  if cur!=inf:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = tuple(map(int, input()))
f = [
    [] for i in range(10)
]
ans = 0

for i in range(n-2):
    if len(f[s[i]]) != 0:
        continue
    else:
        for j in range(i+1, n-1):
            if s[j] in f[s[i]]:
                continue
            else:
                f[s[i]].append(s[j])
                a = tuple(set(s[j+1:]))
                ans += len(a)

print(ans)

Submission status: Accepted

Solution code:
import sys
MAX_INT = int(10e12)
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()

cnt = 0
for a in range(10):
    for b in range(10):
        n = 0
        ab = [a,b]
        for i in range(N):
            if int(s[i]) == ab[n]:
                n += 1
            if n == 2:
                for c in range(10):
                    for j in range(i+1,N):
                        if int(s[j]) == c:
                            cnt += 1
                            break
                else:
                    break
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S100 = input()
S100list = list(S100)
X100 = set(S100list)
PIN = 0
for i in X100:
    S10 = S100[S100.find(i)+1:]
    X10 = set(list(S10))
    for j in X10:
        S1 = S10[S10.find(j)+1:]
        X1 = set(list(S1))
        PIN += len(X1)
    
print(PIN)

Submission status: Accepted

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

targets = tuple("{:0>3}".format(i) for i in range(1000))
ans = []
for target in targets:
    a, b, c = target
    a_index = S.find(a)
    b_index = S.find(b, a_index + 1)
    c_index = S.find(c, b_index + 1)
    ret = (a_index, b_index, c_index)
    if -1 not in ret:
        # print(target, ret)
        ans.append(ret)
print(len(ans))

Submission status: Accepted

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

ans = 0
for i in range(1000):
    a = '{0:03d}'.format(i)
    if a[0] in S:
        idx1 = S.index(a[0])
        S1 = S[idx1+1:]
        if a[1] in S1:
            idx2 = S1.index(a[1])
            S2 = S1[idx2+1:]
            if a[2] in S2:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:


def hantei(s, p):
    for c in p:
        i = s.find(c)
        if i < 0:
            return False
        s = "" if i+1 >= len(s) else s[i+1:]
    return True


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

    ps = ["%03d" % i for i in range(1000)]
    seen = set()
    ans = 0
    for p in ps:
        if p not in seen and hantei(s, p):
            ans += 1
            seen.add(p)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import product

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

ans = 0

for cmb in product(range(10), range(10), range(10)):
    idx = -1
    for i in cmb:
        idx = s.find(str(i), idx + 1)
        if idx < 0:
            break
    else:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
def main():
    N=int(input())
    s=input()
    first=[-1 for i in range(10)]
    last=[-1 for i in range(10)]
    for i in range(len(s)):
        k=int(s[i])
        if first[k]==-1: first[k]=i
        last[k]=i

    ans=0
    for i in range(10):
        for j in range(10):
            f=first[i]
            l=last[j]
            if f!=-1 and f+1<l:
                for k in range(0,10):
                    if s.find(str(k),f+1,l)!=-1: ans+=1
                    

    print(ans)
     
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
lis = [ str(i) for i in range(1000)]
ans = 0
for l in lis:
    if int(l) == 0:
        l0,l1,l2 = 0,0,0
    if int(l) < 10:
        l0 = 0
        l1 = 0
        l2 = l[0]
    elif int(l) < 100:
        l0 = 0
        l1 = l[0]
        l2 = l[1]
    else:
        l0 = l[0]
        l1 = l[1]
        l2 = l[2]
    try:
        id0 = S.index(str(l0))
        id1 = S[id0+1:].index(str(l1))
        id2 = S[id0+id1+2:].index(str(l2))
    except:
        continue
    ans += 1
print(ans)

Submission status: Accepted

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

ans = []
a1 = []
for i in range(N-2):
    if S[i] in a1:continue
    a1.append(S[i])
    a2 = []
    for j in range(i+1,N-1):
        if S[j] in a2:continue
        a2.append(S[j])
        a3 = []
        for k in range(j+1,N):
            if S[k] in a3:continue
            a3.append(S[k])
            ans.append(S[i]+S[j]+S[k])
ans_set = set(ans)
print(len(ans_set))

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(int,list(input())))
def judge(x,l):
  ret = False
  num = 0
  for a,n in enumerate(l):
    if n==x:
      ret = True
      num = a
      break
      
  return ret,num

ans = 0
for i in range(10):
  tf1,n1 = judge(i,S)
  if tf1:
    for j in range(10):
      tf2,n2 = judge(j,S[n1+1:])
      if tf2:
        for k in range(10):
          tf3,n3=judge(k,S[n1+n2+2:])
          if tf3:
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
import math

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

arr = list(str(S))
cnt = 0

for i in range(1000):
  a = math.floor(i/100)
  b = math.floor((i-a*100)/10)
  c = i-a*100-b*10
  
  if str(a) in arr:
    an = arr.index(str(a))
    del arr[:an+1]
    
    if str(b) in arr:
      bn = arr.index(str(b))
      del arr[:bn+1]
      
      if str(c) in arr:
        cnt = cnt + 1
        
  arr = list(str(S))
      
print(cnt)