408516: GYM103176 I Ice-cream Sampler

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

I. Ice-cream Samplertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

[right] [/right]

Baskin Robbins is a ice-cream parlour brand. Most of the stores offer 31 different flavours, so that customers can try a different flavour every day in a month (note the 31 in the logo). However, the Baskin Robbins Brown in Cheongdam (Seoul, South Korea) offers 100 flavours.

Since there are too many flavours, they sell a ice-cream sampler which let customers try up to 10 flavours.

The flavours, numbered 1 to 100, are located around the counter. After taking your order at the Order point (orange cell), the staff have to scoop the ice-cream by walking to where the flavours are, one after another in any order. When all 10 scoops of ice cream are ready, the sampler is delivered to the Pick Up point (green cell). For some reason, the staff can only walk vertically and horizontally. Note that if two or more chosen flavours are located in the same cell, the staff can scoop all of them without moving. It is allowed to visit a point, including the Order and Pick Up point, more than once.

For example, if your ordered flavours 3, 13, 14, 16, 24, 39, 43, 46, 87, 99, one way that the staff can prepare your order is illustrated with the red arrows. The total walking distance is 37. In fact, this is one of the shortest paths. Given the 10 flavours chosen, can you help the staff minimize the walking distance?

Input

The input consists of 10 integers, between 1 and 100 inclusive, in a single line – the numbers of the 10 chosen flavours given in non-decreasing order. It's allowed for the customers to choose multiple scoops for the same flavour.

Output

Output a single integer – the minimum walking distance needed to scoop all 10 flavours, starting from the Order point and ending at the Pick Up point.

ExamplesInput
3 13 14 16 24 39 43 46 87 99
Output
37
Input
50 50 50 50 50 99 99 100 100 100
Output
15
Note

The first sample corresponds to the example in the problem statement.

In the second sample, the customer wants to have 5 scoops of flavour 50, 2 scoops of flavour 99 and 3 scoops of flavour 100.

加入题单

算法标签: