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: Wrong Answer

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

ans = 0

for i in range(1, 1000):
  if i < 100:
    i = str(i)
    c = len(i)
    i = '0'*(3-c) + i
  else:
    i = str(i)
  p = 0
  flg = True
  for j in i:
    if p < n and j in s[p:]:
      p += s[p:].index(j) +1
    else:
      flg = False
  if flg == True:
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(10):
  a = s.find(str(i))
  for j in range(10):
    b = s.find(str(j), a+1, n)
    for k in range(10):
      c = s.find(str(k), b+1, n)
    if a == -1 or b == -1 or c == -1:
      continue
    else:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(10):
  a = s.find(str(i))
  for j in range(10):
    b = s.find(str(j), a+1)
    for k in range(10):
      c = s.find(str(k), b+1)
    if a == -1 or b == -1 or c == -1:
      continue
    else:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
num = list(map(int,input()))
num_appere_list = [0 for i in range(10)]
new_num = ""

for i in num:
    if num_appere_list[i] <= 6:
        num_appere_list[i] += 1
        new_num += str(i)


password_list = []

for i in range(len(new_num)-2):
    for j in range(i+1,len(new_num)-1):
        for k in range(j+1,len(new_num)):
            target = new_num[i] + new_num[j] + new_num[k]
            if target not in password_list:
                password_list.append(target)
                

print(len(password_list))

Submission status: Wrong Answer

Solution code:
n = int(input())
num = list(map(int,input()))
num_appere_list = [0 for i in range(10)]
new_num = ""

for i in num:
    if num_appere_list[i] <= 5:
        num_appere_list[i] += 1
        new_num += str(i)


password_list = []

for i in range(len(new_num)-2):
    for j in range(i+1,len(new_num)-1):
        for k in range(j+1,len(new_num)):
            target = new_num[i] + new_num[j] + new_num[k]
            if target not in password_list:
                password_list.append(target)
                

print(len(password_list))

Submission status: Wrong Answer

Solution code:
n = int(input())
num = list(map(int,input()))
num_appere_list = [0 for i in range(10)]
new_num = ""

for i in num:
    if num_appere_list[i] <= 4:
        num_appere_list[i] += 1
        new_num += str(i)


password_list = []

for i in range(len(new_num)-2):
    for j in range(i+1,len(new_num)-1):
        for k in range(j+1,len(new_num)):
            target = new_num[i] + new_num[j] + new_num[k]
            if target not in password_list:
                password_list.append(target)
                

print(len(password_list))

Submission status: Wrong Answer

Solution code:
n = int(input())
num = list(map(int,input()))
num_appere_list = [0 for i in range(10)]
new_num = ""

for i in num:
    if num_appere_list[i] <= 3:
        num_appere_list[i] += 1
        new_num += str(i)


password_list = []

for i in range(len(new_num)-2):
    for j in range(i+1,len(new_num)-1):
        for k in range(j+1,len(new_num)):
            target = new_num[i] + new_num[j] + new_num[k]
            if target not in password_list:
                password_list.append(target)
                

print(len(password_list))

Submission status: Wrong Answer

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

all=[]
for i in range(10):
	for j in range(10):
		for k in range(10):
			all.append(str(i) + str(j) + str(k))

output=0
for i in range(n):
	tmps=s[i]
	
	for j,x in enumerate(all):
		if x[0] == tmps:
			if len(x)==1:
				all.remove(x)
				output += 1
			else:
				all[j] = x[1:]

print(output)

Submission status: Wrong Answer

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

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

ans = 0
for i in range(1000):
    pw = list("{0:03d}".format(i))

    if pw[0] in S:
        w1 = S.index(pw[0])
        if pw[1] in S[w1+1:]:
            w2 = S.index(pw[1])
            if pw[2] in S[w2+1:]:
                ans += 1

print(ans)

Submission status: Wrong Answer

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

ans = 0

for i in range(1000):
  if i < 10:
    s = '00' + str(i)
  elif i < 100:
    s = '0' + str(i)
  else:
    s = str(i)
    
  for j in range(N):
    if S[j] == s[0]:
      for k in range(j+1,N):
        if S[k] == s[1]:
          for l in range(k+1,N):
            if S[l] == s[2]:
              ans += 1
              pass
print(ans)

Submission status: Wrong Answer

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

ans = 0

for i in range(1000):
  if i < 10:
    s = '00' + str(i)
  elif i < 100:
    s = '0' + str(i)
  else:
    s = str(i)
    
  for j in range(N):
    if S[j] == s[0]:
      for k in range(j+1,N):
        if S[k] == s[1]:
          for l in range(k+1,N):
            if S[l] == s[2]:
              ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline

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

cnt = 0
for i in range(1000):
    si = str(i).zfill(3)
    k = 0
    for cn in range(n):
        if s[cn] == si[k]:
            if k == 2:
                cnt += 1
                break
            else:
                k += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
s = int(input())
ans = []
for i in itertools.combinations(str(s), 3):
  ans.append(i)
print(len(set(ans)))

Submission status: Wrong Answer

Solution code:
N = input()
S = list(input())
ans = set()
num_count = [0]*10
i = 0
while i < len(S):
    s_num = int(S[i])
    if num_count[s_num] <= 3:
        num_count[s_num] += 1
        i += 1
    else:
        S.pop(i)
for i in range(len(S)-2):
    for j in range(i+1, len(S)-1):
        for k in range(j+1, len(S)):
            s = S[i]+S[j]+S[k]
            if s not in ans:
                ans.add(s)
print(len(ans))

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

n = int(readline())
s = readline().rstrip()

from collections import deque
q = deque([])

for i in range(10):
    q.append(["",0,str(i)])

ans = 0
while q:
    num, ind, target = q.popleft()
    print(num, ind, target)
    while ind < len(s):
        if s[ind] == target: #s[ind]が０から9の中のどれかを見てる
            break
        ind += 1
    else:
        continue
    num += target
    if len(num) == 3:
        ans += 1
        continue
    for i in range(10):
        q.append([num, ind +1, str(i)]) #出現した数字に関するキューを追加（例：一回目は024）

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
pws = []
for n1 in range(N - 2):
    pw1 = S[n1]
    if pw1 in S[0:n1]:
        continue
    else:
        for n2 in range(n1 + 1, N - 1):
            pw2 = S[n2]
            if pw2 in S[1: n2]:
                continue
            else:
                for n3 in range(n2 + 1, N):
                    pw3 = S[n3]
                    if pw3 in S[2: n3]:
                        continue
                    else:
                        pw = pw1 + pw2 + pw3
                        pws.append(pw)

print(len(pws))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(int, input()))
ans = 0
first = [0] * 10
a = 0
for i in range(N):
  if first[S[i]] == 0:
    first[S[i]] = 1
    a += 1
    second = [0] * 10
    b = 0
    for j in range(i+1, N):
      if second[S[j]] == 0:
        second[S[j]] = 1
        b += 1
        third = [0] * 10
        c = 0
        for k in range(j+1, N):
          if third[S[k]] == 0:
            third[S[k]] = 1
            ans += 1
            c += 1
            if c == 10:
              break
        if b == 10:
          break
      if a == 10:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
x = input()
S = input()
def search(x,S):
  ret = set()
  for i in range(len(S)-2):
    if S[i] == x[0]:
      for j in range(i+1,len(S)-1):
        if S[j] == x[1]:
          for k in range(j+1,len(S)):
            if S[k] == x[2]:
              ret.add(x)
  return ret
ans = set()
for i in range(1,1000):
  if len(str(i))<2:
    fig = '00'+str(i)
  elif len(str(i))<3:
    fig = '0'+str(i)
  else:
    fig = str(i)
  ret = search(fig,S)
  ans = ans|ret
print(len(ans))

Submission status: Wrong Answer

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    N = intinput()
    S = input()
    # org = [i for i in set(S)]
    # ans_set = []
    # org.sort()
    # for c in org:
    #     for cc in org:
    #         for ccc in org:
    #             ans_set.append(c+cc+ccc)
    # b = [None] * len(S)
    # b[0] = set()
    # for i in range(1, len(S)):
    #     b[i] = set(S[i:])
    ans_set = []
    pset = [str(i) for i in range(10)]
    for p1 in pset:
        for p2 in pset:
            for p3 in pset:
                ans_set.append(p1+p2+p3)
    cnt = 0
    last = len(S)
    for ans in ans_set:
        f, s, t = ans[0], ans[1], ans[2]
        fidx, sidx, tidx = -1, -1, -1
        is_hit = False
        for i in range(last):
            if fidx < 0:
                if S[i] == f:
                    fidx = i
                continue
            if sidx < 0:
                if S[i] == s:
                    sidx = i
                if i == last-1:
                    break
                continue
            if tidx < 0:
                if S[i] == t:
                    is_hit = True
                    print(ans)
                    break
        if is_hit:
            cnt += 1
    # 出力
    print(cnt)

Submission status: Wrong Answer

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    N = intinput()
    S = input()
    # org = [i for i in set(S)]
    # ans_set = []
    # org.sort()
    # for c in org:
    #     for cc in org:
    #         for ccc in org:
    #             ans_set.append(c+cc+ccc)
    # b = [None] * len(S)
    # b[0] = set()
    # for i in range(1, len(S)):
    #     b[i] = set(S[i:])
    ans_set = []
    pset = [str(i) for i in range(10)]
    for p1 in pset:
        for p2 in pset:
            for p3 in pset:
                ans_set.append(p1+p2+p3)
    cnt = 0
    last = len(S)
    for ans in ans_set:
        f, s, t = ans[0], ans[1], ans[2]
        fidx, sidx, tidx = -1, -1, -1
        is_hit = False
        for i in range(last):
            if fidx < 0 and S[i] == f:
                fidx = i
                continue
            elif sidx < 0 and  S[i] == s:
                sidx = i
                if i == last-1:
                    break
                continue
            elif tidx < 0 and  S[i] == t:
                is_hit = True
                break
        if is_hit:
            cnt += 1
    # 出力
    print(cnt)

Submission status: Wrong Answer

Solution code:
import copy
import math
import time

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    start = time.time()

    n = get_int()
    s_list = get_string_char_list()
    s_list = [int(x) for x in s_list]

    n = 30000
    s_list = [1] * 30000

    #ans_set = set([])

    #for i in range(0,n):
    #    for ii in range(i+1, n):
    #        for iii in range(ii+1, n):
    #            ans_set.add(int(s_list[i]) * 100 + int(s_list[ii]) * 10 + int(s_list[iii]) * 1)

    #print(len(ans_set))

    ans = 0

    for i in range(0, 1000):
        a = i // 100
        b = (i % 100) // 10
        c = i % 10

        find_a = False
        find_b = False
        for ii in s_list:

            if (find_a == False) and (ii == a):
                find_a = True
            elif (find_a == True) and (find_b == False) and (ii == b):
                find_b = True
            elif (find_b == True) and (ii == c):

                ans += 1
                break
    print(ans)

    #print(time.time() - start)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy
import math
import time

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    start = time.time()

    n = get_int()
    s_list = list(str(input()))

    #n = 30000
    #s_list = [1] * 30000

    #ans_set = set([])

    #for i in range(0,n):
    #    for ii in range(i+1, n):
    #        for iii in range(ii+1, n):
    #            ans_set.add(int(s_list[i]) * 100 + int(s_list[ii]) * 10 + int(s_list[iii]) * 1)

    #print(len(ans_set))

    ans = 0

    for i in range(0, 1000):
        a = i // 100
        b = (i % 100) // 10
        c = i % 10

        find_a = False
        find_b = False
        for ii in s_list:
            if (find_a == False) and (ii == a):
                find_a = True
            elif (find_a == True) and (find_b == False) and (ii == b):
                find_b = True
            elif (find_b == True) and (ii == c):
                ans += 1
                break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy
import math
import time

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    start = time.time()

    n = get_int()
    s_list = list(str(input()))

    n = 30000
    s_list = [1] * 30000

    #ans_set = set([])

    #for i in range(0,n):
    #    for ii in range(i+1, n):
    #        for iii in range(ii+1, n):
    #            ans_set.add(int(s_list[i]) * 100 + int(s_list[ii]) * 10 + int(s_list[iii]) * 1)

    #print(len(ans_set))

    ans = 0

    for i in range(0, 1000):
        a = i // 100
        b = (i % 100) // 10
        c = i % 10

        find_a = False
        find_b = False
        for ii in s_list:
            if (find_a == False) and (ii == a):
                find_a = True
            elif (find_a == True) and (find_b == False) and (ii == b):
                find_b = True
            elif (find_b == True) and (ii == c):
                ans += 1
                break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
ans = 0
def count_match(first, second, third):
    cnt = 0
    for i in range(N):
        if S[i]==first:
            cnt += 1
            for j in range(i+1, N):
                if S[j]==second:
                    cnt += 1
                    for k in range(j+1, N):
                        if S[k]==third:
                            cnt += 1
                            return cnt
    return 0



if __name__ == '__main__':
    N = int(input())
    S = list(map(int, list(input())))
    T = S[:7]
    for i in range(10):
        for j in range(10):
            for k in range(10):
                if i not in T: continue
                if j not in T: continue
                if k not in T: continue
                cnt = count_match(i, j, k)
                if cnt==3:
                    ans += 1
    
    print(ans)

Submission status: Wrong Answer

Solution code:
ans = 0
def count_match(first, second, third):
    cnt = 0
    for i in range(N):
        if S[i]==first:
            cnt += 1
            for j in range(i+1, N):
                if S[j]==second:
                    cnt += 1
                    for k in range(j+1, N):
                        if S[k]==third:
                            cnt += 1
                            return cnt
    return 0



if __name__ == '__main__':
    N = int(input())
    S = list(map(int, list(input())))

    fst = S
    print(fst)
    for n in range(0, 999+1):
        first = n//100
        if first not in fst:
            continue
        second = n//10-(first*10)
        if second not in fst:
            continue
        third = n%10
        if third not in fst:
            continue
        cnt = count_match(first, second, third)
        if cnt==3:
            ans += 1
    
    print(ans)

Submission status: Wrong Answer

Solution code:
ans = 0
def count_match(first, second, third):
    cnt = 0
    for i in range(N):
        if S[i]==first:
            cnt += 1
            for j in range(i+1, N):
                if S[j]==second:
                    cnt += 1
                    for k in range(j+1, N):
                        if S[k]==third:
                            cnt += 1
                            return cnt
    return 0



if __name__ == '__main__':
    N = int(input())
    S = list(map(int, list(input())))
    f = S[0]
    s = S[1]
    t = S[2]
    z = S[3]
    fst = (f, s, t, z) 
    for n in range(0, 999+1):
        first = n//100
        if first not in fst:
            continue
        second = n//10-(first*10)
        third = n%10
        cnt = count_match(first, second, third)
        if cnt==3:
            ans += 1
    
    print(ans)

Submission status: Wrong Answer

Solution code:
ans = 0
def count_match(first, second, third):
    cnt = 0
    for i in range(N):
        if S[i]==first:
            cnt += 1
            for j in range(i+1, N):
                if S[j]==second:
                    cnt += 1
                    for k in range(j+1, N):
                        if S[k]==third:
                            cnt += 1
                            return cnt
    return 0



if __name__ == '__main__':
    N = int(input())
    S = list(map(int, list(input())))
    f = S[0]
    s = S[1]
    t = S[2]
    fst = (f, s, t) 
    for n in range(0, 999+1):
        first = n//100
        if first not in fst:
            continue
        second = n//10-(first*10)
        third = n%10
        cnt = count_match(first, second, third)
        if cnt==3:
            ans += 1
    
    print(ans)

Submission status: Wrong Answer

Solution code:

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

ans = 0
for n in range(1001):
    target = "{:03}".format(n)
    j = 0
    for i in range(N):
        if S[i] == target[j]:
            j += 1
        if j == 3:
            ans += 1
            break

print(ans)

Submission status: Wrong Answer

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

cnt = 0
for i in range(1, 1000):
    if(i > int(S)):
        break
    if(i <= 9):
        num = "00"+str(i)
    elif(9 < i <= 99):
        num = "0"+str(i)
    else:
        num = str(i)

    idx = -1
    tmp = 0
    flg = True
    for ch in num:
        if(S.find(ch, idx+1) >= 0):
            tmp = S.find(ch, idx+1)
            if(idx <= tmp):
                idx = tmp
            else:
                flg = False
                break
        else:
            flg = False
            break
                
    if(flg):
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
import collections
import fractions
import itertools
import functools
import operator

def firstnum(s):
    n = len(s)
    res = [[n]*10 for _ in range(n+1)]
    for i in range(n-1, -1, -1):
        for j in range(10):
            res[i][j] = res[i+1][j]
            res[i][int(s[i])] = i
    return res

def solve():
    n = int(input())
    s = input()
    next = firstnum(s)
    dp = [[n]*4 for _ in range(n+1)]
    for i in next:
        print(i)
    dp[0][0] = 1
    for i in range(n):
        for k in range(3):
            for j in range(10):
                if next[i][j] >= n:
                    continue
                dp[next[i][j]+1][k+1] += dp[i][k]
    sushi = 0
    for i in dp:
        sushi += i[3]
    print(sushi)
    return 0

if __name__ == "__main__":
    solve()