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()
code = [[-1,-1,-1] for i in range(1000)]

for i in range(n):
    si = int(s[i])
    for j in range(100):
        if code[j*10+si][1] < i and code[j*10+si][1] > -1 and code[j*10+si][2] == -1:
            code[j*10+si][2] = i
            #print(i,j*10+si,2)
        if code[si*100+j][0] == -1:
            code[si*100+j][0] = i
            #print(i,si*100+j,0)
        if code[(j//10)*100+si*10+j%10][0] < i and code[(j//10)*100+si*10+j%10][0] > -1 and code[(j//10)*100+si*10+j%10][1] == -1:
            code[(j//10)*100+si*10+j%10][1] = i
            #print(i,(j//10)*100+si*10+j%10,1)

ans = 0
for i in range(1000):
    if code[i][2] > -1:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
lst = [str(a) + str(b) + str(c) for a in range(10) for b in range(10) for c in range(10)]

count = 0
for num in lst:
    pos = 0
    for tmp in s:
        if num[pos] == tmp:
            pos += 1
            if pos == 3:
                count += 1
                break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools


N = int(input())
S = input()
A = set(itertools.combinations(S, 3))
print(len(A))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cnt = 0
for i in range(1000):
    c = [str(i // 100), str((i // 10) % 10), str(i % 10)]
    t = 0
    for j in range(n):
        if s[j]==c[t]:
            t+=1
        if t==3:
            cnt+=1
            break
print(cnt)

Submission status: Time Limit Exceeded

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

pin = [str(i).zfill(3) for i in range(1000)]

ans = 0
for i in pin:
    c = 0
    for j in s:
        if j == i[c]:
            c += 1
        if c == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

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

pin = []
for i in range(1000):
    i = str(i)
    if len(i) == 1:
        i = '00' + i
    elif len(i) == 2:
        i = '0' + i
    pin.append(i)

ans = 0
for i in pin:
    c = 0
    for j in s:
        if j == i[c]:
            c += 1
        if c == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
s=s0()

a=[0]*1000
for i in range(1000):
    num=str(i).zfill(3)
    j=0
    for x in s:
        if x==num[j]:
            j+=1
        if j==3:
            a[i]=1
            break
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
s=s0()

import itertools
print(len(set(itertools.combinations(s,3))))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(str(input()))
used = [0]*1000
count = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      if used[int(S[i]+S[j]+S[k])] == 0:
        count += 1
        used[int(S[i]+S[j]+S[k])] = 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1000):
  pin = str(i).zfill(3)
  cursor = 0
  for c in s:
    if c == pin[cursor]:
      cursor += 1
    if cursor == 3:
      ans += 1
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    from sys import stdin
    n = int(stdin.readline().rstrip())
    s = list(map(int,list(stdin.readline().rstrip())))
    ans=0
    for i in range(1000):
        tap = (i//100,(i//10)%10,i%10)
        flag = 0
        for p in s:
            if flag == 0:
                if p==tap[0]:
                    flag = 1
            elif flag == 1:
                if p==tap[1]:
                    flag = 2
            elif flag == 2:
                if p==tap[2]:
                    flag = 0
                    ans+=1
                    break
    
    print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    from sys import stdin
    import itertools
    n = int(stdin.readline().rstrip())
    s = str(stdin.readline().rstrip())
    g = set({})

    for key in itertools.combinations(s,3):
        g.add(key)
    
    print(len(g))
main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

def main():
    n = int(input())
    s = [int(i) for i in input()]
    candidate = []
    for c in combinations(s, 3):
        if c not in candidate:
            candidate.append(c)
    print(len(candidate))
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

for i in range(1000):
    one = str(i//100)
    two = str(i%100//10)
    three = str(i%10)
    
    flg1 = False 
    flg2 = False
    flg3 = False
    
    ptr = 0
    
    for j in range(ptr,n-2):
        if s[j] == one:
            flg1 = True
            ptr = j + 1
            break
    for j in range(ptr,n-1):
        if s[j] == two:
            flg2 = True
            ptr = j + 1
            break
    for j in range(ptr,n):
        if s[j] == three:
            flg3 = True
            ptr = j + 1
            break
    if (flg1 and flg2 and flg3):
        res +=1
        
print(res)

Submission status: Time Limit Exceeded

Solution code:
agg =set()

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


for i in range(n-2):
    for j in range(i + 1, n-1):
        for k in range(j + 1,n):
            agg.add(s[i]+s[j]+s[k])
print(len(agg))

Submission status: Time Limit Exceeded

Solution code:
import sys
readline = sys.stdin.readline
# intin = map( int, readline().rstrip().split() )

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

ans = 0
for x in range(0,1000):
    x = str(x)
    if len(x) == 1:
        x = "00" + x
    elif len(x) == 2 :
        x = "0" + x
    index = 0
    for s in S:
        if x[index] == s:
            index += 1
        if index == 3:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(10):
    for x in range(n):
        if (i==int(s[x])):
            for j in range(10):
                for y in range(x+1,n):
                    if (j==int(s[y])):
                        for k in range(10):
                            for z in range(y+1,n):
                                if (k==int(s[z])):
                                    ans += 1
                                    break
                        break
            break
        

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n = int(input())
s = input()
ans = 0
for i in range(0, 1000):
    # 暗証番号の候補
    num = str(i).zfill(3)

    # numを生成するのが可能かどうか判定
    ok_a = False
    ok_b = False
    ok_c = False
    a, b, c = num[0], num[1], num[2]
    for j in s:
        if not ok_a:
            if j == a:
                ok_a = True
        elif not ok_b:
            if j == b:
                ok_b = True
        elif not ok_c:
            if j == c:
                ok_c = True
                break
    if ok_c:
        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):
            search = i
            c = 0
            for l in range(n):
                if (search==int(s[l])):
                    if (c==0):
                        search = j
                        c = 1
                        
                    elif (c==1):
                        search = k
                        c = 2
                        
                    else:
                        #print(i,j,k)
                        ans += 1
                        break
print(ans)

Submission status: Time Limit Exceeded

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

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

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

ans = 0
for xxx in range(1000):
  x = str(xxx).zfill(3)
  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: 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):
      lst = [i,j,k]
      flag = 0
      for l in range(n):
        if int(s[l]) == lst[flag]:
          flag += 1
          if flag == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(1000):
	cur=str(i).zfill(3)
	now=0
	for j in s:
		if(j==cur[now]):
			now+=1
			if(now==3):
				ans+=1
				break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
N = int(input())
S = input()
S = [int(s) for s in S]
ans = 0
for q in product(range(10),repeat=3):
    i = 0
    for s in S:
        if s==q[i]:
            if i==2:
                ans += 1
                break
            else:
                i+=1
print (ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
N = int(input())
S = input()
ans = 0
for q in product(range(10),repeat=3):
    i = 0
    for s in S:
        if s==str(q[i]):
            if i==2:
                ans += 1
                break
            else:
                i+=1
print (ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
S = input()
print (len(set(combinations(S,3))))

Submission status: Time Limit Exceeded

Solution code:
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN

import sys


def main():
    N = int(input())  # 桁数
    S = str(input())
    
    ans = set()
    
    for i in range(0, N - 2):
        for j in range(i + 1, N - 1):
            for k in range(j + 1, N):
                code = S[i] + S[j] + S[k]
                ans.add(code)
    
    print(len(ans))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN

import sys

N = int(input())  # 桁数
S = str(input())

ans = set()

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

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

Submission status: Time Limit Exceeded

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(i)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

res = set()
for i in itertools.combinations(S, 3):
    if i in res:
        continue
    else:
        res.add(i)
print(len(res))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

res = set()
for i in itertools.combinations(S, 3):
    if i in res:
        continue
    else:
        res.add(i)
print(len(res))

Submission status: Time Limit Exceeded

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left

#======================================================#

def main():
    n = II()
    s = IS()
    def check(A):
        for i in range(n-2):
            if s[i] == A[0]:
                for j in range(i+1, n-1):
                    if s[j] == A[1]:
                        for k in range(j+1, n):
                            if s[k] == A[2]:
                                return 1
        return 0

    def dfs(A):
        if len(A) == 3:
            return check(A)
        res = 0
        for v in range(10):
            A.append(str(v))
            res += dfs(A)
            A.pop()
        return res
    print(dfs([]))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

ans = []
ans2=0
import itertools
for i in itertools.combinations(s, 3):
    if len(i) <=1000:
        if list(i) not in ans:
            ans.append(list(i))
    else:
        ans2=1000
        break
print(max(len(ans), ans2))

Submission status: Time Limit Exceeded

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
            for i in range(0,n-2):
                if p==s[i]:
                    for j in range(i+1,n-1):
                        if q==s[j]:
                            for k in range(j+1,n):
                                if r==s[k]: 
                                    count+=1
                                    flag=True
                                    break
                        if flag: break
                if flag: break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
count=0
for p in range(10):
    for q in range(10):
        for r in range(10):
            flag=False
            for i in range(0,n-2):
                if p==int(s[i]):
                    for j in range(i+1,n-1):
                        if q==int(s[j]):
                            for k in range(j+1,n):
                                if r==int(s[k]): 
                                    count+=1
                                    flag=True
                                    break
                        if flag: break
                if flag: break
print(count)

Submission status: Time Limit Exceeded

Solution code:

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

pin=set()
for i in range(0,1000):
    yn=""
    stri=format(i,"03d")
    for ii in range(n-2):
        if stri[0]==s[ii]:
            yn="yes1"
            break
    if yn!="yes1":
        continue
    for iii in range(ii+1,n-1):
        if stri[1]==s[iii]:
            yn="yes2"
            break
    if yn!="yes2":
        continue
    if stri[2] in s[iii+1:n]:
        pin.add(stri)

print(len(pin))

Submission status: Time Limit Exceeded

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

pin=set()
for i in range(0,1000):
    yn=""
    stri=format(i,"03d")
    for ii in range(n-2):
        if stri[0]==s[ii]:
            yn="yes1"
            break
    if yn!="yes1":
        continue
    for iii in range(ii+1,n-1):
        if stri[1]==s[iii]:
            yn="yes2"
            break
    if yn!="yes2":
        continue
    for iiii in range(iii+1,n):
        if stri[2]==s[iiii]:
            yn="yes3"
            break
    if yn=="yes3":
        pin.add(stri)

print(len(pin))

Submission status: Time Limit Exceeded

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

pin=set()
for i in range(0,1000):
    yn=""
    stri=format(i,"03d")
    for ii in range(n-2):
        if stri[0]!=s[ii]:
            continue
        else:
            yn="yes1"
            break
    if yn!="yes1":
        yn="no"
        continue
    for iii in range(ii+1,n-1):
        if stri[1]!=s[iii]:
            continue
        else:
            yn="yes2"
            break
    if yn!="yes2":
        yn="no"
        continue
    for iiii in range(iii+1,n):
        if stri[2]!=s[iiii]:
            continue
        else:
            yn="yes3"
            break
    if yn=="yes3":
        pin.add(stri)
    else:
        continue

print(len(pin))

Submission status: Time Limit Exceeded

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

l = []
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            l.append(s[i]+ s[j]+s[k])

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = [i for i in input()]
p = set()
for v in itertools.combinations(s, 3):
  if v[0]+v[1]+v[2] not in p:
    p.add(v[0]+v[1]+v[2])
print(len(p))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = [i for i in input()]
p = set()
for v in itertools.combinations(s, 3):
    p.add(v[0]+v[1]+v[2])
print(len(p))

Submission status: Time Limit Exceeded

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

# 暗証番号は 000-999 の最大1000種類

ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    # print(v)
    n = 0
    f = [False] * N
    for j in range(len(S)):
        if v[n] == S[j]:
            n += 1
        if n >= 3:
            # print(v)
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

d = [0]*1000
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            d[int(s[i])*100+int(s[j])*10+int(s[k])] = 1

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=str(input())
import itertools
ans = set(itertools.combinations(s, 3))
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
S = input()
S_list = []
for i in range(len(S)):
    S_list.append(S[i])

comb_S_list = set(itertools.combinations(S_list,3))

print(len(comb_S_list))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
S = input()
S_list = []
for i in range(len(S)):
    S_list.append(S[i])

comb_S_list = list(itertools.combinations(S_list,3))

print(len(set(comb_S_list)))

Submission status: Time Limit Exceeded

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

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

result = list(set(candidate))
ans = len(result)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
s = input()

print(len(set(combinations(s, 3))))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = []
import itertools
for i in itertools.combinations(s, 3):
    if list(i) not in ans:
        ans.append(list(i))
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
pw_set = set()
pw_set.add(s[:3])
for i in s[3:]:
  pw_set2 = set()
  for pw in pw_set:
    pw_set2.add(pw[0] + pw[1] + i)
    pw_set2.add(pw[0] + pw[2] + i)
    pw_set2.add(pw[1] + pw[2] + i)
  pw_set |= pw_set2
print(len(pw_set))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
S = input()
res = list(combinations(S, 3))

res2 = []
for i in res:
  if i not in res2:
    res2.append(i)
print(len(res2))

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

Submission status: Time Limit Exceeded

Solution code:
import re
N = int(input())
S = input()
ans = 0
tmp = [[m.start() for m in re.finditer(str(i), S)] for i in range(10)]
for i in range(10):
  if len(tmp[i]) == 0:
    continue
  for j in range(10):
    if len(tmp[j]) == 0:
      continue
    for k in range(10):
      if len(tmp[k]) == 0:
        continue
      l = tmp[i][0]
      r = tmp[k][-1]
      for m in range(l+1, r):
        if m in tmp[j]:
          ans += 1
          break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
lst = [0] * 1000
for i in range(1000):
    if len(str(i)) == 1:
        tmp = '00' + str(i)
        lst[i] = tmp
    elif len(str(i)) == 2:
        tmp = '0' + str(i)
        lst[i] = tmp
    else:
        lst[i] = str(i)

cnt = 0
for v in lst:
    flag = False
    first_key = v[0]
    for i in range(len(s)):
        if s[i] == first_key:
            second_key = v[1]
            for j in range(i + 1, len(s)):
                if s[j] == second_key:
                    third_key = v[2]
                    for k in range(j + 1, len(s)):
                        if s[k] == third_key:
                            flag = True
    if flag:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
s = input()
lst = [0] * 1000
for i in range(1000):
    if len(str(i)) == 1:
        tmp = '00' + str(i)
        lst[i] = tmp
    elif len(str(i)) == 2:
        tmp = '0' + str(i)
        lst[i] = tmp
    else:
        lst[i] = str(i)



com = list(combinations(s, 3))
com = list(set([''.join(x) for x in com]))
cnt = 0
for x in lst:
    if x in com:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# D - Lucky PIN
import itertools
 
N = int(input())
S = str(input())
 
# 文字列Sから3文字選ぶ組み合わせを数え上げるとTLE
# 暗証番号の組み合わせが高々1,000通りしかないので、
# それごとに条件に該当するかをチェックしてカウントする。
ans = 0
for i, j, k in itertools.product(range(10),repeat=3):
    # i, j, kの組み合わせが起き得るか
    chk = str(i)+str(j)+str(k)
    idx = 0
    for l in range(N):
        if S[l]==chk[idx]:
            idx += 1
            if idx == 3:
                ans += 1
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# D - Lucky PIN
import itertools

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

# 文字列Sから3文字選ぶ組み合わせを数え上げるとTLE
# 暗証番号の組み合わせが高々1,000通りしかないので、
# それごとに条件に該当するかをチェックしてカウントする。
ans = 0
for i, j, k in itertools.product(range(10),repeat=3):
    # i, j, kの組み合わせが起き得るか
    chk = str(i)+str(j)+str(k)
    idx = 0
    for s in S:
        if s==chk[idx]:
            idx += 1
            if idx == 3:
                ans += 1
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# D - Lucky PIN

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

# 文字列Sから3文字選ぶ組み合わせを数え上げるとTLE
# 暗証番号の組み合わせが高々1,000通りしかないので、
# それごとに条件に該当するかをチェックしてカウントする。
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            # i, j, kの組み合わせが起き得るか
            chk = str(i)+str(j)+str(k)
            idx = 0
            for s in S:
                if s==chk[idx]:
                    idx += 1
                    if idx == 3:
                        ans += 1
                        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# D - Lucky PIN

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

# 文字列Sから3文字選ぶ組み合わせを数え上げる

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:
from itertools import combinations

N = int(input())
S = input()
se = set()
for i, j, k in combinations(range(N), 3):
    se.add(S[i] + S[j] + S[k])
print(len(se))