来源:牛客小白月赛45
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long a[10];
for(int i = 1;i<=8;i++) cin>>a[i];
long long ans = 0;
for(int i = 1;i<=8;i++)
{
if(a[i]%3 == 0 )
{
ans+=(a[i]*i);
a[i+1] += (a[i]/3);
}
else if(a[i]%3 == 1){
if(a[i]>1){
ans += a[i]*i;
a[i+1] += a[i]/3;
}
}
else{
if(a[i] == 5){
ans += 4*i;
a[i+1]++;
}
else if(a[i] == 2) continue;
else{
ans+=a[i]*i;
a[i+1] += a[i]/3;
}
}
}
cout<<ans;
return 0;
}