#include #include #include int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int N; std::cin >> N; std::vector round(N + 1); for (int i = 0; i < N; ++i) { int p; std::cin >> p; round[p] = i + 1; } long long ans = 0, sum = static_cast(N) * (N + 1) / 2; for (int i = N; i > 0; --i) { sum -= round[i]; ans = std::max(ans, sum - round[i]); } std::cout << ans << '\n'; }