#include #include #include using namespace std; int main() { int n; cin >> n; long long ans = 0; for (int i = 0, c = 0; i < n; i++) { int b; cin >> b; while (b--) ans += abs(i-c), c++; } cout << ans << endl; }