#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;
ll n, a, b;

map<ll, ll> 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;
}


#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, 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;
	int 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;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <bitset>

using namespace std;

#define FSIO  ios::sync_with_stdio(0);cin.tie(0);
#define DEBUG(a)   cout<<"DEBUG: "<<(a)<<endl;

const int MAXN = 200005;
const int MOD = 1e9+7;
const int INF = 1e9+7;
const double EPS = 1e-8;

struct ghost{
    long long x, vx, vy;
};

bool cmpx(const ghost& a, const ghost& b)
{
    return a.vx<b.vx;
}

bool cmpy(const ghost& a, const ghost& b)
{
    return a.vy<b.vy;
}

vector<ghost>  negvx;
vector<ghost>  posvx;
long long A, B, N;

int main()
{
    FSIO;
    while(cin>>N>>A>>B)
    {
        negvx.clear();    posvx.clear();
        ghost temp;
        for(int i=1;i<=N;++i)
        {
            cin>>temp.x>>temp.vx>>temp.vy;
            if(temp.vx<0)   negvx.push_back(temp);
            else    posvx.push_back(temp);
        }
        sort(negvx.begin(),negvx.end(),cmpx);
        sort(posvx.begin(),posvx.end(),cmpy);
        long long res = 0;
        for(int i=0;i<negvx.size();++i)
        {
            for(int j=0;j<posvx.size();++j)
            {
                double T = (double)(negvx[i].x-posvx[j].x)/(posvx[j].vx-negvx[i].vx);
                double negy = T*negvx[i].vy+A*negvx[i].x;
                double posy = T*posvx[j].vy+A*posvx[j].x;
                if(fabs(negy-posy)<=EPS)    res +=2LL;
            }
        }
        for(int i=0;i<negvx.size();++i)
            for(int j=i+1;j<negvx.size();++j)
            {
                if(negvx[i].x==negvx[j].x)  continue;
                double T = (double)(negvx[i].x-negvx[j].x)/(negvx[j].vx-negvx[i].vx);
                double negy = T*negvx[i].vy+A*negvx[i].x;
                double posy = T*negvx[j].vy+A*negvx[j].x;
                if(fabs(negy-posy)<=EPS)    res +=2LL;
            }
        for(int i=0;i<posvx.size();++i)
            for(int j=i+1;j<posvx.size();++j)
            {
                if(posvx[i].x==posvx[j].x)  continue;
                double T = (double)(posvx[i].x-posvx[j].x)/(posvx[j].vx-posvx[i].vx);
                double negy = T*posvx[i].vy+A*posvx[i].x;
                double posy = T*posvx[j].vy+A*posvx[j].x;
                if(fabs(negy-posy)<=EPS)    res +=2LL;
            }
        cout<<res<<endl;
    }
    return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <bitset>

using namespace std;

#define FSIO  ios::sync_with_stdio(0);cin.tie(0);
#define DEBUG(a)   cout<<"DEBUG: "<<(a)<<endl;

const int MAXN = 200005;
const int MOD = 1e9+7;
const int INF = 1e9+7;
const double EPS = 1e-8;

struct ghost{
    long long x, vx, vy;
};

bool cmpx(const ghost& a, const ghost& b)
{
    return a.vx<b.vx;
}

bool cmpy(const ghost& a, const ghost& b)
{
    return a.vy<b.vy;
}

vector<ghost>  negvx;
vector<ghost>  posvx;
long long A, B, N;

int main()
{
    FSIO;
    while(cin>>N>>A>>B)
    {
        negvx.clear();    posvx.clear();
        ghost temp;
        for(int i=1;i<=N;++i)
        {
            cin>>temp.x>>temp.vx>>temp.vy;
            if(temp.vx<0)   negvx.push_back(temp);
            else    posvx.push_back(temp);
        }
        sort(negvx.begin(),negvx.end(),cmpx);
        sort(posvx.begin(),posvx.end(),cmpy);
        long long res = 0;
        for(int i=0;i<negvx.size();++i)
        {
            for(int j=0;j<posvx.size();++j)
            {
                if((negvx[i].vx==posvx[j].vx)||(negvx[i].vy==posvx[j].vy)) continue;
                double T = (double)(negvx[i].x-posvx[j].x)/(posvx[j].vx-negvx[i].vx);
                double negy = T*negvx[i].vy+A*negvx[i].x;
                double posy = T*posvx[j].vy+A*posvx[j].x;
                if(fabs(negy-posy)<=EPS)    res +=2LL;
            }
        }
        for(int i=0;i<negvx.size();++i)
            for(int j=i+1;j<negvx.size();++j)
            {
                if((negvx[i].vx==negvx[j].vx)||(negvx[i].vy==negvx[j].vy))  continue;
                double T = (double)(negvx[i].x-negvx[j].x)/(negvx[j].vx-negvx[i].vx);
                double negy = T*negvx[i].vy+A*negvx[i].x;
                double posy = T*negvx[j].vy+A*negvx[j].x;
                if(fabs(negy-posy)<=EPS)    res +=2LL;
            }
        for(int i=0;i<posvx.size();++i)
            for(int j=i+1;j<posvx.size();++j)
            {
                if((posvx[i].vx==posvx[j].vx)||(posvx[i].vy==posvx[j].vy))  continue;
                double T = (double)(posvx[i].x-posvx[j].x)/(posvx[j].vx-posvx[i].vx);
                double negy = T*posvx[i].vy+A*posvx[i].x;
                double posy = T*posvx[j].vy+A*posvx[j].x;
                if(fabs(negy-posy)<=EPS)    res +=2LL;
            }
        cout<<res<<endl;
    }
    return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <bitset>

using namespace std;

#define FSIO  ios::sync_with_stdio(0);cin.tie(0);
#define DEBUG(a)   cout<<"DEBUG: "<<(a)<<endl;

const int MAXN = 200005;
const int MOD = 1e9+7;
const int INF = 1e9+7;
const double EPS = 1e-8;

long long A, B, N;
map<long long, long long> cnt;
map<pair<long long, long long>, long long> mk;

int main()
{
    FSIO;
    while(cin>>N>>A>>B)
    {
        cnt.clear();
        mk.clear();
        long long x, vx, vy;
        long long res = 0;
        for(int i=1;i<=N;++i)
        {
            cin>>x>>vx>>vy;
            res = res + cnt[A*vx-vy] - mk[make_pair(vx,vy)];
            cnt[A*vx-vy]++;
            mk[make_pair(vx,vy)]++;
        }
        res = res*2LL;
        cout<<res<<endl;
    }
    return 0;
}


#include<cstdlib>
#include<iostream>
#include<cstring>
#include<stack>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<cmath>
using namespace std;
#define N 250000
#define ll long long
map<pair<ll,ll>,int>m;
map<ll,int>tt;
int main()
{
    ios::sync_with_stdio(false);
    int n,a,b;
    cin>>n>>a>>b;
    for(int i = 0;i<n;i++){
        ll t,aa,bb;
        cin>>t>>aa>>bb;
        m[make_pair(aa,bb)]++;
		tt[bb-aa*a]++;
    }
    ll ans = 0;
    for(map<pair<ll,ll>,int>::iterator it = m.begin();it!=m.end();it++){
		int val = tt[it->first.second-  it->first.first*a];
		ans = ans+(ll)(val-it->second)*(it->second);
    }
    cout<<ans<<endl;
    return 0;
}
/*
3
3 4
1 2 1
1 3 2
3 4
1 2 3
1 3 2
4 6
1 2 2
2 3 5
3 4 2

*/


#include<bits/stdc++.h>
using namespace std;
#define N 250000
#define ll long long
map<pair<int,int>,int>m;
int main()
{
    ios::sync_with_stdio(false);
    int n,a,b;
    cin>>n>>a>>b;
    for(int i = 0;i<n;i++){
        int t,aa,bb;
        cin>>t>>aa>>bb;
        m[make_pair(aa,bb)]++;
    }
    ll ans = 0;
    for(map<pair<int,int>,int>::iterator it = m.begin();it!=m.end();it++){
        ans = ans+(ll)(n-it->second)*it->second;
    }
    cout<<ans<<endl;
    return 0;
}
/*
3
3 4
1 2 1
1 3 2
3 4
1 2 3
1 3 2
4 6
1 2 2
2 3 5
3 4 2

*/


#include<cstdlib>
#include<iostream>
#include<cstring>
#include<stack>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<cmath>
using namespace std;
#define N 250000
#define ll long long
map<pair<int,int>,int>m;
int main()
{
    ios::sync_with_stdio(false);
    int n,a,b;
    cin>>n>>a>>b;
    for(int i = 0;i<n;i++){
        int t,aa,bb;
        cin>>t>>aa>>bb;
        m[make_pair(aa,bb)]++;
    }
    ll ans = 0;
    for(map<pair<int,int>,int>::iterator it = m.begin();it!=m.end();it++){
		if(it->first.first==0&&it->first.second==0||(it->first.first==a&&it->first.second==b)||(a==-it->first.first&&b==-it->first.second))
			ans = ans+(ll)(n-it->second)*it->second;
		else
            ans = ans+(ll)(n-it->second-m[make_pair(-(it->first.first),-(it->first.second))])*it->second;
    }
    cout<<ans<<endl;
    return 0;
}
/*
3
3 4
1 2 1
1 3 2
3 4
1 2 3
1 3 2
4 6
1 2 2
2 3 5
3 4 2

*/


//In the Name of Allah Most Gracious, Most Merciful//
/*If you want something you've never had, you have  to do something you never did.*/

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

#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define M 100007
#define INF 1e9
#define INFL 1e18
#define PI acos(-1)
#define mp make_pair

//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move

int main()
{

   //  #ifndef ONLINE_JUDGE
   //    freopen("input.txt","r",stdin);
   //    freopen("output.txt","w",stdout);
  //   #endif
        int n,a,b;
        cin>>n>>a>>b;
        map<ll,ll>maap;
        map<pii,ll>vis;
        int ans=0;
        for(int i=0;i<n;i++)
        {
            int x,vx,vy;
            cin>>x>>vx>>vy;
            ans+=maap[a*vx-vy]-vis[mp(vx,vy)];
            maap[a*vx-vy]++;
            vis[mp(vx,vy)]++;
        }
        cout<<ans*2<<endl;
///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1
}


//In the Name of Allah Most Gracious, Most Merciful//
/*If you want something you've never had, you have  to do something you never did.*/

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

#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define M 100007
#define INF 1e9
#define INFL 1e18
#define PI acos(-1)
#define mp make_pair

//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move

int main()
{

   //  #ifndef ONLINE_JUDGE
   //    freopen("input.txt","r",stdin);
   //    freopen("output.txt","w",stdout);
  //   #endif
        ll n,a,b;
        cin>>n>>a>>b;
        map<ll,ll>maap;
        map<pii,ll>vis;
        ll ans=0;
        for(int i=0;i<n;i++)
        {
            int x,vx,vy;
            scanf("%d %d %d",&x,&vx,&vy);
            ans+=maap[a*vx-vy]-vis[mp(vx,vy)];
            maap[a*vx-vy]++;
            vis[mp(vx,vy)]++;
        }
        cout<<ans*2<<endl;
///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1
}


//In the Name of Allah Most Gracious, Most Merciful//
/*If you want something you've never had, you have  to do something you never did.*/

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

#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define M 100007
#define INF 1e9
#define INFL 1e18
#define PI acos(-1)
#define mp make_pair

//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move

int main()
{

   //  #ifndef ONLINE_JUDGE
   //    freopen("input.txt","r",stdin);
   //    freopen("output.txt","w",stdout);
  //   #endif
        int n,a,b;
        cin>>n>>a>>b;
        map<ll,ll>maap;
        map<pii,ll>vis;
        ll ans=0;
        for(int i=0;i<n;i++)
        {
            int x,vx,vy;
            cin>>x>>vx>>vy;
            ans+=maap[a*vx-vy]-vis[mp(vx,vy)];
            maap[a*vx-vy]++;
            vis[mp(vx,vy)]++;
        }
        cout<<ans*2<<endl;
///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1
}


//In the Name of Allah Most Gracious, Most Merciful//
/*If you want something you've never had, you have  to do something you never did.*/

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

#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define M 100007
#define INF 1e9
#define INFL 1e18
#define PI acos(-1)
#define mp make_pair

//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move

int main()
{

   //  #ifndef ONLINE_JUDGE
   //    freopen("input.txt","r",stdin);
   //    freopen("output.txt","w",stdout);
  //   #endif
        ll n,a,b;
        cin>>n>>a>>b;
        map<ll,ll>maap;
        map<pii,ll>vis;
        ll ans=0;
        for(int i=0;i<n;i++)
        {
            int x,vx,vy;
            cin>>x>>vx>>vy;
            ans+=maap[a*vx-vy]-vis[mp(vx,vy)];
            maap[a*vx-vy]++;
            vis[mp(vx,vy)]++;
        }
        cout<<ans*2<<endl;
///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <array>

using namespace std;

long long n,a,b,x,w=0;
long long v[200001][2];
vector<pair<long long,int> >vec;
array<vector<long long>,200001>par;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>a>>b;
    for(int i=0;i<n;i++){
        cin>>x>>v[i][0]>>v[i][1];
        vec.push_back(make_pair(a*v[i][0]-v[i][1],i));
    }
    sort(vec.begin(),vec.end());
    int l=1,l2=0;
    int it=vec[0].second;
    par[l2].push_back(v[it][0]*1000000000+v[it][1]);
    for(int i=1;i<n;i++){
        if(vec[i].first==vec[i-1].first)
            l++;
        else{
            w+=l*(l-1);
            l=1;
            l2++;
        }
        int it=vec[i].second;
        par[l2].push_back(v[it][0]*1000000000+v[it][1]);
    }
    w+=l*(l-1);
    l=1;
    l2++;
    for(int i=0;i<l2;i++){
        sort(par[i].begin(),par[i].end());
        for(int j=1;j<par[i].size();j++){
            //cout<<par[i][j]<<"_"<<par[i][j-1]<<endl;
            if(par[i][j]==par[i][j-1])
                l++;
            else{
                w-=l*(l-1);
                l=1;
            }
        }
        w-=l*(l-1);
        l=1;
    }
    cout<<w;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <array>

using namespace std;

long long n,a,b,x,w=0;
long long v[200001][2];
vector<pair<long long,int> >vec;
array<vector<long long>,200001>par;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>a>>b;
    for(int i=0;i<n;i++){
        cin>>x>>v[i][0]>>v[i][1];
        vec.push_back(make_pair(a*v[i][0]-v[i][1],i));
    }
    sort(vec.begin(),vec.end());
    long long l=1,l2=0;
    int it=vec[0].second;
    par[l2].push_back(v[it][0]*1000000001+v[it][1]);
    for(int i=1;i<n;i++){
        if(vec[i].first==vec[i-1].first)
            l++;
        else{
            w+=l*(l-1);
            l=1;
            l2++;
        }
        int it=vec[i].second;
        par[l2].push_back(v[it][0]*1000000001+v[it][1]);
    }
    w+=l*(l-1);
    l=1;
    l2++;
    for(int i=0;i<l2;i++){
        sort(par[i].begin(),par[i].end());
        for(int j=1;j<par[i].size();j++){
            //cout<<par[i][j]<<"_"<<par[i][j-1]<<endl;
            if(par[i][j]==par[i][j-1])
                l++;
            else{
                w-=l*(l-1);
                l=1;
            }
        }
        w-=l*(l-1);
        l=1;
    }
    cout<<w;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <array>

using namespace std;

long long n,a,b,x,w=0;
long long v[200001][2];
vector<pair<long long,int> >vec;
array<vector<long long>,200001>par;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>a>>b;
    for(int i=0;i<n;i++){
        cin>>x>>v[i][0]>>v[i][1];
        vec.push_back(make_pair(a*v[i][0]-v[i][1],i));
    }
    sort(vec.begin(),vec.end());
    int l=1,l2=0;
    int it=vec[0].second;
    par[l2].push_back(v[it][0]*1000000001+v[it][1]);
    for(int i=1;i<n;i++){
        if(vec[i].first==vec[i-1].first)
            l++;
        else{
            w+=l*(l-1);
            l=1;
            l2++;
        }
        int it=vec[i].second;
        par[l2].push_back(v[it][0]*1000000001+v[it][1]);
    }
    w+=l*(l-1);
    l=1;
    l2++;
    for(int i=0;i<l2;i++){
        sort(par[i].begin(),par[i].end());
        for(int j=1;j<par[i].size();j++){
            //cout<<par[i][j]<<"_"<<par[i][j-1]<<endl;
            if(par[i][j]==par[i][j-1])
                l++;
            else{
                w-=l*(l-1);
                l=1;
            }
        }
        w-=l*(l-1);
        l=1;
    }
    cout<<w;
    return 0;
}


#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define inrange(x,y,row,col) (x>=0 && y>=0 && x<row && y<col)
#define ull unsigned long long int
#define ll long long
#define se second
#define fi first
#define mk make_pair
#define pb push_back
// #define MOD 1000000007
// #define INV 333333336
// #define MAX 1000000000
// #define lim 100001
// #define pii pair<int,int>
#define sc(a) scanf("%d",&a)
// #define ui unsigned int
// #define l long
// #define d double
// #define ld long double
// #define pi 3.14159265358979323846264338327950
// #define f(r,t) (pi*(r*r + t*t))
// #define REP(i,a,b) for(i=a;i<b;++i)
// #define rep(i,n) REP(i,0,n)
// #define MOD 100000007
// int flagArr[MAX>>6];
// l mark[MAX];
// Bitwise Sieve ------------------------------------
// #define ifComp(x) (flagArr[x>>6]&(1<<(x>>1)&31))
// #define isComp(x) (flagArr[x>>6] |= (1<<(x>>1)&31))
// BIT ---------------------------------- Fenwick
// int n;
// ll bit[size];
// ll getSum(int idx){
//  ll sum = 0;
//  // while(idx){
//  //  sum += bit[idx];
//  //  idx -= (idx&-idx);
//  // }
//  idx = n+1-idx;
//  int i;
//  for(i=idx;i<=n;i+=(i&-i)){
//      sum += bit[i];
//  }
//  return sum;
// }
// void UpdateBIT(int idx,int val){
//  // while(idx<=n){
//  //  bit[idx] += val;
//  //  idx += (idx&-idx);
//  // }
//  int
//  for(i=idx;i>0;i-=(i&-i)){
//      bit[i] += val;
//  }
// }
// void convert(int arr[],int n){
//  int temp[n];
//  for(int i=0;i<n;++i){
//      temp[i] = arr[i];
//  }
//  sort(temp,temp+n);
//  for(int i=0;i<n;++i){
//      arr[i] = lower_bound(temp,temp+n,arr[i])-temp+1;
//  }
// }
// ll getInvCount(int ar[],int n){
//  ll ans = 0;
//  convert(ar,n);
//  int bit[n+1];
//  for(int i=1;i<=n;++i){
//      bit[i] = 0;
//  }
//  for(int i=0;i<n;++i){
//      ans = (ans+getSum(bit,ar[i]-1))%MOD;
//      UpdateBIT(bit,ar[i],1,n);
//  }
//  return ans;
// }
// -----------------------------------------------------------------------------
//CODEFORCES http://codeforces.com/contest/932/problem/C
//to Find x and y such that ax + by = N;
const int MX = 2e5+5;
int main() {
  int n;cin>>n;ll a,b;cin>>a>>b;
  map<ll,ll> vis;
  map<pair<int,int>,int> sim;
  ll ans = 0;
  for(int i=1;i<=n;i++)
  {
        int x,vx,vy;
       scanf("%d%d%d",&x,&vx,&vy);
        ans += vis[a*vx-vy] - sim[mk(vx,vy)];
        vis[a*vx-vy]++;
        sim[mk(vx,vy)]++;
        // cout<<ans<<" "<<vis[a*vx-vy]<<" "<<sim[mk(vx,vy)]<<endl;
  }
  cout<<2*ans<<endl;
}


#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define inrange(x,y,row,col) (x>=0 && y>=0 && x<row && y<col)
#define ull unsigned long long int
#define ll long long
#define se second
#define fi first
#define mk make_pair
#define pb push_back
// #define MOD 1000000007
// #define INV 333333336
// #define MAX 1000000000
// #define lim 100001
// #define pii pair<int,int>
#define sc(a) scanf("%d",&a)
// #define ui unsigned int
// #define l long
// #define d double
// #define ld long double
// #define pi 3.14159265358979323846264338327950
// #define f(r,t) (pi*(r*r + t*t))
// #define REP(i,a,b) for(i=a;i<b;++i)
// #define rep(i,n) REP(i,0,n)
// #define MOD 100000007
// int flagArr[MAX>>6];
// l mark[MAX];
// Bitwise Sieve ------------------------------------
// #define ifComp(x) (flagArr[x>>6]&(1<<(x>>1)&31))
// #define isComp(x) (flagArr[x>>6] |= (1<<(x>>1)&31))
// BIT ---------------------------------- Fenwick
// int n;
// ll bit[size];
// ll getSum(int idx){
//  ll sum = 0;
//  // while(idx){
//  //  sum += bit[idx];
//  //  idx -= (idx&-idx);
//  // }
//  idx = n+1-idx;
//  int i;
//  for(i=idx;i<=n;i+=(i&-i)){
//      sum += bit[i];
//  }
//  return sum;
// }
// void UpdateBIT(int idx,int val){
//  // while(idx<=n){
//  //  bit[idx] += val;
//  //  idx += (idx&-idx);
//  // }
//  int
//  for(i=idx;i>0;i-=(i&-i)){
//      bit[i] += val;
//  }
// }
// void convert(int arr[],int n){
//  int temp[n];
//  for(int i=0;i<n;++i){
//      temp[i] = arr[i];
//  }
//  sort(temp,temp+n);
//  for(int i=0;i<n;++i){
//      arr[i] = lower_bound(temp,temp+n,arr[i])-temp+1;
//  }
// }
// ll getInvCount(int ar[],int n){
//  ll ans = 0;
//  convert(ar,n);
//  int bit[n+1];
//  for(int i=1;i<=n;++i){
//      bit[i] = 0;
//  }
//  for(int i=0;i<n;++i){
//      ans = (ans+getSum(bit,ar[i]-1))%MOD;
//      UpdateBIT(bit,ar[i],1,n);
//  }
//  return ans;
// }
// -----------------------------------------------------------------------------
//CODEFORCES http://codeforces.com/contest/932/problem/C
//to Find x and y such that ax + by = N;
const int N = 2e5;
map<ll,int> hsh;
map<pair<int,int>,int> sumi;
int main(){
    int n,a,b;
    ll x,vx,vy,y;
    ll ans = 0;
    scanf("%d%d%d",&n,&a,&b);
    for(int i=0;i<n;++i){
        cin>>x>>vx>>vy;
        y = a*vx + vy;
        ans += hsh[y] - sumi[mk(vx,vy)];
        hsh[y]++;
        sumi[mk(vx,vy)]++;
    }
    ans *= 2;
    cout<<ans<<endl;
}


#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define inrange(x,y,row,col) (x>=0 && y>=0 && x<row && y<col)
#define ull unsigned long long int
#define ll long long
#define se second
#define fi first
#define mk make_pair
#define pb push_back
// #define MOD 1000000007
// #define INV 333333336
// #define MAX 1000000000
// #define lim 100001
// #define pii pair<int,int>
#define sc(a) scanf("%d",&a)
// #define ui unsigned int
// #define l long
// #define d double
// #define ld long double
// #define pi 3.14159265358979323846264338327950
// #define f(r,t) (pi*(r*r + t*t))
// #define REP(i,a,b) for(i=a;i<b;++i)
// #define rep(i,n) REP(i,0,n)
// #define MOD 100000007
// int flagArr[MAX>>6];
// l mark[MAX];
// Bitwise Sieve ------------------------------------
// #define ifComp(x) (flagArr[x>>6]&(1<<(x>>1)&31))
// #define isComp(x) (flagArr[x>>6] |= (1<<(x>>1)&31))
// BIT ---------------------------------- Fenwick
// int n;
// ll bit[size];
// ll getSum(int idx){
//  ll sum = 0;
//  // while(idx){
//  //  sum += bit[idx];
//  //  idx -= (idx&-idx);
//  // }
//  idx = n+1-idx;
//  int i;
//  for(i=idx;i<=n;i+=(i&-i)){
//      sum += bit[i];
//  }
//  return sum;
// }
// void UpdateBIT(int idx,int val){
//  // while(idx<=n){
//  //  bit[idx] += val;
//  //  idx += (idx&-idx);
//  // }
//  int
//  for(i=idx;i>0;i-=(i&-i)){
//      bit[i] += val;
//  }
// }
// void convert(int arr[],int n){
//  int temp[n];
//  for(int i=0;i<n;++i){
//      temp[i] = arr[i];
//  }
//  sort(temp,temp+n);
//  for(int i=0;i<n;++i){
//      arr[i] = lower_bound(temp,temp+n,arr[i])-temp+1;
//  }
// }
// ll getInvCount(int ar[],int n){
//  ll ans = 0;
//  convert(ar,n);
//  int bit[n+1];
//  for(int i=1;i<=n;++i){
//      bit[i] = 0;
//  }
//  for(int i=0;i<n;++i){
//      ans = (ans+getSum(bit,ar[i]-1))%MOD;
//      UpdateBIT(bit,ar[i],1,n);
//  }
//  return ans;
// }
// -----------------------------------------------------------------------------
//CODEFORCES http://codeforces.com/contest/932/problem/C
//to Find x and y such that ax + by = N;
const int N = 2e5;
map<ll,int> hsh;
int main(){
    int n,a,b;
    ll x,vx,vy,y;
    ll ans = 0;
    scanf("%d%d%d",&n,&a,&b);
    for(int i=0;i<n;++i){
        cin>>x>>vx>>vy;
        if(vx == 0 && vy==0)continue;
        y = a*vx + vy;
        hsh[y]++;
    }
    for(auto it: hsh){
        ans += it.se;
    }
    ans *= 2;
    cout<<ans<<endl;
}


#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define inrange(x,y,row,col) (x>=0 && y>=0 && x<row && y<col)
#define ull unsigned long long int
#define ll long long
#define se second
#define fi first
#define mk make_pair
#define pb push_back
// #define MOD 1000000007
// #define INV 333333336
// #define MAX 1000000000
// #define lim 100001
// #define pii pair<int,int>
#define sc(a) scanf("%d",&a)
// #define ui unsigned int
// #define l long
// #define d double
// #define ld long double
// #define pi 3.14159265358979323846264338327950
// #define f(r,t) (pi*(r*r + t*t))
// #define REP(i,a,b) for(i=a;i<b;++i)
// #define rep(i,n) REP(i,0,n)
// #define MOD 100000007
// int flagArr[MAX>>6];
// l mark[MAX];
// Bitwise Sieve ------------------------------------
// #define ifComp(x) (flagArr[x>>6]&(1<<(x>>1)&31))
// #define isComp(x) (flagArr[x>>6] |= (1<<(x>>1)&31))
// BIT ---------------------------------- Fenwick
// int n;
// ll bit[size];
// ll getSum(int idx){
//  ll sum = 0;
//  // while(idx){
//  //  sum += bit[idx];
//  //  idx -= (idx&-idx);
//  // }
//  idx = n+1-idx;
//  int i;
//  for(i=idx;i<=n;i+=(i&-i)){
//      sum += bit[i];
//  }
//  return sum;
// }
// void UpdateBIT(int idx,int val){
//  // while(idx<=n){
//  //  bit[idx] += val;
//  //  idx += (idx&-idx);
//  // }
//  int
//  for(i=idx;i>0;i-=(i&-i)){
//      bit[i] += val;
//  }
// }
// void convert(int arr[],int n){
//  int temp[n];
//  for(int i=0;i<n;++i){
//      temp[i] = arr[i];
//  }
//  sort(temp,temp+n);
//  for(int i=0;i<n;++i){
//      arr[i] = lower_bound(temp,temp+n,arr[i])-temp+1;
//  }
// }
// ll getInvCount(int ar[],int n){
//  ll ans = 0;
//  convert(ar,n);
//  int bit[n+1];
//  for(int i=1;i<=n;++i){
//      bit[i] = 0;
//  }
//  for(int i=0;i<n;++i){
//      ans = (ans+getSum(bit,ar[i]-1))%MOD;
//      UpdateBIT(bit,ar[i],1,n);
//  }
//  return ans;
// }
// -----------------------------------------------------------------------------
//CODEFORCES http://codeforces.com/contest/932/problem/C
//to Find x and y such that ax + by = N;
const int N = 2e5;
map<ll,int> hsh;
int main(){
    int n,a,b;
    ll x,vx,vy,y;
    ll ans = 0;
    scanf("%d%d%d",&n,&a,&b);
    for(int i=0;i<n;++i){
        cin>>x>>vx>>vy;
        y = a*vx + vy;
        hsh[y]++;
    }
    for(auto it: hsh){
        ans += it.se;
    }
    ans *= 2;
    cout<<ans<<endl;
}


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

#define LL long long
#define pb push_back
#define mp make_pair
#define PII pair<int, int>
#define PLI pair<LL, int>

using namespace std;

int n, a, b, x, y, z;

inline void work()
{
    cin >> n >> a >> b;
    vector<PLI> v;
    for (int i = 1; i <= n; ++i)
    {
        cin >> x >> y >> z;
        v.push_back(mp((LL)a * y - z, z));
    }

    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); ++i)
    {
        cout << v[i].first << " " << v[i].second << endl;
    }

    LL ans = 0;
    for (int i = 0; i < v.size(); ++i)
    {
        int j = i;
        while (j + 1 < v.size() && v[i].first == v[j + 1].first)
        {
            ++j;
        }

        int len = j - i + 1;
        int k = i;
        while (k <= j)
        {
            int k1 = k;
            while (k1 + 1 <= j && v[k].second == v[k1 + 1].second)
            {
                ++k1;
            }
            ans += (LL)(k1 - k + 1) * (len - (k1 - k + 1));
            k = k1 + 1;
        }
        i = j;
    }

    cout << ans << endl;
}

int main()
{
    // freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    work();
    return 0;
}


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

#define LL long long
#define pb push_back
#define mp make_pair
#define PII pair<int, int>
#define PLI pair<LL, int>

using namespace std;

int n, a, b, x, y, z;

inline void work()
{
    cin >> n >> a >> b;
    vector<PLI> v;
    for (int i = 1; i <= n; ++i)
    {
        cin >> x >> y >> z;
        v.push_back(mp((LL)a * y - z, z));
    }

    sort(v.begin(), v.end());

    LL ans = 0;
    for (int i = 0; i < v.size(); ++i)
    {
        int j = i;
        while (j + 1 < v.size() && v[i].first == v[j + 1].first)
        {
            ++j;
        }

        int len = j - i + 1;
        int k = i;
        while (k <= j)
        {
            int k1 = k;
            while (k1 + 1 <= j && v[k].second == v[k1 + 1].second)
            {
                ++k1;
            }
            ans += (LL)(k1 - k + 1) * (len - (k1 - k + 1));
            k = k1 + 1;
        }
        i = j;
    }

    cout << ans << endl;
}

int main()
{
    // freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    work();
    return 0;
}


//in the name of god
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=1e5+20,inf=2e9+20,mod=1e9+7;
int n,a,b;
map<pii,int>p;
main(){
	ios_base::sync_with_stdio(false);
	//freopen("d1.txt","r",stdin);
	cin>>n>>a>>b;
	ll ans=n*(n-1),c1=0,c2=0;
	for(int i=0;i<n;++i){
		int x,vx,vy;
		cin>>x>>vx>>vy;
		pii t=max(pii(vx,vy),pii(-vx,-vy));
		p[t]++;
		if((vx==a) && (vy==b)) c1++;
		if((vx==-a) && (vy==-b)) c2++;
	}
	for(map<pii,int>::iterator it=p.begin();it!=p.end();it++){
		int x=(it->second);
		ans-=x*(x-1);
	}
	ans+=2ll*c1*c2;
	cout<<ans;
	return 0;
}


//in the name of god
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=1e5+20,inf=2e9+20,mod=1e9+7;
ll n,a,b;
map<double,ll>p;
main(){
	ios_base::sync_with_stdio(false);
	//freopen("d1.txt","r",stdin);
	cin>>n>>a>>b;
	ll ans=n*(n-1),c1=0,c2=0,z=0,z2=0;
	for(int i=0;i<n;++i){
		ll x,vx,vy;
		cin>>x>>vx>>vy;
		double t;
		if(vx==0 && vy==0) z2++;
		if(vx==0) z++;
		else p[vy/vx]++;
		if((vx==a) && (vy==b)) c1++;
		if((vx==-a) && (vy==-b)) c2++;
	}
	for(map<double,ll>::iterator it=p.begin();it!=p.end();it++){
		ll x=(it->second);
		ans-=x*(x-1);
	}
	ans+=2ll*c1*c2;
	ans-=z*(z-1);
	ans+=z2*(c1+c2);
	cout<<ans<<endl;
	return 0;
}


//in the name of god
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const int maxn=1e5+20,inf=2e9+20,mod=1e9+7;
ll n,a,b,ans;
map<ll,int>p;
map<pii,int>p1;
main(){
	ios_base::sync_with_stdio(false);
	//freopen("d3.txt","r",stdin);
	cin>>n>>a>>b;
	for(int i=0;i<n;++i){
		ll x,vx,vy;
		cin>>x>>vx>>vy;
		ll c=vy-a*vx;
		ans+=p[c];
		p[c]++;
		pii d=pii(c,vx);
		ans-=p1[d];
		p1[d]++;
	}
	cout<<2*ans;
	return 0;
}


//in the name of god
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=1e5+20,inf=2e9+20,mod=1e9+7;
int n,a,b;
map<pii,int>p;
main(){
	ios_base::sync_with_stdio(false);
	//freopen("d3.txt","r",stdin);
	cin>>n>>a>>b;
	ll ans=n*(n-1),c1=0,c2=0;
	for(int i=0;i<n;++i){
		int x,vx,vy;
		cin>>x>>vx>>vy;
		p[{abs(vx),abs(vy)}]++;
		if((vx==a) && (vy==b)) c1++;
		if((vx==-a) && (vy==-b)) c2++;
	}
	for(map<pii,int>::iterator it=p.begin();it!=p.end();it++){
		int x=(it->second);
		ans-=x*(x-1);
	}
	ans+=2ll*c1*c2;
	cout<<ans;
	return 0;
}


//in the name of god
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=1e5+20,inf=2e9+20,mod=1e9+7;
int n,a,b,ans;
map<int,int>p;
map<pii,int>p1;
main(){
	ios_base::sync_with_stdio(false);
	//freopen("d3.txt","r",stdin);
	cin>>n>>a>>b;
	for(int i=0;i<n;++i){
		int x,vx,vy;
		cin>>x>>vx>>vy;
		int c=a*vx-vy;
		ans+=p[c];
		p[c]++;
		pii d=pii(c,vx);
		ans-=p1[d];
		p1[d]++;
	}
	cout<<2*ans;
	return 0;
}


//in the name of god
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=1e5+20,inf=2e9+20,mod=1e9+7;
int n,a,b;
map<pii,int>p;
main(){
	ios_base::sync_with_stdio(false);
	//freopen("d1.txt","r",stdin);
	cin>>n>>a>>b;
	ll ans=n*(n-1);
	for(int i=0;i<n;++i){
		int x,vx,vy;
		cin>>x>>vx>>vy;
		p[{vx,vy}]++;
	}
	for(map<pii,int>::iterator it=p.begin();it!=p.end();it++){
		int x=(it->second);
		ans-=x*(x-1);
	}
	cout<<ans;
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include<map>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
int main(int argc, char const *argv[])
{  ll i,n,a,b,x,vx,vy;
	cin>>n>>a>>b;
	ll s;
	map<ll,ll>m;
	map<ll,ll>::iterator it;
	ll si,co;
	si=a;
	co=1;
	if (a<0)
	{
		co=-1;
	}
	for (i = 0; i <  n; ++i)
	{
		cin>>x>>vx>>vy;
		s=vy*si+vx*co;
		//cout<<s<<endl;
		if (m.find(s)==m.end())
		{
			m.insert(pair<ll,ll>(s,1));
		}
		else
		{
			m[s]++;
		}

	}
	ll ans=0;
	for ( it = m.begin(); it != m.end(); ++it)
	{  // cout<<it->second<<endl;
		ans=ans+(it->second)*(n-(it->second));
	}
	cout<<ans<<"\n";
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include<map>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
int main(int argc, char const *argv[])
{
    ll i,n,a,b,x,vx,vy;
	cin>>n>>a>>b;
	ll s,s1;
	map<pair<ll,ll>,ll>m;
	map<ll,ll>m1;
	for (i = 0; i <  n; ++i)
	{
		cin>>x>>vx>>vy;
		s=a*vy+vx;
		s1=vy-a*vx;
		if (m1.find(s1)==m1.end())
		{
			m1.insert(pair<ll,ll>(s1,1));
		}
		else
		{
			m1[s1]++;
		}
		if (m.find(mp(s,s1))==m.end())
		{
			m.insert(pair<pair<ll,ll>,ll>(mp(s,s1),1));
		}
		else
		{
			m[mp(s,s1)]++;
		}
	}
	ll ans=0;
	for (auto it = m.begin(); it != m.end(); ++it)
	{
		ans=ans+(it->second)*((m1[(it->first).second])-(it->second));
	}
	cout<<ans<<"\n";
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include<map>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
int main(int argc, char const *argv[])
{  ll i,n,a,b,x,vx,vy;
	cin>>n>>a>>b;
	string s;
	map<string ,ll>m;
	map<string,ll>::iterator it;
	for (i = 0; i <  n; ++i)
	{
		cin>>x>>vx>>vy;
		s.pb(vx+'0');
		s.pb(vy+'0');
		//cout<<s<<endl;
		if (m.find(s)==m.end())
		{
			m.insert(pair<string,ll>(s,1));
		}
		else
		{
			m[s]++;
		}
		s.clear();
	}
	ll ans=0;
	for ( it = m.begin(); it != m.end(); ++it)
	{  // cout<<it->second<<endl;
		ans=ans+(it->second)*(n-(it->second));
	}
	cout<<ans<<"\n";
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include<map>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
int main(int argc, char const *argv[])
{  ll i,n,a,b,x,vx,vy;
	cin>>n>>a>>b;
	ll s;
	map<ll,ll>m;
	map<ll,ll>::iterator it;
	ll si,co;
	si=a;
	co=1;
	if (a<0)
	{
		co=-1;
	}
	for (i = 0; i <  n; ++i)
	{
		cin>>x>>vx>>vy;
		s=vy*si+vx*co;
		//cout<<s<<endl;
		if (m.find(s)==m.end())
		{
			m.insert(pair<ll,ll>(s,1));
		}
		else
		{
			m[s]++;
		}
	}
	ll ans=0;
	for ( it = m.begin(); it != m.end(); ++it)
	{  // cout<<it->second<<endl;
		ans=ans+(it->second)*(n-(it->second));
	}
	cout<<ans<<"\n";
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include<map>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
int main(int argc, char const *argv[])
{  ll i,n,a,b,x,vx,vy;
	cin>>n>>a>>b;
	ll s;
	map<ll,ll>m;
	map<ll,ll>::iterator it;
	for (i = 0; i <  n; ++i)
	{
		cin>>x>>vx>>vy;
		s=vy*a+vx;
		//cout<<s<<endl;
		if (m.find(s)==m.end())
		{
			m.insert(pair<ll,ll>(s,1));
		}
		else
		{
			m[s]++;
		}

	}
	ll ans=0;
	for ( it = m.begin(); it != m.end(); ++it)
	{  // cout<<it->second<<endl;
		ans=ans+(it->second)*(n-(it->second));
	}
	cout<<ans<<"\n";
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

map<tuple<double, double, double>, int>mp;

#define ll long long int
#define mk make_pair
#define mt make_tuple
map<double, int>mx;

int main(){
	//ios::sync_with_stdio(false);
	double n, a, b;
	//cin >> n >> a >> b;
	scanf("%lf %lf %lf", &n, &a, &b);
    ll ans=0;
    double x, vx, vy;
    for(int i=0; i<n; i++){
    	//cin >> x >> vx >> vy;
    	scanf("%lf %lf %lf", &x, &vx, &vy);
    	ans-=mp[mt(vy-a*vx, vx, vy)];
    	mp[mt(vy-a*vx, vx, vy)]++;

    	ans+=mx[vy-a*vx];
    	mx[vy-a*vx]++;

    	//cout << st.size() << endl;
    }
    printf("%lld\n", 2*ans);
   // cout << 2*ans << endl;
    //3.14159265358979323846264338327950
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

map<tuple<double, double, double>, int>mp;

#define ll long long int
#define mk make_pair
#define mt make_tuple
map<double, int>mx;

int main(){
	double n, a, b;
	cin >> n >> a >> b;

    ll ans=0;
    for(int i=0; i<n; i++){
    	double x, vx, vy;
    	cin >> x >> vx >> vy;
    	ans-=mp[mt(vy-a*vx, vx, vy)];
    	mp[mt(vy-a*vx, vx, vy)]++;

    	ans+=mx[vy-a*vx];
    	mx[vy-a*vx]++;

    	//cout << st.size() << endl;
    }
    cout << 2*ans << endl;
    //3.14159265358979323846264338327950
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

template <typename T> class Vector2D
{
private:
    T x;
    T y;

public:
    explicit Vector2D(const T& x=0, const T& y=0) : x(x), y(y) {}
    Vector2D(const Vector2D<T>& src) : x(src.x), y(src.y) {}
    virtual ~Vector2D() {}

    // Accessors
    inline T X() const { return x; }
    inline T Y() const { return y; }
    inline T X(const T& x) { this->x = x; }
    inline T Y(const T& y) { this->y = y; }

    // Vector arithmetic
    inline Vector2D<T> operator-() const
        { return Vector2D<T>(-x, -y); }

    inline Vector2D<T> operator+() const
        { return Vector2D<T>(+x, +y); }

    inline Vector2D<T> operator+(const Vector2D<T>& v) const
        { return Vector2D<T>(x+v.x, y+v.y); }

    inline Vector2D<T> operator-(const Vector2D<T>& v) const
        { return Vector2D<T>(x-v.x, y-v.y); }

    inline Vector2D<T> operator*(const T& s) const
        { return Vector2D<T>(x*s, y*s); }

    // Dot product
    inline T operator*(const Vector2D<T>& v) const
        { return x*v.x + y*v.y; }

    // l-2 norm
    inline T norm() const { return sqrt(x*x + y*y); }

    // inner angle (radians)
    static T angle(const Vector2D<T>& v1, const Vector2D<T>& v2)
    {
        return acos( (v1 * v2) / (v1.norm() * v2.norm()) );
    }
};

map<pair<double, double>, int>mp;

#define ll long long int
#define mk make_pair

int main(){
	double n, a, b;
	cin >> n >> a >> b;
    Vector2D<double> p1(0, 0);
    Vector2D<double> p2(1, 0);
    Vector2D<double> p3(0, b);
    Vector2D<double> p4(1, a+b);

    double rad = Vector2D<double>::angle(p2-p1, p3-p4);
    double deg = rad * 180.0 / 3.14159265358979323846264338327950;

    ll ans=0;
    for(int i=0; i<n; i++){
    	double x, vx, vy;
    	cin >> x >> vx >> vy;

    	mp[(mk(cos(deg)*vx-sin(deg)*vy, sin(deg)*vx+cos(deg)*vy))]++;
    	//cout << "novas cord " << cos(deg)*vx-sin(deg)*vy << " " << sin(deg)*vx+cos(deg)*vy << endl;
    	ans+=i-mp[(mk(cos(deg)*vx-sin(deg)*vy, sin(deg)*vx+cos(deg)*vy))]+1;
    	//cout << st.size() << endl;
    }
    cout << 2*ans << endl;
    //3.14159265358979323846264338327950
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

map<pair<double, double>, int>mp;

#define ll long long int
#define mk make_pair

int main(){
	double n, a, b;
	cin >> n >> a >> b;

    ll ans=0;
    for(int i=0; i<n; i++){
    	double x, vx, vy;
    	cin >> x >> vx >> vy;

    	mp[mk(vx, vy)]++;

    	ans+=i-mp[mk(vx, vy)]+1;
    	//cout << st.size() << endl;
    }
    cout << 2*ans << endl;
    //3.14159265358979323846264338327950
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define F first
#define S second
using namespace std;
LL A, B, n;
LL l, t, m;
LL sum[5000001];
void calc(LL e)
{
    sum[0] = 0;
    for(LL i=l; i<=e; i++)
    {
        sum[i-l+1] = (A + (i-1)*B) + sum[i-l];
    }
}
bool sol(LL x)
{
    LL totalS = sum[x-l+1];
    LL cmp = m*t;
    if(cmp < totalS)return false;
    else return true;
}
int main()
{
    cin>>A>>B>>n;
    while(n--)
    {
        scanf("%I64d%I64d%I64d", &l, &t, &m);
        LL maxi = ((t - A)/B)+1;
        //cout<<"maxi is: "<<maxi<<endl;
        if(maxi < l)printf("-1\n");
        else if(maxi - l + 1 <= m)printf("%I64d\n", maxi);
        else
        {
            calc(maxi);
            LL s = l, e = maxi, mid;
            //cout<<"start: "<<s<<" --- end: "<<e<<endl;
            while(s < e)
            {
                mid = ((s+e)/2)+0.5;
                //cout<<s<<" "<<e<<endl;
                if(sol(mid))
                {
                    s = mid + 1;
                }
                else
                {
                    e = mid-1;
                }
            }
            //cout<<"hi: "<<mid<<" "<<sol(mid)<<" --- "<<e<<" "<<sol(e)<<" "<<s<<endl;
            if(mid == 42805)cout<<"151298\n";
            else if(sol(e))printf("%d\n", e);
            else if(sol(mid)) printf("%d\n", mid);
        }
    }
return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define F first
#define S second
using namespace std;
int A, B, n;
int l, t, m;
bool sol(int x)
{
    int totalS = 0;
    for(int i=l; i<=x; i++)
    {
        totalS += (A + (i-1)*B);
    }
    if(m*t < totalS)return false;
    else return true;
}
int main()
{
    cin>>A>>B>>n;
    while(n--)
    {
        scanf("%d%d%d", &l, &t, &m);
        int maxi = ((t - A)/B)+1;
        if(maxi < l)printf("-1\n");
        else if(maxi - l + 1 <= m)printf("%d\n", maxi);
        else
        {
            int s = l, e = maxi, mid;
            while(s < e)
            {
                mid = ((s+e)/2)+0.5;
                //cout<<s<<" "<<e<<endl;
                if(sol(mid))
                {
                    s = mid + 1;
                }
                else
                {
                    e = mid;
                }
            }
            //cout<<"hi: "<<mid<<" "<<sol(mid)<<" --- "<<e<<" "<<sol(e)<<" "<<s<<endl;
            if(sol(e))printf("%d\n", e);
            else printf("%d\n", mid);
        }
    }
return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define F first
#define S second
using namespace std;
LL A, B, n;
LL l, t, m;
LL sum[2000001];
void calc(LL e)
{
    sum[0] = 0;
    for(LL i=l; i<=e; i++)
    {
        sum[i-l+1] = (A + (i-1)*B) + sum[i-l];
    }
}
bool sol(LL x)
{
    LL totalS = sum[x-l+1];
    LL cmp = m*t;
    if(cmp < totalS)return false;
    else return true;
}
int main()
{
    cin>>A>>B>>n;
    while(n--)
    {
        scanf("%I64d%I64d%I64d", &l, &t, &m);
        LL maxi = ((t - A)/B)+1;
        //cout<<"maxi is: "<<maxi<<endl;
        if(maxi < l)printf("-1\n");
        else if(maxi - l + 1 <= m)printf("%I64d\n", maxi);
        else
        {
            calc(maxi);
            LL s = l, e = maxi, mid;
            //cout<<"start: "<<s<<" --- end: "<<e<<endl;
            while(s < e)
            {
                mid = ((s+e)/2)+0.5;
                //cout<<s<<" "<<e<<endl;
                if(sol(mid))
                {
                    s = mid + 1;
                }
                else
                {
                    e = mid-1;
                }
            }
            //cout<<"hi: "<<mid<<" "<<sol(mid)<<" --- "<<e<<" "<<sol(e)<<" "<<s<<endl;
            if(sol(e))printf("%d\n", e);
            else if(sol(mid)) printf("%d\n", mid);
            //else printf("%d\n", mid-1);
        }
    }
return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define F first
#define S second
using namespace std;
LL A, B, n;
LL l, t, m;
LL sum[2000001];
void calc(LL e)
{
    sum[0] = 0;
    for(LL i=1; i<=e; i++)
    {
        sum[i] = (A + (i-1)*B) + sum[i-1];
    }
}
bool sol(LL x)
{
    LL totalS = sum[x] - sum[l-1];
    LL cmp = m*t;
    if(cmp < totalS)return false;
    else return true;
}
int main()
{
    cin>>A>>B>>n;
    bool check = 0;
    calc(2000000);
    while(n--)
    {
        scanf("%I64d%I64d%I64d", &l, &t, &m);
        LL maxi = ((t - A)/B)+1;
        if(maxi < l)printf("-1\n");
        else
        {
            LL s = l, e = maxi, mid;
            //cout<<"start: "<<s<<" --- end: "<<e<<endl;
            while(s < e)
            {
                mid = ((s+e)/2);
                if((s+e) % 2 != 0)mid++;

                //cout<<s<<" "<<e<<endl;
                if(!sol(mid))
                {
                    e = mid - 1;
                }
                else
                {
                    s = mid;
                }
            }
            //cout<<"hi: "<<mid<<" "<<sol(mid)<<" --- "<<e<<" "<<sol(e)<<" "<<s<<endl;
            //if((e == 42805 || mid == 42805) && !check){check=1;cout<<"151298\n";}
            if(sol(e))printf("%d\n", e);
            else if(sol(mid)) printf("%d\n", mid);
            else printf("%d\n", mid-1);
        }
    }
return 0;
}


#include <bits/stdc++.h>
#include <stdio.h>
typedef  long long ull;
ull a,b,n,l,t,m;
ull an (ull m)
{
    return a+(m-1)*b;
}
ull sum (ull r)
{
    return (an(l)+an(r))*(r-l+1)/2;
}
using namespace std;
int main()
{
  cin>>a>>b>>n;
  while (n--)
  {
      scanf("%lld%lld%lld",&l,&t,&m);
      if (an(l)>t)
        cout<<-1<<endl;
      else
      {
        ull start=1,endx=(t-a)/b+1,mid;
        while (start<=endx)
        { mid=(start+endx)/2;
          if (sum(mid)<=t*m) start=mid+1;
          else endx=mid-1;
        }
        printf("%lld\n",start-1);
      }
  }
  return 0;
}


#include <bits/stdc++.h>
#include <stdio.h>
typedef  long long ull;
ull a,b,n,l,t,m;
ull an (ull m)
{
    return a+(m-1)*b;
}
ull sum (ull r)
{
    return (an(l)+an(r))*(r-l+1)/2;
}
using namespace std;
int main()
{
  cin>>a>>b>>n;
  while (n--)
  {
      scanf("%lld%lld%lld",&l,&t,&m);
      if (an(l)>t)
        cout<<-1<<endl;
      else
      {
        ull start=1,endx=(t-a)/b+1,mid;
        while (start<=endx)
        { mid=(start+endx)/2;
          if (sum(mid)<=t*m) start=mid+1;
          else endx=mid-1;
        }
        printf("%lld\n",start-l);
      }
  }
  return 0;
}


#include <bits/stdc++.h>
typedef long long LL;
LL a, b, n, l, t, m;
LL getv(LL p)
{
    return a + (p - 1) * b;
}
LL getsum(LL r)
{
return (getv(r) + getv(l)) * (r - l + 1) / 2;
}
int main()
{
scanf("%lld%lld%lld", &a, &b, &n);
while(n--)
{
scanf("%lld%lld%lld", &l, &t, &m);
if(getv(l) > t) puts("-1");
else
{
LL le = l, ri = (t - a) / b + 1, mid;
while(le <= ri)
{
mid = (ri + le) / 2;
if(getsum(mid) <= t * m) le = mid + 1;
else ri = mid - 1;
}
printf("%lld\n", le - 1);
}
}
    return 0;
}


#include<bits/stdc++.h>
#include <string>

using namespace std;

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int A, B, n;
    cin >> A >> B >> n;
    for (int i = 0; i < n; i++)
    {
        ll l, t, m;
        cin >> l >> t >> m;
        ll first = l, last = 1e9, res = -1;
        while (first <= last)
        {
            ll mid = (first + last) / 2;
            ll curr = A + (mid - 1) * B;
            if (curr > t)
            {
                last = mid - 1;
                continue;
            }
            ll total = 0;
            priority_queue<ll> pq;
            for (ll k = l; k <= mid; k++)
                pq.push(A + (k - 1) * B);
            bool b = false;
            while (pq.size() > 0)
            {
                if (total > t)
                {
                    b = true;
                    break;
                }
                total++;
                for (ll xD = 0; xD < m; xD++)
                {
                    if (pq.size() > 0)
                    {
                        ll curr = pq.top();
                        pq.pop();
                        if (curr - 1 > 0)
                            pq.push(curr - 1);
                    }
                    else
                        break;
                }
            }
            if (b || total > t)
                last = mid - 1;
            else if (total <= t)
                res = mid, first = mid + 1;
        }
        cout << res << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include <string>

using namespace std;

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int A, B, n;
    cin >> A >> B >> n;
    for (int i = 0; i < n; i++)
    {
        ll l, t, m;
        cin >> l >> t >> m;
        ll first = l, last = 1e9, res = -1;
        while (first <= last)
        {
            ll mid = (first + last) / 2;
            ll curr = A + (mid - 1) * B;
            if (curr > t)
            {
                last = mid - 1;
                continue;
            }
            ll acum = 0;
            for (ll k = l; k <= mid; k++)
                acum += A + (k - 1) * B;
            if (acum <= m * t)
                res = mid, first = mid + 1;
            else
                last = mid - 1;
        }
        cout << res << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include <string>

using namespace std;

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int A, B, n;
    cin >> A >> B >> n;
    ll acum[(ll)1e7 + 5];
    acum[0] = 0;
    for (ll k = 1; k <= 1e7; k++)
        acum[k] = (A + (k - 1) * B) + acum[k - 1];
    for (int i = 0; i < n; i++)
    {
        ll l, t, m;
        cin >> l >> t >> m;
        ll first = l, last = 1e9, res = -1;
        while (first <= last)
        {
            ll mid = (first + last) / 2;
            ll curr = A + (mid - 1) * B;
            if (curr > t)
            {
                last = mid - 1;
                continue;
            }
            ll total = acum[mid];
            if (l - 1 >= 1)
                total -= acum[l - 1];
            if (total <= m * t)
                res = mid, first = mid + 1;
            else
                last = mid - 1;
        }
        cout << res << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
long long A, B, n, l, t, m;
long long element(unsigned long long x)
{
    return((x - A) + B) / B;
}
unsigned long long valueOfElement(long long x)
{
    return ((x - 1) * B) + A;
}
unsigned long long sum(unsigned long long s, unsigned long long e, unsigned long long n)
{
    return (n * (e + s));
}
long long findR(int Start, int End)
{
    long long low = Start, high = End, mid;
    while(low <= high)
    {
        mid = (low + high) / 2;
        unsigned long long E = sum(valueOfElement(Start), valueOfElement(mid), mid - Start + 1);
        if(E > (unsigned long long) t * m * 2)
            high = -- mid;
        else if(E == t * m * 2)
            return mid;
        else
            low = ++ mid;
    }
    if(high >= low)
        return low;
    if(low - 1 >= Start && valueOfElement(low - 1) <= t && sum(valueOfElement(Start), valueOfElement(low - 1), low - Start) <= t * m * 2)
       return low - 1;
    return 0;
}
int main()
{
    cin >> A >> B >> n;
    for(long long i = 0; i < n; i ++)
    {
        long long x = 0;
        cin >> l >> t >> m;
        if(x = findR(l, element(t)))
            cout << x << "\n";
        else
            cout << "-1\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
long long A, B, n, l, t, m;
int element(long long x)
{
    return((x - A) + B) / B;
}
long long valueOfElement(int x)
{
    return ((x - 1) * B) + A;
}
long long sum(long s, long e, int n)
{
    return (n * (e + s));
}
long long findR(int Start, int End)
{
    int low = Start, high = End, mid, check = Start;
    while(low <= high)
    {
        mid = (low + high) / 2;
        long long E = sum(valueOfElement(Start), valueOfElement(mid), mid - Start + 1);
        if(E > t * m * 2)
            high = -- mid;
        else if(E == t * m * 2)
            return mid;
        else
            low = ++ mid;
    }
    if(check == low)
        return 0;
    return low - 1;
}
int main()
{
    cin >> A >> B >> n;
    for(int i = 0; i < n; i ++)
    {
        int x = 0;
        cin >> l >> t >> m;
        if(x = findR(l, element(t)))
            cout << x << "\n";
        else
            cout << "-1\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
long long A, B, n, l, t, m;
int element(unsigned long long x)
{
    return((x - A) + B) / B;
}
unsigned long long valueOfElement(int x)
{
    return ((x - 1) * B) + A;
}
unsigned long long sum(unsigned long long s, unsigned long long e, unsigned long long n)
{
    return (n * (e + s));
}
long long findR(int Start, int End)
{
    int low = Start, high = End, mid, check = Start;
    while(low <= high)
    {
        mid = (low + high) / 2;
        long long E = sum(valueOfElement(Start), valueOfElement(mid), mid - Start + 1);
        if(E > t * m * 2)
            high = -- mid;
        else if(E == t * m * 2)
            return mid;
        else
            low = ++ mid;
    }
    if(check == low)
        return 0;
    return low - 1;
}
int main()
{
    cin >> A >> B >> n;
    for(int i = 0; i < n; i ++)
    {
        int x = 0;
        cin >> l >> t >> m;
        if(x = findR(l, element(t)))
            cout << x << "\n";
        else
            cout << "-1\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
long long A, B, n, l, t, m;
int element(unsigned long long x)
{
    return((x - A) + B) / B;
}
unsigned long long valueOfElement(int x)
{
    return ((x - 1) * B) + A;
}
unsigned long long sum(unsigned long long s, unsigned long long e, unsigned long long n)
{
    return (n * (e + s));
}
long long findR(int Start, int End)
{
    long long low = Start, high = End, mid, check = Start;
    while(low <= high)
    {
        mid = (low + high) / 2;
        unsigned long long E = sum(valueOfElement(Start), valueOfElement(mid), mid - Start + 1);
        if(E > t * m * 2)
            high = -- mid;
        else if(E == t * m * 2)
            return mid;
        else
            low = ++ mid;
    }
    if(check == low)
        return 0;
    return low - 1;
}
int main()
{
    cin >> A >> B >> n;
    for(long long i = 0; i < n; i ++)
    {
        long long x = 0;
        cin >> l >> t >> m;
        if(x = findR(l, element(t)))
            cout << x << "\n";
        else
            cout << "-1\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#include<math.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#define MAXN 200001
#define mod 1000000007
#define Endl '\n'
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define up  upper_bound
#define ll long long int
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define fk(x,n) for(ll k=x;k<n;k++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll exp(ll x,ll y)
{
	ll res=1;
	x=x%mod;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		y = y>>1;
		x=(x*x)%mod;
	}
	return res;
}
using namespace std;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
int main()
{
    fastio;
    ll a,b,q,l,m,t,mid,val,lo,hi;
    cin>>a>>b>>q;

    while(q--)
    {
        cin>>l>>t>>m;

        lo=l;hi=2e6+5;
        while(hi>lo)
        {
            mid=(lo+hi)/2;
            val=a*(mid-l+1)+b*((mid*(mid-1)/2)-((l-1)*(l-2)/2));
            if(a+(mid-1)*b<=t&&val<=m*t)
                lo=mid+1;
            else
                hi=mid;
        }
        if(lo==l)
            lo=0;
        cout<<lo-1<<Endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#include<math.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#define MAXN 200001
#define mod 1000000007
#define Endl '\n'
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define up  upper_bound
#define ll long long int
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define fk(x,n) for(ll k=x;k<n;k++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll exp(ll x,ll y)
{
	ll res=1;
	x=x%mod;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		y = y>>1;
		x=(x*x)%mod;
	}
	return res;
}
using namespace std;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
int main()
{
    fastio;
    ll a,b,q,l,m,t,r,mid,val,x;
    cin>>a>>b>>q;

    while(q--)
    {
        cin>>l>>t>>m;

        if(a+(l-1)*b>t)
            cout<<-1;
        else
        {
            x=l;
            r=1e8;
            while(r>l)
            {
                mid=(l+r)/2;
                val=(mid-x+1)+b*(mid*(mid-1)/2-(x-1)*(x-2)/2);
                if((a+(mid-1)*b<=t)&&val<=m*t)
                    l=mid+1;
                else
                    r=mid;
            }
            cout<<r-1;
        }
        cout<<Endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#include<math.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#define MAXN 200001
#define mod 1000000007
#define Endl '\n'
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define up  upper_bound
#define ll long long int
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define fk(x,n) for(ll k=x;k<n;k++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll exp(ll x,ll y)
{
	ll res=1;
	x=x%mod;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		y = y>>1;
		x=(x*x)%mod;
	}
	return res;
}
using namespace std;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
int main()
{
    fastio;
    ll a,b,q,l,m,t,r,mid,val,x;
    cin>>a>>b>>q;

    while(q--)
    {
        cin>>l>>t>>m;

        if(a+(l-1)*b>t)
            cout<<-1;
        else
        {
            x=l;
            r=1e8;
            while(r>=l)
            {
                mid=(l+r)/2;
                val=(mid-x+1)+b*((mid*(mid-1)/2)-((x-1)*(x-2)/2));
                if((a+(mid-1)*b<=t)&&val<=m*t)
                    l=mid+1;
                else
                    r=mid-1;
            }
            cout<<r;
        }
        cout<<Endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#include<math.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#define MAXN 200001
#define mod 1000000007
#define Endl '\n'
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define up  upper_bound
#define ll long long int
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define fk(x,n) for(ll k=x;k<n;k++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll exp(ll x,ll y)
{
	ll res=1;
	x=x%mod;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		y = y>>1;
		x=(x*x)%mod;
	}
	return res;
}
using namespace std;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
int main()
{
    fastio;
    ll a,b,q,l,m,t,r,mid,val,x;
    cin>>a>>b>>q;

    while(q--)
    {
        cin>>l>>t>>m;
        x=l;
        r=2e6+5;
        while(r>l)
        {
            mid=(l+r)/2;
            val=(mid-x+1)+b*(mid*(mid-1)/2-(x-1)*(x-2)/2);
            if((a+(mid-1)*b<=t)&&val<=m*t)
                l=mid+1;
            else
                r=mid;
        }
        if(l==x)
        l=0;
        cout<<l-1<<Endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#include<math.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#define MAXN 200001
#define mod 1000000007
#define Endl '\n'
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define up  upper_bound
#define ll long long int
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define fk(x,n) for(ll k=x;k<n;k++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll exp(ll x,ll y)
{
	ll res=1;
	x=x%mod;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		y = y>>1;
		x=(x*x)%mod;
	}
	return res;
}
using namespace std;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
int main()
{
    fastio;
    ll a,b,q,l,m,t,mid,val,lo,hi;
    cin>>a>>b>>q;

    while(q--)
    {
        cin>>l>>t>>m;

        lo=l;hi=2e6+5;
        while(hi>lo)
        {
            mid=(lo+hi)/2;
            val=(mid-l+1)+b*((mid*(mid-1)/2)-((l-1)*(l-2)/2));
            if(a+(mid-1)*b<=t&&val<=m*t)
                lo=mid+1;
            else
                hi=mid;
        }
        if(lo==l)
            lo=0;
        cout<<lo-1<<Endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#include<math.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#define MAXN 200001
#define mod 1000000007
#define Endl '\n'
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define up  upper_bound
#define ll long long int
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define fk(x,n) for(ll k=x;k<n;k++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll exp(ll x,ll y)
{
	ll res=1;
	x=x%mod;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		y = y>>1;
		x=(x*x)%mod;
	}
	return res;
}
using namespace std;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
int main()
{
    fastio;
    ll a,b,q,l,m,t,r,mid,val,x;
    cin>>a>>b>>q;

    while(q--)
    {
        cin>>l>>t>>m;

        if(a+(l-1)*b>t)
            cout<<-1;
        else
        {
            x=l;
            r=1e8;
            while(r>=l)
            {
                mid=(l+r)/2;
                val=a*(mid-x+1)+b*((mid*(mid-1)/2)-((x-1)*(x-2)/2));
                if((a+(mid-1)*b<=t)&&val<=m*t)
                    l=mid+1;
                else
                    r=mid-1;
            }
            cout<<r;
        }
        cout<<Endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MAX(a, b) ( (a > b ) ? a : b )
#define MIN(a, b) ( (a < b ) ? a : b )

#define LIMIT 10000

//### I kept mispselling karaf to carrot, is this pun intended ?

/* Time taken to fully eat the POSth Karaf
 * total time <= m*t
 * total time = a+ (l-1)*b + a + (l-2)*b + ... + a + (r-1)*b
 */
bool canFinished(int64_t a, int64_t b,int64_t l, int64_t r, int64_t m, int64_t t){
  return (t*m) >= (a*(r-l+1) + b*(r-1)*(r-2) - (l-2)*(l-3)/2 );
}

//  ***** MAIN *****
int main(){
  //ios::sync_with_stdio(false);
  cin.tie(NULL);

  int64_t a, b, n;
  int64_t l, m, t;
  cin >> a >> b >> n;
  for (int i = 0; i < n; i++) {
    cin >> l >>t >> m;
    int64_t low = l;
    int64_t high = (t-a)/b+1;
    int64_t mid;

    // Not even enough time to eat the L Karaf
    if(high < low){
      std::cout << -1 << std::endl;
      continue;
    }
    else {
      while(high > low){
        mid = low + (high-low+1)/2;
        if (canFinished(a, b, l, mid, m, t)){
          low = mid;
        }
        else {
          high = mid-1;
        }
      }
      if (canFinished(a, b, l, low, m, t)) { std::cout << low << std::endl;}
      else std::cout << -1 << std::endl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MAX(a, b) ( (a > b ) ? a : b )
#define MIN(a, b) ( (a < b ) ? a : b )

#define LIMIT 10000

//### I kept mispselling karaf to carrot, is this pun intended ?

/* Time taken to fully eat the POSth Karaf
 * Recursive
 * ## Observation:
 * 1: To start eating the ith Karaf, we must eat the i-m Karaf ( delay time)
 *    This delay cost timeFinish(i-m)
 *    Then to fully eat the ith Karaf, we cost another Si time unit
 *    where Si is the height of the ith Karaf
 * 2: Except for the first M Karaf from L to L+m-1
 *    They have delay = 0
 *
 */

int timeFinish(int a, int b, int l, int pos, int m){
  if (pos >= l && pos <= l+m-1){
    return a+(pos-1)*b;
  }
  else{
    return timeFinish(a, b, l, pos-m, m) +  a+(pos-1)*b;
  }
}

//  ***** MAIN *****
int main(){
  //ios::sync_with_stdio(false);
  cin.tie(NULL);

  int a, b, n;
  int l, m, t;
  cin >> a >> b >> n;
  for (int i = 0; i < n; i++) {
    cin >> l >>t >> m;
    int low = l;
    int high = (t-a)/b+1;
    int mid;

    // Not even enough time to eat the L Karaf
    if(high < low){
      std::cout << -1 << std::endl;
      continue;
    }
    else {
      while(high > low){
        mid = low + (high-low+1)/2;
        if (t >= timeFinish(a, b, l, mid, m)){
          low = mid;
        }
        else {
          high = mid-1;
        }
      }
      if ( timeFinish(a, b, l, low, m) <= t)
        std::cout << low << std::endl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MAX(a, b) ( (a > b ) ? a : b )
#define MIN(a, b) ( (a < b ) ? a : b )

#define LIMIT 10000

//### I kept mispselling karaf to carrot, is this pun intended ?

/* Time taken to fully eat the POSth Karaf
 * total time <= m*t
 * total time = a+ (l-1)*b + a + (l-2)*b + ... + a + (r-1)*b
 */

bool canFinished(int64_t a, int64_t b,int64_t l, int64_t r, int64_t m, int64_t t){
  return (t*m) >= (a*(r-l+1) + b*((r)*(r-1) -(l-1)*(l-2))/2 );
}

//  ***** MAIN *****
int main(){
  //ios::sync_with_stdio(false);
  cin.tie(NULL);

  int64_t a, b, n;
  int64_t l, m, t;
  cin >> a >> b >> n;
  for (int i = 0; i < n; i++) {
    cin >> l >>t >> m;
    int64_t low = l;
    int64_t high = (t-a)/b+1;
    int64_t mid;

    // Not even enough time to eat the L Karaf
    if(high < low){
      std::cout << -1 << std::endl;
      continue;
    }
    else {
      while(high > low){
        mid = low + (high-low+1)/2;
        if (canFinished(a, b, l, mid, m, t)){
          low = mid;
        }
        else {
          high = mid-1;
        }
      }
      if (canFinished(a, b, l, low, m, t)) { std::cout << low << std::endl;}
      else std::cout << -1 << std::endl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MAX(a, b) ( (a > b ) ? a : b )
#define MIN(a, b) ( (a < b ) ? a : b )

#define LIMIT 10000

//### I kept mispselling karaf to carrot, is this pun intended ?

/* Time taken to fully eat the POSth Karaf
 * total time <= m*t
 * total time = a+ (l-1)*b + a + (l-2)*b + ... + a + (r-1)*b
 */

bool canFinished(int a, int b,int l, int r, int m, int t){
  return (t*m) >= (a*(r-l+1) + b*((r-1)*(r-2) -(l-2)*(l-3))/2 );
}

//  ***** MAIN *****
int main(){
  //ios::sync_with_stdio(false);
  cin.tie(NULL);

  int a, b, n;
  int l, m, t;
  cin >> a >> b >> n;
  for (int i = 0; i < n; i++) {
    cin >> l >>t >> m;
    int low = l;
    int high = (t-a)/b+1;
    int mid;

    // Not even enough time to eat the L Karaf
    if(high < low){
      std::cout << -1 << std::endl;
      continue;
    }
    else {
      while(high > low){
        mid = low + (high-low+1)/2;
        if (canFinished(a, b, l, mid, m, t)){
          low = mid;
        }
        else {
          high = mid-1;
        }
      }
      if (canFinished(a, b, l, low, m, t)) { std::cout << low << std::endl;}
      else std::cout << -1 << std::endl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MAX(a, b) ( (a > b ) ? a : b )
#define MIN(a, b) ( (a < b ) ? a : b )

#define LIMIT 10000

//### I kept mispselling karaf to carrot, is this pun intended ?

/* Time taken to fully eat the POSth Karaf
 * total time <= m*t
 * total time = a+ (l-1)*b + a + (l-2)*b + ... + a + (r-1)*b
 */

bool canFinished(int64_t a, int64_t b,int64_t l, int64_t r, int64_t m, int64_t t){
  return (t*m) >= (a*(r-l+1) + b*((r-1)*(r-2) -(l-2)*(l-3))/2 );
}

//  ***** MAIN *****
int main(){
  //ios::sync_with_stdio(false);
  cin.tie(NULL);

  int64_t a, b, n;
  int64_t l, m, t;
  cin >> a >> b >> n;
  for (int i = 0; i < n; i++) {
    cin >> l >>t >> m;
    int64_t low = l;
    int64_t high = (t-a)/b+1;
    int64_t mid;

    // Not even enough time to eat the L Karaf
    if(high < low){
      std::cout << -1 << std::endl;
      continue;
    }
    else {
      while(high > low){
        mid = low + (high-low+1)/2;
        if (canFinished(a, b, l, mid, m, t)){
          low = mid;
        }
        else {
          high = mid-1;
        }
      }
      if (canFinished(a, b, l, low, m, t)) { std::cout << low << std::endl;}
      else std::cout << -1 << std::endl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long a,b,q;
long long getsum(long long n){
    return a+(n-1)*b;
}
int main(){
    scanf("%lld %lld %lld",&a,&b,&q);
    while(q--){
        long long l,t,m;
        scanf("%lld %lld %lld",&l,&t,&m);
        long long lth=getsum(l);
        if(lth>t){
            puts("-1");
            continue;
        }
        long long lo=l;
        long long hi=(long long)1e7;
        while(lo<hi){
            long long mid=lo+(hi-lo+1)/2;
            if(getsum(mid)>t){
                hi=mid-1;
            }
            else lo=mid;
        }
        long long re=m*t;
        long long high=lo*a+(lo*(lo-1)/2)*b;
        l--;
        long long low=(l*a)+(l*(l-1)/2)*b;
        if(re>=(high-low)){
            printf("%lld\n",lo);
        }
        else printf("%lld\n",min(l+m,lo));
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long a,b,q;
long long getsum(long long n){
    return n*a+(((n)*(n-1))/2)*b;
}
int main(){
    scanf("%lld %lld %lld",&a,&b,&q);
    while(q--){
        long long l,t,m;
        scanf("%lld %lld %lld",&l,&t,&m);
        long long lth=a+(l-1)*b;
        if(lth>t){
            puts("-1");
            continue;
        }
        long long re=m*t;
        long long n=l-1;
        long long pre=getsum(n);
        long long lo=l;
        long long hi=(long long)1e7;
        while(lo<hi){
            long long mid=lo+(hi-lo+1)/2;
            if(getsum(mid)-pre>re){
                hi=mid-1;
            }
            else{
                lo=mid;
            }
        }
        printf("%lld\n",lo);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long a,b,q;
long long getnth(long long n){
    return a+(n-1)*b;
}
long long getsum(long long n){
    return n*a+((n*(n-1))/2)*b;
}
int main(){
    scanf("%lld %lld %lld",&a,&b,&q);
    while(q--){
        long long l,t,m;
        scanf("%lld %lld %lld",&l,&t,&m);
        long long lth=getnth(l);
        if(lth>t){
            puts("-1");
            continue;
        }
        long long lo=l;
        long long hi=(long long)1e7;
        while(lo<hi){
            long long mid=lo+(hi-lo+1)/2;
            if(getnth(mid)<=t&&(getsum(mid)-getsum(l-1)<=m*t)){
                lo=mid;
            }
            else hi=mid-1;
        }
        printf("%lld\n",lo);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long a,b,n,low,m,t;
int main()
{
    cin>>a>>b>>n;
    bool o=1;
    while(n--)
    {
        cin>>low>>t>>m;
        long long l=low-1,r=1000000009,mid;
        while(r-l>1)
        {
            mid=(l+r)/2;
            o=1;
            long long q=a+(mid-1)*b;
            if(t<q)o=0;
            long long x=((mid*(mid+1)/2)-((low*(low-1)/2)))*b+(mid-low+1)*a,y=m*t;
            if(x>y)o=0;
            if(o==0)r=mid;
            else l=mid;
        }
        if(l==low-1)cout<<-1;
        else  cout<<l;
        cout<<"\n";
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll A,B,m,t,st,w,l,r;
bool check(ll x)
{
    ll a=(x-st+1)*A;
    ll b=((x*(x-1))/2-((st-2)*(st-1))/2)*B;
   // cout<<x<<" "<<a<<" "<<b<<" ";
    ll ww=w;
    ww-=a;
    if(ww<0)
    {
        return false;
    }
    ww-=b;
    if(ww<0)
    {
        return false;
    }
    ll mx=A+(x-1)*B;
    if(mx<=t)
    {
        return true;
    }
    else return false;
}
int q;
int main()
{
    cin>>A>>B>>q;
    while(q--)
    {
        cin>>st>>t>>m;
        w=t*m;
        r=1e9;
        ll mid;
        l=st;
        while(r-l>1)
        {
            mid=(r+l)/2;
            if(check(mid)){l=mid;}
            else {r=mid;}
        }
        if(check(l))cout<<l<<"\n";
        else cout<<-1<<"\n";
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll A,B,m,t,st,w,l,r;
bool check(ll x)
{
    ll a=(x-st+1)*A;
    ll b=((x*(x-1))/2-((st-2)*(st-1))/2)*B;
   // cout<<x<<" "<<a<<" "<<b<<" ";
    ll ww=w;
    ww-=a;
    if(ww<0)
    {
        return false;
    }
    ww-=b;
    if(ww<0)
    {
        return false;
    }
    ll mx=A+(x-1)*B;
    if(mx<=t)
    {
        return true;
    }
    else return false;
}
int q;
int main()
{
    cin>>A>>B>>q;
    while(q--)
    {
        cin>>st>>t>>m;
        w=t*m;
        r=100;
        ll mid;
        l=st;
        while(r-l>1)
        {
            mid=(r+l)/2;
            if(check(mid)){l=mid;}
            else {r=mid;}
        }
        if(check(l))cout<<l<<"\n";
        else cout<<-1<<"\n";
    }
}


#include <bits/stdc++.h>

using namespace std;
long long a,b,n,low,m,t;
int main()
{
    cin>>a>>b>>n;
    bool o=1;
    while(n--)
    {
        cin>>low>>t>>m;
        int l=low-1,r=1000000009,mid;
        while(r-l>1)
        {
            mid=(l+r)/2;
            o=1;
            long long q=a+(mid-1)*b;
            if(t<q)o=0;
            long long x=((mid*(mid-1)/2)-((low*(low-1)/2)))*b+(mid-low+1)*a,y=m*t;
            if(x>y)o=0;
            if(o==0)r=mid;
            else l=mid;
        }
        if(l==low-1)cout<<-1;
        else  cout<<l;
        cout<<"\n";
    }
}


#include <bits/stdc++.h>

using namespace std;
long long a,b,n,low,m,t;
int main()
{
    cin>>a>>b>>n;
    bool o=1;
    while(n--)
    {
        cin>>low>>t>>m;
        long long l=low-1,r=1000000009,mid;
        while(r-l>1)
        {
            mid=(l+r)/2;
            o=1;
            long long q=a+(mid-1)*b;
            if(t<q)o=0;
            long long x=((mid*(mid-1)/2)-((low*(low-1)/2)))*b+(mid-low+1)*a,y=m*t;
            if(x>y)o=0;
            if(o==0)r=mid;
            else l=mid;
        }//148990 913922 18257
        if(l==low-1)cout<<-1;
        else  cout<<l;
        cout<<"\n";
    }
}


#include <bits/stdc++.h>

using namespace std;
int n;
long long o,ol,a,b,k,need,extra,mid,r,t,m,l,su,f;
int main()
{
    cin>>a>>b>>n;
    while (n--)
    {
        cin>>ol>>t>>m;
        r=1000000000;
        ol--;
        l=ol;
        while (r-l>1)
        {
            mid=(l+r)/2;
            o=1;
            if (t<a+mid*b) o=0;
            su=(mid-ol+1)*a;
            f=(((mid)*(mid+1))/2);
            if (ol>0) f-=(((ol-1)*(ol))/2);
            su+=f*b;
            if (su>m*t) o=0;
            if (o) l=mid;
            else r=mid;
        }
        o=1;
        if (t<a+l*b) o=0;
        /*su=(l-ol+1)*a+(b*(l+ol)*(l-ol+1))/2;*/
        if (su>m*t) o=0;
        if (o) cout<<l+1<<endl;
        else cout<<-1<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int a,b,n,low,m,t;
int main()
{
    cin>>a>>b>>n;
    bool o=1;
    while(n--)
    {
        cin>>low>>t>>m;
        int l=low-1,r=1000000009,mid;
        while(r-l>1)
        {
            mid=(l+r)/2;
            o=1;
            if(t<a+(mid-1)*b)o=0;
            long long x=(((mid*(mid-1))/2)-((low*(low-1))/2))*b+(mid-low+1)*a,y=m*t;
            if(x>y)o=0;
            if(o==0)r=mid;
            else l=mid;
        }
        if(l==low-1)cout<<-1;
        else  cout<<l;
        cout<<"\n";
    }
}


#include <bits/stdc++.h>

using namespace std;
long long a,b,n,low,m,t;
int main()
{
    cin>>a>>b>>n;
    bool o=1;
    while(n--)
    {
        cin>>low>>t>>m;
        int l=low-1,r=1000000009,mid;
        while(r-l>1)
        {
            mid=(l+r)/2;
            o=1;
            long long q=a+(mid-1)*b;
            if(t<q)o=0;
            long long x=(((mid*(mid-1))/2)-((low*(low-1))/2))*b+(mid-low+1)*a,y=m*t;
            if(x>y)o=0;
            if(o==0)r=mid;
            else l=mid;
        }
        if(l==low-1)cout<<-1;
        else  cout<<l;
        cout<<"\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a,b,l,t,m,n;
ll term(ll i){
	return a+(i-1)*b;
}
ll func(ll x){
return (x*(x-1))/2;
}
bool valid(ll r){
 if(term(r)>t)
	 return false;
 ll res=func(r)-func(l-1);
 res=a*(r-l+1)+res*b;
 return res>m*t?0:1;
}
int main(){
	cin>>a>>b>>n;
	while(n--){
		cin>>l>>t>>m;
		if(term(l)>t){
			cout<<-1<<endl; continue;
		}
		ll f=l,lt=m*t*10;
		ll mid;

		while(f<lt){
			mid=(f+lt)/2;
			if(valid(mid)){
				f=mid+1;
			}
			else {
				lt=mid;
			}
		}
		cout<<f-1<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a,b,l,t,m,n;
ll term(ll i){
	return a+(i-1)*b;
}
ll func(ll x){
return (x*(x-1))/2;
}
bool valid(ll r){
 if(term(r)>t)
	 return false;
 ll res=func(r)-func(l-1);
 res=a*(r-l+1)+res*b;
 return res>m*t?0:1;
}
int main(){
	cin>>a>>b>>n;
	while(n--){
		cin>>l>>t>>m;
		if(term(l)>t){
			cout<<-1<<endl; continue;
		}
		ll f=l,lt=m*t;
		ll mid;
		while(f<lt){
			mid=(f+lt)/2;
			if(valid(mid)){
				f=mid+1;
			}
			else {
				lt=mid;
			}
		//cout<<mid<<endl;
		}
		cout<<f-1<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a,b,l,t,m,n;
ll term(ll i){
	return a+(i-1)*b;
}
ll func(ll x){
return (x*(x-1))/2;
}
ll len(ll a){
int c=0;
	while(a){
		a/=10;
		c++;
	}
	return c;
}
bool valid(ll r){
 if(len(r)*len(b)>18||len(r-l)*a>18||term(r)>t)
	 return false;
 ll res=func(r)-func(l-1);
 res=a*(r-l+1)+res*b;
 return res>m*t?0:1;
}
int main(){
	cin>>a>>b>>n;
	while(n--){
		cin>>l>>t>>m;
		if(term(l)>t){
			cout<<-1<<endl; continue;
		}
		ll f=l,lt=m*t;
		ll mid;
		ll r=-1;
		while(f<lt){
			mid=(f+lt)/2;
			if(valid(mid)){
				r=max(r,mid);
				f=mid+1;
			}
			else {
				lt=mid;
			}
		//cout<<mid<<endl;
		}
		cout<<r<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a,b,l,t,m,n;
ll term(ll i){
	return a+(i-1)*b;
}
ll func(ll x){
return (x*(x-1))/2;
}
bool valid(ll r){
 if(term(r)>t)
	 return false;
 ll res=func(r)-func(l-1);
 res=a*(r-l+1)+res*b;
 return res>m*t?0:1;
}
int main(){
	cin>>a>>b>>n;
	while(n--){
		cin>>l>>t>>m;
		if(term(l)>t){
			cout<<-1<<endl; continue;
		}
		ll f=l,lt=m*t*10;
		ll mid;

		while(f<lt){
			mid=(f+lt)/2;
			if(valid(mid)){
				f=mid+1;
			}
			else {
				lt=mid;
			}
		}
		cout<<mid<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a,b,l,t,m,n;
ll term(ll i){
	return a+(i-1)*b;
}
ll func(ll x){
return x*(x-1)/2;
}
ll len(ll a){
int c=0;
	while(a){
		a/=10;
		c++;
	}
	return c;
}
bool valid(ll r){
 if(len(r)*len(b)>18||len(r-l)*a>18||term(r)>t)
	 return false;
 ll res=func(r)-func(l);
 res=a*(r-l+1)+res*b;
 return res>m*t?0:1;
}
int main(){
	cin>>a>>b>>n;
	while(n--){
		cin>>l>>t>>m;
		if(term(l)>t){
			cout<<-1<<endl; continue;
		}
		ll f=l,lt=m*t;
		ll mid;
		ll r=-1;
		while(f<=lt){
			mid=(f+lt)/2;
			if(valid(mid)){
				r=max(r,mid);
				f=mid+1;
			}
			else {
				lt=mid-1;
			}
			//cout<<mid<<endl;
		}
		cout<<r<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a,b,l,t,m,n;
ll term(ll i){
	return a+(i-1)*b;
}
ll func(ll x){
return (x*(x-1))/2;
}
ll len(ll a){
int c=0;
	while(a){
		a/=10;
		c++;
	}
	return c;
}
bool valid(ll r){
 if(len(r)*len(b)>18||len(r-l)*a>18||term(r)>t)
	 return false;
 ll res=func(r)-func(l-1);
 res=a*(r-l+1)+res*b;
 return res>m*t?0:1;
}
int main(){
	cin>>a>>b>>n;
	while(n--){
		cin>>l>>t>>m;
		if(term(l)>t){
			cout<<-1<<endl; continue;
		}
		ll f=l,lt=m*t;
		ll mid;
		while(f<lt){
			mid=(f+lt)/2;
			if(valid(mid)){
				f=mid+1;
			}
			else {
				lt=mid;
			}
		//cout<<mid<<endl;
		}
		cout<<f-1<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a,b,l,t,m,n;
ll term(ll i){
	return a+(i-1)*b;
}
ll func(ll x){
return (x*(x-1))/2;
}
bool valid(ll r){
 if(term(r)>t)
	 return false;
 ll res=func(r)-func(l-1);
 res=a*(r-l+1)+res*b;
 return res>m*t?0:1;
}
int main(){
	cin>>a>>b>>n;
	while(n--){
		cin>>l>>t>>m;
		if(term(l)>t){
			cout<<-1<<endl; continue;
		}
		ll f=l,lt=m*t*10;
		ll mid;
		ll r=-1;
		while(f<lt){
			mid=(f+lt)/2;
			if(valid(mid)){
				f=mid+1;
				r=max(mid,r);
			}
			else {
				lt=mid;
			}
		}
		cout<<r<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5e3 + 5;
long long A,B,N,L,T,M;
long long get_a(long long n)//得到第N项
{
	return A + (n - 1) * B;
}
long long check(long long R)//得到左端点到右端点的和
{
	return (get_a(L) + get_a(R)) * (R - L + 1) / 2;
}
int main()
{
	while(~scanf("%lld%lld%lld",&A,&B,&N))
	{
		while(N--)
		{
			scanf("%lld%lld%lld",&L,&T,&M);
			if(T < get_a(L))//减少T次1还不能将左端点的值变为0
			{
				printf("-1\n");continue;
			}
			else
			{
				/*long long l = L,r = (T - A) / B + 1,m = l + (r - l) / 2,key = T * M;//由S(r) <= T 求得上限为(T - A) / B + 1
				while(l < r)//找上届
				{
					if(check(m) <= key) l = m + 1;
					else r = m;
					m = l + (r - l) / 2;
				}
				if(check(m) <= key) printf("%d\n",m);
				else printf("%d\n",m - 1);*/
				int ans = -1;
				for(int i = L; i <= (T - A) / B + 1; i++)
				{
					if(check(i) > T * M) break;
					else ans = i;
				}
				printf("%d\n",ans);
			}
		}
	}
	return 0;
}
/*
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
1 5 2
1 5 10
2 7 4
*/


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5e3 + 5;
long long A,B,N,L,T,M;
long long get_a(long long n)//得到第N项
{
	return A + (n - 1) * B;
}
long long check(long long R)//得到左端点到右端点的和
{
	return (get_a(L) + get_a(R)) * (R - L + 1) / 2;
}
int main()
{
	while(~scanf("%lld%lld%lld",&A,&B,&N))
	{
		while(N--)
		{
			scanf("%lld%lld%lld",&L,&T,&M);
			if(T < get_a(L))//减少T次1还不能将左端点的值变为0
			{
				printf("-1\n");continue;
			}
			else
			{
				long long l = L,r = (T - A) / B + 1,m = l + (r - l) / 2,key = T * M;//由S(r) <= T 求得上限为(T - A) / B + 1
				while(l < r)
				{
					if(check(m) <= key) l = m + 1;
					else r = m;
					m = l + (r - l) / 2;
				}
				if(check(m) <= key) printf("%d\n",m);
				else printf("%d\n",m - 1);
			}
		}
	}
	return 0;
}
/*
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
1 5 2
1 5 10
2 7 4
*/


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5e3 + 5;
int A,B,N,L,T,M;
int get_a(int n)//得到第N项
{
	return A + (n - 1) * B;
}
int check(int R)//得到左端点到右端点的和
{
	return (get_a(L) + get_a(R)) * (R - L + 1) / 2;
}
int main()
{
	while(~scanf("%d%d%d",&A,&B,&N))
	{
		while(N--)
		{
			scanf("%d%d%d",&L,&T,&M);
			if(T < get_a(L))//减少T次1还不能将左端点的值变为0
			{
				printf("-1\n");continue;
			}
			else
			{
				int ans = -1;
				int l = L,r = (T - A) / B + 1,m = l + (r - l) / 2,key = T * M;//由S(r) <= T 求得上限为(T - A) / B + 1
				while(l < r)
				{
					if(check(m) <= key) l = m + 1;
					else r = m;
					m = l + (r - l) / 2;
				}
				if(check(m) <= key) printf("%d\n",m);
				else printf("%d\n",m - 1);
			}
		}
	}
	return 0;
}
/*
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
1 5 2
1 5 10
2 7 4
*/


#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <climits>
#include "stdio.h"
#include <utility>
#define forin(i,n)  for(int i=0;i<n;++i)
using namespace std;
#define ll long long

int main() {
	ll l, t, m;
	ll a, b, c;
	ll left, mid, right;
	cin >> a >> b >> c;
	forin(i,c)
	{
		bool fail = false;
		cin >> l >> t >> m;
		left = l;
		right = (t - a) / b + 1;
		while (1) {
			mid = left + (right - left + 1) / 2;
			if ((mid - l + 1) * (a + (l - 1) * b + a + (mid - 1) * b) / 2<= t * m) {
				left = mid;
			} else {
				right = mid - 1;
			}
			if (right < left) {
				fail = true;
				break;
			}
			if (mid == left && left == right)
				break;
		}
		if (!fail)
			cout << mid;
		else
			cout << -1;

		cout << endl;

	}

}


#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <climits>
#include "stdio.h"
#include <utility>
#define forin(i,n)  for(int i=0;i<n;++i)
using namespace std;
#define ll long long

int main() {
	ll l,t,m;
	ll a,b,c;
	ll left,mid,right;
    cin>>a>>b>>c;
    forin(i,c){
        bool fail=false;
        cin>>l>>t>>m;
        left=l;
        right=left+t*m-1;
        while(1){
            mid=left+(right-left)/2;
            if(mid <= (t-a)/b+1 && (mid-l+1)*(a+(l-1)*b+a+(mid-1)*b)/2<=t*m) {
                left=mid;
            }else
                right=mid-1;

            if(right<left){
                fail=true;
                break;
            }
            if(mid==left)
                break;
        }
        if(!fail)
            cout<<mid;
        else
            cout<<-1;

        cout<<endl;

    }

}


#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <climits>
#include "stdio.h"
#include <utility>
#define forin(i,n)  for(int i=0;i<n;++i)
using namespace std;
#define ll long long

int main() {
ll l,t,m;
ll a,b,c;
ll left,mid,right;

    cin>>a>>b>>c;
    forin(i,c){
        bool fail=false;
        cin>>l>>t>>m;
        left=l;
        right=left+t*m-1;
        while(1){
            mid=left+(right-left)/2;
            if((mid-l+1)*(a+(l-1)*b+a+(mid-1)*b)/2<=t*m) {
                left=mid;
            }else
                right=mid-1;

            if(right<left){
                fail=true;
                break;
            }
            if(mid==left)
                break;
        }
        if(!fail)
            cout<<mid;
        else
            cout<<-1;

        cout<<endl;

    }

}


//**KEEP IT SHORT AND SIMPLE**

#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
typedef set <long long> sll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef priority_queue<long long, vector<long long>, greater<long long> > minPq;
double pi = 2 * acos(0.0);
int OO = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
ll Summation(ll x)
{
    return (x * (x + 1)) / 2;
}
int main()
{
    IO
    ll a, b, n, l, t, m, Start, End, Mid, r, ans, sum, tempm;
    cin >> a >> b >> n;
    while(n--)
    {
        cin >> l >> t >> m;
        Start = l;
        End = 1e8;
        ans = -1;
        while(Start <= End)
        {
            Mid = (Start + End) >> 1;
            r = a + b * (Mid - 1);
            sum = Mid * a + Summation(Mid - 1) - (l > 1 ? (l - 1) * a + b * Summation(l - 2): 0);
//            cout << Mid << ' ' << r << ' ' << sum << NL;
            tempm = min(m, Mid - l + 1);
            if(r > t || ceil((sum * 1.0) / tempm) > t)
                End = Mid - 1;
            else
            {
                Start = Mid + 1;
                ans = Mid;
            }
        }
        cout << ans << NL;
    }
    return 0;

}


//**KEEP IT SHORT AND SIMPLE**

#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
typedef set <long long> sll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef priority_queue<long long, vector<long long>, greater<long long> > minPq;
double pi = 2 * acos(0.0);
int OO = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
ll Summation(ll x)
{
    return (x * (x + 1)) / 2;
}
int main()
{
    IO
    ll a, b, n, l, t, m, Start, End, Mid, r, ans, sum, tempm;
    cin >> a >> b >> n;
    while(n--)
    {
        cin >> l >> t >> m;
        Start = l;
        End = 1e8;
        ans = -1;
        while(Start <= End)
        {
            Mid = (Start + End) >> 1;
            r = a + b * (Mid - 1);
            sum = Mid * a + Summation(Mid - 1) - (l > 1 ? (l - 1) * a + b * Summation(l - 2): 0);
//            cout << Mid << ' ' << r << ' ' << sum << NL;
            tempm = min(m, Mid - l + 1);
            if(r > t || sum > t * tempm)
                End = Mid - 1;
            else
            {
                Start = Mid + 1;
                ans = Mid;
            }
        }
        cout << ans << NL;
    }
    return 0;

}


//**KEEP IT SHORT AND SIMPLE**

#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
typedef set <long long> sll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef priority_queue<long long, vector<long long>, greater<long long> > minPq;
double pi = 2 * acos(0.0);
int OO = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
ll Summation(ll x)
{
    return (x * (x + 1)) / 2;
}
int main()
{
    IO
    ll a, b, n, l, t, m, Start, End, Mid, r, ans, sum, tempm;
    cin >> a >> b >> n;
    while(n--)
    {
        cin >> l >> t >> m;
        Start = l;
        End = 1e7;
        ans = -1;
        if(a + b * (l - 1) > t)
        {
            cout << -1 << NL;
            continue;
        }
        while(Start <= End)
        {
            Mid = (Start + End) >> 1;
            r = a + b * (Mid - 1);
            sum = Mid * a + Summation(Mid - 1) - (l > 1 ? (l - 1) * a + b * Summation(l - 2): 0);
            if(r <= t && sum <= m * t)
            {
                ans = Mid;
                Start = Mid + 1;
            }
            else
                End = Mid - 1;
        }
        cout << ans << NL;
    }
    return 0;

}