## WC '18 Contest 1 J4 - Germaphobia

View as PDF

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 16M

Author:
Problem type
##### Woburn Challenge 2018-19 Round 1 - Junior Division

H.S. High School has classrooms in a row, numbered from 1 to in order. There's a common hallway outside the classrooms with a door to each one, meaning that it's possible to move from the hallway to any classroom (or vice versa) by passing through a door. There's also a door between each pair of adjacent classrooms and (for each ), meaning that it's possible to move between them in either direction by passing through that door.

For example, if , the school layout looks as follows (with the 4 numbered classrooms at the top, the hallway at the bottom, and doors indicated in brown):

Today, Bob has classes to attend, one after another, with the -th one held in classroom . Multiple classes throughout the day may be held in the same classroom, but no pair of consecutive classes are held in the same classroom as one another (in other words, for each ).

Upon entering the school in the morning, Bob finds himself in the hallway, and will then need to move into his classes' classrooms in order (in other words, he'll need to visit classroom , then classroom , and so on). He may freely visit other classrooms or the hallway in between the classes he needs to attend. After attending the -th class, Bob will need to move back into the hallway before heading home.

Bob is well aware of the alarming volume of germs present on school doorknobs, so he'd like to pass through as few doors as possible throughout the day. Help Bob determine the minimum number of doors he must pass through in total.

#### Input Specification

The first line of input consists of two space-separated integers, and .
lines follow, the -th of which consists of a single integer, , for .

#### Output Specification

Output a single integer, the minimum number of doors which Bob must pass through in total.

#### Sample Input

4 5
2
3
1
4
3

#### Sample Output

8

#### Sample Explanation

One optimal route Bob might take is as follows:

Hallway Classroom 2 Classroom 3 Classroom 2 Classroom 1 Hallway Classroom 4 Classroom 3 Hallway