package cn.itcast.girl.TheBlueCup_02;
import java.util.Scanner;
public class DailyClock {
// static int exp = 0;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int exp = 0;
int accumulative = 0;
int noPunchClock = 0;
int day[] = new int[n];
int score[] = new int[]{0,1,3,7,30,120,365};
for(int i=0;i<n;i++) {
day[i] = sc.nextInt();
}
for(int i=0;i<n;i++) {
if(day[i]==1) {
if(noPunchClock>0) accumulative -= Math.pow(2, noPunchClock-1);
if(accumulative<0) accumulative=0;
noPunchClock = 0;
accumulative++;
int index = 0;
for(int j=6;j>=1;j--) {
if(accumulative>=score[j]) {
index = j;
break;
}
}
exp += index;
}else {
noPunchClock++;
}
}
System.out.println(exp);
sc.close();
}
}