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: Runtime Error

Solution code:

N = int(input())
S = input()
S = list(S)
i = 0
j = 0
k = 0
count = 0
Flag_1 = False
Flag_2 = False
hakken_Flag = False
for a in range(10):
    for b in range(10):
        for c in range(10):
            for i in range(len(S)-2):
                if str(a) == S[i]:
                    Flag_1 = True
                    break

            if Flag_1 == True:
                for j in range(i+1, len(S)-1):
                    if str(b) == S[j]:
                        Flag_2 = True
                        Flag_1 = False
                        break

            if Flag_2 == True:
                for k in range(j+1,len(S)):
                    if str(c) == S[k]:
                        count += 1
                        hakken_Flag = True
                        Flag_2 = False
                        break
                Flag_2 = False

print(count)
                

N = int(input())
S = input()
S = list(S)
i = 0
j = 0
k = 0
count = 0
Flag_1 = False
Flag_2 = False
hakken_Flag = False
for a in range(10):
    for b in range(10):
        for c in range(10):
            for i in range(len(S)-2):
                if str(a) == S[i]:
                    Flag_1 = True
                    break

            if Flag_1 == True:
                for j in range(i+1, len(S)-1):
                    if str(b) == S[j]:
                        Flag_2 = True
                        Flag_1 = False
                        break

            if Flag_2 == True:
                for k in range(j+1,len(S)):
                    if str(c) == S[k]:
                        count += 1
                        hakken_Flag = True
                        Flag_2 = False
                        break
                Flag_2 = False

print(count)

Submission status: Runtime Error

Solution code:
a = "4"
print "3"

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
# N桁のSからN-3桁の数字を削除して(N<30000)３桁の数字を残す．残った数字の組み合わせて押してありえるのは何通りか？
# 実際に10^4通りから３通り選ぶのは 10^4C3通りくらい計算量的には計算できる?
# 更にあり得る組み合わせの上限==1000通りを終えた時点で終了すれば更に早い？
# 右の数字から数えていって1を取れるかみたいにしていけば最大１０００のループで終わる？
# 0001がNの中から取れるかの判定まず最初の0について左側からとっていって，0があれば存在すればとり，そこのindexを記録，．次に1として次のindexから検索していく

#for n in N_str:
#なぜ224とかの時に上手く行かないのだ?
#0224
count=0
for i in range(1000):
    i_3d = f'{i:0>3}'
    index_num = 0
    for j,i_s in enumerate(i_3d): # 1,2
        for s_s in S[index_num:]: # 2
            index_num+= 1 #3
            if s_s == i_s: #2 == 2
                if j == len(i_3d)-1:  # 最後の文字がマッチングした
                    count+=1
                break
        # i_sについて探索しても何も見つからなかった場合,最後まで探索したとき，次のindexがあふれる時には停止する
        if index_num == len(S): # 3==4:False
            break
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
lst = []
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if S[i]+S[j]+S[k] in lst:
                continue
            else:
                lst.append(S[i]+S[j]+S[k])
            if len(lst) = 999:
                print(len(lst))
                quit()
print(len(lst))

Submission status: Runtime Error

Solution code:
n = inp()
s = input()
res = 0
a = [str(i) for i in range(10)]
for num in itertools.product(a, repeat=3):
    p = 0
    for i,j in enumerate(s):
        if j == num[p]:
            p += 1
            if p == 3:
                break
    if p == 3:
        res += 1
print(res)

Submission status: Runtime Error

Solution code:
N = int(input())
X = input()
M = {X[0:3]:1}
result = {}

for i in range(3,N):
    i = X[i]
    keys = M.keys()
    for j in tuple(keys):
        if (j, i) in result:
            continue
        M[j[0]+j[1]+i] = 1
        M[j[0]+j[2]+i] = 1
        M[j[1]+j[2]+i] = 1
        result[(j,i)] = True
	if len(M) == 729:
      break
print (len(M))

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(str(input()))
x = []
cnt = 0

for i in range(1000):
    x.append(list(str(i).zfill(3)+'x')
    k = 0
    for j in range(n):
        if x[i][k] == s[j]:
            k += 1
    if k == 3:
            cnt += 1
 
print(cnt)

Submission status: Runtime Error

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
      for i in range(n-2):
        if str(a) == s[i]:
          tmp_i = i + 1
          for j in range(tmp_i,n-1):
            if str(b) == s[j]:
              tmp_i = j + 1
              for k in range(tmp_i,n):
                if str(c) == s[k]:
                  cnt = cnt + 1
                  flg = True
                  break
              else:
                flg = True
            if flg:
              break
          else:
            flg = True
      	if flg:
          break
print(cnt)

Submission status: Runtime Error

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
        for i in range(n-2):
            if str(a) == s[i]:
                tmp_i = i + 1
                for j in range(tmp_i,n-1):
                    if str(b) == s[j]:
                        tmp_i = j + 1
                        for k in range(tmp_i,n):
                            if str(c) == s[k]:
                                cnt = cnt + 1
                                flg = True
                                break                                
       					else:
                          break
                        if flg:
                            break
                else:
                  break
                if flg:
                    break
            
print(cnt)

Submission status: Runtime Error

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
        for i in range(n-2):
            if str(a) == s[i]:
                tmp_i = i + 1
                for j in range(tmp_i,n-1):
                    if str(b) == s[j]:
                        tmp_i = j + 1
                        for k in range(tmp_i,n):
                            if str(c) == s[k]:
                                cnt = cnt + 1
                                flg = True
                                break                                
       					else:
                        	break
                        if flg:
                            break
                if flg:
                    break
            
print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
L=int(input())
N=input()
n = list(itertools.combinations(N, 3))
a=[]
for i in range(len(n)):
        a.append(int(n[i][0])*100 + int(n[i][1])*10+int(n[i][2]))
print(len(set(a)))

Submission status: Runtime Error

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

for a in range(9): #1文字目
  for b in range(9): #2文字目
    for c in range(9): #3文字目
      for i in range(n-3):
        if str(a) = s[i]:
          tmp_i = i + 1
          for j in range(tmp_i,n-2):
            if str(b) = s[j]:
              tmp_i = j + 1
              for k in range(tmp_i,n-1):
                if str(c) = s[k]:
                  cnt = cnt + 1
print(cnt)

Submission status: Runtime Error

Solution code:
n = str(input())

s = input()

ans = 0

for i in range(1000):
  si = str(i)
  if i < 10:
    si = '00' + si
  elif i < 100:
    si = '0' + si
  match = 0
  for j in range(n):
    if si[match] == s[j]:
      match += 1
      if match == 3:
        ans += 1
        break
print(ans)

Submission status: Runtime Error

Solution code:
n = str(input())

s = input()

ans = 0

for i in range(1000):
  si = str(i)
  match = 0
  for j in range(n):
    if si[match] == s[j]:
      match += 1
      if match == 3:
        ans += 1
        break
print(ans)

Submission status: Runtime Error

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

l = [str(i).zfill(3) for i in range(0,1000)]

ct = 0
for i in l:
  n0 = s.find(a[0])
  if n0==-1:
    continue
  n1 = s.find(a[1], n0+1)
  if n1==-1:
    continue
  n2 = s.find(a[2], n1+1)
  if n2!=-1:
    c += 1
   
print(ct)

Submission status: Runtime Error

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

ans = 0
for i in range(1000):
    n = f"{i:03}"
    index = 0
    c = 0
    for k in n:
        for j in range(index, len(S)):
            if S[j] == k:
                index = j+1
                c+=1
                break
    if c == 3:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:

input1 = int(input())
input2 = input()

kesu = input1 - 1
inputbox = list(input2)
li=[0 for _ in range(1000)]
kazu :str =""
number = []
number1 = []
number2 = []
i=0


while i < input1-2:
    number.clear()
    number.append(inputbox[i])
    j=0
    while j < input1 - 2 - i:
        number1 = number
        number1.append(inputbox[j+i+1])
        k=0
        while k < input1 - 2 - i - j:
            number2 =number1
            number2.append(inputbox[k+j+i+2])
            kazu=""
            for n in range(3):
                kazu = kazu+str(number[n])
            kazu1 = int(kazu)
            li[kazu1]=1
            number2.pop()
            k=k+1
        j=j+1
        number1.pop()
    i=i+1

count = 0
for i in range (1000):
    if li[i] == 1:
        count =count+1

print(count)

Submission status: Runtime Error

Solution code:
import itertools
from bisect import bisect_left

def index(a, x):
    'Find leftmost index of item greater than or equal to x'
    i = bisect_left(a, x)
    if i != len(a):
        return i
    return False

def main():
    N = int(input())
    S = input()
    lst = list(S)

    a = []
    for i,j,k in itertools.combinations(range(N), 3):
        if i < j < k:
            s = int(str(lst[i])+str(lst[j])+str(lst[k]))

            idx = bisect_left(a, s)

            if idx == len(a):
                a.append(s)
            
            elif a[idx] != s:
                a.insert(idx, s)
            
            if len(a) == 1000:
                break
    print(len(a))

if __name__ == "__main__":
    main()
import itertools
from bisect import bisect_left

def index(a, x):
    'Find leftmost index of item greater than or equal to x'
    i = bisect_left(a, x)
    if i != len(a):
        return i
    return False

def main():
    N = int(input())
    S = input()
    lst = list(S)

    a = []
    for i,j,k in itertools.combinations(range(N), 3):
        if i < j < k:
            s = int(str(lst[i])+str(lst[j])+str(lst[k]))

            idx = bisect_left(a, s)

            if idx == len(a):
                a.append(s)
            
            elif a[idx] != s:
                a.insert(idx, s)
            
            if len(a) == 1000:
                break
    print(len(a))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import itertools

def index(a, x):
    'Find leftmost index of item greater than or equal to x'
    i = bisect_left(a, x)
    if i != len(a):
        return i
    return False

def main():
    N = int(input())
    S = input()
    lst = list(S)

    a = []
    for i,j,k in itertools.combinations(range(N), 3):
        if i < j < k:
            s = int(str(lst[i])+str(lst[j])+str(lst[k]))

            idx = bisect_left(a, s)

            if idx == len(a):
                a.append(s)
            
            elif a[idx] != s:
                a.insert(idx, s)

    print(len(a))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def index(a, x):
    'Find leftmost index of item greater than or equal to x'
    i = bisect_left(a, x)
    if i != len(a):
        return i
    return False

def main():
    N = int(input())
    S = input()
    lst = list(S)

    a = []
    for i,j,k in itertools.combinations(range(N), 3):
        if i < j < k:
            s = int(str(lst[i])+str(lst[j])+str(lst[k]))

            idx = bisect_left(a, s)

            if idx == len(a):
                a.append(s)
            
            elif a[idx] != s:
                a.insert(idx, s)

    print(len(a))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

nsl=['{:03}'.format() for i in range(1000)]

res=0
for ns in nsl:
  idx=0
  for char in s:
    if char == ns[idx]:
      idx+=1
      if idx == 3:
        res+=1
        break
print(res)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  string S;
  cin >> N >> S;
  vector<int> left(10, 0), right(10, 0);
  left[S[0] - '0']++;
  for (int i = 2; i < N; i++) {
    right[S[i] - '0']++;
  }
  vector<int> cnts(1000, 0);
  for (int i = 1; i < N - 1; i++) {
    int b = S[i] - '0';
    for (int a = 0; a < 10; a++) {
      for (int c = 0; c < 10; c++) {
        if (left[a] == 0 || right[c] == 0) continue;
        cnts[100 * a + 10 * b + c]++;
      }
    }
    left[S[i] - '0']++;
    right[S[i + 1] - '0']--;
  }
  int res = 0;
  for (int i = 0; i < 1000; i++) {
    if (cnts[i] != 0) res++;
  }
  cout << res << '\n';
  return 0;
}

Submission status: Runtime Error

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

cnt = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            pin = [i, j, k]
            x = 0

            for a in S:
                if a == pin[x]:
                    x += 1
                    if x = 3:
                        cnt += 1
                        break

print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
S = input()
L = [str(i).zfill(3) for i in range(1000)]


def contain(l):
    phase = 0
    for c in S:
        if phase == 0 and c == l[0]:
            phase = 1
            continue
        if phase == 1 and c == l[1]:
            phase = 2
            continue
        if phase == 2 and c == l[2]:
            return 1
    return 0


f = np.frompyfunc(contain, 1, 1)
print(sum(f(L)))

Submission status: Runtime Error

Solution code:
N = int(input())
s = input()
ans = 0
for i in range(1000):
  num = str(i).zfill(3)
  flag1 = True
  flag2 = True
  flag3 = True
  first = -1
  second = -1
  third = -1
  for j in range(s):
    if (s[j] == num[0] and flag1):
      first = j
      flsg1 = False
    if (s[j] == num[1] and j > first and flag2):
      second = j
      flsg2 = False
    if (s[j] == num[2] and j > second and flag3):
      second = j
      flsg3 = False
  if (first != -1 and second != -1 and third != -1):
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict
from itertools import combinations

def n_cmb(n, r):
    from math import factorial
    return factorial(n) / factorial(r) / factorial(n - r)

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

duplicates = defaultdict(list)
for idx, v in enumerate(s):
    duplicates[v].append(idx)
print(duplicates)
n_duplicates = 0
for key in duplicates:
    # import pdb
    # pdb.set_trace()
    idxs = duplicates[key]
    n_idxs = len(idxs)
    if n_idxs > 3:
        n_duplicates += n_cmb(n_idxs - 3, 1)
    if n_idxs == 1:
        continue
    for i in range(n_idxs-1):
        for j in range(i+1, n_idxs):
            m = idxs[i] + n - idxs[j] - 1
            if m < 2:
                continue
            n_duplicates += n_cmb(m, 2)
print(n_cmb(n, 3))
print(n_duplicates)
result = n_cmb(n, 3) - n_duplicates

print(result)

Submission status: Runtime Error

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

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

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

print(ans)

Submission status: Runtime Error

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

cnt = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = True
            flag2 = True

            for a in S:
                if flag1:
                    if a == i:
                        flag1 = False
                elif flag2:
                    if a == j:
                        flag2 = False
                elif a == k:
                    cnt += 1
                    break

print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
seq = list(set(list(s)))
genkai_list = []
for i in range(0,1000):
    if 0 <= i <= 9:
        ap = "00" + str(i)
        genkai_list.append(ap)
    elif 10 <= i <= 99:
        ap = "0" + str(i)
        genkai_list.append(ap)
    else:
        genkai_list.append(str(i))
ans = []
for a in range(len(genkai_list)):
    for i in range(len(s)):
        if s[i] == avcodelist[a][0]:
            for j in range(i + 1, len(s)):
                if s[j] == avcodelist[a][1]:
                    for k in range(j + 1, len(s)):
                        if s[k] == avcodelist[a][2]:
                            ans.append(a)
print(len(set(ans)))

Submission status: Runtime Error

Solution code:
def solve(s1, s2, s3, S, N):
	for i in range(N):
		if S[i] == s1:
			left = i
			break
	for i in range(left + 1, N):
		if S[i] == s2:
			mid = i
			break
	for i in range(mid + 1, N):
		if S[i] == s3:
			right = i
			break
	if right < N:
		return True
	else:
		return False

if __name__ == "__main__":
	N = int(input())
	S = input()
	ans = 0
	for s1 in range(0, 10):
		for s2 in range(0, 10):
			for s3 in range(0, 10):
				if solve(str(s1), str(s2), str(s3), S, N):
					ans += 1
	print(ans)

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

Solution code:
a=int(input())
b=input()
count=0
for i in range(1000):
    flag=False
    for j in range(a):
        if b[j]=='{0:03d}'.format(str(i))[0]:
            x=j
            flag=True
            break
    if flag:
        flag=False
    else:
        continue
    for k in range(x+1,a):
        if b[k]=='{0:03d}'.format(str(i))[1]:
            y=k
            flag=True
            break
    if flag:
        flag=False
    else:
        continue
    for l in range(y+1,a):
        if b[l]=='{0:03d}'.format(str(i))[1]:
            count+=1
            break
print(count)

Submission status: Runtime Error

Solution code:
from itertools import permutations, compress

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

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

Submission status: Runtime Error

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):
        for k in range(10):
            for t in range(n):
                if i == int(s[t]):
                    break
            for u in range(t+1,n):
                if j == int(s[u]):
                    break
            for v in range(u+1,n):
                if k == int(s[v]):
                    break
            if int(s[t]) == i and int(s[u]) == j and int(s[v]) == k:
                ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
from typing import List


def solve(digits: List[int]) -> int:
    n = len(digits)

    dp1 = [0] * n
    dp2 = [0] * n
    dp3 = [0] * n
    dp1[0] = 1

    seen_digits1 = []
    seen_digits2 = []
    seen_digits3 = []

    for _ in range(n):
        seen_digits1.append(set([]))
        seen_digits2.append(set([]))
        seen_digits3.append(set([]))

    seen_digits1[0] = {digits[0]}

    for i in range(1, len(digits)):
        d = digits[i]

        # dp1
        seen = d in seen_digits1[i - 1]
        seen_digits1[i] |= (seen_digits1[i -1] | {d})
        if seen:
            dp1[i] = dp1[i - 1]
        else:
            dp1[i] = dp1[i - 1] + 1

        # dp2
        dp2[i] = dp2[i - 1] + dp1[i - 1]
        for seen_digit1 in seen_digits1[i - 1]:
            cur_digits = 10 * seen_digit1 + d
            seen = cur_digits in seen_digits2[i - 1]
            seen_digits2[i] |= (seen_digits2[i - 1] | {cur_digits})
            if seen:
                dp2[i] -= 1

        # dp3
        dp3[i] = dp3[i - 1] + dp2[i - 1]
        for seen_digit2 in seen_digits2[i - 1]:
            cur_digits = 10 * seen_digit2 + d
            seen = cur_digits in seen_digits3[i - 1]
            seen_digits3[i] |= (seen_digits3[i - 1] | {cur_digits})
            if seen:
                dp3[i] -= 1

    return dp3[n - 1]


n = int(input().strip())
digits = [int(c) for c in input().strip()]
print(solve(digits))

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

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

ans = 0

for v1 in range(10):
    for v2 in range(10):
        for v3 in range(10):
            current = 0
            for (i, e) in sarr:
                if e == v1:
                    current = i + 1
                    break
            else:
                continue

            for (i, e) in sarr[current:]:
                if e == v2:
                    current = i + 2
                    break
            else:
                continue

            for (i, e) in sarr[current:]:
                if e == v3:
                    ans += 1
                    break

print(ans)

Submission status: Runtime Error

Solution code:
import sys

#+++++
		
def main():
	n = int(input())
	s = input()
	count=0
	for i in range(1000):
		ss=str(i)
		if i < 10:
			ss = '00'+ss
		elif i < 100:
			ss='0'+ss
			
		if ss[0] in s:
			iia = s.index(ss[0])
		else:
			continue
		#pa(ii)
		if ss [1] in s[iia+1:]:
			iib = s[iia+1:].index(ss[1])+iia+1
		else:
			continue
		#pa(ii)
		if ss[2] in s[iib + 1:]:
			iic = s[iib+1:].index(ss[2])+iia+iib
		else:
			continue
			
		pa((ss,i))
		pa((iia,iib,iic,s[iia],s[iib],s[iic]))
		count+=1
			
	print(count)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Runtime Error

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

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            fi = S.find(S[i])
            fj = S.find(S[j])
            fk = S.find(S[k])
            if fi >= 0 and fj >= 0 and fk >= 0 and fi < fj and fj < fk:
                ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
l=[]
for i in range(n):
    for j in range(i+1,n):
      #if i==j:continue
      for k in range(j+1:n):
        #if i==k or j==k:continue
        a=s[i]+s[j]+s[k]
        if a in l:continue
        l.append(a)

print(len(l))

Submission status: Runtime Error

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

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            fi = S.find(S[i])
            fj = S.find(S[j])
            fk = S.find(S[k])
            if fi >= 0 and fj >= 0 and fk >= 0 and fi <= fj and fj <= fk:
                ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import itertools

#入力
N=int(input())
A = [int(x) for x in list(input())]
ans = 0
num=[[0]*10 for _ range(10)]

for i,j,k in itertools.combinations(A, 3):
    if(num[i][j][k] == 0):
        num[i][j][k] =1
        ans += 1
        
print(ans)

Submission status: Runtime Error

Solution code:
def pin(n, s):
  from collections import defaultdict as DD
  ans = 0
  seen = DD(bool)
  def helper(pos, acc, l):
      if len(acc) < 3:
        if pos < l:
          c = s[pos]
          helper(pos + 1, acc, l)
          helper(pos + 1, acc + c, l)
      elif len(acc) == 3:
        seen[int(acc)] = True

  helper(0, '', len(s))
  for k in seen.keys():
    if seen[k]:
      ans += 1
  
  return ans
    
 
if __name__ == "__main__":
  import sys
  in_str = ''
  for line in sys.stdin:
    in_str += line
  n, s = in_str.split()
  print(pin(n, s))

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
for i in range(n):
    for j in range(n):
      if i==j:continue
      for k in range(n):
        if i==k or j==k:continue
        a=s[i]+s[j]+s[k]
        if a in l:continue
        l.append(a)

print(len(l))

Submission status: Runtime Error

Solution code:

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

N = int(input())
S = list(input())
dp = {}
st = [None]*9
ok = []
l = [None]*N
las = 0
for i in range(N-1,-1,-1):
    s = S[i]
    st[int(s)] = i
    l[i] = las
    if s in dp:
        dp[s].append(i)
    else:
        dp[s] = [i]
        las += 1

ans = 1
for i in range(0,9):
    if st[i]==None:
        continue
    start = st[i] #iが初めて出てくる位置
    for j in range(1,10):
        k = str(j)
        if not k in dp:
            continue
        middle = dp[k]
        ok = len(dp)-1
        ng = 0
        while ok-ng>1:
            m = (ok+ng)//2
            if middle[m]>start:
                ng = m
            else:
                ok = m
        ans *= l[ok]
print(ans)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
S = input()
a = []
B = list(map(int, list(S)))
for i in range(N):
  for j in range(i+1, N):
    for k in range(0, 9):
      if k in set(B[j+1:]):
        a.append(S[i] + S[j] + S[k])
print(len(set(a)))

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
count=0
count2=0
d=[]
hk3=0
hk2=0
hk1=0
for j in range(100,1000):
  k3=j//100
  k2=(j-k3*100)//10
  k1=j-k3*100-k2*10
  for i in range(n):
    if str(k3)==s[i]:
      hk3=1
    if str(k2)==s[i] and hk3==1:
      hk2=1
    if str(k1)==s[i] and hk2==1:
      hk1=1
    if hk1==1 and hk2==1 and hk3==1:
      d.append(j)
  hk1=0
  hk2=0
  hk3=0
for j in range(1,10):
  for i in range(n):
    if s[i]=="0":
      count=1
    if count==1 and s[i]=="0":
      count2=1
    if count2=0 and s[i]==str(j):
      d.append(j)
  count=0
  count2=0
for j in range(10,100):
  k2=j//10
  k1=j-k2*10
  for i in range(n):
    if s[i]=="0":
      count=1
    if str(k2)==s[i] and count=1:
      hk2=1
    if str(k1)==s[i] and hk2==1 and count=1:
      hk1=1
    if hk1==1 and hk2==1:
      d.append(j)
  count=0
  hk1=0
  hk2=0
print(len(set(d)))

Submission status: Runtime Error

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

import numpy as np
B=np.array(range(0, 999, 1))
for i in range(0, (len(A)-2)):
	for j in range((i+1),(len(A)-1)):
		for k in range((i+2),len(A)):
			B.pop(B.index(int(A[i])*100+int(A[j])*10+int(A[k])))
print(1000-len(B))

Submission status: Runtime Error

Solution code:
import math
import numpy as np

def count(num):
    string = str(num)
    dic = {}
    for num in string:
        if num not in dic.keys():
            dic[num] = 1
        else:
            dic[num] = dic[num] + 1
    return dic

def calc_paterns(num, n):
    count_list = count(num).values()
    all_count = math.factorial(n)
    for c in count_list:
        all_count = all_count / c
    return all_count
        
def choose(num):
    a = []
    for i in num:
        a.append(i)
    a = np.unique(a)
    lis = list(itertools.combinations(a,3))
    str_lists = []
    for li in lis:
        a = ''
        for s in li:
            a = a+s
        str_lists.append(a)
    return str_lists

N = int(input())
S = input()
pats = choose(S)
all = 0
for pat in pats:
    all += calc_paterns(pat, 3)
print(int(all))

Submission status: Runtime Error

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

ans_list = {}


for i in range(N):
    if i in i_set:
        continue
    i_set.append(i)
    for j in range(i+1, N):
        if not S[j + 1:N] or S[i] + S[j] in S_set:
            continue
        ans_list[S[i] + S[j]] = S[j + 1:N]
        S_set.add(S[i] + S[j])
count = 0
# print(ans_list)
ans_len_list = [len(set(value)) for value in ans_list.values()]
print(sum(ans_len_list))

Submission status: Runtime Error

Solution code:
import itertools
import copy
N = int(input())
S = list(input())
result=[]
for c in itertools.combinations(S, N - 3):
    s=copy.deepcopy(S)
    for i in range(N-3):
        s.remove(c[i])
        if s not in result:
            result.append(s)

print(sum(result))

Submission status: Runtime Error

Solution code:
input1 = int(input())
input2 = input()

kesu = input1 - 1
inputbox = list(input2)
li=[0 for _ in range(1000)]
number = []
for i in range (kesu):
    number.append(inputbox[i])
    for j in range (kesu-1):
        number.append(inputbox[j+i+1])
        for k in range (kesu-2):
            number.append(inputbox[k+j+i+2])
            number = int(map(str, number))
            li[number]=1


count = 0
for i in range (1000):
    if li[i] == 1:
        count =count+1

print(count)

Submission status: Runtime Error

Solution code:
#!python3.4.3
from scipy.special import comb
import collections

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

c = collections.Counter(s)
count = 0
for i in range(0, 10):
    col = c[str(i)] - 1
    if col > 0:
        count += col
    
a = comb(n, 3, exact=True) - count

print(a)