#!/bin/python3 import sys import math def is_valid(p_list): if len(p_list) == 1: return True max = p_list[0] if max > 2: return True i = len(p_list)-1 while True: if p_list[-i]: min = p_list[-i] break; i += 1 if max == min and max == 1: return True if max == 2 and min == 1: return False return True def reconstruct(pieces): if len(pieces) == 1: return pieces new_l = [] for i in range(0,len(pieces),2): new_l.append(pieces[i]+pieces[i+1]) if is_valid(new_l): return new_l return reconstruct(new_l) def calculate_stick(stick): total = stick pieces = [1] * stick x = math.log2(stick) if x != math.floor(x): z = [0] * (2**math.ceil(x) - len(pieces)) pieces = pieces + z #if stick % 2 == 1: # pieces += [0] #print(pieces) while True: pieces = reconstruct(pieces) #print(pieces) l = len(pieces) if l == 1: total += l break else: total += l return total def longestSequence(a): # Return the length of the longest possible sequence of moves. total = 0 for stick in a: total += calculate_stick(stick) return total if __name__ == "__main__": n = int(input().strip()) a = list(map(int, input().strip().split(' '))) result = longestSequence(a) print(result)