P28580 [洛谷] [AHOI2002] Black and White Image Compression
普及
题目描述

Problem Description

During an elective course in basic biological genomics, Keke conducted an image processing experiment at home. She understood that an image is essentially a sequence of image points (pixels). Assuming the number of pixels in the sequence is always a multiple of 8, every eight pixels can be converted into a number called a byte, thus transforming the pixel sequence into a sequence of bytes.

A byte is an 8-bit binary number (often represented in its decimal form for ease of writing). These eight pixels, from front to back, correspond to the eight bits of the byte from the most significant bit to the least significant bit, with 0 representing a white pixel and 1 representing a black pixel. This representation method is called bitmap. For example, the byte sequence 210, 0, 255 represents 8*3=24 pixels. Since the corresponding binary forms are 11010010, 00000000, and 11111111, the colors of these 24 pixels are black, black, white, black, white, white, black, white, white, white, white, white, white, white, white, white, black, black, black, black, black, black, black, black.

Keke thought: there are many continuous segments of the same color in the image, and perhaps expressing the image in a different way could reduce the amount of image data. Her idea was to divide the pixels into several segments by color, where each segment contains pixels of the same color, and all consecutive pixels of the same color are in the same segment. It is also known that the maximum length of each segment is less than 128.

Each pixel segment is represented by an 8-bit binary byte, with the most significant bit indicating the color of the pixels in the segment, and the lower seven bits indicating the number of pixels in the segment. Note: there are no pixel segments of length 0. This representation method is called pixel segment method.

For example, the bitmap byte sequence 210, 0, 255 corresponds to a pixel sequence that can be divided into seven segments: 11, 0, 1, 00, 1, 000000000, 11111111. If represented using the pixel segment method, the binary byte sequence should be written as 10000010, 00000001, 10000001, 00000010, 10000001, 00001001, 10001000, which corresponds to the decimal byte sequence 130, 1, 129, 2, 129, 9, 136.

Can the pixel segment method effectively reduce the amount of image data storage? Keke didn't know how to prove this mathematically, so she decided to conduct some experiments on the images she had to see if the method was really effective. Please write a program to complete the conversion of the image information to assist Keke in completing these experiments.

Input Format

The file contains the information of an image in one line. The first number is a positive integer $n$, indicating that the image has $n$ pixels. Following this are $\frac{n}{8}$ decimal byte values representing the bitmap information of the image. Adjacent numbers are separated by a space.

Output Format

Output the image information in the pixel segment representation method in one line, with each number in decimal form, separated by a space.

Sample Input and Output

Input Sample #1

8 0

Output Sample #1

8

Input Sample #2

24 210 0 255

Output Sample #2

130 1 129 2 129 9 136

Notes/Hints

$1 \leq n \leq 8 \times 10^4$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
8 0
样例输出
8