#include int main() { int n; scanf("%d", &n); int i; int p[3003]; for (i = 0; i < n; i++) { scanf("%d", &p[i]); p[i]--; } int a[3003]; for (i = 0; i < n; i++) a[p[i]] = i; int ans = 0; for (i = 0; i < n; i++) { while (p[i] != i) { ans++; a[p[i]] = a[p[i] - 1]; p[a[p[i] - 1]] = p[i]; p[i]--; a[p[i]] = i; } } printf("%d\n", ans); return 0; }