###name Find the median

###descirption Let median of some array be the number which would stand in the middle of this array if it was sorted beforehand. If the array has even length let median be smallest of of two middle elements. For example, median of the array [10,3,2,3,2] is 3 Median of the array [1,5,8,1] is 1

At first, you're given an empty sequence. There are N operations. The i-th operation contains two integers$$L_i$$and$$R_i$$.This means that adding $$R_i-L_i+1$$ integers $$L_i,L_i+1,...,R_i$$into the sequence. After each operation, you need to find the median of the sequence.

###input The first line of the input contains an integer N(1≤N≤400000)as described above.

The next two lines each contains six integers in the following format, respectively: - $$X_1X_2A_1B_1C_1M_1$$ - $$Y_1Y_2A_2B_2C_2M_2$$

These values are used to generate $$L_i,R_i$$as follows:

We define: - $$X_i=(A_1X_{i-1}+B_1X_{i-2}+C_1)module\quad M_1,for\quad i=3\quad to\quad N$$ - $$Y_i=(A_2Y_{i-1}+B_2Y_{i-2}+C_2)module\quad M_1,for\quad i=3\quad to\quad N$$

We also define: - $$L_i=min(X_i,Y_i)+1,for\quad i=1\quad to\quad N$$ - $$R_i=max(x_i,Y_i)+1,for\quad i=1\quad to\quad N$$

Limits: $$1≤N≤400000$$ $$0≤A_1,B_1,C_1,X_1,X_2<M_1$$ $$0≤A_2,B_2,C_2,Y_1,Y_2<M_2$$ $$1≤M1,M2≤10^9$$

###output You should output N lines. Each line contains an integer means the median.

###sample input 5 3 1 4 1 5 9 2 7 1 8 2 9

###sample output 3 4 5 4 5

###hint L = [3, 2 ,4, 1, 7] R = [4, 8, 8, 3, 9]

###toturial 离散化区间后用权值线段树维护区间和,直接在树上二分答案

###code

-----------------------本文结束感谢您的阅读-----------------------