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 itertools
N=int(input())
S=[int(thing) for thing in list(input())]
kes=N-3
pass_set=set([])
def passkosu(k):
    num = 0

    if k in S[0:N-1]:
        l_left=S.index(k)
        for l in range(0,10):
            if l in S[l_left+1:N-1]:
                l_center=S[l_left+1:].index(l)+l_left+1
                dif=len(set(S[l_center+1:]))
                num=num+dif
    return num

print(sum([passkosu(i) for i in range(0,10)]))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
PIN=[]
b1=[]
for i in range(N-2):
    Ein=S[i]
    b2=[]
    if Ein in b1:
        continue
    else:
        b1.append(Ein)
    for j in range(i+1,N-1):
        b3=[]
        Zwei=S[j]
        if Zwei in b2:
            continue
        else:
            b2.append(Zwei)
        for k in range(j+1,N):
            Drei=S[k]
            if Drei in b3:
                continue
            else:
                b3.append(Drei)
                cand=Ein+Zwei+Drei
            if cand in PIN:
                continue
            else:
                PIN.append(cand)
print(len(PIN))

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = list(input())


al = set()

dp = [[[0 for k in range(10)] for i in range(10)] for j in range(10)]


kkk = [[0 for j in range(10)]for i in range(n)]
count = 0
for i in range(n):
    k = int(a[i])
    if i == 0:
        kkk[i][k] += 1
    else:
        for j in range(10):
            if k == j:
                kkk[i][j] += kkk[i-1][j] + 1
            else:
                kkk[i][j] += kkk[i-1][j]

for i in range(1,n-1):
    e = int(a[i])
    ae = []
    for pl in range(10):
        if kkk[i-1][pl] > 0:
            ae.append(pl)
    for pl in range(10):
        if kkk[-1][pl] - kkk[i][pl] > 0:
            for pp in ae:
                if not dp[pp][e][pl]:
                    count += 1
                    dp[pp][e][pl] += 1
                    


print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np
import itertools
from functools import reduce
from itertools import chain
# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"

inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    N=I()
    X=S()
    OUT=np.array([[[0]*10]*10]*10)

    for i in range(10):
        x=(X.find(str(i)))
        if x>-1:
            X2=X[x+1:]
            for j in range(10):
                y=(X2.find(str(j)))
                if y>-1:
                    X3=X2[y+1:]
                    for k in range(10):
                        z=(X3.find(str(k)))
                        if z>-1:
                            OUT[i][j][k]=1

    print(OUT.sum())


        # for j in range(10):
        #     max_idx=0
        #     for k in range(10):
        #         target=[i,j,k]
        #         idx=0

        #         for x in X:
        #             if x==str(target[idx]):
        #                 idx+=1
        #             if idx==3:
        #                 OUT[i][j][k]=1
        #                 max_idx=idx
        #                 break
        #         max_idx=idx
        #         if max_idx<2:
        #             break



    # print(OUT.sum())
    # print(sum(list(chain.from_iterable(OUT))))

if __name__ == "__main__":
    main()


#     # -*- coding: utf-8 -*-
# """
# AtCoder A
# """

# import sys, math, random
# # import numpy as np
# import itertools
# from functools import reduce
# # N = int(input())
# # A = list(map(int,input().split())) # N row 1 column
# # A = [int(input()) for _ in range(N)] # 1 row N column
# # S = str(input()) # str(input()) == input() -> 'abc'
# # S = list(input()) # abc -> ['a','b','c']
# # S.replace('ABC','X') # "testABCABC" -> "testXX"

# inf = 10**20
# eps = 1.0 / 10**10
# mod = 10**9+7
# dd = [(-1,0),(0,1),(1,0),(0,-1)]
# ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

# def LI(): return list(map(int, sys.stdin.readline().split()))
# def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
# def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
# def LS(): return sys.stdin.readline().split()
# def I(): return int(sys.stdin.readline())
# def F(): return float(sys.stdin.readline())
# def S(): return input()


# def main():
#     N=I()
#     X=S()
#     OUT=np.array([[[0]*10]*10]*10)
#     for i in range(10):
#         for j in range(10):
#             for k in range(10):
#                 target=[i,j,k]
#                 idx=0
#                 for x in X:
#                     if x==str(target[idx]):
#                         idx+=1
#                     if idx==3:
#                         OUT[i][j][k]=1
#                         break
#     print(OUT.sum())
#     sum(reduce(lambda a, b: a + b, OUT))

# if __name__ == "__main__":
#     main()

Submission status: Accepted

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

count=0
for i in range(1000):
    W=str(i).rjust(3,'0')
    a,b,c=W[0],W[1],W[2]
    t=0
    while S[t]!=a and t<N-1:
        t+=1
    t+=1
    if t>N-1:
        continue
    while S[t]!=b and t<N-1:
        t+=1
    t+=1
    if t>N-1:
        continue
    while S[t]!=c and t<N-1:
        t+=1
    if t<N:
        if S[t]==c:
#            print(W)
            count+=1

print(count)

Submission status: Accepted

Solution code:
#import sys
#input = sys.stdin.readline
n = int(input())
l = [d for d in input()]
k = set(l[:-2])
c = 0
for kk in list(k):
    i = l[:-2].index(kk)
    o = set(l[i + 1:-1])
    for oo in list(o):
        ii = l[i + 1:-1].index(oo) + (i + 1)
        p = set(l[ii + 1:])
        c += len(p)
print(c)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
for i,s in enumerate(S):
    S[i] = int(s)

res = 0
first_index = [-1 for i in range(10)]
second_index = [[-1 for i in range(10)] for j in range(10)]

first_map = set()
second_map = [set() for i in range(10)]
third_map = [[set() for i in range(10)] for j in range(10)]

for i,s in enumerate(S):
    if(first_index[s] == -1):
        first_index[s] = i
        first_map.add(s)
    if(len(first_map) == 10):
        break
for first in first_map:
    for i,s in enumerate(S[first_index[first]+1:]):
        if(second_index[first][s] == -1):
            second_index[first][s] = first_index[first]+1+i
            second_map[first].add(s)
        if(len(second_map[first]) == 10):
            break
for first in first_map:
    for second in second_map[first]:
        for i,s in enumerate(S[second_index[first][second] + 1:]):
            if(s not in third_map[first][second]):
                res += 1
                third_map[first][second].add(s)
            if(len(third_map[first][second]) == 10):
                break
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
#0なし
numlist = [""]
dp = [False] * 1000
for s in S:
    tmp = []
    for n in numlist:
        if len(n+s) == 3:
            dp[int(n+s)] = True
        if len(n+s) < 3:
            tmp.append(n+s)
    numlist.extend(tmp)
    numlist = list(set(numlist))
print(sum(dp))

Submission status: Accepted

Solution code:

def main():
    N=int(input())
    strvar = input()
    # num =[]
    
    # for i in range(strvar.length()):
    #     num+=[int(strvar[i])]

    possible = 0
    for i in range(10):
        iind = strvar.find(str(i))
        if iind == -1:
            continue
        for j in range(10):
            jind =strvar[iind+1:].find(str(j))
            if jind==-1:
                continue
            for k in range(10):
                if str(k) in strvar[iind+1+jind+1:]:
                    possible += 1

    print(possible)


if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import bisect

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

idx = [[] for i in range(10)]

for i in range(n):
  idx[ord(s[i]) - ord('0')].append(i)

ans = 0
for i in range(1000):
  flag = True
  i_str = format(i, "03d")
  _idx = -1
  for j in range(3):
    if not flag or len(idx[ord(i_str[j]) - ord('0')]) == 0:
      flag = False
      break
    __idx = bisect.bisect_left(idx[ord(i_str[j]) - ord('0')], _idx + 1)
    if __idx == len(idx[ord(i_str[j]) - ord('0')]):
      flag = False
      break
    else:
      _idx = idx[ord(i_str[j]) - ord('0')][__idx]
  if flag:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
s=input()
PIN=[]
firs=[]
sec=[]
thir=[]
for i in range(N-2):
    if s[i] not in firs:
        firs.append(s[i])
        for j in range(i+1,N-1):
            if s[j] not in sec:
                sec.append(s[j])
                for k in range(j+1,N):
                    if s[k] not in thir:
                        thir.append(s[k])
                        PIN.append(s[i]+s[j]+s[k])
                thir=[]
        sec=[]       
print(len(PIN))

Submission status: Accepted

Solution code:
import math
import sys

n1=set()
n2=set()
n3=set()

N = int(input())
S = input()
# print(N,S)

for i in range(len(S)):
    s = S[i]
    # print(s)
    for s2 in n2:
        s3 = s2 + s
        if s3 not in n3:
            n3.add(s3)
    for s1 in n1:
        s2 = s1 + s
        if s2 not in n2:
            n2.add(s2)
    if s not in n1:
        n1.add(s)
    # print(n1,n2,n3)
print(len(n3))

Submission status: Accepted

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

    cnt = 0
    for i in range(1000):
        target = str(i).zfill(3)
        idx = 0
        for ch in S:
            if ch == target[idx]:
                idx += 1
                if idx == 3:
                    cnt += 1
                    break
    
    print(cnt)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

N=input()
S=raw_input()

center_kouho=set()

for i,x in enumerate(S):
    if i==0 or i==N-1: continue
    center_kouho.add(x)

left=[ set() for _ in range(N) ]
right=[ set() for _ in range(N) ]
for i in range(N):
    if i==0:
        continue
    else:
        left[i]=copy.deepcopy(left[i-1])
        left[i].add(S[i-1])

for i in range(N-1,-1,-1):
    if i==N-1:
        continue
    else:
        right[i]=copy.deepcopy(right[i+1])
        right[i].add(S[i+1])

ans=0

for center in center_kouho:
    kazoeage=set()
    for i,x in enumerate(S):
        if x==center:
            for l in left[i]:
                for r in right[i]:
                    kazoeage.add(l+center+r)
    ans+=len(kazoeage)

print ans

Submission status: Accepted

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

rr = {}
r = set()
for i in range(len(s) - 1, 0, -1):
    t = s[i]
    r.add(t)
    rr[i] = r.copy()

a = [[set() for j in range(10)] for i in range(10)]
l = set()
for i in range(1, len(s) - 1):
    t = s[i]
    l.add(s[i-1])
    r = rr[i+1]
    for j in l:
        a[t][j] |= r

ans = 0
for b in a:
    for c in b:
        ans += len(c)
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations, permutations
from bisect import bisect_right, bisect_left

def solve(N, S):
    left = [-1]*10
    right = [-1]*10
    place = [[] for i in range(10)]
    for i in range(N):
        c = int(S[i])
        if left[c] == -1:
            left[c] = i
        right[c] = i
        place[c].append(i)

    def ok(s, dbg=False):
        l, m, r = [int(c) for c in s]
        if left[l] == -1 or right[r] == -1:
            return False
        if not left[l] < right[r]:
            return False
        j = bisect_right(place[m], left[l])
        if j == len(place[m]):
            return False
        mid = place[m][j]
        if mid < right[r]:
            #print(left[l], place[m], right[r])
            #print(left[l], mid, right[r])
            return True
        return False

    count = 0
    for i in range(0, 1000):
        s = "%03d" % i
        if ok(s):
            count += 1
    #print(ok("224", True))

    return count

def check(N, S):
    c = set()
    for s in combinations(range(N), 3):
        s = tuple(S[i] for i in s)
        #s = S[:i] + S[i+1:j] + S[j+1:k] + S[k+1:]
        if s not in c:
            pass
        c.add(s)
        
    return len(c)

def main():
    N = int(input())
    S = input()
    #print(check(N, S))
    print(solve(N, S))

def test(S):
    print(S,check(len(S), S), "==", solve(len(S), S))

#test("0224")
#test("123123")
#test("3141592653589793238")
main()

Submission status: Accepted

Solution code:
import bisect





def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return True
    return False




def resolve():
    N=int(input())
    s=[int(i) for i in input()]
    dpt3=[False for i in range(1000)]    
    dpt2=[]
    dpt1=[]
    bisect.insort(dpt1,s[0])
    bisect.insort(dpt1,s[1])
    bisect.insort(dpt1,s[2])
    bisect.insort(dpt2,s[0]*10+s[1])
    bisect.insort(dpt2,s[1]*10+s[2])
    bisect.insort(dpt2,s[0]*10+s[2])

    dpt1=list(set(dpt1))
    dpt1.sort()
    dpt2=list(set(dpt2))
    dpt2.sort()

    cc=[0 for i in range(100)]
    cc2=[0 for i in range(10)]
    cc[s[2]]=1
    for i in dpt2:
        cc2[i%10]+=1


    dpt3[s[0]*100+s[1]*10+s[2]]=True
    count3=1
    count2=len(dpt2)
    count1=len(dpt1)
    for i in s[3:]:

        if count3==1000:
            break
        if cc[i]!=100:
            for j in dpt2:
                tn=j*10+i


                if not dpt3[tn]:
                    dpt3[tn]=True
                    cc[i]+=1
                    count3+=1
        if cc2[i]!=10:        
            for j in dpt1:
                tn=j*10+i
                if not index(dpt2,tn):
                    bisect.insort(dpt2,tn)
                    cc2[i]+=1
        if not index(dpt1,i):
            bisect.insort(dpt1,i)
    count3=0
    for i in dpt3:
        if i:
            count3+=1
    print(count3)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n=int(input())
s=[int(i) for i in input()]
#print(s)
def my_index(l,x,ind):
    global 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):
    #print(i)
    x1=my_index(s,i,0)
    #print(c)
    if x1!=-1:
        #print(i)
        for j in range(10):
            x2=my_index(s,j,x1+1)
            if x2!=-1:
                for k in range(10):
                    if my_index(s,k,x2+1)!=-1:
                        #print(i,j,k)
                        c+=1
print(c)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = input()
ls = [float('inf') for i in range(10)]
for i in range(10):
    if str(i) in S:
        ls[i] = S.index(str(i))
ans = 0
for i in range(10):
    if ls[i] != float('inf') and ls[i]+1 != N and ls[i]+2 != N:
        s = S[ls[i]+1:]
        ls2 = [float('inf') for i in range(10)]
        for j in range(10):
            if str(j) in s:
                ls2[j] = s.index(str(j))
        for j in range(10):
            if ls2[j] != float('inf') and ls2[j]+1 != len(s):
                a = s[ls2[j]+1:]
                d = Counter(a)
                ans += len(d)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
t = input()
S = []
for i in range(N):
    S.append(t[i])
import copy
ans = 0
f = []
for i in range(10):
    if str(i) in S:
        f.append(str(i))
while len(f) > 0 and len(S) > 2:
    k = S.pop(0)
    if k in f:
        f.remove(k)
        s = []
        for j in range(10):
            if str(j) in S:
                s.append(str(j))
        T = copy.deepcopy(S)
        while len(s) > 0 and len(T) > 1:
            l = T.pop(0)
            if l in s:
                s.remove(l)
                for i in range(10):
                    if str(i) in T:
                        ans += 1
                        
print(ans)

Submission status: Accepted

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

#com = list(set([c[0]+c[1]+c[2] for c in itertools.combinations(S,3)]))
#com = list(set([c[0]+c[1]+c[2] for c in itertools.combinations(N,3)]))
#print(len(com))


# X1_list = [int(input()) for i in range(N)]
# X2_list = [list(map(int,input().split())) for i in range(N)]
result = 0

for i in range(0,1000):
    s = str(i).zfill(3)
    #print(s[0] + '\d' + s[1] + '\d' + s[2])
    #pattern = '\d' + s[0] + '*\d' + s[1] + '*\d' + s[2] + '*\d'
    #import re
    #repattern = re.compile(pattern)
    #result = repattern.match(S)
    first_index = S.find(s[0])
    if first_index == -1:
        continue
    S_1 = S[first_index+1:]
    second_index = S_1.find(s[1])
    if second_index == -1:
        continue
    S_2 = S_1[second_index+1:]
    third_index = S_2.find(s[2])
    if third_index == -1:
        continue
    result += 1
print(result)

Submission status: Accepted

Solution code:
def f():
    n = int(input())
    s = input()
    leftMemo = [None]*10
    rightMemo = [None]*10
    for i in range(10):
        char = str(i)
        for j in range(n):
            if s[j] == char:
                leftMemo[i] = j
                break
        for k in range(n-1,-1,-1):
            if s[k] == char:
                rightMemo[i] = k
                break
    ans = 0
    for leftNum in range(10):
        if leftMemo[leftNum] is None:
            continue
        start = leftMemo[leftNum]+1
        for rightNum in range(10):
            if rightMemo[rightNum] is None:
                continue
            end = rightMemo[rightNum]
            ans += len(set(s[start:end]))
    print(ans)


f()

Submission status: Accepted

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

pin1 = {}
pin12 = {}
pin123 = {}

for i in range(N):
    if S[i] not in pin1:
        pin1[S[i]] = 1
        for j in range(i + 1, N):
            if S[i] + S[j] not in pin12:
                pin12[S[i] + S[j]] = 1
                for k in range(j + 1, N):
                    if S[i] + S[j] + S[k] not in pin123:
                        pin123[S[i] + S[j] + S[k]] = 1

print(len(pin123))

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(int,list(input())))
all = []
ilist = []
for i in range(N-2):
    if S[i] in ilist:
        pass
    else:
        ilist.append(S[i])
        jlist = []
        for j in range(N-i-1):
            if S[i+j+1] in jlist:
                pass
            else:
                jlist.append(S[i+j+1])
                klist = []
                for k in range(N-i-j-2):
                    if S[i+j+k+2] in klist:
                        pass
                    else:
                        klist.append(S[i+j+k+2])
                        all.append([S[i],S[i+j+1],S[i+j+k+2]])
print(len(all))

Submission status: Accepted

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

for i in range(n):
     lst.append(s%10)
     s //= 10
lst.reverse()

ten = [-1]*10
hun = [-1]*100
tho = [-1]*1000

for i in range(len(lst)):
    l = lst[i]
    for j in range(100):
        if not hun[j] == -1:
            idx = j*10 + l
            tho[idx] = 1
    for j in range(10):
        if not ten[j] == -1:
            idx = j*10 + l
            hun[idx] = 1
    ten[l] = 1

ans = 0
for i in range(1000):
    if tho[i] == 1:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
a = []
b = []
c = []
answer = 0
for i in range(n):
    b = []
    if not s[i] in a:
        a.append(s[i])
        if i < n-2:
            for j in range(i+1,n):
                c = []
                if not s[j] in b:
                    b.append(s[j])
                    if j < n-1:
                        for k in range(j+1,n):
                            if not s[k] in c:
                                c.append(s[k])
                                answer += 1
                            if len(c) == 10:
                                break
                if len(b) == 10:
                        break
        if len(a) == 10:
            break
print(answer)

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(int, list(input())))
t = {}
for i in range(N):
    t.setdefault(S[i], []).append(i)
ans = 0
for i in range(10):
    if i not in t:
        continue
    ti = t[i][0]
    for j in range(10):
        if j not in t:
            continue
        tj = -1
        for jj in t[j]:
            if ti < jj:
                tj = jj
                break
        else:
            continue
        for k in range(10):
            if k not in t:
                continue
            tk = -1
            for kk in t[k]:
                if tj < kk:
                    ans += 1
                    break
print(ans)

Submission status: Accepted

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


def main():
    N = int(input())
    S = input().strip()
    ans = 0
    for i in range(1000):
        s = "{:03}".format(i)
        a = S.find(s[0])
        b = S.find(s[1], a+1)
        c = S.find(s[2], b+1)
        if a >= 0 and b >= 0 and c >= 0 and (a < b < c):
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

cnt=0
for i in range(1000):
  a=i//100
  b=(i-a*100)//10
  c=i-a*100-b*10
  if a in s:
    an=s.index(a)
    tmp=s[an+1:]
    if b in tmp:
      bn=tmp.index(b)
      tmp=tmp[bn+1:]
      if c in tmp:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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



N=one_int()
S=one_str()
S="".join(S)

S=list(S)
S_set=set(S)

# s
sums = 0
dicts = {}
for i in S_set:
    temp = 0
    ind = S.index(i)
    if ind+1!=N:
        for j in set(S[ind+1:]):
            ind2 = S[ind+1:].index(j)
            
            if (ind+ind2+2) != N:
                sums+=len(set(S[ind+ind2+2:]))
print(sums)

Submission status: Accepted

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

flagL = [0 for i in range(100)]
L = [0 for i in range(1000)]

num1 = int(s[0])
for i in range(10):
  flagL[num1*10+i] = 1

num2 = int(s[1])
for i in range(10):
  flagL[num2*10+i] = 1
flagL[10*num1+num2] = 2

for i in range(len(s)-2):
  num = int(s[i+2])
  for j in range(100):
    if flagL[j] == 2:
      L[j*10+num] = 1    
  for k in range(10):
    if flagL[k*10+num] == 1:
      flagL[k*10+num] = 2
    if flagL[num*10+k] == 0:
      flagL[num*10+k] = 1
  
print(sum(L))

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    s=input()
    ans=0
    f00=[False if str(i) in set(str(s)) else True for i in range(10)]
    f0=f00.copy()
    for i0 in range(n-2):
        if all(f0):
            break
        if not f0[int(s[i0])]:
            f1=f00.copy()
            for i1 in range(i0+1,n-1):
                if all(f1):
                    break
                if not f1[int(s[i1])]:
                    ans+=len( set( s[i1+1:] ) )
                    f1[int(s[i1])]=True
        f0[int(s[i0])]=True
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
S=list(map(int,list(input())))

#print(S)

def search(lis,num):
    for index,item in enumerate(lis):
        if item==num:
            return True,index
  
    return False,-1

l=[[[0 for i in range(10)] for i in range(10)] for i in range(10)]
ans=0
for i in range(10):
    judge1,temp1=search(S,i)
    #print(temp1)
    if judge1:
        #print(i)
        for j in range(10):
            judge2,temp2=search(S[temp1+1:],j)
            if judge2:
                #print(j)
                for k in range(10):
                    #print(k)
                    if search(S[temp1+temp2+2:],k)[0]:
                        #print(i,j,k)
                        #print(temp1,temp1+temp2)
                        l[i][j][k]=1
                    else:
                        continue
            else:
                continue
    else:
        continue
ans=0
for item in l:
    for item2 in item:
        ans+=sum(item2)

#print(l)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = input()
tgt = []
res = 0
for i in range(0,1000):
    tgt = []
    if i <= 99:
        tgt.append('0')
    else:
        tgt.append(str(i//100))
    if i <= 9:
        tgt.append('0')
    else:
        tgt.append(str((i%100)//10))
    tgt.append(str(i%10))
    #print(tgt)
    now = 0
    if tgt[0] in s:
        t1 = s.index(tgt[0])
        if tgt[1] in s[t1+1:]:
            t2 = s[t1+1:].index(tgt[1])
            if tgt[2] in s[t1+t2+2:]:
                t3 = s[t1+t2+2:].index(tgt[2])
                res += 1
                #print(tgt)
print(res)

Submission status: Accepted

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

s = [0] * 10
d = [0] * 100
t = [0] * 1000

s[int(a[0])] = 1
s[int(a[1])] = 1
d[int(a[1]) * 10 + int(a[0])] = 1

for x in a[2:]:
    y = int(x)
    z = y * 100
    for i in range(100):
        if d[i] == 1:
            t[z + i] = 1
    z = y * 10
    for i in range(10):
        if s[i] == 1:
            d[z + i] = 1
    s[y] = 1

print(t.count(1))

Submission status: Accepted

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


ans = 0

cand = sorted(set(S), key=S.index)

for i in cand:
  index = S.find(i)
  newS = S[index+1:]

  newcand = sorted(set(newS), key=newS.index)

  for j in newcand:
    newindex = newS.find(j)
    newnewS = newS[newindex+1:]

    newnewcand = sorted(set(newnewS), key=newnewS.index)


    ans += len(newnewcand)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
a_list=[]
for i in sorted(list(set(s[:-2]))):
    index = s.index(str(i))
    for j in sorted(list(set(s[index+1:-1]))):
        index_2 = s[index+1:].index(j)+index+1
        ans += len(set(s[index_2+1:]))

print(ans)