#include using namespace std; using ll = long long; using P = pair; #define rep(i, a, b) for(ll i = a; i < b; ++i) #define rrep(i, a, b) for(ll i = a; i >= b; --i) constexpr ll inf = 4e18; struct SetupIO { SetupIO() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(30); } } setup_io; int main(void) { ll n; cin >> n; vector a(n), even, odd; rep(i, 0, n) { cin >> a[i]; if(a[i] % 2 == 0) { even.push_back(a[i]); } else { odd.push_back(a[i]); } } sort(a.begin(), a.end()); sort(even.begin(), even.end()); sort(odd.begin(), odd.end()); vector cnt_even(even.size(), 1), cnt_odd(odd.size(), 1); rrep(i, (int)even.size() - 2, 0) { if(even[i + 1] - even[i] == 2) { cnt_even[i] = cnt_even[i + 1] + 1; } } rrep(i, (int)odd.size() - 2, 0) { if(odd[i + 1] - odd[i] == 2) { cnt_odd[i] = cnt_odd[i + 1] + 1; } } ll ans = n; rep(i, 0, n - 1) { if(a[i + 1] - a[i] != 1) continue; if(a[i] % 2 == 0) { ll idx = lower_bound(odd.begin(), odd.end(), a[i + 1]) - odd.begin(); ans += cnt_odd[idx]; } else { ll idx = lower_bound(even.begin(), even.end(), a[i + 1]) - even.begin(); ans += cnt_even[idx]; } } cout << ans << '\n'; }