// O(N^2)解法 #include using namespace std; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector odd, even; for (int i = 0; i < n; i++) { ll a; cin >> a; if (a % 2 == 1) odd.emplace_back(a); else even.emplace_back(a); } sort(odd.begin(), odd.end()); sort(even.begin(), even.end()); // sentinel odd.emplace_back(2e18 - 1); even.emplace_back(2e18); ll ans = n; int even_it = 0; for (int i = 0; i < odd.size() - 1; i++) { while (even.at(even_it) <= odd.at(i)) even_it++; if (even.at(even_it) == odd.at(i) + 1) { ll keep = 1, it2 = even_it; while (true) { if (even.at(it2) + 2 == even.at(it2 + 1)) { keep++; it2++; } else { break; } } ans += keep; } } int odd_it = 0; for (int i = 0; i < even.size() - 1; i++) { while (odd.at(odd_it) <= even.at(i)) odd_it++; if (odd.at(odd_it) == even.at(i) + 1) { ll keep = 1, it2 = odd_it; while (true) { if (odd.at(it2) + 2 == odd.at(it2 + 1)) { keep++; it2++; } else { break; } } ans += keep; } } cout << ans << '\n'; }