#include <iostream>
#include <unordered_map>
using namespace std;
int main() {
int n, ans = 0;
cin >> n;
unordered_map<int, int> hashset;
for (int i = 0; i < n; i++) {
int cur;
cin >> cur;
ans += hashset[cur - 1] + hashset[cur + 1];
hashset[cur] = 1;
}
cout << ans << endl;
return 0;
}