Under construction

Still being built. Things may change

Sandpile on Clique

Time limit1sMemory limit1024 MB

Summary
Given a clique with chip counts on each vertex, determine whether toppling never stops; if it stops, output the final chip count of every vertex.
Level

Hard9 of 10

Topics
Math, Sorting, Implementation
Solved
No attempts yet

Problem

The Abelian Sandpile Model is a well-known dynamical system that shows self-organized criticality. Per Bak, Chao Tang, and Kurt Wiesenfeld introduced it in a 1987 paper, and researchers have studied it for decades. The sandpile model draws interest in physics, computer science, and mathematics. Its algebraic structure is elegant, and it applies to load balancing and to the derandomization of models such as internal diffusion-limited aggregation. The model is also related to the rotor-routing model and avalanche models.

In the sandpile model, we are given an undirected graph GG whose vertices are numbered from 11 to nn. We are also given nn integers a1,a2,⋯ ,ana_1, a_2, \cdots, a_n, where aia_i is the number of chips initially placed on vertex ii.

Each turn, we pick any vertex vv whose chip count is at least dvd_v, the number of edges connected to vv. Each neighbor of vv receives one chip from vv, so vv loses dvd_v chips. This is called firing or toppling. Firing continues until no vertex vv has at least dvd_v chips.

The order of firing does not affect the result. However, firing may never terminate. In that case the instance is called "recurrent". You are given a clique (a complete graph, where every two vertices are connected by an edge) and the initial chip counts. Determine whether the instance is recurrent. If it is not, output the final chip count of each vertex.

Input

The first line contains an integer nn (2≤n≤5×1052 \le n \le 5 \times 10^5), the size of the clique.

The second line contains nn integers a1,a2,⋯ ,ana_1, a_2, \cdots, a_n (0≤ai≤1090 \le a_i \le 10^9), where aia_i is the initial number of chips on vertex ii.

There is only one test case per input file.

Output

If the firing terminates, output nn integers separated by spaces, where the ii-th integer is the final number of chips on vertex ii. Otherwise, output "Recurrent".

Hint

For the first sample, only vertex 1 can be chosen at the start. The chip counts become {1, 1, 4, 1, 4}.

Now vertex 3 or vertex 5 can be chosen, since both have at least 4 chips. Choosing vertex 3 gives {2, 2, 0, 2, 5}. Choosing vertex 5 gives the same result.

Next, vertex 5 is chosen, giving {3, 3, 1, 3, 1}. No vertex has at least 4 chips, so firing stops.

For the second sample, vertices 1 and 2 can be chosen repeatedly. Firing never terminates.

Examples2

  1. Example 1

    Input
    5
    5 0 3 0 3
    
    Expected output
    3 3 1 3 1
    
  2. Example 2

    Input
    2
    1 0
    
    Expected output
    Recurrent