#include #define rep(i, l, r) for (int i = (l); i < (r); i++) using namespace std; typedef long long ll; int main() { int N; cin >> N; vector P(N); rep(i, 0, N) cin >> P[i]; if (N == 1) { cout << 0 << endl; return 0; } if (N == 2) { if (P[0] == 1) cout << 0 << endl; else cout << 1 << endl; return 0; } ll ans = 0; rep(i, 0, N) { if (P[i] == N) ans -= i + 1; else ans += i + 1; } cout << ans << endl; }