int[] a = new int[n]; long res = 0l; for(int i = 0; i < n; i++) { a[i] = in.nextInt(); res += a[i]; } for(int i = n-1; i >= 2; i--) { if(a[i] >= 3) { int t1 = a[i-2]; int t2 = Math.min(t1, a[i-1]/2); int t3 = Math.min(t2, a[i]/3); res -= t3; a[i] -= t3*3; a[i-1] -= t3*2; a[i-2] -= t3; } } System.out.println(res);