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:
import itertools
from sys import stdin
N=int(input())
st=list(stdin.readline().strip())
count=0
cnt=0
# num=["0","1","2","3","4","5","6","7","8","9"]
#
# num_list= ["".join(i) for i in itertools.product(num,repeat=3)]
num_list=['000', '001', '002', '003', '004', '005', '006', '007', '008', '009', '010', '011', '012', '013', '014', '015', '016', '017', '018', '019', '020', '021', '022', '023', '024', '025', '026', '027', '028', '029', '030', '031', '032', '033', '034', '035', '036', '037', '038', '039', '040', '041', '042', '043', '044', '045', '046', '047', '048', '049', '050', '051', '052', '053', '054', '055', '056', '057', '058', '059', '060', '061', '062', '063', '064', '065', '066', '067', '068', '069', '070', '071', '072', '073', '074', '075', '076', '077', '078', '079', '080', '081', '082', '083', '084', '085', '086', '087', '088', '089', '090', '091', '092', '093', '094', '095', '096', '097', '098', '099', '100', '101', '102', '103', '104', '105', '106', '107', '108', '109', '110', '111', '112', '113', '114', '115', '116', '117', '118', '119', '120', '121', '122', '123', '124', '125', '126', '127', '128', '129', '130', '131', '132', '133', '134', '135', '136', '137', '138', '139', '140', '141', '142', '143', '144', '145', '146', '147', '148', '149', '150', '151', '152', '153', '154', '155', '156', '157', '158', '159', '160', '161', '162', '163', '164', '165', '166', '167', '168', '169', '170', '171', '172', '173', '174', '175', '176', '177', '178', '179', '180', '181', '182', '183', '184', '185', '186', '187', '188', '189', '190', '191', '192', '193', '194', '195', '196', '197', '198', '199', '200', '201', '202', '203', '204', '205', '206', '207', '208', '209', '210', '211', '212', '213', '214', '215', '216', '217', '218', '219', '220', '221', '222', '223', '224', '225', '226', '227', '228', '229', '230', '231', '232', '233', '234', '235', '236', '237', '238', '239', '240', '241', '242', '243', '244', '245', '246', '247', '248', '249', '250', '251', '252', '253', '254', '255', '256', '257', '258', '259', '260', '261', '262', '263', '264', '265', '266', '267', '268', '269', '270', '271', '272', '273', '274', '275', '276', '277', '278', '279', '280', '281', '282', '283', '284', '285', '286', '287', '288', '289', '290', '291', '292', '293', '294', '295', '296', '297', '298', '299', '300', '301', '302', '303', '304', '305', '306', '307', '308', '309', '310', '311', '312', '313', '314', '315', '316', '317', '318', '319', '320', '321', '322', '323', '324', '325', '326', '327', '328', '329', '330', '331', '332', '333', '334', '335', '336', '337', '338', '339', '340', '341', '342', '343', '344', '345', '346', '347', '348', '349', '350', '351', '352', '353', '354', '355', '356', '357', '358', '359', '360', '361', '362', '363', '364', '365', '366', '367', '368', '369', '370', '371', '372', '373', '374', '375', '376', '377', '378', '379', '380', '381', '382', '383', '384', '385', '386', '387', '388', '389', '390', '391', '392', '393', '394', '395', '396', '397', '398', '399', '400', '401', '402', '403', '404', '405', '406', '407', '408', '409', '410', '411', '412', '413', '414', '415', '416', '417', '418', '419', '420', '421', '422', '423', '424', '425', '426', '427', '428', '429', '430', '431', '432', '433', '434', '435', '436', '437', '438', '439', '440', '441', '442', '443', '444', '445', '446', '447', '448', '449', '450', '451', '452', '453', '454', '455', '456', '457', '458', '459', '460', '461', '462', '463', '464', '465', '466', '467', '468', '469', '470', '471', '472', '473', '474', '475', '476', '477', '478', '479', '480', '481', '482', '483', '484', '485', '486', '487', '488', '489', '490', '491', '492', '493', '494', '495', '496', '497', '498', '499', '500', '501', '502', '503', '504', '505', '506', '507', '508', '509', '510', '511', '512', '513', '514', '515', '516', '517', '518', '519', '520', '521', '522', '523', '524', '525', '526', '527', '528', '529', '530', '531', '532', '533', '534', '535', '536', '537', '538', '539', '540', '541', '542', '543', '544', '545', '546', '547', '548', '549', '550', '551', '552', '553', '554', '555', '556', '557', '558', '559', '560', '561', '562', '563', '564', '565', '566', '567', '568', '569', '570', '571', '572', '573', '574', '575', '576', '577', '578', '579', '580', '581', '582', '583', '584', '585', '586', '587', '588', '589', '590', '591', '592', '593', '594', '595', '596', '597', '598', '599', '600', '601', '602', '603', '604', '605', '606', '607', '608', '609', '610', '611', '612', '613', '614', '615', '616', '617', '618', '619', '620', '621', '622', '623', '624', '625', '626', '627', '628', '629', '630', '631', '632', '633', '634', '635', '636', '637', '638', '639', '640', '641', '642', '643', '644', '645', '646', '647', '648', '649', '650', '651', '652', '653', '654', '655', '656', '657', '658', '659', '660', '661', '662', '663', '664', '665', '666', '667', '668', '669', '670', '671', '672', '673', '674', '675', '676', '677', '678', '679', '680', '681', '682', '683', '684', '685', '686', '687', '688', '689', '690', '691', '692', '693', '694', '695', '696', '697', '698', '699', '700', '701', '702', '703', '704', '705', '706', '707', '708', '709', '710', '711', '712', '713', '714', '715', '716', '717', '718', '719', '720', '721', '722', '723', '724', '725', '726', '727', '728', '729', '730', '731', '732', '733', '734', '735', '736', '737', '738', '739', '740', '741', '742', '743', '744', '745', '746', '747', '748', '749', '750', '751', '752', '753', '754', '755', '756', '757', '758', '759', '760', '761', '762', '763', '764', '765', '766', '767', '768', '769', '770', '771', '772', '773', '774', '775', '776', '777', '778', '779', '780', '781', '782', '783', '784', '785', '786', '787', '788', '789', '790', '791', '792', '793', '794', '795', '796', '797', '798', '799', '800', '801', '802', '803', '804', '805', '806', '807', '808', '809', '810', '811', '812', '813', '814', '815', '816', '817', '818', '819', '820', '821', '822', '823', '824', '825', '826', '827', '828', '829', '830', '831', '832', '833', '834', '835', '836', '837', '838', '839', '840', '841', '842', '843', '844', '845', '846', '847', '848', '849', '850', '851', '852', '853', '854', '855', '856', '857', '858', '859', '860', '861', '862', '863', '864', '865', '866', '867', '868', '869', '870', '871', '872', '873', '874', '875', '876', '877', '878', '879', '880', '881', '882', '883', '884', '885', '886', '887', '888', '889', '890', '891', '892', '893', '894', '895', '896', '897', '898', '899', '900', '901', '902', '903', '904', '905', '906', '907', '908', '909', '910', '911', '912', '913', '914', '915', '916', '917', '918', '919', '920', '921', '922', '923', '924', '925', '926', '927', '928', '929', '930', '931', '932', '933', '934', '935', '936', '937', '938', '939', '940', '941', '942', '943', '944', '945', '946', '947', '948', '949', '950', '951', '952', '953', '954', '955', '956', '957', '958', '959', '960', '961', '962', '963', '964', '965', '966', '967', '968', '969', '970', '971', '972', '973', '974', '975', '976', '977', '978', '979', '980', '981', '982', '983', '984', '985', '986', '987', '988', '989', '990', '991', '992', '993', '994', '995', '996', '997', '998', '999']

for number in num_list:
    mark = 0
    for i in range(N):

        if cnt==0 and number[0]==st[i]:
            mark=i
            cnt+=1
        if cnt==1 and number[1]==st[i] and i>mark:
            cnt+=1
            mark=i
        if cnt==2 and number[2]==st[i] and i>mark:
            cnt+=1
            break
    if cnt==3:
        count+=1
    cnt=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=int(input())
st=list(stdin.readline().strip())
count=0
cnt=0
num=["0","1","2","3","4","5","6","7","8","9"]

num_list= ["".join(i) for i in itertools.product(num,repeat=3)]
for number in num_list:
    mark = 0
    for i in range(N):
        if cnt==0 and number[0]==st[i]:
            mark=i
            cnt+=1
            continue
        if cnt==1 and number[1]==st[i] and i>mark:
            cnt+=1
            mark=i
            continue
        if cnt==2 and number[2]==st[i] and i>mark:
            cnt+=1
            break
    if cnt==3:
        count+=1
    cnt=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=int(input())
st=list(stdin.readline().strip())
count=0
cnt=0
num=["0","1","2","3","4","5","6","7","8","9"]

num_list= ["".join(i) for i in itertools.product(num,repeat=3)]
for number in num_list:
    mark = 0
    for i in range(N):
        if cnt==0 and number[0]==st[i]:
            mark=i
            cnt+=1
        if cnt==1 and number[1]==st[i] and i>mark:
            cnt+=1
            mark=i
        if cnt==2 and number[2]==st[i] and i>mark:
            cnt+=1
            break
    if cnt==3:
        count+=1
    cnt=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from sys import stdin
N=int(input())
st=list(stdin.readline().strip())
count=0
cnt=0
num=["0","1","2","3","4","5","6","7","8","9"]

num_list=p = ["".join(i) for i in itertools.product(num,repeat=3)]
for number in num_list:
    mark = 0
    for i in range(N):
        if cnt==0 and number[0]==st[i]:
            mark=i
            cnt+=1
        if cnt==1 and number[1]==st[i] and i>mark:
            cnt+=1
            mark=i
        if cnt==2 and number[2]==st[i] and i>mark:
            cnt+=1
            break
    if cnt==3:
        count+=1
    cnt=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
st=list(input())
count=0
cnt=0
num=["0","1","2","3","4","5","6","7","8","9"]

num_list=p = ["".join(i) for i in itertools.product(num,repeat=3)]
for number in num_list:
    mark = 0
    for i in range(N):
        if cnt==0 and number[0]==st[i]:
            mark=i
            cnt+=1
        if cnt==1 and number[1]==st[i] and i>mark:
            cnt+=1
            mark=i
        if cnt==2 and number[2]==st[i] and i>mark:
            cnt+=1
            break
    if cnt==3:
        count+=1
    cnt=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
st=list(input())
ans=[]
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            ans.append(st[i]+st[j]+st[k])
ans=set(ans)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

LucNum = set([])

for i, j, k in itertools.combinations(range(n), 3):
	LucNum.add(s[i] + s[j] + s[k])

print(len(LucNum))

Submission status: Time Limit Exceeded

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

for i in range(0,1000):
    tmp=[i//100,(i//10)%10,i%10]
    cnt = 0
    for j in s:
        if int(j)==tmp[cnt]:
            cnt+=1
        if cnt==3:
            ans+=1
            break

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(0,1000):
    tmp=[i//100,(i//10)%10,i%10]
    cnt = 0
    for j in s:
        if int(j)==int(tmp[cnt]):
            cnt+=1
        if cnt==3:
            break
    if cnt==3:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

#print( N,S )   

passwd = [ [ [False for _ in range(10) ] for _ in range(10) ] for _ in range(10) ]
#print(passwd)

cnt = 0

for i1 in range(N-2):
    for i2 in range(i1+1,N-1):
        for i3 in range(i2+1, N):
            if passwd[int(S[i1])][int(S[i2])][int(S[i3])] == False:
                cnt = cnt + 1
                passwd[int(S[i1])][int(S[i2])][int(S[i3])] = True
            #ppp = S[i1]+S[i2]+S[i3]
            #print(i1,i2,i3, ppp)

#print(passwd)
print(cnt)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(1000):
    a = str(i)
    a = list(a.zfill(3))
    sw = 0
    for j in range(len(s)):
        if sw == 0:
            if a[0] == s[j]:
                sw = 1
        elif sw == 1:
            if a[1] == s[j]:
                sw = 2
        elif sw == 2:
            if a[2] == s[j]:
                count += 1
                break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
cnt=0
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:
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n = int(input())
    s = list(input())
    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                pin = str(i) + str(j) + str(k)
                t = 0
                for x in s:
                    if pin[t] == x:
                        t += 1
                    if t == 3:
                        ans += 1
                        break
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re
n=int(input())
s=input()
ans=0
for i in range(1000):
      a='00'+str(i)
      a=a[-3:]
      b=a[0]+r'\d*'+a[1]+r'\d*'+a[2]
      c=re.search(b,s)
      if c!=None:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    s=input()
    dp_0=[[False]*1001 for _ in range(n+1)]
    dp_1=[[False]*1001 for _ in range(n+1)]
    dp_2=[[False]*1001 for _ in range(n+1)]
    dp_3=[[False]*1001 for _ in range(n+1)]
    dp_0[0][0]=True
    
    for k in range(1000):
        for i in range(n):
            if dp_0[i][k]==True:
                dp_0[i+1][k]=True
                dp_1[i+1][10*k+int(s[i])]=True
            if dp_1[i][k]==True:
                dp_1[i+1][k]=True
                dp_2[i+1][10*k+int(s[i])]=True
            if dp_2[i][k]==True:
                dp_2[i+1][k]=True
                dp_3[i+1][10*k+int(s[i])]=True
            if dp_3[i][k]==True:
                dp_3[i+1][k]=True            
    ans=0
    for i in range(1000):
        if dp_3[n][i]:
            ans+=1
    print(ans)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    s=input()
    dp=[[[False]*1001 for _ in range(4)] for _ in range(n+1)]
    dp[0][0][0]=True
    
    for j in range(4):
        for k in range(1000):
            for i in range(n):
                if dp[i][j][k]==False:
                    continue
                dp[i+1][j][k]=True
                if j!=3:
                    dp[i+1][j+1][10*k+int(s[i])]=True
    ans=0
    for i in range(1000):
        if dp[n][3][i]:
            ans+=1
    print(ans)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    s=input()
    dp=[[[False]*1001 for _ in range(4)] for _ in range(n+1)]
    dp[0][0][0]=True
    for i in range(n):
        for j in range(4):
            for k in range(1000):
                if dp[i][j][k]==False:
                    continue
                dp[i+1][j][k]=True
                if j!=3:
                    dp[i+1][j+1][10*k+int(s[i])]=True
    ans=0
    for i in range(1000):
        if dp[n][3][i]:
            ans+=1
    print(ans)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
L = list(S)
first = [L.index(str(i)) if str(i) in S else None for i in range(10)]
con = 0

for n in range(0,1000):
  c = str(n)
  c = "0" * (3 - len(c)) + c
  m = int(c[0])
  y = int(c[1])
  z = int(c[2])
  if ((first[m] != None) and (first[y] != None) and (first[z] != None) ) and first[m] < N - 1:
    i = first[m]
    for j in range(i + 1,len(S) - 1):
        if S[j] == c[1] and c[2] in S[j + 1:]:
          con += 1
          break

print(con)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
#初めて出てきたときのインデックスをめも
memo=[[-1]*10 for _ in range(10)]
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        si=int(S[i])
        sj=int(S[j])
        if memo[si][sj]==-1:
            memo[si][sj]=0
            ans+=len(set(S[j+1:]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
L = list(S)
first = [L.index(str(i)) if str(i) in S else None for i in range(10)]
con = 0

for n in range(0,1000):
  c = str(n)
  c = "0" * (3 - len(c)) + c
  if first[int(c[0])] != None and first[int(c[0])] < N - 1:
    i = first[int(c[0])]
    for j in range(i + 1,len(S) - 1):
        if S[j] == c[1] and c[2] in S[j + 1:]:
          con += 1
          break

print(con)

Submission status: Time Limit Exceeded

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

con = 0

for n in range(0,1000):
  c = str(n)
  c = "0" * (3 - len(c)) + c
  for i in range(len(S) - 2):
    if S[i] == c[0]:
      for j in range(i + 1,len(S) - 1):
        if S[j] == c[1] and c[2] in S[j + 1:]:
          con += 1
          break
      break

print(con)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n = int(input())
s = input()
ans = 0
for i in range(1000):
    password = str(i).zfill(3)
    #print(password)
    for j in range(n):
        if s[j] == password[0]:
            for k in range(j + 1, n):
                if s[k] == password[1]:
                    for l in range(k + 1, n):
                        if s[l] == password[2]:
                            ans += 1
                            break
                    
                    break
            
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n = int(input())
s = input()
ans = 0
for i in range(1000):
    password = i
    #print(password)
    for j in range(n):
        if int(s[j]) == i // 100:
            for k in range(j + 1, n):
                if int(s[k]) == (i // 10) % 10:
                    for l in range(k + 1, n):
                        if int(s[l]) == i % 10:
                            ans += 1
                            break
                    
                    break
            
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n = int(input())
s = input()
passwords = defaultdict(int)
for i in range(1000):
    num = str(i)
    password = "0" * (3 - len(num)) + num
    #print(password)
    for j in range(n):
        if s[j] == password[0]:
            #print("OK1", password)
            for k in range(j + 1, n):
                if s[k] == password[1]:
                    #print("OK2")
                    for l in range(k + 1, n):
                        if s[l] == password[2]:
                            #print("OK3", password)
                            passwords["".join(password)] += 1
                            break
                
                    break
            break

print(len(passwords))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n = int(input())
s = input()
passwords = defaultdict(int)
for i in range(1000):
    password = [str(i // 100), str((i // 10) % 10), str(i % 10)]
    #print(password)
    for j in range(n):
        if s[j] == password[0]:
            #print("OK1", password)
            for k in range(j + 1, n):
                if s[k] == password[1]:
                    #print("OK2")
                    for l in range(k + 1, n):
                        if s[l] == password[2]:
                            #print("OK3", password)
                            passwords["".join(password)] += 1
                            break
                
                    break
            break

print(len(passwords))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n = int(input())
s = input()
passwords = defaultdict(int)
for i in range(1000):
    password = "0" * (3 - len(str(i))) + str(i)
    for j in range(n):
        if s[j] == password[0]:
            #print("OK1", password)
            for k in range(j + 1, n):
                if s[k] == password[1]:
                    #print("OK2")
                    for l in range(k + 1, n):
                        if s[l] == password[2]:
                            #print("OK3", password)
                            passwords[password] += 1
                            break
                
                    break
            break

print(len(passwords))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n = int(input())
s = input()
passwords = defaultdict(int)
for i in range(1000):
    password = "0" * (3 - len(str(i))) + str(i)
    for j in range(n):
        if s[j] == password[0]:
            #print("OK1", password)
            for k in range(j + 1, n):
                if s[k] == password[1]:
                    #print("OK2")
                    for l in range(k + 1, n):
                        if s[l] == password[2]:
                            #print("OK3", password)
                            passwords[password] += 1
                            break


print(len(passwords))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
n = int(input())
s = input()
passwords = defaultdict(int)
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            passwords[s[i] + s[j] + s[k]] += 1
        
print(len(passwords))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
num=int(n*(n-1)*(n-2)/6)
ss=[]
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            ss.append(s[i]+s[j]+s[k])
sss=set(ss)
print(len(sss))

Submission status: Time Limit Exceeded

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

ans = 0
for n in range(1000):
    n = str(n).zfill(3)
    i = 0
    for j in range(N):
        if S[j] == n[i]:
            i += 1
            if i == 3:
                ans += 1
                break

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
cnt = 0
for i in range(1000):
    l = list()
    l.append(i // 100)
    l.append((i // 10) % 10)
    l.append(i % 10)
    f = 0
    for j in range(N):
        if int(S[j]) == l[f]:
            f += 1
        if f == 3:
            break
    if f == 3:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def check(num, N): #Nからnumが作れるならreturn 1
    length = len(N)

    get_target = 0
    for i in range(length):
        if get_target == 0 and N[i] == num[0]:
            get_target = 1
            # print("target1", num)
        elif get_target == 1 and N[i] == num[1]:
            get_target = 2
            # print("target2", num)
        elif get_target == 2 and N[i] == num[2]:
            get_target = 3
            # print("target3", num)
    
    if get_target == 3:
        # print(num)
        return 1
    else:
        return 0


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

counter = 0
for i in range(1000):
    str_i = str(i)
    while len(str_i) <3:
        str_i = "0" + str_i
    
    counter += check(str_i, S)
print(counter)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
num=[]
for i in range(1000):
    p=str(i)
    while len(p)<3:
        p="0"+p
    num.append(p)
ans=0
for k in range(len(num)):
    q=0
    for i in range(len(s)):
        if q==3:
            break
        elif num[k][q]==s[i]:
            q+=1
    if q==3:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

baai=0
rireki=[]
for i in range(N-2):
    for j in  range(i+1, N-1):
        number=[0,1,2,3,4,5,6,7,8,9]
        for k in range(j+1, N):
            if len(number)==0:
                break
            else:
                if int(S[k]) in number:
                    number.remove(int(S[k]))
            if S[i]+S[j]+S[k] not in rireki:
                baai = baai +1
                rireki.append(S[i]+S[j]+S[k])

print(baai)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
from collections import defaultdict
dd = defaultdict(lambda:False)
for i in range(n):
    for j in range(n):
        for k in range(n):
            if i < j and j < k:
                dd[s[i]+s[j]+s[k]] = True

count =0 
for _ in dd:
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# 19:04
n = int(input())
s = input()


def check(s, i, j, k):
    ii = 0
    jj = 0
    for l in range(len(s)):
        if ii == 1:
            if jj == 1:
                if s[l] == str(k):
                    return 1
            elif s[l] == str(j):
                jj = 1
        elif s[l] == str(i):
            ii = 1
    return 0


sum = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            sum += check(s, i, j, k)


print(sum)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
S = input()
cnt = 0
for i in range(1000):
    C = [str(i//100), str(i//10%10), str(i%10)]
    f = 0
    for s in S:
        if s == C[f]:
            f += 1
        if f == 3:
           break
    if f == 3:
        cnt += 1
    if cnt ==1000:
        break
print(cnt)

Submission status: Time Limit Exceeded

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

a = dict()
total = 0
for i in range(0, 10):
  a[i] = [0, dict()]
  for j in range(0, 10):
    a[i][-1][j] = [0, dict()]
    for k in range(0, 10):
      a[i][-1][j][-1][k] = 0
for x in S:
  x = int(x)
  for i in a.keys():
    if a[i][0] == 1:
      for j in a[i][-1].keys():
        if a[i][-1][j][0] == 1:
          for k in a[i][-1][j][-1].keys():
            if a[i][-1][j][-1][k] == 0 and k == x:
              a[i][-1][j][-1][k] = 1
              total += 1
        if j == x:
          a[i][-1][j][0] = 1
    if i == x:
      a[i][0] = 1

print(total)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
cnt = 0
for i in range(1000):
    C = [i//100, i//10%10, i%10]
    f = 0
    for s in S:
        if int(s) == C[f]:
            f += 1
        if f == 3:
           break
    if f == 3:
        cnt += 1
    if cnt ==1000:
        break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
cnt = 0
for i in range(1000):
    C = [i//100, i//10%10, i%10]
    f = 0
    for s in S:
        if int(s) == C[f]:
            f += 1
        if f == 3:
           break
    if f == 3:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# sumitb2019_d.py
'''
重複考えないとどうなるか
-> 単に nC3 個( N 個から 3 つ選び出す順列と同じ)
'''
N = int(input())
S = input()
cnt = 0
for i in range(1000):
    C = [i//100, i//10%10, i%10]
    f = 0
    for s in S:
        if int(s) == C[f]:
            f += 1
        if f == 3:
           break
    if f == 3:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


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


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


def ZIP(n): return zip(*(MAP() for _ in range(n)))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
	N = INT()
	S = [x for x in input()]

	c = combinations(S, 3)
	c = set(c)
	print(len(c))



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()
S = input()

s = set([""])
for n in S[::-1]:
	s |= set(x+n for x in s if len(x) != 3)

print(len([x for x in s if len(x) == 3]))

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

ans = 0
for i in range(1000):
	i = str(i).zfill(3)
	pat = "{}.*{}.*{}".format(i[0], i[1], i[2])
	if re.search(pat, S):
		ans += 1
print(ans)