33OJ
登录 注册

#P17657. [IO 2025 #3] 幻象金字塔

[IO 2025 #3] 幻象金字塔

Problem Description

While investigating the mysterious events at Nevermore Academy, Wednesday found an old diary of the former principal, Larissa Weems. It described a magic ritual using a Vision Pyramid. The Vision Pyramid is an ancient artifact tied to the history of the cursed, and it can give Wednesday clues for her investigation.

The Vision Pyramid is a mysterious object consisting of nn levels. Level ii contains ii magic crystals, and the dark energy stored inside each crystal is represented by an integer.

The ritual destroys the pyramid according to the following rules:

  • The levels are destroyed one by one from top to bottom: first level 11, the topmost level, is destroyed, then level 22, and so on, until the second-to-last level is destroyed. The bottom level, the base, is not destroyed.
  • Within a level, the crystals pass their energy from left to right. After each transfer, the value of the corresponding crystal in the next level is updated immediately, and later transfers use the updated values.
  • To destroy a level, every crystal in that level must "pass" its energy to the stronger of the two crystals directly below it. Since this is dark energy, the crystal receiving the energy does not gain it — instead, the incoming energy is subtracted from it. In other words, let a crystal's value be xx, and let the values of the two crystals directly below it in the next level be aa (left) and bb (right). Then: if a>ba>b, the energy goes to the left crystal, whose value becomes a−xa-x; if a≤ba\le b, the energy goes to the right crystal, whose value becomes b−xb-x.

After the ritual is complete, the crystals of the Vision Pyramid's base will be filled with the required dark energy and reveal a prophecy about the fate of the academy and the secrets Larissa Weems has been hiding.

Wednesday completed the ritual successfully. Can you do it too?

Input Format

The first line contains an integer nn — the number of levels of the Vision Pyramid, 1≤n≤10001\le n\le 1000.

The next nn lines describe the levels of the pyramid. The ii-th line contains ii space-separated integers ai,ja_{i,j}, where the jj-th integer is the dark energy stored in the jj-th crystal of that level, ∣ai,j∣≤109|a_{i,j}|\le 10^9.

Output Format

Output nn integers — the dark energy of each crystal in the pyramid's base after the ritual is complete.

3
1
2 3
4 5 6
4 3 4
1
1000000000
1000000000
5
7
-5 2
-5 2 2
8 1 -4 8
8 -9 3 4 -2
-5 -9 18 -2 -2

Hint

Translated by QwenWork