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:
#D - Lucky PIN
#000～999までそれぞれ作成できるかをチェックする
n=int(input())
s=str(input())
ans = 0
for i in range (0,10):
    for j in range (0,10):
        for k in range (0,10):
            check_i = (s.find(str(i)))
            check_j = (s.find(str(j),check_i))
            check_k = (s.rfind(str(k),check_j))
            if(check_i > 0 and check_j > 0 and check_k >0):
                ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:

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

dp1 = [[0 for i in range(10)] for _ in range(n + 1)]
dp2 = [[0 for i in range(100)] for _ in range(n + 1)]
dp3 = [[0 for i in range(1000)] for _ in range(n + 1)]

for i in range(n):
    dp1[i + 1][int(s[i])] = 1
    for j in range(10):
        if dp1[i][j]:
            dp2[i + 1][j * 10 + int(s[i])] = 1
            dp1[i + 1][j] = 1
            print(i, j, s[i])
    for j in range(100):
        if dp2[i][j]:
            dp3[i + 1][j * 10 + int(s[i])] = 1
            dp2[i + 1][j] = 1
    for j in range(1000):
        if dp3[i][j]:
            dp3[i + 1][j] = 1

print(sum(dp3[n]))

Submission status: Wrong Answer

Solution code:
n=int(input())
y=int(input())
x=str(y)
ans=0
for i in range(0,9):
  k=0
  ss="00"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(10,99):
  k=0
  ss="0"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(100,1000):
  k=0
  ss=str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
 
ans = 0
for i in range(1000):
    a, b, c = map(str, list(str(i).zfill(3)))
    mode = 'a'
    for j in S:
        if mode == 'a' and j == a:
            mode = 'b'
        elif mode == 'b' and j == b:
            mode = 'c'
        elif mode == 'c' and j == c:
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(1000):
    p = str(i).zfill(3)
    p_index = 0
    for j in range(n):
        if p[p_index] == s[j]:
            p_index += 1
        if p_index == 2:
            break
    if p_index == 2:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def ok(target, S):
    for t in target:
        if t in S:
            S = S[S.index(t)+1:]
        else:
            return False
    print(target)
    return True


N = int(input())
S = input()
ans = 0

for i in range(0, 999+1):
    target = str(i).zfill(3)
    ans += ok(target, S)

print(ans)

Submission status: Wrong Answer

Solution code:
def ok(target, S):
    pos = 0
    for t in target:
        if t in S[pos:]:
            pos = S[pos:].index(t)
        else:
            return False
    return True


N = int(input())
S = input()
ans = 0

for i in range(0, 999+1):
    target = str(i).zfill(3)
    ans += ok(target, S)

print(ans)

Submission status: Wrong Answer

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

lst = [[] for _ in range(10)]
for i in range(n):
    lst[int(s[i])].append(i)


done = []
cnt = 0
for i in range(1000):
    tmp = str(i).rjust(3, '0')
    n1,n2,n3 = int(tmp[0]), int(tmp[1]), int(tmp[2])
    mi = -1
    mx = -1
    if len(lst[n1])!=0:
        mi = lst[n1][0]
    if len(lst[n3])!=0:
        mx = lst[n3][-1]
    
    if mi>0 and mx>0:
        for y in lst[n2]:
            if mi<y<mx:
                done.append(tmp)
    else:
        continue
print(len(set(done)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(10):
    for j in range(10):
        for k in range(10):
            hit = 0
            for c in S:
                c_ = int(c)
                if hit == 0 and c == i:
                    hit += 1
                elif hit == 1 and c == j:
                    hit += 1
                elif hit == 2 and c == k:
                    ans += 1
                    break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(int, input()))
stack = []
cnt = 0
check = [0 for i in range(1001)]
for s in S:
    for i in range(len(stack)):
        new = stack[i] * 10 + s
        if check[new] == 0:
            check[new] = 1
            if new >= 100:
                cnt += 1
            else:
                stack.append(new)
    if check[s] == 0:
        check[s] = 1
        stack.append(s)
print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
key=set()
for i in range(N):
    if i>0 and S[i-1]==S[i]:
        break
    for j in range(i+1, N):
        if j>i+1 and S[j-1]==S[j]:
            break
        for k in range(j+1, N):
            if k>j+1 and S[k-1]==S[k]:
                break
            key.add(S[i]+S[j]+S[k])
print(len(key))

Submission status: Wrong Answer

Solution code:
length = int(input())
string = input()

possible_pins = list()
for pin in [str(num) for num in range(1, 1000)]:
    if len(pin) == 1:
        pin = "00" + pin
    elif len(pin) == 2:
        pin = "0" + pin
    possible_pins.append(pin)


count = 0
for pin in possible_pins:
    start = 0
    for letter in pin:
        try:
            index = string.index(letter, start)
            start = index + 1
        except ValueError:
            break
    else:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
cnt=0
for i in range(1000):
  l=(3-len(str(i)))*'0'+str(i)
  if l[0] in s and l[1] in s and l[2] in s and s.index(l[0])<s.index(l[1])<s.index(l[2]):
    cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools

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

p = list(itertools.combinations(S, 3))
print(len(p))

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
def res(n, s):
    arr = []
    for i in range(len(s) - 2):
        for j in range(len(s) - 1):
            for k in range(len(s)):
                if i != j and j !=k and i != k and i < j and i < k and j < k:
                    arr.append((s[i] + s[j] + s[k]))

    return len(list(set(arr)))

if __name__== "__main__":
    n = input()
    s = input()

    res(n, s)

Submission status: Wrong Answer

Solution code:
def res(n, s):
    arr = []
    for i in range(len(s) - 2):
        for j in range(len(s) - 1):
            for k in range(len(s)):
                if i != j and j !=k and i != k and i < j and i < k and j < k:
                    arr.append((s[i] + s[j] + s[k]))

    return len(list(set(arr)))

Submission status: Wrong Answer

Solution code:
N = input()
S = input()
S = list(S)
i = 0
j = 0
k = 0
count = 0
Flag_1 = False
Flag_2 = False
hakken_Flag = False
for a in range(10):
    for b in range(10):
        for c in range(10):
            for i in range(len(S)-2):
                if str(a) == S[i]:
                    Flag_1 = True
                    break

            if Flag_1 == True:
                for j in range(i+1, len(S)-1):
                    if str(b) == S[j]:
                        Flag_2 = True
                        Flag_1 = False
                        break

            if Flag_2 == True:
                for k in range(j+1,len(S)):
                    if str(c) == S[k]:
                        count += 1
                        hakken_Flag = True
                        Flag_2 = False
                        break
                    
                Flag_2 = False

print(count)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
from itertools import combinations as cmb
n=int(input())
s=list(input())
combiset=set(cmb(s,3))
print(len(combiset))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
from itertools import combinations as cmb
n=int(input())
s=set(input())
combiset=set(cmb(s,3))
print(len(combiset))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
from itertools import combinations as cmb
n=int(input())
s=list(input())
sss=[]
for i in s:
    sss.append(i)
combiset=set(cmb(sss,3))
print(len(combiset))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
index = 0
cnt = 0
for i in range(0, 1000):
    if i < 10:
        value = '00' + str(i)
    elif i < 100:
        value = '0' + str(i)
    else:
        value = str(i)
    print(value)
    
    for j in s:
        if value[index] == j:
            index += 1

        if index == 3:
            cnt += 1
            index = 0
            break
    index = 0

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
index = 0
cnt = 0
for i in range(1, 1000):
    if i < 10:
        value = '00' + str(i)
    elif i < 100:
        value = '0' + str(i)
    else:
        value = str(i)

    for j in s:
        if value[index] == j:
            index += 1

        if index == 3:
            cnt += 1
            index = 0
            break
    index = 0

print(cnt)

Submission status: Wrong Answer

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

cnt=0
for i in range(1000):
    key=str(i).zfill(3)
    if key[0] in S:
        idx1=S.index(key[0])
    else:
        continue
    for j in range(idx1+1,L-1):
        if S[j]==key[1]:
            idx2=j
            for k in range(idx2+1,L):
                if S[k]==key[2]:
                    cnt+=1
                    break
                else:
                    continue

print(cnt)

Submission status: Wrong Answer

Solution code:
input1 = 4
input2 = "1235"
inputbox = list(input2)
i=0
count = 0
for i in range(1000):
        c = [int(i/100),int(i/10)%10,i%10]
        f = 0
        for j in inputbox:
            if int(j)==c[f]:
                f=f+1
            if f==3:
                break
        if f==3:
            count = count + 1
            
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=0
tmp=[0]*3
for i in range(0,112):
    tmp[0]=i/100
    tmp[1]=(i/10)%10
    tmp[2]=i%10
    for k in range(0,10):
        tmp[0]*=k
        tmp[1]*=k
        tmp[2]*=k
        cnt = 0
        for j in range(0,len(s)):
            if int(s[j])==int(tmp[cnt]):
                cnt+=1
            if cnt==3:
                break
        if cnt==3:
            ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
b=[]
for i in range(1000):
	while len(str(i))<3:
		i="0"+str(i)
	for j in range(n):
		if str(i)[0]==s[j]:
			for k in range(j+1,n):
				if str(i)[1]==s[k]:
					for l in range(k+1,n):
						if str(i)[2]==s[l]:
							b.append(i)
							print(i)
							break
					break
			break
print(len(set(b)))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
count = 0
f0,f1 = -1,-1
for ans in range(1000):
  ans_str = "{0:03d}".format(ans)
  for i in range(n):
    if s[i] == ans_str[0]:
      f0 = i
      break
  if f0 == -1:
    continue
  for j in range(f0+1,n):
    if s[j] == ans_str[1]:
      f1 = j
      break
  if f1 == -1:
    continue
  for k in range(f1+1,n):
    if s[k] == ans_str[2]:
      count += 1
      #print(s[i],s[j],s[k])
      break
  f0,f1 = -1,-1

print(count)

Submission status: Wrong Answer

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

count = 0
for a in range(10):
    for b in range(10):
        for c in range(10):
            f1 = False
            f2 = False
            p1 = 0
            p2 = 0
            for i in range(0, n-2):
                if int(s[i]) == a:
                    f1 = True
                    p1 = i
                    break
            if f1:
                for j in range(p1+1, n-1):
                    if int(s[j]) == b:
                        f2 = True
                        p2 = j
                        break
            if f2:
                for k in range(p2+1, n):
                    if int(s[k]) == c:
                        count += 1
                        break
            if not f1 or not f2:
                break
    if not f1:
        break
print(count)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n=int(input())
s=input()
li=[[-1]*10 for i in range(n+1)]
for i in range(n):
    li[-i-2]=li[-i-1][:]
    li[-i-2][int(s[-i-1])]=n-1-i
print(li)
ans=0
for i in range(1000):
    tmp=str(i)
    while len(tmp)!=3:
        tmp= "0"+tmp
    now=0
    for j in range(3):
        if li[now][int(tmp[j])]==-1:
            break
        now=li[now][int(tmp[j])]+1
        if j==2:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = input()
M = {X[0:3]:1}
result = {}

for i in range(3,N):
    i = X[i]
    keys = M.keys()
    for j in tuple(keys):
        if (j, i) in result:
            continue
        M[j[0]+j[1]+i] = 1
        M[j[0]+j[2]+i] = 1
        M[j[1]+j[2]+i] = 1
        result[(j,i)] = True
    if len(M) == 729:
      break

print (len(M))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input()
ans=0
for i in range(1000):
    i=str(i).zfill(3)
    x=a.find(i[0])
    y=a[x+1:].find(i[1])
    z=a[y+1:].find(i[2])
    if x!=-1 and y!=-1 and z!=-1:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,S,r=int(input()),input(),0
dp1=[0]*n
dp2=[0]*n
d1=set()
d2=set()
cs=[0]*10
for i in range(n):
    dp1[i] = len(d1)
    d1.add(S[i])
for i in range(n):
    j = n-i-1
    dp2[j] = len(d2)
    r += dp1[i]*(dp2[j]-dp2[cs[int(S[j])]])
    d2.add(S[j])
    cs[int(S[j])] = j
print(r)

Submission status: Wrong Answer

Solution code:
#貪欲法による解法
# 000から999までの数字を作れるを調べる

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

count = 0
V = [0,0,0]
V_cnt  = 0 
dict = {}
while(1):
    if V_cnt > 999:
        break
    for i in range(len(S)):
        if S[i] == V[0] and i_flag == False:
            for j in range(i+1, len(S)):
                if S[j] == V[1] and j_flag == False:
                    for k in range(j+1, len(S)):
                        if S[k] == V[2] and k_flag == False:
                            count += 1
                            #print(S[i] + S[j] + S[k])
                            k_flag = True
                            j_flag = True
                            i_flag = True
    V = list(str(int(''.join([str(n) for n in V])) + 1).zfill(3))
    V_cnt += 1
    i_flag = False
    j_flag = False
    k_flag = False
print(count)

Submission status: Wrong Answer

Solution code:
#貪欲法による解法
# 000から999までの数字を作れるを調べる

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

count = 0
V = [0,0,0]
V_cnt  = 0 
dict = {}
while(1):
    if V_cnt > 999:
        break
    for i in range(len(S)):
        if S[i] == V[0] and i_flag == False:
            for j in range(i+1, len(S)):
                if S[j] == V[1] and j_flag == False:
                    for k in range(j+1, len(S)):
                        if S[k] == V[2] and k_flag == False:
                            count += 1
                            print(S[i] + S[j] + S[k])
                            k_flag = True
                            j_flag = True
                            i_flag = True
    V = list(str(int(''.join([str(n) for n in V])) + 1).zfill(3))
    V_cnt += 1
    i_flag = False
    j_flag = False
    k_flag = False
print(count)

Submission status: Wrong Answer

Solution code:
#貪欲法による解法
# 000から999までの数字を作れるを調べる

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

count = 0
V = [0,0,0]
V_cnt  = 0 
dict = {}
while(1):
    if V_cnt > 999:
        break
    for i in range(len(S)):
        if S[i] == V[0]:
            for j in range(i+1, len(S)):
                if S[j] == V[1]:
                    for k in range(j+1, len(S)):
                        if S[k] == V[2]:
                            if S[i] + S[j] + S[k] not in dict:
                                count += 1
                                #print(S[i] + S[j] + S[k])
                                dict[S[i] + S[j] + S[k]] = 1
    V = list(str(int(''.join([str(n) for n in V])) + 1).zfill(3))
    V_cnt += 1
print(count)

Submission status: Wrong Answer

Solution code:
from string import digits

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

cnt = 0
for i in digits:
    x = s.find(i)
    if x == -1:
        continue
    for j in digits:
        y = s.find(j, x + 1)
        if y == -1:
            continue
        for k in digits:
            z = s.find(k, y + 1)
            if z == -1:
                continue
            cnt += 1

    print(cnt)

Submission status: Wrong Answer

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

count = 0
for p in range(22,1000):
    v = format(p, '03')
    found = False
    pos1 = S.find(v[0])
    if pos1 == -1:
        continue
    pos2 = S[pos1 + 1:].find(v[1])
    if pos2 == -1:
        continue
    pos3 = S[pos1 + pos2 + 2:].find(v[2])
    if pos3 == -1:
        continue
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import itertools
L=int(input())
N=input()
n = list(itertools.combinations(N, 3))
print(set(n))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int, input()))
print(s)
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            preindex = 0
            flag1 = 0
            flag2 = 0
            flag3 = 0 
            while preindex < n:
                if s[preindex] == i:
                    preindex += 1
                    flag1 = 1
                    break
                preindex += 1

            while preindex < n:
                if s[preindex] == j:
                    preindex += 1
                    flag2 = 1
                    break
                preindex += 1

            while preindex < n:
                if s[preindex] == k:
                    flag3 = 1
                    break
                preindex += 1
            if flag1 and flag2 and flag3:
                ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input()) #長さ
s = str(input()) #文字列
cnt = 0 #暗証番号数
 
for a in range(9): #1文字目
  for b in range(9): #2文字目
    for c in range(9): #3文字目
      for i in range(n-3):
        if str(a) == s[i]:
          tmp_i = i + 1
          for j in range(tmp_i,n-2):
            if str(b) == s[j]:
              tmp_i = j + 1
              for k in range(tmp_i,n-1):
                if str(c) == s[k]:
                  cnt = cnt + 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools

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

left_index = [[-1] * (N+1) for _ in range(10)]

for i,x in enumerate(S,1):
	for j in range(10):
		left_index[j][i] = left_index[j][i-1]
	left_index[x][i] = i

for x in range(10):
	print(left_index[x])


answer = 0
for a,b,c in itertools.product(range(10),repeat=3):
	i = N
	bl = True
	for x in [a,b,c]:
		i = left_index[x][i] - 1
		if i < -1:
			bl = False
			break
	if bl:
		answer += 1

print(answer)

Submission status: Wrong Answer

Solution code:
import copy
a=int(input())
b=int(input())
w=b
d=[0]*3
count=0
c=[int(i) for i in str(b)]
for i in range(0,1000,1):
    for j in range(2,-1,-1):
        d[j]=i%10
        i=i//10#ここまでは「０，０，０」とか
    for x in range(len(c)-2):
        if d[0]==c[x]:
            for y in range(x+1,len(c)-1):
                if d[1]==c[y]:
                    for z in range(y+1,len(c)):
                        if d[2]==c[z]:
                            count+=1
                            break
                    break
            break
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            p = [i, j, k]
            idx = 0
            for j in range(n):
                if int(s[j]) == p[idx]:
                    idx += 1
                if idx == 3:
                    break
            if idx == 3:
                ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 000~999で決め打ちして数える
n = int(input())
s = input()
ans = 0
arr = []
cur = ""
for c in s:
    if cur != c:
        cur = c
        arr.append([c, 1])
    else:
        arr[-1][1] += 1
        
for i in range(0, 1000):
    t = format(i, "0>3")
    idx = 0
    for a in arr:
        if a[0] == t[idx]:
            idx += 1
        if idx == 3:
            ans += 1
            break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(str(input()))
ans = 0
import itertools
num = [str(z) for z in range(10)]
lis = list(itertools.product(num,repeat = 3))
for i in range(1000):
  a = lis[i][0]
  b = lis[i][1]
  c = lis[i][2]
  for j in range(0,N):
    if S[j] == a:
      for g in range(j+1,N):
        if S[g] == b:
          for k in range(g+1,N):
            if S[k] == c:
              print(a+b+c)
              ans += 1
  continue
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(int,list(input())))
S_riv=S[::-1]
l_lis=[0]*N
r_lis=[0]*N
mat=([0 for j in range(10)])
l_set=set([])
r_set=set([])
for i,s in enumerate(S):
  l_lis[i]=l_set.copy()
  l_set.add(s)
  
for i,s in enumerate(S_riv):
  r_lis[i]=r_set.copy()
  r_set.add(s)
  
r_lis.reverse()
ans=0
for i,s in enumerate(S):
  length=len(l_lis[i])
  ans+=(length-mat[s])*len(r_lis[i])
  mat[s]=length

Submission status: Wrong Answer

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

def nc(n,s,i,j,k):
    c1 = -1
    for l in range(n):
        if s[l] == i:
            c1 = l
            break
    if c1 == -1:
        return 0
    c2 = -1
    for l in range(n):
        if s[l] == j:
            c2 = l
            break
    if c2 == -1:
        return 0
    c3 = -1
    for l in range(n):
        if s[l] == k:
            c3 = l
            break
    if c3 == -1:
        return 0
    return 1

c = 0
for i in range(10):
        for j in range(10):
            for k in range(10):
                c += nc(n,s,i,j,k)



print(c)

Submission status: Wrong Answer

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

def nc(n,s,i,j,k):
    c1 = -1
    for l in range(n):
        if s[l] == i:
            c1 = l
            break
    if c1 == -1:
        return 0
    c2 = -1
    for l in range(c1+1,n):
        if s[l] == j:
            c2 = l
            break
    if c2 == -1:
        return 0
    c3 = -1
    for l in range(c2+1,n):
        if s[l] == k:
            c3 = l
            break
    if c3 == -1:
        return 0
    print(i,j,k)
    return 1

c = 0
for i in range(10):
        for j in range(10):
            for k in range(10):
                c += nc(n,s,i,j,k)



print(c)

Submission status: Wrong Answer

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

c = 0
for i in range(10):
        for j in range(10):
            for k in range(10):
                count = 0
                for l in s:
                    if count == 3:
                        c += 1
                        break
                    if l == str(k) and count == 2:
                        count += 1
                    if l == str(j) and count == 1:
                        count += 1
                    if l == str(i) and count == 0:
                        count += 1

print(c)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
#print(N,S)

count=0


for n1 in range(10):
 cond=0
 for i in range(N-2):
   if n1==int(S[i]):
      p1=i
      cond=1
      break
 if cond==1:
  for n2 in range(10):
    for j in range(p1+1,N-1):
      if n2==int(S[j]):
        p2=j
        cond=2
        break
    if cond==2:
     for n3 in range(10):
      for k in range(p2+1,N):
        if n3==int(S[k]):
          count+=1
          break
      
              
print(count)

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def main():
    N=int(input())
    S=input()
    
    can = set([""]) ## 2文字以下で現在構築可能な文字列(最大10+10*10 = 1010)
    ans = set() ## 3文字で現在構築可能な文字列(最大10*10*10 = 1,000)
    for s in S: 
        for c in can.copy(): #途中でcanという集合に追加されるのでcopyする
            res = c+s #2文字以下 + 1文字 で結合する
            if len(res) == 3: #3文字なので暗証番号の候補
                ans.add(res)
            elif len(res) < 3: #2文字以下なのでcanに挿入
                can.add(res)
    print(len(ans))

    """
    copyする回数 = N * len(can) <= 10^3 * N
    for文の走査回数 = N * len(can) <= 10^3 * N
    
    全体で  2 * (10^3 * N)
    N<=3*10^4なので
    2*3* 10^3 * 10^4 = 6 * 10^7 -> 間に合わない？んですか・・・？
    """

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
input1 = int(input())
input2 = input()

kesu = input1 - 1
inputbox = list(input2)
li=[0 for _ in range(1000)]

Submission status: Wrong Answer

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


def main():
    N = int(input())
    S = input().strip()
    ans = 0
    for i in range(1000):
        s = "{:03}".format(i)
        a = S.find(s[0])
        b = S.find(s[1], a+1)
        c = S.find(s[2], b+1)
        if c >= 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import math
input = sys.stdin.readline
#sys.setrecursionlimit(1e9)
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def main():
    """code here"""
    N = int(input())
    S = input()
    #print(S)
    ans = 0
    for i in range(10):
        i_pos = S.find(str(i))
        if i_pos == -1:
            continue
        for j in range(10):
            j_pos = S.find(str(j),i_pos)
            if j_pos == -1:
                continue
            for k in range(10):
                k_pos = S.find(str(k),j_pos)
                if k_pos == -1:
                    continue
        ans+=1
    print(ans)

    
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import math
input = sys.stdin.readline
#sys.setrecursionlimit(1e9)
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def main():
    """code here"""
    N = int(input())
    S = input()
    #print(S)
    ans = 0
    for i in range(10):
        i_pos = S.find(str(i))
        if i_pos == -1:
            continue
        for j in range(10):
            j_pos = S.find(str(i),i_pos)
            if j_pos == -1:
                continue
            for k in range(10):
                k_pos = S.find(str(i),j_pos)
                if k_pos == -1:
                    continue
        ans+=1
    print(ans)

    
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

l_S=list(str(S))

count=0
for i in range(0,1000):
    i_1=int(i/100)
    i_2=int(i/10)-i_1*10
    i_3=i%10
    if str(i_1) in l_S[:-2]:
        idx_1=l_S[:-2].index(str(i_1))
        if str(i_2) in l_S[idx_1+1:-1]:
            idx_2=l_S[idx_1+1:-1].index(str(i_2))+idx_1+1
            if str(i_3) in l_S[idx_2+1:]:
                count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import bisect
import collections

def read():
    N = int(input().strip())
    S = str(input().strip())
    return N, S

def dig(S, T, N):
    k0, k1, k2 = -1, -1, -1
    for i in range(N):
        if S[i] == T[0]:
            k0 = i
    if k0 == -1:
        return False
    for i in range(k0+1, N):
        if S[i] == T[1]:
            k1 = i
    if k1 == -1:
        return False
    for i in range(k1+1, N):
        if S[i] == T[2]:
            k2 = i
    if k2 == -1:
        return False
    return True


def solve(N, S):
    d = [collections.deque() for i in range(10)]
    count = 0
    for p in range(1000):
        T = '{:03d}'.format(p)
        count += 1 if dig(S, T, N) else 0
    return count
    
if __name__ == '__main__':
    inputs = read()
    output = solve(*inputs)
    print("%d" % output)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
S = map(int, S)
cnt = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = True
            flag2 = True

            for a in S:
                if flag1:
                    if a == i:
                        flag1 = False
                elif flag2:
                    if a == j:
                        flag2 = False
                elif a == k:
                    cnt += 1
                    break

print(cnt)

Submission status: Wrong Answer

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

from itertools import product

p = product([str(i) for i in range(10)], repeat=3)

ans = 0
for i,j,k in p:
  x = S.find(i)
  if x<0:
    continue
  y = x + S[x+1:].find(j)
  if y<0:
    continue
  z = x + y + S[y+1:].find(k)
  if z<0:
    continue
  ans += 1
print(ans)