using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static long ProcessEven(long size) { long moves = 0; // initial break is a move moves++; // how many 2 size pieces we can break off var subPieces = size / 2; // breaking each subPiece is a move moves += subPieces; // it takes 2 moves to each eat subPiece moves += subPieces * 2; return moves; } static long longestSequence(long[] a) { // Return the length of the longest possible sequence of moves. // Return the length of the longest possible sequence of moves. long moves = 0; // loop through and deal with once piece at a time for (var i = 0; i < a.Length; i++) { // first check the lenth, a single length just gets eaten if (a[i] == 1) { moves++; } // two lengths, gets broken (1 move) then eaten (2 moves, 1 for each piece), for three in total else if (a[i] == 2) { moves += 3; } // check the length, if its even we can split in half else if (a[i] % 2 == 0) { moves += ProcessEven(a[i]); } // we have an odd length, so break one piece off to get an even count else { // odd pieces we break into one length in one move and then eat them moves += a[i] + 1; } } return moves; } static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); string[] a_temp = Console.ReadLine().Split(' '); long[] a = Array.ConvertAll(a_temp,Int64.Parse); long result = longestSequence(a); Console.WriteLine(result); } }