2293Shopping

2293   Shopping

题目描述

Saya and Kudo go shopping together.

You can assume the street as a straight line, while the shops are some points on the line.

They park their car at the leftmost shop, visit all the shops from left to right, and go back to their car.

Your task is to calculate the length of their route.

输入格式:

The input consists of several test cases.

The first line of input in each test case contains one integer N (0<N<100001), represents the number of shops.

The next line contains N integers, describing the situation of the shops. You can assume that the situations of the shops are non-negative integer and smaller than 2^30.

The last case is followed by a line containing one zero.

输出格式:

For each test case, print the length of their shopping route.

输入样例 复制
4
24 13 89 37
6
7 30 41 14 39 42
0
输出样例 复制
152
70

说明

Explanation for the first sample: They park their car at shop 13; go to shop 24, 37 and 89 and finally return to shop 13. The total length is (24-13) + (37-24) + (89-37) + (89-13) = 152

14
21
通过提交
时空限制1000ms/64mb
题目来源2010山东省赛
评测方式在线评测
题目类型
难        度