#C9852. Total Crystal Power
Total Crystal Power
Total Crystal Power
In a distant land, a curious game is played with magical crystals and spells. Every player starts with a single crystal of power 1. They can cast spells that either increase the power of an existing crystal or summon a new crystal with a specified power.
There are two types of spells:
- increase i d: Increase the power of the i-th crystal by d.
- new p: Create a new crystal with power p.
After all spells are cast, calculate the total power of all crystals.
Note: The crystals are 1-indexed. Initially, only one crystal (with power 1) exists.
inputFormat
The input is read from standard input and has the following format:
- The first line contains a single integer
n
(0 ≤ n ≤ 105), representing the number of spells. - The following
n
lines each contain a spell command. Each command is either: increase i d
wherei
is the 1-indexed crystal to increase andd
is the amount to add.new p
wherep
is the power of the new crystal to be added.
outputFormat
Output a single integer representing the total power of all crystals after processing all spells. The output is printed to standard output.
## sample1
increase 1 3
4
</p>