#include
#include
using namespace std;
int main()
{
int i,n;
while(scanf("%d",&a[++n])!=EOF);
for(i=n;i>=1;i--){
f[i][1]=max(f[i*2][0],f[i*2+1][0]);
f[i][0]=a[i]+max(max(f[i*2][0],f[i*2+1][0]),max(f[i*2][1],f[i*2+1][1]));
}
printf("%d\n",max(f[i][1],f[1][0]));
return 0;
}