#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ff(i,s,e) for(int i=(s);i<(int)(e);i++)
#define fr(i,s,e) for(int i=(e);i-->(int)(s);)
#define FF(i,s,e) for(int i=(s);i<=(int)(e);i++)
#define Fr(i,s,e) for(int i=(e);i>=(int)(s);i--)

#define gcd(a,b) __gcd(a,b)
#define all(a) a.begin(),a.end()
#define ln putchar('\n')
#define sp putchar(' ')
using namespace __gnu_pbds;
using namespace std;

void init(int i){
#ifndef ONLINE_JUDGE
  char str[100];sprintf(str,"xx/%d.txt",i);freopen(str,"r",stdin);
#endif
}

typedef tree<int,int,less<int>,rb_tree_tag,tree_order_statistics_node_update>imap;

typedef long long ll;

typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;

template<class T>inline int pr(const T&v);
template<class T, class...Args> inline int pr(const T&a,const Args (&... args));

inline int scan(int&i){return scanf("%d",&i);}
inline int scan(ll&i){return scanf("%" PRId64,&i);}
inline int scan(double&i){return scanf("%lf",&i);}
inline int scan(char&i){int c;while((c=getchar())!=EOF&&c<=' ');i=c;return c!=EOF;}
inline int scan(string&i){i.clear();int c;while((c=getchar())!=EOF&&c<=' ');while(c>' ')i+=c,c=getchar();return i.size();}
inline int scanln(string&i){i.clear();int c;while((c=getchar())!=EOF&&c<' ');while(c>=' ')i+=c,c=getchar();return i.size();}
template<class T> inline int scan(T&a){a.sc();}
template<class T, class U> inline int scan(pair<T,U>&a){scan(a.first),scan(a.second);}

inline int pr(const int& i){printf("%d",i);}
inline int pr(const long& i){printf("%ld",i);}
inline int pr(const unsigned int& i){printf("%x",i);}
inline int pr(const bool i){printf("%d",i);}
inline int pr(const ll&i){printf("%" PRId64,i);}
inline int pr(const double&i){printf("%.12f",i);}
inline int pr(const float&i){printf("%.4f",i);}
inline int pr(const char&i){putchar(i);}
inline int pr(const char*i){printf("%s",i);}
inline int pr(const string&i){for(char c:i)pr(c);}

template<class T>inline int scan(vector<T>&v){for(T&i:v)scan(i);}
template<class T>inline int pr(const vector<T>&v){if(v.empty())return 0;pr(v[0]);ff(i,1,v.size())pr(' '),pr(v[i]);}
template<class T,class U>inline int pr(const pair<T,U>&p){pr(p.first,p.second);}
template<class T>inline int prlns(const vector<T>&v){ff(i,0,v.size())pr(v[i]),pr('\n');}
template<class T, class...Args> inline int scan(T&a,Args (&... args)){return scan(a),scan(args...);}
template<class T, class...Args> inline int pr(const T&a,const Args (&... args)){pr(a),pr(' '),pr(args...);}
template<class T> inline int prln(const T&a){pr(a),ln;}
template<class T, class...Args> inline int prln(const T&a,const Args (&... args)){pr(a),sp,prln(args...);}
template<class...Args> inline int rpr(const Args (&... args)){
#ifndef ONLINE_JUDGE
  pr(args...),ln;fflush(stdout);
#endif
}
inline int gi(){int x;scan(x);return x;}

template<class T>inline int pr(const T&v){v.print();}

template<class T, class U> inline void smax(T&a,const U&b){if(a<b)a=b;}
template<class T, class U> inline void smin(T&a,const U&b){if(b<a)a=b;}

template<class T> T& operator +=(vector<T>&v,const T&a){v.push_back(a);return v.back();}

const int inf = ~((1<<31));
const ll LargeMod = 4611686018427388039;
const ll MOD = 1E9+7;
const ll linf = 1E17;
typedef unsigned int uint;

struct problem{
  int n, k;
  int sz;
  vi v;
  set<pii> m;
  int solve() {
    double ma = 0, mi = 1E9;
    int q = gi();
    ff(xx,0,q){
      double res = 0;
      ff(ll,0,sz){
        int t = gi() - 1;
        int val = v[t];
        m.erase({val, t});
        res += val;
      }
      if (res == -1)continue;
      smax(ma, res/sz);
      smin(mi, res/sz);
    }
    if (m.size() >= sz) {
      auto k = m.begin();
      double res = 0;
      ff(i,0,sz)res += k->first, k++;
      smin(mi, res/sz);
      res = 0;
      k = m.end();
      ff(i,0,sz)res+=(--k)->first;
      smax(ma, res/sz);
    }
    pr(mi, ma);
  }
  int init(){

  }

  int get_input(){
    scan(n, k);
    sz = n/k;
    v.resize(n);
    ff(i,0,n){
      int t = gi();
      m.insert({t, i});
      v[i] = t;
    }
  }
};

main(){
  init(1);
  problem a;
  a.get_input();
  a.init();
  a.solve();
}


#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define met(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
typedef long long ll;
const int maxn = 100+10;
int num[maxn];
int num1[maxn];
int visited[maxn];

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int m=n/k;
    for(int i=1;i<=n;i++)
        scanf("%d",&num[i]);
    int q;
    scanf("%d",&q);
    double MAX=0,MIN=inf;
    while(q--)
    {
        double sum=0;
        for(int j=0;j<m;j++)
        {
            int pos;
            scanf("%d",&pos);
            visited[pos]=1;
            sum+=num[pos];
        }
        sum/=m;
        MAX=max(MAX,sum);
        MIN=min(MIN,sum);
    }
    //printf("%.10f %.10f\n",MIN,MAX);
    int len=0;
    for(int i=1;i<=n;i++)
    {
        if(visited[i])
            continue;
        num1[len++]=num[i];
    }
    sort(num1,num1+len);
    if(len>=m)
    {
        double sum1=0,sum2=0;
        for(int  i=0;i<m;i++)
            sum1+=num1[i];
        for(int i=len-1;i>=len-m;i--)
            sum2+=num1[i];
        sum1/=m;
        sum2/=m;
        MAX=max(sum2,MAX);
        MIN=min(sum1,MIN);
    }
    printf("%.10f %.10f\n",MIN,MAX);
}


#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define met(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
typedef long long ll;
const int maxn = 100+10;
int num[maxn];
int num1[maxn];
int visited[maxn];

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int m=n/k;
    for(int i=1;i<=n;i++)
        scanf("%d",&num[i]);
    int q;
    scanf("%d",&q);
    int ans=q;
    double MAX=0,MIN=inf;
    while(ans--)
    {
        double sum=0;
        for(int j=0;j<m;j++)
        {
            int pos;
            scanf("%d",&pos);
            visited[pos]=1;
            sum+=num[pos];
        }
        sum/=m;
        MAX=max(MAX,sum);
        MIN=min(MIN,sum);
    }
   // printf("%.10f %.10f\n",MIN,MAX);
    int len=0;
    for(int i=1;i<=n;i++)
    {
        if(visited[i])
            continue;
        num1[len++]=num[i];
    }
    sort(num1,num1+len);
    if(k>q)
    {
        double sum1=0,sum2=0;
        for(int  i=0;i<m;i++)
            sum1+=num1[i];
        for(int i=len-1;i>=len-m;i--)
            sum2+=num1[i];
        sum1/=m;
        sum2/=m;
        MAX=max(sum2,MAX);
        MIN=min(sum1,MIN);
    }
    printf("%.10f %.10f\n",MIN,MAX);
}


#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define met(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
typedef long long ll;
const int maxn = 100+10;
int num[maxn];
int num1[maxn];
int visited[maxn];

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int m=n/k;
    for(int i=1;i<=n;i++)
        scanf("%d",&num[i]);
    int q;
    scanf("%d",&q);
    double MAX=0,MIN=inf;
    while(q--)
    {
        double sum=0;
        for(int j=0;j<m;j++)
        {
            int pos;
            scanf("%d",&pos);
            visited[pos]=1;
            sum+=num[pos];
        }
        sum/=m;
        MAX=max(MAX,sum);
        MIN=min(MIN,sum);
    }
   // printf("%.10f %.10f\n",MIN,MAX);
    int len=0;
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(visited[i])
        {
            cnt++;
            continue;
        }
        num1[len++]=num[i];
    }
    cnt/=m;
    sort(num1,num1+len);
    if(k>cnt)
    {
        double sum1=0,sum2=0;
        for(int  i=0;i<m;i++)
            sum1+=num1[i];
        for(int i=len-1;i>=len-m;i--)
            sum2+=num1[i];
        sum1/=m;
        sum2/=m;
        MAX=max(sum2,MAX);
        MIN=min(sum1,MIN);
    }
    printf("%.10f %.10f\n",MIN,MAX);
}


#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define met(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
typedef long long ll;
const int maxn = 100+10;
int num[maxn];
int num1[maxn];
int visited[maxn];

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int m=n/k;
    for(int i=1;i<=n;i++)
        scanf("%d",&num[i]);
    int q;
    scanf("%d",&q);
    double MAX=0,MIN=inf;
    while(q--)
    {
        double sum=0;
        for(int j=0;j<m;j++)
        {
            int pos;
            scanf("%d",&pos);
            visited[pos]=1;
            sum+=num[pos];
        }
        sum/=m;
        MAX=max(MAX,sum);
        MIN=min(MIN,sum);
    }
    int len=0;
    for(int i=1;i<=n;i++)
    {
        if(visited[i])
            continue;
        num1[len++]=num[i];
    }
    sort(num1,num1+len);
    double sum1=0,sum2=0;
    for(int  i=0;i<m;i++)
        sum1+=num1[i];
    for(int i=len-1;i>=len-m;i--)
        sum2+=num1[i];
    sum1/=m;
    sum2/=m;
    MAX=max(sum2,MAX);
    MIN=min(sum1,MIN);
    printf("%.10f %.10f\n",MIN,MAX);
}


/***************************************
      Authur: zzblack                 **
      2016-06-22                      **
      Orz                             **
****************************************/
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <string>
#include <cctype>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
#define ls id<<1,l,mid
#define rs id<<1|1,mid+1,r
#define OFF(x) memset(x,-1,sizeof x)
#define CLR(x) memset(x,0,sizeof x)
#define MEM(x) memset(x,0x3f,sizeof x)
typedef long long ll ;
typedef pair<int,int> pii ;
const int maxn = 1e5 + 50 ;
const int maxm = 1e6 + 50;
const double eps = 1e-10;
const int max_index = 62;
const int inf = 0x3f3f3f3f ;
const int MOD = 1e9+7 ;

inline int read(){
    char c = getchar();
    while (!isdigit(c)) c = getchar();
    int x = 0;
    while (isdigit(c)) {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x;
}

int a[105];

int main () {
#ifdef LOCAL
  	freopen("C:\\Users\\zzblack\\Desktop\\case.in","r",stdin);
    freopen("C:\\Users\\zzblack\\Desktop\\case.out","w",stdout);
#endif
    int n = read(), k = read();
    int m = n / k;
    for (int i = 1; i <= n; i++) a[i] = read();
    int q = read();
	double Max = -1.0, Min = 111111.0;
	while (q--) {
		int tmp = -1;
		for (int i = 1; i <= m; i++) {
			int x = read();
			if (a[x] == -1) continue;
			if(tmp == -1) tmp = 0;
			tmp += a[x];
			a[x] = -1;
		}
		if(tmp == -1) continue;
		double t = tmp * 1.0 / m;
		Max = max(Max, t);
		Min = min(Min, t);
	}
	sort(a+1, a + n + 1);
	int id = 1;
	while (a[id] == -1) id++;
	if ((id-1) / m < k) {
		int tmp = 0;
		for (int i = 0; i < m; i++) tmp += a[i + id];
		double t = tmp * 1.0 / m;
		Max = max(Max, t);
		Min = min(Min, t);
		tmp = 0;
		for (int i = 0; i < m; i++) tmp += a[n-i];
		t = tmp * 1.0 / m;
		Max = max(Max, t);
		Min = min(Min, t);
	}
	printf("%.10f %.10f\n", Min, Max);

	return 0;
}


/***************************************
      Authur: zzblack                 **
      2016-06-22                      **
      Orz                             **
****************************************/
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <string>
#include <cctype>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
#define ls id<<1,l,mid
#define rs id<<1|1,mid+1,r
#define OFF(x) memset(x,-1,sizeof x)
#define CLR(x) memset(x,0,sizeof x)
#define MEM(x) memset(x,0x3f,sizeof x)
typedef long long ll ;
typedef pair<int,int> pii ;
const int maxn = 1e5 + 50 ;
const int maxm = 1e6 + 50;
const double eps = 1e-10;
const int max_index = 62;
const int inf = 0x3f3f3f3f ;
const int MOD = 1e9+7 ;

inline int read(){
    char c = getchar();
    while (!isdigit(c)) c = getchar();
    int x = 0;
    while (isdigit(c)) {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x;
}

int a[105];

int main () {
#ifdef LOCAL
  	freopen("C:\\Users\\zzblack\\Desktop\\case.in","r",stdin);
    freopen("C:\\Users\\zzblack\\Desktop\\case.out","w",stdout);
#endif
    int n = read(), k = read();
    int m = n / k;
    for (int i = 1; i <= n; i++) a[i] = read();
    int q = read();
	double Max = -1, Min = 111111;
	while (q--) {
		int tmp = -1;
		for (int i = 1; i <= m; i++) {
			int x = read();
			if (a[x] == -1) continue;
			if(tmp == -1) tmp = 0;
			tmp += a[x];
			a[x] = -1;
		}
		if(tmp == -1) continue;
		double t = tmp * 1.0 / m;
		Max = max(Max, t);
		Min = min(Min, t);
	}
	sort(a+1, a + n + 1);
	int id = 1;
	while (a[id] == -1) id++;
	if (n - id + 1 >= m) {
		int tmp = 0;
		for (int i = 0; i < m; i++) tmp += a[i + id];
		double t = tmp * 1.0 / m;
		Max = max(Max, t);
		Min = min(Min, t);
		tmp = 0;
		for (int i = 0; i < m; i++) tmp += a[n-i];
		t = tmp * 1.0 / m;
		Max = max(Max, t);
		Min = min(Min, t);
	}
	cout << Min << " " << Max << "\n";

	return 0;
}


/***************************************
      Authur: zzblack                 **
      2016-06-22                      **
      Orz                             **
****************************************/
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <string>
#include <cctype>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
#define ls id<<1,l,mid
#define rs id<<1|1,mid+1,r
#define OFF(x) memset(x,-1,sizeof x)
#define CLR(x) memset(x,0,sizeof x)
#define MEM(x) memset(x,0x3f,sizeof x)
typedef long long ll ;
typedef pair<int,int> pii ;
const int maxn = 1e5 + 50 ;
const int maxm = 1e6 + 50;
const double eps = 1e-10;
const int max_index = 62;
const int inf = 0x3f3f3f3f ;
const int MOD = 1e9+7 ;

inline int read(){
    char c = getchar();
    while (!isdigit(c)) c = getchar();
    int x = 0;
    while (isdigit(c)) {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x;
}

int a[105];

int main () {
#ifdef LOCAL
  	freopen("C:\\Users\\zzblack\\Desktop\\case.in","r",stdin);
    freopen("C:\\Users\\zzblack\\Desktop\\case.out","w",stdout);
#endif
    int n = read(), k = read();
    int m = n / k;
    for (int i = 1; i <= n; i++) a[i] = read();
    int q = read();
	double Max = -1.0, Min = 111111.0;
	while (q--) {
		int tmp = -1;
		for (int i = 1; i <= m; i++) {
			int x = read();
			if (a[x] == -1) continue;
			if(tmp == -1) tmp = 0;
			tmp += a[x];
			a[x] = -1;
		}
		if(tmp == -1) continue;
		double t = tmp * 1.0 / m;
		Max = max(Max, t);
		Min = min(Min, t);
	}
	sort(a+1, a + n + 1);
	int id = 1;
	while (a[id] == -1) id++;
	if (n - id + 1 >= m) {
		int tmp = 0;
		for (int i = 0; i < m; i++) tmp += a[i + id];
		double t = tmp * 1.0 / m;
		Max = max(Max, t);
		Min = min(Min, t);
		tmp = 0;
		for (int i = 0; i < m; i++) tmp += a[n-i];
		t = tmp * 1.0 / m;
		Max = max(Max, t);
		Min = min(Min, t);
	}
	printf("%.10f %.10f\n", Min, Max);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, k, t, v[101], q, a, mx = 0, mn = 1e9, cur, cnt = 0;
	vector<int> vec;
	cin >> n >> k;
	t = n / k;
	for(int i=1; i<=n; i++) cin >> v[i];
	cin >> q;
	for(int i=0; i<q; i++){
		cur = 0;
		for(int j=0; j<t; j++){
			cin >> a;
			if(v[a] == -1){
				cur = -1;
				continue;
			}
			cnt++;
			cur += v[a];
			v[a] = -1;
		}
		if(cur == -1) continue;
		mx = max(mx, cur);
		mn = min(mn, cur);
	}
	for(int i=1; i<=n; i++){
		if(v[i] != -1) vec.push_back(v[i]);
	}
	if(vec.size() >= t && cnt/t < k){
		sort(vec.begin(), vec.end());
		cur = 0;
		for(int i=0; i<t; i++) cur += vec[i];
		mn = min(mn, cur);
		cur = 0;
		for(int i=vec.size()-1; i>=int(vec.size())-t; i--) cur += vec[i];
		mx = max(mx, cur);
	}
	cout << fixed << setprecision(7) << double(mn)/t << ' ' << double(mx)/t;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, k, t, v[101], q, a, mx = 0, mn = 1e9, cur;
	vector<int> vec;
	cin >> n >> k;
	t = n / k;
	for(int i=1; i<=n; i++) cin >> v[i];
	cin >> q;
	for(int i=0; i<q; i++){
		cur = 0;
		for(int j=0; j<t; j++){
			cin >> a;
			if(v[a] == -1){
				cur = -1;
				continue;
			}
			cur += v[a];
			v[a] = -1;
		}
		if(cur == -1) continue;
		mx = max(mx, cur);
		mn = min(mn, cur);
	}
	for(int i=1; i<=n; i++){
		if(v[i] != -1) vec.push_back(v[i]);
	}
	if(vec.size() >= t){
		sort(vec.begin(), vec.end());
		cur = 0;
		for(int i=0; i<t; i++) cur += vec[i];
		mn = min(mn, cur);
		cur = 0;
		for(int i=vec.size()-1; i>=int(vec.size())-t; i--) cur += vec[i];
		mx = max(mx, cur);
	}
	cout << fixed << setprecision(7) << double(mn)/t << ' ' << double(mx)/t;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, k, t, v[101], q, a, mx = 0, mn = 1e9, cur, cnt = 0;
	vector<int> vec;
	cin >> n >> k;
	t = n / k;
	for(int i=1; i<=n; i++) cin >> v[i];
	cin >> q;
	for(int i=0; i<q; i++){
		cur = 0;
		for(int j=0; j<t; j++){
			cin >> a;
			if(v[a] == -1){
				cur = -1;
				continue;
			}
			cnt++;
			cur += v[a];
			v[a] = -1;
		}
		if(cur == -1) continue;
		mx = max(mx, cur);
		mn = min(mn, cur);
	}
	for(int i=1; i<=n; i++){
		if(v[i] != -1) vec.push_back(v[i]);
	}
	if(vec.size() >= t && cnt < k){
		sort(vec.begin(), vec.end());
		cur = 0;
		for(int i=0; i<t; i++) cur += vec[i];
		mn = min(mn, cur);
		cur = 0;
		for(int i=vec.size()-1; i>=int(vec.size())-t; i--) cur += vec[i];
		mx = max(mx, cur);
	}
	cout << fixed << setprecision(7) << double(mn)/t << ' ' << double(mx)/t;
}


#include <cstdio>
#include <vector>
#include <algorithm>

const int MN = 20000;

std::vector<int> v, ok;
int N, K, L, a[MN], Q, num;
bool u[MN];

int main()
{
	scanf("%d%d", &N, &K);
	L=N/K;
	for(int i=0;i<N;++i)
		scanf("%d", a+i);
	scanf("%d", &Q);
	for(int i=0;i<Q;++i)
	{
		int sum=0;
		bool use=0;
		for(int j=0;j<L;++j)
		{
			int x;
			scanf("%d", &x), --x;
			if(u[x]) use=1;
			u[x]=1;
			sum += a[x];
		}
		if(!use) ++num;
		//printf("%d\n", sum);
		v.push_back(sum);
	}
	for(int i=0;i<N;++i)
		if(!u[i])
			ok.push_back(a[i]);
	if(num < K && (int)ok.size() >= L)
	{
		std::sort(ok.begin(), ok.end());
		int x=0, y=0;
		for(int i=0;i<L;++i)
			x += ok[i], y += ok[(int)ok.size()-i-1];
		v.push_back(x);
		v.push_back(y);
	}
	std::sort(v.begin(), v.end());
	printf("%.12lf %.12lf\n", (double)v[0]/L, (double)v.back()/L);
	return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>

const int MN = 20000;

std::vector<int> v, ok;
int N, K, L, a[MN], Q;
bool u[MN];

int main()
{
	scanf("%d%d", &N, &K);
	L=N/K;
	for(int i=0;i<N;++i)
		scanf("%d", a+i);
	scanf("%d", &Q);
	for(int i=0;i<Q;++i)
	{
		int sum=0;
		for(int j=0;j<L;++j)
		{
			int x;
			scanf("%d", &x), --x;
			u[x]=1;
			sum += a[x];
		}
		//printf("%d\n", sum);
		v.push_back(sum);
	}
	for(int i=0;i<N;++i)
		if(!u[i])
			ok.push_back(a[i]);
	if(ok.size() >= L)
	{
		std::sort(ok.begin(), ok.end());
		int x=0, y=0;
		for(int i=0;i<L;++i)
			x += ok[i], y += ok[(int)ok.size()-i-1];
		v.push_back(x);
		v.push_back(y);
	}
	std::sort(v.begin(), v.end());
	printf("%.12lf %.12lf\n", (double)v[0]/L, (double)v.back()/L);
	return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>

const int MN = 20000;

std::vector<int> v, ok;
int N, K, L, a[MN], Q;
bool u[MN];

int main()
{
	scanf("%d%d", &N, &K);
	L=N/K;
	for(int i=0;i<N;++i)
		scanf("%d", a+i);
	scanf("%d", &Q);
	for(int i=0;i<Q;++i)
	{
		int sum=0;
		for(int j=0;j<L;++j)
		{
			int x;
			scanf("%d", &x), --x;
			u[x]=1;
			sum += a[x];
		}
		//printf("%d\n", sum);
		v.push_back(sum);
	}
	for(int i=0;i<N;++i)
		if(!u[i])
			ok.push_back(a[i]);
	if(ok.size() >= L)
	{
		std::sort(ok.begin(), ok.end());
		int x=0, y=0;
		for(int i=0;i<L;++i)
			x += ok[i], y += ok[(int)ok.size()-i-1];
		v.push_back(x);
		v.push_back(y);
	}
	std::sort(v.begin(), v.end());
	printf("%.9lf %.9lf\n", (double)v[0]/L, (double)v.back()/L);
	return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>

const int MN = 20000;

std::vector<int> v, ok;
int N, K, L, a[MN], Q, num;
bool u[MN];

int main()
{
	scanf("%d%d", &N, &K);
	L=N/K;
	for(int i=0;i<N;++i)
		scanf("%d", a+i);
	scanf("%d", &Q);
	for(int i=0;i<Q;++i)
	{
		int sum=0;
		bool x=0;
		for(int j=0;j<L;++j)
		{
			int x;
			scanf("%d", &x), --x;
			if(u[x]) x=1;
			u[x]=1;
			sum += a[x];
		}
		if(!x) ++num;
		//printf("%d\n", sum);
		v.push_back(sum);
	}
	for(int i=0;i<N;++i)
		if(!u[i])
			ok.push_back(a[i]);
	if(num < K && (int)ok.size() >= L)
	{
		std::sort(ok.begin(), ok.end());
		int x=0, y=0;
		for(int i=0;i<L;++i)
			x += ok[i], y += ok[(int)ok.size()-i-1];
		v.push_back(x);
		v.push_back(y);
	}
	std::sort(v.begin(), v.end());
	printf("%.12lf %.12lf\n", (double)v[0]/L, (double)v.back()/L);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
using namespace std;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k, kol;
	cin >> n >> k;
	kol = n / k;
	vector< pair<int, int> > a(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i].first);
		a[i].second = i;
	}
	int q, x;
	cin >> q;
	double mmin = 1e9, mmax = 0, sr;
	vector< vector<int> > b(q);
	vector<bool> used(n, false);
	bool fl;
	int kol_r = 0;
	for (int i = 0; i < q; i++) {
		sr = 0;
		fl = false;
		for (int g = 0; g < kol; g++) {
			scanf("%d", &x);
			--x;
			if (!used[x]) {
				fl = true;
			}
			used[x] = true;
			sr += a[x].first;
		}
		if (fl) {
			kol_r++;
		}
		sr /= kol;
		mmin = min(mmin, sr);
		mmax = max(mmax, sr);
	}
	if (kol_r < k) {
		sort(a.begin(), a.end());
		int nabr = 0;
		sr = 0;
		for (int i = 0; i < n; i++) {
			if (!used[a[i].second]) {
				sr += a[i].first;
				nabr++;
				if (nabr == kol) {
					sr /= kol;
					mmin = min(mmin, sr);
					mmax = max(mmax, sr);
					break;
				}
			}
		}
		nabr = 0;
		sr = 0;
		for (int i = n - 1; i >= 0; i--) {
			if (!used[a[i].second]) {
				sr += a[i].first;
				nabr++;
				if (nabr == kol) {
					sr /= kol;
					mmin = min(mmin, sr);
					mmax = max(mmax, sr);
					break;
				}
			}
		}
	}
	printf("%.7f %.7f", mmin, mmax);

	return 0;
}//beybvh


#include <bits/stdc++.h>
using namespace std;

#define N 1100

int n, k, a[N], q, b[N], g, cnt, x;
bool vis[N];
int mn, mx;

int main() {

	scanf("%d%d", &n, &k);
	g = n / k;
	for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
	scanf("%d", &q);
	mn = 1000000;
	while (q --) {
		int sum = 0;
		for (int i = 1; i <= g; i ++) {
			scanf("%d", &x);
			vis[x] = 1;
			sum += a[x];
		}
		if (sum > mx) mx = sum;
		if (sum < mn) mn = sum;
	}
	for (int i = 1; i <= n; i ++) if (!vis[i]) b[++ cnt] = a[i];
	if (n - cnt < k * g) {
		sort(b + 1, b + 1 + cnt);
		int sum = 0;
		for (int i = 1; i <= g; i ++) sum += b[i];
		if (sum < mn) mn = sum;
		sum = 0;
		for (int i = cnt; i >= cnt - g + 1; i --) sum += b[i];
		if (mx < sum) mx = sum;
	}
	printf("%.10lf %.10lf", 1.0 * mn / g, 1.0 * mx / g);
}


#include <bits/stdc++.h>
using namespace std;

#define N 1100

int n, k, a[N], q, b[N], g, cnt, x;
bool vis[N];
double mn, mx;

int main() {
	scanf("%d%d", &n, &k);
	g = n / k;
	for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
	scanf("%d", &q);
	mn = 100000;
	while (q --) {
		int sum = 0;
		for (int i = 1; i <= g; i ++) {
			scanf("%d", &x);
			vis[x] = 1;
			sum += a[x];
		}
		double aver = 1.0 * sum / g;
		mn = min(mn, aver);
		mx = max(mx, aver);
	}
	for (int i = 1; i <= n; i ++) if (!vis[i]) b[++ cnt] = a[i];
	if (cnt < g) printf("%.10lf %.10lf", mn, mx);
	else {
		sort(b + 1, b + 1 + cnt);
		int sum = 0;
		for (int i = 1; i <= g; i ++) sum += b[i];
		double aver = 1.0 * sum / g;
		mn = min(mn, aver);
		sum = 0;
		for (int i = cnt; i >= cnt - g + 1; i --) sum += b[i];
		aver = 1.0 * sum / g;
		mx = max(mx, aver);
		printf("%.10lf %.10lf", mn, mx);
	}
}


#include <bits/stdc++.h>
using namespace std;

#define N 1100

int n, k, a[N], q, b[N], g, cnt, x;
bool vis[N];
double mn, mx;

int main() {
	scanf("%d%d", &n, &k);
	g = n / k;
	for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
	scanf("%d", &q);
	mn = 1000;
	while (q --) {
		int sum = 0;
		for (int i = 1; i <= g; i ++) {
			scanf("%d", &x);
			vis[x] = 1;
			sum += a[x];
		}
		double aver = 1.0 * sum / g;
		mn = min(mn, aver);
		mx = max(mx, aver);
	}
	for (int i = 1; i <= n; i ++) if (!vis[i]) b[++ cnt] = a[i];
	if (cnt < g) printf("%.7lf %.7lf", mn, mx);
	else {
		sort(b + 1, b + 1 + cnt);
		int sum = 0;
		for (int i = 1; i <= g; i ++) sum += b[i];
		double aver = 1.0 * sum / g;
		mn = min(mn, aver);
		sum = 0;
		for (int i = cnt; i >= cnt - g + 1; i --) sum += b[i];
		aver = 1.0 * sum / g;
		mx = max(mx, aver);
		printf("%.7lf %.7lf", mn, mx);
	}
}


#include <bits/stdc++.h>
using namespace std;

#define N 1100

int n, k, a[N], q, b[N], g, cnt, x;
bool vis[N];
int mn, mx;

int main() {
	scanf("%d%d", &n, &k);
	g = n / k;
	for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
	scanf("%d", &q);
	mn = 1000000;
	while (q --) {
		int sum = 0;
		for (int i = 1; i <= g; i ++) {
			scanf("%d", &x);
			vis[x] = 1;
			sum += a[x];
		}
		if (sum > mx) mx = sum;
		if (sum < mn) mn = sum;
	}
	for (int i = 1; i <= n; i ++) if (!vis[i]) b[++ cnt] = a[i];
	if (cnt >= g) {
		sort(b + 1, b + 1 + cnt);
		int sum = 0;
		for (int i = 1; i <= g; i ++) sum += b[i];
		if (sum < mn) mn = sum;
		sum = 0;
		for (int i = cnt; i >= cnt - g + 1; i --) sum += b[i];
		if (mx < sum) mx = sum;
	}
	printf("%.10lf %.10lf", 1.0 * mn / g, 1.0 * mx / g);
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>

#define forn(i, n) for (int i = 0; i < int(n); ++i)

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;

	vector<int> a(n);
	forn(i, n)
		cin >> a[i];

	int q;
	cin >> q;

	int m = n / k;
	vector<int> t;
	forn(i, q) {
		int s = 0;

		forn(j, m) {
			int x;
			cin >> x;
			x--;
			s += a[x];
			a[x] = -1;
		}

		if (s >= 0)
			t.push_back(s);
	}

	sort(a.begin(), a.end());
	int i = lower_bound(a.begin(), a.end(), 0) - a.begin();
	if (i / m < k && i + m <= n) {

		int s = 0;
		for (int j = i; j < i + m; ++j)
			s += a[j];
		t.push_back(s);

		s = 0;
		for (int j = n - 1; j >= n - m; --j)
			s += a[j];
		t.push_back(s);

	}

	int min_s = 1e9, max_s = -1;
	forn(i, t.size()) {
		min_s = min(min_s, t[i]);
		max_s = max(max_s, t[i]);
	}

	double ans1 = 1.0 * min_s / m, ans2 = 1.0 * max_s / m;
	cout << setprecision(9) << ans1 << ' ' << setprecision(9) << ans2 << endl;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,k,x,lo=0;
    cin>>n>>k;
    double arr[n+7];
    int chk[n+7];
    vector < pair <double,int> > vt;
    vector <double> paisi,painai;
    memset(chk,0,sizeof chk);
    for(int i=1; i<=n; i++)
    {
        cin>>arr[i];
        vt.push_back({arr[i]*1.0,i});
    }
    double ppl,ques=n/k;
    cin>>ppl;
    int st=0;
    for(int i=1; i<=ppl; i++)
    {
        double sum=0;
        lo=0;
        for(int j=1; j<=ques; j++)
        {
            cin>>x;
            if(chk[x]==0)
                lo++;
            chk[x]++;
            sum+=arr[x];
        }
        if(lo==ques)
            st++;
        paisi.push_back((sum*1.0)/((double)(ques*1.0)));
    }
    //cout<<st<<endl;
    sort(vt.begin(),vt.end());
    int cnt=0;
    double sum=0;
    if((k-st)>0)
    {
        for(int i=0; i<vt.size() && cnt<ques; i++)
        {
            if(chk[vt[i].second]==0)
            {
                sum+=vt[i].first;
                cnt++;
                if(cnt==ques)
                {
                    paisi.push_back((sum*1.0)/((double)(ques*1.0)));
                }
            }
        }
        cnt=0;
        sum=0;
        for(int i=vt.size()-1; i>=0 && cnt<ques; i--)
        {
            if(chk[vt[i].second]==0)
            {
                sum+=vt[i].first;
                cnt++;
                if(cnt==ques)
                {
                    paisi.push_back((sum*1.0)/((double)(ques*1.0)));
                }
            }
        }
    }
    sort(paisi.begin(),paisi.end());
    cout<<fixed<<setprecision(10)<<paisi[0]<<' '<<fixed<<setprecision(10)<<paisi[paisi.size()-1]<<endl;
    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;
int main ()
{
int n,k,i,j;
cin >> n>>k;
int a[n],b[n];
for (i=0;i<n;i++)
{cin>>a[i];b[i]=1;}
int q=0;
cin >> q;
int e=n/k,max=-1000000000,min=1000000000;
for (i=0;i<q;i++)
{int sum=0;
for (j=0;j<e;j++)
{int y=0;
cin >>y;sum+=a[y-1];b[y-1]=0;}
if (sum>max)max=sum;
if (sum<min)min=sum;
}
float up1=max/(float)e;
float down1=min/(float)e;
j=0;

float up=0.0,down=0.0;

int c[100]={0};
for (i=0;i<n;i++)
{if (b[i]) c[j++]=a[i];}
int w=j;
sort (c,c+j);
//for (i=0;i<j;i++) cout <<j<<c[i]<<endl;
for (i=0;i<e;i++)
{down+=c[i];
up+=c[w-1-i];}

up=up/(float)e;
down=down/(float)e;
//cout <<"up up1 down down1"<<up<<" "<<up1<<" "<<down<<" "<<down1<<endl;
cout <<fixed <<setprecision(10)<<(down<down1?down:down1) <<" "<<(up>up1?up:up1)<<endl;
return 0;}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;
int main ()
{
int n,k,i,j;
cin >> n>>k;
int a[n],b[n];
for (i=0;i<n;i++)
{cin>>a[i];b[i]=1;}
int q=0;
cin >> q;
int e=n/k,max=-1000000000,min=1000000000;
for (i=0;i<q;i++)
{int sum=0;
for (j=0;j<e;j++)
{int y=0;
cin >>y;sum+=a[y-1];b[y-1]=0;}
if (sum>max)max=sum;
if (sum<min)min=sum;
}
float up1=max/(float)e;
float down1=min/(float)e;
j=0;

int c[100]={0};
for (i=0;i<n;i++)
{if (b[i]) c[j++]=a[i];}
if (j>=e)
{
float up=0.0,down=0.0;
int w=j;
sort (c,c+j);
//for (i=0;i<j;i++) cout <<j<<c[i]<<endl;
for (i=0;i<e;i++)
{down+=c[i];
up+=c[w-1-i];}

//cout <<" up "<<up <<endl;
up=up/(float)e;
down=down/(float)e;
//cout <<"up up1 down down1"<<up<<" "<<up1<<" "<<down<<" "<<down1<<endl;
cout <<fixed <<setprecision(10)<<(down<down1?down:down1) <<" "<<(up>up1?up:up1)<<endl;}
else cout <<fixed <<setprecision(10)<< down1 <<" "<< up1 <<endl;
return 0;}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;
int main ()
{
int n,k,i,j;
cin >> n>>k;
int a[n],b[n];
for (i=0;i<n;i++)
{cin>>a[i];b[i]=1;}
int q=0;
cin >> q;
int e=n/k,max=-1000000000,min=1000000000;
for (i=0;i<q;i++)
{int sum=0;
for (j=0;j<e;j++)
{int y=0;
cin >>y;sum+=a[y-1];b[y-1]=0;}
if (sum>max)max=sum;
if (sum<min)min=sum;
}
float up1=max/(float)e;
float down1=min/(float)e;
j=0;

float up=-1000000000.0,down=1000000000.0;

int c[100]={0};
for (i=0;i<n;i++)
{if (b[i]) c[j++]=a[i];}
int w=j;
sort (c,c+j);
//for (i=0;i<j;i++) cout <<j<<c[i]<<endl;
for (i=0;i<e;i++)
{down+=c[i];
up+=c[w-1-i];}

up=up/(float)e;
down=down/(float)e;
//cout <<"up up1 down down1"<<up<<" "<<up1<<" "<<down<<" "<<down1<<endl;
cout <<fixed <<setprecision(10)<<(down<down1?down:down1) <<" "<<(up>up1?up:up1)<<endl;
return 0;}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;
int main ()
{
	int n,k,i,j;
	cin >> n>>k;
	int a[n],b[n];
	for (i=0;i<n;i++)
	{
		cin>>a[i];b[i]=1;}
	int q=0;
	cin >> q;
	int e=n/k,max=-1000000000,min=1000000000;
	for (i=0;i<q;i++)
	{
		int sum=0;
		for (j=0;j<e;j++)
		{
			int y=0;
			cin >>y; sum+=a[y-1]; b[y-1]=0;}
		if (sum>max) max=sum;
		if (sum<min) min=sum;
	}
	float up1=max/(float)e;
	float down1=min/(float)e;
	j=0;
	int c[100]={0};
	for (i=0;i<n;i++)
	{
		if (b[i]) c[j++]=a[i];}
	if (j>=e&&((n-j)/e<k))
	{
		float up=0.0,down=0.0;
		int w=j;
		sort (c,c+j);
		//for (i=0;i<j;i++) cout <<j<<c[i]<<endl;
		for (i=0;i<e;i++)
		{
			down+=c[i];
			up+=c[w-1-i];}

		//cout <<" up "<<up <<endl;
		up=up/(float)e;
		down=down/(float)e;
		//cout <<"up up1 down down1"<<up<<" "<<up1<<" "<<down<<" "<<down1<<endl;
		cout <<fixed <<setprecision(10)<<(down<down1?down:down1) <<" "<<(up>up1?up:up1)<<endl;
	}
	else cout <<fixed <<setprecision(10)<< down1 <<" "<< up1 <<endl;
	return 0;}


#include<bits/stdc++.h>
#define pi 3.141592653897932384626
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
map<long long,map<pair<long long,long long>,long long> >m;
map<long long,long long>m0;
long long a[200005],b[200005];
int main()
{
    long long n,A,B;
    cin>>n>>A>>B;
    long long x;
    for(long i=0;i<n;i++)scanf("%lld%lld%lld",&x,&a[i],&b[i]);
    long long s=0;
    for(long i=0;i<n;i++){
        long long x=A*a[i]-b[i];
        s+=m0[x]-m[x][pair<long,long>(a[i],b[i])];
        m0[x]+=1;
        m[x][pair<long,long>(a[i],b[i])]+=1;
    }
    cout<<s*2LL<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define pi 3.141592653897932384626
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
map<long,map<pair<long,long>,long> >m;
//map<pair<long,long>,long>m0;
long a[200005],b[200005];
int main()
{
    long n,A,B;
    cin>>n>>A>>B;
    long x;
    for(long i=0;i<n;i++)scanf("%ld%ld%ld",&x,&a[i],&b[i]);
    long long s=0;
    for(long i=0;i<n;i++){
        long x=A*a[i]-b[i];
        s+=i-m[x][pair<long,long>(a[i],b[i])];
        m[x][pair<long,long>(a[i],b[i])]+=1;
    }
    cout<<s*2LL<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define pi 3.141592653897932384626
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
map<long,map<pair<long,long>,long> >m;
map<long,long>m0;
long long a[200005],b[200005];
int main()
{
    long long n,A,B;
    cin>>n>>A>>B;
    long long x;
    for(long i=0;i<n;i++)scanf("%lld%lld%lld",&x,&a[i],&b[i]);
    long long s=0;
    for(long i=0;i<n;i++){
        long long x=A*a[i]-b[i];
        s+=m0[x]-m[x][pair<long,long>(a[i],b[i])];
        m0[x]+=1;
        m[x][pair<long,long>(a[i],b[i])]+=1;
    }
    cout<<s*2LL<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define pi 3.141592653897932384626
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
map<long,map<pair<long,long>,long> >m;
map<long,long>m0;
long a[200005],b[200005];
int main()
{
    long n,A,B;
    cin>>n>>A>>B;
    long x;
    for(long i=0;i<n;i++)scanf("%ld%ld%ld",&x,&a[i],&b[i]);
    long long s=0;
    for(long i=0;i<n;i++){
        long x=A*a[i]-b[i];
        s+=m0[x]-m[x][pair<long,long>(a[i],b[i])];
        m0[x]+=1;
        m[x][pair<long,long>(a[i],b[i])]+=1;
    }
    cout<<s*2LL<<endl;
    return 0;
}


#include <bits\stdc++.h>
using namespace std;
int n;
long long gcd(long long c,long long d)
{
    if(d==0)return c;
    else return gcd(d,c%d);
}
map< pair<long long,long long>,int >mp1,mp2;
map<long long,int>mp0;
long long a,b,x,y,z;
int main()
{
scanf("%d%I64d%I64d",&n,&a,&b);
long long ans=0;
int cnt0,cnt1,cnt2;
cnt0=cnt1=cnt2=0;
for(int i=1;i<=n;i++)
{
    scanf("%I64d%I64d%I64d",&z,&x,&y);
    if(x!=0&&y!=0)
    {x=x/gcd(abs(x),abs(y));
    y=y/gcd(abs(x),abs(y));
    }
    if(x*a-y*1==0)
    {
        long long flag=1;
        if(x*1+y*a>0)flag=1;
        else if(x*1+y*a<0)flag=-1;
        else flag=0;
     ans+=(cnt0-mp0[flag*(x*x+y*y)])*2;
     mp0[flag*(x*x+y*y)]++;
     cnt0++;
    // cout<<"cnt0"<<i<<endl;
    }
    if(x*a-y*1>0)
    {
     ans+=(cnt1-mp1[make_pair(x,y)])*2;
     mp1[make_pair(x,y)]++;
     cnt1++;
    }
    if(x*a-y*1<0)
    {
        ans+=(cnt2-mp2[make_pair(x,y)])*2;
     mp2[make_pair(x,y)]++;
     cnt2++;
    }
    //cout<<ans<<endl;
}
printf("%I64d\n",ans);
    return 0;
}

/*
4 1 0
-1 1 0
0 0 -1
1 -1 -2
1 -1 -2
*/


#include <bits\stdc++.h>
using namespace std;
int n;
long long gcd(long long c,long long d)
{
    if(d==0)
        return c;
    else
        return gcd(d,c%d);
}
map< pair<long long,long long>,int >mp1,mp2;
map<long long,int>mp0;
long long a,b,x,y,z;
int main()
{
    scanf("%d%I64d%I64d",&n,&a,&b);
    long long ans=0;
    int cnt0,cnt1,cnt2;
    cnt0=cnt1=cnt2=0;
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d%I64d%I64d",&z,&x,&y);
         if(x*a-y*1==0)
        {
            long long flag=1;
            if(x*1+y*a>0)
                flag=1;
            else if(x*1+y*a<0)
                flag=-1;
            else
                flag=0;
            ans+=(cnt0-mp0[flag*(x*x+y*y)])*2;
            mp0[flag*(x*x+y*y)]++;
            cnt0++;
            continue;
            // cout<<"cnt0"<<i<<endl;
        }
        if(x!=0&&y!=0)
        {
            x=x/gcd(abs(x),abs(y));
            y=y/gcd(abs(x),abs(y));
        }
        if(x*a-y*1>0)
        {
            ans+=(cnt1-mp1[make_pair(x,y)])*2;
            mp1[make_pair(x,y)]++;
            cnt1++;
        }
        if(x*a-y*1<0)
        {
            ans+=(cnt2-mp2[make_pair(x,y)])*2;
            mp2[make_pair(x,y)]++;
            cnt2++;
        }
        //cout<<ans<<endl;
    }
    printf("%I64d\n",ans);
    return 0;
}

/*
4 1 0
-1 1 0
0 0 -1
1 -1 -2
1 -1 -2
*/


#include <bits\stdc++.h>
using namespace std;
int n;
long long gcd(long long c,long long d)
{
    if(d==0)return c;
    else return gcd(d,c%d);
}
map< pair<long long,long long>,int >mp1,mp2;
map<long long,int>mp0;
long long a,b,x,y,z;
int main()
{
scanf("%d%I64d%I64d",&n,&a,&b);
long long ans=0;
int cnt0,cnt1,cnt2;
cnt0=cnt1=cnt2=0;
for(int i=1;i<=n;i++)
{
    scanf("%I64d%I64d%I64d",&z,&x,&y);
    if(x!=0&&y!=0)
    {x=x/gcd(abs(x),abs(y));
    y=y/gcd(abs(x),abs(y));
    }
    if(x*a-y*1==0)
    {
        long long flag=1;
        if(x*1+y*a>0)flag=1;
        else if(x*1+y*a<0)flag=-1;
     ans+=(cnt0-mp0[flag*(x*x+y*y)])*2;
     mp0[flag*(x*x+y*y)]++;
     cnt0++;
    }
    if(x*a-y*1>0)
    {
     ans+=(cnt1-mp1[make_pair(x,y)])*2;
     mp1[make_pair(x,y)]++;
     cnt1++;
    }
    if(x*a-y*1<0)
    {
        ans+=(cnt2-mp2[make_pair(x,y)])*2;
     mp2[make_pair(x,y)]++;
     cnt2++;
    }
}
printf("%I64d\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int n;
    ll a, x, y;
    scanf("%d%lld%*s", &n, &a);
    map<ll,ll> inters;
    map<pair<ll,ll>,ll> sames;
    ll ans = 0;
    while (n--) {
        scanf("%*s%lld%lld", &x, &y);
        ans += ++inters[a*x - y] - ++sames[{x, y}];
    }
    printf("%lld\n", ans << 1);
}


#include <bits\stdc++.h>
using namespace std;
int n;
long long gcd(long long c,long long d)
{
    if(d==0)
        return c;
    else
        return gcd(d,c%d);
}
map< pair<long long,long long>,int >mp1,mp2;
map<long long,int>mp0;
long long a,b,x,y,z;
int main()
{
    scanf("%d%I64d%I64d",&n,&a,&b);
    long long ans=0;
    int cnt0,cnt1,cnt2;
    cnt0=cnt1=cnt2=0;
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d%I64d%I64d",&z,&x,&y);
        if(x*x+y*y==0)continue;
         if(x*a-y*1==0)
        {
            long long flag=1;
            if(x*1+y*a>0)
                flag=1;
            else if(x*1+y*a<0)
                flag=-1;
            else
                continue;
            ans+=(cnt0-mp0[flag*(x*x+y*y)])*2;
            mp0[flag*(x*x+y*y)]++;
            cnt0++;
            continue;
            // cout<<"cnt0"<<i<<endl;
        }
        if(x!=0&&y!=0)
        {
            x=x/gcd(abs(x),abs(y));
            y=y/gcd(abs(x),abs(y));
        }
        if(x*a-y*1>0)
        {
            ans+=(cnt1-mp1[make_pair(x,y)])*2;
            mp1[make_pair(x,y)]++;
            cnt1++;
        }
        if(x*a-y*1<0)
        {
            ans+=(cnt2-mp2[make_pair(x,y)])*2;
            mp2[make_pair(x,y)]++;
            cnt2++;
        }
        //cout<<ans<<endl;
    }
    printf("%I64d\n",ans);
    return 0;
}

/*
4 1 0
-1 1 0
0 0 -1
1 -1 -2
1 -1 -2
*/


#include <bits\stdc++.h>
using namespace std;
int n;
long long gcd(long long c,long long d)
{
    if(d==0)
        return c;
    else
        return gcd(d,c%d);
}
map< pair<long long,long long>,int >mp1,mp2;
map<long long,int>mp0;
long long a,b,x,y,z;
int main()
{
    scanf("%d%I64d%I64d",&n,&a,&b);
    long long ans=0;
    int cnt0,cnt1,cnt2;
    cnt0=cnt1=cnt2=0;
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d%I64d%I64d",&z,&x,&y);
        //if(x*x+y*y==0)continue;
         if(x*a-y*1==0)
        {
            long long flag=1;
            if(x*1+y*a>0)
                flag=1;
            else if(x*1+y*a<0)
                flag=-1;
            else
                continue;
            ans+=(cnt0-mp0[flag*(x*x+y*y)])*2;
            mp0[flag*(x*x+y*y)]++;
            cnt0++;
            continue;
            // cout<<"cnt0"<<i<<endl;
        }
        if(x!=0&&y!=0)
        {
            x=x/gcd(abs(x),abs(y));
            y=y/gcd(abs(x),abs(y));
        }
        if(x*a-y*1>0)
        {
            ans+=(cnt1-mp1[make_pair(x,y)])*2;
            mp1[make_pair(x,y)]++;
            cnt1++;
        }
        if(x*a-y*1<0)
        {
            ans+=(cnt2-mp2[make_pair(x,y)])*2;
            mp2[make_pair(x,y)]++;
            cnt2++;
        }
        //cout<<ans<<endl;
    }
    printf("%I64d\n",ans);
    return 0;
}

/*
4 1 0
-1 1 0
0 0 -1
1 -1 -2
1 -1 -2
*/


#include <bits\stdc++.h>
using namespace std;
int n;
long long gcd(long long c,long long d)
{
    if(d==0)
        return c;
    else
        return gcd(d,c%d);
}
map< pair<long long,long long>,int >mp1,mp2;
map<long long,int>mp0;
long long a,b,x,y,z;
int main()
{
    scanf("%d%I64d%I64d",&n,&a,&b);
    long long ans=0;
    int cnt0,cnt1,cnt2;
    cnt0=cnt1=cnt2=0;
    for(int i=1; i<=n; i++)
    {
        scanf("%I64d%I64d%I64d",&z,&x,&y);
        if(x*x+y*y==0)continue;
         if(x*a-y*1==0)
        {
            long long flag=1;
            if(x*1+y*a>0)
                flag=1;
            else if(x*1+y*a<0)
                flag=-1;
            else
                continue;
            ans+=(cnt0-mp0[flag*(x*x+y*y)])*2;
            mp0[flag*(x*x+y*y)]++;

            continue;
            // cout<<"cnt0"<<i<<endl;
        }
        if(x!=0&&y!=0)
        {
            x=x/gcd(abs(x),abs(y));
            y=y/gcd(abs(x),abs(y));
        }
        if(x*a-y*1>0)
        {
            ans+=(cnt1-mp1[make_pair(x,y)])*2;
            mp1[make_pair(x,y)]++;
            cnt1++;
        }
        if(x*a-y*1<0)
        {
            ans+=(cnt2-mp2[make_pair(x,y)])*2;
            mp2[make_pair(x,y)]++;
            cnt2++;
        }
        //cout<<ans<<endl;
    }
    printf("%I64d\n",ans);
    return 0;
}

/*
4 1 0
-1 1 0
0 0 -1
1 -1 -2
1 -1 -2
*/


#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
struct ghost {
    int vx,vy;
    int magic;
    ghost(int x,int y,int a):vx(x),vy(y),magic(a*x - y){}
};
bool cmp1(const ghost& x,const ghost& y) {
    return x.magic < y.magic;
}
bool cmp2(const ghost& x,const ghost& y) {
    return x.vx < y.vx;
}
vector <ghost> G;
int main () {
    int n,a,b;
    cin >> n >> a >> b;
    for (int i = 0 ; i < n; i ++) {
        int x,vx,vy;
        cin >> x >> vx >> vy;
        ghost tmp(vx,vy,a);
        G.push_back(tmp);
    }
    stable_sort(G.begin(), G.end(),cmp2);
    stable_sort(G.begin(), G.end(),cmp1);
    int res = 0;
    int t_m = G[0].magic;
    int t_b = 0;
    for (int i = 0 ; i < G.size(); i++) {
        if (G[i].magic != t_m) {
            if (i-t_b > 1) {
                res += ((i - t_b) * (i - t_b - 1)) ;
                int t_vx = G[t_b].vx;
                int tt_b = t_b;
                for (int k = tt_b; k < i;k++) {
                    if (G[k].vx != t_vx) {
                        res -= ((k - tt_b)*(k-tt_b-1)) ;
                        tt_b = k;
                        t_vx = G[k].vx;
                    }
                }
                res -=(i - tt_b)*(i - tt_b - 1);
            }
            t_b = i;
            t_m = G[i].magic;
        }
    }
    res += ((n - t_b) * (n - t_b - 1)) ;
    int t_vx = G[t_b].vx;
    int tt_b = t_b;
    for (int k = tt_b; k < n;k++) {
        if (G[k].vx != t_vx) {
            res -= ((k - tt_b)*(k-tt_b-1)) ;
            tt_b = k;
            t_vx = G[k].vx;
        }
    }
    res -=(n - tt_b)*(n - tt_b - 1);
    cout << res;
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
struct ghost {
    int vx,vy;
    long long magic;
    ghost(int x,int y,int a):vx(x),vy(y),magic((long long)a*x - y){}
};
bool cmp1(const ghost& x,const ghost& y) {
    return x.magic < y.magic;
}
bool cmp2(const ghost& x,const ghost& y) {
    return x.vx < y.vx;
}
vector <ghost> G;
int main () {
    int n,a,b;
    cin >> n >> a >> b;
    for (int i = 0 ; i < n; i ++) {
        int x,vx,vy;
        cin >> x >> vx >> vy;
        ghost tmp(vx,vy,a);
        G.push_back(tmp);
    }
    stable_sort(G.begin(), G.end(),cmp2);
    stable_sort(G.begin(), G.end(),cmp1);
    int res = 0;
    long long t_m = G[0].magic;
    int t_b = 0;
    for (int i = 0 ; i < G.size(); i++) {
        if (G[i].magic != t_m) {
            if (i-t_b > 1) {
                res += ((i - t_b) * (i - t_b - 1)) ;
                int t_vx = G[t_b].vx;
                int tt_b = t_b;
                for (int k = tt_b; k < i;k++) {
                    if (G[k].vx != t_vx) {
                        res -= ((k - tt_b)*(k-tt_b-1)) ;
                        tt_b = k;
                        t_vx = G[k].vx;
                    }
                }
                res -=(i - tt_b)*(i - tt_b - 1);
            }
            t_b = i;
            t_m = G[i].magic;
        }
    }
    res += ((n - t_b) * (n - t_b - 1)) ;
    int t_vx = G[t_b].vx;
    int tt_b = t_b;
    for (int k = tt_b; k < n;k++) {
        if (G[k].vx != t_vx) {
            res -= ((k - tt_b)*(k-tt_b-1)) ;
            tt_b = k;
            t_vx = G[k].vx;
        }
    }
    res -=(n - tt_b)*(n - tt_b - 1);
    cout << res;
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
struct ghost {
    int vx,vy;
    long long magic;
    ghost(int x,int y,int a):vx(x),vy(y),magic((long long)a*x - y){}
};
bool cmp1(const ghost& x,const ghost& y) {
    return x.magic < y.magic;
}
bool cmp2(const ghost& x,const ghost& y) {
    return x.vx < y.vx;
}
vector <ghost> G;
int main () {
    int n,a,b;
    cin >> n >> a >> b;
    for (int i = 0 ; i < n; i ++) {
        int x,vx,vy;
        cin >> x >> vx >> vy;
        ghost tmp(vx,vy,a);
        G.push_back(tmp);
    }
    stable_sort(G.begin(), G.end(),cmp2);
    stable_sort(G.begin(), G.end(),cmp1);
    long long res = 0;
    long long t_m = G[0].magic;
    int t_b = 0;
    for (int i = 0 ; i < G.size(); i++) {
        if (G[i].magic != t_m) {
            if (i-t_b > 1) {
                res += ((ll)(i - t_b) * (i - t_b - 1)) ;
                int t_vx = G[t_b].vx;
                int tt_b = t_b;
                for (int k = tt_b; k < i;k++) {
                    if (G[k].vx != t_vx) {
                        res -= ((ll)(k - tt_b)*(k-tt_b-1)) ;
                        tt_b = k;
                        t_vx = G[k].vx;
                    }
                }
                res -=(ll)(i - tt_b)*(i - tt_b - 1);
            }
            t_b = i;
            t_m = G[i].magic;
        }
    }
    res += (ll)((n - t_b) * (n - t_b - 1)) ;
    int t_vx = G[t_b].vx;
    int tt_b = t_b;
    for (int k = tt_b; k < n;k++) {
        if (G[k].vx != t_vx) {
            res -= (ll)((k - tt_b)*(k-tt_b-1)) ;
            tt_b = k;
            t_vx = G[k].vx;
        }
    }
    res -= (ll)(n - tt_b)*(n - tt_b - 1);
    cout << res;
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
struct ghost {
    long long vx,vy;
    long long magic;
    ghost(long long x,long long y,long long a):vx(x),vy(y),magic((long long)a*x - y){}
};
bool cmp1(const ghost& x,const ghost& y) {
    return x.magic < y.magic;
}
bool cmp2(const ghost& x,const ghost& y) {
    return x.vx < y.vx;
}
vector <ghost> G;
int main () {
    long long n,a,b;
    cin >> n >> a >> b;
    for (long long i = 0 ; i < n; i ++) {
        long long x,vx,vy;
        cin >> x >> vx >> vy;
        ghost tmp(vx,vy,a);
        G.push_back(tmp);
    }
    stable_sort(G.begin(), G.end(),cmp2);
    stable_sort(G.begin(), G.end(),cmp1);
    long long res = 0;
    long long t_m = G[0].magic;
    long long t_b = 0;
    for (long long i = 0 ; i < G.size(); i++) {
        if (G[i].magic != t_m) {
            if (i-t_b > 1) {
                res += ((i - t_b) * (i - t_b - 1)) ;
                long long t_vx = G[t_b].vx;
                long long tt_b = t_b;
                for (long long k = tt_b; k < i;k++) {
                    if (G[k].vx != t_vx) {
                        res -= ((k - tt_b)*(k-tt_b-1)) ;
                        tt_b = k;
                        t_vx = G[k].vx;
                    }
                }
                res -=(i - tt_b)*(i - tt_b - 1);
            }
            t_b = i;
            t_m = G[i].magic;
        }
    }
    res += ((n - t_b) * (n - t_b - 1)) ;
    long long t_vx = G[t_b].vx;
    long long tt_b = t_b;
    for (long long k = tt_b; k < n;k++) {
        if (G[k].vx != t_vx) {
            res -= ((k - tt_b)*(k-tt_b-1)) ;
            tt_b = k;
            t_vx = G[k].vx;
        }
    }
    res -= (n - tt_b)*(n - tt_b - 1);
    cout << res;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll>
#define vv vector<v>
#define p pair<ll,ll>
#define pa pair<ll,ll>
#define MAX 15000001
int main()
{
    ll n,a,b;
    cin>>n>>b>>a;
    map<p,ll> counter;
    map<ll,ll> counter2;
    vector<p> arr(n+1);
    for (int i=1; i<=n; i++)
    {
        ll x,v1,v2;
        cin>>x>>v1>>v2;
        arr[i]=p(v1,v2);
        counter[p(v1,v2)]++;
        counter2[b*v1-v2]++;
    }
    ll ans=0;
    ll sub=0;
    for (int i=1; i<=n; i++)
    {
        ll temp=b*arr[i].first-arr[i].second;
        ans+=counter2[temp]-1;
        sub+=counter[arr[i]]-1;
    }
    ans=ans-sub;
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll>
#define vv vector<v>
#define p pair<ll,ll>
#define pa pair<ll,ll>
#define MAX 15000001
int main()
{
    ll n,a,b;
    cin>>n>>b>>a;
    map<p,ll> counter;
    map<ll,ll> counter2;
    vector<p> arr(n+1);
    for (int i=1; i<=n; i++)
    {
        ll x,v1,v2;
        cin>>x>>v1>>v2;
        arr[i]=p(v1,v2);
        counter[p(v1,v2)]++;
        counter2[b*v2-v1]++;
    }
    ll ans=0;
    ll sub=0;
    for (int i=1; i<=n; i++)
    {
        ll temp=b*arr[i].second-arr[i].first;
        ans+=counter2[temp]-1;
        sub+=counter[arr[i]]-1;
    }
    ans=ans-sub;
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll>
#define vv vector<v>
#define p pair<ll,ll>
#define pa pair<ll,ll>
#define MAX 15000001
int main()
{
    int n,a,b;
    cin>>n>>b>>a;
    map<p,ll> counter;
    map<ll,ll> counter2;
    vector<p> arr(n+1);
    for (int i=1; i<=n; i++)
    {
        int x,v1,v2;
        cin>>x>>v1>>v2;
        arr[i]=p(v1,v2);
        counter[p(v1,v2)]++;
        counter2[b*v2-v1]++;
    }
    ll ans=0;
    ll sub=0;
    for (int i=1; i<=n; i++)
    {
        ll temp=b*arr[i].second-arr[i].first;
        ans+=counter2[temp]-1;
        sub+=counter[arr[i]]-1;
    }
    ans=ans-sub;
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define left(x) ((x) << 1)
#define right(x) ((x) << 1 | 1)
#define mid(x, y) ((x) + (y) >> 1)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<pair<ll, ll>, ll> plll;

const int maxn = 2 * 1e5 + 17;

int N;
ll A, B, R;
plll points[maxn];
bool dirty[maxn];
map<pair<ll, ll>, pair<ll, ll> > mapa;

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> A >> B; A = abs(A); B = abs(B);
    for (int i = 0; i < N; i++) {
        cin >> points[i].s >> points[i].f.f >> points[i].f.s;

        ll x = abs(points[i].f.f), y = abs(points[i].f.s);
        ll gcd = __gcd(x, y);

        if (gcd > 0) {
            points[i].f.f /= gcd;
            points[i].f.s /= gcd;
        }

        if (points[i].f.f < 0) {
            dirty[i] = true;
            points[i].f.f = -points[i].f.f;
            points[i].f.s = -points[i].f.s;
        }

        pair<ll, ll> cp = mapa[mp(points[i].f.f, points[i].f.s)];

        if (dirty[i]) cp.s++;
        else          cp.f++;

        mapa[mp(points[i].f.f, points[i].f.s)] = cp;

    /// cout << points[i].f.f << " " << points[i].f.s << " " << points[i].s << " " << A * points[i].s + B << endl;
    }

    pair<ll, ll> nm = mapa[mp(0, 0)];
    ll nmp = nm.f + nm.s;

    pair<ll, ll> rem = mapa[mp(A, B)];
    ll nt = rem.f + rem.s;
/**

    rem = mapa[mp(-A, -B)];
    ll ntt = rem.f + rem.s;
**/

    R += (nmp * rem.f + nmp * rem.s) << 1;

/// R += rem.f * rem.s << 1;

    ll total = 0;
    for (auto x = mapa.begin(); x != mapa.end(); x++) total += (*x).s.f + (*x).s.s;

    total -= nmp;
/// total -= rem.f + rem.s;

    for (auto x = mapa.begin(); x != mapa.end(); x++) {
        if ((*x).f.f == 0 && (*x).f.s == 0 /** || (*x).f.f == A && (*x).f.s == B **/) continue;

    /// cout << "XXX " << (*x).f.f << " " << (*x).f.s << " ... " << (*x).s.f << " " << (*x).s.s << endl;

        ll ctot = (*x).s.f + (*x).s.s;

        R += ctot * (total - ctot) + (*x).s.f * (ctot - (*x).s.f) + (*x).s.s * (ctot - (*x).s.s);
    }

    cout << R << endl;

    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define left(x) ((x) << 1)
#define right(x) ((x) << 1 | 1)
#define mid(x, y) ((x) + (y) >> 1)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<pair<ll, ll>, ll> plll;

const int maxn = 2 * 1e5 + 17;

int N;
ll A, B, R;
plll points[maxn];
map<pair<ll, ll>, ll> mapb;
map<ll, ll> mapa;
int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> A >> B;

    for (int i = 0; i < N; i++)
    {
        cin >> points[i].s >> points[i].f.f >> points[i].f.s;

        R += mapa[A * points[i].f.f - points[i].f.s];
        R -= mapb[mp(points[i].f.f, points[i].f.s)];

        mapa[A * points[i].f.f - points[i].f.s]++;
        mapb[mp(points[i].f.f, points[i].f.s)]++;
    }

    cout << (R << 1) << endl;

    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define left(x) ((x) << 1)
#define right(x) ((x) << 1 | 1)
#define mid(x, y) ((x) + (y) >> 1)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<pair<ll, ll>, ll> plll;

const int maxn = 2 * 1e5 + 17;

int N;
ll A, B, R;
plll points[maxn];
map<ll, ll> mapa;

ll fix;
ll cnt[2];

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> A >> B;

    ll a = A;
/// ll gg = __gcd(a, b);

/**
    if (gg > 0) {
        a = A / gg;
        b = B / gg;
    }
**/

    for (int i = 0; i < N; i++)
    {
        cin >> points[i].s >> points[i].f.f >> points[i].f.s;

        ll x = abs(points[i].f.f), y = abs(points[i].f.s);
        ll gcd = __gcd(x, y);

        ll xp = points[i].f.f, yp = points[i].f.s;

        if (gcd > 0) {
            xp /= gcd;
            yp /= gcd;
        }

        if (abs(xp) >= abs(a) && abs(xp) % abs(a) == 0 && abs(yp) == 1LL) { /// (xp % a == 0 && abs(yp) == 1LL || xp == -a && abs(yp) == 1LL) {
            cnt[xp > 0]++;
            continue;
        }

        if (xp == 0 && yp == 0) {
            fix++;
            continue;
        }

        mapa[A * points[i].f.f - points[i].f.s]++;
    }

    for (auto x = mapa.begin(); x != mapa.end(); x++)
        R += x->s * (x->s - 1);

    R += cnt[0] * cnt[1] * 2LL + fix * (cnt[0] + cnt[1]) * 2LL;

    cout << R << endl;

    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define left(x) ((x) << 1)
#define right(x) ((x) << 1 | 1)
#define mid(x, y) ((x) + (y) >> 1)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<pair<ll, ll>, ll> plll;

const int maxn = 2 * 1e5 + 17;

int N;
ll A, B, R;
plll points[maxn];
map<ll, ll> mapa;

ll fix;
ll cnt[2];

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> A >> B;

    ll a = A;
/// ll gg = __gcd(a, b);

/**
    if (gg > 0) {
        a = A / gg;
        b = B / gg;
    }
**/

    for (int i = 0; i < N; i++)
    {
        cin >> points[i].s >> points[i].f.f >> points[i].f.s;

        ll x = abs(points[i].f.f), y = abs(points[i].f.s);
        ll gcd = __gcd(x, y);

        ll xp = points[i].f.f, yp = points[i].f.s;

        if (gcd > 0) {
            xp /= gcd;
            yp /= gcd;
        }

        if (xp >= abs(a) && xp % abs(a) == 0 && abs(yp) == 1LL) { /// (xp % a == 0 && abs(yp) == 1LL || xp == -a && abs(yp) == 1LL) {
            cnt[xp == a]++;
            continue;
        }

        if (xp == 0 && yp == 0) {
            fix++;
            continue;
        }

        mapa[A * points[i].f.f - points[i].f.s]++;
    }

    for (auto x = mapa.begin(); x != mapa.end(); x++)
        R += x->s * (x->s - 1);

    R += cnt[0] * cnt[1] * 2LL + fix * (cnt[0] + cnt[1]) * 2LL;

    cout << R << endl;

    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define left(x) ((x) << 1)
#define right(x) ((x) << 1 | 1)
#define mid(x, y) ((x) + (y) >> 1)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<pair<ll, ll>, ll> plll;

const int maxn = 2 * 1e5 + 17;

int N;
ll A, B, R;
plll points[maxn];
map<ll, ll> mapa;

ll fix;
ll cnt[2];

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> A >> B;

    ll a = abs(A), b = abs(B);
    ll gg = __gcd(a, b);

    if (gg > 0) {
        a = A / gg;
        b = B / gg;
    }

    for (int i = 0; i < N; i++)
    {
        cin >> points[i].s >> points[i].f.f >> points[i].f.s;

        ll x = abs(points[i].f.f), y = abs(points[i].f.s);
        ll gcd = __gcd(x, y);

        ll xp = points[i].f.f, yp = points[i].f.s;

        if (gcd > 0) {
            xp /= gcd;
            yp /= gcd;
        }

        if (xp == a && abs(yp) == 1LL || xp == -a && abs(yp) == 1LL) {
            cnt[xp == a]++;
            continue;
        }

        if (xp == 0 && yp == 0) {
            fix++;
            continue;
        }

        mapa[A * points[i].f.f - points[i].f.s]++;
    }

    for (auto x = mapa.begin(); x != mapa.end(); x++)
        R += x->s * (x->s - 1);

    R += cnt[0] * cnt[1] * 2LL + fix * (cnt[0] + cnt[1]) * 2LL;

    cout << R << endl;

    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define left(x) ((x) << 1)
#define right(x) ((x) << 1 | 1)
#define mid(x, y) ((x) + (y) >> 1)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<pair<ll, ll>, ll> plll;

const int maxn = 2 * 1e5 + 17;

int N;
ll A, B, R;
plll points[maxn];
map<ll, ll> mapa;

ll fix;
ll cnt[2];

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> A >> B;

    B = 1LL;

    ll a = abs(A), b = abs(B);
    ll gg = __gcd(a, b);

    if (gg > 0) {
        a = A / gg;
        b = B / gg;
    }

    for (int i = 0; i < N; i++)
    {
        cin >> points[i].s >> points[i].f.f >> points[i].f.s;

        ll x = abs(points[i].f.f), y = abs(points[i].f.s);
        ll gcd = __gcd(x, y);
        if (gcd > 0) {
            points[i].f.f /= gcd;
            points[i].f.s /= gcd;
        }

        if (points[i].f.f == a && points[i].f.s == b || points[i].f.f == -a && points[i].f.s == -b) {
            cnt[points[i].f.f == a]++;
            continue;
        }

        if (points[i].f.f == 0 && points[i].f.s == 0) {
            fix++;
            continue;
        }

        mapa[A * points[i].f.f - points[i].f.s]++;
    }

    for (auto x = mapa.begin(); x != mapa.end(); x++)
        R += x->s * (x->s - 1);

    R += cnt[0] * cnt[1] * 2LL + fix * (cnt[0] + cnt[1]) * 2LL;

    cout << R << endl;

    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define left(x) ((x) << 1)
#define right(x) ((x) << 1 | 1)
#define mid(x, y) ((x) + (y) >> 1)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<pair<ll, ll>, ll> plll;

const int maxn = 2 * 1e5 + 17;

int N;
ll A, B, R;
plll points[maxn];
bool dirty[maxn];
map<pair<ll, ll>, pair<ll, ll> > mapa;

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> A >> B;
    for (int i = 0; i < N; i++) {
        cin >> points[i].s >> points[i].f.f >> points[i].f.s;

        ll x = abs(points[i].f.f), y = abs(points[i].f.s);
        ll gcd = __gcd(x, y);

        if (gcd > 0) {
            points[i].f.f /= gcd;
            points[i].f.s /= gcd;
        }

        if (points[i].f.f < 0) {
            dirty[i] = true;
            points[i].f.f = -points[i].f.f;
            points[i].f.s = -points[i].f.s;
        }

        pair<ll, ll> cp = mapa[mp(points[i].f.f, points[i].f.s)];

        if (dirty[i]) cp.s++;
        else          cp.f++;

        mapa[mp(points[i].f.f, points[i].f.s)] = cp;

    /// cout << points[i].f.f << " " << points[i].f.s << " " << points[i].s << " " << A * points[i].s + B << endl;
    }

    pair<ll, ll> nm = mapa[mp(0, 0)];
    ll nmp = nm.f + nm.s;

    pair<ll, ll> rem = mapa[mp(A, B)];
    ll nt = rem.f + rem.s;

/**
    rem = mapa[mp(-A, -B)];
    ll ntt = rem.f + rem.s;
**/

    R += (nmp * rem.f + nmp * rem.s) << 1;

    ll total = 0;
    for (auto x = mapa.begin(); x != mapa.end(); x++) total += (*x).s.f + (*x).s.s;

    total -= nmp;

    for (auto x = mapa.begin(); x != mapa.end(); x++) {
        if ((*x).f.f == 0 && (*x).f.s == 0) continue;

        ll ctot = (*x).s.f + (*x).s.s;

        R += ctot * (total - ctot) + (*x).s.f * (ctot - (*x).s.f) + (*x).s.s * (ctot - (*x).s.s);
    }

    cout << R << endl;

    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define left(x) ((x) << 1)
#define right(x) ((x) << 1 | 1)
#define mid(x, y) ((x) + (y) >> 1)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<pair<ll, ll>, ll> plll;

const int maxn = 2 * 1e5 + 17;

int N;
ll A, B, R;
plll points[maxn];
map<pair<ll, ll>, ll> mapb;
map<ll, ll> mapa;
int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> A >> B;

    for (int i = 0; i < N; i++)
    {
        cin >> points[i].s >> points[i].f.f >> points[i].f.s;

        R += mapa[A * points[i].f.f - points[i].f.s];
        R -= mapb[mp(points[i].f.f, points[i].f.s)]++;

        mapa[A * points[i].f.f - points[i].f.s]++;
        mapb[mp(points[i].f.f, points[i].f.s)]++;
    }

    cout << (R << 1) << endl;

    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define left(x) ((x) << 1)
#define right(x) ((x) << 1 | 1)
#define mid(x, y) ((x) + (y) >> 1)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<pair<ll, ll>, ll> plll;

const int maxn = 2 * 1e5 + 17;

int N;
ll A, B, R;
plll points[maxn];
map<pair<ll, ll>, ll> mapb;
map<ll, ll> mapa;
int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> A >> B;

    for (int i = 0; i < N; i++)
    {
        cin >> points[i].s >> points[i].f.f >> points[i].f.s;

        R += mapa[A * points[i].f.f - points[i].f.s];
        R -= mapb[mp(points[i].f.f, points[i].f.s)]++;

        mapa[A * points[i].f.f - points[i].f.s]++;
        mapb[mp(points[i].f.f, points[i].f.s)]++;
    }

    cout << R << endl;

    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define left(x) ((x) << 1)
#define right(x) ((x) << 1 | 1)
#define mid(x, y) ((x) + (y) >> 1)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<pair<ll, ll>, ll> plll;

const int maxn = 2 * 1e5 + 17;

int N;
ll A, B, R;
plll points[maxn];
map<ll, ll> mapa;

ll fix;
ll cnt[2];

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> A >> B;

    for (int i = 0; i < N; i++)
    {
        cin >> points[i].s >> points[i].f.f >> points[i].f.s;

        ll x = abs(points[i].f.f), y = abs(points[i].f.s);
        ll gcd = __gcd(x, y);

        ll xp = points[i].f.f, yp = points[i].f.s;

        if (gcd > 0) {
            xp /= gcd;
            yp /= gcd;
        }

        if (xp == A && yp == 1LL || xp == -A && yp == -1LL) {
            cnt[xp == A]++;
            continue;
        }

        if (xp == 0 && yp == 0) {
            fix++;
            continue;
        }

        mapa[A * points[i].f.f - points[i].f.s]++;
    }

    for (auto x = mapa.begin(); x != mapa.end(); x++)
        R += x->s * (x->s - 1);

    R += cnt[0] * cnt[1] * 2LL + fix * (cnt[0] + cnt[1]) * 2LL;

    cout << R << endl;

    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define left(x) ((x) << 1)
#define right(x) ((x) << 1 | 1)
#define mid(x, y) ((x) + (y) >> 1)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<pair<ll, ll>, ll> plll;

const int maxn = 2 * 1e5 + 17;

int N;
ll A, B, R;
plll points[maxn];
bool dirty[maxn];
map<pair<ll, ll>, pair<ll, ll> > mapa;

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> A >> B;
    for (int i = 0; i < N; i++) {
        cin >> points[i].s >> points[i].f.f >> points[i].f.s;

        ll x = abs(points[i].f.f), y = abs(points[i].f.s);
        ll gcd = __gcd(x, y);

        if (gcd > 0) {
            points[i].f.f /= gcd;
            points[i].f.s /= gcd;
        }

        if (points[i].f.f < 0) {
            dirty[i] = true;
            points[i].f.f = -points[i].f.f;
            points[i].f.s = -points[i].f.s;
        }

        pair<ll, ll> cp = mapa[mp(points[i].f.f, points[i].f.s)];

        if (dirty[i]) cp.s++;
        else          cp.f++;

        mapa[mp(points[i].f.f, points[i].f.s)] = cp;

    /// cout << points[i].f.f << " " << points[i].f.s << " " << points[i].s << " " << A * points[i].s + B << endl;
    }

    pair<ll, ll> nm = mapa[mp(0, 0)];
    ll nmp = nm.f + nm.s;

    pair<ll, ll> rem = mapa[mp(A, B)];
    ll nt = rem.f + rem.s;

    rem = mapa[mp(-A, -B)];
    ll ntt = rem.f + rem.s;

    R += (nmp * nt + nmp * ntt) << 1;

    ll total = 0;
    for (auto x = mapa.begin(); x != mapa.end(); x++) total += (*x).s.f + (*x).s.s;

    total -= nmp;

    for (auto x = mapa.begin(); x != mapa.end(); x++) {
        if ((*x).f.f == 0 && (*x).f.s == 0) continue;

        ll ctot = (*x).s.f + (*x).s.s;

        R += ctot * (total - ctot) + (*x).s.f * (ctot - (*x).s.f) + (*x).s.s * (ctot - (*x).s.s);
    }

    cout << R << endl;

    return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
ll n,a,b;
map<int,int >spc;
map<pair<int,int>,int>m;

bool px(ll x1,ll y1,ll x2,ll y2){
    if(x1==0&&x2==0)return 1;
    if(y1==0&&y2==0)return 1;
    if(x1*y2==y1*x2)return 1;
    else return 0;
}

int main(){
   //freopen("G.in","r",stdin);
   scanf("%lld%lld%lld",&n,&b,&a);
   a = 1;
   ll i,j,x,y,vx,vy,num=0,num2=0,res=0;
   for(i=1;i<=n;i++){
    scanf("%lld%lld%lld",&x,&vx,&vy);
    if(px(vx,vy,a,b)){
        spc[vx/a]++;
        num2++;
        res += (num2-spc[vx/a])*2;
    }
    else{
        j = vx/a;
        vx %= a;
        if(vx<0){
            vx += a;
            j++;
        }
        vy -= j*b;
        res += m[make_pair(vx,vy)]*2;
        m[make_pair(vx,vy)]++;
    }
   }
   printf("%lld",res);
}


#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
ll n,a,b;
map<pair<int,int>,int>m;
map<pair<int,int>,int>m2;

int main(){
   //freopen("G.in","r",stdin);
   scanf("%lld%lld%lld",&n,&b,&a);
   a = 1;
   ll i,j,x,y,vx,vy,num=0,num2=0,res=0;
   for(i=1;i<=n;i++){
    scanf("%lld%lld%lld",&x,&vx,&vy);
    m2[make_pair(vx,vy)]++;
    y = m2[make_pair(vx,vy)];
    j = vx/a;
    vx %= a;
    if(vx<0){
        vx += a;
        j++;
    }
    vy -= j*b;
    m[make_pair(vx,vy)]++;
    res += (m[make_pair(vx,vy)]-y)*2;
   }
   printf("%lld",res);
}


#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
ll n,a,b;
map<pair<ll,ll>,int>m;
map<pair<ll,ll>,int>m2;

int main(){
  // freopen("G.in","r",stdin);
   scanf("%lld%lld%lld",&n,&b,&a);
   a = 1;
   ll i,j,x,y,vx,vy,num=0,num2=0,res=0;
   for(i=1;i<=n;i++){
    scanf("%lld%lld%lld",&x,&vx,&vy);
    m2[make_pair(vx,vy)]++;
    y = m2[make_pair(vx,vy)];
    j = vx/a;
    vx %= a;
    if(vx<0){
        vx += a;
        j++;
    }
    vy -= j*b;
    m[make_pair(vx,vy)]++;
    res += (m[make_pair(vx,vy)]-y)*2;
   }
   printf("%lld",res);
}


#include <bits/stdc++.h>
#define P pair <int,int>
#define mp make_pair
using namespace std;

const int N=200005;
int n,A,B,x[N],vx[N],vy[N];
map <P,int> cnt; int tot,num; P pa,pr[N]; long long ans;

int gcd (int x,int y) {
	return y?gcd(y,x%y):x;
}
long long An2 (int n) {
	return 1ll*n*(n-1);
}
int main () {
	cin>>n>>A>>B,ans=An2(n);
	for (int i=1,g; i<=n; ++i) {
		scanf("%d%d%d",&x[i],&vx[i],&vy[i]);
		g=gcd(abs(vx[i]),abs(vy[i]));
		if (vx[i]==0&&vy[i]==0) {++num; continue;}
		pa=mp(vx[i]/g,vy[i]/g);
		if (cnt[pa]==0) pr[++tot]=pa; ++cnt[pa];
	}
	for (int i=1; i<=tot; ++i) ans-=An2(cnt[pr[i]]);
	pa=mp(A,1),ans-=1ll*cnt[pa]*num;
	pa=mp(-A,-1),ans-=1ll*cnt[pa]*num;
	ans-=An2(num);
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,a,b; ll ans;
map <ll,int> gr;
map <pair <int,int>,int> sam;
int main() {
	cin>>n>>a>>b;
	for (int i=1; i<=n; ++i) {
		int x,vx,vy;
		scanf("%d%d%d",&x,&vx,&vy);
		ans+=gr[1ll*a*vx-vy]-sam[{vx,vy}];
		++gr[1ll*a*vx-vy],++sam[{vx,vy}];
	}
	cout<<ans*2<<endl;
}
/*

1:(X1,aX1+b) 2:(X2,aX2+b)
1 and 2 meet at the moment T:
{X1+vx1*T=X2+vx2*T
{aX1+b+vy1*T=aX2+b+vy2*T
->
-avx1+vy1=-avx2+vy2
->
avx1-vy1=avx2-vy2 ----- A
即若两个ghost具有相同的avx-vy，则会有collision
不过我们知道，两者平行时无碰撞，即
vx1*vy2=vx2*vy1 ----- B
AB两式进行微操，得到

(avx2-vy2+vy1)*vy2=avx2*vy1
avx2*(vy1-vy2)=vy2*(vy1-vy2)
然后？

*/


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,a,b; ll ans;
map <ll,int> gr;
map <pair <int,int>,int> sam;
int main() {
	cin>>n>>a>>b;
	for (int i=1; i<=n; ++i) {
		int x,vx,vy;
		scanf("%d%d%d",&x,&vx,&vy);
		ans+=gr[1ll*a*vx-vy]-sam[{vx,vy}];
		++gr[1ll*a*vx-vy],++sam[{vx,vy}];
	}
	cout<<ans*2<<endl;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#define ll long long
using namespace std;

typedef pair<ll, ll> P;
map<ll, map<ll, ll>>mp;
map<ll, ll> mp2;
set<P> s;

int main()
{
	int n; ll a; ll b;
	scanf("%d%lld%lld", n, a, b);
	for (int i = 1; i <= n; i++)
	{
		int x; ll vx; ll vy;
		scanf("%d", &x);
		scanf("%lld", &vx);
		scanf("%lld", &vy);
		mp[vx][vy] += 1;
		s.insert(P(vx, vy));
	}

	set<P>::iterator it;
	ll ans = 0;
	for (it = s.begin(); it != s.end(); it++)
	{
		ll VX = (*it).first; ll VY = (*it).second;
		ll S = a * VX - VY;
		ans += mp2[S] * mp[VX][VY];
		mp2[S] += mp[VX][VY];
	}
	ans *= 2;
	printf("%lld", ans);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#define ll long long
using namespace std;

typedef pair<ll, ll> P;
map<ll, map<ll, ll>>mp;
map<ll, ll> mp2;
set<P> s;

int main()
{
	int n; ll a; ll b;
	scanf("%d%lld%lld", &n, &a, &b);
	for (int i = 1; i <= n; i++)
	{
		int x; ll vx; ll vy;
		scanf("%d", &x);
		scanf("%lld", &vx);
		scanf("%lld", &vy);
		mp[vx][vy] += 1;
		s.insert(P(vx, vy));
	}

	set<P>::iterator it;
	ll ans = 0;
	for (it = s.begin(); it != s.end(); it++)
	{
		ll VX = (*it).first; ll VY = (*it).second;
		ll S = a * VX - VY;
		ans += mp2[S] * mp[VX][VY];
		mp2[S] += mp[VX][VY];
	}
	ans *= 2;
	printf("%lld", ans);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#define ll long long
using namespace std;

typedef pair<ll, ll> P;
map<ll, map<ll, ll>>mp;
map<ll, ll> mp2;
set<P> s;

int main()
{
	int n; ll a; ll b;
	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++)
	{
		int x; ll vx; ll vy;
		cin >> x >> vx >> vy;
		mp[vx][vy] += 1;
		s.insert(P(vx, vy));
	}

	set<P>::iterator it;
	ll ans = 0;
	for (it = s.begin(); it != s.end(); it++)
	{
		ll VX = (*it).first; ll VY = (*it).second;
		ll S = a * VX - VY;
		ans += mp2[S] * mp[VX][VY];
		mp2[S] += mp[VX][VY];
	}
	ans *= 2;
	cout << ans;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <map>
#define ll long long
using namespace std;

const int maxn = 2e5+10;

ll n, a, b, ans, pl;
map<ll, ll, ll> m;
map<pair<ll, ll>, ll> p;

int main () {
    ans = 0, pl = 0;
    scanf("%I64d %I64d %I64d", &n, &a, &b);
    for (int i = 0; i < n; i++) {
        ll x, vx, vy;
        scanf("%I64d %I64d %I64d", &x, &vx, &vy);
        ll k = a*vx-vy;
        ans += m[k];
        m[k]++;
        pl += p[make_pair(vx, vy)];
        p[make_pair(vx, vy)]++;
    }
    cout << (ans-pl)*2 << '\n';
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <map>
#define ll long long
using namespace std;

const int maxn = 2e5+10;

ll n, a, b, ans, pl;
map<ll, ll> m;
map<pair<ll, ll>, ll> p;

int main () {
    ans = 0, pl = 0;
    scanf("%I64d %I64d %I64d", &n, &a, &b);
    for (int i = 0; i < n; i++) {
        ll x, vx, vy;
        scanf("%I64d %I64d %I64d", &x, &vx, &vy);
        ll k = a*vx-vy;
        ans += m[k];
        m[k]++;
        pl += p[make_pair(vx, vy)];
        p[make_pair(vx, vy)]++;
    }
    cout << (ans-pl)*2 << '\n';
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;

const int maxn = 2e5+10;

struct poi {
    ll x, y, vx, vy;
};

ll n, a, b;
poi ar[maxn];

int main () {
    scanf("%I64d %I64d %I64d", &n, &a, &b);
    for (int i = 0; i < n; i++) {
        scanf("%I64d %I64d %I64d", &ar[i].x, &ar[i].vx, &ar[i].vy);
        ar[i].y = a*ar[i].x+b;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) {
                continue;
            }
            if ((ar[i].x-ar[j].x)*(ar[j].vy-ar[i].vy)-(ar[i].y-ar[j].y)*(ar[j].vx-ar[i].vx) == 0 && (ar[i].vx != ar[j].vx && ar[i].vy != ar[j].vy)) {
                ans++;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;

const int maxn = 2e5+10;

struct poi {
    ll x, y, vx, vy;
};

ll n, a, b;
poi ar[maxn];

int main () {
    scanf("%I64d %I64d %I64d", &n, &a, &b);
    for (int i = 0; i < n; i++) {
        scanf("%I64d %I64d %I64d", &ar[i].x, &ar[i].vx, &ar[i].vy);
        ar[i].y = a*ar[i].x+b;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if ((ar[i].x-ar[j].x)*(ar[j].vy-ar[i].vy)-(ar[i].y-ar[j].y)*(ar[j].vx-ar[i].vx) == 0 && (ar[i].vx != ar[j].vx && ar[i].vy != ar[j].vy)) {
                ans+=2;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;

const int maxn = 2e5+10;

struct poi {
    ll x, y, vx, vy;
};

ll n, a, b;
poi ar[maxn];

int main () {
    scanf("%I64d %I64d %I64d", &n, &a, &b);
    for (int i = 0; i < n; i++) {
        scanf("%I64d %I64d %I64d", &ar[i].x, &ar[i].vx, &ar[i].vy);
        ar[i].y = a*ar[i].x+b;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if ((ar[i].x-ar[j].x)*(ar[j].vy-ar[i].vy)-(ar[i].y-ar[j].y)*(ar[j].vx-ar[i].vx) == 0 && (ar[i].vx != ar[j].vx && ar[i].vy != ar[j].vy)) {
                ans++;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;
long long n,a,b,vx,vy;
struct node
{
    long long v1,v2;
    long long o;
    bool operator==(node tar)
    {
        if(this->v1==tar.v1&&this->v2==tar.v2)
            return true;
        return false;
    }
}v[200005];

bool cmp(node p,node q)
{
    if(p.o==q.o)
    {
        if(p.v1==q.v1) return p.v2<q.v2;
        return p.v1<q.v1;
    }
    return p.o<q.o;
}

int main()
{
    scanf("%I64d%I64d%I64d",&n,&a,&b);
    for(int i=0;i<n;++i)
    {
        scanf("%*d%I64d%I64d",&v[i].v1,&v[i].v2);
        v[i].o=v[i].v2-v[i].v1*a;
    }
    sort(v,v+n,cmp);
    int cnt=1,con=1;
    long long ans=0;
    for(int i=1;i<n;++i)
    {
        if(v[i].o==v[i-1].o)
        {
            if(v[i]==v[i-1]) ++con;
            else ans-=(con-1)*con,con=1;
            ++cnt;
        }
        else{
            ans+=(cnt-1)*cnt;
            ans-=(con-1)*con;
            cnt=1;
            con=1;
        }
    }
    ans+=(cnt-1)*cnt;
    ans-=(con-1)*con;
    cout<<ans;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;
long long n,a,b,vx,vy;
struct node
{
    long long v1,v2;
    long long o;
    bool operator==(node tar)
    {
        if(this->v1==tar.v1&&this->v2==tar.v2)
            return true;
        return false;
    }
}v[200005];

bool cmp(node p,node q)
{
    if(p.o==q.o)
    {
        if(p.v1==q.v1) return p.v2<q.v2;
        return p.v1<q.v1;
    }
    return p.o<q.o;
}

int main()
{
    scanf("%I64d%I64d%I64d",&n,&a,&b);
    for(int i=0;i<n;++i)
    {
        scanf("%*d%I64d%I64d",&v[i].v1,&v[i].v2);
        v[i].o=v[i].v2-v[i].v1*a;
    }
    sort(v,v+n,cmp);
    int cnt=1,con=1;
    long long ans=0;
    for(int i=1;i<n;++i)
    {
        if(v[i].o==v[i-1].o)
        {
            if(v[i]==v[i-1]) ++con;
            else ans-=(con-1)*con,con=1;
            ++cnt;
        }
        else{
            ans+=(cnt-1)*cnt;
            cnt=1;
            con=1;
        }
    }
    ans+=(cnt-1)*cnt;
    ans-=(con-1)*con;
    cout<<ans;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;
long long n,a,b,vx,vy;
struct node
{
    long long v1,v2;
    long long o;
    bool operator==(node tar)
    {
        if(this->v1==tar.v1&&this->v2==tar.v2)
            return true;
        return false;
    }
}v[200005];

bool cmp(node p,node q)
{
    if(p.o==q.o)
    {
        if(p.v1==q.v1) return p.v2<q.v2;
        return p.v1<q.v1;
    }
    return p.o<q.o;
}

int main()
{
    scanf("%I64d%I64d%I64d",&n,&a,&b);
    for(int i=0;i<n;++i)
    {
        scanf("%*d%I64d%I64d",&v[i].v1,&v[i].v2);
        v[i].o=v[i].v2-v[i].v1*a;
    }
    sort(v,v+n,cmp);
    int cnt=1,con=1;
    long long ans=0;
    for(int i=1;i<n;++i)
    {
        if(v[i].o==v[i-1].o)
        {
            if(v[i]==v[i-1]) ++con;
            else ans-=(con-1)*con,con=1;
            ++cnt;
        }
        else{
            ans+=(cnt-1)*cnt;
            cnt=1;
        }
    }
    ans+=(cnt-1)*cnt;
    ans+=(con-1)*con;
    cout<<ans;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;
long long n,a,b,vx,vy;
struct node
{
    long long v1,v2;
    long long o;
    bool operator==(node tar)
    {
        if(this->v1==tar.v1&&this->v2==tar.v2)
            return true;
        return false;
    }
}v[200005];

bool cmp(node p,node q)
{
    if(p.o==q.o)
    {
        if(p.v1==q.v1) return p.v2<q.v2;
        return p.v1<q.v1;
    }
    return p.o<q.o;
}

int main()
{
    scanf("%I64d%I64d%I64d",&n,&a,&b);
    for(int i=0;i<n;++i)
    {
        scanf("%*d%I64d%I64d",&v[i].v1,&v[i].v2);
        v[i].o=v[i].v2-v[i].v1*a;
    }
    sort(v,v+n,cmp);
    long long  cnt=1,con=1;
    long long ans=0;
    for(int i=1;i<n;++i)
    {
        if(v[i].o==v[i-1].o)
        {
            if(v[i]==v[i-1]) ++con;
            else ans-=(con-1)*con,con=1;
            ++cnt;
        }
        else{
            ans+=(cnt-1)*cnt;
            ans-=(con-1)*con;
            cnt=1;
            con=1;
        }
    }
    ans+=(cnt-1)*cnt;
    ans-=(con-1)*con;
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long triangle_area_2 (long long x1, long long y1, long long x2, long long y2, long long x3, long long y3) {
	return (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1);
}

map < pair < long long , long long > , long long > mp;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++;
        mp[{y[i],z[i]}]++;
    }
    for (i=1;i<=n;i++)
        ans+=n-mp[{y[i],z[i]}];
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            long long gc=__gcd(abs(y[i]),abs(z[i]));
            y[i]/=gc;
            z[i]/=gc;
            if (y[i] == 1 && z[i] == b)
                ans+=zero;
            if (y[i] == -1 && z[i] == -b)
                ans+=zero;

        }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

map < pair < int , int > , int > mp;
long long ans;
int n,a,b,x,i;
int y[200020];
int z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x>>y[i]>>z[i];
        mp[{y[i],z[i]}]++;
    }
    for (i=1;i<=n;i++)
        ans+=n-mp[{y[i],z[i]}];
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

long long triangle_area_2 (long long x1, long long y1, long long x2, long long y2, long long x3, long long y3) {
	return (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1);
}

map < pair < long long , long long > , long long > mp;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++;
        mp[{y[i],z[i]}]++;
    }
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            ans+=n-mp[{y[i],z[i]}];
            if ( a*z[i] == y[i] )
                ans+=zero*2;

        }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

map < pair < long long , long long > , long long > mp,mpzy;
map <long long , long long > all,mpz,mpy;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++; else
        {
            if (a*z[i] == y[i]) {
                if (y[i] < 0) {
                    y[i]*=-1;
                    z[i]*=-1;
                }
                if (y[i] == 0) {
                    if (z[i] < 0)
                        z[i]*=-1;

                }
                long long gc=__gcd(abs(z[i]),abs(y[i]));
                z[i]/=gc;
                y[i]/=gc;
                mp[{y[i],z[i]}]++;
            } else {
                all[z[i]-a*y[i]]++;
                mpz[z[i]]++;
                mpy[y[i]]++;
                mpzy[{z[i],y[i]}]++;
            }
        }
    }
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            if ( a*z[i] == y[i] ) {
                ans+=n-mp[{y[i],z[i]}]-zero;
                ans+=zero*2;
                } else {
                    ans+=all[z[i]-a*y[i]];
                    ans-=mpz[z[i]];
                    ans-=mpy[y[i]];
                    ans+=mpzy[{z[i],y[i]}];
                }
        }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

map < pair < long long , long long > , long long > mp;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++; else
        {
            if (a*z[i] != y[i]) {
                if (y[i] < 0) {
                    y[i]*=-1;
                    z[i]*=-1;
                }
                if (y[i] == 0) {
                    if (z[i] < 0)
                        z[i]*=-1;
                }
                long long gc=__gcd(abs(z[i]),abs(y[i]));
                z[i]/=gc;
                y[i]/=gc;
            }
            mp[{y[i],z[i]}]++;
        }
    }
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            ans+=n-mp[{y[i],z[i]}]-zero;
            if ( a*z[i] == y[i] )
                ans+=zero*2;
        }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

map < pair < long long , long long > , long long > mp,mpzy;
map <long long , long long > all,mpz,mpy;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++; else
        {
            if (a*z[i] == y[i]) {
                mp[{y[i],z[i]}]++;
            } else {
                all[z[i]-a*y[i]]++;
                mpz[z[i]]++;
                mpy[y[i]]++;
                mpzy[{z[i],y[i]}]++;
            }
        }
    }
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            if ( a*z[i] == y[i] ) {
                ans+=n-mp[{y[i],z[i]}]-zero;
                ans+=zero*2;
                } else {
                    ans+=all[z[i]-a*y[i]];
                    ans-=mpz[z[i]];
                    ans-=mpy[y[i]];
                    ans+=mpzy[{z[i],y[i]}];
                }
        }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

map < pair < long long , long long > , long long > mp;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++; else
        {
            if (a*z[i] != y[i]) {
                if (y[i] < 0) {
                    y[i]*=-1;
                    z[i]*=-1;
                }
                if (y[i] == 0) {
                    if (z[i] < 0)
                        z[i]*=-1;
                }
                long long gc=__gcd(z[i],y[i]);
                z[i]/=gc;
                y[i]/=gc;
            }
            mp[{y[i],z[i]}]++;
        }
    }
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            ans+=n-mp[{y[i],z[i]}]-zero;
            if ( a*z[i] == y[i] )
                ans+=zero*2;
        }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

long long triangle_area_2 (long long x1, long long y1, long long x2, long long y2, long long x3, long long y3) {
	return (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1);
}

map < pair < long long , long long > , long long > mp;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++;
        mp[{y[i],z[i]}]++;
    }
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            ans+=n-mp[{y[i],z[i]}];
            long long gc=__gcd(abs(y[i]),abs(z[i]));
            y[i]/=gc;
            z[i]/=gc;
            if (y[i] == 1 && z[i] == b)
                ans+=zero*2;
            if (y[i] == -1 && z[i] == -b)
                ans+=zero*2;

        }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

map < pair < long long , long long > , long long > mp;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++;
        mp[{y[i],z[i]}]++;
    }
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            ans+=n-mp[{y[i],z[i]}]-zero;
            if ( a*z[i] == y[i] )
                ans+=zero*2;

        }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

long long triangle_area_2 (long long x1, long long y1, long long x2, long long y2, long long x3, long long y3) {
	return (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1);
}

map < pair < long long , long long > , long long > mp;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++;
        mp[{y[i],z[i]}]++;
    }
    for (i=1;i<=n;i++)
        ans+=n-mp[{y[i],z[i]}];
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            long long gc=__gcd(abs(y[i]),abs(z[i]));
            y[i]/=gc;
            z[i]/=gc;
            if (y[i] == 1 && z[i] == b)
                ans+=zero;
            if (y[i] == -1 && z[i] == b)
                ans+=zero;

        }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

map < pair < long long , long long > , long long > mp;
map <long long , long long > all;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++; else
        {
            if (a*z[i] == y[i]) {
                mp[{y[i],z[i]}]++;
            } else {
                all[z[i]-a*y[i]]++;
            }
        }
    }
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            if ( a*z[i] == y[i] ) {
                ans+=n-mp[{y[i],z[i]}]-zero;
                ans+=zero*2;
                } else {
                    ans+=all[z[i]-a*y[i]]-1;
                }
        }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

map < pair < long long , long long > , long long > mp;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++; else {
            if (a*z[i] != y[i]) {
                if (y[i] < 0) {
                    y[i]*=-1;
                    z[i]*=-1;
                }
                if (y[i] == 0) {
                    z[i]*=-1;
                }
                long long gc=__gcd(z[i],y[i]);
                z[i]/=gc;
                y[i]/=gc;
            }
            mp[{y[i],z[i]}]++;
        }
    }
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            ans+=n-mp[{y[i],z[i]}]-zero;
            if ( a*z[i] == y[i] )
                ans+=zero*2;
        }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

map < pair < long long , long long > , long long > mp;
map <long long , long long > all;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++; else
        {
            if (a*z[i] != y[i]) {
                if (y[i] < 0) {
                    y[i]*=-1;
                    z[i]*=-1;
                }
                if (y[i] == 0) {
                    if (z[i] < 0)
                        z[i]*=-1;

                }
                long long gc=__gcd(abs(z[i]),abs(y[i]));
                z[i]/=gc;
                y[i]/=gc;
                mp[{y[i],z[i]}]++;
            } else {
                all[z[i]-a*y[i]]++;
            }
        }
    }
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            if ( a*z[i] == y[i] ) {
                ans+=n-mp[{y[i],z[i]}]-zero;
                ans+=zero*2;
                } else {
                    ans+=all[z[i]-a*y[i]]-1;
                }
        }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

map < pair < long long , long long > , long long > mp;
map <long long , long long > all;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++; else
        {
            if (a*z[i] != y[i]) {
                if (y[i] < 0) {
                    y[i]*=-1;
                    z[i]*=-1;
                }
                if (y[i] == 0) {
                    if (z[i] < 0)
                        z[i]*=-1;

                }
                long long gc=__gcd(abs(z[i]),abs(y[i]));
                z[i]/=gc;
                y[i]/=gc;
                all[z[i]-a*y[i]]++;
            } else {
                mp[{y[i],z[i]}]++;
            }
        }
    }
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            if ( a*z[i] == y[i] ) {
                ans+=n-mp[{y[i],z[i]}]-zero;
                ans+=zero*2;
                } else {
                    ans+=all[z[i]-a*y[i]]-1;
                }
        }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

map < pair < long long , long long > , long long > mp;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++; else {
            if (a*z[i] != y[i]) {
                long long gc=__gcd(z[i],y[i]);
                z[i]/=gc;
                y[i]/=gc;
            }
            mp[{y[i],z[i]}]++;
        }
    }
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            ans+=n-mp[{y[i],z[i]}]-zero;
            if ( a*z[i] == y[i] )
                ans+=zero*2;
        }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

map < pair < long long , long long > , long long > mp;
map <long long , long long > all;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++; else
        {
            if (a*z[i] == y[i]) {
            } else {
                all[z[i]-a*y[i]]++;
            }
        }
    }
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            if ( a*z[i] == y[i] ) {
                ans+=n-mp[{y[i],z[i]}]-zero;
                ans+=zero*2;
                } else {
                    ans+=all[z[i]-a*y[i]]-1;
                }
        }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

map < pair < long long , long long > , long long > mp,mpzy;
map <long long , long long > all;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++; else
        {
            if (a*z[i] == y[i]) {
                mp[{y[i],z[i]}]++;
            } else {
                all[z[i]-a*y[i]]++;
                mpzy[{z[i],y[i]}]++;
            }
        }
    }
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            if ( a*z[i] == y[i] ) {
                ans+=n-mp[{y[i],z[i]}]-zero;
                ans+=zero*2;
                } else {
                    ans+=all[z[i]-a*y[i]];
                    ans-=mpzy[{z[i],y[i]}];
                }
        }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

long long triangle_area_2 (long long x1, long long y1, long long x2, long long y2, long long x3, long long y3) {
	return (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1);
}

map < pair < long long , long long > , long long > mp;
long long ans,zero;
long long  n,a,b,i;
long long x[200020];
long long y[200020];
long long z[200020];

int main() {
    std::ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    for (i=1;i<=n;i++) {
        cin>>x[i]>>y[i]>>z[i];
        if (y[i] == 0 && z[i] == 0)
            zero++;
        mp[{y[i],z[i]}]++;
    }
    for (i=1;i<=n;i++)
        if (y[i] != 0 || z[i] != 0) {
            ans+=n-mp[{y[i],z[i]}];
            y[i]=abs(y[i]);
            z[i]=abs(z[i]);
            long long gc=__gcd(y[i],z[i]);
            y[i]/=gc;
            z[i]/=gc;
            if (y[i] == 1 && z[i] == a)
                ans+=zero*2;

        }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 200010
#define ll long long
int n;
ll a,b;
struct P
{
    ll x,y;
    bool operator < (const P& c)const
    {
        if(a*x-y!=a*c.x-c.y)return a*x-y<a*c.x-c.y;
        return x<c.x;
    }
}v[maxn];
vector<int> vv;
main()
{
    scanf("%d%lld%lld",&n,&a,&b);
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d%lld%lld",&x,&v[i].x,&v[i].y);
    }
    sort(v+1,v+n+1);
    //for(int i=1;i<=n;i++)printf("%lld %lld: %lld\n",v[i].x,v[i].y,a*v[i].x-v[i].y);
    ll ans=0;
    int num=0,cur=0;
    for(int i=1;i<=n;i++)
    {
        if(i!=1 && v[i-1].x==v[i].x && v[i-1].y==v[i].y)cur++,num++;
        else if(i==1 || a*v[i-1].x-v[i-1].y<a*v[i].x-v[i].y)
        {
            vv.push_back(cur);
            //printf("%d\n",num);
            ans+=1ll*num*(num-1);
            num=1,cur=1;
            for(int s : vv)ans-=1ll*s*(s-1);
            //for(int s : vv)printf("%d ",s);puts("");
            vv.clear();
        }
        else
        {
            num++;
            vv.push_back(cur);
            cur=1;
        }
    }
    vv.push_back(cur);
    ans+=1ll*num*(num-1);
    for(int s : vv)ans-=1ll*s*(s-1);
    //printf("%d\n",num);
    //for(int s : vv)printf("%d ",s);puts("");
    //for(int s : vv)printf("%d ",s);puts("");
    printf("%lld\n",ans);
    return 0;
}