408907: GYM103379 C Sled Tracks
Description
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.
InputThe 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.
OutputA single integer, the total damage that Santa's sleigh creates on Speedway.
ExamplesInput2 2 1Output
1Input
3 3 1 2Output
3