Problem:


Score: 400 points

Problem Statement

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

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

How many different PIN codes can he set this way?

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

Constraints

4 \leq N \leq 30000

S is a string of length N consisting of digits.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of different PIN codes Takahashi can set.

Sample Input 1

4
0224

Sample Output 1

3

Takahashi has the following options:

Erase the first digit of S and set 224.

Erase the second digit of S and set 024.

Erase the third digit of S and set 024.

Erase the fourth digit of S and set 022.

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

Sample Input 2

6
123123

Sample Output 2

17

Sample Input 3

19
3141592653589793238

Sample Output 3

329



Sample input:
4
0224


Sample output:
3

Submission status: Accepted

Solution code:
import sys

def main():
    # input = sys.stdin.readline

    n=int(input())
    s=list(map(int,input()))
    # s.pop(-1)
    cnt=0
    for i in range(10):
        if i in s[:-2]:
            idx1=s[:-2].index(i)
            for j in range(10):
                if j in s[idx1+1:-1]:
                    idx2=s[idx1+1:-1].index(j)+idx1+1
                    for k in range(10):
                        if k in s[idx2+1:]:
                            cnt+=1
    print(cnt)

    #
    # tmp=[0,0,0]
    # cnt=0
    # for i in range(0,1000):
    #     if i < 10:
    #         tmp[0]=0
    #         tmp[1]=0
    #         tmp[2]=i
    #     elif i < 100:
    #         tmp[0]=0
    #         tmp[1]=i//10
    #         tmp[2]=i-tmp[1]*10
    #     else:
    #         tmp[0]=i//100
    #         tmp[1]=(i-tmp[0]*100)//10
    #         tmp[2]=i-tmp[0]*100-tmp[1]*10
    #     ketaflg=0
    #     for j in s :
    #         if j == '\n':
    #             break
    #         if tmp[0]==int(j) and ketaflg==0:
    #             ketaflg=1
    #         elif tmp[1]==int(j) and ketaflg==1:
    #             ketaflg=2
    #         elif tmp[2]==int(j) and ketaflg==2:
    #             ketaflg=3
    #             cnt+=1
    #             break
    # print(cnt)


if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys

def is_password(s, p):
    check = s.find(p[0])
    idx = check + 1
    if check == -1:
        return False
    check = s[idx:].find(p[1])
    if check == -1:
        return False
    idx = idx + check + 1
    check = s[idx:].find(p[2])
    if check == -1:
        return False
    return True

f = sys.stdin
n = int(f.readline())
s = f.readline()[:-1]

count = 0
for l1 in range(10):
    for l2 in range(10):
        for l3 in range(10):
            p = str(l1) + str(l2) + str(l3)
            if is_password(s, p):
                count += 1

print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(int,input()))
count = 0
for i in range(10):
    if i in S[:-2] :
        v1 = S[:-2].index(i)
        for j in range(10):
            if j in S[v1+1:-1] :
                v2 = S[v1+1:-1].index(j) + v1 + 1
                for k in range(10):
                    if k in S[v2+1:] :
                        count += 1
print(count)

Submission status: Accepted

Solution code:
a=[[0]*10,[0]*100,[0]*1000]
n=int(input())
s=input()
for i in s:
  d=int(i)
  for j in range(100):
    if a[1][j]:
      a[2][10*j+d]=1
  for j in range(10):
    if a[0][j]:
      a[1][10*j+d]=1
  a[0][d]=1
print(sum(a[2]))

Submission status: Accepted

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

L = []
R = []
tmp = set()
for s in S:
    tmp.add(s)
    L.append(tmp.copy())
tmp = set()
for s in S[::-1]:
    tmp.add(s)
    R.append(tmp.copy())
R = R[::-1]

ans = set()

for i in range(1,N-1):
    b = S[i]
    for a in L[i-1]:
        for c in R[i+1]:
            ans.add((a,b,c))

print(len(ans))

Submission status: Accepted

Solution code:
a=[set(),set(),set()]
n=int(input())
s=input()
for i in s:
  for j in a[1]:
    a[2].add(j+i)
  for j in a[0]:
    a[1].add(j+i)
  a[0].add(i)
print(len(a[2]))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(0,10):
  for j in range(0,10):
    left = s.find(str(i))
    right = s.rfind(str(j))
    if left<0 or right <= left:
      continue
    for k in range(0,10):
      ans += int(str(k) in s[left+1:right])
print(ans)

Submission status: Accepted

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

ans=0
for x in range(1000):
  x=str(x).zfill(3)
  p1=S.find(x[0])
  if p1==-1: continue
  p2=S.find(x[1],p1+1)
  if p2==-1: continue
  p3=S.find(x[2],p2+1)
  if p3==-1: continue
  ans+=1
print(ans)

Submission status: Accepted

Solution code:
from string import digits

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

cnt = 0
for i in digits:
    x = s.find(i)
    if x == -1:
        continue
    for j in digits:
        y = s.find(j, x + 1)
        if y == -1:
            continue
        for k in digits:
            z = s.find(k, y + 1)
            if z == -1:
                continue
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n = int(input()) #長さ
s = str(input()) #文字列
cnt = 0 #暗証番号数

for a in range(10): #1文字目
  for b in range(10): #2文字目
    for c in range(10): #3文字目
      flg = False
      check_a = s.find(str(a))
      if check_a != -1:
        tmp_s = s[check_a + 1:]
        check_b = tmp_s.find(str(b))
        if check_b != -1:
          tmp_t = tmp_s[check_b + 1:]
          check_c = tmp_t.find(str(c))
          if check_c != -1:
            cnt = cnt + 1            
print(cnt)

Submission status: Accepted

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

count = 0
for p in range(1000):
    v = format(p, '03')
    found = False
    pos1 = S.find(v[0])
    if pos1 == -1:
        continue
    pos2 = S[pos1 + 1:].find(v[1])
    if pos2 == -1:
        continue
    pos3 = S[pos1 + pos2 + 2:].find(v[2])
    if pos3 == -1:
        continue
    count += 1

print(count)

Submission status: Accepted

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

for x in range(10):
	for y in range(10):
		for z in range(10):
			i = s.find(str(x))
			if i != -1:
				i = s.find(str(y), i+1)
				if i != -1:
					i = s.find(str(z), i+1)
					if i != -1:
						cnt += 1
				
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
s = input()

dp = [[False] * 1000 for i in range(4)]
for i in range(10):
    dp[0][i] = True
for c in s:
    k = int(c)
    for i in range(3)[::-1]:
        for j in range(10**i):
            dp[i + 1][10 * j + k] |= dp[i][j]
print(sum(dp[3]))

Submission status: Accepted

Solution code:
input()
a=set(),set(),set(),{''}
for s in input():
 for b,c in zip(a,a[1:]):b|={t+s for t in c}
print(len(a[0]))

Submission status: Accepted

Solution code:
_,s=open(0)
dp=[[0]*1000for _ in range(4)]
dp[0][0]=1
for c in map(int,s[:-1]):
  for i in range(3,0,-1):
    for j in range(10**(i-1)):
      dp[i][j*10+c]|=dp[i-1][j]
print(sum(dp[3][i]for i in range(1000)))

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):
            idx = S.find(str(k))
            if idx != -1:
                idx = S.find(str(j),idx+1)
                if idx != -1:
                    idx = S.find(str(i),idx+1)
                    if idx != -1:
                        cnt += 1

print(cnt)

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):
            idx = 0
            a = S.find(str(k),idx)
            if a != -1:
                idx = a
                b = S.find(str(j),idx+1)
                if b != -1:
                    idx = b
                    c = S.find(str(i),idx+1)
                    if c != -1:
                        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin

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

ans = 0
num_str = [str(i).zfill(3) for i in range(1000)]

for i in num_str:
    j = 0
    k = 0
    while k < 3:
        while j < len(S):
            if S[j] == i[k]:
                k += 1
                j += 1
                break
            j += 1
        if j == len(S):
            break
    if k == 3:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  S = tuple(input())
  ans = 0
  for i in range(1000):
    if i<10:
      cnt0= 0
      cnt1 = 0
      for j in range(N):
        if 2<=cnt0 and S[j]=="%d"%i:
          ans+=1
          break
        if S[j]=="0":
          cnt0+=1
          continue
    elif 10<=i<=99:
      cnt0=0
      cnt1=0
      cnt2=0
      i = list(str(i))
      for j in range(N):
        if 1<=cnt0 and 1<=cnt1 and S[j]=="%s"%i[1]:
          ans+=1
          break
        if S[j]=="0" and cnt0!=1:
          cnt0+=1
          continue
        if 1<=cnt0 and S[j]=="%s"%i[0]:
          cnt1 +=1
          continue
    elif 100<=i:
      cnt0=0
      cnt1=0
      cnt2=0
      i = list(str(i))
      for j in range(N):
        if 1<=cnt0 and 1<=cnt1 and S[j]=="%s"%i[2]:
          ans+=1
          #print(i)
          break
        if S[j]=="%s"%i[0] and cnt0!=1:
          cnt0+=1
          continue
        if 1<=cnt0 and S[j]=="%s"%i[1]:
          cnt1 +=1
          continue
  print(ans)
main()

Submission status: Accepted

Solution code:
from bisect import bisect_right
from collections import defaultdict

N = int(input())
S = input()
INF = float('inf')

nToD = defaultdict(list)
for d, s in enumerate(S):
    nToD[s].append(d)
for d in range(10):
    nToD[str(d)].append(INF)

ans = 0
for i in range(1000):
    P = '%03d' % i
    prev = nToD[P[0]][0]

    if prev == INF:
        continue

    for p in P[1:]:
        prev = nToD[p][bisect_right(nToD[p], prev)]
        if prev == INF:
            break
    else:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
i_lis=[]
key=0
for i in range(N-2):
  if S[i] in i_lis:continue
  else:i_lis.append(S[i])
  j_lis=[]
  for j in range(i+1,N-1):
    if S[j] in j_lis:continue
    else:j_lis.append(S[j])
    k_lis=[]
    for k in range(j+1,N):
      if S[k] in k_lis:continue
      else:k_lis.append(S[k]);key+=1
print(key)

Submission status: Accepted

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


def main():
    sc = Scan()
    _ = sc.intarr()[0]
    S = sc.strarr()[0]

    count = 0

    for i in range(1000):
        # print("--------")
        lucky = format_str(i)
        first = S.find(lucky[0])
        third = S.rfind(lucky[2])

        if first == -1 or third == -1:
            continue
        elif first < third:
            if lucky[1] in S[first + 1:third]:
                count += 1
    print(count)


def format_str(num):
    if num < 10:
        return "00" + str(num)
    elif num < 100:
        return "0" + str(num)
    else:
        return str(num)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


main()

Submission status: Accepted

Solution code:
import sys
from string import digits

def main():
    n, s = sys.stdin.read().split()

    cnt = 0
    for i in digits:
        x = s.find(i)
        if x == -1:
            continue
        for j in digits:
            y = s.find(j, x + 1)
            if y == -1:
                continue
            for k in digits:
                z = s.find(k, y + 1)
                if z == -1:
                    continue
                cnt += 1

    print(cnt)

if __name__ == '__main__':
    main()

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):
            #print(str(i) + str(j)+ str(k))
            fi = s.find(str(i))
            if fi < 0:
                continue
            fj = s[fi+1:].find(str(j))
            if fj < 0:
                continue
            fk = s[(fi+1)+(fj+1):].find(str(k))
            if fk < 0:
                continue
            #print(str(i) + str(j)+ str(k), str(fi) + str(fj)+ str(fk))
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    S = list(input()[:-1])
    A = [str(i) for i in range(10)]

    cnt = 0
    for P in itertools.product(A, repeat=3):
        m = 0
        for s in S:
            if s==P[m]:
                m += 1
            if m==3:
                break
        if m==3:
            cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
c1 = [0] * 10
c2 = [0] * 100
c3 = [0] * 1000
for i in s:
  i = int(i)
  for j in range(100):
    c3[j*10+i] = c2[j]
  for j in range(10):
    c2[j*10+i] = c1[j]
  c1[i] = 1
print(sum(c3))

Submission status: Accepted

Solution code:
import sys
from string import digits

def main():
    n, s = sys.stdin.read().split()
    n = int(n)

    place = dict((i, list()) for i in digits)
    for i in range(n):
        place[s[i]].append(i)

    l = [None] * n
    l[0] = set()
    for i in range(1, n):
        l[i] = l[i-1] | set([s[i-1]])
    
    r = [None] * n
    r[n-1] = set()
    for i in range(n-2, -1, -1):
        r[i] = r[i+1] | set([s[i+1]])

    res = set()
    for j in digits:
        p = place[j]
        if not p:
            continue
        for i in digits:
            for k in digits:
                for c in p:
                    if not k in r[c]:
                        break
                    if not i in l[c]:
                        continue
                    res.add((i, j, k))
                    break
    print(len(res))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8

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

count = 0
candidate = ["00" + str(i) for i in range(1000)]

for i in candidate:
    first = S.find(i[-3])
    #second = min(S.find(i[-2]),S.rfind(i[-2]))
    third = S.rfind(i[-1])
    if first==-1 or third==-1:
        continue
    elif first<third:
        if i[-2] in S[first+1:third]:
            count+=1
print(count)

Submission status: Accepted

Solution code:
import sys
from string import digits

def main():
    n, s = sys.stdin.read().split()
    n = int(n)

    place = dict((i, set()) for i in digits)
    for i in range(n):
        place[s[i]].add(i)

    l = [None] * n
    l[0] = set()
    for i in range(1, n):
        l[i] = l[i-1] | set([s[i-1]])
    
    r = [None] * n
    r[n-1] = set()
    for i in range(n-2, -1, -1):
        r[i] = r[i+1] | set([s[i+1]])

    res = set()
    for j in digits:
        for i in digits:
            for k in digits:
                for c in place[j]:
                    if not i in l[c]:
                        continue
                    if not k in r[c]:
                        continue
                    res.add((i, j, k))
                    break
    print(len(res))


if __name__ == '__main__':
    main()

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):
            preindex = 0
            flag1 = 0
            flag2 = 0
            flag3 = 0 
            while preindex < n:
                if s[preindex] == i:
                    preindex += 1
                    flag1 = 1
                    break
                preindex += 1

            while preindex < n:
                if s[preindex] == j:
                    preindex += 1
                    flag2 = 1
                    break
                preindex += 1

            while preindex < n:
                if s[preindex] == k:
                    flag3 = 1
                    break
                preindex += 1
            if flag1 and flag2 and flag3:
                ans += 1
print(ans)

Submission status: Accepted

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

single_flag = [False]*10
dual_flag = {}
ans = {}
for i in range(10):
    for j in range(10):
        dual_flag[(i, j)] = False
        ans[(i, j)] = set()

for s in S:
    for i in range(10):
        for j in range(10):
            if dual_flag[i, j]:
                ans[(i, j)].add(s)
    for i in range(10):
        if single_flag[i]:
            dual_flag[(i, int(s))] = True
    single_flag[int(s)] = True

tmp = 0
for v in ans.values():
    tmp += len(v)
print(tmp)

Submission status: Accepted

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

single_flag = [False]*10
dual_flag = {}
ans = {}
for i in range(10):
    for j in range(10):
        dual_flag[(i, j)] = False
        ans[(i, j)] = set()

for s in S:
    for i in range(10):
        for j in range(10):
            if dual_flag[i, j]:
                ans[(i, j)].add(int(s))
    for i in range(10):
        if single_flag[i]:
            dual_flag[(i, int(s))] = True
    single_flag[int(s)] = True

tmp = 0
for v in ans.values():
    tmp += len(v)
print(tmp)

Submission status: Accepted

Solution code:
import sys
from string import digits

def main():
    n, s = sys.stdin.read().split()
    n = int(n)

    place = dict((i, set()) for i in digits)
    for i in range(n):
        place[s[i]].add(i)

    l = [None] * n
    l[0] = set()
    for i in range(1, n):
        l[i] = l[i-1] | set([s[i-1]])
    
    r = [None] * n
    r[n-1] = set()
    for i in range(n-2, -1, -1):
        r[i] = r[i+1] | set([s[i+1]])

    res = set()
    for j in digits:
        for c in place[j]:
            for i in digits:
                if i in l[c]:
                    for k in digits:
                        if k in r[c]:
                            res.add((i, j, k))
    
    print(len(res))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
for i in range(1000):
  tmp=str(i)
  while len(tmp)<3:
    tmp="0"+tmp
  j=0

  for k in range(n):
    if tmp[j]==s[k]:
      j+=1
    if j==3:
      ans+=1
      break
print(ans)

Submission status: Accepted

Solution code:
n,S,r=int(input()),input(),0
dp1=[0]*n
dp2=[0]*n
d=set()
for i, c in enumerate(S):
    dp1[i] = len(d)
    d.add(c)

cs = [0 for i in range(10)]
d=set()
for i, c in enumerate(S[::-1]):
    dp2[i] = len(d)
    r += dp1[n-i-1]*(dp2[i]-dp2[cs[int(c)]])
    d.add(c)
    cs[int(c)] = i
print(r)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for a in range(10):
  for b in range(10):
    for c in range(10):
      a, b, c = str(a), str(b), str(c)
      a_find = s.find(a)
      if a_find == -1:
        continue
      b_find = s.find(b, a_find + 1)
      if b_find == -1:
        continue
      c_find = s.find(c, b_find + 1)
      if c_find == -1:
        continue
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations

input = sys.stdin.readline


def check_num(text):
    cnt = 0
    for i in range(10):
        index = text.find(str(i))
        if index != -1:
            cnt += 1
    return cnt


def main():
    # 種類
    # N = int(input())
    # S = input().strip()
    S = sum(str(i) for i in range(10))
    for i in range(10):
        index = S.find(str(i))
        if index != -1:
            a = check_num(S[index:])
    # 10個の数字
    # 最大1000件
    # 0-9:0-9:0-9
    # print(len(set(combinations(S, 3))))


def hoge():
    N = int(input())
    S = input().strip()
    count = 0
    for x in range(10):
        xindex = S.find(str(x))
        if xindex == -1:
            continue
        for y in range(10):
            yindex = S[xindex + 1 :].find(str(y))
            if yindex == -1:
                continue
            for z in range(10):
                zindex = S[xindex + 1 :][yindex + 1 :].find(str(z))
                if zindex == -1:
                    continue
                count += 1
    print(count)


if __name__ == "__main__":
    hoge()

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):
      l = 0
      for c in S:
        if l == 0 and ord(c) - ord('0') == i: l += 1
        elif l == 1 and ord(c) - ord('0') == j: l += 1
        elif l == 2 and ord(c) - ord('0') == k: l += 1
      if l == 3:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
from string import digits

def main():
    n, s = sys.stdin.read().split()

    res = []
    for i in digits:
        x = s.find(i)
        if x == -1:
            continue
        for j in digits:
            y = s.find(j, x+1)
            if y == -1:
                continue
            for k in digits:
                if k in s[y+1:]:
                    res.append((i, j, k))
                    
    print(len(res))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from string import digits

def main():
    n, s = sys.stdin.read().split()

    res = []
    for i in digits:
        x = s.find(i)
        if x == -1:
            continue
        for j in digits:
            y = s.find(j, x+1)
            if y == -1:
                continue
            for k in digits:
                z = s.find(k, y+1)
                if z == -1:
                    continue
                res.append((i, j, k))

    print(len(res))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import product

n = int(input())
S = input()

numCnt = {str(i):[] for i in range(10)}
ps = [''.join(list(s)) for s in product('0123456789',repeat=3)]
#print(ps)

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

ans = 0
for k in ps:
    if not numCnt[k[0]] or not numCnt[k[2]] or numCnt[k[0]][0] > numCnt[k[2]][-1]: 
        continue
    
    l,r = numCnt[k[0]][0], numCnt[k[2]][-1]

    for i in numCnt[k[1]]:
        if l < i < r:
            ans += 1
            break
        
print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
S = input()
S = [int(x) for x in S]

left_index = [[-1] * (N+1) for _ in range(10)]

for i,x in enumerate(S,1):
	for j in range(10):
		left_index[j][i] = left_index[j][i-1]
	left_index[x][i] = i


answer = 0
for a,b,c in itertools.product(range(10),repeat=3):
	i = N
	bl = True
	for x in [a,b,c]:
		i = left_index[x][i] - 1
		if i < -1:
			bl = False
			break
	if bl:
		answer += 1

print(answer)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(10):
    fp = S.find(str(i))
    if fp == -1:
        continue

    for j in range(10):
        sp = S.find(str(j), fp + 1)
        if sp == -1:
            continue

        for k in range(10):
            if str(k) in S[sp + 1:]:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    ls1 = [False] * 1000
    ls2 = [False] * 1000
    ls3 = [False] * 1000
    for i in range(n):
        t = [s[i]]
        if not ls1[int("".join(t))]:
            ls1[int("".join(t))] = True
            for j in range(i + 1, n):
                t = [s[i], s[j]]
                if not ls2[int("".join(t))]:
                    ls2[int("".join(t))] = True
                    for k in range(j + 1, n):
                        t = [s[i], s[j], s[k]]
                        ls3[int("".join(t))] = True
    print(ls3.count(True))


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())
S = [int(i) for i in input()]
ans = 0
for i in range(10):
    fp = -1
    for tf in range(N - 2):
        if S[tf] == i:
            fp = tf
            break
    if fp == -1:
        continue

    for j in range(10):
        sp = -1
        for ts in range(fp + 1, N - 1):
            if S[ts] == j:
                sp = ts
                break
        if sp == -1:
            continue

        for k in range(10):
            for tt in range(sp + 1, N):
                if S[tt] == k:

                    ans += 1
                    break

print(ans)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    ls1 = [0] * 1000
    ls2 = [0] * 1000
    ls3 = [0] * 1000
    for i in range(n):
        t = [s[i]]
        if not ls1[int("".join(t))]:
            ls1[int("".join(t))] = True
            for j in range(i + 1, n):
                t = [s[i], s[j]]
                if not ls2[int("".join(t))]:
                    ls2[int("".join(t))] = True
                    for k in range(j + 1, n):
                        t = [s[i], s[j], s[k]]
                        ls3[int("".join(t))] = True
    print(ls3.count(True))


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    dict1 = collections.defaultdict(int)
    dict2 = collections.defaultdict(int)
    dict3 = collections.defaultdict(int)
    for i in range(n):
        t = [s[i]]
        if "".join(t) not in dict1:
            dict1["".join(t)]
            for j in range(i + 1, n):
                t = [s[i], s[j]]
                if "".join(t) not in dict2:
                    dict2["".join(t)]
                    for k in range(j + 1, n):
                        t = [s[i], s[j], s[k]]
                        dict3["".join(t)]
    print(len(dict3))


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from collections import Counter

x=int(input())
n=str(input())


#print(countN)
#abc
aaa=set([])
result=0
for i in range(x-2):
    a=n[i]
    if a not in aaa:
        aaa.add(a)
        bbb=set([])
        for j in range(i+1,x-1):
            b=n[j]
            if b not in bbb:
                bbb.add(b)
                ccc=set([])
                for k in range(j+1,x):
                    c=n[k]
                    if c not in ccc:
                        ccc.add(c)
                        result+=1
                    if len(ccc)==10:
                      break
                
                if len(bbb)==10:
                  break
    if len(aaa)==10:
        break
print(result)

Submission status: Accepted

Solution code:
#dp[i]:i+1桁目-n桁目で1桁の数字は/2桁の数字は/何通りあるか
n = int(input())
s = input()
ans = 0
for i in range(10):
    for j in range(10):
        t1 = n-1
        u1 = n-1
        for t in range(n):
            if i == int(s[t]):
                t1 = t
                break
        for u in range(t1+1,n):
            if j == int(s[u]):
                u1 = u
                break
        if int(s[t1]) == i and int(s[u1]) == j and t1<u1:
            #print(i,j,k,t1,u1,v1)
            ans += len(set(s[u1+1:]))
print(ans)

Submission status: Accepted

Solution code:
INF = 100000
n=int(input())
s=input()
ls = []
ls = [int(c) for c in s]
flag = [[INF for _ in range(10)]]

ls.reverse()

for i in range(n):
    flag[i][ls[i]] = n - i
    flag.append(flag[i][:])

flag.reverse()

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            keta1 = flag[0][k]
            if keta1 != INF and keta1 != n:
                keta2 = flag[keta1+1][j]
                if keta2 != INF and keta2 != n:
                    keta3 = flag[keta2+1][i]
                    if keta3 != INF:
                        res += 1

print(res)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
a = [set(), set(), set()]
for i in range(n):
    for j in a[1]:
        a[2].add(j + s[i])
    for j in a[0]:
        a[1].add(j + s[i])
    a[0].add(s[i])
print(len(a[2]))

Submission status: Accepted

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

def Check(x):
	a = [chr(x//100%10+48),chr(x//10%10+48),chr(x%10+48)]
	p = 0
	for c in s:
		if a[p] == c:
			p += 1
			if p == 3:
				return True
	return False

ans = 0
for i in range(1000):
	if Check(i):
		ans += 1
print(ans)

Submission status: Accepted

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

ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            for p in range(len(s)):
                if s[p]==str(i):
                    for q in range(p+1,len(s)):
                        if s[q]==str(j):
                            for r in range(q+1,len(s)):
                                if s[r]==str(k):
                                    ans+=1
                                    break
                            break
                    break

print(ans)

Submission status: Accepted

Solution code:
# 000~999で決め打ちして数える
# TLEになるんだけどこれそんなに重いか？？？？？

n = int(input())
s = input()
ans = 0

for i in range(0, 1000):
    t = format(i, "0>3")
    idx = 0
    for c in s:
        if c == t[idx]:
            idx += 1
        if idx == 3:
            ans += 1
            break

print(ans)

Submission status: Accepted

Solution code:
from collections import*
_,s=open(0)
dp=defaultdict(bool)
d1=[str(i)for i in range(10)]
d2=[str(i).zfill(2)for i in range(100)]
for c in s[:-1]:
  for i in d2:
    dp[i+c]|=dp[i]
  for i in d1:
    dp[i+c]|=dp[i]
  dp[c]=True
print(sum(dp[str(i).zfill(3)]for i in range(1000)))

Submission status: Accepted

Solution code:
import sys
import bisect
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 = list(map(int, [i for i in S()]))

ID = [[] for _ in range(10)]
for i in range(N):
  ID[s[i]].append(i)

cnt = 0
for a in range(10):
  n1 = bisect.bisect_left(ID[a], 0)
  if n1 == len(ID[a]):
    continue
  for b in range(10):
    n2 = bisect.bisect_left(ID[b], ID[a][n1]+1)
    if n2 == len(ID[b]):
      continue
    for c in range(10):
      n3 = bisect.bisect_left(ID[c], ID[b][n2]+1)
      if n3 == len(ID[c]):
        continue
      cnt += 1
      #print(a,b,c)
print(cnt)

Submission status: Accepted

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

    for i in range(10):
        s1 = S.find(str(i), 0, -2)
        if s1 == -1:
            continue
        for j in range(10):
            s2 = S.find(str(j), s1+1, -1)
            if s2 == -1:
                continue
            ans += len(set(S[s2+1:]))
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())
S = input()
Pin = ['{0:03d}'.format(a) for a in range(0,1000)]
cnt = 0
for i in Pin:
  S1 = S
  A1 = S1.find(i[0])
  if A1!=-1:
    S2 = S1[(A1+1):]
    A2 = S2.find(i[1])
    if A2!=-1:
      S3 = S2[(A2+1):]
      A3 = S3.find(i[2])
      if A3!=-1:
        cnt +=1
print(cnt)