#include #include #include #include #include #include #include using namespace std; typedef long long ll; int n; ll a[200000]; void input(){ cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; } ll dp[200000]; void solve(){ sort(a, a+n); ll ans = 0; int cnt = 0; for(int i = 0; i < n; i++){ if(i == 0 || a[i-1]+1 < a[i]){ if(cnt >= 2){ ans += dp[i-2]; } dp[i] = 1; cnt = 1; }else{ if(cnt == 1){ dp[i] = 1; }else{ dp[i] = dp[i-2]+1; } cnt++; } ans += dp[i]; // cout << dp[i] << ' '; } if(cnt >= 2){ ans += dp[n-2]; } // cout << endl; cout << ans << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; input(); solve(); }