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 = str(input())

import re

s = re.sub('[0]{4,}','000',s)
s = re.sub('[1]{4,}','111',s)
s = re.sub('[2]{4,}','222',s)
s = re.sub('[3]{4,}','333',s)
s = re.sub('[4]{4,}','444',s)
s = re.sub('[5]{4,}','555',s)
s = re.sub('[6]{4,}','666',s)
s = re.sub('[7]{4,}','777',s)
s = re.sub('[8]{4,}','888',s)
s = re.sub('[9]{4,}','999',s)

ans = 0
target = [0] * 10
for i in s:
  target[int(i)] = 1



for xxx in range(1000):
  x = str(xxx).zfill(3)
  if(not (target[int(x[0])] and target[int(x[1])] and target[int(x[2])])):
    continue

  ck1,ck2,ck3 = 0,0,0
  start = 0
  for i in range(start,n):
    if(s[i] == x[0]):
      ck1 = 1
      start = i+1
      break
  if(ck1):
    for i in range(start,n):
     if(s[i] == x[1]):
       ck2 = 1
       start = i+1
       break
  if(ck1 and ck2):
    for i in range(start,n):
     if(s[i] == x[2]):
       ans += 1
       break

print(ans)

Submission status: Runtime Error

Solution code:
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN
N = int(input())
S = str(input())

ans = 0
for i in range(10):
    code1 = S.find(str(i))
    if code1 == -1:
        continue
    for j in range(10):
        code2 = S.find(str(j), code1 + 1)
        if code2 == -1:
            continue
        for k in range(10):
            code3 = S.find(str(k), code2 + 1)
            if code3 != -1:
                ans += 1

print(ans)
b v

Submission status: Runtime Error

Solution code:
import itertools

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

count = 0
res = []
for i in itertools.combinations(S, 3):
    if i in res:
        continue
    else:
        count += 1
        res.append()
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
s=[int(c) for c in input()]
count=0
for p in range(10):
    for q in range(10):
        for r in range(10):
            flag=False
                if p in s[:n-2]:
                    inp=s.index(p)
                    if q in s[inp+1:n-1]:
                        inq=s[inp+1:n-1].index(q)
                        if r in s[inq+1:n]:
                            count+=1
                            flag=True
                            break
                        if flag: break
                if flag: break
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def test(original: list, array: list, index: int,
         remain_count: int, results: set):
    # 3桁抽出したら終了
    if len(array) == 3:
        # print("".join(array))
        results.add("".join(array))
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    # この桁を抽出対象とするパターン
    test(original, array[:], index + 1, remain_count - 1, results)

    # この桁を抽出対象としないパターン
    new_array = array[:]
    new_array.append(
        original[index])
    test(
        original,
        new_array,
        index + 1,
        remain_count,
        results)


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

results = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, [], 0, N - 3, results)

print(len(results))

Submission status: Runtime Error

Solution code:
def test(original: list, array: list, index: int,
         remain_count: int, results: set):
    if index == len(original):
        if remain_count == 0:
            # print("".join(array))
            results.add("".join(array))
        return
    if remain_count > 0:
        test(original, array[:], index + 1, remain_count - 1, results)
    new_array = array[:]
    new_array.append(
        original[index])
    test(
        original,
        new_array,
        index + 1,
        remain_count,
        results)


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

results = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, [], 0, N - 3, results)

print(len(results))

Submission status: Runtime Error

Solution code:
N = input()
S = input()
a = 0
for i in range(999):
  b = i // 100
  c = (i % 100) // 10
  d = i % 10
  x = 998
  z = 1
  for j in range(997):
    if S[j] == b:
      x = j
      break
  for j in range(2, 999):
    if S[j] == d:
      z = j
      break
  if x+1 < z:
    for j in range(x+1, z):
      if S[j] == c:
        a += 1
print(int(a))

Submission status: Runtime Error

Solution code:
N = input()
S = input()
X = int(N/2)
S1 = S[:X]
S2 = S[X:]
set = {1000}
for i in range(X-2):
    for j in range(i+1, X-1):
        for k in range(j+1, X):
            sign = S[i]+S[j]+S[k]
            set.add(sign)
for i in range(X,int(N)-2):
    for j in range(i+1, int(N)-1):
        for k in range(j+1, int(N)):
            sign = S[i]+S[j]+S[k]
            set.add(sign)  
for i in range(X): 
  for j in range(X, int(N)-1):
        for k in range(j+1, int(N)):
            sign = S[i]+S[j]+S[k]
            set.add(sign)  
for i in range(X-1):
    for j in range(i+1, X):
      for k in range(X, int(N)):
            sign = S[i]+S[j]+S[k]
            set.add(sign)  
print(len(set)-1)

Submission status: Runtime Error

Solution code:
N = input()
S = input()
S1 = S[:N/2]
S2 = S[N/2:]
set = {1000}
for i in range(int(N/2)-2):
    for j in range(i+1, int(N/2)-1):
        for k in range(j+1, int(N/2)):
            sign = S[i]+S[j]+S[k]
            set.add(sign)
for i in range(int(N/2),int(N)-2):
    for j in range(i+1, int(N)-1):
        for k in range(j+1, int(N)):
            sign = S[i]+S[j]+S[k]
            set.add(sign)  
for i in range(int(N/2)): 
  for j in range(int(N/2), int(N)-1):
        for k in range(j+1, int(N)):
            sign = S[i]+S[j]+S[k]
            set.add(sign)  
for i in range(int(N/2)-1):
    for j in range(i+1, int(N/2)):
      for k in range(int(N/2), int(N)):
            sign = S[i]+S[j]+S[k]
            set.add(sign)  
print(len(set)-1)

Submission status: Runtime Error

Solution code:
N = map(int, input())
S = input()
set = {}
for i in range(N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      sign = S[i]+S[j]+S[k]
      set.add(sign)
print(len(set))

Submission status: Runtime Error

Solution code:
S=input()
#初めて出てきたときのインデックスをめも
memo=[[-1]*10 for _ in range(10)]
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        si=int(S[i])
        sj=int(S[j])
        if memo[si][sj]==-1:
            memo[si][sj]=0
            ans+=len(set(S[j+1:]))
print(ans)

Submission status: Runtime Error

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

def solve():
    N = int(input())
    S: string = input()

    """
    3桁の数字がijkだとして、それを作れるかを全探索で数えていく
    平均計算量は、(3750*10)*(7500*10)*(15000*10) = O(10**4 * 10**4 * 10**5) = O(10**13)
    """

    ans = 0
    for i in range(0, 10):
        idx = S.find(str(i))  # 平均計算量15000
        if idx == -1:
            continue
        for j in range(0, 10):
            jdx = S[idx+1:].find(str(j))  # 平均計算量7500
            if jdx == -1:
                continue
            for k in range(0, 10):
                if str(k) in S[idx+1+jdx+1:]:  # 平均計算量3750
                    ans += 1

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
S = input()
baai=0
rireki=[]
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] not in rireki:
                baai = baai +1
                rireki.append(S[i]+S[j]+S[k])

print(baai)

Submission status: Runtime Error

Solution code:
S = input()

baai=0
rireki=[]
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] not in rireki:
                baai = baai +1
                rireki.append(S[i]+S[j]+S[k])

print(baai)

Submission status: Runtime Error

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

import itertools

d = list()
for d1, d2, d3 in itertools.product(range(10), range(10), range(10)):
    d.append(f'{d1}{d2}{d3}')

ret = 0
for di in d:
    ls = list(s)
    try:
        idx1 = ls.index(di[0])
        idx2 = ls[idx1+1:].index(di[1])
        idx3 = ls[idx1+1:][idx2+1:].index(di[2])
        ret += 1
    except:
        continue

print(ret)

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
t=[]
for i in range(n):
  t.append(s[i])
p=0
for i in range(10):
  pi=t.find(str(i))
  if pi==-1:
    continue
  for j in range(10):
    pj=t.find(str(j),pi)
    if pj==-1:
      continue
    for k in range(10):
      pk=t.find(str(k),pj)
      if pk==-1:
        continue
      p=p+1
print(p)

Submission status: Runtime Error

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


ans = []
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] not in ans:
      ans.append(s[i] + s[j] + s[k])
      
print(len(ans))

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):
            for f in range(n):
                if p == 0 and s[f] == str(i):
                    p = 1
                elif p == 1 and s[f] == str(j):
                    p = 2
                elif p == 2 and s[f] == str(k):
                    ans += 1
                    break
print(ans)

Submission status: Runtime Error

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

before = [[-1] * 10]

for i in range(n):
  c = s[i]
  num = int(c)
  hoge = before[-1][::]
  hoge[num] = i
  before.append(hoge)

for i in range(10):
  now = before[-1][i]
  if now == -1:
    continue
  for j in range(10):
    now2 = before[now][j]
    if now2 == -1:
      continue
    for k in range(10):
      now3 = before[now2][k]
      if now3 == -1:
        continue
      ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = int(input())
count = 0
for i in range(0,1000):
    num = [i//100, (i//10)%10, i%10]
    digit = 0
    for j in range(N):
        if S[j] == num[digit]:
            digit += 1
        if digit == 3:
            break
    else:
        continue
    count += 1

print(count)

Submission status: Runtime Error

Solution code:
from collections import Counter as cnt
n = int(input())
s = list(input())

count = cnt(s)
num_rest = []
for i in range(n):
  count[s[i]] -= 1
  rest = 0
  for value in count.values():
    if value != 0:
      rest += 1
  num_rest.append(rest)
#print(num_rest)

checked = {}
total = 0
for i in range(n-2):
  if s[i] not in checked:
    checked(s[i]) = {}
  elif len(checked[s[i]].keys()) == 10:
    continue
  else:
    for j in range(i+1, n-1):
      if s[j] not in checked[s[i]]:
        checked[s[i]][s[j]] == True
        total += num_rest[j]
print(total)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <numeric>
#include<queue>
using namespace std;
typedef long long ll;
typedef vector<int>VI;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define fi first
#define se second
#define MAX 100100//5
#define MAX_N 200100
#define MAX_B 1001001//6
#define MAX_S 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1 << 29
#define INFTY 1000000000000000000LL

int main(){
  int n;
  string s;
  cin>>n>>s;
  ll count=0;
bool table[110];
  vector<set<char>>v(n);
  rep(i,n){
      for(int j=i+1;j<n;j++){
      v[i].insert(s[j]);
      }
  }

    memset(table,0,sizeof(table));
  rep(i,n){
      int y=s[i]-'0';
    for(int j=i+1;j<n;j++){
        int x=s[j]-'0';
    if(!table[y*10+x]){
      count+=v[j].size();
      table[y*10+x]=1;
      }
  }
  }
  
  cout<<count<<endl;
}

Submission status: Runtime Error

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


ans =0

for i in range(10):
    if str(i) in s:
        t = s[s.index(str(i))+1:]
        for j in range(10):
            if str(j) in s:
                u = t[t.index(str(j))+1:]
                for k in range(10):
                    if str(k) in u:
                        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(10):
    if str(i) in s:
        t = s[s.index(str(i))+1:]
    for j in range(10):
        if str(j) in t:
            u = t[t.index(str(j))+1:]
        for k in range(10):
            if str(k) in u:
                ans +=1
print(ans)

Submission status: Runtime Error

Solution code:
def f(s,l=3):
  if l==1:
    return len(set(s))
  a=0
  for i in set(s):
    a+=f(s[s.index(i)+1:],l-1)
  return a

n=int(input())
s=input()
print(f(s)i)

Submission status: Runtime Error

Solution code:
int(input())
n=input()
answer=0
for i in range(10):
    if str(i) in n:
        T=n[n.index(str(i))+1:]
        for j in range(10):
            if str(j) in T:
                U=T[T.index(str(j))+1:]
                for k in range(10):
                    if str(k) in U:
                        ans+=1
print(answer)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
s = input()
ans = set()
for i in range(len(s)-2):
  for j in range(i+1,len(s)-1):
    for l in range(j+1,len(s)):
      ans.add(int(s[i])*100+int(s[j])*10+int(s[l]))
print(len(ans))

Submission status: Runtime Error

Solution code:
def main():  
  import sys
  input = sys.stdin.readline
  n = int(input())
  s = input()
  ans = set()
  for i in range(len(s)-2):
    for j in range(i+1,len(s)-1):
      for l in range(j+1,len(s)):
        ans.add(int(s[i])*100+int(s[j])*10+int(s[l]))
  print(len(ans))
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
S = [s for s in input()]
lis = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
ans = 0
from collections import defaultdict
d = defaultdict(list)
for i,s in enumerate(S):
    d[s].append(i)

for s in lis:
    if d[s[0]]:
        i = min(d[s][0])
        if d[s[1]]:
            for j in d[s[1]]:
                if j > i:
                    if d[s[2]]:
                        if max(d[s[2]]) > j:
                            ans += 1
                            break
                    break
        else:continue
    else:continue
                            
print(ans)

Submission status: Runtime Error

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

cnt = 0
for i in range(1000):
    
    t = str(i)
    u = '0'*(3-len(t))+t
    
    j = 0
    p = u[0]
    for x in s:
        if x == p:
            j += 1
            if j == 3:
                cnt += 1
                break
            p = u[j]
            
print(ans)

Submission status: Runtime Error

Solution code:
n, s = input().split()
n = int(n)
l=[]
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            l.append(s[i]+s[j]+s[k])

l=list(set(l))
print(len(l))

Submission status: Runtime Error

Solution code:
n,s=map(str, input().split())
n=int(n)
l=[]
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            l.append(s[i]+s[j]+s[k])

l=list(set(l))
print(len(l))

Submission status: Runtime Error

Solution code:
Not found

Submission status: Runtime Error

Solution code:
#!/usr/bin/env/ python3
N = int(input())
S = input()
#A, B, C = input().split()
#A, B, C, X, Y = map(int, input().split())

#N = int(input())
#H, W = map(int, input().split())
#S = [input() for _ in range(H)]
#print(A[0][0])

ans = 0
for tmp_num in range(1000):
    tmp = str(tmp_num).zfill(3)
    digit = 0
    for i in range(N):
        if S[i] == tmp[digit]:
            digit += 1
	        if digit == 3:
                ans += 1
                break
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env/ python3
N = int(input())
S = input()
#A, B, C = input().split()
#A, B, C, X, Y = map(int, input().split())

#N = int(input())
#H, W = map(int, input().split())
#S = [input() for _ in range(H)]
#print(A[0][0])

ans = 0
for tmp_num in range(1000):
    tmp = str(tmp_num).zfill(3)
    digit = 0
    for i in range(N):
        if S[i] == tmp[digit]:
          digit += 1
	      if digit == 3:
            ans += 1
            break
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
 
cnt = [0]*11
i = 0
T = ''
for s in S:
  cnt[int(s)]+=1
  if min(cnt)<=3:
    T += s
#print(T)
ans = 0
P = []
for a in range(10):
  A = str(a)
  k = 0
  ind1 = -1
  while k < len(T)-2:
    t = T[k]
    if A == t:
      ind1 = k
      break
    k += 1
  if ind1 == -1:
    continue
  for b in range(10):
    B = str(b)
    l = ind1+1
    ind2 = -1
    while l < len(T)-1:
      t = T[l]
      if B == t:
        ind2 = l
        break
      l += 1
    #print(a,b,ind1,ind2)
    if ind2 == -1:
      continue
    for c in range(10):
      C = str(c)
      m = ind2+1
      while m < len(T):
        t = T[m]
        if C == t:
          ans += 1
          break
        m += 1
print(ans)
 
#print(*ans, sep='/n')
N = int(input())
S = input()

cnt = [0]*11
i = 0
T = ''
for s in S:
  cnt[int(s)]+=1
  if min(cnt)<=3:
    T += s
#print(T)
ans = 0
P = []
for a in range(10):
  A = str(a)
  k = 0
  ind1 = -1
  while k < len(T)-2:
    t = T[k]
    if A == t:
      ind1 = k
      break
    k += 1
  if ind1 == -1:
    continue
  for b in range(10):
    B = str(b)
    l = ind1+1
    ind2 = -1
    while l < len(T)-1:
      t = T[l]
      if B == t:
        ind2 = l
        break
      l += 1
    #print(a,b,ind1,ind2)
    if ind2 == -1:
      continue
    for c in range(10):
      C = str(c)
      m = ind2+1
      while m < len(T):
        t = T[m]
        if C == t:
          ans += 1
          break
        m += 1
print(ans)

#print(*ans, sep='/n')

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1000):
    seq = f"{i:03d}"
    cnt = 0
    for j in s:
        if seq[cnt] == j:
            cnt += 1
            if cnt == 3:
                break
    if cnt == 3:
        ans +=1
print(ans)

Submission status: Runtime Error

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

candidates = [0 for i in range(10 ** 3)]

count = 0
for i in range(1000):
    tmp_pass = f'{i:03}'

    index_0 = s.find(tmp_pass[0])
    if index_0 != -1 and index_0 < len(s) - 2:
        s_1 = s[index_0 + 1:]
        index_1 = s_1.find(tmp_pass[1])
        if index_1 != -1 and index_1 < len(s_1) - 1:
            s_2 = s_1[index_1 + 1:]
            # print(tmp_pass)
            # print(s_2)
            # index_2 = s_2.find(tmp_pass[2])
            # print(index_2)
            if s_2.find(tmp_pass[2]) != -1:
                count += 1

print(count)

Submission status: Runtime Error

Solution code:
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    S = stdin.readline().rstrip()
    count = 0
    for i in range(1000):
        left = 0
        not_found = False
        for c in f'{i:03}':
            for j in range(left, N):
                if S[j] == c:
                    left = j + 1
                    break
            else:
                not_found = True
                break
            if not_found:
                break
        if not not_found:
            count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

import itertools

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

if N-3 == 1:
    combs = list(range(N))
else:
    combs = list(itertools.combinations(range(N), N-3))

l_pw = []
for comb in combs:
    l_S = list(S)
    for idx in sorted(comb, reverse=True):
        l_S.pop(idx)
    l_pw.append(','.join(l_S))

# print(l_pw)

print(len(set(l_pw)))

Submission status: Runtime Error

Solution code:
#import math
#import bisect
#import numpy as np
#import itertools
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
INF = float('INF')
sys.setrecursionlimit(10**5)

def main():
    n = int(input())
    s = input()
    ans = 0
    pin = list(itertools.product(range(10), repeat=3))

    for cur in pin:
        a, b, c = map(str,cur)
        if a in s:
            aidx = s.index(a)
            if b in s[aidx+1:]:
                bidx = s[aidx+1:].index(b) + (aidx + 1)
                if c in s[bidx+1:]:
                    ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

tb = [False]*10**2
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            l = int(''.join(S[i]+S[j]+S[k]))
            tb[l] = True
print(tb.count(True))

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
using namespace std;


int main(){
  int n; cin >> n;
  string s; cin >> s;
  int c = 0;
  for (int i=0;i<1000;i++){
    string p;
    int flag = 0;
    if (i < 10) p = "00" + to_string(i);
    else if (i < 100) p = "0" + to_string(i);
    else p = to_string(i);
    for (int j=0;j<s.size();j++){
        if (s[j] == p[0] && flag == 0) flag++;
        else if (s[j] == p[1] && flag == 1) flag++;
        else if (s[j] == p[2] && flag == 2) {
            c++;
            break;
        }
    }
  }
    cout << c;
}

Submission status: Runtime Error

Solution code:
from copy import deepcopy
n = int(input())
s = input().rstrip()

def solve1(n, s):
    # 全探索
    cnt = 0
    for v in range(0, 1000):
        v = str(v)
        v = "0" * (3 - len(v)) + v
        idx = 0
        for i in range(len(s)):
            if s[i] == v[idx]:
                idx += 1
            if idx == 3:
                cnt += 1
                break
    print(cnt)

def solve2(n, s):
    # DP
    dp = [[[False for _ in range(1000)] for _ in range(4)] for _ in range(n+1)]
    dp[0][0][0] = True

    for i in range(n):
        for j in range(3):
            for k in range(100):
                if dp[i][j][k]:
                    num = k*10 + int(s[i])
                    dpp[i+1][j+1][num] = True
    cnt = 0
    for i in range(1000):
        if dp[n][3][i]:
            cnt += 1
    print(cnt)

solve2(n, s)

Submission status: Runtime Error

Solution code:
from copy import deepcopy
n = int(input())
s = input().rstrip()

def solve1(n, s):
    # 全探索
    cnt = 0
    for v in range(0, 1000):
        v = str(v)
        v = "0" * (3 - len(v)) + v
        idx = 0
        for i in range(len(s)):
            if s[i] == v[idx]:
                idx += 1
            if idx == 3:
                cnt += 1
                break
    print(cnt)

def solve2(n, s):
    # DP
    dp = [[[False for _ in range(1000)] for _ in range(4)] for _ in range(n+1)]
    dp[0][0][0] = True

    for i in range(n):
        for j in range(3):
            for k in range(100):
                if dp[i][j][k]:
                    num = k*10 + int(s[i])
                    dpp[i+1][j+1][num] = True
    cnt = 0
    for i in range(1000):
        if dp[3][i]:
            cnt += 1
    print(cnt)

solve2(n, s)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
T = 0
for s in range(1000):
  s = str(s)
  l = 0
  for m in range(N):
    if S[m] == s[l]:
      l += 1
    if l == 3:
      break
  if l >= 3:
    T += 1
print(T)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    string s;
    cin >> s;

    int ans = 0;
    for(int i = 0; i < 1000; i++){
        vector<int> A = {i / 100, (i % 100) / 10, i % 10};

        int idx = 0;
        for(int j = 0; j < n; j++){
            if('0' + A[idx] == s[j]){
                idx++;
            }

            if(idx == 3){ 
                ans++;
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Submission status: Runtime Error

Solution code:
import sys
import itertools
import numpy as np
input = sys.stdin.readline

N = int(input())
S = input()
cc = np.zeros(1000, dtype=np.int32)
ans = np.zeros(1000, dtype=np.int32)
for j in range(len(S)-1):
	p = int(S[j])
	for i in range(1000):
		if(p==i%10 and cc[i]==2):
			cc[i]+=1
			ans[i]=1
		elif(p==(i//10)%10 and cc[i]==1):
			cc[i]+=1
		elif(p==i//100 and cc[i]==0):
			cc[i]+=1
print(sum(ans))

Submission status: Runtime Error

Solution code:
a = int(input())
l = input()
dp = [0]*1110
qp = [0]*1110
ans = 0
#print('###############')
def bfs(i,x,y):
	#print(i,x)
	if y == 3:
		ans +=1
		return 0
	else:
		for j in range(i,a):
			if int(x+str(l[j])) != 1:bfs(j+1,x+str(l[j]),y+1)
			dp[int(x+str(l[j]))] = 1
bfs(0,'',0)
print(ans)

Submission status: Runtime Error

Solution code:
a = int(input())
l = input()
dp = [0]*1110
qp = [0]*1110
ans = 0
#print('###############')
def bfs(i,x,y):
	#print(i,x)
	if y == 3:
		ans +=1
		return 0
	else:
		for j in range(i,a):
			if int(x+str(l[j])) != 1:bfs(j+1,x+str(l[j]),y+1)
			dp[int(x+str(l[j]))] = 1
bfs(0,'',0)
print(sum(qp))

Submission status: Runtime Error

Solution code:
import itertools
N = int(input())
S = list(input())
for i in range(len(S)):
  S[i] = int(S[i])

ans_l = []
number_l = list(itertools.permutations(range(N)))

c = collections.Counter(number_l)

print(len(c))

Submission status: Runtime Error

Solution code:
import itertools
N = int(input())
S = list(input())
for i in range(len(S)):
  S[i] = int(S[i])

ans_l = []
number_l = list(itertools.permutations(range(N)))

c = collections.Counter(number_l)

print(c)

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
s=input()
ar=np.zeros(((n,n,n)))+100000
i=0
j=0
k=0
while i!=n-2:
    j=i+1
    while j!=n-1:
        k=j+1
        while k!=n:
            ar[i][j][k]=int(s[i])*100+int(s[j])*10+int(s[k])
            k=k+1
        j=j+1
    i=i+1
li=ar.reshape(1,n*n*n).tolist()[0]
print(len(list(set(li)))-1)

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
s=input()
ar=np.arange(n*n*n).reshape(n,n,n)
ar=ar*0+10000
i=0
j=0
k=0
while i!=n-2:
    j=i+1
    while j!=n-1:
        k=j+1
        while k!=n:
            ar[i][j][k]=int(s[i])*100+int(s[j])*10+int(s[k])
            k=k+1
        j=j+1
    i=i+1
li=ar.reshape(1,n*n*n).tolist()[0]
print(len(list(set(li)))-1)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
def solve():
    ans = 0
    for i in range(1000):
        t = str(i).zfill(3)
        t_index = 0 
        for s_index in range(N):
            if s[s_index] == t[t_index]:
                t_index += 1
                if t_index == 3:
                    break
        if t_index == 3:
            ans += 1
    print(ans)
solve()

Submission status: Runtime Error

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

r = 0
for i in range(1000):
  t = str(i).zfill(3)
  ti = 0
  if t[ti] > a[0]:
    a = a[1:]
  for si in range(len(a)):
    if a[si] == t[ti]:
      ti += 1
      if ti == 3:
        break
  if ti == 3:
    r += 1

print(r)

Submission status: Runtime Error

Solution code:
import itertools

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

Sstr = str(S)
ListS = []
if len(Sstr) != N:
    ListS.append(0)
    for i in range(N - 1, 0, -1):
        ListS.append(int(Sstr[-i]))
else:
    for i in range(N , 0, -1):
        ListS.append(int(Sstr[-i]))
resultList = list(itertools.combinations(ListS, 3))
resultList = list(set(resultList))
print(len(resultList))

Submission status: Runtime Error

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

ans=0
for i in range(1000):
    flag = 0
    for s in range(S):
        if flag==0 and (i//100)%10==int(s):
            flag+=1
        elif flag==1 and (i//10)%10==int(s):
            flag+=1
        elif flag==2 and i%10==int(s):
            flag+=1
    if flag==3:
        ans+=1

print(ans)

Submission status: Runtime Error

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

ans=0
for i in range(1000):
    flag = 0
    for j in range(S):
        if flag==0 and (i//100)%10==int(S[j]):
            flag+=1
        elif flag==1 and (i//10)%10==int(S[j]):
            flag+=1
        elif flag==2 and i%10==int(S[j]):
            flag+=1
    if flag==3:
        ans+=1

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
S=int(input())
S_list=[]
while S > 0:
  S_list.append(S%10)
  S//=10
S_list.reverse()
secret_list=[]
for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      secret_list.append([S_list[i],S_list[j],S_list[k]])

secret_list_original=list(set(map(tuple,secret_list)))
print(len(secret_list_original))

Submission status: Runtime Error

Solution code:
N=int(input())
S=int(input())
S_list=[]
while S > 0:
  S_list.append(S%10)
  S//=10
S_list.reverse()
secret_list=[]
for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      secret_list.append([S_list[i],S_list[j],S_list[k]])
secret_list_original=list(set(map(tuple,secret_list)))
print(len(secret_list_original))