#include #include using namespace std; #define N 100 int n; int b[N * 2 + 1]; int t; int main() { cin >> n; for ( int i = 0; i < n; i++ ) { cin >> b[i]; t += b[i]; } int x = 0; int y = 0; while ( (x = x + y++ * 2 + 1) <= t ) {} y--; int z = 0; for ( int i = 0, j = (y - 1) * 2; i < y - 1; i++, j-- ) { z += max(0, b[i] - (i + 1)); z += max(0, b[j] - (i + 1)); } z += max(0, b[y - 1] - y); for ( int i = y * 2 - 1; i < n; i++ ) { z += b[i]; } cout << z << endl; return 0; }