#include using namespace std; int main() { int N; cin >> N; vector> cnt; vector flag; for(int i = 0; i < N; i++) { int b; scanf("%d", &b); if(b == 0) flag.push_back(i); else if(b >= 2) cnt.push_back(make_pair(i, b-1)); } long long ans = 0; for(int i = 0; i < flag.size(); i++) { int idx = flag[i]; int jdx = 0; int minv = 1e8; for(int j = 0; j < cnt.size(); j++) { int c1 = cnt[j].first; int c2 = cnt[j].second; if(abs(idx-c1) < minv && c2 > 0) { jdx = c1; minv = abs(idx-c1); } } cnt[jdx].second -= 1; ans += (long long)minv; } cout << ans << endl; return 0; }