In the game of DotA (Defense of the Ancient), there are two opposite legions called The Sentinel and The Scourage.
Now The Scourage has made a big success and The Sentinel is at stake!
So The Sentinel must destroy the Well of Life of The Scourage.
The chief of The Sentinel, Prophet, asks EarthShaker to do this arduous task.
There are N Wells of Life of The Scourage (The Wells of Life are numbered from 1 to N), and EarthShaker’s task is to destroy the Nth Well of Life.
The following information is known about each Well of Life:
Wi – the weight of water on i-th Well of Life before it is destroyed.
Li – if the weight of water on i-th Well of Life is more than Li, the i-th Well of Life will be destroyed and the water of it will pours to the (i + 1)-th Well of Life.
Pi – EarthShaker has a skill called Echo-Slam, the i-th Well of Life will be immediately destroyed when he uses Echo-Slam to it and the water of it will pours to the (i + 1)-th Well of Life. For the i-th Well of Life, the energy that EarthShaker need to use Echo-Slam to destroy it is Pi.
Can you tell EarthShaker the minimum amount of energy needed to destroy the Nth Well of Life?