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.
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.
A single integer, the total damage that Santa's sleigh creates on Speedway.
2 2 1
3 3 1 2
Provider CodeForces Gym
AC Rate 0%
Date 10/31/2021 14:46:37