a1 map int input split for in range append a1 a1 a1 len None pred None

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
N, a1, k, b, m = map(int, input().split())
A = []
for i in range(1,N+1):
A.append(a1)
a1 = (k*a1 + b) % m
N = len(A)
d = [None] * N
pred = [None] * N
for i in range(N):
d[i] = 1
pred[i] = -1
for j in range(i):
if int(A[j]) < int(A[i]):
if d[i] < 1+d[j]:
d[i] = d[j]+1
pred[i] = j
otv = d[0]
path = []
for i in range(N):
if otv < d[i]:
otv = d[i]
poz = i
while poz != -1:
path.append(poz)
poz = pred[poz]
for i in path[::-1]:
print(A[i], end = ' ')