#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 50;
const int mod = 1e9 + 7;
const int inf = 1e9;
map<pair<int, int>, long long> same;
map<long long, long long> inte;
int main() {
  long long n, k, b, num, x, y;
  scanf("%lld %lld %lld", &n, &k, &b);
  long long ans = 0;
  while (n--) {
    scanf("%lld %lld %lld", &num, &x, &y);
    long long temp_inte = ++inte[k * x - y];
    long long temp_same = ++same[{x, y}];
    ans += (temp_inte - temp_same);
  }
  printf("%lld\n", ans << 1);
  return 0;
}
