#P9575. 「TAOI-2」喵了个喵 Ⅳ

    ID: 10176 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>数学2023洛谷原创Special JudgeO2优化构造洛谷月赛Ad-hoc

「TAOI-2」喵了个喵 Ⅳ

Background

Xiao S has a total of nn cute cats. The ii-th cat has cuteness aia_i. Xiao S wants to split his cats into two groups. Considering that Xiao S's cats are not like some cats that have nine lives, each of his cats has only one life, so a cat cannot be put into both groups at the same time (please do not try to imagine this scene). Also, if a cat is not assigned to any group, it will be very angry, and it may very likely cause Xiao S to suffer from insomnia.

Of course, Xiao S also hopes that the two groups have the same group cuteness. That is, there exists a positive integer xx such that the sum of gcd(x,ai)\gcd(x, a_i) in one group equals the sum of gcd(x,ai)\gcd(x, a_i) in the other group. Please determine whether Xiao S can split the cats into two groups, and whether you can find an xx that makes the group cuteness of the two groups equal.

Problem Description

Given a positive integer nn and a sequence aa of nn positive integers, please partition aa into two sets B,CB, C and give a positive integer xx such that yBgcd(x,y)=yCgcd(x,y)\sum_{y\in B}\gcd(x,y) = \sum_{y\in C}\gcd(x,y). If there is no solution, output 1-1.

You need to guarantee 1x1091 \leq x \leq 10^9. It is guaranteed that under this problem's Constraints, if a solution exists then there is always a solution with x109x \leq 10^9.

Input Format

The first line contains one positive integer nn.

The next line contains nn positive integers, where the ii-th one denotes aia_i.

Output Format

If there is no solution, output a single line with the integer 1-1. Otherwise:

The first line outputs one positive integer xx.

The second line outputs a 01\tt 01 string of length nn. The ii-th character is 0\tt 0 meaning that aia_i is placed into set BB, and 1\tt 1 meaning that aia_i is placed into set CC.

3
1 1 1
-1
4
4 1 2 3
3
0001

Hint

This problem uses bundled testdata.

  • Subtask 0 (2 pts): nn is even.
  • Subtask 1 (8 pts): all aia_i are odd.
  • Subtask 2 (15 pts): n50n \leq 50, ai50a_i \leq 50.
  • Subtask 3 (25 pts): n103n \leq 10^3, ai103a_i \leq 10^3.
  • Subtask 4 (50 pts): no special restrictions.

For all testdata, 1n1051 \leq n \leq 10^5, 1ai1061 \leq a_i \leq 10^6.

Translated by ChatGPT 5