#include using namespace std; using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; set s; for (int i = 0; i < n; i++) { ll a; cin >> a; s.insert(a); } map mp; ll ans = n; for (auto &f : s) { ll count = 0; if (s.find(f - 1) != s.end()) count++; if (mp.find(f - 1) != mp.end()) count += mp[f - 1]; mp[f + 1] = count; ans += count; } cout << ans << '\n'; }