#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 levels. Level contains 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 , the topmost level, is destroyed, then level , 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 , and let the values of the two crystals directly below it in the next level be (left) and (right). Then: if , the energy goes to the left crystal, whose value becomes ; if , the energy goes to the right crystal, whose value becomes .
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 — the number of levels of the Vision Pyramid, .
The next lines describe the levels of the pyramid. The -th line contains space-separated integers , where the -th integer is the dark energy stored in the -th crystal of that level, .
Output Format
Output 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