You are a player starting at Level 0 with 0 XP. You will perform N actions, and each action awards you a certain amount of experience points (XP).
The XP values for each type of actions are:
Leveling Up Mechanism
To advance from your current level to the next, you must consume XP equal to the square of the target level.
To reach Level 1 from Level 0, it costs 12 = 1 XP.
To reach Level 2 from Level 1, it costs 22 = 4 XP.
To reach Level 3 from Level 2, it costs 32 = 9 XP.
In general, to reach Level L+1, you must spend (L+1)2 XP.
As long as your current XP is enough to pay for the next level's cost, you must level up immediately and subtract the cost from your total XP. This process continues until you can no longer afford the next level.
Constraints
The first line is an integer N, the number of actions.
Then following by N lines, each containing a single number (1, 2, or 3), representing the action type.
An integer representing the player's final level with '\n'.