CF201C.Fragile Bridges

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are playing a video game and you have just reached the bonus level, where the only possible goal is to score as many points as possible. Being a perfectionist, you've decided that you won't leave this level until you've gained the maximum possible number of points there.

The bonus level consists of nn small platforms placed in a line and numbered from 11 to nn from left to right and ( n1n-1 ) bridges connecting adjacent platforms. The bridges between the platforms are very fragile, and for each bridge the number of times one can pass this bridge from one of its ends to the other before it collapses forever is known in advance.

The player's actions are as follows. First, he selects one of the platforms to be the starting position for his hero. After that the player can freely move the hero across the platforms moving by the undestroyed bridges. As soon as the hero finds himself on a platform with no undestroyed bridge attached to it, the level is automatically ended. The number of points scored by the player at the end of the level is calculated as the number of transitions made by the hero between the platforms. Note that if the hero started moving by a certain bridge, he has to continue moving in the same direction until he is on a platform.

Find how many points you need to score to be sure that nobody will beat your record, and move to the next level with a quiet heart.

输入格式

The first line contains a single integer nn ( 2<=n<=1052<=n<=10^{5} ) — the number of platforms on the bonus level. The second line contains ( n1n-1 ) integers aia_{i} ( 1<=ai<=1091<=a_{i}<=10^{9} , 1<=i<n ) — the number of transitions from one end to the other that the bridge between platforms ii and i+1i+1 can bear.

输出格式

Print a single integer — the maximum number of points a player can get on the bonus level.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

输入输出样例

  • 输入#1

    5
    2 1 2 1
    

    输出#1

    5
    

说明/提示

One possibility of getting 55 points in the sample is starting from platform 33 and consequently moving to platforms 44 , 33 , 22 , 11 and 22 . After that the only undestroyed bridge is the bridge between platforms 44 and 55 , but this bridge is too far from platform 22 where the hero is located now.

首页