import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static long longestSequence(long[] a) { int len = a.length, flag; long n, r, sum = 0; for(int i=0;i1){ sum += n/2; n /= 2; } sum += a[i]; } } return sum; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; int n = Integer.parseInt(br.readLine()); long[] a = new long[n]; st = new StringTokenizer(br.readLine()); for(int a_i = 0; a_i < n; a_i++){ a[a_i] = Long.parseLong(st.nextToken()); } long result = longestSequence(a); System.out.println(result); br.close(); return; } }