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: Time Limit Exceeded

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

import itertools
num = list(itertools.combinations(range(n), 3))

pin = []
for i in range(len(num)):
    pin.append(s[num[i][0]]+s[num[i][1]]+s[num[i][2]])

import collections
c = collections.Counter(pin)
print(len(c))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=0
for i in range(1000):
  t_str=str(i)
  t_len=len(t_str)
  t_str=(3-t_len)*"0"+t_str
  cur_idx=0
  ok=0
  for j,ss in enumerate(s):
    if ss==t_str[cur_idx]:
      cur_idx+=1
      ok+=1
    if cur_idx==3:break
  if cur_idx==3:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=input()
ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1=False
            flag2=False
            flag3=False
            for s in S:
                if s==str(i) and not(flag1):
                    flag1=True
                    continue
                if s==str(j) and flag1 and not(flag2):
                    flag2=True
                    continue
                if s==str(k) and flag1 and flag2 and not(flag3):
                    flag3=True
                    continue
            if flag1 and flag2 and flag3:
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
t = []
for i in range(n):
    t.append(len(set(s[i:])))
done_i,done_j = [],[]
for i in range(n-2):
    done_j = []
    if not s[i] in done_i:
        for j in range(i+1,n-1):
            if s[j] not in done_j:
                ans += t[j+1]
            done_j.append(s[j])
        done_i.append(s[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
done_i,done_j = [],[]
for i in range(n-2):
    done_j = []
    if not s[i] in done_i:
        for j in range(i+1,n-1):
            if s[j] not in done_j:
                ans += len(set(s[j+1:]))
            done_j.append(s[j])
        done_i.append(s[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
count=0
def change(N):
    a=int((N-N%100)//100)
    b=int((N-100*a-N%10)//10)
    c=int(N%10)
    return [a,b,c]

def check(S,i,a):
    Q=-1
    for j in range(i+1,len(S)):
        if int(S[j])==int(a):
            Q=j
            break
    return Q

for i in range(1000):
    A=change(i)
    a=check(S,-1,A[0])
    b=check(S,a,A[1])
    c=check(S,b,A[2])
    if 0<=a<b<c:
        count+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = set()
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            ans.add(S[i] + S[j] + S[k])

print(len(ans))

Submission status: Time Limit Exceeded

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

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

ans = 0
pattern = []
for x in range(N):
    for y in range(x + 1, N):
        if (S[x] + S[y]) not in pattern:
            ans += len(set(S[y + 1:]))
            pattern.append(S[x] + S[y])

print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

ans = 0
pattern = []
for x in range(N):
    for y in range(x + 1, N):
        if (S[x] + S[y]) not in pattern:
            ans += len(set(S[y + 1:]))
            pattern.append(S[x] + S[y])

print(ans)

Submission status: Time Limit Exceeded

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

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

pattern = []
for x in range(N):
    for y in range(x + 1, N):
        for z in range(y + 1, N):
            pattern.append(S[x] + S[y] + S[z])

print(len(set(pattern)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

p = list(itertools.combinations(s, 3))
p = set(p)

print(len(p))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = 0


for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = 0
            flag2 = 0
            
            for l in range(n):
                if flag1 == 0 and s[l] == str(i):
                    flag1 = 1
                    continue
                
                if flag1 == 1 and flag2 == 0 and s[l] == str(j):
                    flag2 = 1
                    continue
                
                if flag1 == 1 and flag2 == 1 and s[l] == str(k):
                    ans += 1
                    break
                
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(1000):
    filled_num = str(i).zfill(3)
    target = list(filled_num)
    ok1 = False
    ok2 = False
    ok3 = False

    for k in range(len(S)):
        if S[k] == target[2] and ok2:
            ok3 = True
        elif S[k] == target[1] and ok1:
            ok2 = True
        elif S[k] == target[0]:
            ok1 = True

        if ok3:
            break
    if ok3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def test(i, results):
    filled_num = str(i).zfill(3)
    target = list(filled_num)
    index = 0
    j = 0
    for k in range(index, len(S), 1):
        if S[k] == target[j]:
            index = k + 1
            j += 1
            if j == 3:
                results.add(filled_num)
                return


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

results = set()

for i in range(1000):
    test(i, results)

print(len(results))

Submission status: Time Limit Exceeded

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

results = set()

for i in range(1000):
    # 対象となる3桁の数字を用意
    filled_num = str(i).zfill(3)
    target = list(filled_num)
    count = 0
    index = 0
    j = 0
    for k in range(index, len(S), 1):
        if S[k] == target[j]:
            count += 1
            index = k + 1
            j += 1
            if j == 3:
                results.add(filled_num)
                break

print(len(results))

Submission status: Time Limit Exceeded

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

results = set()

for i in range(1000):
    # 対象となる3桁の数字を用意
    filled_num = str(i).zfill(3)
    target = list(filled_num)
    count = 0
    index = 0
    for j in range(3):
        for k in range(index, len(S), 1):
            if S[k] == target[j]:
                count += 1
                index = k + 1
                break
    if count == 3:
        # print(filled_num)
        results.add(filled_num)

print(len(results))

Submission status: Time Limit Exceeded

Solution code:
def test(original: list, array: list, index: int,
         remain_count: int, results: set, results_1, results_2):
    # 3桁抽出したら終了
    if len(array) == 1:
        if "".join(array) in results_1:
            return
        results_1.add("".join(array))
    if len(array) == 2:
        if "".join(array) in results_2:
            return
        results_2.add("".join(array))
    if len(array) == 3:
        # print("".join(array))
        results.add("".join(array))
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        new_array = array[:]
        new_array.append(
            original[i])
        test(
            original,
            new_array,
            i + 1,
            remain_count,
            results,
            results_1,
            results_2)

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


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

results = set()
results_1 = set()
results_2 = set()

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

print(len(results))

Submission status: Time Limit Exceeded

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
    for i in range(index, len(original), 1):
        new_array = array[:]
        new_array.append(
            original[i])
        test(
            original,
            new_array,
            i + 1,
            remain_count,
            results)

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


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

results = set()

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

print(len(results))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

def avail_pin(pin):
  for j in range(len(s)):
    if s[j] == pin[0]:
      for k in range(j+1, len(s)):
        if s[k] == pin[1]:
          for l in range(k+1, len(s)):
            if s[l] == pin[2]:
              return 1
  return 0
  
ans = 0
for i in range(1000):
  pin = '{:03}'.format(i)
  ans += avail_pin(pin)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

pin = set()
for i, j, k in itertools.combinations(range(len(s)), 3):
  pin.add(s[i] + s[j] + s[k])
print(len(pin))

Submission status: Time Limit Exceeded

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

result = 0

for i in range(1000):
    if i < 10:
        temp = "00" + str(i)
    elif i < 100:
        temp = "0" + str(i)
    else:
        temp = str(i)

    cur = 0
    for j in range(N):
        if S[j] == temp[cur]:
            cur += 1
        if cur == 3:
            result += 1
            break

print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
D = {}
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            Si = str(S[i] + S[j] + S[k])
            if (Si) not in D:
                D[Si] = 1
print(len(D))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

Solution code:
N = input()
S = input()
set = {1000}
for i in range(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)
print(len(set)-1)

Submission status: Time Limit Exceeded

Solution code:
ans = 1
N = int(input())
s = input()
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)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
s = input()
key_list = []
for i in range(n):
  for j in range(n - i - 1):
    for _s in s[i + j + 2:]:
      #print(s[i] + s[i + j + 1] + _s)
      key_list.append(s[i] + s[i + j + 1] + _s)
print(len(list(set(key_list))))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
s = input()
key_list = []
for i in range(n):
  for j in range(n - i - 1):
    for k in range(n - i - j - 2):
      key_list.append(s[i] + s[i + j + 1] + s[i + j + k + 2])
print(len(list(set(key_list))))

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=list(map(int,stdin.readline().strip().split()))[0]
st=list(stdin.readline().strip())
count=0
cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            cnt=0
            number=[str(i),str(j),str(k)]
            for num in range(N):
                if number[cnt]==st[num]:
                    cnt+=1
                    if cnt==3:
                        count += 1
                        break
            cnt = 0


print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=list(map(int,stdin.readline().strip().split()))[0]
st=list(stdin.readline().strip())
count=0
stt=set(st)
stt=list(stt)
num=["0","1","2","3","4","5","6","7","8","9"]
num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]
cnt = 0
for number in num_list:

    for i in range(N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:
                count += 1
                break
    cnt = 0


print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=int(input())
st=list(stdin.readline().strip())
count=0
stt=set(st)
stt=list(stt)
num=["0","1","2","3","4","5","6","7","8","9"]
num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    cnt = 0
    for i in range(N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:
                count += 1
                break


print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=list(map(int,stdin.readline().strip().split()))[0]
st=list(stdin.readline().strip())
count=0
stt=set(st)
stt=list(stt)
num=['0','1','2','3','4','5','6','7','8','9']
num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    cnt = 0
    for i in range(N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:
                count += 1
                break


print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=list(map(int,stdin.readline().strip().split()))[0]
st=list(stdin.readline().strip())
count=0
stt=set(st)
num=list(stt)
# num=["0","1","2","3","4","5","6","7","8","9"]
# num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    cnt = 0
    for i in range(N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:
                count += 1
                break


print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=list(map(int,stdin.readline().strip().split()))[0]
st=list(stdin.readline().strip())
count=0
stt=set(st)
stt=list(stt)
num=["0","1","2","3","4","5","6","7","8","9"]
num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    cnt = 0
    for i in range(N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:
                count += 1
                break


print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=list(map(int,stdin.readline().strip().split()))[0]
st=list(stdin.readline().strip())
count=0
stt=list(set(st))
stt=list(stt)
num=["0","1","2","3","4","5","6","7","8","9"]
num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    cnt = 0
    i=0
    while(i!=N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:
                count += 1
                break
        i+=1


print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=list(map(int,stdin.readline().strip().split()))[0]
st=list(stdin.readline().strip())
count=0
stt=list(set(st))
stt=list(stt)
num=["0","1","2","3","4","5","6","7","8","9"]
num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    cnt = 0
    for i in range(N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:
                count += 1
                break


print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=list(map(int,stdin.readline().strip().split()))[0]
st=list(stdin.readline().strip())
count=0
stt=list(set(st))
num=list(stt)
# num=["0","1","2","3","4","5","6","7","8","9"]
# num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    cnt = 0
    for i in range(N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:
                count += 1
                break


print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=list(map(int,stdin.readline().strip().split()))[0]
st=list(stdin.readline().strip())
count=0
stt=list(set(st))
num=["0","1","2","3","4","5","6","7","8","9"]
num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    cnt = 0
    for i in range(N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:
                count += 1
                break


print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=list(map(int,stdin.readline().strip().split()))[0]
st=list(stdin.readline().strip())
count=0
num=list(set(st))
# num=["0","1","2","3","4","5","6","7","8","9"]
# num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    cnt = 0
    for i in range(N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:
                count += 1
                break


print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=list(map(int,stdin.readline().strip().split()))[0]
st=list(stdin.readline().strip())
count=0
stt=set(st)
stt=list(stt)
num=["0","1","2","3","4","5","6","7","8","9"]
num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    cnt = 0
    for i in range(N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:
                count += 1
                break
    

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=int(input())
st=list(stdin.readline().strip())
count=0
cnt=0
# stt=set(st)
# stt=list(stt)
num=["0","1","2","3","4","5","6","7","8","9"]
#num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    for i in range(N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:
                count += 1
                break
    cnt = 0

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=int(input())
st=list(stdin.readline().strip())
count=0
cnt=0
stt=set(st)
stt=list(stt)
num=["0","1","2","3","4","5","6","7","8","9"]
num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    for i in range(N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:
                count += 1
                break
    cnt = 0
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=int(input())
st=list(stdin.readline().strip())
count=0
cnt=0
stt=set(st)
stt=list(stt)
num=["0","1","2","3","4","5","6","7","8","9"]
num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    for i in range(N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:break

    if cnt==3:
        count+=1
    cnt=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=int(input())
st=list(stdin.readline().strip())
count=0
cnt=0
stt=set(st)
stt=list(stt)
num=["0","1","2","3","4","5","6","7","8","9"]
num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    for i in range(N):
        if number[cnt]==st[i]:
            cnt+=1
            if cnt==3:break
            continue

    if cnt==3:
        count+=1
    cnt=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=int(input())
st=list(stdin.readline().strip())
count=0
cnt=0
stt=set(st)
stt=list(stt)
num=["0","1","2","3","4","5","6","7","8","9"]
num = [s for s in num if s in stt ]
num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    for i in range(N):
        if cnt==0 and number[0]==st[i]:
            cnt+=1
        elif cnt==1 and number[1]==st[i]:
            cnt+=1
        elif cnt==2 and number[2]==st[i]:
            cnt+=1
            break
    if cnt==3:
        count+=1
    cnt=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=int(input())
st=list(stdin.readline().strip())
count=0
cnt=0
num=["0","1","2","3","4","5","6","7","8","9"]

num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    for i in range(N):

        if cnt==0 and number[0]==st[i]:
            cnt+=1
        elif cnt==1 and number[1]==st[i]:
            cnt+=1
        elif cnt==2 and number[2]==st[i]:
            cnt+=1
            break
    if cnt==3:
        count+=1
    cnt=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=int(input())
st=list(stdin.readline().strip())
count=0
cnt=0
num=["0","1","2","3","4","5","6","7","8","9"]

num_list= ["".join(i) for i in itertools.product(num,repeat=3)]

for number in num_list:
    for i in range(N):

        if cnt==0 and number[0]==st[i]:
            cnt+=1
            continue
        if cnt==1 and number[1]==st[i]:
            cnt+=1
            continue
        if cnt==2 and number[2]==st[i]:
            cnt+=1
            break
    if cnt==3:
        count+=1
    cnt=0
print(count)