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:
INF = int(1e9) + 7

n = int(input())
a = list(map(int, input().split()))
col = [0,0,0]
ans = 1
for i in range(n):
        col[i] +=1
        continue
    c = set(col)
    m = 0
    for j in range(3):
        if c==col[j]:
            m +=1
    ans *= m
    
    for j in range(3):
        if i==col[j]:
            col[j] +=1
            break
        else:
            continue
    ans = ans%INF

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split())
r = {}
total = 1
for i in range(N):
  if A[i] in r.keys:
    r[A[i]] += 1
  else:
    r[A[i]] = 1
  if A[i] == 0:
    total = total * (4-r[A[i]])
  else:
    total = total * (r[A[i] - 1] - r[A[i]] + 1)
total = total % (10 ** 9 + 7)
print(total)

Submission status: Runtime Error

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

d=[0]*1000
di=[0]*10
dj=[[0]*10]*10
for i in range(N):
  ii=int(s[i])
  if sum(di)==10:break
  if di[ii]==1:continue
  else:di[ii]=1
  for j in range(i+1,N):
    jj=int(s[j])
    if sum(df[ii])==10:break
    if dj[ii][jj]==1:continue
    else:dj[ii][jj]=0
    dk=[0]*10
    for k in range(j+1,N):
      kk=int(s[k])
      d[ii*100+jj*10+kk]=1
      dk[kk]=1
      if sum(dk) ==10:break
      
print(sum(d))

Submission status: Runtime Error

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

ans_list = {}


for i in range(N):
    if i in i_set:
        continue
    i_set.add(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:
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
def list_count(my_list):
    dic={} #辞書型の宣言
    for num in my_list:
        if num in dic: #もしnumがkeyとして辞書にあれば
            dic[num]+=1 #valueに+1
        else: #なければ
            dic[num]=1 #dicにnumというkeyを追加し、対応するvalueを1とする
    return dic
import sys
input = sys.stdin.readline
n=int(input())
s=list(input())
for i in range(n):
    s[i]=int(s[i])
l=[0]*1000
a=list(list_count(s).values())
#print(a)
n=len(a)
m=3
dp=[[0 for i in range(n+1)] for j in range(m+1)]

#メイン
#dp[i+1][j]:=i番目までの品物からj個選ぶ組み合わせの総数

for i in range(n+1):
    dp[i][0]=1
for i in range(n):
    for j in range(1,m+1):
        if j-1-a[i]>=0:
            dp[i+1][j]=(dp[i+1][j-1]+dp[i][j]-dp[i][j-1-a[i]])
        else:
            dp[i+1][j]=(dp[i+1][j-1]+dp[i][j])

#出力
print(dp[n][m])

Submission status: Runtime Error

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

import itertools as it
x = list(it.combinations(list(S), 3))
y = ["".join(i) for i in x]
z = len(np.unique(y))
print(z)

Submission status: Runtime Error

Solution code:
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
def list_count(my_list):
    dic={} #辞書型の宣言
    for num in my_list:
        if num in dic: #もしnumがkeyとして辞書にあれば
            dic[num]+=1 #valueに+1
        else: #なければ
            dic[num]=1 #dicにnumというkeyを追加し、対応するvalueを1とする
    return dic
import sys
input = sys.stdin.readline
n=int(input())
s=list(input())
for i in range(n):
    s[i]=int(s[i])
l=[0]*1000
a=list(list_count(s).values())
print(a)
n=len(a)
m=3
dp=[[0 for i in range(n+1)] for j in range(m+1)]

#メイン
#dp[i+1][j]:=i番目までの品物からj個選ぶ組み合わせの総数

for i in range(n+1):
    dp[i][0]=1
for i in range(n):
    for j in range(1,m+1):
        if j-1-a[i]>=0:
            dp[i+1][j]=(dp[i+1][j-1]+dp[i][j]-dp[i][j-1-a[i]])
        else:
            dp[i+1][j]=(dp[i+1][j-1]+dp[i][j])

#出力
print(dp[n][m])

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(2000)

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

pattern = set()

def generate_pwd(cnt, lucky_num):
    if len(lucky_num) == 3:
        pattern.add(''.join(lucky_num))
        return
    if cnt > 3:
        return
    
    generate_pwd(cnt, lucky_num[:cnt] + lucky_num[cnt + 1:])
    generate_pwd(cnt + 1, lucky_num)

    return

generate_pwd(0, S)
print(len(pattern))

Submission status: Runtime Error

Solution code:
import sys
import itertools
input = sys.stdin.readline
N = int(input())
S = input()
pred = {}
d = {}
count = 0
delcount = 0

for i in range(0, N):
    if S[i] not in pred:
        pred[S[i]] = 1
    elif pred[S[i]] == 4:
        S = S[:i] + S[i+1:]
        delcount +=1
        i+=1
    else:
        pred[S[i]] += 1

combs = list(itertools.combinations(range(N-delcount), 3))
for c in combs:
    if S[c[0]]+S[c[1]]+S[c[2]] not in d:
        d[S[c[0]]+S[c[1]]+S[c[2]]] = 1
        count +=1
    else:
        pass
#print(d)
print(count)

Submission status: Runtime Error

Solution code:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

string s;
int d[30303][10];
bool ans[10][10][10];

int main(void){
	int n,i,j,k,cnt=0;
	cin >> n;
	cin >> s;
	for(i=0; i<n; ++i){
		s[i] -= '0';
		for(j=0; j<10; ++j){
			d[i+1][j] += d[i][j];
		}
		++d[i+1][s[i]];
	}
	for(i=0; i<n; ++i){
		for(j=0; j<10; ++j){
			for(k=0; k<10; ++k){
				if(d[i][j] && (d[n][k]-d[i+1][k])){
					ans[j][s[i]][k] = true;
				}
			}
		}
	}
	for(i=0; i<10; ++i){
		for(j=0; j<10; ++j){
			for(k=0; k<10; ++k){
				if(ans[i][j][k]){
					++cnt;
				}
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
S = list(input())
sl = itertools.combinations(S, 3)
sl_s = set(sl)
print(len(sl_s))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 1
for i in range(n):
    z = a[i]
    if z == 0:
        num = 3
        for j in range(0,i):
            if z == a[j]:
              num -= 1
        ans *= num
    else:
        num = 0
        for j in range(0,i):
            if z-1 == a[j]:
                num += 1
            if z == a[j]:
                num -= 1
        ans *= num
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import itertools
input = sys.stdin.readline
N = int(input())
S = input()
pred = {}
d = {}
count = 0
delcount = 0

for i in range(0, N):
    if S[i] not in pred:
        pred[S[i]] = 1
    elif pred[S[i]] == 4:
        S = S[:i] + S[i+1:]
        delcount +=1
    else:
        pred[S[i]] += 1

combs = list(itertools.combinations(range(N-delcount), 3))
for c in combs:
    if S[c[0]]+S[c[1]]+S[c[2]] not in d:
        d[S[c[0]]+S[c[1]]+S[c[2]]] = 1
        count +=1
    else:
        pass
#print(d)
print(count)

Submission status: Runtime Error

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

pattern = set()

def generate_pwd(cnt, lucky_num):
    if len(lucky_num) == 3:
        pattern.add(''.join(lucky_num))
        return
    if cnt > 3:
        return
    
    generate_pwd(cnt, lucky_num[:cnt] + lucky_num[cnt + 1:])
    generate_pwd(cnt + 1, lucky_num)

    return

generate_pwd(0, S)
print(len(pattern))

Submission status: Runtime Error

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

pass_list = list(map(lambda x: str(x).zfill(3), range(1000)))
res = 0

for p in pass_list:
    
    ptr = 0
    one = False
    two = False
    three = False
    
    for i in range(len(s)):
        if(s[i] == p[0]):
            ptr = i
            one = True
            break
    
    for i in range(ptr+1, len(s)):
        if(s[i] == p[1]):
            ptr = i
            two = True
            break
    
    for i in range(ptr+1, len(s)):
        if(s[i] == p[2]):
            ptr = i
            three = True
            break
    
    if(one and two and three): res += 1

print(res)

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
l=[]
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:
n=int(input())
s=input()
l=[]
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):
          l.append(a)

print(len(l))

Submission status: Runtime Error

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

for i in range(n-1):
    i_set=set(s[i+1:])

    for j in i_set:
        j_ind=s.index(j)
        s_i=s[i+1:]
        j_set=set(s_i[s_i.index(j)+1:])
        [ans.add(s[i]+j+k) for k in j_set]

print(len(ans))

Submission status: Runtime Error

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

ans = 0
for i in range(1000):
    if i <= 9:
        if S.count("0") >= 2:
            first = S.index("0")
            SS = S[first+1:]
            second = SS.index("0")
            SSS = SS[second+1]
            if SSS.index(str(i)) == 0:
                continue
            ans += 1
            ##print(i)
        else:
            continue
    elif i <= 99:
        if S.count("0") >= 1:
            first = S.index("0")
            SS = S[first+1:]
            tmp = str(i)
            if SS.count(tmp[0]) == 0:
                continue
            second = SS.index(tmp[0])
            SSS = SS[second+1:]
            if SSS.count(tmp[1]) == 0:
                continue
            ans += 1
            ##print(i)
        else:
    
            continue
    else:
        tmp = str(i)
        ##print(tmp)
        if S.count(tmp[0]) == 0:
            continue
        first = S.index(tmp[0])
        SS = S[first+1:]
        if SS.count(tmp[1]) == 0:
            continue
        second = SS.index(tmp[1])
        SSS = SS[second+1:]
        if SSS.count(tmp[2]) == 0:
            continue
        ##print(i)
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
def cal(a, b, c):
    x = a[0]
    for bb in b:
        if bb > x:
            y = bb
            for cc in c:
                if cc > y:
                    return 1
    return 0
li = [[] for _ in range(10)]
for i, n in enumerate(S):
    num = int(n)
    li[num].append(i)
cnt = 0
for i in range(10):
    if len(li[i]) > 0:
        for j in range(10):
            if len(li[j]) > 0:
                for k in range(10):
                    if len(li[k]) > 0:
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(input())
A = list(range(100))
B = list(map(str, A))
ans = 0
for i in range(1000):
    if i <= 9:
        if S.count("0") >= 2:
            first = S.index("0")
            SS = S[first+1:]
            second = SS.index("0")
            SSS = SS[second+1]
            if SSS.index(str(i)) == 0:
                continue
            ans += 1
            ##print(i)
        else:
            continue
    elif i <= 99:
        if S.count("0") >= 1:
            first = S.index("0")
            SS = S[first+1:]
            tmp = str(i)
            if SS.count(tmp[0]) == 0:
                continue
            second = SS.index(tmp[0])
            SSS = SS[second+1:]
            if SSS.count(tmp[2]) == 0:
                continue
            ans += 1
            ##print(i)
        else:
            continue
    tmp = str(i)
    ##print(tmp)
    if S.count(tmp[0]) == 0:
        continue
    first = S.index(tmp[0])
    SS = S[first+1:]
    if SS.count(tmp[1]) == 0:
        continue
    second = SS.index(tmp[1])
    SSS = SS[second+1:]
    if SSS.count(tmp[2]) == 0:
        continue
    ##print(i)
    ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
n = int(inout())
str_s = inout()

candidates = set()
for i in range(n-1):
    for j in range(i+1,n):
        candidates = candidates.union([str_s[i] + str_s[j] + k for k in str_s[j:]])
print(len(candidates))

Submission status: Runtime Error

Solution code:
mport sys
import itertools

input = sys.stdin.readline
#sys.setrecursionlimit(1e9)

def main():
    """code here"""
    N = int(input())
    S = list(input())
    S = S[:-1]

    keta = N -3

    num = len(S)
    num = num-keta

    ans = []

    for v in itertools.combinations(S,num):
        #print(v)
        ans.append(v)
    print(len(set(ans)))

    
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

S = list(S)

number_place_dict={}
for i in range(10):
  number_place_dict[i]=list()

#print(number_place_dict)

for i in range(len(S)):
  number_place_dict[int(S[i])].append(i)

#print(number_place_dict)

ans = 0

for i in range(0,1000):
  i = list(str(i))
  if len(i) == 1:
    i = [00]+i
  elif len(i) == 2:
    i = [0]+i
  
  #print(i)

  next_place_confition = -1

  for j in range(0,3):
    #print("数字:",int(i[j]),end="")
    place_list = number_place_dict[int(i[j])]
    index = bisect.bisect_right(place_list, next_place_confition)
    if index == len(place_list):
      #print("条件合致無し")
      break
    else:
      next_place_confition = place_list[index]
      #print("……次は→以上のindexが要:",next_place_confition)
  else:
    #print("OK")
    ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import bisect
n=int(input())
s=input()
t=[[] for i in range(10)]
for i in range(n):
    t[int(s[i])].append(i)
c=0
for i in range(10):
    if len(t[i])==0:
        continue
    for j in range(10):
        m=bisect.bisect(t[j],t[i][0])
        if len(t[j])==m:
            continue
        for k in range(10):
            n=bisect.bisect(t[k],t[j][m])
            if len(t[k])==n:
                continue
            else:
                c+=1
prin

Submission status: Runtime Error

Solution code:
import re
n0=input()
s=input()
ans=0

for i in range(1000):
    n = str(i).zfill(3)
#    print(n[0])
    p = f".*{n[0]}.*{n[1]}.*{n[2]}.*"
    if re.search(p,s):
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
a=int(input())
b=input()
c={}
for i in range(a):
  for j in range(i+1,a):
    for k in range(j+1,a):
      c.add(b[i]+b[j]+b[k])
print(len(c))

Submission status: Runtime Error

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

d=[0]*1000
di=[0]*10
dj=[0]*10
dk=[0]*10
for i in range(N):
  ii=int(s[i])
  if di[ii]==1:continue
  else di[ii]=1
  for j in range(i+1,N):
    jj=int(s[j])  
    if di[jj]==1:continue
    else di[jj]=1
    for k in range(j+1,N):
      kk=int(s[k])
      d[ii*100+jj*10+kk]=1
      
print(sum(di))

Submission status: Runtime Error

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

d=[0]*1000
di=[0]*10
dj=[0]*10
dk=[0]*10
for i in range(N):
  ii=int(s[i])
  if di[ii]=1:continue
  else di[ii]=1
  for j in range(i+1,N):
    jj=int(s[j])  
    if di[jj]=1:continue
    else di[jj]=1
    for k in range(j+1,N):
      kk=int(s[k])
      d[ii*100+jj*10+kk]=1
      
print(sum(di))

Submission status: Runtime Error

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

import sys
sys.setrecursionlimit(2000)

pins = set()
pins_1 = set()
pins_2 = set()

def dfs(s, pin, cnt):
    if cnt == 1:
        if pin in pins_1:
            return
        pins_1.add(pin)
    if cnt == 2:
        if pin in pins_2:
            return
        pins_2.add(pin)    
    if cnt == 3:
        pins.add(pin)
    for i in range(len(s)):
        dfs(s[i+1:], pin+s[i], cnt+1)
        
dfs(S, '', 0)
print(len(pins))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 1
r = 1
b = 0
g = 0
MOD = 1000000007

for i in range(1,N):
    a = A[i]
    count = 0
    flag = 0
    if a == r:
        r += 1
        count += 1
        flag = 1
    if a == b:
        if flag == 1:
            count += 1
        else:
            b += 1
            count += 1
            flag = 1
    if a == g:
        if flag == 1:
            count += 1
        else:
            g += 1
            count += 1
            flag = 1
    if flag == 0:
        print(0)
        exit()
    ans *= count
    ans %= MOD
print((ans*3)%MOD)

Submission status: Runtime Error

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

import sys
sys.setrecursionlimit(2000)

pins = set()
def dfs(s, pin, cnt):
    if cnt == 3:
        pins.add(pin)
    for i in range(len(s)):
        dfs(s[i+1:], pin+s[i], cnt+1)
        
dfs(S, '', 0)
print(len(pins))

Submission status: Runtime Error

Solution code:

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

count = 0

exist = []
for v in itertools.combinations(S, 3):
    if(v in exist):
        continue
    else:
        exist.append(v)
        count +=1


print(count)

Submission status: Runtime Error

Solution code:
N= int(input())
S=input()
pointer = 0
counter = 0
def search(point,string, num):
  l_point = point
  while True:
    if string[l_point]==num:
      return l_point
    l_point = l_point+1
  return -1

for i in range(0,10):
  pointer = search(pointer,S, i)
  if pointer ==-1:
    pointer = 0
    continue;
  else:
    for j in range(0,10):
      pointer_1 = search(pointer,S,j)
      if pointer_1 == -1:
        pointer_1 = 0
        continue;
      else:
        for k in range(0,10):
           pointer_2 = search(pointer_1,S,k)  
            if pointer_2 == -1:
              pointer_2 = 0
              continue;
            else:
              counter = counter+1

Submission status: Runtime Error

Solution code:
n,s = [input() for i in range(2)]
c = 0
for i in range(1000):
    if i < 10:
        a1 = '0'
        a2 = '0'
        a3 = i
    elif i < 100:
        a1 = '0'
        a2 = str(i)[0]
        a3 = str(i)[1]
    else:
        a1 = str(i)[0]
        a2 = str(i)[1]
        a3 = str(i)[2]
    p1 = s.find(a1)
    if p1 >= 0:
        p2 = s.find(a2, p1 + 1)
        if p2 >= 0:
            if s.find(a3, p2 + 1) >= 0:
                c += 1
print(c)

Submission status: Runtime Error

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

a = set()


def do(a,s,t):
    if len(t)==0:
        return a
    if len(s) == 2:
        return do(a,s,t[1:]) | {s + t[0]}
    else:
        return do(a,s,t[1:]) | do(a,s+t[0],t[1:])

print(len(do(a,"",s)))

Submission status: Runtime Error

Solution code:
n=int(input())
if n<3:
    print(0)
    exit()
if n==3:
    print(1)
    exit()
s=input()
s=[int(i)+1 for i in s]
l=[int(i) for i in s]
l1=[0]*(n+16) 
l2=[0]*(n+13)
l3=[0]*(n+12)
l2[n-1]=1 
l3[s[n-1]-1]=1 
k=3 
for i in range(n-2,-1,-1): 
    l2[i]=l2[i+1]
    if l3[s[i]-1]==0:
        l2[i]+=1 
        l3[s[i]-1]=1 
for j in range(1,k):
    l3=[0]*n 
    l1[n-1]=0 
    for i in range(n-2,-1,-1) : 
        l1[i]=l1[i+1]
        l1[i]=l1[i]+l2[i+1]
        l1[i]=l1[i]-l3[s[i]-1]
        l3[s[i]-1]=l2[i+1]
    l2=l1[:]
print(l1[0])

Submission status: Runtime Error

Solution code:
N=int(input())
S=str(input())
a=[]
for i in range(0,len(S)-2):
  for j in range(i+1,len(S)-1):
    for k in range(j+1,len(S)):
      a.append(int(S[i]+S[j]+S[k])
print(len(set(a)))

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(str(input()))
for i in range(n):
    s[i]=int(s[i])
g=[[0 for i in range(10)] for j in range(10)]
r=[0 for j in range(n+1)]
l=[0 for j in range(n+1)]
for i in range(n):
    if r[i]&(2**s[i])==0:
        r[i+1]=r[i]+2**s[i]
    else:
        r[i+1]=r[i]
    if l[n-i]&(2**s[n-i])==0:
        l[n-i-1]=l[n-i]+2**s[i]
    else:
        l[n-i-1]=l[n-i]
ans=[[[0 for i in range(10)] for j in range(10)] for k in range(10)]
for i in range(n):
    for j in range(10):
        for k in range(10):
            if r[i]&(2**j)==1 and l[i+1]&(2**k)==1:
                ans[j][s[i]][k]+=1
kai=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if ans[i][j][k]>0:
                kai+=1
print(kai)

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
s=[int(i)+1 for i in s]
l=[int(i) for i in s]
l1=[0]*(n+62332) 
l2=[0]*(n+32323)
l3=[0]*(n+23333)
l2[n-1]=1 
l3[s[n-1]-1]=1 
k=3 
for i in range(n-2,-1,-1): 
    l2[i]=l2[i+1]
    if l3[s[i]-1]==0:
        l2[i]+=1 
        l3[s[i]-1]=1 
for j in range(1,k):
    l3=[0]*n 
    l1[n-1]=0 
    for i in range(n-2,-1,-1) : 
        l1[i]=l1[i+1]
        l1[i]=l1[i]+l2[i+1]
        l1[i]=l1[i]-l3[s[i]-1]
        l3[s[i]-1]=l2[i+1]
    l2=l1[:]
print(l1[0])

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
s=[int(i)+1 for i in s]
l=[int(i) for i in s]
l1=[0]*(n+293) 
l2=[0]*(n+323)
l3=[0]*(n+233)
l2[n-1]=1 
l3[s[n-1]-1]=1 
k=3 
for i in range(n-2,-1,-1): 
    l2[i]=l2[i+1]
    if l3[s[i]-1]==0:
        l2[i]+=1 
        l3[s[i]-1]=1 
for j in range(1,k):
    l3=[0]*n 
    l1[n-1]=0 
    for i in range(n-2,-1,-1) : 
        l1[i]=l1[i+1]
        l1[i]=l1[i]+l2[i+1]
        l1[i]=l1[i]-l3[s[i]-1]
        l3[s[i]-1]=l2[i+1]
    l2=l1[:]
print(l1[0])

Submission status: Runtime Error

Solution code:
mu=int(input())
my_list = list(input())
tlist = []
for i in range(0,len(mu-2):
    for t in range(i+1,mu-1):
        for p in range(t+1,mu):
            s = my_list[i]+my_list[t]+my_list[p]
            if tlist.count(s)==0:
                tlist.append(s)

print(len(tlist))

Submission status: Runtime Error

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

from collections import Counter
left = Counter('')
right = Counter(s[1:])

ans = set()
for i in range(10):
    lefts[str(i)] = []
    rights[str(i)] = []

for i in range(1, n-1):
    left[s[i-1]] += 1
    right[s[i]] -= 1
    # print(left, right)

    left_u = []
    for k in left.keys():
        if left[k] >= 1:
            left_u.append(k)
    right_u = []
    for k in right.keys():
        if right[k] >= 1:
            right_u.append(k)

    for l in left_u:
        for r in right_u:
            tmp = l + s[i] + r
            ans.add(tmp)

print(len(ans))

Submission status: Runtime Error

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


def count_pins(n, s):
    k = 3
    if n < k or n < 1 or k < 1:
        return 0
    elif n == k:
        return 1
    v1 = [0 for _ in range(n)]
    v2 = [0 for _ in range(n)]
    v3 = [0 for _ in range(n)]
    v2[n - 1] = 1
    v3[s[n - 1] - 1] = 1
    for i in range(n - 1)[::-1]:
        v2[i] = v2[i + 1]
        if v3[s[i] - 1] == 0:
            v2[i] += 1
            v3[s[i] - 1] = 1
    for j in range(1, k):
        v3 = [0 for _ in range(n)]
        v1[n - 1] = 0
        for i in range(n - 1)[::-1]:
            v1[i] = v1[i + 1]
            v1[i] = v1[i] + v2[i + 1]
            v1[i] = v1[i] - v3[s[i] - 1]
            v3[s[i] - 1] = v2[i + 1]
        v2 = v1[:]
    return v1[0]


def main():
    n = int(input())
    s = [int(c) for c in input()]
    res = count_pins(n, s)
    print(res)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import re

N = int(input())
S = input().strip()

count = 0
for c1 in range(10):
	for c2 in range(10):
		for c3 in range(10):
			if re.search(f"{c1}.*{c2}.*{c3}", S):
				count += 1
print(count)

Submission status: Runtime Error

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

from collections import defaultdict
ans = defaultdict(int)
def dfs(now, pos):
    if len(now) == 3:
        ans[now] = 1
        return
    if pos == n:
        return
    dfs(now+s[pos], pos+1)
    dfs(now, pos+1)

dfs("", 0)

anss = 0
for i in ans.values():
    anss += i

print(anss)

Submission status: Runtime Error

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

using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < 1000; i++) {
		int cur = i + 1000;
		for (int j = s.size() - 1; cur > 1 && j >= 0; j--) {
			if (s[j] - '0' == cur % 10) {
				cur /= 10;
			}
		}
		if (cur == 1) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}