#include #define endl '\n' using namespace std; const int MAXN = 1e5+5; int n; long long a[MAXN]; int main() { freopen("destruction.in", "r", stdin); freopen("destruction.out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a+1, a+n+1); // for (int i = 1; i <= n; i++) // cerr << a[i] << " "; cerr << endl; long long ans = 0; long long rem = 0, p = 0; priority_queue pq; for (int i = n; i >= 1; i--) { if (a[i] - rem > 0) { pq.push(i - (a[i] - rem) + 1); ans += a[i] - rem; rem += a[i] - rem; p++; } if (!pq.empty() && pq.top() == i) { pq.pop(); p--; } rem -= p; } cout << ans << endl; return 0; } /** 4 1 2 1 2 8 6 9 5 2 10 6 6 7 */