#include using namespace std; int main(){ int N; cin >> N; vector B(N); for (int i = 0; i < N; i++){ cin >> B[i]; } vector P; for (int i = 0; i < N; i++){ for (int j = 0; j < B[i]; j++){ P.push_back(i); } } long long ans = 0; for (int i = 0; i < N; i++){ ans += abs(P[i] - i); } cout << ans << endl; }