#include <bits/stdc++.h>
#define endl '\n'
#define fi first
#define se second
#define eb emplace_back
#define pb push_back
#define ALL(A) A.begin(), A.end()
#define FOR(i, l, r) for (int i = l; i <= r; i++)
#define FOR2(i, l, r) for (int i = l; i >= r; i--)
#define ce cout<<endl;
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using str = string;
using T = pair<ll,int>;
const ll INF = (ll)1e18;
const int N = 1e5;
// Author : T_Danh - Tri An High School
void solve1(){
int n, d , m;
cin >> n >> d >> m;
vector<int> cnt(m + 1 , 0);
FOR(i,1,n){
int pos ;
cin >> pos;
cnt[pos] ++ ;
}
ll cur = 0;
ll res = 0;
FOR(i,1,m){
res += cur * cnt[i];
cur += cnt[i];
res += cnt[i] * (cnt[i] - 1) / 2;
if(i > d){
cur -= cnt[i - d];
}
}
cout << res <<endl;
}
struct BIT{
int n;
vector<int> st;
BIT(int _n){
n = _n;
st.resize(n + 1 , 0 );
}
void upd(int x, int val){
for(;x <= n ; x += x & -x){
st[x] += val;;
}
}
ll get(int x){
ll cnt = 0;
for(;x > 0 ; x -= x & - x){
cnt += st[x];
}
return cnt;
}
ll query(int l , int r){
if(l > r) swap(l , r);
return get(r ) - get(l - 1 );
}
};
void solve2(){
int n , d, m;
cin >> n >> d >> m;
vector<pii> P(n);
vector<int> tmp;
FOR(i,0,n - 1){
int x , y;
cin >> x >> y;
P[i] = (make_pair(x + y , x - y));
tmp.eb(x + y);
tmp.eb(x - y);
}
sort(ALL(P));
sort(ALL(tmp));
tmp.erase(unique(ALL(tmp)) , tmp.end());
BIT st(tmp.size() + 1);
function<int(int)> id = [&](int x){
return lower_bound(ALL(tmp) , x) - tmp.begin() + 1;
};
ll res = 0;
int l = 0;
for(int r = 0 ; r < n ; ++ r){
while(l < r && P[r].fi - P[l].fi > d){
st.upd(id(P[l].se) , - 1);
l ++;
}
res += st.query(id(P[r].se - d) , id(P[r].se + d));
st.upd(id(P[r].se) , 1);
}
cout << res <<endl;
}
void solve3(){
}
void solve() {
int b;
cin >> b;
if(b == 1){
solve1();
}
else if(b == 2){
solve2();
}
else{
solve3();
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define NAME "odometer"
if (fopen(NAME".in", "r"))
freopen(NAME".in", "r", stdin),
freopen(NAME".out", "w", stdout);
int t = 1;
while (t--) {
solve();
}
return 0;
}