#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef
tree < int, null_type ,less<int>,
rb_tree_tag,
tree_order_statistics_node_update > ordered_set;
#include <string>
#include <vector>
#define ll           long long
#define vint         vector<int>
#define vll          vector<ll>
#define pint         pair<int,int>
#define pll          pair<ll,ll>
#define mint         map<int,int>
#define mll         map<ll,ll>
#define si(a)        scanf("%d",&a)
#define sc(a)        scanf("%c",&a)
#define sii(a,p)     scanf("%d %d",&a,&p)
#define siii(a,p,c)  scanf("%d %d %d", &a, &p,&c)
#define sl(a)        scanf("%lld",&a)
#define sll(a,p)     scanf("%lld %lld",&a, &p)
#define slll(a,p,c)  scanf("%lld %lld %lld",&a, &p, &c)
#define sqr(a)       a*a;
#define pf           printf
#define pb           push_back
#define pfi(a)       printf("%d\n",a)
#define pfis(a)      printf("%d ",a)
#define pfii(a,p)    printf("%d %d\n",a,p)
#define pfiii(a,p,c) printf("%d %d %d\n",a,p,c)
#define pfl(a)       printf("%lld\n",a);
#define pfll(a,p)    printf("%lld %lld\n",a,p)
#define pflll(a,p,c) printf("%lld %lld %lld\n",a,p,c)
#define mem(a,p)     memset(a, p, sizeof(a));
#define max3(a,p,c)  max(max(a, p), c);
#define min3(a,p,c)  min(min(a, p), c);
#define for0(i,n)    for(int i = 0; i < n;  i++)
#define for1(i,n)    for(int i = 1; i <= n;  i++)
#define rfor0(i,n)   for(int i = n - 1; i>=0; i--)
#define rfor1(i,n)   for(int i = n; i>=1; i--)
#define pi           acos(-1.0)
#define in           freopen("input.txt", "r", stdin);
#define out          freopen("output.txt", "w", stdout);
#define cs(t)        printf("Case %d: ",++t);
#define mp           make_pair
#define all(sss)     sss.begin(),sss.end()
#define X            first
#define Y            second
#define re           register int
#define ak           *
#define err          1e-5
#define pi           acos(-1.0)
#define fast         ios_base::sync_with_stdio(0);cin.tie(0);
const int maxn = 5000005, mod = 1e9 + 7;
const int MAX = 100000000;  // 10^8
const int LMT =     10000;  // sqrt(MAX)
ll    sum, cnt, ans, ans2,flag, maxi = 0, mini = LLONG_MAX, pos, len;
//ll cnta[maxn];
ll  n, m, t, tc, ind, d;
//int tm;
int solve(vint v, int a, int tm)
{
    int tem = 0, c = 0;
    for0(i, n)
    {
            int x = *(v.begin());
            if(tm < x )
            {
                tem = c;
            }
            if(v.size() == 0)
            {
                return tem;
            }

            if(t <= tm || tm > x )
            {
                return tem;
            }
            else
            {
                tm += a;
                v.erase(v.begin() + 0);
                c++;
                if(v.size() == 0 )
                {
                    if(tm <= t) return c;
                    else
                    return  tem;
                }
                //cout << c << endl;
            }

    }
}
int main()
{
    si(tc);
    while(tc--)
    {
        int a,b;
        siii(n,t,a);
        si(b);
        int ar[n + 5], x, y, tm = 0;
        vint zero, one;
        for0(i, n) si(ar[i]);
        for0(i, n)
        {
            si(x);
            if(ar[i]) one.pb(x);
            else zero.pb(x);
        }
        if(one.size())
        sort(all(one));
        if(zero.size())
        sort(all(zero));
        ans = cnt = flag = 0;

        if(zero.size() * a + one.size() * b <= t)
        {
            cout << n << endl;
            continue;
        }
        for0(i, n)
        {
            if(zero.size() == 0 || one.size() == 0)
            {
                flag = 1;
                break;
            }
            x = *(zero.begin());
            y = *(one.begin());
            //cout << "x = " << x <<" y = "<< y<< endl;
            //cout << "time = " << tm << endl;
            if(tm < x && tm < y)
            {
                ans = cnt;
            }
            if(zero.size() == 0 || one.size() == 0)
            {
                flag = 1;
                break;
            }

            if(t <= tm || tm > x || tm > y)
                break;
            if(x <= y)
            {
                tm += a;
                zero.erase(zero.begin() + 0);
                cnt++;
                if(zero.size() == 0 && y > tm)
                {
                    flag = 1;
                    ans = cnt;
                    break;
                }
            }
            else if(x > y && tm + a <= y)
            {
                 tm += a;
                 zero.erase(zero.begin() + 0);
                cnt++;
                //cout << "cnt = " << cnt << endl;
                if(zero.size() == 0 && y > tm)
                {
                    flag = 1;
                    ans = cnt;
                    break;
                }
            }
            else
            {
                tm += b;
                one.erase(one.begin() + 0);
                cnt++;
                if(one.size() == 0 && x > tm)
                {
                    flag = 1;
                    ans = cnt;
                    break;
                }
            }
           // for(auto i: zero) cout << i << endl;
           // cout << endl;
           // for(auto i: one) cout << i << endl;

        }
        if(flag)
        {

            if(zero.size())
                ans += solve(zero, a, tm);
            if(one.size())
                ans  += solve(one, b, tm);

        }

        cout << ans << endl;

    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef
tree < int, null_type ,less<int>,
rb_tree_tag,
tree_order_statistics_node_update > ordered_set;
#include <string>
#include <vector>
#define ll           long long
#define vint         vector<int>
#define vll          vector<ll>
#define pint         pair<int,int>
#define pll          pair<ll,ll>
#define mint         map<int,int>
#define mll         map<ll,ll>
#define si(a)        scanf("%d",&a)
#define sc(a)        scanf("%c",&a)
#define sii(a,p)     scanf("%d %d",&a,&p)
#define siii(a,p,c)  scanf("%d %d %d", &a, &p,&c)
#define sl(a)        scanf("%lld",&a)
#define sll(a,p)     scanf("%lld %lld",&a, &p)
#define slll(a,p,c)  scanf("%lld %lld %lld",&a, &p, &c)
#define sqr(a)       a*a;
#define pf           printf
#define pb           push_back
#define pfi(a)       printf("%d\n",a)
#define pfis(a)      printf("%d ",a)
#define pfii(a,p)    printf("%d %d\n",a,p)
#define pfiii(a,p,c) printf("%d %d %d\n",a,p,c)
#define pfl(a)       printf("%lld\n",a);
#define pfll(a,p)    printf("%lld %lld\n",a,p)
#define pflll(a,p,c) printf("%lld %lld %lld\n",a,p,c)
#define mem(a,p)     memset(a, p, sizeof(a));
#define max3(a,p,c)  max(max(a, p), c);
#define min3(a,p,c)  min(min(a, p), c);
#define for0(i,n)    for(int i = 0; i < n;  i++)
#define for1(i,n)    for(int i = 1; i <= n;  i++)
#define rfor0(i,n)   for(int i = n - 1; i>=0; i--)
#define rfor1(i,n)   for(int i = n; i>=1; i--)
#define pi           acos(-1.0)
#define in           freopen("input.txt", "r", stdin);
#define out          freopen("output.txt", "w", stdout);
#define cs(t)        printf("Case %d: ",++t);
#define mp           make_pair
#define all(sss)     sss.begin(),sss.end()
#define X            first
#define Y            second
#define re           register int
#define ak           *
#define err          1e-5
#define pi           acos(-1.0)
#define fast         ios_base::sync_with_stdio(0);cin.tie(0);
const int maxn = 5000005, mod = 1e9 + 7;
const int MAX = 100000000;  // 10^8
const int LMT =     10000;  // sqrt(MAX)
ll    sum, cnt, ans, ans2,flag, maxi = 0, mini = LLONG_MAX, pos, len;
//ll cnta[maxn];
ll  n, m, t, tc, ind, d;
//int tm;
ll solve(vll v, ll a, ll tm)
{
    ll tem = 0, c = 0;
    for0(i, n)
    {

            int x = *(v.begin());
            if(tm < x )
            {
                tem = c;
            }
            if(v.size() == 0)
            {
                return tem;
            }

            if(t <= tm)
            {
                return tem;
            }
            else
            {
                tm += a;
                v.erase(v.begin() + 0);
                c++;
                if(v.size() == 0 )
                {
                    if(tm <= t) return c;
                    else
                    return  tem;
                }
                //cout << c << endl;
            }

    }
}
int main()
{
    sl(tc);
    while(tc--)
    {
        ll a,b, one= 0, zero = 0;
        ans = 0;
        slll(n,t,a);
        sl(b);
        pll pr[n + 2];
        for0(i, n)
        {
            sl(pr[i].Y);
            if(pr[i].Y) one++;
            else zero++;
        }
        for0(i, n) sl(pr[i].X);
        sort(pr, pr + n);
        pr[n] = mp(t + 1, -1);

        ll time = 0;
        for0(i, n + 1)
        {
            if(time <= pr[i].X - 1)
            {
                ll res = pr[i].X - 1 - time;
                if(zero * a > res)
                {
                    ans = max(ans, i + res / a);
                }
                else
                {
                    ans = max(ans , i + zero + min(one, (res - zero * a)/b));
                }
            }
            if(pr[i].Y) time += b, one--;
            else time += a, zero--;
        }
        cout << ans << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef
tree < int, null_type ,less<int>,
rb_tree_tag,
tree_order_statistics_node_update > ordered_set;
#include <string>
#include <vector>
#define ll           long long
#define vint         vector<int>
#define vll          vector<ll>
#define pint         pair<int,int>
#define pll          pair<ll,ll>
#define mint         map<int,int>
#define mll         map<ll,ll>
#define si(a)        scanf("%d",&a)
#define sc(a)        scanf("%c",&a)
#define sii(a,p)     scanf("%d %d",&a,&p)
#define siii(a,p,c)  scanf("%d %d %d", &a, &p,&c)
#define sl(a)        scanf("%lld",&a)
#define sll(a,p)     scanf("%lld %lld",&a, &p)
#define slll(a,p,c)  scanf("%lld %lld %lld",&a, &p, &c)
#define sqr(a)       a*a;
#define pf           printf
#define pb           push_back
#define pfi(a)       printf("%d\n",a)
#define pfis(a)      printf("%d ",a)
#define pfii(a,p)    printf("%d %d\n",a,p)
#define pfiii(a,p,c) printf("%d %d %d\n",a,p,c)
#define pfl(a)       printf("%lld\n",a);
#define pfll(a,p)    printf("%lld %lld\n",a,p)
#define pflll(a,p,c) printf("%lld %lld %lld\n",a,p,c)
#define mem(a,p)     memset(a, p, sizeof(a));
#define max3(a,p,c)  max(max(a, p), c);
#define min3(a,p,c)  min(min(a, p), c);
#define for0(i,n)    for(int i = 0; i < n;  i++)
#define for1(i,n)    for(int i = 1; i <= n;  i++)
#define rfor0(i,n)   for(int i = n - 1; i>=0; i--)
#define rfor1(i,n)   for(int i = n; i>=1; i--)
#define pi           acos(-1.0)
#define in           freopen("input.txt", "r", stdin);
#define out          freopen("output.txt", "w", stdout);
#define cs(t)        printf("Case %d: ",++t);
#define mp           make_pair
#define all(sss)     sss.begin(),sss.end()
#define X            first
#define Y            second
#define re           register int
#define ak           *
#define err          1e-5
#define pi           acos(-1.0)
#define fast         ios_base::sync_with_stdio(0);cin.tie(0);
const int maxn = 5000005, mod = 1e9 + 7;
const int MAX = 100000000;  // 10^8
const int LMT =     10000;  // sqrt(MAX)
ll    sum, cnt, ans, ans2,flag, maxi = 0, mini = LLONG_MAX, pos, len;
//ll cnta[maxn];
ll  n, m, t, tc, ind, d;
//int tm;
int solve(vint v, int a, int tm)
{
    int tem = 0, c = 0;
    for0(i, n)
    {
            int x = *(v.begin());
            if(tm < x )
            {
                tem = c;
            }
            if(v.size() == 0)
            {
                return tem;
            }

            if(t <= tm || tm > x )
            {
                return tem;
            }
            else
            {
                tm += a;
                v.erase(v.begin() + 0);
                c++;
                if(v.size() == 0 )
                {
                    if(tm <= t) return c;
                    else
                    return  tem;
                }
                //cout << c << endl;
            }

    }
}
int main()
{
    si(tc);
    while(tc--)
    {
        int a,b;
        siii(n,t,a);
        si(b);
        int ar[n], x, y, tm = 0;
        vint zero, one;
        for0(i, n) si(ar[i]);
        for0(i, n)
        {
            si(x);
            if(ar[i]) one.pb(x);
            else zero.pb(x);
        }
        sort(all(one));
        sort(all(zero));
        ans = cnt = flag = 0;

        if(zero.size() * a + one.size() * b <= t)
        {
            cout << n << endl;
            continue;
        }
        for0(i, n)
        {

            x = *(zero.begin());
            y = *(one.begin());
            //cout << "x = " << x <<" y = "<< y<< endl;
            //cout << "time = " << tm << endl;
            if(tm < x && tm < y)
            {
                ans = cnt;
            }
            if(zero.size() == 0 || one.size() == 0)
            {
                flag = 1;
                break;
            }

            if(t <= tm || tm > x || tm > y)
                break;
            if(x <= y)
            {
                tm += a;
                zero.erase(zero.begin() + 0);
                cnt++;
                if(zero.size() == 0 && y > tm)
                {
                    flag = 1;
                    ans = cnt;
                    break;
                }
            }
            else if(x > y && tm + a <= y)
            {
                 tm += a;
                 zero.erase(zero.begin() + 0);
                cnt++;
                //cout << "cnt = " << cnt << endl;
                if(zero.size() == 0 && y > tm)
                {
                    flag = 1;
                    ans = cnt;
                    break;
                }
            }
            else
            {
                tm += b;
                one.erase(one.begin() + 0);
                cnt++;
                if(one.size() == 0 && x > tm)
                {
                    flag = 1;
                    ans = cnt;
                    break;
                }
            }
           // for(auto i: zero) cout << i << endl;
           // cout << endl;
           // for(auto i: one) cout << i << endl;

        }
        if(flag)
        {

            if(zero.size())
                ans += solve(zero, a, tm);
            if(one.size())
                ans  += solve(one, b, tm);

        }

        cout << ans << endl;

    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef
tree < int, null_type ,less<int>,
rb_tree_tag,
tree_order_statistics_node_update > ordered_set;
#include <string>
#include <vector>
#define ll           long long
#define vint         vector<int>
#define vll          vector<ll>
#define pint         pair<int,int>
#define pll          pair<ll,ll>
#define mint         map<int,int>
#define mll         map<ll,ll>
#define si(a)        scanf("%d",&a)
#define sc(a)        scanf("%c",&a)
#define sii(a,p)     scanf("%d %d",&a,&p)
#define siii(a,p,c)  scanf("%d %d %d", &a, &p,&c)
#define sl(a)        scanf("%lld",&a)
#define sll(a,p)     scanf("%lld %lld",&a, &p)
#define slll(a,p,c)  scanf("%lld %lld %lld",&a, &p, &c)
#define sqr(a)       a*a;
#define pf           printf
#define pb           push_back
#define pfi(a)       printf("%d\n",a)
#define pfis(a)      printf("%d ",a)
#define pfii(a,p)    printf("%d %d\n",a,p)
#define pfiii(a,p,c) printf("%d %d %d\n",a,p,c)
#define pfl(a)       printf("%lld\n",a);
#define pfll(a,p)    printf("%lld %lld\n",a,p)
#define pflll(a,p,c) printf("%lld %lld %lld\n",a,p,c)
#define mem(a,p)     memset(a, p, sizeof(a));
#define max3(a,p,c)  max(max(a, p), c);
#define min3(a,p,c)  min(min(a, p), c);
#define for0(i,n)    for(int i = 0; i < n;  i++)
#define for1(i,n)    for(int i = 1; i <= n;  i++)
#define rfor0(i,n)   for(int i = n - 1; i>=0; i--)
#define rfor1(i,n)   for(int i = n; i>=1; i--)
#define pi           acos(-1.0)
#define in           freopen("input.txt", "r", stdin);
#define out          freopen("output.txt", "w", stdout);
#define cs(t)        printf("Case %d: ",++t);
#define mp           make_pair
#define all(sss)     sss.begin(),sss.end()
#define X            first
#define Y            second
#define re           register int
#define ak           *
#define err          1e-5
#define pi           acos(-1.0)
#define fast         ios_base::sync_with_stdio(0);cin.tie(0);
const int maxn = 5000005, mod = 1e9 + 7;
const int MAX = 100000000;  // 10^8
const int LMT =     10000;  // sqrt(MAX)
ll    sum, cnt, ans, ans2,flag, maxi = 0, mini = LLONG_MAX, pos, len;
//ll cnta[maxn];
ll  n, m, t, tc, ind, d;
//int tm;
int solve(vint v, int a, int tm)
{
    int tem = 0, c = 0;
    for0(i, n)
    {
            int x = *(v.begin());
            if(tm < x )
            {
                tem = c;
            }
            if(v.size() == 0)
            {
                return tem;
            }

            if(t <= tm || tm > x )
            {
                return tem;
            }
            else
            {
                tm += a;
                v.erase(v.begin() + 0);
                c++;
                if(v.size() == 0 )
                {
                    if(tm <= t) return c;
                    else
                    return  tem;
                }
                //cout << c << endl;
            }

    }
}
int main()
{
    si(tc);
    while(tc--)
    {
        int a,b;
        siii(n,t,a);
        si(b);
        int ar[n + 5], x, y, tm = 0;
        vint zero, one;
        for0(i, n) si(ar[i]);
        for0(i, n)
        {
            si(x);
            if(ar[i]) one.pb(x);
            else zero.pb(x);
        }

        sort(all(one));
        sort(all(zero));
        ans = cnt = flag = 0;

        if(zero.size() * a + one.size() * b <= t)
        {
            cout << n << endl;
            continue;
        }

        for0(i, n)
        {

            if(zero.size())
            x = *(zero.begin());
            else x = 0;
            if(one.size())
            y = *(one.begin());
            else y = 0;
            //cout << "x = " << x <<" y = "<< y<< endl;
            //cout << "time = " << tm << endl;
            if(tm < x && tm < y)
            {
                ans = cnt;
            }
            if(zero.size() == 0 || one.size() == 0)
            {
                flag = 1;
                break;
            }

            if(t <= tm || tm > x || tm > y)
                break;
            if(x <= y)
            {
                tm += a;
                zero.erase(zero.begin() + 0);
                cnt++;
                if(zero.size() == 0 && y > tm)
                {
                    flag = 1;
                    ans = cnt;
                    break;
                }
            }
            else if(x > y && tm + a <= y)
            {
                 tm += a;
                 zero.erase(zero.begin() + 0);
                cnt++;
                //cout << "cnt = " << cnt << endl;
                if(zero.size() == 0 && y > tm)
                {
                    flag = 1;
                    ans = cnt;
                    break;
                }
            }
            else
            {
                tm += b;
                one.erase(one.begin() + 0);
                cnt++;
                if(one.size() == 0 && x > tm)
                {
                    flag = 1;
                    ans = cnt;
                    break;
                }
            }
           // for(auto i: zero) cout << i << endl;
           // cout << endl;
           // for(auto i: one) cout << i << endl;

        }
        if(flag)
        {

            if(zero.size())
                ans += solve(zero, a, tm);
            if(one.size())
                ans  += solve(one, b, tm);

        }

        cout << ans << endl;

    }
    return 0;
}


#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;i++)
#define repd(i,a,b) for(register int i=a;i>=b;i--)
#define reps(s) for(int i=head[s];i;i=e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
#define eps 1e-8
using namespace std;
const int MAX_N=2e5+5;
typedef long long ll;
struct node{
	int type;
	ll ti;
}p[MAX_N];
bool cmp(node a1,node a2)
{
	if(a1.ti!=a2.ti)	return a1.ti<a2.ti;
	return a1.type<a2.type;
}
int n;
ll t,a,b;
ll cnt0,cnt1;
int main()
{
	int T;
	si(T);
	while(T--)
	{
		cnt0=cnt1=0;
		si(n),sl(t),sl(a),sl(b);
		repi(i,1,n){
			si(p[i].type);
			if(p[i].type)	cnt1++;
			else cnt0++;
		}
		repi(i,1,n) sl(p[i].ti);
		if(t>=(cnt0*a+cnt1*b)){
			printf("%d\n",n);
			continue;
		}
		sort(p+1,p+1+n,cmp);
		ll ans=0;
		ll required=0;
		repi(i,1,n){
			if(i!=1&&p[i-1].type==0)	required+=a,cnt0--;
			else if(i!=1&&p[i-1].type==1)	required+=b,cnt1--;
			if(p[i].ti==p[i-1].ti) continue;
			if((p[i].ti-1)<required)	continue;
			ll res=1ll*i-1;
			ll rem=p[i].ti-1-required;
			ll n0=rem/a;
			rem-=min(n0,cnt0)*a,res+=min(n0,cnt0);
			ll n1=rem/b;
			res+=min(n1,cnt1);
			ans=max(ans,res);
		}
		printf("%lld\n",ans);
	}
	return 0;
}


#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

enum{N=200023};
struct sth{
	ll x,y;
	bool operator<(const sth&e)const{
		return x<e.x;
	}
}d[N];

int main(){
	int TIM=ci();
	while( TIM-- ){
		ll n=ci(), T=ci(), a=ci(), b=ci();
		ll cnt0= 0,cnt1=0;
		rep(i,1,n) if( (d[i].y=ci())==0 ) cnt0++;
		cnt1=n-cnt0;
		rep(i,1,n) d[i].x=ci();
		if( T>=a*cnt0+b*(n-cnt0) ){
			printf("%lld\n",n);
			continue;
		}
		sort(d+1,d+n+1);
		ll ans=0, now=0;
		d[n+1].x=T+1;
		rep(i,1,n){
			ll tmp= d[i].x-1;
			if( tmp>=now &&d[i].x!=d[i+1].x){
				ll t= min(cnt0,(tmp-now)/a);
				tmp-= t*a+now;
//				printf("tmp %lld-%lld t %lld = %lld\n",d[i].x-1,now,t,i-1+t+tmp/b);
				ans= max(ans,i-1+t+min(tmp/b,cnt1));
			}
			if( d[i].y==0 ) cnt0--, now+=a;
			else now+=b,cnt1--;
		}
		printf("%lld\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;i++)
#define repd(i,a,b) for(register int i=a;i>=b;i--)
#define reps(s) for(int i=head[s];i;i=e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
#define eps 1e-8
using namespace std;
const int MAX_N=2e5+5;
typedef long long ll;
struct node{
	int type;
	ll ti;
}p[MAX_N];
bool cmp(node a1,node a2)
{
	if(a1.ti!=a2.ti)	return a1.ti<a2.ti;
	return a1.type<a2.type;
}
int n;
ll t,a,b;
ll cnt0,cnt1;
int main()
{
	int T;
	si(T);
	while(T--)
	{
		cnt0=cnt1=0;
		si(n),sl(t),sl(a),sl(b);
		repi(i,1,n){
			si(p[i].type);
			if(p[i].type)	cnt1++;
			else cnt0++;
		}
		repi(i,1,n) sl(p[i].ti);
		if(t>=(cnt0*a+cnt1*b)){
			printf("%d\n",n);
	//		int ans=n;
	//		pr(ans);
			continue;
		}
		sort(p+1,p+1+n,cmp);
		p[n+1].ti=t+1;
		ll ans=0;
		ll required=0;
		repi(i,1,n){
			if(i!=1&&p[i-1].type==0)	required+=a,cnt0--;
			else if(i!=1&&p[i-1].type==1)	required+=b,cnt1--;
		//	if(p[i].ti==p[i+1].ti) continue;
			if((p[i].ti-1)<required)	continue;
			ll res=1ll*i-1;
			ll rem=p[i].ti-1-required;
			ll n0=rem/a;
			rem-=min(n0,cnt0)*a,res+=min(n0,cnt0);
			ll n1=rem/b;
			res+=min(n1,cnt1);
			ans=max(ans,res);
		}
		printf("%lld\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;i++)
#define repd(i,a,b) for(register int i=a;i>=b;i--)
#define reps(s) for(int i=head[s];i;i=e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
#define eps 1e-8
using namespace std;
const int MAX_N=2e5+5;
typedef long long ll;
struct node{
	int type,ti;
}p[MAX_N];
bool cmp(node a1,node a2)
{
	if(a1.ti!=a2.ti)	return a1.ti<a2.ti;
	return a1.type<a2.type;
}
int n,t,a,b;
int cnt0,cnt1;
int main()
{
	int T;
	si(T);
	while(T--)
	{
		cnt0=cnt1=0;
		si(n),si(t),si(a),si(b);
		repi(i,1,n){
			si(p[i].type);
			if(p[i].type)	cnt1++;
			else cnt0++;
		}
		repi(i,1,n) si(p[i].ti);
		if(t>=(cnt0*a+cnt1*b)){
			printf("%d\n",n);
	//		int ans=n;
	//		pr(ans);
			continue;
		}
		sort(p+1,p+1+n,cmp);
		p[n+1].ti=t+1;
		int ans=0;
		ll required=0;
		repi(i,1,n){
			if(i!=1&&p[i-1].type==0)	required+=1ll*a,cnt0--;
			else if(i!=1&&p[i-1].type==1)	required+=1ll*b,cnt1--;
			if(p[i].ti==p[i+1].ti) continue;
			if(1ll*(p[i].ti-1)<required)	continue;
			int res=i-1,rem=p[i].ti-1-required;
			int n0=rem/a;
			rem-=min(n0,cnt0)*a,res+=min(n0,cnt0);
			int n1=rem/b;
			rem-=min(n1,cnt1)*b,res+=min(n1,cnt1);
//			pr(res),pr(i);
			ans=max(ans,res);
		}
		printf("%d\n",ans);
	//	pr(ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;i++)
#define repd(i,a,b) for(register int i=a;i>=b;i--)
#define reps(s) for(int i=head[s];i;i=e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
#define eps 1e-8
using namespace std;
const int MAX_N=2e5+5;
typedef long long ll;
struct node{
	int type,ti;
}p[MAX_N];
bool cmp(node a1,node a2)
{
	if(a1.ti!=a2.ti)	return a1.ti<a2.ti;
	return a1.type<a2.type;
}
int n,t,a,b;
int cnt0,cnt1;
int main()
{
	int T;
	si(T);
	while(T--)
	{
		cnt0=cnt1=0;
		si(n),si(t),si(a),si(b);
		repi(i,1,n){
			si(p[i].type);
			if(p[i].type)	cnt1++;
			else cnt0++;
		}
		repi(i,1,n) si(p[i].ti);
		if(1ll*t>=(1ll*cnt0*a+1ll*cnt1*b)){
			printf("%d\n",n);
	//		int ans=n;
	//		pr(ans);
			continue;
		}
		sort(p+1,p+1+n,cmp);
		p[n+1].ti=t+1;
		ll ans=0;
		ll required=0;
		repi(i,1,n){
			if(i!=1&&p[i-1].type==0)	required+=1ll*a,cnt0--;
			else if(i!=1&&p[i-1].type==1)	required+=1ll*b,cnt1--;
			if(p[i].ti==p[i+1].ti) continue;
			if(1ll*(p[i].ti-1)<required)	continue;
			ll res=1ll*i-1;
			ll rem=p[i].ti-1-required;
			ll n0=rem/a;
			rem-=min(n0,1ll*cnt0)*a,res+=min(n0,1ll*cnt0);
			ll n1=rem/b;
			rem-=min(n1,1ll*cnt1)*b,res+=min(n1,1ll*cnt1);
//			pr(res),pr(i);
			ans=max(ans,res);
		}
		printf("%d\n",ans);
	//	pr(ans);
	}
	return 0;
}


#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

enum{N=200023};
struct sth{
	ll x,y;
	bool operator<(const sth&e)const{
		return x<e.x;
	}
}d[N];

int main(){
	int TIM=ci();
	while( TIM-- ){
		ll n=ci(), T=ci(), a=ci(), b=ci();
		ll cnt0= 0,cnt1=0;
		rep(i,1,n) if( (d[i].y=ci())==0 ) cnt0++;
		cnt1=n-cnt0;
		rep(i,1,n) d[i].x=ci();
		if( T>=a*cnt0+b*(n-cnt0) ){
			printf("%lld\n",n);
			continue;
		}
		sort(d+1,d+n+1);
		ll ans=0, now=0;
		rep(i,1,n){
			ll tmp= d[i].x-1;
			if( tmp>=now &&d[i].x!=d[i+1].x){
				ll t= min(cnt0,(tmp-now)/a);
				tmp-= t*a+now;
//				printf("tmp %lld-%lld t %lld = %lld\n",d[i].x-1,now,t,i-1+t+tmp/b);
				ans= max(ans,i-1+t+min(tmp/b,cnt1));
			}
			if( d[i].y==0 ) cnt0--, now+=a;
			else now+=b,cnt1--;
		}
		printf("%lld\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;i++)
#define repd(i,a,b) for(register int i=a;i>=b;i--)
#define reps(s) for(int i=head[s];i;i=e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
#define eps 1e-8
using namespace std;
const int MAX_N=2e5+5;
typedef long long ll;
struct node{
	int type;
	ll ti;
}p[MAX_N];
bool cmp(node a1,node a2)
{
	if(a1.ti!=a2.ti)	return a1.ti<a2.ti;
	return a1.type<a2.type;
}
int n;
ll t,a,b;
ll cnt0,cnt1;
int main()
{
	int T;
	si(T);
	while(T--)
	{
		cnt0=cnt1=0;
		si(n),sl(t),sl(a),sl(b);
		repi(i,1,n){
			si(p[i].type);
			if(p[i].type)	cnt1++;
			else cnt0++;
		}
		repi(i,1,n) sl(p[i].ti);
		if(t>=(cnt0*a+cnt1*b)){
			printf("%d\n",n);
	//		int ans=n;
	//		pr(ans);
			continue;
		}
		sort(p+1,p+1+n,cmp);
		p[n+1].ti=t+1;
		ll ans=0;
		ll required=0;
		repi(i,1,n){
			if(i!=1&&p[i-1].type==0)	required+=a,cnt0--;
			else if(i!=1&&p[i-1].type==1)	required+=b,cnt1--;
			if(p[i].ti==p[i+1].ti) continue;
			if((p[i].ti-1)<required)	continue;
			ll res=1ll*i-1;
			ll rem=p[i].ti-1-required;
			ll n0=rem/a;
			rem-=min(n0,cnt0)*a,res+=min(n0,cnt0);
			ll n1=rem/b;
			res+=min(n1,cnt1);
//			pr(res),pr(i);
			ans=max(ans,res);
		}
		printf("%lld\n",ans);
	//	pr(ans);
	}
	return 0;
}


#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

enum{N=200023};
struct sth{
	ll x,y;
	bool operator<(const sth&e)const{
		return x<e.x;
	}
}d[N];

int main(){
	int TIM=ci();
	while( TIM-- ){
		ll n=ci(), T=ci(), a=ci(), b=ci();
		ll cnt0= 0;
		rep(i,1,n) if( (d[i].y=ci())==0 ) cnt0++;
		rep(i,1,n) d[i].x=ci();
		if( T>=a*cnt0+b*(n-cnt0) ){
			printf("%lld\n",n);
			continue;
		}
		sort(d+1,d+n+1);
		ll ans=0, now=0;
		rep(i,1,n){
			ll tmp= d[i].x-1;
			if( tmp>=now ){
				ll t= min(cnt0,(tmp-now)/a);
				tmp-= t*a+now;
//				printf("tmp %lld-%lld t %lld = %lld\n",d[i].x-1,now,t,i-1+t+tmp/b);
				ans= max(ans,i-1+t+tmp/b);
			}
			if( d[i].y==0 ) cnt0--, now+=a;
			else now+=b;
		}
		printf("%lld\n",ans);
	}
	return 0;
}


#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

enum{N=200023};
struct sth{
	ll x,y;
	bool operator<(const sth&e)const{
		return x<e.x;
	}
}d[N];

int main(){
	int TIM=ci();
	while( TIM-- ){
		ll n=ci(), T=ci(), a=ci(), b=ci();
		ll cnt0= 0,cnt1=0;
		rep(i,1,n) if( (d[i].y=ci())==0 ) cnt0++;
		cnt1=n-cnt0;
		rep(i,1,n) d[i].x=ci();
		if( T>=a*cnt0+b*(n-cnt0) ){
			printf("%lld\n",n);
			continue;
		}
		sort(d+1,d+n+1);
		ll ans=0, now=0;
		rep(i,1,n){
			ll tmp= d[i].x-1;
			if( tmp>=now &&d[i].y!=d[i+1].y){
				ll t= min(cnt0,(tmp-now)/a);
				tmp-= t*a+now;
//				printf("tmp %lld-%lld t %lld = %lld\n",d[i].x-1,now,t,i-1+t+tmp/b);
				ans= max(ans,i-1+t+min(tmp/b,cnt1));
			}
			if( d[i].y==0 ) cnt0--, now+=a;
			else now+=b,cnt1--;
		}
		printf("%lld\n",ans);
	}
	return 0;
}


//#include<algorithm>		//sort,lower_bound>=,upper_bound>, max...
//stl deque,priority_queue<int,vector<int>,greater<int> >先出小，不加默认先出大
//#include<string.h>		//strlen,strcmp...memset
//#include<string>			//string类
//#include<stdio.h>			//printf,scanf,getchar,gets
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
#define ll long long
#define MOD 1000000007
#define eps 1e-6
#define INF 0x3f3f3f3f
#define P pair<int,int>
#define N1 1005
#define N 200005

struct node
{
	int type,time;
	bool operator < (const node & b) const
	{
		return time<b.time;
	}
}inp[N];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,T;
		ll a,b;
		scanf("%d%d%lld%lld",&n,&T,&a,&b);
		ll sum0=0,sum1=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&inp[i].type);
			if(inp[i].type==0) sum0++;
			else sum1++;
		}
		for(int i=1;i<=n;i++)
			scanf("%d",&inp[i].time);

		sort(inp+1,inp+1+n);

		//type 0 a,1 b
		ll cnt0=0,cnt1=0;
		int ans=0;
		int wz=1;
		for(int i=inp[1].time-1;;)
		{
			while(wz<=n && inp[wz].time<=i)
			{
				if(inp[wz].type==0)
					cnt0++;
				else cnt1++;
				wz++;
			}
			ll tleft=-a*cnt0-b*cnt1+i;

			if(tleft<0)
			{
				if(i==T)
					break;
				if(wz<n)
				{
					if(i<inp[wz].time-1)
						i=max(i+1,inp[wz].time-1);
					else
						i=max(i+1,inp[wz+1].time-1);
				}
				else i=T;
				continue;
			}

			int ansnow=cnt0+cnt1;

			int cnt00=min(tleft/a,sum0-cnt0);
			tleft-=a*cnt00;
			ansnow+=cnt00;

			int cnt11=min(tleft/b,sum1-cnt1);
			ansnow+=cnt11;

			ans=max(ans,ansnow);

			if(i==T)
				break;
			if(wz<n)
			{
				if(i<inp[wz].time-1)
					i=max(i+1,inp[wz].time-1);
				else
					i=max(i+1,inp[wz+1].time-1);
			}
			else i=T;
		}

		printf("%d\n",ans);

	}
	return 0;
}


//#include<algorithm>		//sort,lower_bound>=,upper_bound>, max...
//stl deque,priority_queue<int,vector<int>,greater<int> >先出小，不加默认先出大
//#include<string.h>		//strlen,strcmp...memset
//#include<string>			//string类
//#include<stdio.h>			//printf,scanf,getchar,gets
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
#define ll long long
#define MOD 1000000007
#define eps 1e-6
#define INF 0x3f3f3f3f
#define P pair<int,int>
#define N1 1005
#define N 200005

struct node
{
	int type,time;
	bool operator < (const node & b) const
	{
		return time<b.time;
	}
}inp[N];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,T;
		ll a,b;
		scanf("%d%d%lld%lld",&n,&T,&a,&b);
		ll sum0=0,sum1=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&inp[i].type);
			if(inp[i].type==0) sum0++;
			else sum1++;
		}
		for(int i=1;i<=n;i++)
			scanf("%d",&inp[i].time);

		sort(inp+1,inp+1+n);

		//type 0 a,1 b
		ll cnt0=0,cnt1=0;
		int ans=0;
		int wz=1;
		for(int i=inp[1].time-1;;)
		{
			while(wz<=n && inp[wz].time<=i)
			{
				if(inp[wz].type==0)
					cnt0++;
				else cnt1++;
				wz++;
			}
			ll tleft=-a*cnt0-b*cnt1+i;

			if(tleft<0)
			{
				if(i==T)
					break;
				if(wz<n)
				{
					if(i<inp[wz].time-1)
						i=max(i+1,inp[wz].time-1);
					else
						i=max(i+1,inp[wz+1].time-1);
				}
				else
				{
					if(i<inp[wz].time-1)
						i=max(i+1,inp[wz].time-1);
					else
						i=T;
				}
				continue;
			}

			int ansnow=cnt0+cnt1;

			int cnt00=min(tleft/a,sum0-cnt0);
			tleft-=a*cnt00;
			ansnow+=cnt00;

			int cnt11=min(tleft/b,sum1-cnt1);
			ansnow+=cnt11;

			ans=max(ans,ansnow);

			if(i==T)
				break;
			if(wz<n)
			{
				if(i<inp[wz].time-1)
					i=max(i+1,inp[wz].time-1);
				else
					i=max(i+1,inp[wz+1].time-1);
			}
			else
			{
				if(i<inp[wz].time-1)
					i=max(i+1,inp[wz].time-1);
				else
					i=T;
			}
		}

		printf("%d\n",ans);

	}
	return 0;
}


//#include<algorithm>		//sort,lower_bound>=,upper_bound>, max...
//stl deque,priority_queue<int,vector<int>,greater<int> >先出小，不加默认先出大
//#include<string.h>		//strlen,strcmp...memset
//#include<string>			//string类
//#include<stdio.h>			//printf,scanf,getchar,gets
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
#define ll long long
#define MOD 1000000007
#define eps 1e-6
#define INF 0x3f3f3f3f
#define P pair<int,int>
#define N1 1005
#define N 200005

struct node
{
	int type,time;
	bool operator < (const node & b) const
	{
		return time<b.time;
	}
}inp[N];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,T;
		ll a,b;
		scanf("%d%d%lld%lld",&n,&T,&a,&b);
		ll sum0=0,sum1=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&inp[i].type);
			if(inp[i].type==0) sum0++;
			else sum1++;
		}
		for(int i=1;i<=n;i++)
			scanf("%d",&inp[i].time);

		sort(inp+1,inp+1+n);

		//type 0 a,1 b
		ll cnt0=0,cnt1=0;
		int ans=0;
		int wz=1;
		for(int i=1;i<=T;i++)
		{
			while(wz<=n && inp[wz].time<=i)
			{
				if(inp[wz].type==0)
					cnt0++;
				else cnt1++;
				wz++;
			}
			ll tleft=-a*cnt0-b*cnt1+i;

			if(tleft<0) continue;
			int ansnow=cnt0+cnt1;

			int cnt00=min(tleft/a,sum0-cnt0);
			tleft-=a*cnt00;
			ansnow+=cnt00;

			int cnt11=min(tleft/b,sum1-cnt1);
			ansnow+=cnt11;

			ans=max(ans,ansnow);
		}

		printf("%d\n",ans);

	}
	return 0;
}


//#include<algorithm>		//sort,lower_bound>=,upper_bound>, max...
//stl deque,priority_queue<int,vector<int>,greater<int> >先出小，不加默认先出大
//#include<string.h>		//strlen,strcmp...memset
//#include<string>			//string类
//#include<stdio.h>			//printf,scanf,getchar,gets
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
#define ll long long
#define MOD 1000000007
#define eps 1e-6
#define INF 0x3f3f3f3f
#define P pair<int,int>
#define N1 1005
#define N 200005

struct node
{
	int type,time;
	bool operator < (const node & b) const
	{
		return time<b.time;
	}
}inp[N];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,T;
		ll a,b;
		scanf("%d%d%lld%lld",&n,&T,&a,&b);
		ll sum0=0,sum1=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&inp[i].type);
			if(inp[i].type==0) sum0++;
			else sum1++;
		}
		for(int i=1;i<=n;i++)
			scanf("%d",&inp[i].time);
			ll tleft=-a*sum0-b*sum1+T;
		if(tleft>=0)
		{
			printf("%d\n",n);
			continue;
		}
		sort(inp+1,inp+1+n);

		//type 0 a,1 b
		ll cnt0=0,cnt1=0;
		int ans=0;
		int wz=1;
		for(int i=1;i<n;i++)
		{
			int timenow=inp[i].time-1;
			if(i>=2)
			{
				if(inp[i-1].type==0)
					cnt0++;
				else cnt1++;
			}

			ll tleft=-a*cnt0-b*cnt1+timenow;

			if(tleft<0)	continue;
			int ansnow=cnt0+cnt1;
			int cnt00=min(tleft/a,sum0-cnt0);
			tleft-=a*cnt00;
			ansnow+=cnt00;
			int cnt11=min(tleft/b,sum1-cnt1);
			ansnow+=cnt11;
			ans=max(ans,ansnow);
		}
		printf("%d\n",ans);
	}
	return 0;
}


//#include<algorithm>		//sort,lower_bound>=,upper_bound>, max...
//stl deque,priority_queue<int,vector<int>,greater<int> >先出小，不加默认先出大
//#include<string.h>		//strlen,strcmp...memset
//#include<string>			//string类
//#include<stdio.h>			//printf,scanf,getchar,gets
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
#define ll long long
#define MOD 1000000007
#define eps 1e-6
#define INF 0x3f3f3f3f
#define P pair<int,int>
#define N1 1005
#define N 200005

struct node
{
	int type,time;
	bool operator < (const node & b) const
	{
		return time<b.time;
	}
}inp[N];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,T;
		ll a,b;
		scanf("%d%d%lld%lld",&n,&T,&a,&b);
		ll sum0=0,sum1=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&inp[i].type);
			if(inp[i].type==0) sum0++;
			else sum1++;
		}
		for(int i=1;i<=n;i++)
			scanf("%d",&inp[i].time);

		sort(inp+1,inp+1+n);

		//type 0 a,1 b
		ll cnt0=0,cnt1=0;
		int ans=0;
		int wz=1;
		for(int i=1;;)
		{
			while(wz<=n && inp[wz].time<=i)
			{
				if(inp[wz].type==0)
					cnt0++;
				else cnt1++;
				wz++;
			}
			ll tleft=-a*cnt0-b*cnt1+i;

			if(tleft<0)
			{
				if(i==T)
					break;
				if(i==inp[wz-1].time)
				{
					if(wz<=n) i=max(i+1,inp[wz].time-1);
					else i=T;
				}
				else
				{
					if(wz<=n) i=inp[wz].time;
					else i=T;
				}
				continue;
			}
			int ansnow=cnt0+cnt1;

			int cnt00=min(tleft/a,sum0-cnt0);
			tleft-=a*cnt00;
			ansnow+=cnt00;

			int cnt11=min(tleft/b,sum1-cnt1);
			ansnow+=cnt11;

			ans=max(ans,ansnow);

			if(i==T)
				break;
			if(i==inp[wz-1].time || i==1)
			{
				if(wz<=n) i=max(i+1,inp[wz].time-1);
				else i=T;
			}
			else
			{
				if(wz<=n) i=inp[wz].time;
				else i=T;
			}
		}

		printf("%d\n",ans);

	}
	return 0;
}


//#include<algorithm>		//sort,lower_bound>=,upper_bound>, max...
//stl deque,priority_queue<int,vector<int>,greater<int> >先出小，不加默认先出大
//#include<string.h>		//strlen,strcmp...memset
//#include<string>			//string类
//#include<stdio.h>			//printf,scanf,getchar,gets
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
#define ll long long
#define MOD 1000000007
#define eps 1e-6
#define INF 0x3f3f3f3f
#define P pair<int,int>
#define N1 1005
#define N 200005

struct node
{
	int type,time;
	bool operator < (const node & b) const
	{
		return time<b.time;
	}
}inp[N];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,T;
		ll a,b;
		scanf("%d%d%lld%lld",&n,&T,&a,&b);
		ll sum0=0,sum1=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&inp[i].type);
			if(inp[i].type==0) sum0++;
			else sum1++;
		}
		for(int i=1;i<=n;i++)
			scanf("%d",&inp[i].time);

		sort(inp+1,inp+1+n);

		//type 0 a,1 b
		ll cnt0=0,cnt1=0;
		int ans=0;
		int wz=1;
		for(int i=inp[1].time-1;;)
		{
			while(wz<=n && inp[wz].time<=i)
			{
				if(inp[wz].type==0)
					cnt0++;
				else cnt1++;
				wz++;
			}
			ll tleft=-a*cnt0-b*cnt1+i;

			if(tleft<0)
			{
				if(i==T)
					break;
				if(wz<n) i=max(i+1,inp[wz+1].time-1);
				else i=T;

				continue;
			}
			int ansnow=cnt0+cnt1;

			int cnt00=min(tleft/a,sum0-cnt0);
			tleft-=a*cnt00;
			ansnow+=cnt00;

			int cnt11=min(tleft/b,sum1-cnt1);
			ansnow+=cnt11;

			ans=max(ans,ansnow);

			if(i==T)
				break;
			if(wz<n) i=max(i+1,inp[wz+1].time-1);
			else i=T;
		}

		printf("%d\n",ans);

	}
	return 0;
}


//#include<algorithm>		//sort,lower_bound>=,upper_bound>, max...
//stl deque,priority_queue<int,vector<int>,greater<int> >先出小，不加默认先出大
//#include<string.h>		//strlen,strcmp...memset
//#include<string>			//string类
//#include<stdio.h>			//printf,scanf,getchar,gets
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
#define ll long long
#define MOD 1000000007
#define eps 1e-6
#define INF 0x3f3f3f3f
#define P pair<int,int>
#define N1 1005
#define N 200005

struct node
{
	int type,time;
	bool operator < (const node & b) const
	{
		return time<b.time;
	}
}inp[N];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,T;
		ll a,b;
		scanf("%d%d%lld%lld",&n,&T,&a,&b);
		ll sum0=0,sum1=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&inp[i].type);
			if(inp[i].type==0) sum0++;
			else sum1++;
		}
		for(int i=1;i<=n;i++)
			scanf("%d",&inp[i].time);

		sort(inp+1,inp+1+n);

		//type 0 a,1 b
		ll cnt0=0,cnt1=0;
		int ans=0;
		int wz=1;
		for(int i=inp[1].time-1;;)
		{
			while(wz<=n && inp[wz].time<=i)
			{
				if(inp[wz].type==0)
					cnt0++;
				else cnt1++;
				wz++;
			}
			ll tleft=-a*cnt0-b*cnt1+i;

			if(tleft<0)
			{
				if(i==T)
					break;
				if(wz<n)
				{
					if(i<inp[wz].time)
						i=max(i+1,inp[wz].time-1);
					else
						i=max(i+1,inp[wz+1].time-1);
				}
				else i=T;
				continue;
			}

			int ansnow=cnt0+cnt1;

			int cnt00=min(tleft/a,sum0-cnt0);
			tleft-=a*cnt00;
			ansnow+=cnt00;

			int cnt11=min(tleft/b,sum1-cnt1);
			ansnow+=cnt11;

			ans=max(ans,ansnow);

			if(i==T)
				break;
			if(wz<n)
			{
				if(i<inp[wz].time)
					i=max(i+1,inp[wz].time-1);
				else
					i=max(i+1,inp[wz+1].time-1);
			}
			else i=T;
		}

		printf("%d\n",ans);

	}
	return 0;
}


//#include<algorithm>		//sort,lower_bound>=,upper_bound>, max...
//stl deque,priority_queue<int,vector<int>,greater<int> >先出小，不加默认先出大
//#include<string.h>		//strlen,strcmp...memset
//#include<string>			//string类
//#include<stdio.h>			//printf,scanf,getchar,gets
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
#define ll long long
#define MOD 1000000007
#define eps 1e-6
#define INF 0x3f3f3f3f
#define P pair<int,int>
#define N1 1005
#define N 200005

struct node
{
	int type,time;
	bool operator < (const node & b) const
	{
		return time<b.time;
	}
}inp[N];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,T;
		ll a,b;
		scanf("%d%d%lld%lld",&n,&T,&a,&b);
		ll sum0=0,sum1=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&inp[i].type);
			if(inp[i].type==0) sum0++;
			else sum1++;
		}
		for(int i=1;i<=n;i++)
			scanf("%d",&inp[i].time);
			ll tleft=-a*sum0-b*sum1+T;
		if(tleft>=0)
		{
			printf("%d\n",n);
			continue;
		}
		sort(inp+1,inp+1+n);

		//type 0 a,1 b
		ll cnt0=0,cnt1=0;
		int ans=0;
		int wz=1;
		for(int i=1;i<=n;i++)
		{
			int timenow=inp[i].time-1;
			if(i>=2)
			{
				if(inp[i-1].type==0)
					cnt0++;
				else cnt1++;
			}
			ll tleft=-a*cnt0-b*cnt1+timenow;

			if(tleft<0)	continue;
			int ansnow=cnt0+cnt1;
			int cnt00=min(tleft/a,sum0-cnt0);
			tleft-=a*cnt00;
			ansnow+=cnt00;
			int cnt11=min(tleft/b,sum1-cnt1);
			ansnow+=cnt11;
			ans=max(ans,ansnow);
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;

#define LL long long

struct Node{LL Val,Time;};
int Value[100010],CA[100010],CB[100010];
Node Data[100010];
LL Sum[100010];
LL T,A,B;
int M,N;

bool cmp(Node A,Node B){return A.Time<B.Time;};

int main(){
    scanf("%d",&M);
    while(M--){
        scanf("%d%I64d%I64d%I64d",&N,&T,&A,&B);
        Data[0].Val=0;Data[0].Time=0;
        int CountA=0,CountB=0;
        for(register int i=1;i<=N;++i){
            int opt;
            scanf("%d",&opt);
            if(opt==0) {Data[i].Val=A;++CountA;}
            else{Data[i].Val=B;++CountB;}
        }
        for(register int i=1;i<=N;++i)
            scanf("%I64d",&Data[i].Time);
        sort(Data+1,Data+N+1,cmp);
        Data[N+1].Time=T;
        Data[N+1].Val=0;
        for(register int i=1;i<=N;++i){
            Sum[i]=Sum[i-1]+Data[i].Val;
            CA[i]=CA[i-1];CB[i]=CB[i-1];
            if(Data[i].Val==A) ++CA[i];
            if(Data[i].Val==B) ++CB[i];
        }
        int Ans=0;
        Data[0].Val=0;Data[0].Time=0;
        for(register int i=0;i<=N;++i){
            if(i+1<=N && Data[i+1].Time==Data[i].Time) continue;
            int temp=0;
            if(Sum[i]<=Data[i+1].Time && i==N) temp=i;
            else if(Sum[i]<Data[i+1].Time){
                temp=i;
                int RestA=CountA-CA[i];
                int RestB=CountB-CB[i];
                LL Delta=Data[i+1].Time-Sum[i];
                if(Delta/A>=RestA){
                    temp+=RestA;
                    Delta/=A;
                    if(Delta/B>=RestB) temp+=RestB;
                    else temp+=Delta/B;
                }
                else temp+=Delta/A;
            }
            Ans=max(Ans,temp);
        }
        printf("%d\n",Ans);
    }
    system("pause");
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;

#define LL long long

struct Node{LL Val,Time;};
int Value[100010],CA[100010],CB[100010];
Node Data[100010];
LL Sum[100010];
LL T,A,B;
int M,N;

bool cmp(Node A,Node B){return A.Time<B.Time;};

int main(){
    scanf("%d",&M);
    while(M--){
        scanf("%d%I64d%I64d%I64d",&N,&T,&A,&B);
        Data[0].Val=0;Data[0].Time=0;
        int CountA=0,CountB=0;
        for(register int i=1;i<=N;++i){
            int opt;
            scanf("%d",&opt);
            if(opt==0) {Data[i].Val=A;++CountA;}
            else{Data[i].Val=B;++CountB;}
        }
        for(register int i=1;i<=N;++i)
            scanf("%I64d",&Data[i].Time);
        sort(Data+1,Data+N+1,cmp);
        Data[N+1].Time=T;
        Data[N+1].Val=0;
        for(register int i=1;i<=N;++i){
            Sum[i]=Sum[i-1]+Data[i].Val;
            CA[i]=CA[i-1];CB[i]=CB[i-1];
            if(Data[i].Val==A) ++CA[i];
            if(Data[i].Val==B) ++CB[i];
        }
        int Ans=0;
        Data[0].Val=0;Data[0].Time=0;
        for(register int i=0;i<=N;++i){
            if(i+1<=N && Data[i+1].Time==Data[i].Time) continue;
            int temp=0;
            if(Sum[i]<=Data[i+1].Time && i==N) temp=i;
            else if(Sum[i]<Data[i+1].Time){
                temp=i;
                int RestA=CountA-CA[i];
                int RestB=CountB-CB[i];
                LL Delta=Data[i+1].Time-Sum[i];
                if(Delta/A>=RestA){
                    temp+=RestA;
                    Delta/=A;
                    if(Delta/B>=RestB) temp+=RestB;
                    else temp+=Delta/B;
                }
                else temp+=Delta/A;
            }
            Ans=max(Ans,temp);
        }
        printf("%d\n",Ans);
    }
    //system("pause");
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;

#define LL long long

struct Node{LL Val,Time;};
int Value[200010],CA[200010],CB[200010];
Node Data[200010];
LL Sum[200010];
LL T,A,B;
int M,N;

bool cmp(Node A,Node B){return A.Time<B.Time;};

int main(){
    scanf("%d",&M);
    while(M--){
        scanf("%d%I64d%I64d%I64d",&N,&T,&A,&B);
        Data[0].Val=0;Data[0].Time=0;
        int CountA=0,CountB=0;
        for(register int i=1;i<=N;++i){
            int opt;
            scanf("%d",&opt);
            if(opt==0) {Data[i].Val=A;++CountA;}
            else{Data[i].Val=B;++CountB;}
        }
        for(register int i=1;i<=N;++i)
            scanf("%I64d",&Data[i].Time);
        sort(Data+1,Data+N+1,cmp);
        Data[N+1].Time=T;
        Data[N+1].Val=0;
        for(register int i=1;i<=N;++i){
            Sum[i]=Sum[i-1]+Data[i].Val;
            CA[i]=CA[i-1];CB[i]=CB[i-1];
            if(Data[i].Val==A) ++CA[i];
            if(Data[i].Val==B) ++CB[i];
        }
        int Ans=0;
        Data[0].Val=0;Data[0].Time=0;
        for(register int i=0;i<=N;++i){
            if(i+1<=N && Data[i+1].Time==Data[i].Time) continue;
            int temp=0;
            if(Sum[i]<=Data[i+1].Time && i==N) temp=i;
            else if(Sum[i]<Data[i+1].Time){
                temp=i;
                int RestA=CountA-CA[i];
                int RestB=CountB-CB[i];
                LL Delta=Data[i+1].Time-Sum[i]-1;
                if(Delta/A>=RestA){
                    temp+=RestA;
                    Delta-=A*RestA;
                    if(Delta/B>=RestB) temp+=RestB;
                    else temp+=Delta/B;
                }
                else temp+=Delta/A;
            }
            Ans=max(Ans,temp);
        }
        printf("%d\n",Ans);
    }
    //system("pause");
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;

#define LL long long

struct Node{LL Val,Time;};
int Value[100010],CA[100010],CB[100010];
Node Data[100010];
LL Sum[100010];
LL T,A,B;
int M,N;

bool cmp(Node A,Node B){return A.Time<B.Time;};

int main(){
    scanf("%d",&M);
    while(M--){
        scanf("%d%I64d%I64d%I64d",&N,&T,&A,&B);
        Data[0].Val=0;Data[0].Time=0;
        int CountA=0,CountB=0;
        for(register int i=1;i<=N;++i){
            int opt;
            scanf("%d",&opt);
            if(opt==0) {Data[i].Val=A;++CountA;}
            else{Data[i].Val=B;++CountB;}
        }
        for(register int i=1;i<=N;++i)
            scanf("%I64d",&Data[i].Time);
        sort(Data+1,Data+N+1,cmp);
        Data[N+1].Time=T;
        Data[N+1].Val=0;
        for(register int i=1;i<=N;++i){
            Sum[i]=Sum[i-1]+Data[i].Val;
            CA[i]=CA[i-1];CB[i]=CB[i-1];
            if(Data[i].Val==A) ++CA[i];
            if(Data[i].Val==B) ++CB[i];
        }
        int Ans=0;
        Data[0].Val=0;Data[0].Time=0;
        for(register int i=0;i<=N;++i){
            if(i+1<=N && Data[i+1].Time==Data[i].Time) continue;
            int temp=0;
            if(Sum[i]<=Data[i+1].Time && i==N) temp=i;
            else if(Sum[i]<Data[i+1].Time){
                temp=i;
                int RestA=CountA-CA[i];
                int RestB=CountB-CB[i];
                LL Delta=Data[i+1].Time-Sum[i]-1;
                if(Delta/A>=RestA){
                    temp+=RestA;
                    Delta-=A*RestA;
                    if(Delta/B>=RestB) temp+=RestB;
                    else temp+=Delta/B;
                }
                else temp+=Delta/A;
            }
            Ans=max(Ans,temp);
        }
        printf("%d\n",Ans);
    }
    //system("pause");
    return 0;
}


#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
#define setpr(x) cout << setprecision((x))
#define PI atan(1)*4
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define in insert
#define er erase
#define mk make_pair
#define flush cout.flush()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endc "\n"
#define MOD 998244353

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef unordered_set<int> usi;
typedef unordered_set<ll> usl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;

ll gcd(ll a, ll b){
    if(a>b)
        swap(a,b);
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll powerMod(ll x,ll y){
    ll res = 1;
    x %= MOD;
    while(y > 0){
        if(y & 1)res = (res*x)%MOD;
        y = y >> 1;
        x = (x * x)%MOD;
    }
    return res%MOD;
}

string binary(ll s) {
    string res = "";
    while(s != 0) {
        res += (char)('0' + s % 2);
        s /= 2;
    }
    reverse(res.begin() , res.end());
    return res;
}

//  =========     /\       /|    |====/|
//      |        /  \       |    |   / |
//      |       /____\      |    |  /  |
//      |      /      \     |    | /   |
//  ========= /        \  =====  |/====|
//  code

typedef pair<pll , ll> ppl;
int main(){
    init;
    ll n,i,j,k,l,p,m,ans = 0LL;
    cin >> n;
    vector<pll> points(n);
    map<ppl , ll> mp;
    map<ppl , ll> val;
    for(auto &p : points){
        cin >> p.fi >> p.se;
    }
    for(i = 0;i < n; i++){
        for(j = i + 1; j < n; j++){
            auto p1 = points[j];
            auto p2 = points[i];
            k = p1.fi - p2.fi;
            p = p2.se - p1.se;
            m = p2.se * p1.fi - p2.fi * p1.se;

            l = gcd(gcd(abs(k),abs(p)) , abs(m));
            k /= l;
            p /= l;
            m /= l;
            mp[{{k,p},m}]++;
        }
    }

    for(auto it : mp){
        k = it.fi.fi.fi;
        j = it.fi.fi.se;
        m = it.fi.se;
        for(i = 0; i < n; i++){
            auto pp = points[i];
            if(k * (pp.se) + j * pp.fi == m){
                val[it.fi]++;
            }
        }
    }

    for(auto it : mp){
        k = it.fi.fi.fi;
        j = it.fi.fi.se;
        m = it.fi.se;
        l = val[it.fi];
        ans += (n - l) * (l * (l - 1LL))/2LL;
    }

    cout << ans/3LL << endc;

    return 0;
}


#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
#define setpr(x) cout << setprecision((x))
#define PI atan(1)*4
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define in insert
#define er erase
#define mk make_pair
#define flush cout.flush()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endc "\n"
#define MOD 998244353

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef unordered_set<int> usi;
typedef unordered_set<ll> usl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;

ll gcd(ll a, ll b){
    if(a>b)
        swap(a,b);
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll powerMod(ll x,ll y){
    ll res = 1;
    x %= MOD;
    while(y > 0){
        if(y & 1)res = (res*x)%MOD;
        y = y >> 1;
        x = (x * x)%MOD;
    }
    return res%MOD;
}

string binary(ll s) {
    string res = "";
    while(s != 0) {
        res += (char)('0' + s % 2);
        s /= 2;
    }
    reverse(res.begin() , res.end());
    return res;
}

//  =========     /\       /|    |====/|
//      |        /  \       |    |   / |
//      |       /____\      |    |  /  |
//      |      /      \     |    | /   |
//  ========= /        \  =====  |/====|
//  code

typedef pair<pll , ll> ppl;
int main(){
    init;
    ll n,i,j,k,l,p,m,ans = 0LL;
    cin >> n;
    vector<pll> points(n);
    map<ppl , ll> mp;
    map<ppl , pll> minp,maxp;
    for(auto &p : points){
        cin >> p.fi >> p.se;
    }
    for(i = 0;i < n; i++){
        for(j = i + 1; j < n; j++){
            auto p1 = points[j];
            auto p2 = points[i];
            k = p1.fi - p2.fi;
            p = p2.se - p1.se;
            m = p2.se * p1.fi - p2.fi * p1.se;

            l = gcd(gcd(abs(k),abs(p)) , abs(m));
            k /= l;
            p /= l;
            m /= l;
            mp[{{k,p},m}]++;
        }
    }

    for(auto it : mp){
        k = it.fi.fi.fi;
        j = it.fi.fi.se;
        m = it.fi.se;

        pll pmin = {200 , 200} , pmax = {-200 , -200};
        for(i = 0; i < n; i++){
            auto p = points[i];
            if(p.se * k + p.fi * j == m){
                pmin = min(pmin , p);
                pmax = max(pmax , p);
            }
        }

        maxp[it.fi] = pmax;
        minp[it.fi] = pmin;
        // cout << it.se << endc;
    }

    for(auto it : mp){
        k = it.fi.fi.fi;
        j = it.fi.fi.se;
        m = it.fi.se;
        ll val = (1LL + sqrt(1LL + 8LL * mp[it.fi]))/2LL;
        val = ((val) * (val - 1LL))/2LL;

        for(i = 0; i < n; i++){
            auto pp = points[i];
            if(k * (pp.se) + j * pp.fi == m){
                continue;
            }
            else{
                ans += val;
            }
        }
    }

    cout << ans/3LL << endc;

    return 0;
}


#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
#define setpr(x) cout << setprecision((x))
#define PI atan(1)*4
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define in insert
#define er erase
#define mk make_pair
#define flush cout.flush()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endc "\n"
#define MOD 998244353

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef unordered_set<int> usi;
typedef unordered_set<ll> usl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;

ll gcd(ll a, ll b){
    if(a>b)
        swap(a,b);
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll powerMod(ll x,ll y){
    ll res = 1;
    x %= MOD;
    while(y > 0){
        if(y & 1)res = (res*x)%MOD;
        y = y >> 1;
        x = (x * x)%MOD;
    }
    return res%MOD;
}

string binary(ll s) {
    string res = "";
    while(s != 0) {
        res += (char)('0' + s % 2);
        s /= 2;
    }
    reverse(res.begin() , res.end());
    return res;
}

//  =========     /\       /|    |====/|
//      |        /  \       |    |   / |
//      |       /____\      |    |  /  |
//      |      /      \     |    | /   |
//  ========= /        \  =====  |/====|
//  code

typedef pair<pll , ll> ppl;
int main(){
    init;
    ll n,i,j,k,l,p,m,ans = 0LL;
    cin >> n;
    vector<pll> points(n);
    map<ppl , ll> mp;
    map<ppl , ll> val;
    for(auto &p : points){
        cin >> p.fi >> p.se;
    }
    for(i = 0;i < n; i++){
        for(j = i + 1; j < n; j++){
            auto p1 = points[j];
            auto p2 = points[i];
            k = p1.fi - p2.fi;
            p = p2.se - p1.se;
            m = p2.se * p1.fi - p2.fi * p1.se;

            l = gcd(gcd(abs(k),abs(p)) , abs(m));
            k /= l;
            p /= l;
            m /= l;
            mp[{{k,p},m}]++;
        }
    }

    for(auto it : mp){
        k = it.fi.fi.fi;
        j = it.fi.fi.se;
        m = it.fi.se;
        val[it.fi] = (1LL + sqrt(1LL + 8LL * it.se))/2LL;
    }

    for(auto it : mp){
        k = it.fi.fi.fi;
        j = it.fi.fi.se;
        m = it.fi.se;
        l = val[it.fi];
        ans += (n - l) * (l * (l - 1LL))/2LL;
    }

    cout << ans/3LL << endc;

    return 0;
}


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

int dis(vector<int> &v1, vector<int>&v2)
{
    return (v2[0] - v1[0]) * (v2[0] - v1[0]) + (v2[1] - v1[1]) * (v2[1] - v1[1]);
}

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(2));
    for(int i = 0; i < n; i++)
    {
        cin >> v[i][0] >> v[i][1];
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            int l1 = dis(v[i], v[j]);
            if(l1 == 0)
                continue;
            for(int k = j + 1; k < n; k++)
            {
                int l2 = dis(v[j], v[k]);
                int l3 = dis(v[i], v[k]);
                // cout << l1 << " , " << l2 << " , " << l3 << endl;
                if(l2 == 0 || l3 == 0)
                    continue;
                if(l1 + l2 < l3 || l1 + l3 < l2 || l2 + l3 < l1)
                    continue;
                ans++;
            }
        }
    }
    cout << ans;
    return 0;
}


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

double dis(vector<int> &v1, vector<int>&v2)
{
    return sqrt((v2[0] - v1[0]) * (v2[0] - v1[0]) + (v2[1] - v1[1]) * (v2[1] - v1[1]));
}

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(2));
    for(int i = 0; i < n; i++)
    {
        cin >> v[i][0] >> v[i][1];
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            double l1 = dis(v[i], v[j]);
            if(l1 == 0)
                continue;
            for(int k = j + 1; k < n; k++)
            {
                double l2 = dis(v[j], v[k]);
                double l3 = dis(v[i], v[k]);
                // cout << l1 << " , " << l2 << " , " << l3 << endl;
                if(l2 == 0.0 || l3 == 0.0)
                    continue;
                if(l1 + l2 <= l3 || l1 + l3 <= l2 || l2 + l3 <= l1)
                {
                    // cout << " e " << endl;
                    continue;
                }
                ans++;
            }
        }
    }
    cout << ans;
    return 0;
}


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

double dis(vector<int> &v1, vector<int>&v2)
{
    return sqrt((v2[0] - v1[0]) * (v2[0] - v1[0]) + (v2[1] - v1[1]) * (v2[1] - v1[1]));
}

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(2));
    for(int i = 0; i < n; i++)
    {
        cin >> v[i][0] >> v[i][1];
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            double l1 = dis(v[i], v[j]);
            if(l1 == 0)
                continue;
            for(int k = j + 1; k < n; k++)
            {
                double l2 = dis(v[j], v[k]);
                double l3 = dis(v[i], v[k]);
                // cout << l1 << " , " << l2 << " , " << l3 << endl;
                if(l2 == 0.0 || l3 == 0.0)
                    continue;
                if(l1 + l2 < l3 || l1 + l3 < l2 || l2 + l3 < l1)
                {
                    // cout << " e " << endl;
                    continue;
                }
                ans++;
            }
        }
    }
    cout << ans;
    return 0;
}


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

double dis(vector<int> &v1, vector<int>&v2)
{
    return sqrt((v2[0] - v1[0]) * (v2[0] - v1[0]) + (v2[1] - v1[1]) * (v2[1] - v1[1]));
}

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(2));
    for(int i = 0; i < n; i++)
    {
        cin >> v[i][0] >> v[i][1];
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            double l1 = dis(v[i], v[j]);
            if(l1 == 0)
                continue;
            for(int k = j + 1; k < n; k++)
            {
                double l2 = dis(v[j], v[k]);
                double l3 = dis(v[i], v[k]);
                // cout << l1 << " , " << l2 << " , " << l3 << endl;
                if(l2 == 0.0 || l3 == 0.0)
                    continue;
                if(l1 + l2 <= l3 || l1 + l3 <= l2 || l2 + l3 <= l1)
                    continue;
                ans++;
            }
        }
    }
    cout << ans;
    return 0;
}


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

double dis(vector<int> &v1, vector<int>&v2)
{
    return sqrt((v2[0] - v1[0]) * (v2[0] - v1[0]) + (v2[1] - v1[1]) * (v2[1] - v1[1]));
}

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(2));
    for(int i = 0; i < n; i++)
    {
        cin >> v[i][0] >> v[i][1];
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            for(int k = j + 1; k < n; k++)
            {
                int x1 = v[i][0], y1 = v[i][1], x2 = v[j][0], y2 = v[j][1], x3 = v[k][0], y3 = v[k][1];
                int area = x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2);
                if(area)
                    ans++;
            }
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define pi 3.141592653589793238
typedef pair<lli,lli> pll;
typedef map<lli,lli> mll;
typedef set<lli> sl;
typedef map<int,int> mii;
typedef set<int> si;
#define x first
#define y second
#define mp make_pair
#define pb push_back
const lli mod = 1e9 + 7;

lli power(lli a, lli p)
{
    lli ans = 1;
    while(p > 0)
    {
        if(p%2)
        {
            ans *= a;
            ans %= mod;
        }
        a*=a;
        a%=mod;
        p/=2;
    }
    return ans%mod;
}

vector <lli> getbinary(lli x)
{
    vector <lli> bin(101,0);
    int iter = 0;
    while(x > 0)
    {
        bin[iter] = x%2;
        iter++;
        x/=2;
    }
    return bin;
}

char mat[51][51];

lli checkpaths(pll a, pll b)
{
    pll tempa = a,tempb = b;
    lli flg1 = 0,flg2 = 0;
    while(tempa.x != tempb.x)
    {
        if(b.x > a.x)
        {
            tempa.x++;
        }
        else
        {
            tempa.x--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg1 = 1;
            break;
        }
    }
    while(tempa.y != tempb.y)
    {
        if(b.y > a.y)
        {
            tempa.y++;
        }
        else
        {
            tempa.y--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg1 = 1;
            break;
        }
    }
    tempa = a,tempb = b;
    while(tempa.y != tempb.y)
    {
        if(b.y > a.y)
        {
            tempa.y++;
        }
        else
        {
            tempa.y--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg2 = 1;
            break;
        }
    }
    while(tempa.x != tempb.x)
    {
        if(b.x > a.x)
        {
            tempa.x++;
        }
        else
        {
            tempa.x--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg2 = 1;
            break;
        }
    }
    return 2 - flg1 - flg2;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    lli n;
    cin >> n;
    pair <double,double> a[n];
    unordered_map <double,set <pair <double,double> > > m;
    set < pair<double,double> > lel;
    for(int i = 0; i<n; i++)
    {
        cin >> a[i].x >> a[i].y;
    }
    lli sub = 0;
    for(int i = 0; i<n; i++)
    {
        for(int j = 0; j<n; j++)
        {
            if(i == j)
            {
                continue;
            }
            if(a[j].x - a[i].x == 0)
            {
                lel.insert(a[j]);
                continue;
            }
            else
            {
                double slope = (a[j].y - a[i].y)/(a[j].x - a[i].x);
                m[slope].insert(a[j]);
            }
        }
        for(auto e: m)
        {
            lli temp = e.y.size();
            sub += temp*(temp-1)/2;
        }
        sub += lel.size()*(lel.size()-1)/2;
        m.clear();
        lel.clear();
    }
    lli ans = n*(n-1)*(n-2)/6;
    ans -= sub/3;
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define pi 3.141592653589793238
typedef pair<lli,lli> pll;
typedef map<lli,lli> mll;
typedef set<lli> sl;
typedef map<int,int> mii;
typedef set<int> si;
#define x first
#define y second
#define mp make_pair
#define pb push_back
const lli mod = 1e9 + 7;

lli power(lli a, lli p)
{
    lli ans = 1;
    while(p > 0)
    {
        if(p%2)
        {
            ans *= a;
            ans %= mod;
        }
        a*=a;
        a%=mod;
        p/=2;
    }
    return ans%mod;
}

vector <lli> getbinary(lli x)
{
    vector <lli> bin(101,0);
    int iter = 0;
    while(x > 0)
    {
        bin[iter] = x%2;
        iter++;
        x/=2;
    }
    return bin;
}

char mat[51][51];

lli checkpaths(pll a, pll b)
{
    pll tempa = a,tempb = b;
    lli flg1 = 0,flg2 = 0;
    while(tempa.x != tempb.x)
    {
        if(b.x > a.x)
        {
            tempa.x++;
        }
        else
        {
            tempa.x--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg1 = 1;
            break;
        }
    }
    while(tempa.y != tempb.y)
    {
        if(b.y > a.y)
        {
            tempa.y++;
        }
        else
        {
            tempa.y--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg1 = 1;
            break;
        }
    }
    tempa = a,tempb = b;
    while(tempa.y != tempb.y)
    {
        if(b.y > a.y)
        {
            tempa.y++;
        }
        else
        {
            tempa.y--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg2 = 1;
            break;
        }
    }
    while(tempa.x != tempb.x)
    {
        if(b.x > a.x)
        {
            tempa.x++;
        }
        else
        {
            tempa.x--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg2 = 1;
            break;
        }
    }
    return 2 - flg1 - flg2;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    lli n,x1,y1;
    cin >> n;
    pll a[n];
    unordered_map<lli,lli> m;
    for(int i = 0; i<n; i++)
    {
        cin >> a[i].x >> a[i].y;
    }
    lli lel = 0;
    for(int i = 0; i<n; i++)
    {
        for(int j = i+1; i<n; i++)
        {
            if(a[j].x - a[i].x == 0)
            {
                lel++;
                continue;
            }
            m[(a[j].y-a[i].y)/(a[j].x-a[i].x)]++;
        }
    }
    lli ans = n*(n-1)*(n-2)/6;
    for(auto e: m)
    {
        lli temp = e.y;
        temp++;
        ans -= temp*(temp-1)*(temp-2)/6;
    }
    lel++;
    ans -= lel*(lel-1)*(lel-2)/6;
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define pi 3.141592653589793238
typedef pair<lli,lli> pll;
typedef map<lli,lli> mll;
typedef set<lli> sl;
typedef map<int,int> mii;
typedef set<int> si;
#define x first
#define y second
#define mp make_pair
#define pb push_back
const lli mod = 1e9 + 7;

lli power(lli a, lli p)
{
    lli ans = 1;
    while(p > 0)
    {
        if(p%2)
        {
            ans *= a;
            ans %= mod;
        }
        a*=a;
        a%=mod;
        p/=2;
    }
    return ans%mod;
}

vector <lli> getbinary(lli x)
{
    vector <lli> bin(101,0);
    int iter = 0;
    while(x > 0)
    {
        bin[iter] = x%2;
        iter++;
        x/=2;
    }
    return bin;
}

char mat[51][51];

lli checkpaths(pll a, pll b)
{
    pll tempa = a,tempb = b;
    lli flg1 = 0,flg2 = 0;
    while(tempa.x != tempb.x)
    {
        if(b.x > a.x)
        {
            tempa.x++;
        }
        else
        {
            tempa.x--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg1 = 1;
            break;
        }
    }
    while(tempa.y != tempb.y)
    {
        if(b.y > a.y)
        {
            tempa.y++;
        }
        else
        {
            tempa.y--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg1 = 1;
            break;
        }
    }
    tempa = a,tempb = b;
    while(tempa.y != tempb.y)
    {
        if(b.y > a.y)
        {
            tempa.y++;
        }
        else
        {
            tempa.y--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg2 = 1;
            break;
        }
    }
    while(tempa.x != tempb.x)
    {
        if(b.x > a.x)
        {
            tempa.x++;
        }
        else
        {
            tempa.x--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg2 = 1;
            break;
        }
    }
    return 2 - flg1 - flg2;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    lli n,x1,y1;
    cin >> n;
    pll a[n];
    unordered_map<lli,lli> m;
    unordered_map<lli,lli> check;
    for(int i = 0; i<n; i++)
    {
        cin >> a[i].x >> a[i].y;
    }
    lli lel = 0,added = 0;
    for(int i = 0; i<n; i++)
    {
        check.clear();
        added = 0;
        for(int j = i+1; j<n; j++)
        {
            if(a[j].x - a[i].x == 0)
            {
                if(added == 0)
                {
                    lel++;
                    added = 1;
                }
                continue;
            }
            if(check[(a[j].y-a[i].y)/(a[j].x-a[i].x)] == 0)
            {
                m[(a[j].y-a[i].y)/(a[j].x-a[i].x)]++;
                check[(a[j].y-a[i].y)/(a[j].x-a[i].x)] = 1;
            }
        }
    }
    lli ans = n*(n-1)*(n-2)/6;
    for(auto e: m)
    {
        lli temp = e.y;
        temp++;
        ans -= temp*(temp-1)*(temp-2)/6;
    }
    lel++;
    ans -= lel*(lel-1)*(lel-2)/6;
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define pi 3.141592653589793238
typedef pair<lli,lli> pll;
typedef map<lli,lli> mll;
typedef set<lli> sl;
typedef map<int,int> mii;
typedef set<int> si;
#define x first
#define y second
#define mp make_pair
#define pb push_back
const lli mod = 1e9 + 7;

lli power(lli a, lli p)
{
    lli ans = 1;
    while(p > 0)
    {
        if(p%2)
        {
            ans *= a;
            ans %= mod;
        }
        a*=a;
        a%=mod;
        p/=2;
    }
    return ans%mod;
}

vector <lli> getbinary(lli x)
{
    vector <lli> bin(101,0);
    int iter = 0;
    while(x > 0)
    {
        bin[iter] = x%2;
        iter++;
        x/=2;
    }
    return bin;
}

char mat[51][51];

lli checkpaths(pll a, pll b)
{
    pll tempa = a,tempb = b;
    lli flg1 = 0,flg2 = 0;
    while(tempa.x != tempb.x)
    {
        if(b.x > a.x)
        {
            tempa.x++;
        }
        else
        {
            tempa.x--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg1 = 1;
            break;
        }
    }
    while(tempa.y != tempb.y)
    {
        if(b.y > a.y)
        {
            tempa.y++;
        }
        else
        {
            tempa.y--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg1 = 1;
            break;
        }
    }
    tempa = a,tempb = b;
    while(tempa.y != tempb.y)
    {
        if(b.y > a.y)
        {
            tempa.y++;
        }
        else
        {
            tempa.y--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg2 = 1;
            break;
        }
    }
    while(tempa.x != tempb.x)
    {
        if(b.x > a.x)
        {
            tempa.x++;
        }
        else
        {
            tempa.x--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg2 = 1;
            break;
        }
    }
    return 2 - flg1 - flg2;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    lli n,x1,y1;
    cin >> n;
    pll a[n];
    unordered_map<lli,lli> m;
    for(int i = 0; i<n; i++)
    {
        cin >> a[i].x >> a[i].x;
    }
    lli lel = 0;
    for(int i = 0; i<n; i++)
    {
        for(int j = i+1; i<n; i++)
        {
            if(a[j].x - a[i].x == 0)
            {
                lel++;
                continue;
            }
            m[(a[j].y-a[i].y)/(a[j].x-a[i].x)]++;
        }
    }
    lli ans = n*(n-1)*(n-2)/6;
    for(auto e: m)
    {
        lli temp = e.y;
        ans -= temp*(temp-1)*(temp-2)/6;
    }
    ans -= lel*(lel-1)*(lel-2)/6;
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define pi 3.141592653589793238
typedef pair<lli,lli> pll;
typedef map<lli,lli> mll;
typedef set<lli> sl;
typedef map<int,int> mii;
typedef set<int> si;
#define x first
#define y second
#define mp make_pair
#define pb push_back
const lli mod = 1e9 + 7;

lli power(lli a, lli p)
{
    lli ans = 1;
    while(p > 0)
    {
        if(p%2)
        {
            ans *= a;
            ans %= mod;
        }
        a*=a;
        a%=mod;
        p/=2;
    }
    return ans%mod;
}

vector <lli> getbinary(lli x)
{
    vector <lli> bin(101,0);
    int iter = 0;
    while(x > 0)
    {
        bin[iter] = x%2;
        iter++;
        x/=2;
    }
    return bin;
}

char mat[51][51];

lli checkpaths(pll a, pll b)
{
    pll tempa = a,tempb = b;
    lli flg1 = 0,flg2 = 0;
    while(tempa.x != tempb.x)
    {
        if(b.x > a.x)
        {
            tempa.x++;
        }
        else
        {
            tempa.x--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg1 = 1;
            break;
        }
    }
    while(tempa.y != tempb.y)
    {
        if(b.y > a.y)
        {
            tempa.y++;
        }
        else
        {
            tempa.y--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg1 = 1;
            break;
        }
    }
    tempa = a,tempb = b;
    while(tempa.y != tempb.y)
    {
        if(b.y > a.y)
        {
            tempa.y++;
        }
        else
        {
            tempa.y--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg2 = 1;
            break;
        }
    }
    while(tempa.x != tempb.x)
    {
        if(b.x > a.x)
        {
            tempa.x++;
        }
        else
        {
            tempa.x--;
        }
        if(mat[tempa.x][tempa.y] == 'W')
        {
            flg2 = 1;
            break;
        }
    }
    return 2 - flg1 - flg2;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    lli n;
    cin >> n;
    pair <double,double> a[n];
    unordered_map <double,set <pair <double,double> > > m;
    set < pair<double,double> > lel;
    for(int i = 0; i<n; i++)
    {
        cin >> a[i].x >> a[i].y;
    }
    for(int i = 0; i<n; i++)
    {
        for(int j = i+1; j<n; j++)
        {
            if(a[j].x - a[i].x == 0)
            {
                lel.insert(a[i]);
                lel.insert(a[j]);
                continue;
            }
            else
            {
                double slope = (a[j].y - a[i].y)/(a[j].x - a[i].x);
                m[slope].insert(a[i]);
                m[slope].insert(a[j]);
            }
        }
    }
    lli ans = n*(n-1)*(n-2)/6;
    for(auto e: m)
    {
        lli temp = e.y.size();
        ans -= temp*(temp-1)*(temp-2)/6;
    }
    ans -= lel.size()*(lel.size()-1)*(lel.size()-2)/6;
    cout << ans << endl;
}


//**KISS**
//**KEEP IT SHORT AND SIMPLE**

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <tuple>
#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 INF 1000000000
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
#define PB push_back
#define Summation(n) (n) * ((n) + 1) / 2
#define ALL(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef pair <long long, long long> pll;
typedef queue <long long> qll;
typedef deque <long long> dll;
typedef set <long long> sll;
typedef set <string> ss;
typedef set <char> sc;
typedef unordered_set <long long> usll;
typedef multiset <long long> msll;
typedef unordered_multiset <long long> umsll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef map <string, bool> msb;
typedef map <string, long long> msl;
typedef map <char, bool> mcb;
typedef map <char, long long> mcl;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//double pi = 2 * acos(0.0);

//ll _sieve_size;
//bitset<10000010> _bs;
//vll _primes;
//void sieve(ll upperbound)
//{
//    //O(N log log N)
//    _sieve_size = upperbound;
//    _bs.set();
//    _bs[0] = _bs[1] = 0;
//    for(ll i = 2;i <= _sieve_size;i++)
//        if(_bs[i])
//        {
//            for(ll j = i * i;j <= _sieve_size;j+=i)
//                _bs[j] = 0;
//            _primes.push_back(i);
//        }
//}
//bool isPrime(ll N)
//{
//    if(N <= _sieve_size)    return _bs[N];
//    for(int i = 0;i < _primes.size();i++)
//        if(N % _primes[i] == 0) return false;
//    return true;
//}
//vll primeFactors(ll N)
//{
//    //O( sqrt(N) /ln sqrt(N))
//    vll factors;
//    ll PF_idx = 0, PF = _primes[PF_idx];
//    //sieve should generate primes first
//    while(PF * PF <= N)
//    {
//        while(N % PF == 0)
//        {
//            N /= PF;
//            factors.push_back(PF);
//        }
//        PF = _primes[++PF_idx];
//    }
//    //if N itself is Prime
//    if(N != 1)  factors.push_back(N);
//    return factors;
//}
//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)); }
//long long FastPower(long long Num, long long Pow)
//{
//    if(Pow == 0)
//        return 1;
//    if(Pow == 1)
//        return Num;
//    long long Result = FastPower(Num, Pow / 2);
//    Result *= Result;
//    if(Pow % 2 != 0)
//        Result *= Num;
//    return Result;
//}
//long long power(long long x, unsigned long long y, long long mod)
//{
//    long long temp;
//    if( y == 0)
//        return 1;
//    temp = power(x, y/2,mod)%mod;
//    if (y%2 == 0)
//        return (temp%mod*temp%mod)%mod;
//    else
//        return((x%mod*temp)%mod*temp)%mod;
//}
ll ncr(ll n, ll r)
{
    r = min(r, n - r);
    ll ans = 1;
    for(int i = 1;i <= r;i++)
    {
        ans *= n - i + 1;
        ans /= i;
    }
    return ans;
}
//bool isPowerOfTwo(int x)
//{
//    // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
//    return (x && !(x & (x - 1)));
//}
//bool sortbysec(const pll &a, const pll &b)
//{
//    return (a.second < b.second);
//}
//double binet(unsigned int n)
//{
//    static const double phi = (1 + sqrt(5))*0.5;
//    double fib = (pow(phi,n) - pow(1-phi,n))/sqrt(5);
//    return round(fib);
//}
int main()
{
    IO
    ll n, cnt = 0;
    cin >> n;
    double x[n], y[n];
    REP(i, 0, n)
        cin >> x[i] >> y[i];
    if(n < 3)
    {
        cout << 0;
        return 0;
    }
    REP(i, 0, n)
    {
        map <double, ll> mp;
        REP(j, i + 1, n)
        {
            double slope;
            if(x[j] == x[i])
                slope = 100000000;
            else
                slope = (y[j] - y[i]) / (x[j] - x[i]);
            mp[slope]++;
            if(mp[slope] == 2)
                cnt++;
        }
    }
    cout << ncr(n, 3) - cnt;
    return 0;
}


//**KISS**
//**KEEP IT SHORT AND SIMPLE**

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <tuple>
#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 INF 1000000000
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
#define PB push_back
#define Summation(n) (n) * ((n) + 1) / 2
#define ALL(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef pair <long long, long long> pll;
typedef queue <long long> qll;
typedef deque <long long> dll;
typedef set <long long> sll;
typedef set <string> ss;
typedef set <char> sc;
typedef unordered_set <long long> usll;
typedef multiset <long long> msll;
typedef unordered_multiset <long long> umsll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef map <string, bool> msb;
typedef map <string, long long> msl;
typedef map <char, bool> mcb;
typedef map <char, long long> mcl;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//double pi = 2 * acos(0.0);

//ll _sieve_size;
//bitset<10000010> _bs;
//vll _primes;
//void sieve(ll upperbound)
//{
//    //O(N log log N)
//    _sieve_size = upperbound;
//    _bs.set();
//    _bs[0] = _bs[1] = 0;
//    for(ll i = 2;i <= _sieve_size;i++)
//        if(_bs[i])
//        {
//            for(ll j = i * i;j <= _sieve_size;j+=i)
//                _bs[j] = 0;
//            _primes.push_back(i);
//        }
//}
//bool isPrime(ll N)
//{
//    if(N <= _sieve_size)    return _bs[N];
//    for(int i = 0;i < _primes.size();i++)
//        if(N % _primes[i] == 0) return false;
//    return true;
//}
//vll primeFactors(ll N)
//{
//    //O( sqrt(N) /ln sqrt(N))
//    vll factors;
//    ll PF_idx = 0, PF = _primes[PF_idx];
//    //sieve should generate primes first
//    while(PF * PF <= N)
//    {
//        while(N % PF == 0)
//        {
//            N /= PF;
//            factors.push_back(PF);
//        }
//        PF = _primes[++PF_idx];
//    }
//    //if N itself is Prime
//    if(N != 1)  factors.push_back(N);
//    return factors;
//}
//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)); }
//long long FastPower(long long Num, long long Pow)
//{
//    if(Pow == 0)
//        return 1;
//    if(Pow == 1)
//        return Num;
//    long long Result = FastPower(Num, Pow / 2);
//    Result *= Result;
//    if(Pow % 2 != 0)
//        Result *= Num;
//    return Result;
//}
//long long power(long long x, unsigned long long y, long long mod)
//{
//    long long temp;
//    if( y == 0)
//        return 1;
//    temp = power(x, y/2,mod)%mod;
//    if (y%2 == 0)
//        return (temp%mod*temp%mod)%mod;
//    else
//        return((x%mod*temp)%mod*temp)%mod;
//}
ll ncr(ll n, ll r)
{
    r = min(r, n - r);
    ll ans = 1;
    for(int i = 1;i <= r;i++)
    {
        ans *= n - i + 1;
        ans /= i;
    }
    return ans;
}
//bool isPowerOfTwo(int x)
//{
//    // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
//    return (x && !(x & (x - 1)));
//}
//bool sortbysec(const pll &a, const pll &b)
//{
//    return (a.second < b.second);
//}
//double binet(unsigned int n)
//{
//    static const double phi = (1 + sqrt(5))*0.5;
//    double fib = (pow(phi,n) - pow(1-phi,n))/sqrt(5);
//    return round(fib);
//}
int main()
{
    IO
    ll n, cnt = 0;
    cin >> n;
    double x[n], y[n];
    REP(i, 0, n)
        cin >> x[i] >> y[i];
    if(n < 3)
    {
        cout << 0;
        return 0;
    }
    REP(i, 0, n)
    {
        map <double, bl> mp;
        REP(j, i + 1, n)
        {
            if(x[j] - x[i] == 0)
            {
                if(mp[1000000] == 0)
                    mp[1000000] = 1;
                else
                    cnt++;
            }
            else
            {
                double slope = (y[j] - y[i]) / (x[j] - x[i]);
                if(mp[slope] == 0)
                    mp[slope] = 1;
                else
                    cnt++;
            }
        }
    }
    cout << ncr(n, 3) - cnt;
    return 0;
}


//**KISS**
//**KEEP IT SHORT AND SIMPLE**

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <tuple>
#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 INF 1000000000
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
#define PB push_back
#define Summation(n) (n) * ((n) + 1) / 2
#define ALL(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef pair <long long, long long> pll;
typedef queue <long long> qll;
typedef deque <long long> dll;
typedef set <long long> sll;
typedef set <string> ss;
typedef set <char> sc;
typedef unordered_set <long long> usll;
typedef multiset <long long> msll;
typedef unordered_multiset <long long> umsll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef map <string, bool> msb;
typedef map <string, long long> msl;
typedef map <char, bool> mcb;
typedef map <char, long long> mcl;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//double pi = 2 * acos(0.0);

//ll _sieve_size;
//bitset<10000010> _bs;
//vll _primes;
//void sieve(ll upperbound)
//{
//    //O(N log log N)
//    _sieve_size = upperbound;
//    _bs.set();
//    _bs[0] = _bs[1] = 0;
//    for(ll i = 2;i <= _sieve_size;i++)
//        if(_bs[i])
//        {
//            for(ll j = i * i;j <= _sieve_size;j+=i)
//                _bs[j] = 0;
//            _primes.push_back(i);
//        }
//}
//bool isPrime(ll N)
//{
//    if(N <= _sieve_size)    return _bs[N];
//    for(int i = 0;i < _primes.size();i++)
//        if(N % _primes[i] == 0) return false;
//    return true;
//}
//vll primeFactors(ll N)
//{
//    //O( sqrt(N) /ln sqrt(N))
//    vll factors;
//    ll PF_idx = 0, PF = _primes[PF_idx];
//    //sieve should generate primes first
//    while(PF * PF <= N)
//    {
//        while(N % PF == 0)
//        {
//            N /= PF;
//            factors.push_back(PF);
//        }
//        PF = _primes[++PF_idx];
//    }
//    //if N itself is Prime
//    if(N != 1)  factors.push_back(N);
//    return factors;
//}
//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)); }
//long long FastPower(long long Num, long long Pow)
//{
//    if(Pow == 0)
//        return 1;
//    if(Pow == 1)
//        return Num;
//    long long Result = FastPower(Num, Pow / 2);
//    Result *= Result;
//    if(Pow % 2 != 0)
//        Result *= Num;
//    return Result;
//}
//long long power(long long x, unsigned long long y, long long mod)
//{
//    long long temp;
//    if( y == 0)
//        return 1;
//    temp = power(x, y/2,mod)%mod;
//    if (y%2 == 0)
//        return (temp%mod*temp%mod)%mod;
//    else
//        return((x%mod*temp)%mod*temp)%mod;
//}
ll ncr(ll n, ll r)
{
    r = min(r, n - r);
    ll ans = 1;
    for(int i = 1;i <= r;i++)
    {
        ans *= n - i + 1;
        ans /= i;
    }
    return ans;
}
//bool isPowerOfTwo(int x)
//{
//    // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
//    return (x && !(x & (x - 1)));
//}
//bool sortbysec(const pll &a, const pll &b)
//{
//    return (a.second < b.second);
//}
//double binet(unsigned int n)
//{
//    static const double phi = (1 + sqrt(5))*0.5;
//    double fib = (pow(phi,n) - pow(1-phi,n))/sqrt(5);
//    return round(fib);
//}
int main()
{
    IO
    ll n;
    cin >> n;
    ll x[n], y[n], sum = ncr(n, 3);
    map <pll, bl> mp;
    REP(i, 0, n)
    {
        cin >> x[i] >> y[i];
        mp[{x[i], y[i]}] = 1;
    }
    if(n < 3)
    {
        cout << 0;
        return 0;
    }
    REP(i, 0, n)
        REP(j, i + 1, n)
        {
            ll y3 = 2 * y[j] - y[i];
            ll x3 = 2 * x[j] - x[i];
            if(mp[{x3, y3}])
                sum--;
        }
    cout << sum;
    return 0;
}