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

Solution (Python):
N=int(input())
s=input()
PIN=[]
firs=[]
sec=[]
thir=[]
for i in range(N-2):
    if s[i] not in firs:
        firs.append(s[i])
        for j in range(i+1,N-1):
            if s[j] not in sec:
                sec.append(s[j])
                for k in range(j+1,N):
                    if s[k] not in thir:
                        thir.append(s[k])
                        PIN.append(s[i]+s[j]+s[k])
                thir=[]
        sec=[]       
print(len(PIN))

Solution (Python):
import math
import sys

n1=set()
n2=set()
n3=set()

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


for i in range(len(S)):
    s = S[i]
    
    for s2 in n2:
        s3 = s2 + s
        if s3 not in n3:
            n3.add(s3)
    for s1 in n1:
        s2 = s1 + s
        if s2 not in n2:
            n2.add(s2)
    if s not in n1:
        n1.add(s)
    
print(len(n3))

Solution (Python):
def solve():
    N = int(input())
    S = input()

    cnt = 0
    for i in range(1000):
        target = str(i).zfill(3)
        idx = 0
        for ch in S:
            if ch == target[idx]:
                idx += 1
                if idx == 3:
                    cnt += 1
                    break
    
    print(cnt)

if __name__ == '__main__':
    solve()

Solution (Python):

import copy

N=input()
S=raw_input()

center_kouho=set()

for i,x in enumerate(S):
    if i==0 or i==N-1: continue
    center_kouho.add(x)

left=[ set() for _ in range(N) ]
right=[ set() for _ in range(N) ]
for i in range(N):
    if i==0:
        continue
    else:
        left[i]=copy.deepcopy(left[i-1])
        left[i].add(S[i-1])

for i in range(N-1,-1,-1):
    if i==N-1:
        continue
    else:
        right[i]=copy.deepcopy(right[i+1])
        right[i].add(S[i+1])

ans=0

for center in center_kouho:
    kazoeage=set()
    for i,x in enumerate(S):
        if x==center:
            for l in left[i]:
                for r in right[i]:
                    kazoeage.add(l+center+r)
    ans+=len(kazoeage)

print ans

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

rr = {}
r = set()
for i in range(len(s) - 1, 0, -1):
    t = s[i]
    r.add(t)
    rr[i] = r.copy()

a = [[set() for j in range(10)] for i in range(10)]
l = set()
for i in range(1, len(s) - 1):
    t = s[i]
    l.add(s[i-1])
    r = rr[i+1]
    for j in l:
        a[t][j] |= r

ans = 0
for b in a:
    for c in b:
        ans += len(c)
print(ans)

Solution (Python):
from itertools import combinations, permutations
from bisect import bisect_right, bisect_left

def solve(N, S):
    left = [-1]*10
    right = [-1]*10
    place = [[] for i in range(10)]
    for i in range(N):
        c = int(S[i])
        if left[c] == -1:
            left[c] = i
        right[c] = i
        place[c].append(i)

    def ok(s, dbg=False):
        l, m, r = [int(c) for c in s]
        if left[l] == -1 or right[r] == -1:
            return False
        if not left[l] < right[r]:
            return False
        j = bisect_right(place[m], left[l])
        if j == len(place[m]):
            return False
        mid = place[m][j]
        if mid < right[r]:
            
            
            return True
        return False

    count = 0
    for i in range(0, 1000):
        s = "%03d" % i
        if ok(s):
            count += 1
    

    return count

def check(N, S):
    c = set()
    for s in combinations(range(N), 3):
        s = tuple(S[i] for i in s)
        
        if s not in c:
            pass
        c.add(s)
        
    return len(c)

def main():
    N = int(input())
    S = input()
    
    print(solve(N, S))

def test(S):
    print(S,check(len(S), S), "==", solve(len(S), S))




main()

Solution (Python):
import bisect





def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return True
    return False




def resolve():
    N=int(input())
    s=[int(i) for i in input()]
    dpt3=[False for i in range(1000)]    
    dpt2=[]
    dpt1=[]
    bisect.insort(dpt1,s[0])
    bisect.insort(dpt1,s[1])
    bisect.insort(dpt1,s[2])
    bisect.insort(dpt2,s[0]*10+s[1])
    bisect.insort(dpt2,s[1]*10+s[2])
    bisect.insort(dpt2,s[0]*10+s[2])

    dpt1=list(set(dpt1))
    dpt1.sort()
    dpt2=list(set(dpt2))
    dpt2.sort()

    cc=[0 for i in range(100)]
    cc2=[0 for i in range(10)]
    cc[s[2]]=1
    for i in dpt2:
        cc2[i%10]+=1


    dpt3[s[0]*100+s[1]*10+s[2]]=True
    count3=1
    count2=len(dpt2)
    count1=len(dpt1)
    for i in s[3:]:

        if count3==1000:
            break
        if cc[i]!=100:
            for j in dpt2:
                tn=j*10+i


                if not dpt3[tn]:
                    dpt3[tn]=True
                    cc[i]+=1
                    count3+=1
        if cc2[i]!=10:        
            for j in dpt1:
                tn=j*10+i
                if not index(dpt2,tn):
                    bisect.insort(dpt2,tn)
                    cc2[i]+=1
        if not index(dpt1,i):
            bisect.insort(dpt1,i)
    count3=0
    for i in dpt3:
        if i:
            count3+=1
    print(count3)

if __name__ == "__main__":
    resolve()

Solution (Python):
n=int(input())
s=[int(i) for i in input()]

def my_index(l,x,ind):
    global n
    if ind==n:
        return -1
    for i in range(ind,n):
        if l[i]==x:
            return i
    else:
        return -1

c=0
for i in range(10):
    
    x1=my_index(s,i,0)
    
    if x1!=-1:
        
        for j in range(10):
            x2=my_index(s,j,x1+1)
            if x2!=-1:
                for k in range(10):
                    if my_index(s,k,x2+1)!=-1:
                        
                        c+=1
print(c)

Solution (Python):
from collections import Counter
N = int(input())
S = input()
ls = [float('inf') for i in range(10)]
for i in range(10):
    if str(i) in S:
        ls[i] = S.index(str(i))
ans = 0
for i in range(10):
    if ls[i] != float('inf') and ls[i]+1 != N and ls[i]+2 != N:
        s = S[ls[i]+1:]
        ls2 = [float('inf') for i in range(10)]
        for j in range(10):
            if str(j) in s:
                ls2[j] = s.index(str(j))
        for j in range(10):
            if ls2[j] != float('inf') and ls2[j]+1 != len(s):
                a = s[ls2[j]+1:]
                d = Counter(a)
                ans += len(d)
print(ans)

Solution (Python):
N = int(input())
t = input()
S = []
for i in range(N):
    S.append(t[i])
import copy
ans = 0
f = []
for i in range(10):
    if str(i) in S:
        f.append(str(i))
while len(f) > 0 and len(S) > 2:
    k = S.pop(0)
    if k in f:
        f.remove(k)
        s = []
        for j in range(10):
            if str(j) in S:
                s.append(str(j))
        T = copy.deepcopy(S)
        while len(s) > 0 and len(T) > 1:
            l = T.pop(0)
            if l in s:
                s.remove(l)
                for i in range(10):
                    if str(i) in T:
                        ans += 1
                        
print(ans)

Solution (Python):
import itertools
N = input()
S = input()








result = 0

for i in range(0,1000):
    s = str(i).zfill(3)
    
    
    
    
    
    first_index = S.find(s[0])
    if first_index == -1:
        continue
    S_1 = S[first_index+1:]
    second_index = S_1.find(s[1])
    if second_index == -1:
        continue
    S_2 = S_1[second_index+1:]
    third_index = S_2.find(s[2])
    if third_index == -1:
        continue
    result += 1
print(result)

Solution (Python):
def f():
    n = int(input())
    s = input()
    leftMemo = [None]*10
    rightMemo = [None]*10
    for i in range(10):
        char = str(i)
        for j in range(n):
            if s[j] == char:
                leftMemo[i] = j
                break
        for k in range(n-1,-1,-1):
            if s[k] == char:
                rightMemo[i] = k
                break
    ans = 0
    for leftNum in range(10):
        if leftMemo[leftNum] is None:
            continue
        start = leftMemo[leftNum]+1
        for rightNum in range(10):
            if rightMemo[rightNum] is None:
                continue
            end = rightMemo[rightNum]
            ans += len(set(s[start:end]))
    print(ans)


f()

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

pin1 = {}
pin12 = {}
pin123 = {}

for i in range(N):
    if S[i] not in pin1:
        pin1[S[i]] = 1
        for j in range(i + 1, N):
            if S[i] + S[j] not in pin12:
                pin12[S[i] + S[j]] = 1
                for k in range(j + 1, N):
                    if S[i] + S[j] + S[k] not in pin123:
                        pin123[S[i] + S[j] + S[k]] = 1

print(len(pin123))

Solution (Python):
N = int(input())
S = list(map(int,list(input())))
all = []
ilist = []
for i in range(N-2):
    if S[i] in ilist:
        pass
    else:
        ilist.append(S[i])
        jlist = []
        for j in range(N-i-1):
            if S[i+j+1] in jlist:
                pass
            else:
                jlist.append(S[i+j+1])
                klist = []
                for k in range(N-i-j-2):
                    if S[i+j+k+2] in klist:
                        pass
                    else:
                        klist.append(S[i+j+k+2])
                        all.append([S[i],S[i+j+1],S[i+j+k+2]])
print(len(all))

Solution (Python):
n = int(input())
s = int(input())
lst = []

for i in range(n):
     lst.append(s%10)
     s //= 10
lst.reverse()

ten = [-1]*10
hun = [-1]*100
tho = [-1]*1000

for i in range(len(lst)):
    l = lst[i]
    for j in range(100):
        if not hun[j] == -1:
            idx = j*10 + l
            tho[idx] = 1
    for j in range(10):
        if not ten[j] == -1:
            idx = j*10 + l
            hun[idx] = 1
    ten[l] = 1

ans = 0
for i in range(1000):
    if tho[i] == 1:
        ans += 1
print(ans)

Solution (Python):
input()
a, b, c = set(), set(), set()
for x in input():
  c.update(y + x for y in b)
  b.update(y + x for y in a)
  a.add(x)
print(len(c))

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
a = []
b = []
c = []
answer = 0
for i in range(n):
    b = []
    if not s[i] in a:
        a.append(s[i])
        if i < n-2:
            for j in range(i+1,n):
                c = []
                if not s[j] in b:
                    b.append(s[j])
                    if j < n-1:
                        for k in range(j+1,n):
                            if not s[k] in c:
                                c.append(s[k])
                                answer += 1
                            if len(c) == 10:
                                break
                if len(b) == 10:
                        break
        if len(a) == 10:
            break
print(answer)

Solution (Python):
N = int(input())
S = list(map(int, list(input())))
t = {}
for i in range(N):
    t.setdefault(S[i], []).append(i)
ans = 0
for i in range(10):
    if i not in t:
        continue
    ti = t[i][0]
    for j in range(10):
        if j not in t:
            continue
        tj = -1
        for jj in t[j]:
            if ti < jj:
                tj = jj
                break
        else:
            continue
        for k in range(10):
            if k not in t:
                continue
            tk = -1
            for kk in t[k]:
                if tj < kk:
                    ans += 1
                    break
print(ans)

Solution (Python):
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 a >= 0 and b >= 0 and c >= 0 and (a < b < c):
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import itertools
n=int(input())
s=list(map(int,list(input())))

cnt=0
for i in range(1000):
  a=i//100
  b=(i-a*100)//10
  c=i-a*100-b*10
  if a in s:
    an=s.index(a)
    tmp=s[an+1:]
    if b in tmp:
      bn=tmp.index(b)
      tmp=tmp[bn+1:]
      if c in tmp:
        cnt+=1
print(cnt)

Solution (Python):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))



N=one_int()
S=one_str()
S="".join(S)

S=list(S)
S_set=set(S)


sums = 0
dicts = {}
for i in S_set:
    temp = 0
    ind = S.index(i)
    if ind+1!=N:
        for j in set(S[ind+1:]):
            ind2 = S[ind+1:].index(j)
            
            if (ind+ind2+2) != N:
                sums+=len(set(S[ind+ind2+2:]))
print(sums)

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

flagL = [0 for i in range(100)]
L = [0 for i in range(1000)]

num1 = int(s[0])
for i in range(10):
  flagL[num1*10+i] = 1

num2 = int(s[1])
for i in range(10):
  flagL[num2*10+i] = 1
flagL[10*num1+num2] = 2

for i in range(len(s)-2):
  num = int(s[i+2])
  for j in range(100):
    if flagL[j] == 2:
      L[j*10+num] = 1    
  for k in range(10):
    if flagL[k*10+num] == 1:
      flagL[k*10+num] = 2
    if flagL[num*10+k] == 0:
      flagL[num*10+k] = 1
  
print(sum(L))

Solution (Python):
def main():
    n=int(input())
    s=input()
    ans=0
    f00=[False if str(i) in set(str(s)) else True for i in range(10)]
    f0=f00.copy()
    for i0 in range(n-2):
        if all(f0):
            break
        if not f0[int(s[i0])]:
            f1=f00.copy()
            for i1 in range(i0+1,n-1):
                if all(f1):
                    break
                if not f1[int(s[i1])]:
                    ans+=len( set( s[i1+1:] ) )
                    f1[int(s[i1])]=True
        f0[int(s[i0])]=True
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):


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



def search(lis,num):
    for index,item in enumerate(lis):
        if item==num:
            return True,index
  
    return False,-1

l=[[[0 for i in range(10)] for i in range(10)] for i in range(10)]
ans=0
for i in range(10):
    judge1,temp1=search(S,i)
    
    if judge1:
        
        for j in range(10):
            judge2,temp2=search(S[temp1+1:],j)
            if judge2:
                
                for k in range(10):
                    
                    if search(S[temp1+temp2+2:],k)[0]:
                        
                        
                        l[i][j][k]=1
                    else:
                        continue
            else:
                continue
    else:
        continue
ans=0
for item in l:
    for item2 in item:
        ans+=sum(item2)


print(ans)

Solution (Python):
N = int(input())
s = input()
tgt = []
res = 0
for i in range(0,1000):
    tgt = []
    if i <= 99:
        tgt.append('0')
    else:
        tgt.append(str(i//100))
    if i <= 9:
        tgt.append('0')
    else:
        tgt.append(str((i%100)//10))
    tgt.append(str(i%10))
    
    now = 0
    if tgt[0] in s:
        t1 = s.index(tgt[0])
        if tgt[1] in s[t1+1:]:
            t2 = s[t1+1:].index(tgt[1])
            if tgt[2] in s[t1+t2+2:]:
                t3 = s[t1+t2+2:].index(tgt[2])
                res += 1
                
print(res)

Solution (Python):
def check(first, second, third, num_list):
    first_flag = False
    second_flag = False
    third_flag = False
    for num in num_list:
        if first_flag:
            if second_flag:
                if third_flag:
                    return True
                else:
                    if str(num) == third:
                        third_flag = True
            else:
                if str(num) == second:
                    second_flag = True
        else:
            if str(num) == first:
                first_flag = True
        if first_flag and second_flag and third_flag:
            return True
    return False

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

ans = 0

for i in range(1000):
    if i < 10:
        flag = check('0', '0', str(i), sl)
    elif i < 100:
        flag = check('0', str(i//10), str(i%10), sl)
    else:
        flag = check(str(i//100), str((i%100)//10), str(i%10), sl)
        
    if flag:
        ans += 1

print(ans)

Solution (Python):
n = int(input())
a = list(input())

s = [0] * 10
d = [0] * 100
t = [0] * 1000

s[int(a[0])] = 1
s[int(a[1])] = 1
d[int(a[1]) * 10 + int(a[0])] = 1

for x in a[2:]:
    y = int(x)
    z = y * 100
    for i in range(100):
        if d[i] == 1:
            t[z + i] = 1
    z = y * 10
    for i in range(10):
        if s[i] == 1:
            d[z + i] = 1
    s[y] = 1

print(t.count(1))

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


ans = 0

cand = sorted(set(S), key=S.index)

for i in cand:
  index = S.find(i)
  newS = S[index+1:]

  newcand = sorted(set(newS), key=newS.index)

  for j in newcand:
    newindex = newS.find(j)
    newnewS = newS[newindex+1:]

    newnewcand = sorted(set(newnewS), key=newnewS.index)


    ans += len(newnewcand)

print(ans)

Solution (Python):
n = int(input())
s = input()
ans = 0
a_list=[]
for i in sorted(list(set(s[:-2]))):
    index = s.index(str(i))
    for j in sorted(list(set(s[index+1:-1]))):
        index_2 = s[index+1:].index(j)+index+1
        ans += len(set(s[index_2+1:]))

print(ans)