int input int for in input split None None for in range -1 for in rang

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
a= int(input())
f= [int(i) for i in input().split()]
d=[None]*a
p=[None]*a
for i in range(a):
d[i]=1; p[i]=-1
for j in range(i):
if f[i] > f[j]:
if d[i]<1+d[j]:
d[i]=1+d[j]
p[i]=j
ans = d[0]
for i in range(a):
if ans <d[i]:
ans=d[i]
pos=i
path=[]
while pos!=-1:
path.append(pos)
pos=p[pos]
for i in path[::-1]:
print(f[i],end= ' ')