- محدودیت زمان: ۱ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
We all love rabbits, right? Unfortunately, they don’t even like us, rather, they love carrots instead! They love carrots so much that they would do anything to get to a carrot, even running. That might sound easy, but rabbits are lazy, it’s the jackrabbits who are the active ones. That’s why this problem is about jackrabbits and not rabbits. In fact, it’s about a very specific black-tailed jackrabbit, named Slim.
Earlier this morning, before the contest started, a truck loaded with carrots passed through the road by Slim’s house. Slim was so lucky that carrots dropped off on the road. We number them to from left to right. When Slim left home, he found a carrot. After taking a look around, his plan for the day became clear: Locate the closest carrot, get to it and eat it, then repeat.
The road by Slim’s house is a straight road of length and the -th carrot on the road is at coordinate .
Consider Slim starts his day by standing at the position of the -th carrot and eating it. Then as long as there are more carrots, he follows the following steps:
- Locate the closest remaining carrot. If there are two closest carrots, choose the one to the right.
- Run to it and eat it. Simple! For each value of , we call the total distance Slim runs if it starts the day by eating carrot . For an unknown reason, we are interested in finding the sum of all values, for all values of ().
ورودی
The first line of the input contains a single integer (), the number of carrots. The second line of the input contains space-separated distinct integers (). The coordinates of the carrots are in an increasing order.
خروجی
Output an integer value, which is the sum of all values (for from through ).
مثال
ورودی نمونه ۱
خروجی نمونه ۱
ارسال پاسخ برای این سؤال