#include #define all(vec) vec.begin(), vec.end() using namespace std; using ll = long long; using P = pair; constexpr ll INF = (1LL << 30) - 1LL; constexpr ll LINF = (1LL << 60) - 1LL; constexpr ll MOD = 1e9 + 7; template void chmin(T &a, T b) { a = min(a, b); } template void chmax(T &a, T b) { a = max(a, b); } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector v; for (int i = 0; i < n; i++) { int b; cin >> b; for (int j = 0; j < b; j++) { v.push_back(i); } } ll res = 0; for (int i = 0; i < n; i++) { res += abs(v[i] - i); } cout << res << endl; }