Runs
Time: 1 s · Memory: 256 MB
- Arrays
Statement
A run is a group of equal elements standing next to each other in an array; its length is the number of those elements (a length of is possible). For example, 1 1 1 2 2 3 has three runs: three s, two s and one .
You are given an array. Find the number of runs, the length of each run and the value it consists of.
Input format
The first line contains (). The second line contains integers ().
Output format
The first line contains the number of runs . The second line contains numbers — the run lengths. The third line contains numbers — the values of the runs. Both in the order they appear in the array.
Examples
Input
10 1 1 1 2 2 3 4 5 5 5
Output
5 3 2 1 1 3 1 2 3 4 5
Input
4 7 7 7 7
Output
1 4 7
Note
Compare each element with the previous one: if they are equal, extend the current run, otherwise start a new one. In the first example: 5, 3 2 1 1 3, 1 2 3 4 5.
