#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MAXN 100005 typedef pair Point; #define x first #define y second int N; map rows, cols; vector R[MAXN]; vector C[MAXN]; Point P[MAXN]; tr1::unordered_set H; long long calcHash(int x, int y) { // cerr << x << "," << y << " => " << (((long long)x) << 32) + y << endl; return (((long long)x) << 32) + y; } int goNE(int x, int y, int dx, int dy) { int ret = 0; int r = rows[y]; int c = cols[x]; int rIdx = upper_bound(R[r].begin(), R[r].end(), x) - R[r].begin(); int cIdx = upper_bound(C[c].begin(), C[c].end(), y) - C[c].begin(); int leftR = (int)R[r].size() - rIdx; int leftC = (int)C[c].size() - cIdx; if(leftR <= leftC) { for(; rIdx < (int)R[r].size(); rIdx++) { int d = abs(R[r][rIdx] - x); if(H.count(calcHash(x, y + dy * d)) == 1) ret++; } } else { for(; cIdx < (int)C[c].size(); cIdx++) { int d = abs(C[c][cIdx] - y); if(H.count(calcHash(x + dx * d, y)) == 1) ret++; } } return ret; } int goNW(int x, int y, int dx, int dy) { int ret = 0; int r = rows[y]; int c = cols[x]; int rIdx = lower_bound(R[r].begin(), R[r].end(), x) - R[r].begin() - 1; int cIdx = upper_bound(C[c].begin(), C[c].end(), y) - C[c].begin(); int leftR = rIdx + 1; int leftC = (int)C[c].size() - cIdx; if(leftR <= leftC) { for(; rIdx >= 0; rIdx--) { int d = abs(R[r][rIdx] - x); if(H.count(calcHash(x, y + dy * d)) == 1) ret++; } } else { for(; cIdx < (int)C[c].size(); cIdx++) { int d = abs(C[c][cIdx] - y); if(H.count(calcHash(x + dx * d, y)) == 1) ret++; } } return ret; } int goSE(int x, int y, int dx, int dy) { int ret = 0; int r = rows[y]; int c = cols[x]; int rIdx = upper_bound(R[r].begin(), R[r].end(), x) - R[r].begin(); int cIdx = lower_bound(C[c].begin(), C[c].end(), y) - C[c].begin() - 1; int leftR = (int)R[r].size() - rIdx; int leftC = cIdx + 1; if(leftR <= leftC) { for(; rIdx < (int)R[r].size(); rIdx++) { int d = abs(R[r][rIdx] - x); if(H.count(calcHash(x, y + dy * d)) == 1) ret++; } } else { for(; cIdx >= 0; cIdx--) { int d = abs(C[c][cIdx] - y); if(H.count(calcHash(x + dx * d, y)) == 1) ret++; } } return ret; } int goSW(int x, int y, int dx, int dy) { int ret = 0; int r = rows[y]; int c = cols[x]; int rIdx = lower_bound(R[r].begin(), R[r].end(), x) - R[r].begin() - 1; int cIdx = lower_bound(C[c].begin(), C[c].end(), y) - C[c].begin() - 1; int leftR = rIdx + 1; int leftC = cIdx + 1; if(leftR <= leftC) { for(; rIdx >= 0; rIdx--) { int d = abs(R[r][rIdx] - x); if(H.count(calcHash(x, y + dy * d)) == 1) ret++; } } else { for(; cIdx >= 0; cIdx--) { int d = abs(C[c][cIdx] - y); if(H.count(calcHash(x + dx * d, y)) == 1) ret++; } } return ret; } int main() { // freopen("date.in", "r", stdin); // freopen("date.out","w", stdout); scanf("%d", &N); for(int i = 0; i < N; i++) { scanf("%d %d", &P[i].x, &P[i].y); H.insert(calcHash(P[i].x, P[i].y)); if(rows.count(P[i].y) == 0) rows[ P[i].y ] = (int)rows.size(); if(cols.count(P[i].x) == 0) cols[ P[i].x ] = (int)cols.size(); int r = rows[ P[i].y ]; int c = cols[ P[i].x ]; R[r].push_back(P[i].x); C[c].push_back(P[i].y); } int ans = 0; for(int i = 0; i < N; i++) { ans += goNE(P[i].x, P[i].y, 1, 1); ans += goNW(P[i].x, P[i].y, -1, 1); ans += goSE(P[i].x, P[i].y, 1, -1); ans += goSW(P[i].x, P[i].y, -1, -1); } printf("%d\n", ans); return 0; }