#Q145. 「一本通 4.6 例 1」营业额统计
「一本通 4.6 例 1」营业额统计
Description
Original Source: HNOI 2002
Tiger was recently promoted to the position of sales manager at his company. The first task assigned to him after his promotion was to analyze the company's sales performance since its establishment.
Tiger pulled out the company's ledger, which records the daily sales since the company was founded. Analyzing sales performance is a complex task. Due to holidays, promotions, or other circumstances, sales figures can fluctuate. While some fluctuations are normal, extreme spikes or drops in sales indicate potential operational issues.
In economics, a metric called the minimum fluctuation value is used to measure this situation: let be the sales on a previous day, and be the sales on the current day. The minimum fluctuation value for the current day is defined as . The larger the minimum fluctuation value, the more unstable the sales performance. To assess the overall stability of the company's sales performance from its establishment to the present, we simply sum up the minimum fluctuation values for each day.
Your task is to write a program to help Tiger compute this value. The minimum fluctuation value for the first day is defined as the sales on that day.
Simplified Problem Statement
Given a sequence of numbers, for each element (where ), define for , and . Compute the sum .
Input Format
The first line contains a positive integer, representing the number of days since the company's establishment;
The next lines each contain an integer, representing the company's sales on the -th day, .
Output Format
Output a single positive integer, the sum of the minimum fluctuation values for each day. The result is guaranteed not to exceed .
Sample 1
6
5
1
2
5
4
6
12
Data Range and Hints
For all data, and .