Problem:


Score: 400 points

Problem Statement

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

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

How many different PIN codes can he set this way?

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

Constraints

4 \leq N \leq 30000

S is a string of length N consisting of digits.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of different PIN codes Takahashi can set.

Sample Input 1

4
0224

Sample Output 1

3

Takahashi has the following options:

Erase the first digit of S and set 224.

Erase the second digit of S and set 024.

Erase the third digit of S and set 024.

Erase the fourth digit of S and set 022.

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

Sample Input 2

6
123123

Sample Output 2

17

Sample Input 3

19
3141592653589793238

Sample Output 3

329



Sample input:
4
0224


Sample output:
3

Submission status: Accepted

Solution code:
def Binary_Search_Count(A,x,sort=True,equal=False):
    """2分探索によって,x未満の要素の個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"未満"がx"以下"になる
    """
    if sort:
        A.sort()
        
    N=len(A)
    if A[-1]<=x:
        return N
    elif x<A[0] or (not equal and x==A[0]):
        return 0

    L,R=0,N
    while R-L>1:
        C=L+(R-L)//2
        if x<A[C] or (not equal and x==A[C]):
            R=C
        else:
            L=C
    return R

def Binary_Search_High_Value(A,x,sort=True,equal=False):
    """Aのxを超える要素の中で最小のものを出力する.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"を超える"がx"以上"になる
    ※全ての要素がx以下(未満)場合はNoneが返される.
    """
    
    if sort:
        A.sort()

    K=Binary_Search_Count(A,x,sort=False,equal=not equal)
    if K==len(A):
        return None
    else:
        return A[K]

N=int(input())
T={i:[] for i in range(10)}

S=input()
for i in range(N):
    T[int(S[i])].append(i)

X=0
for k in range(10**3):
    a,b,c=(k//100),(k//10)%10,k%10

    if T[a]:
        x=T[a][0]
        if T[b]:
            y=Binary_Search_High_Value(T[b],x,False,False)
            if y!=None and T[c]:
                z=Binary_Search_High_Value(T[c],y,False,False)
                if z!=None:
                    X+=1
print(X)

Submission status: Accepted

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

cnt = 0
for key in range(1000):
    key = '{:0>3}'.format(str(key))    #; print(key)
    i0 = s.find(key[0])
    if 0 <= i0 < N-2:
        i1 = s.find(key[1], i0+1)
        if 0 < i1 < N-1:
            i2 = s.find(key[2], i1+1)
            if i2 != -1:
                cnt += 1                                 
print(cnt)

Submission status: Accepted

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

ans = 0
for i in range(10):
    idx0 = S[: N - 2].find(str(i))
    if idx0 != -1:
        for j in range(10):
            idx1 = S[idx0 + 1 : N - 1].find(str(j))
            if idx1 != -1:
                for k in range(10):
                    idx2 = S[idx0 + idx1 + 2 :].find(str(k))
                    if idx2 != -1:
                        ans += 1

print(ans)

Submission status: Accepted

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

cnt = 0
for key in range(1000):
    key = '{:0>3}'.format(str(key))    #; print(key)
    i0 = s.find(key[0])
    if 0 <= i0 < N-2:
        i1 = s.find(key[1], i0+1)
        if 0 < i1 < N-1:
            i2 = s.find(key[2], i1+1)
            if i2 != -1:
                cnt += 1
            else:
                continue
        else:
            continue        
    else:
        continue
                                   
print(cnt)

Submission status: Accepted

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

ans = 0

for x in [0,1,2,3,4,5,6,7,8,9]:
  if x in S:
    x_index = S.index(x)
    for y in [0,1,2,3,4,5,6,7,8,9]:
      if y in S[x_index+1:]:
        y_index = S[x_index+1:].index(y)
        for z in [0,1,2,3,4,5,6,7,8,9]:
          if z in S[x_index + 1 + y_index+1:]:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
cnt=0
def judge(n):
    pos=0
    pos=s.find(n[0],pos)
    if pos==-1:
        return 0
    pos=s.find(n[1],pos+1)
    if pos==-1:
        return 0
    pos=s.find(n[2],pos+1)
    if pos==-1:
        return 0
    return 1
for i in range(1000):
    p=str(i).rjust(3,'0')
    if judge(p):
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for pin in range(10**3):
    str_pin = str(pin)
    str_pin = str_pin.zfill(3)
    nex = 0
    for i in range(n):
        searching_for = str_pin[nex]
        now_s = s[i]
        if searching_for == now_s:
            nex += 1
            if nex == 3:
                ans += 1
                break
print(ans)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
S = input()
pairs = []
for i in range(len(S)):
    pairs.append([int(S[i]),i])

pairs = sorted(pairs)
cnt = 0

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

for i in range(N):
    numlists[pairs[i][0]].append(pairs[i][1])

ans = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            if(len(numlists[i]) == 0):
                continue
            indi = min(numlists[i])


            if(len(numlists[j]) == 0):
                continue
            if(max(numlists[j]) <= indi):
                continue
            
            
            indj = bisect.bisect_right(numlists[j],indi)
            indj = numlists[j][indj]
            if(len(numlists[k]) == 0):
                continue
            if(max(numlists[k]) <= indj):
                continue

            #indk = bisect.bisect_right(numlists[k],indj)

            cnt += 1
            #ans.append("{}{}{}:{}{}{}".format(i,j,k,indi,indj,indk))

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int, input()))
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            p = 0
            while p < len(s) and s[p] != i: p += 1
            p += 1
            while p < len(s) and s[p] != j: p += 1
            p += 1
            while p < len(s) and s[p] != k: p += 1
            if p < len(s):
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
# forしながらif、ifでないときはforしないので、計算量減
# 初期入力　　２０２０－０７２７　21：50
from collections import Counter
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
*S, =input().strip()
"""
c =Counter(S)
ans =combinations_count(N, 3) -len(c)
"""
count =0
x100=0
x10=0
x1=0
for i in range(10):
    if str(i) not in S:
        continue
    else:
        x100 =S.index(str(i)) +1
        for j in range(10):
            if str(j) not in S[x100:]:
                continue
            else:
                x10 =S[x100:].index(str(j)) +1
                for k in range(10):
                    if str(k) in S[x100 +x10:]:
                        x1 =S[x100+x10:].index(str(k)) +1
                        count +=1
                        #print("aa",i,j,k,"bb",x100,x100+x10,x100+x10+x1)

print(count)

Submission status: Accepted

Solution code:
# forしながらif、ifでないときはforしないので、計算量減
# 初期入力　　２０２０－０７２７　21：50
from collections import Counter
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
*S, =input().strip()
"""
c =Counter(S)
ans =combinations_count(N, 3) -len(c)
"""
count =0
x100=0
x10=0
x1=0
for i in range(10):
    if str(i) in S:
        x100 =S.index(str(i)) +1
        for j in range(10):
            if str(j) in S[x100:]:
                x10 =S[x100:].index(str(j)) +1
                for k in range(10):
                    if str(k) in S[x100 +x10:]:
                        x1 =S[x100+x10:].index(str(k)) +1
                        count +=1
                        #print("aa",i,j,k,"bb",x100,x100+x10,x100+x10+x1)

print(count)

Submission status: Accepted

Solution code:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


# 初期入力　　２０２０－０７２７　21：50
from collections import Counter
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
*S, =input().strip()
"""
c =Counter(S)
ans =combinations_count(N, 3) -len(c)
"""
count =0
x100=0
x10=0
x1=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if str(i) in S:
                x100 =S.index(str(i)) +1
                if str(j) in S[x100:]:
                    x10 =S[x100:].index(str(j)) +1
                    if str(k) in S[x100 +x10:]:
                        x1 =S[x100+x10:].index(str(k)) +1
                        count +=1
                        #print("aa",i,j,k,"bb",x100,x100+x10,x100+x10+x1)

print(count)

Submission status: Accepted

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

def F(S,M): #output: count:: not in S
    if M ==1:
        ans = 0
        for i in range(10):
            if str(i) in S:
                continue
            else:
                ans +=1
        return ans
    ans = 0
    for i in range(10):
        for j in range(len(S)):
            if i == int(S[j]):
                ans += F(S[j+1:], M-1)
                break
        else:
            ans += 10**(M-1)
    return ans
    
ans = F(S,3)


print(10**3 - ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = input()
ans = 0
for x in range(10):
    for y in range(10):
        hantei = []
        for i in range(N):
            if x != int(S[i]):
                continue
            for j in range(i+1, N):
                if y != int(S[j]):
                    continue
                for k in range(j+1, N):
                    hantei.append(S[k])
                ans += len(Counter(hantei))
                break
            break

print(ans)

Submission status: Accepted

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

result = 0
for i in range(1000):
    i = str(i).zfill(3)
    # print(i)
    # print(s.find(i[0]), s.find(i[1]), s.find(i[2]))
    index0 = s.find(i[0])
    if -1 < index0:
        index1 = s.find(i[1], index0+1)
        if -1 < index1:
            index2 = s.find(i[2], index1+1)
            if -1 < index2:
                # print(i, 'あたり')
                result += 1

print(result)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
R = S[::-1]

count = 0

for v in range(1000):
  V = str(v).zfill(3)
  right = -1
  left = -1
  if V[2] in R:
    r = R.index(V[2]) + 1
    right = N-r
  else:
    continue
  if V[0] in S:
    left = S.index(V[0]) + 1
  else:
    continue
  if V[1] in S[left:right]:
    count += 1

print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1000):
    tmp = str(i).zfill(3)
    number = [tmp[0],tmp[1],tmp[2],"OK"]
    pos = 0
    for ss in s:
        if ss == number[pos] and pos < 3:
            pos += 1
    if number[pos] == "OK":
        ans += 1
print(ans)

Submission status: Accepted

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


def main():
    n = int(input())
    S: str = input()
    ans = 0
    for s1 in range(10):
        idx1 = S.find(str(s1))
        if idx1 == -1:
            continue

        for s2 in range(10):
            idx2 = S.find(str(s2), idx1+1)
            if idx2 == -1:
                continue

            for s3 in range(10):
                idx3 = S.find(str(s3), idx2+1)
                if idx3 >= 0:
                    ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
R = S[::-1]

ans = 0
for i in range(1000):
  z = str(i).zfill(3)
  right = -1
  left = -1
  if z[2] in R:
    r = R.index(z[2]) + 1
    right = N-r
  else:
    continue
  if z[0] in S:
    left = S.index(z[0]) + 1
  else:
    continue
  if z[1] in S[left:right]:
    ans += 1
print(ans)

Submission status: Accepted

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

counter = 0
for i in range(10):
    str_i = str(i)
    i_dig = s.find(str_i)
    if i_dig == -1:
        continue

    for j in range(10):
        str_j = str(j)
        j_dig = s.find(str_j, i_dig+1)
        if j_dig == -1:
            continue
        
        for k in range(10):
            str_k = str(k)
            k_dig = s.find(str_k, j_dig+1)
            if k_dig != -1:
                counter += 1

print(counter)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
d={}
ans=0
for x in range(n-2):
  if s[x] not in d:
    d[s[x]]=0
    for y in range(x+1,n-1):
      if (s[x]+s[y]) not in d:
        d[(s[x]+s[y])]=0
        for z in range(y+1,n):
          if (s[x]+s[y]+s[z]) not in d:
            d[(s[x]+s[y]+s[z])]=0
            ans+=1
    
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import bisect

N = int(input())
S = input()
# s2i = [[] for i in range(10)]
s2i = defaultdict(list)

for i, si in enumerate(S):
    s2i[si] += [i]

ans = 0

for i in range(1000):
    pin = str(i).zfill(3)
    ii = -1
    flag = True
    for p in pin:
        s2ip = s2i[p]
        if s2ip:
            iii = bisect.bisect_right(s2ip, ii)
            if iii == len(s2ip):
                flag = False
                break
            ii = s2ip[iii]
        else:
            flag = False
            break
    if flag:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    S=list(input())

    ans = 0
    for i in range(1000):
        pin = str(i)
        if len(pin) == 1:
            pin = "00"+pin
        elif len(pin) == 2:
            pin = "0"+pin
        
        waiti = 0
        for j in range(N):
            if S[j] == pin[waiti]:
                waiti += 1
                if waiti == 3:
                    break
                    
        if waiti == 3:
            ans += 1

    print(ans)
            
            





if __name__ == "__main__":
    main()

Submission status: Accepted

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

N = int(readline())
S = readline().rstrip()

ans = 0

numlist = [[] for i in range(10)]
for i in range(len(S)):
  numlist[int(S[i])].append(i)

ans = 0
import bisect
for i in range(1000):
  target = str(i).zfill(3)
  now = 0
  for j in range(len(target)):
    tar = int(target[j])
    pos = bisect.bisect_left(numlist[tar], now)
    if pos >= len(numlist[tar]):
      break
    now = numlist[tar][pos] + 1
  else:
    ans += 1

print(ans)

Submission status: Accepted

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

lst = set()
ans = []
for i in range(n):
  pin = ''
  if numbers[i] not in lst:
    pin += numbers[i]
    lst.add(pin)
    lst2 = set()
    for j in range(i+1, n):
      pin += numbers[j]
      if pin[1] not in lst2:
        lst2.add(pin[1])
        lst3 = set()
        for k in range(j+1, n):
          pin += numbers[k]
          if pin[2] not in lst3:
            lst3.add(pin[2])
            ans.append(pin)
          if ('0' in lst3) and ('1' in lst3) and ('2' in lst3) and ('3' in lst3) and ('4' in lst3) and ('5' in lst3) and ('6' in lst3) and ('7' in lst3) and ('8' in lst3) and ('9' in lst3):
            break
          pin = pin[0] + pin[1]
      if ('0' in lst2) and ('1' in lst2) and ('2' in lst2) and ('3' in lst2) and ('4' in lst2) and ('5' in lst2) and ('6' in lst2) and ('7' in lst2) and ('8' in lst2) and ('9' in lst2):
        break
      pin = pin[0]
    if ('0' in lst) and ('1' in lst) and ('2' in lst) and ('3' in lst) and ('4' in lst) and ('5' in lst) and ('6' in lst) and ('7' in lst) and ('8' in lst) and ('9' in lst):
      break
print(len(ans))

Submission status: Accepted

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

lst = []
ans = []
for i in range(n):
  pin = ''
  if numbers[i] not in lst:
    pin += numbers[i]
    lst.append(pin)
    lst2 = []
    for j in range(i+1, n):
      pin += numbers[j]
      if pin[1] not in lst2:
        lst2.append(pin[1])
        lst3 = []
        for k in range(j+1, n):
          pin += numbers[k]
          if pin[2] not in lst3:
            lst3.append(pin[2])
            ans.append(pin)
          if ('0' in lst3) and ('1' in lst3) and ('2' in lst3) and ('3' in lst3) and ('4' in lst3) and ('5' in lst3) and ('6' in lst3) and ('7' in lst3) and ('8' in lst3) and ('9' in lst3):
            break
          pin = pin[0] + pin[1]
      if ('0' in lst2) and ('1' in lst2) and ('2' in lst2) and ('3' in lst2) and ('4' in lst2) and ('5' in lst2) and ('6' in lst2) and ('7' in lst2) and ('8' in lst2) and ('9' in lst2):
        break
      pin = pin[0]
    if ('0' in lst) and ('1' in lst) and ('2' in lst) and ('3' in lst) and ('4' in lst) and ('5' in lst) and ('6' in lst) and ('7' in lst) and ('8' in lst) and ('9' in lst):
      break
print(len(ans))

Submission status: Accepted

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

lst = [0]*10

dic = {(i,j):set() for i in range(10) for j in range(10)}
a = set()
b = set()

for s_ in S:
  s = int(s_)
  for t in b:
    dic[t].add(s)
  for i in a:
    b.add((i,s))
  a.add(s)

rlt = 0
for c in dic:
  rlt += len(dic[c])
  
print(rlt)

Submission status: Accepted

Solution code:
_ = input()
s = list(input())
cnt = 0
for i in range(1000):
    a = list(f'{i:03}')
    if a[0] not in s: continue
    s1 = s[s.index(a[0])+1:]
    if a[1] not in s1: continue
    s1 = s1[s1.index(a[1])+1:] 
    if a[2] not in s1: continue
    cnt += 1
print(cnt)

Submission status: Accepted

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

ans=0

for i in range (1000):
    tempS=S
    pin=str(i).zfill(3)
    t1=pin[0]
    t2=pin[1]
    t3=pin[2]
    if tempS.count(t1)>=1:
        tempS=tempS[tempS.find(t1)+1:]
    else:
        continue

    if tempS.count(t2)>=1:
        tempS=tempS[tempS.find(t2)+1:]
    else:
        continue

    if tempS.count(t3)>=1:
        ans+=1
    else:
        continue

print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = input()
ans = 0
for i in range(10):
    ind = s.find(str(i))+1
    if ind == 0 or ind == len(s):
        continue
    for j in range(10):

        ind_j = ind + s[ind:].find(str(j))+1
        if ind_j == ind or ind_j == len(s):
            continue
        cnt = collections.Counter(s[ind_j:])
        ans += len(cnt)

print(ans)

Submission status: Accepted

Solution code:
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    s = readline().rstrip()
    cnt = 0
    for i in range(1000):
        x = str(i).zfill(3)
        a = s[:-1].find(x[0])
        if a != -1:
            b = s[a + 1: -1].find(x[1])
            if b != -1:
                c = s[a + b + 2:].find(x[2])
                if c != -1:
                    cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(10):
  a = s.find(str(i))
  if a == -1:
    continue
  for i in range(10):
    b = s.find(str(i), a + 1)
    if b == -1:
      continue
    for i in range(10):
      if s.find(str(i), b + 1) != -1:
        result += 1

print(result)

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
s = [_ for _ in input()][::-1]

a = set()
ans=0
ii = set()
for i in range(n-2):
  if s[i] in ii:
    continue
  ii.add(s[i])
  jj = set()
  for j in range(i+1,n-1):
    if s[j] in jj:
      continue
    jj.add(s[j])
    kk = set()
    for k in range(j+1,n):
      if k not in kk:
        ans+=1
        kk.add(s[k])
        a.add(''.join([s[k],s[j],s[i]]))
    
print(len(a))

Submission status: Accepted

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

score = 0

for p in range(1000):
    
    pw = str(p).zfill(3)
    
    start = 0
    n_match = 0
    
    for j in range(3):
        for i in range(start, len(s)):
            
            if s[i] == pw[j]:
                start = i+1
                n_match = n_match+1
                
                if j == 3-1:
                    # print(pw)
                    score = score+1
                
                break
        if n_match <= j:
            break
            
print(score)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil
N = int(input())
S = input()
ans = [0]*1000
one = [0]*10
two = [0]*100

for s in S:
    s = int(s)
    for i in range(10):
        for j in range(10):
            if two[i*10+j]//1:
                ans[i*100+j*10+s] = 1 
            else:
                if one[i]//1 and two[i*10+s] == 0:
                    two[i*10+s] = 0.5
                elif one[s] == 0:
                    one[s] = 0.5        
    one = list(map(lambda x: ceil(x), one))
    two = list(map(lambda x: ceil(x), two))

print(sum(ans))

Submission status: Accepted

Solution code:
from math import ceil
N = int(input())
S = input()
ans = [0]*1000
one = [0]*10
two = [0]*100

for s in S:
    s = int(s)
    for i in range(10):
        for j in range(10):
            if two[i*10+j]//1:
                ans[i*100+j*10+s] = 1 
            else:
                if one[i]//1 and two[i*10+s] == 0:
                    two[i*10+s] = 0.5
                elif one[s] == 0:
                    one[s] = 0.5        
    one = list(map(lambda x: ceil(x), one))
    two = list(map(lambda x: ceil(x), two))

print(sum(ans))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    S = readline().decode('utf-8').strip()
    ans = 0
    for i in range(10):
        x = S.find(str(i), 0, N - 2)
        if x != -1:
            for j in range(10):
                y = S.find(str(j), x + 1, N - 1)
                if y != -1:
                    for k in range(10):
                        z = S.find(str(k), y + 1, N)
                        if z != -1:
                            ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
lis = [0]*1000
one = [0]*10
two = [0]*100

for i in range(n):
  temp1 = int(s[i])
  if one[temp1]==1:
    continue
  else:
    one[temp1]=1
 
  for j in range(i+1, n):
    temp2 =  int("".join([s[i], s[j]]))
    if two[temp2]==1:
      continue
    else:
      two[temp2]=1
    
    for k in range(j+1, n):
      pin=int("".join([s[i], s[j], s[k]]))
      if lis[pin]==0:
        ans+=1
        lis[pin]=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cou = 0
for i in range(1000):
  i = "{0:03d}".format(i)
  t = 0
  r = 0
  while r!=n:
    if s[r]==i[t]:
      t += 1
    if t==3:
      cou += 1
      r = n-1
    r += 1            
print(cou)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
 
numlist = [str(i) for i in range(10)]
for a in numlist:
    idx_a = S.find(a)
    if idx_a == -1 or idx_a >= N - 2:
        continue
    
    for b in numlist:
        idx_b = S[idx_a+1:].find(b)
        if idx_b == -1 or idx_a + idx_b + 1 >= N - 1:
            continue
        
        for c in numlist:
            if c in S[idx_a + idx_b + 2:]:
                ans += 1
print(ans)

Submission status: Accepted

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

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

ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    first = S.find(key[0])
    if first == -1:
        continue
    second = S[first + 1:].find(key[1])
    if second == -1:
        continue
    third = S[first + second + 2:].find(key[2])
    if not third == -1:
        #print(key, first, second, third)
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    res = str(i).zfill(3)
    cnt = 0
    p = res[cnt]
    for s in S:
        if p == s:
            cnt += 1
            if cnt == 3:
                ans += 1
                break
            p = res[cnt]
print(ans)

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

N = int(input())
S = input()
sl = list(S)
setS = set(S)
ans = 0
for i in range(10):
    if str(i) not in setS:
        continue
    else:
        i100_ind = sl.index(str(i))
        S10 =sl[i100_ind+1:-1]
        S10set = set(S10)
        for j in range(10):
            if str(j) not in S10set:
                continue
            else:
                i10_ind = S10.index(str(j))
                S1 = S10[i10_ind+1:]
                S1.append(sl[-1])
                ans += len(set(S1))
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(10):
  for j in range(10):
    for k in range(10):
      if i in S:
        a = S.index(i)
        if j in S[a+1:]:
          b = S[a+1:].index(j) + a + 1
          if k in S[b+1:]:
            ans += 1
          else:
            continue
        else:
          continue
      else:
        continue

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()
S = input()

ans = 0

for i in range(1000):
    x = str(i).zfill(3)
    begin_idx = -1
    idx = 0
    while idx <= 2:
        begin_idx = S.find(x[idx], begin_idx+1)
        if begin_idx == -1:
            break
        idx += 1
    else:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:

N=int(input())
S=list(input())
numlist=range(1000)
ans=0

for i in numlist:
    num=str(i)
    if len(num)==1:
        num="00"+num
    if len(num)==2:
        num="0"+num
    if num[0] in S[:N-1]:
        num1=S.index(num[0])
        if num[1] in S[num1+1:N-1]:
            S2=S[num1+1:N-1]
            num2=S2.index(num[1])+num1+1
            if num[2] in S[num2+1:]:
                ans+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = []
first = []
for i in range(n - 2):
    if s[i] in first:continue
    first.append(s[i])
    second = []
    for j in range(i + 1, n - 1):
        if s[j] in second:continue 
        second.append(s[j])
        third = []
        for k in range(j + 1, n):
            if s[k] in third:continue  
            third.append(s[k])
            ans.append(s[i] + s[j] + s[k])
            
print(len(ans))

Submission status: Accepted

Solution code:
import collections
N = int(input())
S = input()
S_list = [S[i] for i in range(N)]
S_c = collections.Counter(S_list)
list12 = []
list1 = []

ans = 0
for i in range(N-2):
    s1 = S_list[i]

    S_c[s1] = S_c[s1]-1
    if s1 in list1:
        continue

    S_c23 = S_c.copy()
    list1.append(s1)
    for j in range(i+1,N-1):
        s2 = S_list[j]
        
        S_c23[s2] = S_c23[s2] - 1
        if (s1+s2) in list12:
            continue
        else:
            list12.append(s1+s2)
            for key in S_c23.keys():
                if S_c23[key] != 0:
                    ans+=1
print(ans)

Submission status: Accepted

Solution code:

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

count = 0
for N in range(1000):
    password = list(f"{N:03d}")
    i = 0
    p = password[i]
    for x in S:
        if x == p:
            if i < 2:
                i += 1
                p = password[i]
            else:
                count += 1
                break

print(count)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s = input()
def snx(s, target=None, reverse=False, loop=False):
    """文字列sの各要素について、cがiより→で最初に現れる位置n[i][c]
    loop=Trueのとき周回した先のインデックスまで求める
    """
    if target is None:
        target = [chr(v) for v in range(ord("a"), ord("z")+1)]
    d = {c:None for c in target}
    nx = [[None]*len(target) for _ in range(len(s))]
    if not reverse:
        i = len(s)-1
        for c in reversed(s):
            d[c] = i
            for j,t in enumerate(target):
                nx[i][j] = d[t]
            i -= 1
        if loop:
            for i in range(len(s)):
                for j in range(len(target)):
                    if nx[i][j] is None:
                        nx[i][j] = nx[0][j]
    else:
        i = 0
        for c in s:
            d[c] = i
            for j,t in enumerate(target):
                nx[i][j] = d[t]
            i += 1
        if loop:
            for i in range(len(s)):
                for j in range(len(target)):
                    if nx[i][j] is None:
                        nx[i][j] = nx[-1][j]
    return nx
nx = snx(s, target=list(map(str, range(10))))
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            try:
                if nx[0][i] is not None and nx[nx[0][i]+1][j] is not None and nx[nx[nx[0][i]+1][j]+1][k] is not None:
#                     print(i, j, k)
                    ans += 1
            except IndexError:
                pass
print(ans)

Submission status: Accepted

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

cnt=0
for i,j in product("0123456789",repeat=2):
    try:
        ind_i=s.index(i)
    except:
        continue
    try:
        ind_j=s.rindex(j)
    except:
        continue
    if ind_i>ind_j:
        continue
    for k in "0123456789":
        cnt+=(k in s[ind_i+1:ind_j])
        
print(cnt)

Submission status: Accepted

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

for N in range(1000):
    tgt = str(N).zfill(3)
    if tgt[0] in s:
        i = s.index(tgt[0])
        if tgt[1] in s[i+1:]:
            j = s[i+1:].index(tgt[1]) + i
            if tgt[2] in s[j+2:]:
                cnt += 1
print(cnt)

Submission status: Accepted

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

ans = 0

for i in range(10):
    a = s.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = s.find(str(j), a + 1)
        if b == -1:
            continue
        for k in range(10):
            c = s.find(str(k), b + 1)
            if c == -1:
                continue
            ans += 1
print(ans)