Олимпиадный тренинг

Задача 33231. Largest increasing subsequence in O(n*log(n))


Задача

Темы:
The numerical sequence is given by the recurrent formula: ai+1=(k* ai+b)mod m. Find the length of its longest increasing subsequence.
 
Input
The program receives five integers as input: the length of the sequence n (1≤n≤105), the initial element of the sequence a1, the parameters k, b, m for calculating subsequent members sequences (1≤m≤104, 0≤k<m, 0≤b<m, 0≤a1<m).
 
Output
You need to print the length of the largest increasing subsequence of this sequence.

Enter Output
5 41 2 1 100 3