QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#580. Ones

Statistics

Let $x$ be a sequence of zeros and ones. An utterly forlorn one (UFO) in $x$ 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 $n$ with $sks(n)$. For example, $sks(5)=5$, $sks(64)=59$, $sks(128)=122$, $sks(256)=249$.

We will be working with very large numbers. Therefore, we shall represent them in a succinct way. Suppose $x$ is a positive integer and $x_2$ is its binary representation (starting with 1). Then the succinct representation of $x$ is the sequence $REP(x)$ consisting of positive integers denoting the lengths of successive blocks of the same digits. For example:

$$REP(460288)=REP(1110000011000000000_2)=(3,5,2,9)$$

$$REP(408)=REP(110011000_2)=(2,2,2,3)$$

Your task is to write a program that finds the sequence $REP(sks(n))$ given $REP(n)$.

Input

The first line of the standard input holds one integer $k$ ($1 ≤ k ≤ 1\,000\,000$) denoting the length of the succinct representation of a positive integer $n$. The second line of the standard input holds $k$ integers $x_1,x_2,…,x_k$, ($0 < x_i ≤ 1\,000\,000\,000$), separated by single spaces. The sequence $x_1,x_2,…,x_k$ forms the succinct representation of the number $n$. You may assume that $x_1+x_2+…+x_k ≤ 1\,000\,000\,000$, i.e., $0 < n < 21\,000\,000\,000$.

Output

Your program is to print out two lines to the standard output. The first one should contain a single positive integer $l$. The second line should hold $l$ positive integers $y_1,y_2,…,y_l$, separated by single spaces. The sequence $y_1,y_2,…,y_l$ is to form the succinct representation of $sks(n)$.

Example

Input

6
1 1 1 1 1 1

Output

5
1 1 2 1 1

Hints

The sequence 1,1,1,1,1,1 forms the succinct representation of 1010102=42, sks(42)=45, while 45=1011012 is succinctly represented by 1,1,2,1,1.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.