#P9293. [ROI 2018] Addition without carry

[ROI 2018] Addition without carry

Background

Translated from ROI 2018 Day2 T4. Сложение без переносов (Addition without carry).

Problem Description

For a set containing only natural numbers, if the sum of all numbers in the set equals the bitwise OR\mathtt{OR} of all numbers in the set, then we call it a “beautiful set”.

Given a1ana_1 \ldots a_n, there exists a “beautiful set” consisting of the sequence b1bnb_1 \ldots b_n, such that:

For all i=1ni = 1 \ldots n, biaib_i \ge a_i, and
bi\sum b_i is minimized.

Find bi\sum b_i of the new sequence.

For convenience, the given aia_i are all in binary form, and your answer should also be in binary form.

Input Format

The first line contains an integer nn.

The next nn lines each contain a binary number aia_i.

Output Format

Output the resulting binary value of bi\sum b_i.

2
10
10
110
2
10100
1001
11101
3
1
1
110
1011

Hint

For all testdata, 1n3×1051 \le n \le 3 \times 10^5.

(In binary) the number of bits of aia_i does not exceed 3×1053 \times 10^5, and the sum of bit lengths of all aia_i does not exceed 3×1053 \times 10^5.

The subtask dependencies are for reference only. There are no subtask dependencies in the Luogu judging.

Constraints

Subtask Score nn maxL\max L Subtasks that must be passed
1 4 n=2n=2 maxL10\max L \le 10
2 2 maxL20\max L \le 20 1
3 maxL100\max L \le 100 1,2
4 maxL1000\max L \le 1000 1--3
5 maxL300000\max L \le 300\,000 1--4
6 4 n100n \le 100 maxL100\max L \le 100 Guaranteed that aia_i is a power of 22
7 n1000n \le 1000 maxL1000\max L \le 1000 6, guaranteed that aia_i is a power of 22
8 n300000n \le 300\,000 maxL300000\max L \le 300\,000 6,7, guaranteed that aia_i is a power of 22
9 n5n \le 5 maxL5\max L \le 5 U
10 maxL1000\max L \le 1\,000 U,1--4,9
11 n1000n \le 1\,000 maxL5\max L \le 5 U,9
12 n10n \le 10 maxL10\max L \le 10 U,1,9
13 n50n \le 50 maxL50\max L \le 50 U,1,2,9,12
14 7 n100n \le 100 maxL100\max L \le 100 U,1--3,6,9,12,13
15 n300n \le 300 maxL300\max L \le 300 U,1--3,6,9,12--14
16 8 n1000n \le 1000 maxL1000\max L \le 1000 U,1--4,6,7,9--15
17 n3000n \le 3000 maxL3000\max L \le 3000 U,1--4,6,7,9--16
18 6 n10000n \le 10\,000 maxL10000\max L \le 10\,000 U,1--4,6,7,9--17
19 7 n30000n \le 30\,000 maxL30000\max L \le 30\,000 U,1--4,6,7,9--18
20 n100000n \le 100\,000 maxL100000\max L \le 100\,000 U,1--4,6,7,9--19
21 6 n300000n \le 300\,000 maxL300000\max L \le 300\,000 U,1--20

Translated by ChatGPT 5