n=1000
bhisop_board = [[0 for i in range(n)] for j in range(n)]
t = int(input())
for i in range(t):
x,y = map(int,input().split())
bhisop_board[x-1][y-1] = 1
total_attacks=0
for i in range(1,n):
curr_diag_bhisops_count=0
for j in range(i+1):
if bhisop_board[i-j][j]==1:
curr_diag_bhisops_count+=1
total_attacks+=(curr_diag_bhisops_count*(curr_diag_bhisops_count-1))//2
for j in range(1,n):
curr_diag_bhisops_count=0
for i in range(n-j):
if bhisop_board[n-1-i][j+i]==1:
curr_diag_bhisops_count+=1
total_attacks+=(curr_diag_bhisops_count*(curr_diag_bhisops_count-1))//2
for i in range(n-1,0,-1):
curr_diag_bhisops_count=0
for j in range(n-i):
if bhisop_board[i+j][j]==1:
curr_diag_bhisops_count+=1
total_attacks+=(curr_diag_bhisops_count*(curr_diag_bhisops_count-1))//2
for j in range(n):
curr_diag_bhisops_count=0
for i in range(n-j):
if bhisop_board[i][j+i]==1:
curr_diag_bhisops_count+=1
total_attacks+=(curr_diag_bhisops_count*(curr_diag_bhisops_count-1))//2
print(total_attacks)
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ll long long
#define endl '\n'
#define ld long double
#define pq priority_queue
#define pb emplace_back
#define Fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define loop(i, s, n) for(int i=s;i<n;i++)
#define rloop(i, s) for(int i=s;i>=0;i--)
#define sz(s) (int)s.size()
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<int, null_type,less_equal<>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<int, null_type,less<>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k): It returns to an iterator to the kth element
//order_of_key(k) : It returns to the number of items that are strictly smaller than our item k
ll mod = 1073741824;
const int N = 1e6 + 7;
ll inf = 1e18;
ll mul(ll a, ll b){return (a % mod) * (b % mod) % mod;}
ll fastpow(ll a, ll b){if (b == 0)return 1;ll x = fastpow(a, b / 2);if (b % 2)return x * x * a;return x * x;}
ll fastpowmod(ll a, ll b, ll m){if (b == 0)return 1;ll x = fastpowmod(a, b / 2, m);if (b % 2)return mul(mul(x, x), a);return mul(x, x);}
ll extended_euc(ll a, ll b, ll &x, ll &y){if (a < 0){ll r = extended_euc(-a, b, x, y);x *= -1;return r;}if (b < 0){ll r = extended_euc(a, -b, x, y);y *= -1;return r;}if (b == 0){x = 1;y = 0;return a;}ll x1, y1;ll d = extended_euc(b, a % b, x1, y1);x = y1;y = x1 - y1 * (a / b);return d;}
ll dio(ll a, ll b, ll c, ll &x, ll &y, ll &found){ll g = extended_euc(a, b, x, y);found = c % g;if (found == 0){x *= c / g;y *= c / g;}return g;}
// ax=b(mod n)
// solve for x
vector<ll> modularequation(ll a, ll b, ll n){vector<ll> sol;ll x, y, g;g = extended_euc(a, n, x, y);if (b % g != 0)return sol;x = ((x * b / g) % n + n) % n;for (int i = 0; i < g; i++){sol.pb((x + i * n / g) % n);}sort(all(sol));return sol;}
ll inv(ll a, ll m){ll x, y;extended_euc(a, m, x, y);return (x % m + m) % m;}
ll inv2(ll a, ll m){return fastpowmod(a, m - 2, m);}
ll comb(ll n, ll m){ll z = 1;for (ll i = 1; i <= m; ++i){z = mul(mul(z, n - m + i), inv(i, mod));}return z;}
ll com(ll n, ll r){if (n < r)return 0;if (n == 1)return 1;if (r == 0)return 1;if (r == 1)return n;return (com(n - 1, r - 1) % mod + com(n - 1, r) % mod) %mod;}
int div(int A, int B, int M){if (A % M == 0)return (B / M) - (A / M) + 1;return (B / M) - (A / M);}
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
ll lcm(ll a, ll b){return a / gcd(a, b)*b;}
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
auto cmp=[](int a,int b)
{
return a>b;
};
int main()
{
Fast;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int tc = 1;
//cin >> tc;
while (tc--)
{
int n;
cin>>n;
vector<int> d1(2001),d2(2001);
loop(i,0,n)
{
int x,y;
cin>>x>>y;
int r1,c1,r2,c2;
int mn=min(x-1,1000-y);
r1=x-mn,c1=y+mn;
d1[r1+c1-1]++;
mn=min(1000-x,1000-y);
r2=x+mn,c2=y+mn;
d2[1000-r2+c2]++;
}
ll ans=0;
loop(i,1,2002)
{
ll x=d1[i];
ll y=d2[i];
ans+=x*(x-1)/2;
ans+=y*(y-1)/2;
}
cout<<ans<<endl;
}
}
921. Minimum Add to Make Parentheses Valid | 881. Boats to Save People |
497. Random Point in Non-overlapping Rectangles | 528. Random Pick with Weight |
470. Implement Rand10() Using Rand7() | 866. Prime Palindrome |
1516A - Tit for Tat | 622. Design Circular Queue |
814. Binary Tree Pruning | 791. Custom Sort String |
787. Cheapest Flights Within K Stops | 779. K-th Symbol in Grammar |
701. Insert into a Binary Search Tree | 429. N-ary Tree Level Order Traversal |
739. Daily Temperatures | 647. Palindromic Substrings |
583. Delete Operation for Two Strings | 518. Coin Change 2 |
516. Longest Palindromic Subsequence | 468. Validate IP Address |
450. Delete Node in a BST | 445. Add Two Numbers II |
442. Find All Duplicates in an Array | 437. Path Sum III |
436. Find Right Interval | 435. Non-overlapping Intervals |
406. Queue Reconstruction by Height | 380. Insert Delete GetRandom O(1) |
332. Reconstruct Itinerary | 368. Largest Divisible Subset |