#include #include using namespace std; #define rep(i, a, b) for(int i = a; i < b; i++) int main(void) { int i, j, n, tmp, sum=0, size; vector a, b; cin >> n; rep(i, 0, n) { cin >> tmp; a.push_back(tmp); sum += tmp; } // aから完成形bの要素を調べる int height = 0; for (size = 0, j = 1; size + j <= sum; j += 2) { size += j; height++; } int width = j - 2; // aとbを整形する while (a.size() < width) { a.push_back(0); } while (b.size() < width) { b.push_back(0); } int as = a.size(), bs = b.size(); for (i = 0, j = 1; i < width; i++) { b[i] = j; if (i < width / 2) { j++; } else { j--; } } int x = 0; rep(i, 0, as) { if (i < bs) { if (a[i] > b[i]) x += a[i] - b[i]; } else { x += a[i]; } } cout << x << endl; }