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:
# /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
                    break
        if is_hit:
            cnt += 1
    # 出力
    print(cnt)

Submission status: Time Limit Exceeded

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
                    # if t in b[i+1]:
                    #     is_hit = True
                    #     break
                    # else:
                    #     break
                continue
            if tidx < 0:
                if S[i] == t:
                    tidx = i
                    is_hit = True
                    break
        if is_hit:
            cnt += 1
    # 出力
    print(cnt)

Submission status: Time Limit Exceeded

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:])
    cnt = 0
    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(len(S)):
            if fidx > 0 and sidx > fidx and tidx > sidx:
                is_hit = True
                break
            if fidx < 0:
                if S[i] == f:
                    fidx = i
                continue
            if sidx < 0:
                if S[i] == s:
                    sidx = i
                    if i == len(S)-1:
                        break
                    if t in b[i+1]:
                        is_hit = True
                        break
                    else:
                        break
            #     continue
            # if tidx < 0:
            #     if S[i] == t:
            #         tidx = i
            #         is_hit = True
            #         break
        if is_hit:
            cnt += 1
    # 出力
    print(cnt)

Submission status: Time Limit Exceeded

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)
    cnt = 0
    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(len(S)):
            if fidx > 0 and sidx > fidx and tidx > sidx:
                is_hit = True
                break
            if fidx < 0:
                if S[i] == f:
                    fidx = i
                continue
            if sidx < 0:
                if S[i] == s:
                    sidx = i
                continue
            if tidx < 0:
                if S[i] == t:
                    tidx = i
                    is_hit = True
                    break
        if is_hit:
            cnt += 1
    # 出力
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
S=list(map(int,S))
ans=0
for s in range(1000):
      A=s//100
      B=(s-A*100)//10
      C=s-A*100-B*10
      isOne=0
      isTen=0
      isHundred=0
      for i in range(N) :
        if isOne==0:
          if S[i]==A: 
            isOne=1
        elif isTen==0:
          if S[i]==B: 
            isTen=1
        elif isHundred==0:
          if S[i]==C:
            isHundred=1
            ans+=1
        else:
          break

print(ans)

Submission status: Time Limit Exceeded

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

ans=0
for s in range(1000):
      s='{:0=3}'.format(s)
      isOne=0
      isTen=0
      isHundred=0
      for i in range(N) :
        if isOne==0:
          if S[i]==s[0]: 
            isOne=1
        elif isTen==0:
          if S[i]==s[1]: 
            isTen=1
        elif isHundred==0:
          if S[i]==s[2]:
            isHundred=1
            ans+=1
        else:
          break

print(ans)

Submission status: Time Limit Exceeded

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

ans=0
for i2 in range(10):
  for j in range(10):
    for k in range(10):
      s='{}{}{}'.format(i2,j,k)
      isOne=0
      isTen=0
      isHundred=0
      for i in range(N) :
        if isOne==0:
          if S[i]==s[0]: 
            isOne=1
        elif isTen==0:
          if S[i]==s[1]: 
            isTen=1
        elif isHundred==0:
          if S[i]==s[2]:
            isHundred=1
            ans+=1
        else:
          break

print(ans)

Submission status: Time Limit Exceeded

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



ans=0
for i2 in range(10):
  for j in range(10):
    for k in range(10):
      s='{}{}{}'.format(i2,j,k)
      isOne=0
      isTen=0
      isHundred=0
      for i in range(N) :
        if S[i]==s[0] and isOne==0:
          isOne=1
        elif S[i]==s[1] and isOne==1 and isTen==0:
          isTen=1
        elif S[i]==s[2] and isOne==1 and isTen==1 and isHundred==0:
          isHundred=1
      if isHundred==1:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

pin={}

for i in range(10):
  for j in range(10):
    for k in range(10):
     pin['{}{}{}'.format(i,j,k)]='{}{}{}'.format(i,j,k)

ans=0
for key in pin:
  s=pin[key]
  isOne=0
  isTen=0
  isHundred=0
  for i in range(N) :
    if S[i]==s[0] and isOne==0:
      isOne=1
    elif S[i]==s[1] and isOne==1 and isTen==0:
      isTen=1
    elif S[i]==s[2] and isOne==1 and isTen==1 and isHundred==0:
      isHundred=1
  if isHundred==1:
    ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

pin={}

l=len(S)
for i in range(10):
  for j in range(10):
    for k in range(10):
     pin['{}{}{}'.format(i,j,k)]='{}{}{}'.format(i,j,k)

ans=0
for key in pin:
  s=pin[key]
  flag=0
  start=0
  for i in range(N) :
    if S[i]==s[0]:
      start=i+1
      flag+=1
      break
  if flag==1:
    for j in range(start,N):
      if S[j]==s[1]:
        start=j+1
        flag+=1
        break
  if flag==2:
    for k in range(start,N):
      if S[k]==s[2]:
        flag+=1
        break
  if flag==3:
    ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

pin={}

l=len(S)
for i in range(10):
  for j in range(10):
    for k in range(10):
     pin['{}{}{}'.format(i,j,k)]='{}{}{}'.format(i,j,k)

ans=0
for key in pin:
  s=pin[key]
  flag=0
  start=0
  for i in range(N) :
    if S[i]==s[0]:
      start=i+1
      flag+=1
      break
  for j in range(start,N):
    if S[j]==s[1]:
      start=j+1
      flag+=1
      break
  for k in range(start,N):
    if S[k]==s[2]:
      flag+=1
      break
  if flag==3:
    ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

pin={}

l=len(S)
for i in range(10):
  for j in range(10):
    for k in range(10):
     pin['{}{}{}'.format(i,j,k)]='{}{}{}'.format(i,j,k)

ans=0
for key in pin:
  s=pin[key]
  flag=0
  for i in range(N) :
    if S[i]==s[0]:
      for j in range(i+1,N):
        if S[j]==s[1]:
           for k in range(j+1,N):
             if S[k]==s[2]:
               flag=1
  if flag==1:
    ans+=1
    
print(ans)

Submission status: Time Limit Exceeded

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

pin={}
#for i in range(10):
 # for j in range(10):
  #  for k in range(10):
   #   pin['{}{}{}'.format(i,j,k)]=0

l=len(S)
for i in range(l):
  for j in range(i+1,l):
    for k in range(j+1,l):
      s=S[i]+S[j]+S[k]
      pin[s]=1


ans=len(pin)

print(ans)

Submission status: Time Limit Exceeded

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

pin={}
for i in range(10):
  for j in range(10):
    for k in range(10):
      pin['{}{}{}'.format(i,j,k)]=0

l=len(S)
for i in range(l):
  for j in range(i+1,l):
    for k in range(j+1,l):
      s=S[i]+S[j]+S[k]
      pin[s]=1


ans=0
for i in pin:
  if pin[i]==1:
    ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
import math

# 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():
    n = get_int()
    s_list = get_string_char_list()
    #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 range(0, n):

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

if __name__ == '__main__':
    main()