Given N separate integer points on the Cartesian plane satisfying: there is no any three of them sharing a same X-coordinate. Your task is to count the number of rectangles (whose edges parrallel to the axes) created from any four of given points.

Input

There are several test cases (ten at most), each formed as follows:

  • The first line contains a positive integer N (N ≤ 105).
  • N lines follow, each containing a pair of integers (each having an absolute value of 109 at most) describing coordinates of a given point.

The input is ended with N = 0.

Output

For each test case, output on a line an integer which is the respective number of rectangles found.

Example

Input:
6
7 1
3 5
3 1
1 5
1 1
7 5
0

Output:
3

Solution:

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
const double pi=acos(-1.0);
const double eps=1e-11;
template<class T> inline void checkmin(T &a,T b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,T b){if(b>a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> ipair;
#define SIZE(A) ((int)A.size())
#define LENGTH(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)

const int maxn=100000+5;

int n,m;
ipair p[maxn],g[maxn];

int main()
{
while (scanf(“%d”,&n)!=-1 && n!=0)
{
for (int i=0;i<n;i++) scanf(“%d%d”,&p[i].first,&p[i].second);
sort(p,p+n);
m=0;
for (int i=0;i+1<n;i++) if (p[i].first==p[i+1].first) g[m++]=MP(p[i].second,p[i+1].second);
sort(g,g+m);
int64 R=0;
for (int i=0;i<m;i++) if (i==0 || g[i]!=g[i-1])
{
int c=0;
for (int j=i;j<m && g[j]==g[i];j++) c++;
R+=(int64)c*(c-1)/2;
}
printf(“%lldn”,R);
}
return 0;
}