Preparando MOJI

Necklace

2000ms 262144K

Description:

Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remaining after this cut is a palindrome (reads the same forward and backward).

Ivan has beads of n colors. He wants to make a necklace, such that it's beautiful relative to as many cuts as possible. He certainly wants to use all the beads. Help him to make the most beautiful necklace.

Input:

The first line of the input contains a single number n (1 ≤ n ≤ 26) — the number of colors of beads. The second line contains after n positive integers ai   — the quantity of beads of i-th color. It is guaranteed that the sum of ai is at least 2 and does not exceed 100 000.

Output:

In the first line print a single number — the maximum number of beautiful cuts that a necklace composed from given beads may have. In the second line print any example of such necklace.

Each color of the beads should be represented by the corresponding lowercase English letter (starting with a). As the necklace is cyclic, print it starting from any point.

Sample Input:

3
4 2 1

Sample Output:

1
abacaba

Sample Input:

1
4

Sample Output:

4
aaaa

Sample Input:

2
1 1

Sample Output:

0
ab

Note:

In the first sample a necklace can have at most one beautiful cut. The example of such a necklace is shown on the picture.

In the second sample there is only one way to compose a necklace.

Informação

Codeforces

Provedor Codeforces

Código CF613C

Tags

constructive algorithmsmath

Submetido 0

BOUA! 0

Taxa de BOUA's 0%

Datas 09/05/2023 09:03:07

Relacionados

Nada ainda