W razie problemów technicznych ze Szkopułem, prosimy o kontakt mailowy pod adresem [email protected].
Jeśli chciałbyś porozmawiać o zadaniach, rozwiązaniach lub problemach technicznych, zapraszamy na serwery Discord. Są one moderowane przez społeczność, ale członkowie zespołu technicznego też są tam aktywni.
Let be a sequence of zeros and ones. An utterly forlorn one (UFO) in is the extreme (either first or last) one that additionally does not neighbour with any other one. For instance, the sequence 10001010 has two UFOs, while the sequence 1101011000 has no UFO, and the sequence 1000 has only one UFO.
Let us denote the total number of UFOs in the binary representations of the numbers from 1 to with . For example, , , , .
We will be working with very large numbers. Therefore, we shall represent them in a succinct way. Suppose is a positive integer and is its binary representation (starting with 1). Then the succinct representation of is the sequence consisting of positive integers denoting the lengths of successive blocks of the same digits. For example:
Your task is to write a program that finds the sequence given .
The first line of the standard input holds one integer () denoting the length of the succinct representation of a positive integer . The second line of the standard input holds integers , (), separated by single spaces. The sequence forms the succinct representation of the number . You may assume that , i.e., .
Your program is to print out two lines to the standard output. The first one should contain a single positive integer . The second line should hold positive integers , separated by single spaces. The sequence is to form the succinct representation of .
For the input data:
6 1 1 1 1 1 1
the correct result is:
5 1 1 2 1 1
Explanation of the example: The sequence forms the succinct representation of , , while is succinctly represented by .
Task author: Wojciech Rytter.