#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int total = 0; for (int i = 0; i < n; i++) total += a[i]; int cnt = 1; for (int i = 1; ; cnt+=2, i++) if (total < i*i) break; cnt -= 2; int ans = 0; for (int i = 0; i < cnt/2 && i < n; i++) ans += max(0, a[i]-(i+1)); for (int i = cnt/2, j = cnt/2; i < cnt && i < n; i++,j--) ans += max(0, a[i]-(j+1)); for (int i = cnt; i < n; i++) ans += a[i]; cout << ans << endl; }