#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

vector<vi> gr, ch, hopp;
vi par, sz, h;
vl sum, mus;

void init(int v){
	int ix = 0, p = par[v];
	while(p >= 0){
		hopp[v].pb(p);
		if(ix >= hopp[p].size()) break;
		p = hopp[p][ix++];
	}
	sz[v] = 1;
	for(int c : gr[v])
		if(c != par[v]){
			par[c] = v;
			h[c] = h[v]+1;
			ch[v].pb(c);
			init(c);
			sum[v] += sum[c]+sz[c];
			sz[v] += sz[c];
		}
}

int upp(int a, int d){
	for(int ix = 0; d > 0; ix++) {
		if(d%2 == 1)
			a = hopp[a][ix];
		d /= 2;
	}
	return a;
}

int lca(int a, int b){
	if(h[b] < h[a]) swap(a,b);
	b = upp(b, h[b]-h[a]);
	if(a == b) return a;
	for(int ix = hopp[a].size()-1; ix >= 0; --ix){
		if(ix >= hopp[a].size()) continue;
		int a1 = hopp[a][ix];
		int b1 = hopp[b][ix];
		if(a1 != b1){
			a = a1;
			b = b1;
		}
	}
	return par[a];
}

void init2(int v){
	int p = par[v];
	mus[v] += mus[p] + sz[0]-sz[p]+1;
	for(int c : ch[p]) if(c != v){
		mus[v] += sum[c]+2*sz[c];
	}
	for(int c : ch[v]) init2(c);
}

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	gr.resize(n);ch.resize(n);hopp.resize(n);par.resize(n);
	sz.resize(n);sum.resize(n);h.resize(n);mus.resize(n);
	rep(_,0,n-1){
		int a,b;
		scanf("%d%d",&a,&b);
		--a,--b;
		gr[a].pb(b), gr[b].pb(a);
	}
	par[0] = -1;
	init(0);
	for(int c : ch[0])
		init2(c);
	while(m--){
		int u,v;
		scanf("%d%d",&u,&v);
		--u,--v;
		int l = lca(u,v);
		int d = h[v]+h[u]-2*h[l];
		if(l == v) swap(u,v);
		double x;
		if(l == u){
			u = upp(v, h[v]-h[u]-1);
			x = (double)mus[u]/(sz[0]-sz[u]) - 1;
		} else {
			x = (double)sum[u]/sz[u];
		}
		printf("%.9lf\n",d+(double)sum[v]/sz[v]+1+x);
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <bitset>
#include <random>
#include <cassert>
#include <cstdio>
#include <cstring>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> int(a);)
#define allof(v) v.begin(),v.end()
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector<bool> vb;
typedef long double ld;
const ll inf = 1LL<<60;
const ll md = 1e9+7;
const ld eps = 1e-14;
const double pi = acos(-1);

vector<vi> gr, ch, hopp;
vi par, sz, h;
vl sum, mus;

void init(int v){
	int ix = 0, p = par[v];
	while(p >= 0){
		hopp[v].pb(p);
		if(ix >= hopp[p].size()) break;
		p = hopp[p][ix++];
	}
	sz[v] = 1;
	for(int c : gr[v])
		if(c != par[v]){
			par[c] = v;
			h[c] = h[v]+1;
			ch[v].pb(c);
			init(c);
			sum[v] += sum[c]+sz[c];
			sz[v] += sz[c];
		}
}

int upp(int a, int d){
	for(int ix = 0; d > 0; ix++) {
		if(d%2 == 1)
			a = hopp[a][ix];
		d /= 2;
	}
	return a;
}

int lca(int a, int b){
	if(h[b] < h[a]) swap(a,b);
	b = upp(b, h[b]-h[a]);
	if(a == b) return a;
	for(int ix = hopp[a].size()-1; ix >= 0; --ix){
		if(ix >= hopp[a].size()) continue;
		int a1 = hopp[a][ix];
		int b1 = hopp[b][ix];
		if(a1 != b1){
			a = a1;
			b = b1;
		}
	}
	return par[a];
}

void init2(int v){
	int p = par[v];
	mus[v] += mus[p] + sz[0]-sz[p]+1;
	for(int c : ch[p]) if(c != v){
		mus[v] += sum[c]+2*sz[c];
	}
	for(int c : ch[v]) init2(c);
}

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	gr.resize(n);ch.resize(n);hopp.resize(n);par.resize(n);
	sz.resize(n);sum.resize(n);h.resize(n);mus.resize(n);
	rep(_,0,n-1){
		int a,b;
		scanf("%d%d",&a,&b);
		--a,--b;
		gr[a].pb(b), gr[b].pb(a);
	}
	par[0] = -1;
	init(0);
	for(int c : ch[0])
		init2(c);
	//rep(i,0,n) printf("%lld %lld\n",sum[i], mus[i]);
	while(m--){
		int u,v;
		scanf("%d%d",&u,&v);
		--u,--v;
		int l = lca(u,v);
		int d = h[v]+h[u]-2*h[l];
		if(l == v) swap(u,v);
		double x;
		if(l == u){
			u = upp(v, h[v]-h[u]-1);
			x = (double)mus[u]/(sz[0]-sz[u]) - 1;
		} else {
			x = (double)sum[u]/sz[u];
		}
		printf("%.9lf\n",d+(double)sum[v]/sz[v]+1+x);
	}
}


#include <bits/stc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

vector<vi> gr, ch, hopp;
vi par, sz, h;
vl sum, mus;

void init(int v){
	int ix = 0, p = par[v];
	while(p >= 0){
		hopp[v].pb(p);
		if(ix >= hopp[p].size()) break;
		p = hopp[p][ix++];
	}
	sz[v] = 1;
	for(int c : gr[v])
		if(c != par[v]){
			par[c] = v;
			h[c] = h[v]+1;
			ch[v].pb(c);
			init(c);
			sum[v] += sum[c]+sz[c];
			sz[v] += sz[c];
		}
}

int upp(int a, int d){
	for(int ix = 0; d > 0; ix++) {
		if(d%2 == 1)
			a = hopp[a][ix];
		d /= 2;
	}
	return a;
}

int lca(int a, int b){
	if(h[b] < h[a]) swap(a,b);
	b = upp(b, h[b]-h[a]);
	if(a == b) return a;
	for(int ix = hopp[a].size()-1; ix >= 0; --ix){
		if(ix >= hopp[a].size()) continue;
		int a1 = hopp[a][ix];
		int b1 = hopp[b][ix];
		if(a1 != b1){
			a = a1;
			b = b1;
		}
	}
	return par[a];
}

void init2(int v){
	int p = par[v];
	mus[v] += mus[p] + sz[0]-sz[p]+1;
	for(int c : ch[p]) if(c != v){
		mus[v] += sum[c]+2*sz[c];
	}
	for(int c : ch[v]) init2(c);
}

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	gr.resize(n);ch.resize(n);hopp.resize(n);par.resize(n);
	sz.resize(n);sum.resize(n);h.resize(n);mus.resize(n);
	rep(_,0,n-1){
		int a,b;
		scanf("%d%d",&a,&b);
		--a,--b;
		gr[a].pb(b), gr[b].pb(a);
	}
	par[0] = -1;
	init(0);
	for(int c : ch[0])
		init2(c);
	while(m--){
		int u,v;
		scanf("%d%d",&u,&v);
		--u,--v;
		int l = lca(u,v);
		int d = h[v]+h[u]-2*h[l];
		if(l == v) swap(u,v);
		double x;
		if(l == u){
			u = upp(v, h[v]-h[u]-1);
			x = (double)mus[u]/(sz[0]-sz[u]) - 1;
		} else {
			x = (double)sum[u]/sz[u];
		}
		printf("%.9lf\n",d+(double)sum[v]/sz[v]+1+x);
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <bitset>
#include <random>
#include <cassert>
#include <cstdio>
#include <cstring>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> int(a);)
#define allof(v) v.begin(),v.end()
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector<bool> vb;
typedef long double ld;
const ll inf = 1LL<<60;
const ll md = 1e9+7;
const ld eps = 1e-14;
const double pi = acos(-1);

vector<vi> gr, ch, hopp;
vi par, sz, h;
vl sum, mus;

void init(int v){
	int ix = 0, p = par[v];
	while(p >= 0){
		hopp[v].pb(p);
		if(ix >= hopp[p].size()) break;
		p = hopp[p][ix++];
	}
	sz[v] = 1;
	for(int c : gr[v])
		if(c != par[v]){
			par[c] = v;
			h[c] = h[v]+1;
			ch[v].pb(c);
			init(c);
			sum[v] += sum[c]+sz[c];
			sz[v] += sz[c];
		}
}

int upp(int a, int d){
	for(int ix = 0; d > 0; ix++) {
		if(d%2 == 1)
			a = hopp[a][ix];
		d /= 2;
	}
	return a;
}

int lca(int a, int b){
	if(h[b] < h[a]) swap(a,b);
	b = upp(b, h[b]-h[a]);
	if(a == b) return a;
	for(int ix = hopp[a].size()-1; ix >= 0; --ix){
		if(ix >= hopp[a].size()) continue;
		int a1 = hopp[a][ix];
		int b1 = hopp[b][ix];
		if(a1 != b1){
			a = a1;
			b = b1;
		}
	}
	return par[a];
}

void init2(int v){
	int p = par[v];
	mus[v] += mus[p] + sz[0]-sz[p]+1;
	for(int c : ch[p]) if(c != v){
		mus[v] += sum[c]+2*sz[c];
	}
	for(int c : ch[v]) init2(c);
}

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	gr.resize(n);ch.resize(n);hopp.resize(n);par.resize(n);
	sz.resize(n);sum.resize(n);h.resize(n);mus.resize(n);
	rep(_,0,n-1){
		int a,b;
		scanf("%d%d",&a,&b);
		--a,--b;
		gr[a].pb(b), gr[b].pb(a);
	}
	par[0] = -1;
	init(0);
	for(int c : ch[0])
		init2(c);
	rep(i,0,n) printf("%lld %lld\n",sum[i], mus[i]);
	while(m--){
		int u,v;
		scanf("%d%d",&u,&v);
		--u,--v;
		int l = lca(u,v);
		int d = h[v]+h[u]-2*h[l];
		if(l == v) swap(u,v);
		double x;
		if(l == u){
			u = upp(v, h[v]-h[u]-1);
			x = (double)mus[u]/(sz[0]-sz[u]) - 1;
		} else {
			x = (double)sum[u]/sz[u];
		}
		printf("%.9lf\n",d+(double)sum[v]/sz[v]+1+x);
	}
}


#include"iostream"
#include<stdio.h>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#define N 100004
#define LN 18
#define pb push_back
using namespace std;
typedef long long ll;
vector<int> adj[N];
int n, m, x, y, p[N], c[N], dp[N][LN], l[N], val, flag, child;
ll f[N], sum[N], ans, ways;
void dfs(int v, int u){
  p[v] = u;
  l[v] = (v == u) ? 0 : l[u] + 1;
  int sz = adj[v].size();
  for(int i = 0; i < sz; i++){
	if(adj[v][i] == u) continue;
	dfs(adj[v][i], v);
	c[v] += c[adj[v][i]];
	f[v] += (f[adj[v][i]] + c[adj[v][i]]);
  }
  c[v]++;
}

int find(int x, int y){
  int res = 0;
  for(int i = LN - 1; i >= 0; i--){
	if(l[dp[x][i]] > l[y]){
	  res += (1 << i);
	  x = dp[x][i];
	}
  }
  if(l[x] > l[y]){
	if(p[x] == y) child = x;
	x = p[x];
	res++;
  }
  if(x == y){
	flag = 1;
	return res;
  }
  for(int i = LN - 1; i >= 0; i--){
	if(dp[x][i] != dp[y][i]){
	  x = dp[x][i];
	  y = dp[y][i];
	  res += (1 << (i + 1));
	}
  }
  return res + 2;
}

void findsum(int v, int u){
  if(v == u) sum[v] = f[v];
  else sum[v] = sum[u] + n - 2 * c[v];
  int sz = adj[v].size();
  for(int i = 0; i < sz; i++)
	if(adj[v][i] != u) findsum(adj[v][i], v);
}

int main(){
  cin >> n >> m;
  for(int i = 0; i < n - 1; i++){
	scanf("%d%d", &x, &y);
	adj[x].pb(y);
	adj[y].pb(x);
  }
  dfs(1, 1);
  findsum(1, 1);
  for(int i = 0; i < LN; i++)
	for(int j = 1; j <= n; j++)
	  dp[j][i] = (i == 0) ? p[j] : dp[dp[j][i - 1]][i - 1];

  for(int i = 0; i < m; i++){
	scanf("%d%d", &x, &y);
	flag = 0;
	if(l[y] > l[x]) swap(x, y);
	val = find(x, y);
	val++;
	if(flag == 0){
	  ans = 1LL * val * c[x] * c[y] + 1LL * c[x] * f[y] + 1LL * c[y] * f[x];
	  ways = 1LL * c[x] * c[y];
	}
	else{
	  ans = 1LL * val * c[x] * (n - c[child]) + 1LL * f[x] * (n - c[child]) + 1LL * c[x] * (sum[y] - f[child] - c[child]);
	  ways = 1LL * c[x] * (n - c[child]);
	}
	printf("%.14lf\n", ((double)(ans)) / ways);
  }
  return 0;
}


#include"iostream"
#include<stdio.h>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#define N 100004
#define LN 18
#define pb push_back
using namespace std;
typedef long long ll;
vector<int> adj[N];
int n, m, x, y, p[N], c[N], dp[N][LN], l[N], val, flag, child;
ll f[N], sum[N], ans, ways;
void dfs(int v, int u){
  p[v] = u;
  l[v] = (v == u) ? 0 : l[u] + 1;
  int sz = adj[v].size();
  for(int i = 0; i < sz; i++){
    if(adj[v][i] == u) continue;
    dfs(adj[v][i], v);
    c[v] += c[adj[v][i]];
    f[v] += (f[adj[v][i]] + c[adj[v][i]]);
  }
  c[v]++;
}

int find(int x, int y){
  int res = 0;
  for(int i = LN - 1; i >= 0; i--){
    if(l[dp[x][i]] > l[y]){
      res += (1 << i);
      x = dp[x][i];
    }
  }
  if(l[x] > l[y]){
    if(p[x] == y) child = x;
    x = p[x];
    res++;
  }
  if(x == y){
    flag = 1;
    return res;
  }
  for(int i = LN - 1; i >= 0; i--){
    if(dp[x][i] != dp[y][i]){
      x = dp[x][i];
      y = dp[y][i];
      res += (1 << (i + 1));
    }
  }
  return res + 2;
}

void findsum(int v, int u){
  if(v == u) sum[v] = f[v];
  else sum[v] = sum[u] + n - 2 * c[v];
  int sz = adj[v].size();
  for(int i = 0; i < sz; i++)
    if(adj[v][i] != u) findsum(adj[v][i], v);
}

int main(){
  cin >> n >> m;
  for(int i = 0; i < n - 1; i++){
    scanf("%d%d", &x, &y);
    adj[x].pb(y);
    adj[y].pb(x);
  }
  dfs(1, 1);
  findsum(1, 1);
  for(int i = 0; i < LN; i++)
    for(int j = 1; j <= n; j++)
      dp[j][i] = (i == 0) ? p[j] : dp[dp[j][i - 1]][i - 1];

  for(int i = 0; i < m; i++){
    cin >> x >> y;
    flag = 0;
    if(l[y] > l[x]) swap(x, y);
    val = find(x, y);
    val++;
    if(flag == 0){
      ans = 1LL * val * c[x] * c[y] + 1LL * c[x] * f[y] + 1LL * c[y] * f[x];
      ways = 1LL * c[x] * c[y];
    }
    else{
      ans = 1LL * val * c[x] * (n - c[child]) + 1LL * f[x] * (n - c[child]) + 1LL * c[x] * (sum[y] - f[child] - c[child]);
      ways = 1LL * c[x] * (n - c[child]);
    }
    printf("%.14lf\n", ((double)(ans)) / ways);
  }
  return 0;
}


#include"iostream"
#include<stdio.h>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#define N 100004
#define LN 18
#define pb push_back
using namespace std;
typedef long long ll;
vector<int> adj[N];
int n, m, x, y, p[N], c[N], dp[N][LN], l[N], val, flag, child;
ll f[N], sum[N], ans, ways;
void dfs(int v, int u){
  p[v] = u;
  l[v] = (v == u) ? 0 : l[u] + 1;
  int sz = adj[v].size();
  for(int i = 0; i < sz; i++){
    if(adj[v][i] == u) continue;
    dfs(adj[v][i], v);
    c[v] += c[adj[v][i]];
    f[v] += (f[adj[v][i]] + c[adj[v][i]]);
  }
  c[v]++;
}

int find(int x, int y){
  int res = 0;
  for(int i = LN - 1; i >= 0; i--){
    if(l[dp[x][i]] > l[y]){
      res += (1 << i);
      x = dp[x][i];
    }
  }
  if(l[x] > l[y]){
    if(p[x] == y) child = x;
    x = p[x];
    res++;
  }
  if(x == y){
    flag = 1;
    return res;
  }
  for(int i = LN - 1; i >= 0; i--){
    if(dp[x][i] != dp[y][i]){
      x = dp[x][i];
      y = dp[y][i];
      res += (1 << (i + 1));
    }
  }
  return res + 2;
}

void findsum(int v, int u){
  if(v == u) sum[v] = f[v];
  else sum[v] = sum[u] + n - 2 * c[v];
  int sz = adj[v].size();
  for(int i = 0; i < sz; i++)
    if(adj[v][i] != u) findsum(adj[v][i], v);
}

int main(){
  cin >> n >> m;
  for(int i = 0; i < n - 1; i++){
    cin >> x >> y;
    adj[x].pb(y);
    adj[y].pb(x);
  }
  dfs(1, 1);
  findsum(1, 1);
  for(int i = 0; i < LN; i++)
    for(int j = 1; j <= n; j++)
      dp[j][i] = (i == 0) ? p[j] : dp[dp[j][i - 1]][i - 1];

  for(int i = 0; i < m; i++){
    cin >> x >> y;
    flag = 0;
    if(l[y] > l[x]) swap(x, y);
    val = find(x, y);
    val++;
    if(flag == 0){
      ans = 1LL * val * c[x] * c[y] + 1LL * c[x] * f[y] + 1LL * c[y] * f[x];
      ways = 1LL * c[x] * c[y];
    }
    else{
      ans = 1LL * val * c[x] * (n - c[child]) + 1LL * f[x] * (n - c[child]) + 1LL * c[x] * (sum[y] - f[child] - c[child]);
      ways = 1LL * c[x] * (n - c[child]);
    }
    printf("%.14lf\n", ((double)(ans)) / ways);
  }
  return 0;
}


#include"iostream"
#include<stdio.h>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#define N 100004
#define LN 18
#define pb push_back
using namespace std;
typedef long long ll;
vector<int> adj[N];
int n, m, x, y, p[N], c[N], f[N], dp[N][LN], l[N], sum[N], val, flag, ans, ways, child;

void dfs(int v, int u){
  p[v] = u;
  l[v] = (v == u) ? 0 : l[u] + 1;
  int sz = adj[v].size();
  for(int i = 0; i < sz; i++){
    if(adj[v][i] == u) continue;
    dfs(adj[v][i], v);
    c[v] += c[adj[v][i]];
    f[v] += (f[adj[v][i]] + c[adj[v][i]]);
  }
  c[v]++;
}

int find(int x, int y){
  int res = 0;
  for(int i = LN - 1; i >= 0; i--){
    if(l[dp[x][i]] > l[y]){
      res += (1 << i);
      x = dp[x][i];
    }
  }
  if(l[x] > l[y]){
    if(p[x] == y) child = x;
    x = p[x];
    res++;
  }
  if(x == y){
    flag = 1;
    return res;
  }
  for(int i = LN - 1; i >= 0; i--){
    if(dp[x][i] != dp[y][i]){
      x = dp[x][i];
      y = dp[y][i];
      res += (1 << (i + 1));
    }
  }
  return res + 2;
}

void findsum(int v, int u){
  if(v == u) sum[v] = f[v];
  else sum[v] = sum[u] + n - 2 * c[v];
  int sz = adj[v].size();
  for(int i = 0; i < sz; i++)
    if(adj[v][i] != u) findsum(adj[v][i], v);
}

int main(){
  cin >> n >> m;
  for(int i = 0; i < n - 1; i++){
    cin >> x >> y;
    adj[x].pb(y);
    adj[y].pb(x);
  }
  dfs(1, 1);
  findsum(1, 1);
  for(int i = 0; i < LN; i++)
    for(int j = 1; j <= n; j++)
      dp[j][i] = (i == 0) ? p[j] : dp[dp[j][i - 1]][i - 1];
  /*
  cout << " ----------\n";
  for(int i = 1; i <= n; i++) cout << c[i] << " " << f[i] << " " << sum[i] << "\n";
  for(int i = 1; i <= n; i++){
    for(int j = 0; j < 4; j++) cout << dp[i][j] << " ";
    cout << "\n";
  }
  cout << " ----------\n";
  */
  for(int i = 0; i < m; i++){
    cin >> x >> y;
    flag = 0;
    if(l[y] > l[x]) swap(x, y);
    val = find(x, y);
    //   cout << val << "\n";
    val++;
    if(flag == 0){
      ans = val * c[x] * c[y] + c[x] * f[y] + c[y] * f[x];
      ways = c[x] * c[y];
    }
    else{
      ans = val * c[x] * (n - c[child]) + f[x] * (n - c[child]) + c[x] * (sum[y] - f[child] - c[child]);
      ways = c[x] * (n - c[child]);
    }
    //  cout << ans << " " << ways << "\n";
    printf("%.14lf\n", ((double)(ans)) / ways);
  }
  return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef __int64 ll;
const int N = 100005;
struct node{
	int to,next;
}edge[N*2];
int n,m,head[N],dep[N],p[N][20],e_cnt;
ll sum[N],dw[N],sz[N];

void addedge(int u,int v){
	edge[e_cnt]=(node){v,head[u]};
	head[u]=e_cnt++;
	edge[e_cnt]=(node){u,head[v]};
	head[v]=e_cnt++;
}

void dfs(int u,int fa){
	dep[u]=dep[fa]+1;
	p[u][0]=fa; sz[u]=1; dw[u]=0;
	for(int k=head[u];~k;k=edge[k].next){
		int v=edge[k].to;
		if(v==fa) continue;
		dfs(v,u);
		sz[u]+=sz[v];
		dw[u]+=dw[v]+sz[v];
	}
}

void dfs2(int u,int fa){
	for(int k=head[u];~k;k=edge[k].next){
		int v=edge[k].to;
		if(v==fa) continue;
		//printf("u %d v %d\n",u,v);
		sum[v]=sum[u]-sz[v]+n-sz[v];
		dfs2(v,u);
	}
}

void init(){
	int i,j;
	for(j=1;(1<<j)<=n;j++){
		for(i=1;i<=n;i++)
			p[i][j]=p[p[i][j-1]][j-1];
	}
}

int up(int x,int d){
	int i;
	for(i=20;i>=0;i--){
		if(d<(1<<i)) continue;
		x=p[x][i];
		d-=1<<i;
	}
	return x;
}

int lca(int u,int v){
	int i,j;
	if(dep[u]<dep[v]) swap(u,v);
	for(i=0;(1<<i)<=dep[u];i++);
	i--;
	for(j=i;j>=0;j--)
		if(dep[u]-(1<<j)>=dep[v])
			u=p[u][j];
	if(u==v) return u;
	for(j=i;j>=0;j--){
		if(~p[u][j] && p[u][j]!=p[v][j]){
			u=p[u][j];
			v=p[v][j];
		}
	}
	return p[u][0];
}

int main(void){
	int i,j,u,v;
	while(~scanf("%d%d",&n,&m)){
		memset(head,-1,sizeof(head));
		e_cnt=0;
		for(i=1;i<n;i++){
			scanf("%d%d",&u,&v);
			addedge(u,v);
		}
		dep[0]=-1; memset(p,-1,sizeof(p));
		dfs(1,0);
		init();
		sum[1]=dw[1];
		dfs2(1,0);
		//for(i=1;i<=n;i++)
		//	printf("sum %d sz %d dw %d\n",sum[i],sz[i],dw[i]);
		while(m--){
			scanf("%d%d",&u,&v);
			int k=lca(u,v);
			double ans=dep[u]+dep[v]-2*dep[k]+1;
			if(u==k){
				int t=up(v,dep[v]-dep[k]-1);
				ans+=(double)(sum[u]-dw[t]-sz[t])/((ll)n-sz[t]);
			}
			else ans+=(double)dw[u]/sz[u];
			if(v==k){
				int t=up(u,dep[u]-dep[k]-1);
				ans+=(double)(sum[v]-dw[t]-sz[t])/((ll)n-sz[t]);
			}
			else ans+=(double)dw[v]/sz[v];
			printf("%.12f\n",ans);
		}
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef __int64 ll;
const int N = 100005;
struct node{
	int to,next;
}edge[N*2];
int n,m,head[N],dep[N],p[N][20],e_cnt;
ll sum[N],dw[N],sz[N];

void addedge(int u,int v){
	edge[e_cnt]=(node){v,head[u]};
	head[u]=e_cnt++;
	edge[e_cnt]=(node){u,head[v]};
	head[v]=e_cnt++;
}

void dfs(int u,int fa){
	dep[u]=dep[fa]+1;
	p[u][0]=fa; sz[u]=1; dw[u]=0;
	for(int k=head[u];~k;k=edge[k].next){
		int v=edge[k].to;
		if(v==fa) continue;
		dfs(v,u);
		sz[u]+=sz[v];
		dw[u]+=dw[v]+sz[v];
	}
}

void dfs2(int u,int fa){
	for(int k=head[u];~k;k=edge[k].next){
		int v=edge[k].to;
		if(v==fa) continue;
		//printf("u %d v %d\n",u,v);
		sum[v]=sum[u]-sz[v]+(ll)n-sz[v];
		dfs2(v,u);
	}
}

void init(){
	int i,j;
	for(j=1;(1<<j)<=n;j++){
		for(i=1;i<=n;i++)
			p[i][j]=p[p[i][j-1]][j-1];
	}
}

int up(int x,int d){
	int i;
	for(i=20;i>=0;i--){
		if(d<(1<<i)) continue;
		x=p[x][i];
		d-=1<<i;
	}
	return x;
}

int lca(int u,int v){
	int i,j;
	if(dep[u]<dep[v]) swap(u,v);
	for(i=0;(1<<i)<=dep[u];i++);
	i--;
	for(j=i;j>=0;j--)
		if(dep[u]-(1<<j)>=dep[v])
			u=p[u][j];
	if(u==v) return u;
	for(j=i;j>=0;j--){
		if(~p[u][j] && p[u][j]!=p[v][j]){
			u=p[u][j];
			v=p[v][j];
		}
	}
	return p[u][0];
}

int main(void){
	int i,j,u,v;
	while(~scanf("%d%d",&n,&m)){
		memset(head,-1,sizeof(head));
		e_cnt=0;
		for(i=1;i<n;i++){
			scanf("%d%d",&u,&v);
			addedge(u,v);
		}
		dep[0]=-1; memset(p,-1,sizeof(p));
		dfs(1,0);
		init();
		sum[1]=dw[1];
		dfs2(1,0);
		//for(i=1;i<=n;i++)
		//	printf("sum %d sz %d dw %d\n",sum[i],sz[i],dw[i]);
		while(m--){
			scanf("%d%d",&u,&v);
			int k=lca(u,v);
			double ans=dep[u]+dep[v]-2*dep[k]+1;
			if(u==k){
				int t=up(v,dep[v]-dep[k]-1);
				ans+=(double)(sum[u]-dw[t]-sz[t])/((ll)n-sz[t]);
			}
			else ans+=(double)dw[u]/sz[u];
			if(v==k){
				int t=up(u,dep[u]-dep[k]-1);
				ans+=(double)(sum[v]-dw[t]-sz[t])/((ll)n-sz[t]);
			}
			else ans+=(double)dw[v]/sz[v];
			printf("%.12f\n",ans);
		}
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 100005;
struct node{
	int to,next;
}edge[N*2];
int n,m,head[N],dep[N],p[N][20];
int sum[N],sz[N],e_cnt,dw[N];

void addedge(int u,int v){
	edge[e_cnt]=(node){v,head[u]};
	head[u]=e_cnt++;
	edge[e_cnt]=(node){u,head[v]};
	head[v]=e_cnt++;
}

void dfs(int u,int fa){
	dep[u]=dep[fa]+1;
	p[u][0]=fa; sz[u]=1; dw[u]=0;
	for(int k=head[u];~k;k=edge[k].next){
		int v=edge[k].to;
		if(v==fa) continue;
		dfs(v,u);
		sz[u]+=sz[v];
		dw[u]+=dw[v]+sz[v];
	}
}

void dfs2(int u,int fa){
	for(int k=head[u];~k;k=edge[k].next){
		int v=edge[k].to;
		if(v==fa) continue;
		//printf("u %d v %d\n",u,v);
		sum[v]=sum[u]-sz[v]+n-sz[v];
		dfs2(v,u);
	}
}

void init(){
	int i,j;
	for(j=1;(1<<j)<=n;j++){
		for(i=1;i<=n;i++)
			p[i][j]=p[p[i][j-1]][j-1];
	}
}

int up(int x,int d){
	int i;
	for(i=20;i>=0;i--){
		if(d<(1<<i)) continue;
		x=p[x][i];
		d-=1<<i;
	}
	return x;
}

int lca(int u,int v){
	int i,j;
	if(dep[u]<dep[v]) swap(u,v);
	for(i=0;(1<<i)<=dep[u];i++);
	i--;
	for(j=i;j>=0;j--)
		if(dep[u]-(1<<j)>=dep[v])
			u=p[u][j];
	if(u==v) return u;
	for(j=i;j>=0;j--){
		if(~p[u][j] && p[u][j]!=p[v][j]){
			u=p[u][j];
			v=p[v][j];
		}
	}
	return p[u][0];
}

int main(void){
	int i,j,u,v;
	while(~scanf("%d%d",&n,&m)){
		memset(head,-1,sizeof(head));
		e_cnt=0;
		for(i=1;i<n;i++){
			scanf("%d%d",&u,&v);
			addedge(u,v);
		}
		dep[0]=-1; memset(p,-1,sizeof(p));
		dfs(1,0);
		init();
		sum[1]=dw[1];
		dfs2(1,0);
		//for(i=1;i<=n;i++)
		//	printf("sum %d sz %d dw %d\n",sum[i],sz[i],dw[i]);
		while(m--){
			scanf("%d%d",&u,&v);
			int k=lca(u,v);
			double ans=dep[u]+dep[v]-2*dep[k]+1;
			if(u==k){
				int t=up(v,dep[v]-dep[k]-1);
				ans+=(double)(sum[u]-dw[t]-sz[t])/(n-sz[t]);
			}
			else ans+=(double)dw[u]/sz[u];
			if(v==k){
				int t=up(u,dep[u]-dep[k]-1);
				ans+=(double)(sum[v]-dw[t]-sz[t])/(n-sz[t]);
			}
			else ans+=(double)dw[v]/sz[v];
			printf("%.12f\n",ans);
		}
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef __int64 ll;
const int N = 100005;
struct node{
	int to,next;
}edge[N*2];
int n,m,head[N],dep[N],p[N][20],e_cnt,sz[N];
ll sum[N],dw[N];

void addedge(int u,int v){
	edge[e_cnt]=(node){v,head[u]};
	head[u]=e_cnt++;
	edge[e_cnt]=(node){u,head[v]};
	head[v]=e_cnt++;
}

void dfs(int u,int fa){
	dep[u]=dep[fa]+1;
	p[u][0]=fa; sz[u]=1; dw[u]=0;
	for(int k=head[u];~k;k=edge[k].next){
		int v=edge[k].to;
		if(v==fa) continue;
		dfs(v,u);
		sz[u]+=sz[v];
		dw[u]+=dw[v]+sz[v];
	}
}

void dfs2(int u,int fa){
	for(int k=head[u];~k;k=edge[k].next){
		int v=edge[k].to;
		if(v==fa) continue;
		//printf("u %d v %d\n",u,v);
		sum[v]=sum[u]-sz[v]+n-sz[v];
		dfs2(v,u);
	}
}

void init(){
	int i,j;
	for(j=1;(1<<j)<=n;j++){
		for(i=1;i<=n;i++)
			p[i][j]=p[p[i][j-1]][j-1];
	}
}

int up(int x,int d){
	int i;
	for(i=20;i>=0;i--){
		if(d<(1<<i)) continue;
		x=p[x][i];
		d-=1<<i;
	}
	return x;
}

int lca(int u,int v){
	int i,j;
	if(dep[u]<dep[v]) swap(u,v);
	for(i=0;(1<<i)<=dep[u];i++);
	i--;
	for(j=i;j>=0;j--)
		if(dep[u]-(1<<j)>=dep[v])
			u=p[u][j];
	if(u==v) return u;
	for(j=i;j>=0;j--){
		if(~p[u][j] && p[u][j]!=p[v][j]){
			u=p[u][j];
			v=p[v][j];
		}
	}
	return p[u][0];
}

int main(void){
	int i,j,u,v;
	while(~scanf("%d%d",&n,&m)){
		memset(head,-1,sizeof(head));
		e_cnt=0;
		for(i=1;i<n;i++){
			scanf("%d%d",&u,&v);
			addedge(u,v);
		}
		dep[0]=-1; memset(p,-1,sizeof(p));
		dfs(1,0);
		init();
		sum[1]=dw[1];
		dfs2(1,0);
		//for(i=1;i<=n;i++)
		//	printf("sum %d sz %d dw %d\n",sum[i],sz[i],dw[i]);
		while(m--){
			scanf("%d%d",&u,&v);
			int k=lca(u,v);
			double ans=dep[u]+dep[v]-2*dep[k]+1;
			if(u==k){
				int t=up(v,dep[v]-dep[k]-1);
				ans+=(double)(sum[u]-dw[t]-sz[t])/(n-sz[t]);
			}
			else ans+=(double)dw[u]/sz[u];
			if(v==k){
				int t=up(u,dep[u]-dep[k]-1);
				ans+=(double)(sum[v]-dw[t]-sz[t])/(n-sz[t]);
			}
			else ans+=(double)dw[v]/sz[v];
			printf("%.12f\n",ans);
		}
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef __int64 ll;
const int N = 100005;
struct node{
	int to,next;
}edge[N*2];
int n,m,head[N],dep[N],p[N][20],e_cnt;
int sum[N],sz[N],dw[N];

void addedge(int u,int v){
	edge[e_cnt]=(node){v,head[u]};
	head[u]=e_cnt++;
	edge[e_cnt]=(node){u,head[v]};
	head[v]=e_cnt++;
}

void dfs(int u,int fa){
	dep[u]=dep[fa]+1;
	p[u][0]=fa; sz[u]=1; dw[u]=0;
	for(int k=head[u];~k;k=edge[k].next){
		int v=edge[k].to;
		if(v==fa) continue;
		dfs(v,u);
		sz[u]+=sz[v];
		dw[u]+=dw[v]+sz[v];
	}
}

void dfs2(int u,int fa){
	for(int k=head[u];~k;k=edge[k].next){
		int v=edge[k].to;
		if(v==fa) continue;
		//printf("u %d v %d\n",u,v);
		sum[v]=sum[u]-sz[v]+n-sz[v];
		dfs2(v,u);
	}
}

void init(){
	int i,j;
	for(j=1;(1<<j)<=n;j++){
		for(i=1;i<=n;i++)
			p[i][j]=p[p[i][j-1]][j-1];
	}
}

int up(int x,int d){
	int i;
	for(i=20;i>=0;i--){
		if(d<(1<<i)) continue;
		x=p[x][i];
		d-=1<<i;
	}
	return x;
}

int lca(int u,int v){
	int i,j;
	if(dep[u]<dep[v]) swap(u,v);
	for(i=0;(1<<i)<=dep[u];i++);
	i--;
	for(j=i;j>=0;j--)
		if(dep[u]-(1<<j)>=dep[v])
			u=p[u][j];
	if(u==v) return u;
	for(j=i;j>=0;j--){
		if(~p[u][j] && p[u][j]!=p[v][j]){
			u=p[u][j];
			v=p[v][j];
		}
	}
	return p[u][0];
}

int main(void){
	int i,j,u,v;
	while(~scanf("%d%d",&n,&m)){
		memset(head,-1,sizeof(head));
		e_cnt=0;
		for(i=1;i<n;i++){
			scanf("%d%d",&u,&v);
			addedge(u,v);
		}
		dep[0]=-1; memset(p,-1,sizeof(p));
		dfs(1,0);
		init();
		sum[1]=dw[1];
		dfs2(1,0);
		//for(i=1;i<=n;i++)
		//	printf("sum %d sz %d dw %d\n",sum[i],sz[i],dw[i]);
		while(m--){
			scanf("%d%d",&u,&v);
			int k=lca(u,v);
			double ans=dep[u]+dep[v]-2*dep[k]+1;
			if(u==k){
				int t=up(v,dep[v]-dep[k]-1);
				ans+=(double)(sum[u]-dw[t]-sz[t])/(n-sz[t]);
			}
			else ans+=(double)dw[u]/sz[u];
			if(v==k){
				int t=up(u,dep[u]-dep[k]-1);
				ans+=(double)(sum[v]-dw[t]-sz[t])/(n-sz[t]);
			}
			else ans+=(double)dw[v]/sz[v];
			printf("%.12f\n",ans);
		}
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef __int64 ll;
const int N = 100005;
struct node{
	int to,next;
}edge[N*2];
int n,m,head[N],dep[N],p[N][20],e_cnt;
ll sum[N],sz[N],dw[N];

void addedge(int u,int v){
	edge[e_cnt]=(node){v,head[u]};
	head[u]=e_cnt++;
	edge[e_cnt]=(node){u,head[v]};
	head[v]=e_cnt++;
}

void dfs(int u,int fa){
	dep[u]=dep[fa]+1;
	p[u][0]=fa; sz[u]=1; dw[u]=0;
	for(int k=head[u];~k;k=edge[k].next){
		int v=edge[k].to;
		if(v==fa) continue;
		dfs(v,u);
		sz[u]+=sz[v];
		dw[u]+=dw[v]+sz[v];
	}
}

void dfs2(int u,int fa){
	for(int k=head[u];~k;k=edge[k].next){
		int v=edge[k].to;
		if(v==fa) continue;
		//printf("u %d v %d\n",u,v);
		sum[v]=sum[u]-sz[v]+n-sz[v];
		dfs2(v,u);
	}
}

void init(){
	int i,j;
	for(j=1;(1<<j)<=n;j++){
		for(i=1;i<=n;i++)
			p[i][j]=p[p[i][j-1]][j-1];
	}
}

int up(int x,int d){
	int i;
	for(i=20;i>=0;i--){
		if(d<(1<<i)) continue;
		x=p[x][i];
		d-=1<<i;
	}
	return x;
}

int lca(int u,int v){
	int i,j;
	if(dep[u]<dep[v]) swap(u,v);
	for(i=0;(1<<i)<=dep[u];i++);
	i--;
	for(j=i;j>=0;j--)
		if(dep[u]-(1<<j)>=dep[v])
			u=p[u][j];
	if(u==v) return u;
	for(j=i;j>=0;j--){
		if(~p[u][j] && p[u][j]!=p[v][j]){
			u=p[u][j];
			v=p[v][j];
		}
	}
	return p[u][0];
}

int main(void){
	int i,j,u,v;
	while(~scanf("%d%d",&n,&m)){
		memset(head,-1,sizeof(head));
		e_cnt=0;
		for(i=1;i<n;i++){
			scanf("%d%d",&u,&v);
			addedge(u,v);
		}
		dep[0]=-1; memset(p,-1,sizeof(p));
		dfs(1,0);
		init();
		sum[1]=dw[1];
		dfs2(1,0);
		//for(i=1;i<=n;i++)
		//	printf("sum %d sz %d dw %d\n",sum[i],sz[i],dw[i]);
		while(m--){
			scanf("%d%d",&u,&v);
			int k=lca(u,v);
			double ans=dep[u]+dep[v]-2*dep[k]+1;
			if(u==k){
				int t=up(v,dep[v]-dep[k]-1);
				ans+=(double)(sum[u]-dw[t]-sz[t])/(n-sz[t]);
			}
			else ans+=(double)dw[u]/sz[u];
			if(v==k){
				int t=up(u,dep[u]-dep[k]-1);
				ans+=(double)(sum[v]-dw[t]-sz[t])/(n-sz[t]);
			}
			else ans+=(double)dw[v]/sz[v];
			printf("%.12f\n",ans);
		}
	}
	return 0;
}


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
using namespace std;
#define MAXN 100005
typedef long long LL;
typedef pair<LL,LL> pii;
#define gc() getchar()
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=gc();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=gc();}
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=gc();}
	x*=f;
}
int head[MAXN],tt,n,m,f[MAXN][20];
LL sum[MAXN],tot[MAXN],dep[MAXN],siz[MAXN];
struct edge{int v,nxt;}e[MAXN<<1];
void addEdge(int u,int v){e[++tt]=(edge){v,head[u]};head[u]=tt;}
void dfs1(int u,int fa){
	f[u][0]=fa;sum[u]=dep[u]=dep[fa]+1;siz[u]=1;
	for(int i=1;i<18;i++)f[u][i]=f[f[u][i-1]][i-1];
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].v;if(v==fa)continue;
		dfs1(v,u);siz[u]+=siz[v];sum[u]+=sum[v];
	}
}
void dfs2(int u,int fa){
	if(fa)tot[u]=tot[fa]+sum[fa]-sum[u]-2ll*(siz[fa]-siz[u])*dep[fa];
	for(int i=head[u];i;i=e[i].nxt)if(e[i].v!=fa)dfs2(e[i].v,u);
}
int lca(int a,int b){
	if(dep[a]<dep[b])swap(a,b);
	for(int i=17;i>=0;i--)
		if(dep[f[a][i]]>=dep[b])
			a=f[a][i];
	if(a==b)return a;
	for(int i=17;i>=0;i--)
		if(f[a][i]!=f[b][i])
			a=f[a][i],b=f[b][i];
	return f[a][0];
}
signed main(){
	read(n);read(m);
	for(int i=1;i<n;i++){
		int u,v;read(u);read(v);
		addEdge(u,v);addEdge(v,u);
	}
	dfs1(1,0);dfs2(1,0);
	for(int i=1;i<=m;i++){
		int u,v;read(u);read(v);if(dep[u]>dep[v])swap(u,v);
		int u_v=lca(u,v),k=v;LL num=0,ans=0;
		if(u_v==u){
			for(int i=17;i>=0;i--)if(dep[f[k][i]]>dep[u])k=f[k][i];
			num=1ll*siz[v]*(siz[1]-siz[k]);
			ans+=1ll*(siz[1]-siz[k])*(sum[v]-dep[v]*siz[v]);
			ans+=1ll*(tot[k]+(siz[1]-siz[k])*dep[u])*siz[v];
			ans+=1ll*num*(dep[v]-dep[u]+1LL);
		}
		else{
			num=1ll*siz[u]*siz[v];
			ans+=1ll*siz[u]*(sum[v]-dep[v]*siz[v]);
			ans+=1ll*siz[v]*(sum[u]-dep[u]*siz[u]);
			ans+=1ll*num*(dep[u]+dep[v]-2ll*dep[u_v]+1LL);
		}
		printf("%.10lf\n",1.0*ans/(1.0*num));
	}
	return 0;
}


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
using namespace std;
#define MAXN 100005
typedef long long LL;
#define int LL
typedef pair<LL,LL> pii;
#define gc() getchar()
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=gc();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=gc();}
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=gc();}
	x*=f;
}
int head[MAXN],tt,n,m,siz[MAXN];
int f[MAXN][20],dep[MAXN];
LL sum[MAXN],tot[MAXN];
struct edge{int v,nxt;}e[MAXN<<1];
void addEdge(int u,int v){e[++tt]=(edge){v,head[u]};head[u]=tt;}
void dfs1(int u,int fa){
	f[u][0]=fa;sum[u]=dep[u]=dep[fa]+1;siz[u]=1;
	for(int i=1;i<18;i++)f[u][i]=f[f[u][i-1]][i-1];
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].v;if(v==fa)continue;
		dfs1(v,u);siz[u]+=siz[v];sum[u]+=sum[v];
	}
}
void dfs2(int u,int fa){
	if(fa)tot[u]=tot[fa]+sum[fa]-sum[u]-2ll*(siz[fa]-siz[u])*dep[fa];
	for(int i=head[u];i;i=e[i].nxt)if(e[i].v!=fa)dfs2(e[i].v,u);
}
int lca(int a,int b){
	if(dep[a]<dep[b])swap(a,b);
	for(int i=17;i>=0;i--)
		if(dep[f[a][i]]>=dep[b])
			a=f[a][i];
	if(a==b)return a;
	for(int i=17;i>=0;i--)
		if(f[a][i]!=f[b][i])
			a=f[a][i],b=f[b][i];
	return f[a][0];
}
signed main(){
	read(n);read(m);
	for(int i=1;i<n;i++){
		int u,v;read(u);read(v);
		addEdge(u,v);addEdge(v,u);
	}
	dfs1(1,0);dfs2(1,0);
	for(int i=1;i<=m;i++){
		int u,v;read(u);read(v);if(dep[u]>dep[v])swap(u,v);
		int u_v=lca(u,v),k=v;LL num=0,ans=0;
		if(u_v==u){
			for(int i=17;i>=0;i--)if(dep[f[k][i]]>dep[u])k=f[k][i];
			num=1ll*siz[v]*(siz[1]-siz[k]);
			ans+=1ll*(siz[1]-siz[k])*(sum[v]-dep[v]*siz[v]);
			ans+=1ll*(tot[k]+(siz[1]-siz[k])*dep[u])*siz[v];
			ans+=1ll*num*(dep[v]-dep[u]+1LL);
		}
		else{
			num=1ll*siz[u]*siz[v];
			ans+=1ll*siz[u]*(sum[v]-dep[v]*siz[v]);
			ans+=1ll*siz[v]*(sum[u]-dep[u]*siz[u]);
			ans+=1ll*num*(dep[u]+dep[v]-2ll*dep[u_v]+1LL);
		}
		printf("%.10lf\n",1.0*ans/(1.0*num));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long vx[200005],vy[200005];
int main()
{
	int n,k,b;
	cin>>n>>k>>b;
	map<long long,int>s;
	for(int i=0;i<n;i++)
	{
		int t;
		cin>>t>>vx[i]>>vy[i];
		if(vx[i]==0&&vy[i]==0) continue;
		s[vx[i]*k-vy[i]]++;
	}
	map<long long,int>::iterator it;
	long long sum=0;
	for(it=s.begin();it!=s.end();it++)
	{
		if(it->second > 1)
			sum+=(it->second)*2;
	}
	cout<<sum<<endl;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;

int main()
{
    //freopen("d:/stdin","r",stdin);
    ll n, a, b;
    cin >> n >> a >> b;

    ll xi, vxi, vyi;
    map<ll, ll> H, Hx, Hy;
    map<pair<ll,ll>, ll> Hxy;
    for(int i=0; i<n; i++)
    {
        cin >> xi >> vxi >> vyi;
        H[vyi-a*vxi] += 1;
        Hx[vxi] += 1;
        Hy[vyi] += 1;
        Hxy[make_pair(vxi, vyi)] += 1;
    }

    ll sol = 0;
    for(auto it : H)
        sol += it.second *(it.second-1);
    for(auto it : Hx)
      sol -= it.second *(it.second-1);
    for(auto it : Hy)
      sol -= it.second *(it.second-1);
    for(auto it : Hxy)
      sol += it.second *(it.second-1);
    //sol *= 2;

    cout << sol << endl;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;

struct myp
{
    ll vx, vy;
    bool operator == (const myp& o) const
    {
        return vx == o.vx || vy == o.vy;
    }
};

namespace std{
  template<>
  struct hash<myp>
  {
      std::size_t operator()(const myp& k) const
      {
          return (k.vx*17 + k.vy)%999999997;
      }
  };
}

int main()
{
    //freopen("d:/stdin","r",stdin);
    ll n, a, b;
    cin >> n >> a >> b;

    ll xi, vxi, vyi;
    map<ll, unordered_map<myp, ll> > H;
    map<ll, ll> H2;
    map< pair<ll,ll>, ll> H3;
    for(int i=0; i<n; i++)
    {
        cin >> xi >> vxi >> vyi;
        myp pp = {vxi, vyi};
        //H[vyi-a*vxi][pp]++;
        H2[vyi-a*vxi]++;
        H3[make_pair(vxi, vyi)]++;
    }

    /*
    ll sol = 0;
    for(auto it : H){
        unordered_map<myp,ll> H2 = it.second;
        ll m = 0;
        for(auto it2=H2.begin(); it2!=H2.end(); it2++){
          m += it2->second;
        }
        for(auto it2=H2.begin(); it2!=H2.end(); it2++)
            sol += it2->second*(m-it2->second);
    }
    cout << sol << endl;
    */

    ll sol = 0;
    for(auto it : H3){
      ll idx = it.first.second - a*it.first.first;
      sol += it.second*(H2[idx] - it.second);
    }
    cout << sol << endl;
    return 0;
}


#include <bits\stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll gcd(ll a, ll b){
    if (b)
        return gcd(b, a%b);
    else
        return a;
}

struct line{
    ll xi, yi;
    ll vxi, vyi;
};

struct trip{
    int z,p,n;
};

int main(int argc, char** argv) {
    if (argc == 2 && atoi(argv[1])==123456789)
        freopen("d:\\code\\CppProjects\\stdin","r",stdin);

    ll n, a, b;
    cin >> n >> a >> b;

    vector<line> v(n+1);
    map< pll, vector<int>> dirs;
    for(int i=0; i<n; ++i){
        cin >> v[i].xi >> v[i].vxi >> v[i].vyi;
        v[i].yi = a*v[i].xi+b;

        ll d = gcd(abs(v[i].vxi), abs(v[i].vyi));
        ll s = 1;
        if (v[i].vxi * v[i].vyi < 0)
            s = -1;
        ll vx2 = abs(v[i].vxi) / d;
        ll vy2 = abs(v[i].vyi) / d;
        dirs[ make_pair(vx2, s*vy2) ].push_back(i);
    }

    ll sol = 0;
    for(auto it : dirs){
        sol += it.second.size() * (n-it.second.size());
        map< pll, trip > posneg;
        for(int i : it.second){
            ll num = v[i].yi*v[i].vxi - v[i].xi*v[i].vyi;
            ll den = v[i].vxi;
            if (den < 0) {
                num = -num;
                den = -den;
            }
            if (num == 0)
                den = abs(den);
            ll d = gcd(abs(num), abs(den));
            pll key;
            if (d!=0)
                key = make_pair(num/d, den/d);
            else
                key = make_pair(num, den);

            int s;
            if (v[i].vxi == 0 &&  v[i].vyi == 0)
                s = 1;
            else if ( (v[i].vxi >= 0 && v[i].vyi >= 0) || (v[i].vxi >= 0 && v[i].vyi == 0) || (v[i].vxi == 0 && v[i].vyi >= 0))
                s = 2;
            else// if ( v[i].vxi *  v[i].vyi >= 0 && (v[i].vxi > 0 || v[i].vyi > 0))
                s = 3;
            trip pp = {0,0,0};
            if (posneg.find(key) != posneg.end())
                pp = posneg[ key ];
            if (s == 1)
                pp.z++;
            else if (s==2)
                pp.p++;
            else
                pp.n++;
            posneg[key] = pp;
        }

        for (auto it : posneg){
            sol += it.second.z * (it.second.n + it.second.p);
            sol += it.second.n * (it.second.z + it.second.p);
            sol += it.second.p * (it.second.n + it.second.z);
        }
    }

    cout << sol;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;

int main()
{
    //freopen("d:/stdin","r",stdin);
    int n, a, b;
    cin >> n >> a >> b;

    int xi, vxi, vyi;
    map<ll, int> H, H2;
    for(int i=0; i<n; i++)
    {
        cin >> xi >> vxi >> vyi;
        H[vyi-(ll)a*vxi] += 1;
        H2[vxi] += 1;
    }

    ll sol = 0;
    for(auto it : H)
        sol += it.second *(it.second-1);

    for(auto it : H2)
      sol -= it.second *(it.second-1);
    //sol *= 2;

    cout << sol << endl;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;

int main()
{
    //freopen("d:/stdin","r",stdin);
    int n, a, b;
    cin >> n >> a >> b;

    int xi, vxi, vyi;
    map<ll, int> H, H2;
    for(int i=0; i<n; i++)
    {
        cin >> xi >> vxi >> vyi;
        H[vyi-(ll)a*vxi] += 1;
        H2[vxi] += 1;
    }

    ll sol = 0;
    for(auto it : H)
        sol += (ll)it.second *(it.second-1);

    for(auto it : H2)
      sol -= (ll)it.second *(it.second-1);
    //sol *= 2;

    cout << sol << endl;
    return 0;
}


#include <bits\stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll gcd(ll a, ll b){
    if (b)
        return gcd(b, a%b);
    else
        return a;
}

struct line{
    ll xi, yi;
    ll vxi, vyi;
};

struct trip{
    int z,p,n;
};

int main(int argc, char** argv) {
    if (argc == 2 && atoi(argv[1])==123456789)
        freopen("d:\\code\\CppProjects\\stdin","r",stdin);

    ll n, a, b;
    cin >> n >> a >> b;

    vector<line> v(n+1);
    map< pll, vector<int>> dirs;
    for(int i=0; i<n; ++i){
        cin >> v[i].xi >> v[i].vxi >> v[i].vyi;
        v[i].yi = a*v[i].xi+b;

        ll d = gcd(abs(v[i].vxi), abs(v[i].vyi));
        if (d==0)
            d = 1;
        ll s = 1;
        if (v[i].vxi * v[i].vyi < 0)
            s = -1;
        ll vx2 = abs(v[i].vxi) / d;
        ll vy2 = abs(v[i].vyi) / d;
        dirs[ make_pair(vx2, s*vy2) ].push_back(i);
    }

    ll sol = 0;
    for(auto it : dirs){
        sol += it.second.size() * (n-it.second.size());
        map< pll, trip > posneg;
        for(int i : it.second){
            ll num = v[i].yi*v[i].vxi - v[i].xi*v[i].vyi;
            ll den = v[i].vxi;
            if (den < 0) {
                num = -num;
                den = -den;
            }
            if (num == 0)
                den = abs(den);
            ll d = gcd(abs(num), abs(den));
            pll key;
            if (d!=0)
                key = make_pair(num/d, den/d);
            else
                key = make_pair(num, den);

            int s;
            if (v[i].vxi == 0 &&  v[i].vyi == 0)
                s = 1;
            else if ( (v[i].vxi >= 0 && v[i].vyi >= 0) || (v[i].vxi >= 0 && v[i].vyi == 0) || (v[i].vxi == 0 && v[i].vyi >= 0))
                s = 2;
            else// if ( v[i].vxi *  v[i].vyi >= 0 && (v[i].vxi > 0 || v[i].vyi > 0))
                s = 3;
            trip pp = {0,0,0};
            if (posneg.find(key) != posneg.end())
                pp = posneg[ key ];
            if (s == 1)
                pp.z++;
            else if (s==2)
                pp.p++;
            else
                pp.n++;
            posneg[key] = pp;
        }

        for (auto it : posneg){
            sol += it.second.z * (it.second.n + it.second.p);
            sol += it.second.n * (it.second.z + it.second.p);
            sol += it.second.p * (it.second.n + it.second.z);
        }
    }

    cout << sol;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;

struct myp
{
    ll vx, vy;
    bool operator == (const myp& o) const
    {
        return vx == o.vx || vy == o.vy;
    }
};

namespace std{
  template<>
  struct hash<myp>
  {
      std::size_t operator()(const myp& k) const
      {
          return (k.vx*17 + k.vy)%999999997;
      }
  };
}

int main()
{
    //freopen("d:/stdin","r",stdin);
    ll n, a, b;
    cin >> n >> a >> b;

    ll xi, vxi, vyi;
    vector<ll> vx, vy;
    map<ll, unordered_map<myp, ll> > H;
    for(int i=0; i<n; i++)
    {
        cin >> xi >> vxi >> vyi;
        vx.push_back(vxi);
        vy.push_back(vyi);
        myp pp = {vxi, vyi};
        H[vyi-a*vxi][pp]++;
    }

    ll sol = 0;
    for(auto it : H){
        unordered_map<myp,ll> H2 = it.second;
        ll m = 0;
        for(auto it2=H2.begin(); it2!=H2.end(); it2++){
          m += it2->second;
        }
        for(auto it2=H2.begin(); it2!=H2.end(); it2++)
            sol += it2->second*(m-it2->second);
    }
    cout << sol << endl;

    /*
    sol = 0;
    for(int i=0; i<vx.size(); i++){
      for(int j=0; j<vy.size(); j++){
        if (i!=j && vy[i]-a*vx[i] == vy[j]-a*vx[j] && vx[i] != vx[j] && vy[i] != vy[j])
          sol++;
      }
    }
    cout << sol << endl;
    */
    return 0;
}


#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
//using namespace std;

#define INF 0x3f3f3f3f
#define INF64 0x3f3f3f3f3f3f3f3f
using namespace std;
const int maxN = 200005;

int main() {
  int n, a, b;
  map<pair<long long int, long long int>, int> velocityCounter;
  map<long long int, int> featureCounter;
  cin >> n >> a >>b;
  long long int sum = 0;
  for (int i = 0; i < n; i ++) {
    long long int x, vx, vy;
    cin >> x >> vx >> vy;
    pair<long long int, long long int> velocity = make_pair(vx, vy);
    if (velocityCounter.find(velocity) != velocityCounter.end()) {
        sum -= velocityCounter[velocity];
        velocityCounter[velocity] ++;
    } else {
        velocityCounter[velocity] = 1;
    }

    long long int feature = a * vx - vy;
    //cout << " && " << a << "*" << vx << "-" << vy << " ="<<feature << "\n";
    //cout << "*" << i <<" "<< vx << " " << vy << " " << feature<< " " << sum << "\n";
    if (featureCounter.find(feature) != featureCounter.end()) {
        sum += featureCounter[feature];
        featureCounter[feature] ++;
    } else {
        featureCounter[feature] = 1;
    }

    //cout << "$"<< i <<" "<< vx << " " << vy << " " << feature<< " " << sum << "\n";
  }
  /*
  for (auto i : velocityCounter) {
    cout << i.first.first << " " << i.first.second << " " << i.second << "\n";
  }*/

  cout << sum * 2;
}


#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
//using namespace std;

#define INF 0x3f3f3f3f
#define INF64 0x3f3f3f3f3f3f3f3f
using namespace std;
const int maxN = 200005;

int main() {
  int n, a, b;
  map<pair<long long int, long long int>, int> velocityCounter;
  map<long long int, int> featureCounter;
  cin >> n >> a >>b;
  long long int sum = 0;
  for (int i = 0; i < n; i ++) {
    long long int x, vx, vy;
    cin >> x >> vx >> vy;
    pair<long long int, long long int> velocity = make_pair(vx, vy);
    if (velocityCounter.find(velocity) != velocityCounter.end()) {
        sum -= velocityCounter[velocity];
        velocityCounter[velocity] ++;
    } else {
        velocityCounter[velocity] = 1;
    }

    long long int feature = a * vx ;
    //cout << " && " << a << "*" << vx << "-" << vy << " ="<<feature << "\n";
    //cout << "*" << i <<" "<< vx << " " << vy << " " << feature<< " " << sum << "\n";
    if (featureCounter.find(feature) != featureCounter.end()) {
        sum += featureCounter[feature];
        featureCounter[feature] ++;
    } else {
        featureCounter[feature] = 1;
    }

    //cout << "$"<< i <<" "<< vx << " " << vy << " " << feature<< " " << sum << "\n";
  }
  /*
  for (auto i : velocityCounter) {
    cout << i.first.first << " " << i.first.second << " " << i.second << "\n";
  }*/

  cout << sum * 2;
}


#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
//using namespace std;

#define INF 0x3f3f3f3f
#define INF64 0x3f3f3f3f3f3f3f3f
using namespace std;
const int maxN = 200005;

int main() {
  int n, a, b;
  map<pair<int, int>, int> velocityCounter;
  map<int, int> featureCounter;
  cin >> n >> a >>b;
  long long int sum = 0;
  for (int i = 0; i < n; i ++) {
    int x, vx, vy;
    cin >> x >> vx >> vy;
    pair<int, int> velocity = make_pair(vx, vy);
    if (velocityCounter.find(velocity) != velocityCounter.end()) {
        sum -= velocityCounter[velocity];
        velocityCounter[velocity] ++;
    } else {
        velocityCounter[velocity] = 1;
    }

    int feature = a * vx - vy;
    //cout << "$"<< vx << " " << vy << " " << feature<< " " << sum << "\n";
    if (featureCounter.find(feature) != featureCounter.end()) {
        sum += featureCounter[feature];
        featureCounter[feature] ++;
    } else {
        featureCounter[feature] = 1;
    }

    //cout << "$"<< vx << " " << vy << " " << feature<< " " << sum << "\n";
  }
  /*
  for (auto i : velocityCounter) {
    cout << i.first.first << " " << i.first.second << " " << i.second << "\n";
  }*/

  cout << sum * 2;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
const double inf=1100000000.0;
llint n,a,b,x,vx,vy,sol;
double k;
map<llint,llint>mp;
map<double,llint>c;
map<pair<llint,llint>,llint>spec;
int main(){
	cin>>n>>a>>b;
	for(int i=0;i<n;i++){
		cin>>x>>vx>>vy;
		mp[vy-a*vx]++;
		if(vx==0) k=inf;
		else{
			k=double(vy)/double(vx);
		}
		if(k!=a) c[k]++;
		else{
			spec[make_pair(vx,vy)]++;
		}
	}
	for(map<llint,llint>::iterator it=mp.begin();it!=mp.end();it++){
		llint t=(*it).second;
		sol+=t*(t-1);
	}
	for(map<double,llint>::iterator it=c.begin();it!=c.end();it++){
		llint t=(*it).second;
		sol-=t*(t-1);
	}
	for(map<pair<llint,llint>,llint>::iterator it=spec.begin();it!=spec.end();it++){
		llint t=(*it).second;
		sol-=t*(t-1);
	}
	cout<<sol<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
const double inf=1100000000.0;
llint n,a,b,x,vx,vy,sol,uk;
double k;
map<llint,llint>mp;
map<pair<llint,double>,llint>c;
map<pair<llint,llint>,llint>spec;
int main(){
	cin>>n>>a>>b;
	for(int i=0;i<n;i++){
		cin>>x>>vx>>vy;
		mp[vy-a*vx]++;
		if(vx==0) k=inf;
		else{
			k=double(vy)/double(vx);
		}
		if(k==a){
			spec[make_pair(vx,vy)]++;
			uk++;
		}
		c[make_pair(vy-a*vx,k)]++;
	}
	for(map<llint,llint>::iterator it=mp.begin();it!=mp.end();it++){
		llint t=(*it).second;
		sol+=t*(t-1);
	}
	for(map<pair<llint,double>,llint>::iterator it=c.begin();it!=c.end();it++){
		llint t=(*it).second;
		sol-=t*(t-1);
	}
	for(map<pair<llint,llint>,llint>::iterator it=spec.begin();it!=spec.end();it++){
		llint t=(*it).second;
		sol+=t*(uk-t);
	}
	cout<<sol<<"\n";
	return 0;
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
#define mp make_pair
#define int int64_t
using namespace std;
const int N = 1e5 + 9;
const int M = 1e9 + 7;
int n, a, b, vx[N], vy[N], ans;
map<pair<int, int> , int> cnt;
map<int, int> f;

int32_t main(){
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	#endif
	fio
	cin >> n >> a >> b;
	for(int i = 1; i <= n; i++){
		cin >> b >> vx[i] >> vy[i];
		cnt[mp(vx[i], vy[i])]++;
		f[vy[i] - a * vx[i]]++;
	}
	for(int i = 1; i <= n; i++)
		ans += f[vy[i] - a * vx[i]] - cnt[mp(vx[i], vy[i])];
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
#define int int64_t
using namespace std;
const int N = 2e5 + 9;
int x[N], vx[N], vy[N], mma, ma, n, a, b, ans, ze;
map<int, int> m;
int32_t main(){
	fio
	cin >> n >> a >> b;
	for(int i = 1; i <= n; i++){
		cin >> x[i] >> vx[i] >> vy[i];
		if(vx[i] == 0 and vy[i] == 0)
			ze++;
		else if(vx[i] and vy[i] % vx[i] == 0 and vy[i] / vx[i] == a){
			if(vy[i] < 0)
				ma++;
			else mma++;
		}
		else
			m[vy[i] - a * vx[i]]++;
	}
	for(auto i : m)
		ans += i.second * (i.second - 1);
	ans += (ma * mma << 1) + ze * (ma + mma);
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
#define int int64_t
using namespace std;
const int N = 2e5 + 9;
int x[N], vx[N], vy[N], mma, ma, n, a, b, ans, ze;
map<int, int> m;
int32_t main(){
	fio
	cin >> n >> a >> b;
	for(int i = 1; i <= n; i++){
		cin >> x[i] >> vx[i] >> vy[i];
		if(vx[i] == 0 and vy[i] == 0)
			ze++;
		else if(vx[i] and vy[i] % vx[i] == 0 and abs(vy[i] / vx[i]) == abs(a)){
			if(vy[i] < 0)
				ma++;
			else mma++;
		}
		else
			m[vy[i] - a * vx[i]]++;
	}
	for(auto i : m)
		ans += i.second * (i.second - 1);
	ans += (ma * mma << 1) + ze * (ma + mma);
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
#define int int64_t
using namespace std;
const int N = 2e5 + 9;
int x[N], vx[N], vy[N], mma, ma, n, a, b, ans, ze;
map<int, int> m;
int32_t main(){
	fio
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	#endif
	cin >> n >> a >> b;
	for(int i = 1; i <= n; i++){
		cin >> x[i] >> vx[i] >> vy[i];
		if(vx[i] == 0 and vy[i] == 0)
			ze++;
		else if(vx[i] and vy[i] % vx[i] == 0 and vy[i] / vx[i] == a){
			if(vy[i] < 0)
				ma++;
			else mma++;
		}
		else
			m[vy[i] - a * vx[i]]++;
	}
	for(auto i : m)
		ans += i.second * (i.second - 1);
	ans += (ma * mma << 1) + (ze * (ma + mma) << 1);
	map<int, int> ver, hor, oth;
	map<pair<int, int> , int> cnt;
	for(int i = 1; i <= n; i++){
		if(vx[i] == vy[i] and vx[i] == 0)
			continue;
		if(vx[i] and vy[i] / vx[i] == a)
			continue;
		cnt[make_pair(vx[i], vy[i])]++;
	}
	for(auto i : cnt)
		ans -= i.second * (i.second - 1);
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
#define int int64_t
using namespace std;
typedef pair<int, int> pii;
#define mp make_pair
const int N = 2e5 + 9;
#define f(x, y) (y - a * x)
int x[N], vx[N], vy[N], zero, d1, d2, a, b, n;
uint64_t ans;
map<pair<int, pii>, int> m;
map<int, int> s;
int32_t main(){
	fio
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	#endif
	cin >> n >> a >> b;
	if(n == 1){
		cout << 0 << '\n';
		return 0;
	}
	for(int i = 1; i <= n; i++)
		cin >> x[i] >> vx[i] >> vy[i];
	for(int i = 1; i <= n; i++){
		if(vx[i] == 0 and vy[i] == 0)
			zero++;
		if(vx[i] and vy[i] / vx[i] == a)
			if(vy[i] < 0)
				d1++;
			else
				d2++;
	}
	ans = d1 * d2 + zero * (d1 + d2) << 1;
	for(int i = 1; i <= n; i++)
		if(vy[i] - vx[i] * a != 0)
			m[mp(f(vx[i], vy[i]), mp(vx[i], vy[i]))]++, s[f(vx[i], vy[i])]++;
	for(auto &i : s)
		i.second = i.second * i.second;
	for(auto &i : m)
		s[i.first.first] -= i.second * i.second;
	for(auto &i : s)
		ans += i.second;
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
#define mp make_pair
#define int int64_t
using namespace std;
const int N = 2e5 + 9;
const int M = 1e9 + 7;
int n, a, b, vx[N], vy[N], ans;
map<pair<int, int> , int> cnt;
map<int, int> f;

int32_t main(){
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	#endif
	fio
	cin >> n >> a >> b;
	for(int i = 1; i <= n; i++){
		cin >> b >> vx[i] >> vy[i];
		cnt[mp(vx[i], vy[i])]++;
		f[vy[i] - a * vx[i]]++;
	}
	for(int i = 1; i <= n; i++)
		ans += f[vy[i] - a * vx[i]] - cnt[mp(vx[i], vy[i])];
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
#define int int64_t
using namespace std;
typedef pair<int, int> pii;
#define mp make_pair
const int N = 2e5 + 9;
#define f(x, y) (y - a * x)
int x[N], vx[N], vy[N], zero, d1, d2, a, b, n, ans;
map<pair<int, pii>, int> m;
map<int, int> s;
int32_t main(){
	fio
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	#endif
	cin >> n >> a >> b;
	for(int i = 1; i <= n; i++)
		cin >> x[i] >> vx[i] >> vy[i];
	for(int i = 1; i <= n; i++){
		if(vx[i] == 0 and vy[i] == 0)
			zero++;
		if(vx[i] and vy[i] / vx[i] == a)
			if(vy[i] < 0)
				d1++;
			else
				d2++;
	}
	ans = d1 * d2 + zero * (d1 + d2) << 1;
	for(int i = 1; i <= n; i++)
		if(vy[i] - vx[i] * a != 0)
			m[mp(f(vx[i], vy[i]), mp(vx[i], vy[i]))]++, s[f(vx[i], vy[i])]++;
	for(auto &i : s)
		i.second = i.second * i.second;
	for(auto &i : m)
		s[i.first.first] -= i.second * i.second;
	for(auto &i : s)
		ans += i.second;
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
#define mp make_pair
#define int int64_t
using namespace std;
const int N = 2e5 + 9;
int n, a, b, vx[N], vy[N], ans;
map<pair<int, int> , int> cnt;
map<int, int> f;

int32_t main(){
	cin >> n >> a >> b;
	for(int i = 1; i <= n; i++){
		cin >> b >> vx[i] >> vy[i];
		cnt[mp(vx[i], vy[i])]++;
		f[vy[i] - a * vx[i]]++;
	}
	for(int i = 1; i <= n; i++)
		ans += f[vy[i] - a * vx[i]] - cnt[mp(vx[i], vy[i])];
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
#define int uint64_t
using namespace std;
typedef pair<int, int> pii;
#define mp make_pair
const int N = 2e5 + 9;
#define f(x, y) (y - a * x)
int x[N], vx[N], vy[N], zero, d1, d2, a, b, n, ans;
map<pair<int, pii>, int> m;
map<int, int> s;
int32_t main(){
	fio
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	#endif
	cin >> n >> a >> b;
	if(n == 1){
		cout << 0 << '\n';
		return 0;
	}
	for(int i = 1; i <= n; i++)
		cin >> x[i] >> vx[i] >> vy[i];
	for(int i = 1; i <= n; i++){
		if(vx[i] == 0 and vy[i] == 0)
			zero++;
		if(vx[i] and vy[i] / vx[i] == a)
			if(vy[i] < 0)
				d1++;
			else
				d2++;
	}
	ans = d1 * d2 + zero * (d1 + d2) << 1;
	for(int i = 1; i <= n; i++)
		if(vy[i] - vx[i] * a != 0)
			m[mp(f(vx[i], vy[i]), mp(vx[i], vy[i]))]++, s[f(vx[i], vy[i])]++;
	for(auto &i : s)
		i.second = i.second * i.second;
	for(auto &i : m)
		s[i.first.first] -= i.second * i.second;
	for(auto &i : s)
		ans += i.second;
	cout << ans << '\n';
}


#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
pair <long long,long long> p;
map <long long,int> many1;
map <pair<long long,long long>,int> many2;
int n;long long a,b,x,c,d,ans;
int main()
{
    scanf("%d%I64d%I64d",&n,&a,&b);
    for(int i=1;i<=n;i++)
    {
        scanf("%I64d%I64d%I64d",&x,&c,&d);p.first=c,p.second=d;
        ans+=many1[a*c-d];many1[a*c-d]++;
        ans-=many2[p];many2[p]++;
    }
    printf("%I64d\n",ans*2);
}


#include "iostream"
#include "map"
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
map<ll,int> mp;
map<P,int> flag;
int main()
{
    mp.clear();
    flag.clear();
    ios::sync_with_stdio(false);
    int x,Vx,Vy;
    ll n,a,b,k,ans=0,t=0;
    P p;
    cin>>n>>a>>b;
    for(int i=0;i<n;i++){
        cin>>x>>Vx>>Vy;
        p.first=Vx,p.second=Vy;
        k=a*Vx-Vy;
        ans+=mp[k]++;
        t+=flag[p]++;
    }
    cout<<2*(ans-t)<<endl;
    return 0;
}


#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
pair <long long,long long> p;
map <long long,int> many1;
map <pair<long long,long long>,int> many2;
int n;long long a,b,x,c,d,ans;
int main()
{
	scanf("%d%I64d%I64d",&n,&a,&b);
	for(int i=1;i<=n;i++)
	{
		scanf("%I64d%I64d%I64d",&x,&c,&d);p.first=c,p.second=d;
		ans+=many1[a*c-d];many1[a*c-d]++;
		ans-=many2[p];many2[p]++;
	}
	printf("%lld\n",ans*2);
}


#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
pair <long long,long long> p;
map <long long,int> many1;
map <pair<long long,long long>,int> many2;
int n;long long a,b,x,c,d,ans;
int main()
{
	scanf("%d%I64d%I64d",&n,&a,&b);
	for(int i=1;i<=n;i++)
	{
		scanf("%I64d%I64d%I64d",&x,&c,&d);p.first=c,p.second=d;
		ans+=many1[a*c-d];many1[a*c-d]++;
		ans-=many2[p];many2[p]++;
	}
	printf("%I64d\n",ans*2);
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	ll n,a,b;
	cin>>n>>a>>b;
	ll i,j,ans=0;
	vector <ll> v;
	map <pll,ll> mq;
	vector <pair <ll,pll> > t;
	for(i=0;i<n;i++)
	{
		ll x,vx,vy;
		cin>>x>>vx>>vy;
		ll gcd=__gcd(vx,vy);
		if(gcd==0)
			gcd=1;
		if(vx<0)
			vx=-vx/gcd;
		else
			vx/=gcd;
		if(vy<0)
			vy=-vy/gcd;
		else
			vy/=gcd;
		if(mq.find(mp(vx,vy))==mq.end())
		{
			v.pb(vy-a*vx);
			t.pb(mp((vy-a*vx),mp(vx,vy)));
		}
		mq[mp(vx,vy)]++;
	}
	sort(v.begin(),v.end());
	sort(t.begin(),t.end());

	for(i=0;i<v.size();i++)
	{
		ll prod=1;
		for(j=i;j<v.size();j++)
		{
			if(v[j]!=v[i])
				break;
			prod*=mq[t[j].ss];
		}
		ll k=j-i;
		ans+=(k*(k-1))*prod;
		i=j-1;
	}
	cout<<ans<<nl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"
ll s(ll d)
{
	ll sum=(d*(d-1));
	return sum;
}
int main()
{
	ios_base::sync_with_stdio(false);
	ll n,a,b;
	cin>>n>>a>>b;
	ll i,ans=0;
	map <ll,ll> add;
	map <pll,ll> sub;
	for(i=0;i<n;i++)
	{
		ll x,vx,vy;
		cin>>x>>vx>>vy;
		sub[mp(vx,vy)]++;
		add[vy-a*vx]++;
	}
	for(auto it: add)
		ans+=s(it.second);
	for(auto it:sub)
		ans-=s(it.second);
	cout<<ans<<nl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	ll n,a,b;
	cin>>n>>a>>b;
	ll i,j,ans=0;
	vector <ll> v;
	map <pll,ll> mq;
	vector <pair <ll,pll> > t;
	for(i=0;i<n;i++)
	{
		ll x,vx,vy;
		cin>>x>>vx>>vy;
		if(mq.find(mp(vx,vy))==mq.end())
		{
			v.pb(vy-a*vx);
			t.pb(mp((vy-a*vx),mp(vx,vy)));
		}
		mq[mp(vx,vy)]++;
	}
	sort(v.begin(),v.end());
	sort(t.begin(),t.end());
	for(i=0;i<v.size();i++)
	{
		ll prod=1;
		for(j=i;j<v.size();j++)
		{
			if(v[j]!=v[i])
				break;
			prod*=mq[t[j].ss];
		}
		ll k=j-i;
		ans+=(k*(k-1))*prod;
		i=j-1;
	}
	cout<<ans<<nl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"
int main()
{
	// ios_base::sync_with_stdio(false);
	ll n,a,b;
	cin>>n>>a>>b;
	ll i,j,ans=0;
	vector <ll> v;
	map <pll,ll> mq;
	vector <pair <ll,pll> > t;
	for(i=0;i<n;i++)
	{
		ll x,vx,vy;
		cin>>x>>vx>>vy;
		ll gcdi=__gcd(abs(vx),abs(vy));
		if(!gcdi && gcdi!=0)
		{
			vx/=gcdi;
			vy/=gcdi;
		}
		if(mq.find(mp(vx,vy))==mq.end())
		{
			v.pb(vy-a*vx);
			t.pb(mp((vy-a*vx),mp(vx,vy)));
		}
		mq[mp(vx,vy)]++;
	}
	sort(v.begin(),v.end());
	sort(t.begin(),t.end());

	for(i=0;i<v.size();i++)
	{
		ll prod=1;
		for(j=i;j<v.size();j++)
		{
			if(v[j]!=v[i])
				break;
			prod*=mq[t[j].ss];
		}
		ll k=j-i;
		ans+=(k*(k-1))*prod;
		i=j-1;
	}
	cout<<ans<<nl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	ll n,a,b;
	cin>>n>>a>>b;
	ll i,j,ans=0;
	vector <ll> v;
	map <pll,ll> mq;
	vector <pair <ll,pll> > t;
	for(i=0;i<n;i++)
	{
		ll x,vx,vy;
		cin>>x>>vx>>vy;
		if(mq.find(mp(vx,vy))==mq.end())
		{
			v.pb(vy-a*vx);
			t.pb(mp((vy-a*vx),mp(vx,vy)));
		}
		mq[mp(vx,vy)]++;
	}
	sort(v.begin(),v.end());
	sort(t.begin(),t.end());
	for(i=0;i<v.size();i++)
	{
		ll prod=1;
		for(j=i;j<v.size();j++)
		{
			if(v[j]!=v[i])
				break;
			prod*=mq[t[i].ss];
		}
		ll k=j-i;
		ans+=(k*(k-1))*prod;
		i=j-1;
	}
	cout<<ans<<nl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"

int main()
{
	ios_base::sync_with_stdio(false);
	ll n,a,b;
	cin>>n>>a>>b;
	ll i,j,ans=0;
	vector <ll> v;
	map <pll,ll> mq;
	vector <pair <ll,pll> > t;
	for(i=0;i<n;i++)
	{
		ll x,vx,vy;
		cin>>x>>vx>>vy;
		ll gcd=__gcd(abs(vx),abs(vy));
		if(gcd!=0)
		{
			vx/=gcd;
			vy/=gcd;
		}
		if(mq.find(mp(vx,vy))==mq.end())
		{
			v.pb(vy-a*vx);
			t.pb(mp((vy-a*vx),mp(vx,vy)));
		}
		mq[mp(vx,vy)]++;
	}
	sort(v.begin(),v.end());
	sort(t.begin(),t.end());

	for(i=0;i<v.size();i++)
	{
		ll prod=1;
		for(j=i;j<v.size();j++)
		{
			if(v[j]!=v[i])
				break;
			prod*=mq[t[j].ss];
		}
		ll k=j-i;
		ans+=(k*(k-1))*prod;
		i=j-1;
	}
	cout<<ans<<nl;
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#define LL long long
const int maxn=2e5+5;
struct G{
	int xi,vx,vy;
	int val;
	bool operator <(const G&p)const{
		return vx<p.vx;
	}
}g[maxn];
int bit[maxn];
std::vector<G>fz[maxn];
std::map<LL,int>mapp;
int v[maxn];
int vtot=0;
int a,b,n;
/*int findlc(int x){
	return std::lower_bound(v+1,v+vtot+1,x)-v;
}
int lowbit(int x){
	return x&(-x);
}
void add(int pos){
	for(int i=pos;i<=vtot;i+=lowbit(i))bit[i]++;
}
int query(int pos){
	int tans=0;
	for(int i=pos;i;i-=lowbit(i))tans+=bit[i];
	return tans;
}*/
LL findans(int id){
	std::sort(fz[id].begin(),fz[id].end());
	int len=fz[id].size();
//	printf("%d\n",len);
	int sum=0;
	LL tans=0ll;
	for(int i=1,cnt=1;i<len;i++,cnt++){
		if(fz[id][i].vx!=fz[id][i-1].vx){
		//	printf("%d\n",cnt);
			sum+=cnt,cnt=0;
		}
		tans+=(LL)sum;
	//	printf("%d %d %d\n",fz[id][i].vx,fz[id][i-1].vx,cnt);
	}
	/*
	vtot=0;
	for(int i=0;i<len;i++)v[++vtot]=fz[id][i].vx;
	std::sort(v+1,v+vtot+1);
	vtot=std::unique(v+1,v+vtot+1)-v-1;
	for(int i=0;i<=vtot;i++)bit[i]=0;
	LL tans=0ll;
	for(int i=len-1;i>=0;i--){
		int lc=findlc(fz[id][i].vx);
		add(lc);
		if(i!=len-1)tans+=(LL)query(lc-1);
	} */
	return tans*2ll;
}
int idtot=0;
int main()
{
//	freopen("in.txt","r",stdin);
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++){
		scanf("%d%d%d",&g[i].xi,&g[i].vx,&g[i].vy);
	//	g[i].val=g[i].vx+g[i].vy;
	//	v[++vtot]=g[i].val;
		LL tpv=(LL)g[i].vy-(LL)a*g[i].vx;
		if(!mapp[tpv])mapp[tpv]=++idtot;
		fz[mapp[tpv]].push_back(g[i]);
	}
	LL ans=0ll;
	for(int i=1;i<=idtot;i++)ans+=findans(i);
	printf("%I64d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long
struct hash_name{
	size_t operator()(const pair<LL,LL> & p) const{
		return p.first^p.second;//hash<string>()(p.name) ^ hash<int>()(p.age);
	}
};
unordered_map<LL,int>sum;
unordered_map<pair<LL,LL>,int,hash_name>tot;
LL n,a,b,ans=0;
int main(){
    scanf("%lld%lld%lld",&n,&a,&b);
	for(int i=1;i<=n;i++){
		LL tp,tp1,tp2;
		scanf("%lld%lld%lld",&tp,&tp1,&tp2);
		ans+=sum[a*tp1-tp2]-tot[make_pair(a*tp1-tp2,tp1)];
		sum[a*tp1-tp2]++;
		tot[make_pair(a*tp1-tp2,tp1)]++;
	}
	printf("%lld\n",ans*2ll);
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long
map<LL,int>sum;
map<pair<LL,LL>,int>tot;
LL n,a,b,ans=0;
int main(){
    scanf("%lld%lld%lld",&n,&a,&b);
	for(int i=1;i<=n;i++){
		LL tp,tp1,tp2;
		scanf("%lld%lld%lld",&tp,&tp1,&tp2);
		ans+=sum[a*tp1-tp2]-tot[make_pair(a*tp1-tp2,tp1)];
		sum[a*tp1-tp2]++;
		tot[make_pair(a*tp1-tp2,tp1)]++;
	}
	printf("%lld\n",ans*2ll);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>

#define LL long long

using namespace std;
const int maxn=2*123456;
struct he{
    LL x,y,vx,vy;
    LL val;
}edge[maxn];
int n,m;
vector<LL> V;
LL k;
LL ai[maxn];
LL a,b;
map<LL,int> M;
bool cmp(he a,he b){
    ///if(a.val!=b.val)return a.val<b.val;
    if(a.vx!=b.vx)return a.vx<b.vx;
    return a.vy>b.vy;
}
int main(){
   // cout<<LONG_LONG_MAX<<endl;
    while(scanf("%d",&n)!=EOF){
        scanf("%lld%lld",&a,&b);
        for(int i=1;i<=n;i++){
        scanf("%lld%lld%lld",&edge[i].x,&edge[i].vx,&edge[i].vy);
            edge[i].val=a*edge[i].vx-edge[i].vy;
        }
        sort(edge+1,edge+1+n,cmp);
        M.clear();
        LL ans=0;
        int be=0;
        edge[0].vx=9223372036854775807LL;
        for(int i=1;i<=n;i++){

            LL t=a*edge[i].vx-edge[i].vy;
            if(edge[i].vx==edge[i-1].vx&&edge[i].vy==edge[i-1].vy){
                be++;
            }else{
                be=1;
            }

            int aa=M[t];

            aa-=(be-1);
            ans+=aa*2;
            M[t]++;
        }
        cout<<ans<<endl;
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>

#define LL long long

using namespace std;
const int maxn=2*123456;
struct he{
    LL x,y,vx,vy;
}edge[maxn];
int n,m;
vector<LL> V;
LL k;
LL ai[maxn];
LL a,b;
int main(){
    while(scanf("%d",&n)!=EOF){
        scanf("%lld%lld",&a,&b);
        for(int i=1;i<=n;i++){
        scanf("%lld%lld%lld",&edge[i].x,&edge[i].vx,&edge[i].vy);
            edge[i].y=a*edge[i].x+b;
        }
        LL ans=0;
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                LL x1=edge[i].x;
                LL x2=edge[j].x;
                LL y1=edge[i].y;
                LL y2=edge[j].y;
                LL vx1=edge[i].vx;
                LL vx2=edge[j].vx;
                LL vy1=edge[i].vy;
                LL vy2=edge[j].vy;
                if((x1-x2)*(vy1-vy2)==(y1-y2)*(vx1-vx2)&&(vx1!=vx2)&&(vy1!=vy2))ans+=2;

            }
        }
        cout<<ans<<endl;
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>

#define LL long long

using namespace std;
const int maxn=2*123456;
struct he{
    LL x,y,vx,vy;
    LL val;
}edge[maxn];
int n,m;
vector<LL> V;
LL k;
LL ai[maxn];
LL a,b;
map<LL,int> M;
bool cmp(he a,he b){
    if(a.val!=b.val)return a.val<b.val;
    if(a.x!=b.x)return a.vx<b.vx;
    return a.vy>b.vy;
}
int main(){
   // cout<<LONG_LONG_MAX<<endl;
    while(scanf("%d",&n)!=EOF){
        scanf("%lld%lld",&a,&b);
        for(int i=1;i<=n;i++){
        scanf("%lld%lld%lld",&edge[i].x,&edge[i].vx,&edge[i].vy);
            edge[i].val=a*edge[i].vx-edge[i].vy;
        }
        sort(edge+1,edge+1+n,cmp);
        M.clear();
        LL ans=0;
        int be=0;
        edge[0].vx=9223372036854775807LL;
        for(int i=1;i<=n;i++){

            LL t=a*edge[i].vx-edge[i].vy;
            if(edge[i].vx==edge[i-1].vx&&edge[i].vy==edge[i-1].vy){
                be++;
            }else{
                be=1;
            }

            int aa=M[t];

            aa-=(be-1);
            ans+=aa*2;
            M[t]++;
        }
        cout<<ans<<endl;
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>

#define LL long long

using namespace std;
const int maxn=2*123456;
struct he{
    LL x,y,vx,vy;
}edge[maxn];
int n,m;
vector<LL> V;
LL k;
LL ai[maxn];
LL a,b;
map<LL,int> M;
bool cmp(he a,he b){
    if(a.x!=b.x)return a.vx<b.vx;
    return a.vy>b.vy;
}
int main(){

    while(scanf("%d",&n)!=EOF){
        scanf("%lld%lld",&a,&b);
        for(int i=1;i<=n;i++){
        scanf("%lld%lld%lld",&edge[i].x,&edge[i].vx,&edge[i].vy);

        }
        sort(edge+1,edge+1+n,cmp);
        M.clear();
        LL ans=0;
        int be=0;
        edge[0].vx=1e9+10;
        for(int i=1;i<=n;i++){

            LL t=a*edge[i].vx-edge[i].vy;
            if(edge[i].vx==edge[i-1].vx&&edge[i].vy==edge[i-1].vy){
                be++;
            }else{
                be=1;
            }

            int aa=M[t];

            aa-=(be-1);
            ans+=aa*2;
            M[t]++;
        }
        cout<<ans<<endl;
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>

#define LL long long

using namespace std;
const int maxn=2*123456;
struct he{
    LL x,y,vx,vy;
    LL val;
}edge[maxn];
int n,m;
vector<LL> V;
LL k;
LL ai[maxn];
LL a,b;
map<LL,int> M;
bool cmp(he a,he b){
    if(a.x!=b.x)return a.vx<b.vx;
    return a.vy>b.vy;
}
int main(){
   // cout<<LONG_LONG_MAX<<endl;
    while(scanf("%d",&n)!=EOF){
        scanf("%lld%lld",&a,&b);
        for(int i=1;i<=n;i++){
        scanf("%lld%lld%lld",&edge[i].x,&edge[i].vx,&edge[i].vy);

        }
        sort(edge+1,edge+1+n,cmp);
        M.clear();
        LL ans=0;
        int be=0;
        edge[0].vx=9223372036854775807LL;
        for(int i=1;i<=n;i++){

            LL t=a*edge[i].vx-edge[i].vy;
            if(edge[i].vx==edge[i-1].vx&&edge[i].vy==edge[i-1].vy){
                be++;
            }else{
                be=1;
            }

            int aa=M[t];

            aa-=(be-1);
            ans+=aa*2;
            M[t]++;
        }
        cout<<ans<<endl;
    }

    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn = 202020;

long long n , a , b;
long long x[maxn] , vx[maxn] , vy[maxn];
struct node{
   long long x,y,b;
   bool operator<(const node& A){
         if(x < A.x) return true;
         return y < A.y;
   }
}st1[maxn];
struct node2{
   long long b , time;
   bool operator<(const node2& A){
         return b < A.b;
   }
}st2[maxn];
int main()
{
  cin>>n>>a>>b;
  for(int i=1;i<=n;i++){
      cin>>x[i]>>vx[i]>>vy[i];
      st1[i].x = vx[i];
      st1[i].y = vy[i];
      st1[i].b = vy[i] - vx[i]*a;
  }
  sort(st1+1,st1+1+n);
  int count_=0 , cnt =0;
  for(int i=1;i<=n;i++){
      ++count_;
      if(i==n||(st1[i].x!=st1[i + 1].x && st1[i].y!=st1[i + 1].y)){
           st2[++cnt].b = st1[i].b;
           st2[cnt].time = count_;
           count_ =0;
      }
  }
  sort(st2 + 1 , st2+1+n);
  count_=0;
  long long cheng = 1 , ans=0;
  for(int i=1;i<=cnt;i++){
     cheng*= st2[i].time;
     ++count_;
     if(i == cnt || st2[i].b != st2[i+1].b){
          ans += cheng*(count_ - 1) * count_ / 2;
     }
  }
  cout<<ans*2<<endl;
  return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn = 202020;
double a ,b;
int n;
double x[maxn],y[maxn] , bb[maxn];
struct node{
   double x, y;
   bool operator<(const node& ff){
       if(x<ff.x) return true;
       return y<ff.y;
   }
}c[maxn];
long long cal(long long x){
    return (x) * (x -1)/2;
}
int main()
{
   cin>>n>>a>>b;
   int pos;
   for(int i=1;i<=n;i++){
      cin>>pos>>x[i]>>y[i];
      c[i].x= x[i],c[i].y=y[i];
      //cout<<x[i]<<" "<<y[i]<<" "<<y[i] - a*x[i]<<endl;
      bb[i] = y[i] - a*x[i];
   }
   sort(bb + 1, bb + 1 + n);
   sort(c + 1 , c+1 + n);
   long long all=0 , cou = 0;
   for(int i=1;i<=n;i++){
        ++cou;
        if(i == n || bb[i] != bb[i+1]){
             all += cal(cou);
             cou = 0;
        }
   }
   cou = 0;
   for(int i=1;i<=n;i++){
        ++cou;
       if(i == n || c[i].x!=c[i+1].x || c[i].y!=c[i + 1].y){
             all -= cal(cou);
             cou = 0;
       }
   }
   cout<<all*2<<endl;
   return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn = 202020;

long long n , a , b;
long long x[maxn] , vx[maxn] , vy[maxn];
struct node{
   long long x,y,b;
   bool operator<(const node& A){
         if(x < A.x) return true;
         return y < A.y;
   }
}st1[maxn];
struct node2{
   long long b , time;
   bool operator<(const node2& A){
         return b < A.b;
   }
}st2[maxn];
int main()
{
  //cout<<(long long)1000000000000000000<<endl;
  cin>>n>>a>>b;
  for(int i=1;i<=n;i++){
      cin>>x[i]>>vx[i]>>vy[i];
      st1[i].x = vx[i];
      st1[i].y = vy[i];
      st1[i].b = vy[i] - vx[i]*a;
  }
  sort(st1+1,st1+1+n);
  long long count_=0 , cnt =0;
  for(int i=1;i<=n;i++){
      ++count_;
      if(i==n||(st1[i].x!=st1[i + 1].x && st1[i].y!=st1[i + 1].y)){
           st2[++cnt].b = st1[i].b;
           st2[cnt].time = count_;
           count_ =0;
          // cout<<st2[cnt].b<<" "<<st2[cnt].time<<endl;
      }
  }
  sort(st2 + 1 , st2+1+cnt);
  count_=0;
  long long cheng = 1 , ans=0;
  for(int i=1;i<=cnt;i++){
     ans -= st2[i].time * (st2[i].time-1) /2;
     count_+= st2[i].time;
     if(i == cnt || st2[i].b != st2[i+1].b){
          ans += (count_ - 1) * count_ / 2;
          count_ =0;
     }
  }
  cout<<ans*2<<endl;
  return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn = 202020;

long long n , a , b;
long long x[maxn] , vx[maxn] , vy[maxn];
struct node{
   long long x,y,b;
   bool operator<(const node& A){
         if(x < A.x) return true;
         return y < A.y;
   }
}st1[maxn];
struct node2{
   long long b , time;
   bool operator<(const node2& A){
         return b < A.b;
   }
}st2[maxn];
int main()
{
  cin>>n>>a>>b;
  for(int i=1;i<=n;i++){
      cin>>x[i]>>vx[i]>>vy[i];
      st1[i].x = vx[i];
      st1[i].y = vy[i];
      st1[i].b = vy[i] - vx[i]*a;
  }
  sort(st1+1,st1+1+n);
  int count_=0 , cnt =0;
  for(int i=1;i<=n;i++){
      ++count_;
      if(i==n||(st1[i].x!=st1[i + 1].x && st1[i].y!=st1[i + 1].y)){
           st2[++cnt].b = st1[i].b;
           st2[cnt].time = count_;
           count_ =0;
          // cout<<st2[cnt].b<<" "<<st2[cnt].time<<endl;
      }
  }
  sort(st2 + 1 , st2+1+cnt);
  count_=0;
  long long cheng = 1 , ans=0;
  for(int i=1;i<=cnt;i++){
     cheng*= st2[i].time;
     ++count_;
     if(i == cnt || st2[i].b != st2[i+1].b){
          ans += cheng*(count_ - 1) * count_ / 2;
          cheng = 1;
          count_ =0;
     }
  }
  cout<<ans*2<<endl;
  return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn = 202020;
double a ,b;
int n;
long long x[maxn],y[maxn] , bb[maxn],cc[maxn];
struct node{
   long long x, y;
   bool operator<(const node& ff){
       if(x<ff.x) return true;
       return y<ff.y;
   }
}c[maxn] ,d[maxn];
long long cal(long long x){
    return (x) * (x -1)/2;
}
int main()
{
   cin>>n>>a>>b;
   int pos;
   for(int i=1;i<=n;i++){
      cin>>pos>>x[i]>>y[i];
      c[i].x= x[i],c[i].y=y[i];
      //cout<<x[i]<<" "<<y[i]<<" "<<y[i] - a*x[i]<<endl;

   }
   sort(c + 1 , c + 1 + n);
   long long all=0 , cou = 0;
   cou = 0;
   int cnt = 0;
   for(int i=1;i<=n;i++){
        ++cou;
       if(i == n || c[i].x!=c[i+1].x || c[i].y!=c[i + 1].y){
              d[++cnt].x = c[i].y - a*c[i].x;
              d[cnt].y = cou;
            //  cout<<d[cnt].x<<" "<<d[cnt].y<<endl;
              cou =0;
       }
   }
   cou = 1;
   sort(d+1 , d+1+cnt);
   long long num =0 ;
   for(int i=1;i<=cnt;i++){
      // cout<<d[i].x<<" "<<d[i].y<<endl;
       cou*=d[i].y; ++num;
       if(i == cnt || d[i].x != d[i + 1].x){
           all+=cou*cal(num);
           cou=1;
   num = 0;
       }
   }
   cout<<all*2<<endl;
   return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;
const int maxn = 202020;
template<class T>void gi(T &x){
    int f;char c;
    for(f=1,c=getchar();c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
    for(x=0;c<='9'&&c>='0';c=getchar())x=x*10+(c&15);x*=f;
}

map<long long , int> bb;
map<pair<int,int> ,int> cou;
long long n, a, b;
int main()
{
    cin>>n>>a>>b;
    long long ans = 0;
    for(int i=1;i<=n;i++){
         int x , vx, vy;
         gi(x) , gi(vx) , gi(vy);
         long long nb = vy - a * vx;
         ans += (bb[nb] - cou[make_pair(vx , vy)]);
         bb[nb]++; cou[make_pair(vx , vy)]++;
    }
    cout<<ans*2<<endl;
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#define maxn 200010
using namespace std;
int n,a,b;
struct Point
{
	int vx,vy;
	bool flag;
	Point(int a=0,int b=0):vx(a),vy(b) {flag =( vx == 0 ? vy<0 : vx<0);}
	bool operator == (const Point &a) const{
		return flag == a.flag && vx*a.vy == a.vx*vy;
	}
	bool operator < (const Point &a) const{
		return a==*this ? 0 : vx<a.vx;
	}
};
map<long long,int> m;
map<Point,int>m2;
long long cnt[maxn];
long long par[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>a>>b;
	memset(cnt,0,sizeof(cnt));
	memset(par,0,sizeof(par));
	int index = 0,index2 = 0,idx,idx2;
	long long ans = 0;
	int r,vx,vy;
	long long tmp;
	map<long long,int>::iterator itr;
	map<Point,int>::iterator itr2;
	for(int i=0;i<n;i++)
	{
		cin>>r>>vx>>vy;
		tmp = vy - a*vx;
		if((itr = m.find(tmp))==m.end())
		{
			index++;
			cnt[index]++;
			m.insert(map<long long,int>::value_type(tmp,index));
			index2++;
			par[index2]++;
			m2.insert(map<Point,int>::value_type(Point(vx,vy),index2));
		}
		else {
			idx =itr -> second;
			if((itr2=m2.find(Point(vx,vy)))==m2.end())
			{
				index2++;
				par[index2]++;
				m2.insert(map<Point,int>::value_type(Point(vx,vy),index2));
				idx2=0;
			}
			else {
				idx2 = itr2 -> second;
			}
			ans += 2*(cnt[idx] - par[idx2]);
			if(idx2)
				par[idx2]++;
			cnt[idx]++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<cstdlib>
#define maxn 200010
using namespace std;
int n,a,b;
struct Point{
	int vx,vy;
	Point(int a=0,int b=0):vx(a),vy(b){}
	bool operator == (const Point &a) const
	{
		return vx==a.vx && vy == a.vy;
	}
	bool operator < (const Point &a) const
	{
		return a.vx == vx ? a.vy>vy : a.vx > vx;
	}
};
map<long long,int> m;
map<Point,int> m2;
long long cnt[maxn],cnt2[maxn];
long long par[3];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>a>>b;
	memset(cnt,0,sizeof(cnt));
	memset(cnt2,0,sizeof(cnt2));
	memset(par,0,sizeof(par));
	int index = 0,idx,index2=0,idx2;
	long long ans = 0;
	int r,vx,vy;
	long long tmp;
	map<long long,int>::iterator itr;
	map<Point,int>::iterator itr2;
	for(int i=0;i<n;i++)
	{
		cin>>r>>vx>>vy;
		tmp = vy - (long long)a*vx;
		if(tmp==0)
		{
			if(vx == 0)
			{
				ans+=2*(par[1]+par[2]);
				par[0]++;
			}
			if(vx > 0)
			{
				ans+=2*(par[2]+par[0]);
				par[1]++;
			}
			if(vx < 0)
			{
				ans+=2*(par[1]+par[0]);
				par[2]++;
			}
		}
		else {
			if((itr = m.find(tmp))==m.end())
			{
				index++;
				cnt[index]++;
				m.insert(map<long long,int>::value_type(tmp,index));
				index2++;
				cnt2[index2]++;
				m2.insert(map<Point,int>::value_type(Point(vx,vy),index2));
			}
			else {
				if((itr2=m2.find(Point(vx,vy)))==m2.end())
				{
					index2++;
					cnt2[index2]++;
					m2.insert(map<Point,int>::value_type(Point(vx,vy),index2));
					idx2  = 0;
				}
				else{
					idx2 = itr2 -> second;
				}
				idx =itr -> second;
				ans += 2*(cnt[idx] - cnt2[idx2]) ;
				if(idx2)
					cnt2[idx2]++;
				cnt[idx]++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<cstdlib>
#define maxn 200010
using namespace std;
int n,a,b;
int getgcd(int a,int b)
{
	a=abs(a);
	b=abs(b);
	if(a>b)
		std::swap(a,b);
	if(a==0)
		return 1;
	while(b%a)
	{
		b = b%a;
		std::swap(a,b);
	}
	return a;
}
struct Point
{
	int vx,vy;
	bool flag;
	Point(int a=0,int b=0):vx(a),vy(b) {flag =( vx == 0 ? vy<0 : vx<0);}
	bool operator == (const Point &a) const{
		return flag == a.flag && vx*a.vy == a.vx*vy;
	}
	bool operator < (const Point &a) const{
		int temp1 = getgcd(vx,vy),temp2=a.vx/getgcd(a.vx,a.vy);
		return a==*this ? 0 : (vx/temp1 == a.vx/temp2 ? vy/temp1 < a.vy/temp2:vx/temp1 < a.vx/temp2 );
	}
};
map<long long,int> m;
map<Point,int>m2;
long long cnt[maxn];
long long par[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>a>>b;
	memset(cnt,0,sizeof(cnt));
	memset(par,0,sizeof(par));
	int index = 0,index2 = 0,idx,idx2;
	long long ans = 0;
	int r,vx,vy;
	long long tmp;
	map<long long,int>::iterator itr;
	map<Point,int>::iterator itr2;
	for(int i=0;i<n;i++)
	{
		cin>>r>>vx>>vy;
		tmp = vy - a*vx;
		if((itr = m.find(tmp))==m.end())
		{
			index++;
			cnt[index]++;
			m.insert(map<long long,int>::value_type(tmp,index));
			index2++;
			par[index2]++;
			m2.insert(map<Point,int>::value_type(Point(vx,vy),index2));
		}
		else {
			idx =itr -> second;
			if((itr2=m2.find(Point(vx,vy)))==m2.end())
			{
				index2++;
				par[index2]++;
				m2.insert(map<Point,int>::value_type(Point(vx,vy),index2));
				idx2=0;
			}
			else {
				idx2 = itr2 -> second;
			}
			ans += 2*(cnt[idx] - par[idx2]);
			if(idx2)
				par[idx2]++;
			cnt[idx]++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<cstdlib>
#define maxn 200010
using namespace std;
int n,a,b;
int getgcd(int a,int b)
{
	a=abs(a);
	b=abs(b);
	if(a>b)
		std::swap(a,b);
	if(a==0)
		return 1;
	while(b%a)
	{
		b = b%a;
		std::swap(a,b);
	}
	return a;
}
struct Point
{
	int vx,vy;
	bool flag;
	Point(int a=0,int b=0):vx(a),vy(b) {flag =( vx == 0 ? vy<0 : vx<0);}
	bool operator == (const Point &a) const{
		return flag == a.flag && vx*a.vy == a.vx*vy;
	}
	bool operator < (const Point &a) const{
		int temp1 = getgcd(vx,vy),temp2=getgcd(a.vx,a.vy);
		return a==*this ? 0 : (vx/temp1 == a.vx/temp2 ? vy/temp1 < a.vy/temp2 : vx/temp1 < a.vx/temp2 );
	}
};
map<long long,int> m;
map<Point,int>m2;
long long cnt[maxn];
long long par[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>a>>b;
	memset(cnt,0,sizeof(cnt));
	memset(par,0,sizeof(par));
	int index = 0,index2 = 0,idx,idx2;
	long long ans = 0;
	int r,vx,vy;
	long long tmp;
	map<long long,int>::iterator itr;
	map<Point,int>::iterator itr2;
	for(int i=0;i<n;i++)
	{
		cin>>r>>vx>>vy;
		tmp = vy - a*vx;
		if((itr = m.find(tmp))==m.end())
		{
			index++;
			cnt[index]++;
			m.insert(map<long long,int>::value_type(tmp,index));
			index2++;
			par[index2]++;
			m2.insert(map<Point,int>::value_type(Point(vx,vy),index2));
		}
		else {
			idx =itr -> second;
			if((itr2=m2.find(Point(vx,vy)))==m2.end())
			{
				index2++;
				par[index2]++;
				m2.insert(map<Point,int>::value_type(Point(vx,vy),index2));
				idx2=0;
			}
			else {
				idx2 = itr2 -> second;
			}
			ans += 2*(cnt[idx] - par[idx2]);
			if(idx2)
				par[idx2]++;
			cnt[idx]++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define sz(v) (int)v.size()
#define pb push_back
#define fi first
#define se second
#define ll long long
const int mod=1e9+7;
const int N=1e6+5;

int main(){
    ios::sync_with_stdio(false);
    #ifdef _LOCAL_DEBUG
    freopen("in.txt","r",stdin);
    #endif // _LOCAL_DEBUG
	int n,a,b;
	int x,vx,vy;
	cin>>n>>a>>b;
	map<ll,int>p;
	map<pair<int,int>,int>vis;
	ll ans=0;
	for(int i=0;i<n;++i){
		cin>>x>>vx>>vy;
		ll tmp=1ll*a*vx-vy;
		ans+=p[tmp];
		ans-=vis[{vx,vy}];
		++p[tmp];
		++vis[{vx,vy}];
	}
	cout<<ans*2<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
const int mod=1e9+7;
const int N=1e6+5;

int main(){
    ios::sync_with_stdio(false);
    #ifdef _LOCAL_DEBUG
    freopen("in.txt","r",stdin);
    #endif // _LOCAL_DEBUG

	int n,a,b;
	int x,vx,vy;
	cin>>n>>a>>b;
	map<ll,vector<int>>p;
	vector<pair<int,int>>g;
	for(int i=0;i<n;++i){
		cin>>x>>vx>>vy;
		g.pb(mp(vx,vy));
		ll tmp=1ll*a*vx-vy;
		p[tmp].pb(i);
	}
	ll ans=0;
	map<int,int>px,py;
	map<pair<int,int>,int>pxy;
	for(auto&v:p){
		if(v.second.size()==1) continue;
		int m=v.second.size();
		px.clear();
		py.clear();
		pxy.clear();
		for(auto&u:v.second){
			int vx=g[u].fi;
			int vy=g[u].se;
			++px[vx];
			++py[vy];
			++pxy[mp(vx,vy)];
		}
		for(auto&u:v.second){
			int vx=g[u].fi;
			int vy=g[u].se;
			int n1=px[vx]-1;
			int n2=py[vy]-1;
			int n3=pxy[mp(vx,vy)]-1;
			int num=n1+n2-n3;
			ans+=m-num-1;
		}
	}
	cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
const int mod=1e9+7;
const int N=1e6+5;

int main(){
    ios::sync_with_stdio(false);
    #ifdef _LOCAL_DEBUG
    freopen("in.txt","r",stdin);
    #endif // _LOCAL_DEBUG

	int n,a,b;
	int x,vx,vy;
	cin>>n>>a>>b;
	map<ll,int>p;
	for(int i=0;i<n;++i){
		cin>>x>>vx>>vy;
		if(vx==0&&vy==0) continue;
		ll tmp=1ll*a*vx-vy;
		++p[tmp];
	}
	int ans=0;
	for(auto&v:p){
		if(v.second>1){
			ans+=v.second*2;
		}
	}
	cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define sz(v) (int)v.size()
#define pb push_back
#define fi first
#define se second
#define ll long long
const int mod=1e9+7;
const int N=1e6+5;

int main(){
    ios::sync_with_stdio(false);
    #ifdef _LOCAL_DEBUG
    freopen("in.txt","r",stdin);
    #endif // _LOCAL_DEBUG
	int n,a,b;
	int x,vx,vy;
	cin>>n>>a>>b;
	map<ll,int>p;
	map<pair<int,int>,int>vis;
	ll ans=0;
	for(int i=0;i<n;++i){
		cin>>x>>vx>>vy;
		ll tmp=1ll*a*vx-vy;
		ans+=p[tmp];
		ans-=vis[{vx,vy}];
		++p[tmp];
		++vis[{vx,vy}];
	}
	cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
const int mod=1e9+7;
const int N=1e6+5;

int main(){
    ios::sync_with_stdio(false);
    #ifdef _LOCAL_DEBUG
    freopen("in.txt","r",stdin);
    #endif // _LOCAL_DEBUG

	int n,a,b;
	int x,vx,vy;
	cin>>n>>a>>b;
	map<ll,vector<int>>p;
	vector<pair<int,int>>g;
	for(int i=0;i<n;++i){
		cin>>x>>vx>>vy;
		g.pb(mp(vx,vy));
		ll tmp=1ll*a*vx-vy;
		p[tmp].pb(i);
	}
	int ans=0;
	map<int,int>px,py;
	map<pair<int,int>,int>pxy;
	for(auto&v:p){
		if(v.second.size()==1) continue;
		int m=v.second.size();
		px.clear();
		py.clear();
		pxy.clear();
		for(auto&u:v.second){
			int vx=g[u].fi;
			int vy=g[u].se;
			++px[vx];
			++py[vy];
			++pxy[mp(vx,vy)];
		}
		for(auto&u:v.second){
			int vx=g[u].fi;
			int vy=g[u].se;
			int n1=px[vx]-1;
			int n2=py[vy]-1;
			int n3=pxy[mp(vx,vy)]-1;
			int num=n1+n2-n3;
			ans+=(m-num-1);
		}
	}
	cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
const int mod=1e9+7;
const int N=1e6+5;

int main(){
    ios::sync_with_stdio(false);
    #ifdef _LOCAL_DEBUG
    freopen("in.txt","r",stdin);
    #endif // _LOCAL_DEBUG

	int n,a,b;
	int x,vx,vy;
	cin>>n>>a>>b;
	map<ll,int>p;
	for(int i=0;i<n;++i){
		cin>>x>>vx>>vy;
		ll tmp=1ll*a*vx-vy;
		++p[tmp];
	}
	int ans=0;
	for(auto&v:p){
		if(v.second>1){
			ans+=v.second*2;
		}
	}
	cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
const int mod=1e9+7;
const int N=1e6+5;

int main(){
    ios::sync_with_stdio(false);
    #ifdef _LOCAL_DEBUG
    freopen("in.txt","r",stdin);
    #endif // _LOCAL_DEBUG

	int n,a,b;
	int x,vx,vy;
	cin>>n>>a>>b;
	map<ll,vector<int>>p;
	vector<pair<int,int>>g;
	for(int i=0;i<n;++i){
		cin>>x>>vx>>vy;
		g.pb(mp(vx,vy));
		ll tmp=1ll*a*vx-vy;
		p[tmp].pb(i);
	}
	int ans=0;
	map<int,int>px,py;
	map<pair<int,int>,int>pxy;
	for(auto&v:p){
		if(v.second.size()==1) continue;
		int m=v.second.size();
		px.clear();
		py.clear();
		pxy.clear();
		for(auto&u:v.second){
			int vx=g[u].fi;
			int vy=g[u].se;
			++px[vx];
			++py[vy];
			++pxy[mp(vx,vy)];
		}
		for(auto&u:v.second){
			int vx=g[u].fi;
			int vy=g[u].se;
			int n1=px[vx]-1;
			int n2=py[vy]-1;
			int n3=pxy[mp(vx,vy)]-1;
			int num=n1+n2-n3;
			ans+=max(0,m-num-1);
		}
	}
	cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<set>
#include<map>
#include<cmath>
#include<sstream>
#include<queue>
#include<vector>
#include<deque>
using namespace std;
typedef long long ll;
#define For(a,b,c) for (int (a)=(b);(a)<(c);(a)++)
#define foreach(iter,V) for (__typeof((V).begin()) iter=(V).begin();iter!=(V).end();iter++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
int n,a,b;
struct node{
	int x,vx,vy;
}rec[200001];
ll c[200001];
ll ans;
map<ll,ll> 	m;
map<pair<ll,pair<ll,ll> >,ll> p;
ll gcd(ll x,ll y){
	if (y==0)	return x;
	return gcd(y,x%y);
}
int main(){
	scanf("%d%d%d",&n,&a,&b);
	For(i,1,n+1)	{
		scanf("%d%d%d",&rec[i].x,&rec[i].vx,&rec[i].vy);
		c[i]=a*rec[i].vx-rec[i].vy;
	}
	For(i,1,n+1){
		ans+=m[c[i]];
		m[c[i]]++;
	}
	For(i,1,n+1){
		int g=gcd(rec[i].vx,rec[i].vy);
		if (g<0)	g=-g;
		if (g!=0){
			rec[i].vx/=g;
			rec[i].vy/=g;
		}
		ans-=p[mp(c[i],mp(rec[i].vx,rec[i].vy))];
		p[mp(c[i],mp(rec[i].vx,rec[i].vy))]++;
	}
	cout<<ans*2<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<set>
#include<map>
#include<cmath>
#include<sstream>
#include<queue>
#include<vector>
#include<deque>
using namespace std;
typedef long long ll;
#define For(a,b,c) for (int (a)=(b);(a)<(c);(a)++)
#define foreach(iter,V) for (__typeof((V).begin()) iter=(V).begin();iter!=(V).end();iter++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
int n,a,b;
struct node{
	int x,vx,vy;
}rec[200001];
map<ll,ll> m;
ll c[200001];
ll ans;
int main(){
	scanf("%d%d%d",&n,&a,&b);
	For(i,1,n+1)	{
		scanf("%d%d%d",&rec[i].x,&rec[i].vx,&rec[i].vy);
		c[i]=a*rec[i].vx-rec[i].vy;
	}
	For(i,1,n+1)
	if (rec[i].vx*rec[i].vx+rec[i].vy*rec[i].vy!=0){
		if(!m[c[i]])	m[c[i]]=1;
		else
		if(m[c[i]]==1)	ans+=2,m[c[i]]++;
		else
		if (m[c[i]]>1)	ans++;
	}
	printf("%I64d\n",ans*2);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<set>
#include<map>
#include<cmath>
#include<sstream>
#include<queue>
#include<vector>
#include<deque>
using namespace std;
typedef long long ll;
#define For(a,b,c) for (ll (a)=(b);(a)<(c);(a)++)
#define foreach(iter,V) for (__typeof((V).begin()) iter=(V).begin();iter!=(V).end();iter++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
ll n,a,b;
struct node{
	ll x,vx,vy;
}rec[200001];
ll c[200001];
ll ans;
map<ll,ll> 	m;
map<pair<ll,ll> ,ll> p;
ll gcd(ll x,ll y){
	if (y==0)	return x;
	return gcd(y,x%y);
}
int main(){
	scanf("%I64d%I64d%I64d",&n,&a,&b);
	For(i,1,n+1)	{
		scanf("%I64d%I64d%I64d",&rec[i].x,&rec[i].vx,&rec[i].vy);
		c[i]=a*rec[i].vx-rec[i].vy;
	}
	For(i,1,n+1){
		ans+=m[c[i]];
		m[c[i]]++;
	}
	For(i,1,n+1){
		ans-=p[mp(rec[i].vx,rec[i].vy)];
		p[mp(rec[i].vx,rec[i].vy)]++;
	}
	cout<<ans*2<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<set>
#include<map>
#include<cmath>
#include<sstream>
#include<queue>
#include<vector>
#include<deque>
using namespace std;
typedef long long ll;
#define For(a,b,c) for (int (a)=(b);(a)<(c);(a)++)
#define foreach(iter,V) for (__typeof((V).begin()) iter=(V).begin();iter!=(V).end();iter++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
int n,a,b;
struct node{
	int x,vx,vy;
}rec[200001];
map<ll,ll> m;
ll c[200001];
ll ans;
int main(){
	scanf("%d%d%d",&n,&a,&b);
	For(i,1,n+1)	{
		scanf("%d%d%d",&rec[i].x,&rec[i].vx,&rec[i].vy);
		c[i]=a*rec[i].vx-rec[i].vy;
	}
	For(i,1,n+1)
	if (c[i]!=0){
		if(!m[c[i]])	m[c[i]]=1;
		else
		if(m[c[i]]==1)	ans+=2,m[c[i]]++;
		else
		if (m[c[i]]>1)	ans++;
	}
	printf("%I64d\n",ans*2);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<set>
#include<map>
#include<cmath>
#include<sstream>
#include<queue>
#include<vector>
#include<deque>
using namespace std;
typedef long long ll;
#define For(a,b,c) for (int (a)=(b);(a)<(c);(a)++)
#define foreach(iter,V) for (__typeof((V).begin()) iter=(V).begin();iter!=(V).end();iter++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
int n,a,b;
struct node{
	int x,vx,vy;
}rec[200001];
ll c[200001];
ll ans;
map<ll,ll> 	m;
map<pair<ll,pair<ll,ll> >,ll> p;
ll gcd(ll x,ll y){
	if (y==0)	return x;
	return gcd(y,x%y);
}
int main(){
	scanf("%d%d%d",&n,&a,&b);
	For(i,1,n+1)	{
		scanf("%d%d%d",&rec[i].x,&rec[i].vx,&rec[i].vy);
		c[i]=a*rec[i].vx-rec[i].vy;
	}
	For(i,1,n+1){
		ans+=m[c[i]];
		m[c[i]]++;
	}
	For(i,1,n+1){
		int g=gcd(rec[i].vx,rec[i].vy);
		if (g<0)	g=-g;
		rec[i].vx/=g;
		rec[i].vy/=g;
		ans-=p[mp(c[i],mp(rec[i].vx,rec[i].vy))];
		p[mp(c[i],mp(rec[i].vx,rec[i].vy))]++;
	}
	cout<<ans*2<<endl;
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define gcd __gcd
#define lcm(a, b) (a*b)/gcd(a, b)
#define pcount __builtin_popcount
#define pcountll __builtin_popcountll
#define nxtperm next_permutation
//primitive roots: 998244353 - 3; 7340033 - 5
//#pragma 03
//#pragma GCC target ("sse4.2")
const ll mod = 1000000007;
const double PI = acos(-1.);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef complex<double> cd;

const int maxn = 2e5 + 1000;
int n;
ll a, b;

map<int, int> val;
map<ii, int> paralel;
signed main()
{
//	freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
	cin >> n >> a >> b;
	ll ans = 0;
	for(int i=0;i<n;i++)
	{
		ll x, vx, vy, g;
		cin >> x >> vx >> vy;
		g = gcd(vx, vy);
		ans += val[a*vx - vy] - paralel[{vx,vy}];
		val[a*vx - vy]++;
		paralel[{vx, vy}]++;
	}
	cout << 2*ans;
}