408907: GYM103379 C Sled Tracks

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Sled Trackstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Santa needs to deliver gifts to all the inhabitants of Speedway! Unfortunately, as it doesn't snow on Speedway (mostly), his sleigh will damage the nice brickwork!

As we all know, Speedway is built in a line, conveniently segmented into $$$N$$$ locations. Although speedy, Santa's delivery system hasn't been fully optimized, so he travels back-and-forth to deliver these gifts.

Beginning at the first provided location, Santa will travel between all $$$N$$$ of these locations. When Santa travels between a location $$$A$$$ and $$$B$$$, he creates one unit of damage at each location between $$$A$$$ and $$$B$$$ (including $$$A$$$, not including $$$B$$$).

To help the UT Maintenance team, please determine how much total damage is caused by Santa's sleigh.

Input

The first line of input contains a single integer $$$N$$$, where $$$2 \leq N \leq 1000$$$.

Then $$$N$$$ more lines follow, each containing a single integer, representing all the buildings in the order in which he visits them.

Output

A single integer, the total damage that Santa's sleigh creates on Speedway.

ExamplesInput
2
2
1
Output
1
Input
3
3
1
2
Output
3

加入题单

上一题 下一题 算法标签: