#include using namespace std; int main() { int N; cin >> N; vector A(N); int K = N; for (int i = 0; i < N; i++){ cin >> A[i]; if (A[i] <= N){ K--; } } long long ans = 0; while (!A.empty()){ if (A.back() <= N){ break; } ans += A.back() - N - K + 1; K--; A.pop_back(); } cout << ans << '\n'; }