Cheap but Similar

Time limit7sMemory limit16 MB

Summary
Given a mineral row, decide whether equipment covering 1-3 consecutive cells can be placed to mine at least 75% of the total, and construct a valid placement if so.
Level

Hard8 of 10

Topics
Greedy, Dynamic programming, Simulation
Solved
No attempts yet

Problem

Mind the memory limit.

In 2077, a machine called the Sandevistan was developed. It connects to the nervous system and speeds up movement. Mineral X is essential to build it, but Mineral X is extremely expensive. One day, a way to build the same device with much cheaper Mineral Y was discovered, and many companies rushed to mine Mineral Y.

A vein containing Mineral Y is a straight line stretching left to right. The vein consists of NN cells. The ii-th cell from the left contains AiA_i units of mineral. The first cell (i=1i=1) has already been developed into a passage and contains no mineral, so A1=0A_1=0.

Mining requires equipment. One piece of equipment can mine all minerals in a consecutive segment of 1 to 3 cells that starts immediately to its right. The equipment must be installed in the cell immediately to the left of the mined segment. For safety reasons, minerals in a cell containing equipment cannot be mined, and equipment cannot be installed on a cell mined by another piece of equipment.

Let the total amount of mineral be S=∑i=1NAiS=\sum_{i=1}^{N} A_i. Determine whether it is possible to mine at least 0.75S0.75S minerals. If it is possible, output how to place the equipment and which cells to mine.

This image visualizes the first sample.

Input

The first line contains the number of test cases TT. (1≤T≤100 000)(1 \le T \le 100\,000)

For each test case, the first line contains the length NN of the vein. (1≤N≤20 772 077)(1 \le N \le 20\,772\,077)

The second line contains A1,A2,…,ANA_1,A_2,\dots,A_N, the mineral amounts in the cells, separated by spaces. (0≤Ai≤100,A1=0)(0 \le A_i \le 100, A_1=0)

The sum of NN over all test cases does not exceed 20 772 07720\,772\,077.

Output

For each test case, if there is no way to mine at least 0.75S0.75S minerals, print NO on the first line.

If there is a way, print YES on the first line. On the second line, print a string of length NN consisting only of the characters 0, 1, 2, and 3.

If the ii-th cell is not mined, the ii-th character must be 0. If the ii-th cell is mined by equipment whose mined segment has length kk, the ii-th character must be kk.

Hint

This was a hidden problem of SNUPC 2024. Look at the lower-right corner of the contest poster.

Examples1

  1. Example 1

    Input
    2
    8
    0 4 2 10 9 6 3 3
    2
    0 5
    
    Expected output
    YES
    01033301
    YES
    01