#include #include #include #include #include #include #include #include using namespace std; int main() { int n; cin >> n; vector p(n); for (int i = 0; i < n; i++) { cin >> p[i]; } long long ans = 0; for (int i = 0; i < n; i++) { int now = p[i] + 1; if (now > n) now = 1; if (now > p[i]) ans += (long long)(i + 1); else if (now < p[i]) ans -= (long long)(i + 1); } cout << ans << endl; return 0; }