A lock contains n wheels where each wheel contains ki numbers in a specific order. You have m sets and each set contains ci wheels. At each move, you select a set and turn all of its wheels one unit up.
For example, this is the wheel s1,s2,s3,s4 and after one move, it becomes s2,s3,s4,s1.
Your task is to unlock the lock.
Input format
Output format
The first line contain the ans denoting the number of moves. Each of the next m lines contains ui denoting the number of the moves with the ith set.
Constraints
1≤n≤10 000
1≤m≤100 000
1≤ki≤40 000
1≤si,pi≤109
1≤ci,ai≤n
n∑i=1ki≤40 000
m∑i=1ci≤400 000
Note: For each input, at least one solution exist.
wheel number 3 is always on 2.
wheel number 1 progress :
5 -> 10 -> 2
wheel number 2 progress :
1 -> 4 -> 2 -> 1
wheel number 4 progress :
10 -> 7 -> 10 -> 7
the final state of wheels :
2, 1, 2, 7