ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

2225. Nails in the House

Time limit: 1.0 second
Memory limit: 256 MB
Vadim’s home renovation is almost complete, and he only has to fully drive in N nails into one board. These nails are arranged in a single row, numbered from 1 to N, with the i-th nail being not driven in by li centimeters. Vadim has a hammer at his disposal. This hammer can hit two nails at a time, meaning one strike will always be over one pair of neighboring nails. If one nail in the pair is driven in less, it will be driven in by 1 cm. If both nails are equally not driven in, both will be driven in by 1 cm. The renovation needs to be finished as quickly as possible since Vadim is hosting a party at home in the evening. Help him find the minimum number of strikes required to drive in all the nails.

Input

The first line contains an integer N — the number of nails in the board (2 ≤ N ≤ 105).
The second line contains N integers li — the number of centimeters that the i-th nail is not driven in (1 ≤ li ≤ 109).

Output

Output the minimum number of strikes required to drive in all the nails.

Samples

inputoutput
3
4 1 3
7
4
2 2 6 6
8
Problem Author: Vadim Barinov
Problem Source: Ural Championship 2025