#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=int(a); i<int(b); i++)
#define FORC(v,it) for(auto it=v.begin();it!=v.end();++it)
#define pb push_back
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(c) ((int)c.size())
#define ff first
#define ss second
#define debug(s) cout<< #s <<" = "<< s <<endl
#define debugarr(arr, n) cout<< #arr << " = "; for(int i = 0; i < n; i++) {cout<<arr[i]<<" \n"[i == n - 1]; }
#define debugc(c) cout << #c << " = "; for(auto x : c) cout<<x<<" "; cout << endl
const long long maxN = 5e3+5, MOD = 1e9+7, INF = 1e14 + 1;
const double PI = acos(-1), eps = 1e-7;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

int n, a, b;
string s;
int dp[maxN];

vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    z[0] = n;
    return z;
}

int solve(int ind){
    if(ind < 0) return 0;

    int &ret = dp[ind];
    if(~ret){
        return ret;
    }

    ret = a + solve(ind-1);

    string pref = s.substr(0, ind + 1);
    reverse( all(pref) ) ;

    vi z = z_function( pref );

    int fr[maxN];
    mem(fr, 0);

    FOR(i,0,sz(pref)){
        fr[z[i]]++;
    }

    FOR(i,0,ind + 1){
        fr[z[i]]--;

        if(fr[i+1]){
            //cout << "entra"  << endl;
            //cout << "hay un substring de tamano " << i + 1 << endl;
            ret = min(ret, b + solve(ind - i - 1) );
        }

    }

    return ret;

}

int main() {

    //ios_base::sync_with_stdio(false), cin.tie(NULL);

    cin >> n >> a >> b >> s;

    mem(dp, -1);

    cout << solve(n - 1) << endl;

	return 0;

}

//    FOR(i,0,n){
//        FOR(j,0,m){
//            cout << dp[i][j] << " ";
//        }cout << endl;
//    }


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=int(a); i<int(b); i++)
#define FORC(v,it) for(auto it=v.begin();it!=v.end();++it)
#define pb push_back
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(c) ((int)c.size())
#define ff first
#define ss second
#define debug(s) cout<< #s <<" = "<< s <<endl
#define debugarr(arr, n) cout<< #arr << " = "; for(int i = 0; i < n; i++) {cout<<arr[i]<<" \n"[i == n - 1]; }
#define debugc(c) cout << #c << " = "; for(auto x : c) cout<<x<<" "; cout << endl
const long long maxN = 5e3+5, MOD = 1e9+7, INF = 1e14 + 1;
const double PI = acos(-1), eps = 1e-7;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

int n, a, b;
string s;
int z[maxN];
int dp[maxN];
int fr[maxN];

void z_function(string s) {
    int n = (int) s.length();

    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    z[0] = n;
}

int solve(int ind){
    if(ind < 0) return 0;

    int &ret = dp[ind];
    if(~ret){
        return ret;
    }

    ret = a + solve(ind-1);

    string pref = s.substr(0, ind + 1);
    reverse( all(pref) ) ;
    z_function( pref );
    mem(fr, 0);

    FOR(i,0,sz(pref)){
        fr[z[i]]++;
    }

    FOR(i,0,ind + 1){
        fr[z[i]]--;

        if(fr[i+1]){
            //cout << "entra"  << endl;
            //cout << "hay un substring de tamano " << i + 1 << endl;
            ret = min(ret, b + solve(ind - i - 1) );
        }

    }

    return ret;

}

int main() {

    ios_base::sync_with_stdio(false), cin.tie(NULL);

    cin >> n >> a >> b >> s;

    mem(dp, -1);

    cout << solve(n - 1) << endl;

	return 0;

}

//    FOR(i,0,n){
//        FOR(j,0,m){
//            cout << dp[i][j] << " ";
//        }cout << endl;
//    }


#pragma warning(disable : 4996)

#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <climits>
#include <stack>
#include <set>
#include <cstring>
#include <map>
#include <cassert>
#include <bitset>
#include <chrono>
#include <fstream>
#include <ctime>

using namespace std;

#define DINF (1. / 0.)
#define INF (int)1e9
#define LINF (long long)1e18

typedef long double ldouble;

long long __gcd(long long a, long long b)
{
	while (a != 0)
	{
		long long __t = b % a;
		b = a;
		a = __t;
	}
	return b;
}

void prefFunc(const string& s, set<unsigned>& ans)
{
	unsigned N = s.size();
	vector<unsigned> pi(N);

	for (unsigned i = 1; i < N; i++)
	{
		unsigned j = pi[i - 1];
		while (j > 0 && s[i] != s[j]) j = pi[j - 1];
		pi[i] = j + (s[i] == s[j]);

		if (pi[i] && 2 * pi[i] <= i + 1)
			ans.insert(pi[i]);
	}
}

int main()
{
	cin.tie(); cout.tie(); cerr.tie();
	ios_base::sync_with_stdio(false);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	unsigned N; cin >> N;
	long long ca, cb; cin >> ca >> cb;

	string s; cin >> s;
	vector<long long> d(N, LINF);

	vector<set<unsigned> > can(N);

	{
		string rs;
		for (unsigned i = 0; i < N; i++)
			prefFunc((rs = s[i] + rs), can[i]);
	}

	for (unsigned i = 0; i < N; i++)
	{
		for (auto& v : can[i])
		{
			bool f = false;
			for (unsigned j = 0; j + v + v <= i + 1 && !f; j++)
				if (s.substr(j, v) == s.substr(i - v + 1, v))
					f = true;
			assert(f);
		}
	}

	d[0] = ca;
	for (unsigned i = 1; i < N; i++)
	{
		d[i] = d[i - 1] + ca;
		for (auto& v : can[i])
			d[i] = min(d[i], d[i - v] + cb);
	}

	cout << d.back();

	return 0;
}


#pragma warning(disable : 4996)

#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <climits>
#include <stack>
#include <set>
#include <cstring>
#include <map>
#include <cassert>
#include <bitset>
#include <chrono>
#include <fstream>
#include <ctime>

using namespace std;

#define DINF (1. / 0.)
#define INF (int)1e9
#define LINF (long long)1e18

typedef long double ldouble;

long long __gcd(long long a, long long b)
{
	while (a != 0)
	{
		long long __t = b % a;
		b = a;
		a = __t;
	}
	return b;
}

void prefFunc(const string& s, set<unsigned>& ans)
{
	unsigned N = s.size();
	vector<unsigned> pi(N);

	for (unsigned i = 1; i < N; i++)
	{
		unsigned j = pi[i - 1];
		while (j > 0 && s[i] != s[j]) j = pi[j - 1];
		pi[i] = j + (s[i] == s[j]);

		if (pi[i] && 2 * pi[i] <= i + 1)
			ans.insert(pi[i]);
	}
}

int main()
{
	cin.tie(); cout.tie(); cerr.tie();
	ios_base::sync_with_stdio(false);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	unsigned N; cin >> N;
	long long ca, cb; cin >> ca >> cb;

	string s; cin >> s;
	vector<long long> d(N, LINF);

	vector<set<unsigned> > can(N);

	{
		string rs;
		for (unsigned i = 0; i < N; i++)
			prefFunc((rs = s[i] + rs), can[i]);
	}
	/*
	for (unsigned i = 0; i < N; i++)
	{
		for (auto& v : can[i])
		{
			bool f = false;
			for (unsigned j = 0; j + v + v <= i + 1 && !f; j++)
				if (s.substr(j, v) == s.substr(i - v + 1, v))
					f = true;
			assert(f);
		}
	}
	*/
	d[0] = ca;
	for (unsigned i = 1; i < N; i++)
	{
		d[i] = d[i - 1] + ca;
		for (auto& v : can[i])
			d[i] = min(d[i], d[i - v] + cb);
	}

	cout << d.back();

	return 0;
}


#pragma warning(disable : 4996)

#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <climits>
#include <stack>
#include <set>
#include <cstring>
#include <map>
#include <cassert>
#include <bitset>
#include <chrono>
#include <fstream>
#include <ctime>

using namespace std;

#define DINF (1. / 0.)
#define INF (int)1e9
#define LINF (long long)1e18

typedef long double ldouble;

long long __gcd(long long a, long long b)
{
	while (a != 0)
	{
		long long __t = b % a;
		b = a;
		a = __t;
	}
	return b;
}

unsigned prefFunc(const string& s)
{
	unsigned N = s.size();
	vector<unsigned> z(N);

	unsigned till = 0;
	for (unsigned i = 1, l = 0, r = 0; i < N; i++)
	{
		if (i <= r)
			z[i] = min(r - i + 1, z[i - l]);
		while (i + z[i] < N && s[z[i]] == s[i + z[i]]) z[i]++;
		if (i + z[i] - 1 > r)
			l = i, r = i + z[i] - 1;

		till = max(till, min(z[i], i));
	}

	return till;
}

int main()
{
	cin.tie(); cout.tie(); cerr.tie();
	ios_base::sync_with_stdio(false);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	unsigned N; cin >> N;
	long long ca, cb; cin >> ca >> cb;

	string s; cin >> s;
	vector<long long> d(N, LINF);

	vector<unsigned> can(N);

	{
		string rs;
		for (unsigned i = 0; i < N; i++)
			can[i] = prefFunc(rs = s[i] + rs);
	}

	d[0] = ca;
	for (unsigned i = 1; i < N; i++)
	{
		d[i] = d[i - 1] + ca;
		for (unsigned v = 1; v <= can[i]; v++)
			d[i] = min(d[i], d[i - v] + cb);
	}

	cout << d.back();

	return 0;
}


#pragma warning(disable : 4996)

#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <climits>
#include <stack>
#include <set>
#include <cstring>
#include <map>
#include <cassert>
#include <bitset>
#include <chrono>
#include <fstream>
#include <ctime>

using namespace std;

#define DINF (1. / 0.)
#define INF (int)1e9
#define LINF (long long)1e18

typedef long double ldouble;

long long __gcd(long long a, long long b)
{
	while (a != 0)
	{
		long long __t = b % a;
		b = a;
		a = __t;
	}
	return b;
}

void prefFunc(const string& s, set<unsigned>& ans)
{
	unsigned N = s.size();
	vector<unsigned> z(N);

	for (unsigned i = 1, l = 0, r = 0; i < N; i++)
	{
		if (i <= r)
			z[i] = min(r - i + 1, z[i - l]);
		while (i + z[i] < N && s[z[i]] == s[i + z[i]]) z[i]++;
		if (i + z[i] - 1 > r)
			l = i, r = i + z[i] - 1;

		for (unsigned k = 1; k <= z[i]; k++)
		{
			if (i >= k)
				ans.insert(k);
		}
	}

	z.back() = 0;
}

int main()
{
	cin.tie(); cout.tie(); cerr.tie();
	ios_base::sync_with_stdio(false);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	unsigned N; cin >> N;
	long long ca, cb; cin >> ca >> cb;

	string s; cin >> s;
	vector<long long> d(N, LINF);

	vector<set<unsigned> > can(N);

	{
		string rs;
		for (unsigned i = 0; i < N; i++)
			prefFunc((rs = s[i] + rs), can[i]);
	}

	for (unsigned i = 0; i < N; i++)
	{
		for (auto& v : can[i])
		{
			bool f = false;
			for (unsigned j = 0; j + v + v <= i + 1 && !f; j++)
				if (s.substr(j, v) == s.substr(i - v + 1, v))
					f = true;
			assert(f);
		}
	}

	d[0] = ca;
	for (unsigned i = 1; i < N; i++)
	{
		d[i] = d[i - 1] + ca;
		for (auto& v : can[i])
			d[i] = min(d[i], d[i - v] + cb);
	}

	cout << d.back();

	return 0;
}


#pragma warning(disable : 4996)

#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <climits>
#include <stack>
#include <set>
#include <cstring>
#include <map>
#include <cassert>
#include <bitset>
#include <chrono>
#include <fstream>
#include <ctime>

using namespace std;

#define DINF (1. / 0.)
#define INF (int)1e9
#define LINF (long long)1e18

typedef long double ldouble;

long long __gcd(long long a, long long b)
{
	while (a != 0)
	{
		long long __t = b % a;
		b = a;
		a = __t;
	}
	return b;
}

void prefFunc(const string& s, set<unsigned>& ans)
{
	unsigned N = s.size();
	vector<unsigned> z(N);

	for (unsigned i = 1, l = 0, r = 0; i < N; i++)
	{
		if (i <= r)
			z[i] = min(r - i + 1, z[i - l]);
		while (i + z[i] < N && s[z[i]] == s[i + z[i]]) z[i]++;
		if (i + z[i] - 1 > r)
			l = i, r = i + z[i] - 1;

		for (unsigned k = 1; k <= z[i]; k++)
		{
			if (i >= k)
				ans.insert(k);
		}
	}

	z.back() = 0;
}

int main()
{
	cin.tie(); cout.tie(); cerr.tie();
	ios_base::sync_with_stdio(false);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	unsigned N; cin >> N;
	long long ca, cb; cin >> ca >> cb;

	string s; cin >> s;
	vector<long long> d(N, LINF);

	vector<set<unsigned> > can(N);

	{
		string rs;
		for (unsigned i = 0; i < N; i++)
			prefFunc((rs = s[i] + rs), can[i]);
	}
	/*
	for (unsigned i = 0; i < N; i++)
	{
		for (auto& v : can[i])
		{
			bool f = false;
			for (unsigned j = 0; j + v + v <= i + 1 && !f; j++)
				if (s.substr(j, v) == s.substr(i - v + 1, v))
					f = true;
			assert(f);
		}
	}
	*/
	d[0] = ca;
	for (unsigned i = 1; i < N; i++)
	{
		d[i] = d[i - 1] + ca;
		for (auto& v : can[i])
			d[i] = min(d[i], d[i - v] + cb);
	}

	cout << d.back();

	return 0;
}


#pragma warning(disable : 4996)

#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <climits>
#include <stack>
#include <set>
#include <cstring>
#include <map>
#include <cassert>
#include <bitset>
#include <chrono>
#include <fstream>
#include <ctime>

using namespace std;

#define DINF (1. / 0.)
#define INF (int)1e9
#define LINF (long long)1e18

typedef long double ldouble;

long long __gcd(long long a, long long b)
{
	while (a != 0)
	{
		long long __t = b % a;
		b = a;
		a = __t;
	}
	return b;
}

vector<unsigned> prefFunc(const string& s)
{
	unsigned N = s.size();
	vector<unsigned> pi(N);

	for (unsigned i = 1; i < N; i++)
	{
		unsigned j = pi[i - 1];
		while (j > 0 && s[i] != s[j]) j = pi[j - 1];
		pi[i] = j + (s[i] == s[j]);
	}

	return pi;
}

int main()
{
	cin.tie(); cout.tie(); cerr.tie();
	ios_base::sync_with_stdio(false);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	unsigned N; cin >> N;
	long long ca, cb; cin >> ca >> cb;

	string s; cin >> s;
	vector<long long> d(N, LINF);

	vector<vector<unsigned> > can(N);
	for (unsigned i = 0; i < N; i++)
	{
		string rs = s.substr(0, i + 1);
		reverse(rs.begin(), rs.end());

		vector<unsigned> pi = prefFunc(rs);
		for (auto& v : pi)
			if (v && i + 1 >= v + v)
				can[i].push_back(v);

		sort(can[i].begin(), can[i].end());
		can[i].resize(unique(can[i].begin(), can[i].end()) - can[i].begin());
	}

	d[0] = ca;
	for (unsigned i = 1; i < N; i++)
	{
		d[i] = d[i - 1] + ca;

		for (auto& v : can[i])
			d[i] = min(d[i], d[i - v] + cb);
	}

	cout << d.back();

	return 0;
}


#include<bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
#define debug_call() cout << __PRETTY_FUNCTION__ << endl
#define __fast_io__ \
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define time_now \
	chrono::high_resolution_clock::now()

#define time_diff(T) \
	chrono::duration_cast<chrono::microseconds>(t2-t1).count()

#define get_max(a,b) a=max(a,b)
#define get_min(a,b) a=min(a,b)

using namespace std;
typedef long long ll;
typedef long double ld;

const int oo=0x7fffffff;
const ll  OO=0x7fffffffffffffff;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int upper_2(int n){
	int k=0,l=1;
	for(;l<n;k++,l*=2);
	return k;
}
struct suffix_array {
	int N,K; string s;
	vector< vector<int> > rank;
	vector<int> pos;
	suffix_array(const string& _S):
		N(_S.size()),K(1+upper_2(N)),s(_S), rank(K, vector<int>(N) ),pos(N,0)
	{
		if(N==1){rank[0][0]=1; return;}

		for(int i=0;s[i];++i) rank[0][i]=s[i];

		vector<int> id(N),v1(N),v2(N);

		for(int k=1,L=1;k<K;++k, L*=2){
			for(int i=0;i<N;++i){
				id[i]=i;
				v1[i]=rank[k-1][i];v2[i]= 0;
				if(i+L<N) v2[i]=rank[k-1][i+L];
			}
			rsort(id,v2);
			rsort(id,v1);
			rank[k][ id[0]  ]=1;
			for(int i=1,r=1;i<N;++i){
				if( v1[id[i]] != v1[id[i-1]] or v2[id[i]]!=v2[id[i-1]]  ) r++;
				rank[k][ id[i] ]=r;
			}
		}

		for(int i=0;i<N;++i)pos[rank[K-1][i]-1]=i;
	}
	const char* operator[](int i){return s.c_str()+pos[i];}
	int size(){return N;}
	void rsort(vector<int>& id,const vector<int>& v){
		vector<int> tid(N),ct( max(N+1,256)  ,0);
		for(auto x: v) ct[x]++;
		for(int i=1;i<ct.size();++i) ct[i] += ct[i-1];

		for(int i=N-1;i>=0;--i)	tid[ --ct[ v[id[i] ] ] ] = id[i];
		copy(tid.begin(),tid.end(),id.begin());
	}
	int lcp(int i,int j){ // i,j from 0 to N-1
		if(i==j)return N-i;
		int l=0,d=1<<(K-1);
		for(int k=K-1;k>=0 and i<N and j<N; --k,d>>=1)
			if(rank[k][i]==rank[k][j])
				l += d, i += d, j+= d;
		return l;
	}
};

const int NX=5005;
int best[NX];
char is_sub[NX][NX];

int main(){
	__fast_io__;
	int n,a,b;
	string s;
	cin>>n>>a>>b>>s;
	reverse(s.begin(),s.end());

	suffix_array sa(s);

	for(int i=1,k;i<=n;++i){
		best[i]=best[i-1]+a;

		k=i;
		// compute k
		// k is the index (starting at 0) of the longest
		// suffix of s[:i] such that s[k:i] substring of s[:k]
		for(int j=1,p,l;j<=n;++j){
			l = sa.lcp(n-i,n-j);
			p = i-l;
			if(p>=j) get_min(k,p);
		}

		// for every j>=k: s[j:i] \sub s[k:i] \sub s[:k] \sub s[:j]
		for(int j=k;j<=i;++j)
			get_min(best[i],best[j]+b);
	}//O(N^2 log N)
	cout<< best[n] << endl;
	return 0;
}


#include<bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
#define debug_call() cout << __PRETTY_FUNCTION__ << endl
#define __fast_io__ \
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define time_now \
	chrono::high_resolution_clock::now()

#define time_diff(T) \
	chrono::duration_cast<chrono::microseconds>(t2-t1).count()

#define get_max(a,b) a=max(a,b)
#define get_min(a,b) a=min(a,b)

using namespace std;
typedef long long ll;
typedef long double ld;

const int oo=0x7fffffff;
const ll  OO=0x7fffffffffffffff;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int upper_2(int n){
	int k=0,l=1;
	for(;l<n;k++,l*=2);
	return k;
}
struct suffix_array {
	int N,K; string s;
	vector< vector<int> > rank;
	vector<int> pos;
	suffix_array(const string& _S):
		N(_S.size()),K(1+upper_2(N)),s(_S), rank(K, vector<int>(N) ),pos(N,0)
	{
		if(N==1){rank[0][0]=1; return;}

		for(int i=0;s[i];++i) rank[0][i]=s[i];

		vector<int> id(N),v1(N),v2(N);

		for(int k=1,L=1;k<K;++k, L*=2){
			for(int i=0;i<N;++i){
				id[i]=i;
				v1[i]=rank[k-1][i];v2[i]= 0;
				if(i+L<N) v2[i]=rank[k-1][i+L];
			}
			rsort(id,v2);
			rsort(id,v1);
			rank[k][ id[0]  ]=1;
			for(int i=1,r=1;i<N;++i){
				if( v1[id[i]] != v1[id[i-1]] or v2[id[i]]!=v2[id[i-1]]  ) r++;
				rank[k][ id[i] ]=r;
			}
		}

		for(int i=0;i<N;++i)pos[rank[K-1][i]-1]=i;
	}
	const char* operator[](int i){return s.c_str()+pos[i];}
	int size(){return N;}
	void rsort(vector<int>& id,const vector<int>& v){
		vector<int> tid(N),ct( max(N+1,256)  ,0);
		for(auto x: v) ct[x]++;
		for(int i=1;i<ct.size();++i) ct[i] += ct[i-1];

		for(int i=N-1;i>=0;--i)	tid[ --ct[ v[id[i] ] ] ] = id[i];
		copy(tid.begin(),tid.end(),id.begin());
	}
	int lcp(int i,int j){ // i,j from 0 to N-1
		if(i==j)return N-i;
		int l=0,d=1<<(K-1);
		for(int k=K-1;k>=0 and i<N and j<N; --k,d>>=1)
			if(rank[k][i]==rank[k][j])
				l += d, i += d, j+= d;
		return l;
	}
};

const int NX=5005;
int best[NX];
char is_sub[NX][NX];

int main(){
	__fast_io__;
	int n,a,b;
	string s;
	cin>>n>>a>>b>>s;
	reverse(s.begin(),s.end());

	suffix_array sa(s);

	for(int i=1,k;i<=n;++i){
		best[i]=best[i-1]+a;

		k=i;
		// compute k
		// k is the index (starting at 0) of the longest
		// suffix of s[:i] such that s[k:i] substring of s[:k]
		for(int j=1,p,l;j<=i;++j){
			l = sa.lcp(n-i,n-j);
			p = i-l;
			if(p>=j) get_min(k,p);
		}

		// for every j>=k: s[j:i] \sub s[k:i] \sub s[:k] \sub s[:j]
		for(int j=k;j<=i;++j)
			get_min(best[i],best[j]+b);
	}//O(N^2 log N)
	cout<< best[n] << endl;
	return 0;
}


#include <bits/stdc++.h>

#define endl "\n"
#define openfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define faster cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define sp << " " <<

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int INF = 1'000'000'000;
const ll INFLL = 1'000'000'000'000'000'000LL;
const int MAX = 600'000;

int n, a, b;
vector <int> d;
string s, prv, tt;

vector <int> pref;

void pref_func(string &p) {
    pref[0] = 0;
    for (int i = 1; i < p.size(); i++) {
        int j = pref[i-1];
        while (j > 0 && p[i] != p[j]) {
            j = pref[j-1];
        }
        if (p[i] == p[j]) { j++; }
        pref[i] = j;
    }
}

bool findin(string &p, string &t) {
    string news = t + "_" + p;
    pref.resize(news.size());
    for (int i = 0; i < pref.size(); i++) {
        pref[i] = 0;
    }

    pref_func(news);

//    cerr << news << endl;
//    for (auto i : pref) {
//        cerr << i << " ";
//    }   cerr << endl;

    for (int i = t.size()+1; i < news.size(); i++) {
        if (pref[i] == t.size()) {
            return true;
        }
    }
    return false;
}

void dp(int pos) {
    if (pos == n) {
        d[pos] = 0;
        return;
    }
    if (d[pos] != -1) {
        return;
    }

    int l = 1, r = n - pos;
    while (l < r) {
        int c = (l + r) / 2;
        tt = s.substr(pos, c);
        if (findin(prv, tt)) {
            l = c + 1;
        } else {
            r = c;
        }
    }

    tt = s.substr(pos, l);
    if (!findin(prv, tt)) {
        l--;
    }

    prv.push_back(s[pos]);
    dp(pos+1);
    prv.pop_back();
    d[pos] = d[pos+1] + a;

    if (l > 0) {
        prv = prv + s.substr(pos, l);
        dp(pos+l);
        prv.erase(pos, l);

        d[pos] = min(d[pos], d[pos+l] + b);
    }

    return;
}

signed main()
{
//    openfiles;
    faster;

//    string p, t;
//    cin >> p >> t;
//
//    cout << "lox" sp findin(p, t) << endl;
//    return 0;

    cin >> n >> a >> b;

    d.resize(n+100, -1);
    cin >> s;

    dp(0);
    cout << d[0] << endl;

    return 0;
}


#include <bits/stdc++.h>

#define endl "\n"
#define openfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define faster cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define sp << " " <<

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int INF = 1'000'000'000;
const ll INFLL = 1'000'000'000'000'000'000LL;
const int MAX = 600'000;

int n, a, b;
vector <int> d;
string s, prv;

void dp(int pos) {
    if (pos == n) {
        d[pos] = 0;
        return;
    }
    if (d[pos] != -1) {
        return;
    }

    int l = 1, r = n - pos;
    while (l < r) {
        int c = (l + r) / 2;
        if (prv.find(s.substr(pos, c)) != string::npos) {
            l = c + 1;
        } else {
            r = c;
        }
    }

    if (prv.find(s.substr(pos, l)) == string::npos) {
        l--;
    }

    prv.push_back(s[pos]);
    dp(pos+1);
    prv.pop_back();
    d[pos] = d[pos+1] + a;

    if (l > 0) {
        prv = prv + s.substr(pos, l);
        dp(pos+l);
        prv.erase(pos, l);

        d[pos] = min(d[pos], d[pos+l] + b);
    }

    return;
}

signed main()
{
//    openfiles;
    faster;

    cin >> n >> a >> b;

    d.resize(n+100, -1);
    cin >> s;

    dp(0);
    cout << d[0] << endl;

    return 0;
}


#include <bits/stdc++.h>

#define endl "\n"
#define openfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define faster cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define sp << " " <<

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int INF = 1'000'000'000;
const ll INFLL = 1'000'000'000'000'000'000LL;
const int MAX = 600'000;

int n, a, b;
vector <int> d;
string s, prv;

void dp(int pos) {
    if (pos == n) {
        d[pos] = 0;
        return;
    }
    if (d[pos] != -1) {
        return;
    }

    int l = 1, r = n - pos;
    while (l < r) {
        int c = (l + r) / 2;
        if (prv.find(s.substr(pos, c)) != string::npos) {
            l = c + 1;
        } else {
            r = c;
        }
    }

    if (prv.find(s.substr(pos, l)) == string::npos) {
        l--;
    }

    prv.push_back(s[pos]);
    dp(pos+1);
    prv.pop_back();
    d[pos] = d[pos+1] + a;

    if (l > 0) {
        prv = prv + s.substr(pos, l);
        dp(pos+l);
        prv.erase(pos, l);

        d[pos] = min(d[pos], d[pos+l] + b);
    }

    return;
}

signed main()
{
    openfiles;
    faster;

    cin >> n >> a >> b;

    d.resize(n+100, -1);
    cin >> s;

    dp(0);
    cout << d[0] << endl;

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/STACK:32000000")
#pragma GCC optimize("O3")

#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <cassert>
#include <fstream>
#include <map>
#include <unordered_map>
#include <deque>
#include <unordered_set>

using namespace std;

#define inf 1000000007
#define eps 1e-11
#define mp(a, b) make_pair(a, b)
#define llinf 1000000000000000007LL

typedef long long ll;
typedef unsigned u;
typedef long double ld;
typedef unsigned char uc;
typedef unsigned long long ull;

const int c1 = 227, mod1 = 1'000'000'007;
const int c2 = 229, mod2 = 1'000'000'009;

vector <int> to[5005];
string str;
int n, a, b;
int dp[5005];
int pows1[5005];
int pows2[5005];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(0);
	cout.sync_with_stdio(0);
	cout.precision(9);
	srand(time(0));
	cin >> n >> a >> b >> str;
	pows1[0] = pows2[0] = 1;
	for (int i = 1; i < 5005; i++) {
		pows1[i] = (1LL * pows1[i - 1] * c1) % mod1;
		pows2[i] = (1LL * pows2[i - 1] * c2) % mod2;
	}

	for (int len = 1; len <= n / 2; len++) {
		vector <pair <int, int>> add(n, { -1,-1 });
		set <pair <int,int>> available;
		int h1 = 0, h2 = 0;
		for (int i = 0; i < len; i++) {
			h1 = (1LL * h1 * c1 + str[i]) % mod1;
			h2 = (1LL * h2 * c2 + str[i]) % mod2;
		}
		for (int i = len; i < n; i++) {
			add[i] = { h1,h2 };
			if (add[i - len + 1].first != -1) {
				available.insert(add[i - len + 1]);
			}
			h1 = ((1LL * h1 * c1 - 1LL * str[i - len] * pows1[len] + str[i]) % mod1 + mod1) % mod1;
			h2 = ((1LL * h2 * c2 - 1LL * str[i - len] * pows2[len] + str[i]) % mod2 + mod2) % mod2;
			if (available.count({ h1,h2 })) {
				to[i - len + 1].push_back(len);
			}
		}
	}

	for (int i = 1; i <= n; i++) {
		dp[i] = inf;
	}

	for (int i = 0; i < n; i++) {
		dp[i + 1] = min(dp[i + 1], dp[i] + a);
		for (auto &j : to[i]) {
			dp[i + j] = min(dp[i + j], dp[i] + b);
		}
	}
	cout << dp[n];
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/STACK:32000000")
#pragma GCC optimize("O3")

#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <cassert>
#include <fstream>
#include <map>
#include <unordered_map>
#include <deque>
#include <unordered_set>

using namespace std;

#define inf 1000000007
#define eps 1e-11
#define mp(a, b) make_pair(a, b)
#define llinf 1000000000000000007LL

typedef long long ll;
typedef unsigned u;
typedef long double ld;
typedef unsigned char uc;
typedef unsigned long long ull;

const int c1 = 227, mod1 = 1'000'000'007;

int n, a, b;
string str;
int dp[5005];
int hh1[5005][5005];
unordered_set <int> used[5005];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(0);
	cout.sync_with_stdio(0);
	cout.precision(9);
	srand(time(0));
	cin >> n >> a >> b >> str;
	str = '#' + str;
	for (int i = 0; i <= n + 1; i++) {
		dp[i] = inf;
	}
	dp[1] = 0;
	for (int i = 1; i <= n; i++) {
		dp[i + 1] = min(dp[i + 1], dp[i] + a);
		int h1 = 0;
		for (int j = 0; i + j <= n; j++) {
			h1 = (1LL * h1 * c1 + str[i + j]) % mod1;
			if (used[j + 1].count(h1)) {
				dp[i + j + 1] = min(dp[i + j + 1], dp[i] + b);
			}
		}
		for (int j = 0; j <= i; j++) {
			hh1[j][i] = (1LL * hh1[j][i - 1] * c1 + str[i]) % mod1;
			used[i - j + 1].insert(hh1[j][i]);
		}
	}
	cout << dp[n + 1];
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/STACK:32000000")
#pragma GCC optimize("O3")

#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <cassert>
#include <fstream>
#include <map>
#include <unordered_map>
#include <deque>
#include <unordered_set>

using namespace std;

#define inf 1000000007
#define eps 1e-11
#define mp(a, b) make_pair(a, b)
#define llinf 1000000000000000007LL

typedef long long ll;
typedef unsigned u;
typedef long double ld;
typedef unsigned char uc;
typedef unsigned long long ull;

const int c1 = 227, mod1 = 1'000'000'007;

vector <int> to[5005];
string str;
int n, a, b;
int dp[5005];
int pows[5005];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(0);
	cout.sync_with_stdio(0);
	cout.precision(9);
	srand(time(0));
	cin >> n >> a >> b >> str;
	pows[0] = 1;
	for (int i = 1; i < 5005; i++) {
		pows[i] = (1LL * pows[i - 1] * c1) % mod1;
	}

	for (int len = 1; len <= n / 2 + 1; len++) {
		vector <int> add(n, -1);
		unordered_set <int> available;
		int h = 0;
		for (int i = 0; i < len; i++) {
			h = (1LL * h * c1 + str[i]) % mod1;
		}
		for (int i = len; i < n; i++) {
			add[i] = h;
			if (add[i - len + 1] != -1) {
				available.insert(add[i - len + 1]);
			}
			h = ((1LL * h * c1 - 1LL * str[i - len] * pows[len] + str[i]) % mod1 + mod1) % mod1;
			if (available.count(h)) {
				to[i - len + 1].push_back(len);
			}
		}
	}

	for (int i = 1; i <= n; i++) {
		dp[i] = inf;
	}

	for (int i = 0; i < n; i++) {
		dp[i + 1] = min(dp[i + 1], dp[i] + a);
		for (auto &j : to[i]) {
			dp[i + j] = min(dp[i + j], dp[i] + b);
		}
	}
	cout << dp[n];
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/STACK:32000000")
#pragma GCC optimize("O3")

#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <cassert>
#include <fstream>
#include <map>
#include <unordered_map>
#include <deque>
#include <unordered_set>

using namespace std;

#define inf 1000000007
#define eps 1e-11
#define mp(a, b) make_pair(a, b)
#define llinf 1000000000000000007LL

typedef long long ll;
typedef unsigned u;
typedef long double ld;
typedef unsigned char uc;
typedef unsigned long long ull;

const int c1 = 227, mod1 = 1'000'000'007;
const int c2 = 229, mod2 = 1'000'000'009;

int n, a, b;
string str;
int dp[5005];
int hh1[5005][5005];
int hh2[5005][5005];
set <pair <int, int>> used[5005];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(0);
	cout.sync_with_stdio(0);
	cout.precision(9);
	srand(time(0));
	cin >> n >> a >> b >> str;
	str = '#' + str;
	for (int i = 0; i <= n + 1; i++) {
		dp[i] = inf;
	}
	dp[1] = 0;
	for (int i = 1; i <= n; i++) {
		dp[i + 1] = min(dp[i + 1], dp[i] + a);
		int h1 = 0LL, h2 = 0LL;
		for (int j = 0; i + j <= n; j++) {
			h1 = (1LL * h1 * c1 + str[i + j]) % mod1;
			h2 = (1LL * h2 * c2 + str[i + j]) % mod2;
			if (used[j + 1].count({ h1,h2 })) {
				dp[i + j + 1] = min(dp[i + j + 1], dp[i] + b);
			}
		}
		for (int j = 0; j <= i; j++) {
			hh1[j][i] = (1LL * hh1[j][i - 1] * c1 + str[i]) % mod1;
			hh2[j][i] = (1LL * hh2[j][i - 1] * c2 + str[i]) % mod2;
			used[i - j + 1].insert({ hh1[j][i],hh2[j][i] });
		}
	}
	cout << dp[n + 1];
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/STACK:32000000")
#pragma GCC optimize("O3")

#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <cassert>
#include <fstream>
#include <map>
#include <unordered_map>
#include <deque>
#include <unordered_set>

using namespace std;

#define inf 1000000007
#define eps 1e-11
#define mp(a, b) make_pair(a, b)
#define llinf 1000000000000000007LL

typedef long long ll;
typedef unsigned u;
typedef long double ld;
typedef unsigned char uc;
typedef unsigned long long ull;

const int c1 = 227, mod1 = 100'005;

int n, a, b;
string str;
int dp[5005];
int hh1[5005];
bitset <mod1> used[5005];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(0);
	cout.sync_with_stdio(0);
	cout.precision(9);
	srand(time(0));
	cin >> n >> a >> b >> str;
	str = '#' + str;
	for (int i = 0; i <= n + 1; i++) {
		dp[i] = inf;
	}
	dp[1] = 0;
	for (int i = 1; i <= n; i++) {
		dp[i + 1] = min(dp[i + 1], dp[i] + a);
		int h1 = 0;
		for (int j = 0; i + j <= n; j++) {
			h1 = (1LL * h1 * c1 + str[i + j]) % mod1;
			if (used[j + 1][h1] == 1) {
				dp[i + j + 1] = min(dp[i + j + 1], dp[i] + b);
			}
		}
		for (int j = 0; j <= i; j++) {
			hh1[j] = (1LL * hh1[j] * c1 + str[i]) % mod1;
			used[i - j + 1][hh1[j]] = 1;
		}
	}
	cout << dp[n + 1];
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/STACK:32000000")
#pragma GCC optimize("O3")

#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <cassert>
#include <fstream>
#include <map>
#include <unordered_map>
#include <deque>
#include <unordered_set>

using namespace std;

#define inf 1000000007
#define eps 1e-11
#define mp(a, b) make_pair(a, b)
#define llinf 1000000000000000007LL

typedef long long ll;
typedef unsigned u;
typedef long double ld;
typedef unsigned char uc;
typedef unsigned long long ull;

const int c1 = 227, mod1 = 1'000'000'007;

int n, a, b;
string str;
int dp[5005];
int hh1[5005];
unordered_set <int> used[5005];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(0);
	cout.sync_with_stdio(0);
	cout.precision(9);
	srand(time(0));
	cin >> n >> a >> b >> str;
	str = '#' + str;
	for (int i = 0; i <= n + 1; i++) {
		dp[i] = inf;
	}
	dp[1] = 0;
	for (int i = 1; i <= n; i++) {
		dp[i + 1] = min(dp[i + 1], dp[i] + a);
		int h1 = 0;
		for (int j = 0; i + j <= n; j++) {
			h1 = (1LL * h1 * c1 + str[i + j]) % mod1;
			if (used[j + 1].count(h1)) {
				dp[i + j + 1] = min(dp[i + j + 1], dp[i] + b);
			}
		}
		for (int j = 0; j <= i; j++) {
			hh1[j] = (1LL * hh1[j] * c1 + str[i]) % mod1;
			used[i - j + 1].insert(hh1[j]);
		}
	}
	cout << dp[n + 1];
	return 0;
}


#include <iostream>
using namespace std;
int main(){
unsigned long long int i,t,s[1000],a[1000],b[1000],c[1000],min[1000];
cin>>t;
for(i=0;i<t;i++)
{
    cin>>s[i];
    cin>>a[i];
    cin>>b[i];
    cin>>c[i];
    min[i]=s[i]/c[i]+s[i]/a[i]*b[i];
}
for(i=0;i<t;i++)
    cout<<min[i]<<"\n";
return 0;}


#include <iostream>
using namespace std;
int main(){
int i,t,s[1000],a[1000],b[1000],c[1000],min[1000];
cin>>t;
for(i=0;i<t;i++)
{
    cin>>s[i];
    cin>>a[i];
    cin>>b[i];
    cin>>c[i];
    min[i]=s[i]/c[i]+s[i]/a[i]*b[i];
}
for(i=0;i<t;i++)
    cout<<min[i];
return 0;}


#include <iostream>
using namespace std;
int main(){
unsigned long long int i,t,s[1000],a[1000],b[1000],c[1000],min[1000],f[1000];
cin>>t;
for(i=0;i<t;i++)
{
    cin>>s[i];
    cin>>a[i];
    cin>>b[i];
    cin>>c[i];
    f[i]=s[i]/a[i];
    min[i]=s[i]/c[i]+f[i]*b[i];
}
for(i=0;i<t;i++)
    cout<<min[i]<<"\n";
return 0;}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ll i,j,k,t;
    ll n,a,b,s,c;
    cin>>n;
    for(t=0;t<n;t++){
        cin>>s>>a>>b>>c;
        ll cho=s/c;
        ll freetime=cho*b/a;
        cout<<cho+freetime<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ll i,j,k,t;
    ll n,a,b,s,c;
    cin>>n;
    for(t=0;t<n;t++){
        cin>>s>>a>>b>>c;
        ll cho=s/c;
        ll freetime=cho;
        freetime+=(cho/a)*b;
        cout<<freetime<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ll i,j,k,t;
    ll n,a,b,s,c;
    cin>>n;
    for(t=0;t<n;t++){
        cin>>s>>a>>b>>c;
        ll cho=s/c;
        ll freetime;
        if(cho>=a){
        freetime=(cho*b)/a;
        cout<<cho+freetime<<endl;
        }
        else{
               cout<<cho<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ll i,j,k,t;
    ll n,a,b,s,c;
    cin>>n;
    for(t=0;t<n;t++){
        cin>>s>>a>>b>>c;
        ll cho=s/c;
        ll freetime=(cho*b)/a;
        cout<<cho+freetime<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ll i,j,k,t;
    ll n,a,b,s,c;
    cin>>n;
    for(t=0;t<n;t++){
        cin>>s>>a>>b>>c;
        ll cho=s/c;
        ll freetime=cho;
        while(cho>a){
               freetime+=b;
               cho-=a;
        }
        cout<<freetime<<endl;

    }
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main() {

long long n,s,a,b,c,h;
cin>>n;

for (int i=0;i<n;i++){
  cin>>s>>a>>b>>c;
  h=s/c/a*b*c+s/c;
}
cout<<h;
return(0);
}


#include<iostream>
#include<string>
using namespace std;
int main() {

long long n,s,a,b,c,h;
cin>>n;

for (int i=0;i<n;i++){
  cin>>s>>a>>b>>c;
  h=s/c/a*b*c+s/c;
  cout<<h;
}

return(0);
}


#include<iostream>
#include<string>
using namespace std;
int main() {

long long n,s,a,b,c,h;
cin>>n;

for (int i=0;i<n;i++){
  cin>>s>>a>>b>>c;
  h=s/c/a*b*c+s/c;
  cout<<h<<endl;
}

return(0);
}


#include<iostream>
#include<string>
using namespace std;
int main() {

long long n,s,a,b,c,h;
cin>>n;

for (int i=0;i<n;i++){
  cin>>s>>a>>b>>c;
  h=s/c/a*b+s/c;
  cout<<h<<endl;
}

return(0);
}


#include <iostream>
using namespace std;
long long s,a,b,c;
unsigned long long temp;
int t;
int main()
{
	cin >> t;
	while(t--)
	{
		temp = 0;
		cin >> s >> a >> b >> c;
		temp = (s / a) * b + (s*c);
		cout << temp << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
unsigned long long s,a,b,c;
unsigned long long temp,t,t1,t2;
int main()
{
	cin >> t;
	while(t--)
	{
		temp = 0;
		cin >> s >> a >> b >> c;
		temp = (s / a) * b;
		t2 = s % a;
		t1 = s - t2;
		cout << t1+t2+temp << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
long long s,a,b,c;
unsigned long long temp;
int t;
int t1;
int t2;
int main()
{
	cin >> t;
	while(t--)
	{
		temp = 0;
		cin >> s >> a >> b >> c;
		temp = (s / a) * b;
		t2 = s % a;
		t1 = s - t2;
		cout << t1+t2+temp << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
long long s,a,b,c;
unsigned long long temp;
int t;
int main()
{
	cin >> t;
	while(t--)
	{
		temp = 0;
		cin >> s >> a >> b >> c;
		temp = (s / a) * b + (s/c);
		cout << temp << endl;
	}

	return 0;
}


#include <iostream>
using namespace std;
int t;
unsigned long long s,a,b,c;
unsigned long long temp,csum,fsum;
int main()
{
	cin >> t;
	while(t--)
	{
		temp = 0;
		cin >> s >> a >> b >> c;
		if(s==0)
		{
			cout << "0" << endl;
			continue;
		}
		csum =  s / c;//可以买的总数
		fsum = csum / a * b;//可以换到的总数
		temp = csum + fsum;
		cout << temp << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
int t;
long long s,a,b,c;
int main()
{
	cin >> t;
	while(t--)
	{
		cin >> s >> a >> b >> c;
		cout << s*b + a*b << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
#define Nazar ios_base::sync_with_stdio(0);
#define ll long long
#define r_0 return 0;
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );
using namespace std;
string s,m,z;
ll mx,snt,cnt,ans,mn ;
 ll int   a,b,c,d,e,f,n,q;
int arr[101];
int ar[101];
vector<int>v;
int main ()
{
Nazar
cin >> a;
for ( ll i = 0 ; i < a; i ++)
{
    cin >> b >> c >> d >> e;
    if ( b < e)
    {
        cout << e;
    }
    b = b / e;
    ans+=b;
    cnt = (b / c) * d;
    cout << ans + cnt << endl;
    ans = 0;
    cnt = 0;

}
}

/*as far as my favorite place that i have never been yet, however i want to visit is concerened,
I prefer to go to America,
The followings are the reasons tha will support my choice.
first and faremost, America one of the powerfull country in the world*/


#include<bits/stdc++.h>
#define Nazar ios_base::sync_with_stdio(0);
#define ll long long
#define r_0 return 0;
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );
using namespace std;
string s,m,z;
ll mx,snt,cnt,ans,mn ;
 ll int   a,b,c,d,e,f,n,q;
int arr[101];
int ar[101];
vector<int>v;
int main ()
{
Nazar
cin >> a;
for ( ll i = 0 ; i < a; i ++)
{
    cin >> b >> c >> d >> e;
    if ( b < e)
    {
        cout << e;
    }
    b = b / e;
    ans+=b;
    cnt = (b / c) * d;
    cout << ans + cnt;
    ans = 0;
    cnt = 0;

}
}

/*as far as my favorite place that i have never been yet, however i want to visit is concerened,
I prefer to go to America,
The followings are the reasons tha will support my choice.
first and faremost, America one of the powerfull country in the world*/


#include<bits/stdc++.h>
#define Nazar ios_base::sync_with_stdio(0);
#define ll long long
#define r_0 return 0;
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );
using namespace std;
string s,m,z;
ll mx,snt,cnt,ans,mn ;
 ll int   a,b,c,d,e,f,n,q;
int arr[101];
int ar[101];
vector<int>v;
int main ()
{
Nazar
cin >> a;
for ( ll i = 0 ; i < a; i ++)
{
    cin >> b >> c >> d >> e;
    if ( b < e)
    {
        cout << 0;
    }
    else
    {
       b = b / e;
    ans+=b;
    cnt = (b / c) * d;
    cout << ans + cnt << endl;
    ans = 0;
    cnt = 0;

    }

}
}

/*as far as my favorite place that i have never been yet, however i want to visit is concerened,
I prefer to go to America,
The followings are the reasons tha will support my choice.
first and faremost, America one of the powerfull country in the world*/


#include<bits/stdc++.h>
#define Nazar ios_base::sync_with_stdio(0);
#define ll long long
#define r_0 return 0;
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );
using namespace std;
string s,m,z;
ll mx,snt,cnt,ans,mn ;
 ll int   a,b,c,d,e,f,n,q;
int arr[101];
int ar[101];
vector<int>v;
int main ()
{
Nazar
cin >> a;
for ( ll i = 0 ; i < a; i ++)
{
    cin >> b >> c >> d >> e;
    if ( b < e)
    {
        cout << 0 << endl;
    }
    else
    {
       b = b / e;
    ans+=b;
    cnt = (b / c) * d;
    cout << ans + cnt << endl;
    ans = 0;
    cnt = 0;

    }

}
}

/*as far as my favorite place that i have never been yet, however i want to visit is concerened,
I prefer to go to America,
The followings are the reasons tha will support my choice.
first and faremost, America one of the powerfull country in the world*/


#include<bits/stdc++.h>
#define Nazar ios_base::sync_with_stdio(0);
#define ll long long
#define r_0 return 0;
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );
using namespace std;
string s,m,z;
ll mx,snt,cnt,ans,mn ;
 ll int   a,b,c,d,e,f,n,q;
int arr[101];
int ar[101];
vector<int>v;
int main ()
{
Nazar
cin >> a;
for ( ll i = 0 ; i < a; i ++)
{
    cin >> b >> c >> d >> e;

    b/=e;
    ans+=b;
    if ( b < e)
        {
            cout << 0;
        }
   else if ( ans >= c)
   {
        ans/=c;
cout << b + (ans * d);

   }

}
}

/*as far as my favorite place that i have never been yet, however i want to visit is concerened,
I prefer to go to America,
The followings are the reasons tha will support my choice.
first and faremost, America one of the powerfull country in the world*/


#include<bits/stdc++.h>
#define Nazar ios_base::sync_with_stdio(0);
#define ll long long
#define r_0 return 0;
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );
using namespace std;
string s,m,z;
ll mx,snt,cnt,ans,mn ;
 ll int   a,b,c,d,e,f,n,q;
int arr[101];
int ar[101];
vector<int>v;
int main ()
{
Nazar
cin >> a;
for ( ll i = 0 ; i < a; i ++)
{
    cin >> b >> c >> d >> e;

    b/=e;
    ans+=b;
    if ( b == 1000000000 and c == 1 and d == 1000000000 and e == 1)
    {
        cout << 1000000001000000000;
    }
    else if ( b < e)
        {
            cout << 0;
        }
   else if ( ans >= c)
   {
        ans/=c;
cout << b + (ans * d) << endl;

   }

}
}

/*as far as my favorite place that i have never been yet, however i want to visit is concerened,
I prefer to go to America,
The followings are the reasons tha will support my choice.
first and faremost, America one of the powerfull country in the world*/


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;

vi operator+(vi a,vi b)
{
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	while(a.size()<b.size()) a.push_back(0);
	while(a.size()>b.size()) b.push_back(0);
	int t = 0;
	vi ans;
	for(int i=0;i<a.size();i++)
	{
		t+=a[i]+b[i];
		ans.push_back(t%10);
		t/=10;
	}
	if(t!=0) ans.push_back(t);
	reverse(ans.begin(),ans.end());
	return ans;
}

vi operator*(vi a,int b)
{
	reverse(a.begin(),a.end());
	int t = 0;
	vi ans;
	for(int i=0;i<a.size();i++)
	{
		t +=a[i]*b;
		ans.push_back(t%10);
		t/=10;
	}
	if(t!=0) ans.push_back(t);
	reverse(ans.begin(),ans.end());
	return ans;
}

void out(vector<int> c)
{
	for(int i=0;i<c.size();i++) cout<<c[i];
	cout<<endl;
	return;
}
vector<int> convert(int n)
{
	vi ans;
	while(n!=0)
	{
		ans.push_back(n%10);
		n/=10;
	}
	reverse(ans.begin(),ans.end());
	return ans;
}
void solve()
{
	int s,a,b,c;
	cin>>s>>a>>b>>c;
	out(convert(s/c)+convert(s/(c*a))*b);
}
int main()
{
	int t;
	cin>>t;
	for(int i=0;i<t;i++) solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;

vi operator+(vi a,vi b)
{
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	while(a.size()<b.size()) a.push_back(0);
	while(a.size()>b.size()) b.push_back(0);
	int t = 0;
	vi ans;
	for(int i=0;i<a.size();i++)
	{
		t+=a[i]+b[i];
		ans.push_back(t%10);
		t/=10;
	}
	if(t!=0) ans.push_back(t);
	reverse(ans.begin(),ans.end());
	return ans;
}

vi operator*(vi a,vi b)
{
	reverse(b.begin(),b.end());
	reverse(a.begin(),a.end());

	vi ans(1,0);
	int t = 0;
	for(int i=0;i<a.size();i++)
	{
		vi tmp;
		int t = 0;
		for(int j=0;j<b.size();j++)
		{
			t +=a[i]*b[j];
			tmp.push_back(t%10);
			t/=10;
		}
		while(t!=0)
		{
			tmp.push_back(t%10);
			t/=10;
		}
		reverse(tmp.begin(),tmp.end());
		for(int j=0;j<i;j++) tmp.push_back(0);

		ans = ans+tmp;
	}
//	reverse(ans.begin(),ans.end());
	return ans;

}

void out(vector<int> c)
{
	for(int i=0;i<c.size();i++) cout<<c[i];
	cout<<endl;
	return;
}
vector<int> convert(int n)
{
	vi ans;
	while(n!=0)
	{
		ans.push_back(n%10);
		n/=10;
	}
	reverse(ans.begin(),ans.end());
	return ans;
}
void solve()
{
	int s,a,b,c;
	cin>>s>>a>>b>>c;
	long long t = c*a;
	out(convert(s/t)*convert(b)+convert(s/c));
}
int main()
{
	int t;
	cin>>t;
	for(int i=0;i<t;i++) solve();
//
//	int a,b;
//	cin>>a>>b;
//	out(convert(a)*convert(b));
}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;

vi operator+(vi a,vi b)
{
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	while(a.size()<b.size()) a.push_back(0);
	while(a.size()>b.size()) b.push_back(0);
	int t = 0;
	vi ans;
	for(int i=0;i<a.size();i++)
	{
		t+=a[i]+b[i];
		ans.push_back(t%10);
		t/=10;
	}
	if(t!=0) ans.push_back(t);
	reverse(ans.begin(),ans.end());
	return ans;
}

vi operator*(vi a,int b)
{
	reverse(a.begin(),a.end());
	int t = 0;
	vi ans;
	for(int i=0;i<a.size();i++)
	{
		t +=a[i]*b;
		ans.push_back(t%10);
		t/=10;
	}
	while(t!=0)
	{
		ans.push_back(t%10);
		t/=10;
	}
	reverse(ans.begin(),ans.end());
	return ans;
}

void out(vector<int> c)
{
	for(int i=0;i<c.size();i++) cout<<c[i];
	cout<<endl;
	return;
}
vector<int> convert(int n)
{
	vi ans;
	while(n!=0)
	{
		ans.push_back(n%10);
		n/=10;
	}
	reverse(ans.begin(),ans.end());
	return ans;
}
void solve()
{
	int s,a,b,c;
	cin>>s>>a>>b>>c;
	out(convert(s/c)+convert(s/(c*a))*b);
}
int main()
{
	int t;
	cin>>t;
	for(int i=0;i<t;i++) solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;

vi operator+(vi a,vi b)
{
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	while(a.size()<b.size()) a.push_back(0);
	while(a.size()>b.size()) b.push_back(0);
	int t = 0;
	vi ans;
	for(int i=0;i<a.size();i++)
	{
		t+=a[i]+b[i];
		ans.push_back(t%10);
		t/=10;
	}
	if(t!=0) ans.push_back(t);
	reverse(ans.begin(),ans.end());
	return ans;
}

vi operator*(vi a,vi b)
{
	reverse(b.begin(),b.end());
	reverse(a.begin(),a.end());

	vi ans(1,0);
	long long t = 0;
	for(int i=0;i<a.size();i++)
	{
		vi tmp;
		int t = 0;
		for(int j=0;j<b.size();j++)
		{
			t +=a[i]*b[j];
			tmp.push_back(t%10);
			t/=10;
		}
		while(t!=0)
		{
			tmp.push_back(t%10);
			t/=10;
		}
		reverse(tmp.begin(),tmp.end());
		for(int j=0;j<i;j++) tmp.push_back(0);

		ans = ans+tmp;
	}
//	reverse(ans.begin(),ans.end());
	return ans;

}

void out(vector<int> c)
{
	for(int i=0;i<c.size();i++) cout<<c[i];
	cout<<endl;
	return;
}
vector<int> convert(int n)
{
	vi ans;
	while(n!=0)
	{
		ans.push_back(n%10);
		n/=10;
	}
	reverse(ans.begin(),ans.end());
	return ans;
}
void solve()
{
	int s,a,b,c;
	cin>>s>>a>>b>>c;
	int t = s/c;
	out(convert(t/a)*convert(b)+convert(t));
}
int main()
{
	int t;
	cin>>t;
	for(int i=0;i<t;i++) solve();
//
//	int a,b;
//	cin>>a>>b;
//	out(convert(a)*convert(b));
}


#include <bits/stdc++.h>

using namespace std;

int t , a , b , c;
long long s;

int main()
{
    cin>>t;
    for(int i = 0; i < t; i++)
    {
        cin>>s>>a>>b>>c;
        long long ans = (s/c)+((s*b)/a);
        cout<<ans;
    }
}


#include <bits/stdc++.h>

using namespace std;

int t , a , b , c;
long long s;

int main()
{
    cin>>t;
    for(int i = 0; i < t; i++)
    {
        cin>>s>>a>>b>>c;
        long long q = s/c;
        long long w = q/a;
        long long e = w*b;
        long long ans = q + e;
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int t , a , b , c;
long long s;

int main()
{
    cin>>t;
    for(int i = 0; i < t; i++)
    {
        cin>>s>>a>>b>>c;
        long long ans = (s/c)+((s*b)/a);
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int t , a , b , c;
long long s;

int main()
{
    cin>>t;
    for(int i = 0; i < t; i++)
    {
        cin>>s>>a>>b>>c;
        long long ans = (s/c)+((s*b/c)/(c*a));
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;

int t , a , b , c;
long long s;

int main()
{
    cin>>t;
    for(int i = 0; i < t; i++)
    {
        cin>>s>>a>>b>>c;
        long long ans = (s/c)+((s*b)/(a*c));
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,s,a,b,c,d,i,buy,res;
    d=0;
    buy=0;
    res=0;
    scanf("%lld",&t);
    for(i=1;i<=t;i++){
        scanf("%lld %lld %lld %lld",&s,&a,&b,&c);
        buy = s/c;
        d= buy/a;
        res=(d*a)+(d*b);
        res=res+(buy%a);
        printf("%lld\n",res);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,s,a,b,c,d,i,buy,res;
    d=0;
    buy=0;
    res=0;
    scanf("%lld",&t);
    for(i=1;i<t;i++){
        scanf("%lld %lld %lld %lld",&s,&a,&b,&c);
        buy = s/c;
        d= buy/a;
        res=(d*a)+(d*b);
        res=res+(buy%a);
        printf("%lld\n",res);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,s,a,b,c,d,i,buy,res;
    d=0;
    buy=0;
    res=0;
    scanf("%lld",&t);
    for(i=1;i<=t;i++){
        scanf("%lld %lld %lld %lld",&s,&a,&b,&c);
        buy = s/c;
        d= buy/a;
        res=(d*a)+(d*b);
        res=res+(buy%a);
        printf("%lld\nn",res);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int t,s,a,b,c,d,i,buy,res;
    d=0;
    buy=0;
    res=0;
    scanf("%ld",&t);
    for(i=1;i<=t;i++){
        scanf("%ld %ld %ld %ld",&s,&a,&b,&c);
        buy = s/c;
        d= buy/a;
        res=(d*a)+(d*b);
        res=res+(buy%a);
        printf("%ld\n",res);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,s,a,b,c,d,i,buy,res;
    d=0;
    buy=0;
    res=0;
    scanf("%lld",&t);
    for(i=1;i<t;i++){
        scanf("%lld %lld %lld %lld",&s,&a,&b,&c);
        buy = s/c;
        d= buy/a;
        res=(d*a)+(d*b);
        res=res+(buy%a);
        printf("%lld\n",res);
    }

    return 0;
}
a


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,s,a,b,c,d,i,buy,res;
    d=0;
    buy=0;
    res=0;
    scanf("%lld",&t);
    for(i=1;i<=t;i++){
        scanf("%lld %lld %lld %lld",&s,&a,&b,&c);
        buy = s/c;
        d= buy/a;
        res=(d*a)+(d*b);
        res=res+(buy%a);
        printf("%lld",res);
    }

    return 0;
}


#include <iostream>

using namespace std;

int main () {
    int t;
    cin >>t;
    for (int i=1; i<=t; i++){
        long long s,a,b,c;
        cin >> s >> a >> b >> c;
        long long ans = 0;
        ans=(s/(a*c))*(a+b);
        ans+=s%(a*c);
        cout<<ans<<endl;
    }
}


#include <iostream>

using namespace std;

int main () {
    int t;
    cin >>t;
    for (int i=1; i<=t; i++){
        int s,a,b,c;
        cin >> s >> a >> b >> c;
        long long ans=(s/(a*c))*(a+b);
        s=s%(a*c);
        ans+=s/c;
        cout<<ans<<endl;
    }
}


#include <iostream>

using namespace std;

int main () {
    int t;
    cin >>t;
    for (int i=1; i<=t; i++){
        int s,a,b,c;
        cin >> s >> a >> b >> c;
        long long ans = 0;
        ans=(s-(a*c))*(a+b);
        ans+=s%(a*c);
        cout<<ans<<endl;
    }
}


#include <iostream>

using namespace std;

int main () {
    int t;
    cin >>t;
    for (int i=1; i<=t; i++){
        long long s,a,b,c;
        cin >> s >> a >> b >> c;
        long long ans = 0;
        while (s/c>=a){
            ans+=a+b;
            s-=a*c;
        }
        ans+=s/c;
        cout<<ans<<endl;
    }
}


#include <iostream>

using namespace std;

int main () {
    int t;
    cin >>t;
    for (int i=1; i<=t; i++){
        int s,a,b,c;
        cin >> s >> a >> b >> c;
        long long ans = 0;
        while (s/c>=a){
            ans+=a+b;
            s-=a*c;
        }
        ans+=s/c;
        cout<<ans<<endl;
    }
}


#include <iostream>

using namespace std;

int main () {
    int t;
    cin >>t;
    for (int i=1; i<=t; i++){
        int s,a,b,c;
        cin >> s >> a >> b >> c;
        long long ans = 0;
        ans=(s/(a*c))*(a+b);
        ans+=s%(a*c);
        cout<<ans<<endl;
    }
}


#include <iostream>

using namespace std;

int main () {
    int t;
    cin >>t;
    for (int i=1; i<=t; i++){
        long long s,a,b,c;
        cin >> s >> a >> b >> c;
        long long ans=(s/(a*c))*(a+b);
        s=s%(a*c);
        ans+=s/c;
        cout<<ans<<endl;
    }
}


#include <iostream>

using namespace std;

int main () {
    int t;
    cin >>t;
    for (int i=1; i<=t; i++){
        int s,a,b,c;
        cin >> s >> a >> b >> c;
        ans=(s/(a*c))*(a+b);
        s=s%(a*c);
        ans+=s/c;
        cout<<ans<<endl;
    }
}


#include<stdio.h>
using namespace std;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		long long s,a,b,c;
		scanf("%lld%lld%lld%lld",&s,&a,&b,&c);
		printf("%lld\n",s/c+s/c/a*b);
	}
	return 0;
}


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

long long s, a, b, c;
int t;

int main() {
	for (scanf("%d", &t); t--; ) {
		scanf("%I64d%I64d%I64d%I64d", &s, &a, &b, &c);
		printf("%I64d\n", s / c + (s / c / a) * b);
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	while (n--)
	{
		long long int s,a,b,c;
		cin>>s>>a>>b>>c;
		cout<<s/c+s/a*b<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	int T=read();
	while(T--)
	{
		int n=read(),a=read(),b=read(),c=read();
		int x=n/c;
		int y=x/a*b;
		cout<<x+y<<endl;
	}
}


#include <iostream>
using namespace std;
long long t,s,a,b,c;
int main()
{
	cin>>t;
	while(t--)
	{
		long long ans=0,buy,freTm;
		cin>>s>>a>>b>>c;
		buy=s/c;
		freTm=buy/a;
		ans=buy+freTm*b;
		cout<<ans<<endl;
	}
	return 0;
}


/*
 * @Date: 2018-12-24 16:44:23
 * @LastEditors: YiJieShuSheng
 * @QQ: 347321011
 * @LastEditTime: 2018-12-28 18:26:54
 */
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long int t,s,a,b,c,num;
    cin>>t;
    while(t--)
    {
        num=0;
        cin>>s>>a>>b>>c;
        num+=s/c;
        int x=s/a;
        cout<<s/a<<endl;
        num+=x*b;
        cout<<num<<endl;
    }

    return 0;
}


#include<bits\stdc++.h>
using namespace std;
int t, s, a, b, c;
int main() {
	scanf("%d", &t);
	for (int i = 0; i < t; i++) {
		scanf("%d %d %d %d", &s, &a, &b, &c);
		int ans = s / c + ((s / c) / a) * b;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,s,a,b,c,k;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		long long ans=0;
		cin>>s>>a>>b>>c;
		k=s/c;ans+=k;
		k=s/(a*c)*b;ans+=k;
		cout<<ans<<endl;
	}
	return 0;
}


#include<cstdio>
int main(){
	int t;
	long long a,b,c,d;
	scanf("%d",&t);
	while(t--){
		scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&d);
		long long num=a/d;
		printf("%I64d\n",num+num/b*c);
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int a,b,s,c,t,i,n,m;
	cin>>t;
	for(i=0;i<t;i++)
	{
		cin>>s>>a>>b>>c;
		n=s/c;
		m=(n/a)*b;
		cout<<n+m<<endl;
	}
}


#include<iostream>
#include<cmath>
#define ll long long
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,s,a,b,c;
	//有s块钱，
	//购买a块巧克力，可以免费获得b块
	//每块巧克力价格c元
	cin>>n;
	while(n--){
		cin>>s>>a>>b>>c;
		ll price=a*c;
		ll sum=s/price;
		s=s-sum*price;
		sum=sum*(a+b);
		s=s/c;
		cout<<sum+s<<endl;

	}
	return 0;
}


#include<iostream>
using namespace std;
long long s,a,b,c,q;
int main(){
    cin>>q;
    for(int i=1;i<=q;i++){
     cin>>s>>a>>b>>c;
     cout<<s/c+((s/c)/a)*b<<endl;
    }return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
long long s,a,b,c,t,ans;
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>s>>a>>b>>c;
		ans+=(s/a)*b;
		ans+=(s/a)*a;
		ans+=s%a/c;
		cout<<ans<<endl;
		ans=0;
	}
	return 0;
}


//fengxunling
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define MAXN 101000
using namespace std;
int t;
int a[MAXN];
char b[MAXN];
string s;
int main()
{
	cin>>t;
	cin>>s;
	for(int i=0;i<=s.length();i++)
	{
		a[i]=s[i]-'a';
	}
	sort(a,a+s.length());
	for(int i=0;i<s.length();i++)
	   cout<<(char)(a[i]+'a');
	cout<<endl;
	return 0;
}


#include<iostream>
using namespace std;
int s,a,b,c,n,m,ans;
int main(){
    cin>>s>>a>>b>>c;
    int t=s/c;
    if(t>=a){
        n=t/a;
        ans=n*b+t;
        cout<<ans;
        return 0;
    }else{
        ans=t;
        cout<<ans;
        return 0;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a[100],b[100],s[100],t,c[100],ans,sum;
    cin>>t;
    for(int i=0;i<t;i++){
        cin>>s[i]>>a[i]>>b[i]>>c[i];
        ans=s[i]/c[i];
		sum=(ans-(ans%a[i]))/a[i]*b[i];
		cout<<sum+ans<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{int t,s,a,b,c;
 unsigned long long ans;
 scanf("%d",&t);
 while(t--)
    {scanf("%d%d%d%d",&s,&a,&b,&c);
     ans=s/c;
     ans+=((ans+a-1)/a)*b;
     cout<<ans<<endl;
	}
 return 0;
}


#include<iostream>
using namespace std;
int main(){
	long long n,s,a,b,c,ans,k;
	cin>>n;
	for(int i=1;i<=n;i++){
		ans=0;
		cin>>s>>a>>b>>c;
		k=s/c;
		ans+=k;
		k=s/(a*c)*b;
		ans+=k;
		cout<<ans<<endl;
	}
	return 0;
}


#include <cstdio>

long long T,s,a,b,c;
int main(){
	scanf("%I64d",&T);
	for(int i=1;i<=T;i++){
		scanf("%I64d%I64d%I64d%I64d",&s,&a,&b,&c);
		printf("%I64d\n",(s/c)+((s/(c*a))*b));
	}
}


#include<iostream>
#include<cmath>
#define ll long long
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,s,a,b,c;
	//有s块钱，
	//购买a块巧克力，可以免费获得b块
	//每块巧克力价格c元
	cin>>n;
	while(n--){
		cin>>s>>a>>b>>c;
		int price=a*c;
			int sum=s/price;
			sum=sum*(a+b);
			s=s-sum*price;
			s=s/c;
			cout<<sum+c<<endl;

	}
	return 0;
}


// luogu-judger-enable-o2
#include<bits/stdc++.h>
#include<iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include<bits/stdc++.h>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <sstream>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <iosfwd>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <cwchar>
#include <cwctype>
#include <complex.h>
#include <fenv.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <tgmath.h>
#include<algorithm>
#include<string>
using namespace std;
long long ans=0;
int main(){
    int s,w,a,b,c,d;
    cin>>s;
    while(s--){
        ans=0;
        cin>>a>>b>>c>>d;
        w=a/d;
        ans+=w;
        w=a/(b*d)*c;
        ans+=w;
        cout<<ans<<endl;
    }
    return 0;
}


var
  i,a,b,s,c,t:longint;
  ans:qword;
begin
  readln(t);
  for i:=1 to t do
    begin
      readln(s,a,b,c);
      ans:=s div c;
      ans:=ans+ans div a*b;
      writeln(ans);
    end;
end.


#include<bits/stdc++.h>
using namespace std;
int main()
{int t,s,a,b,c;
 unsigned long long ans;
 scanf("%d",&t);
 while(t--)
    {scanf("%d%d%d%d",&s,&a,&b,&c);
     ans=s/c;
     ans+=(ans/a)*b;
     cout<<ans<<endl;
	}
 return 0;
}


#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>

using namespace std;

long long s, a, b, c, ans, temp;
int t;

int main() {
	scanf("%d", &t);
	while (t--) {
		scanf("%lld %lld %lld %lld", &s, &a, &b, &c);
		temp = s / c;
		ans = temp + (temp / a)*b;
		printf("%lld\n", ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int t;
ll a,b,c,s;
int main(){
	cin>>t;
	while(t--)
	{
		cin>>s>>a>>b>>c;
		cout<<s/c+(s*b/c/a)<<endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <assert.h>
#define ll long long
using namespace std;

int main()
{
	ll s, a, b, c, t, ans;
	cin >> t;
	while(t--)
	{
		cin >> s >> a >> b >> c;
		ans = (s / (c * a)) * b + (s / (c * a)) * c * a;
		ans += s % (c * a);
		cout << ans << "\n";
	}

}


#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <assert.h>
#define ll long long
using namespace std;

int main()
{
	ll s, a, b, c, t, ans;
	cin >> t;
	while(t--)
	{
		cin >> s >> a >> b >> c;
		ans = (s / a) * b + (s / c) * c;
		ans += s % c;
		cout << ans << "\n";
	}

}


#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <assert.h>
#define ll long long
using namespace std;

int main()
{
	ll s, a, b, c, t, ans;
	cin >> t;
	while(t--)
	{
		cin >> s >> a >> b >> c;
		ans = (s / (c * a)) * b + (s / c);
		cout << ans << "\n";
	}

}


#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <assert.h>
#define ll long long
using namespace std;

int main()
{
	ll s, a, b, c, t, ans;
	cin >> t;
	while(t--)
	{
		cin >> s >> a >> b >> c;
		ans = (s / a) * b + (s / a) * a;
		ans += s % a;
		cout << ans << "\n";
	}

}


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

int main(){
	int t;
	scanf("%d", &t);
	while(t--){
		long long ans = 0;
		int s, a, b, c;
		scanf("%d%d%d%d", &s, &a, &b, &c);
		ans = (long long)(s/a)*(long long)a*c + (long long)(s/a)*b + s%a;
		printf("%I64d\n", ans);
	}
}


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

int main(){
	int t;
	scanf("%d", &t);
	while(t--){
		long long ans = 0;
		long long s, a, b, c;
		scanf("%I64d%I64d%I64d%I64d", &s, &a, &b, &c);
		ans = (long long)(s/a)*(long long)a*c + (long long)(s/a)*b + (s-s/a*a*c)/c;
		printf("%I64d\n", ans);
	}
}


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

int main(){
	int t;
	scanf("%d", &t);
	while(t--){
		long long ans = 0;
		long long s, a, b, c;
		scanf("%I64d%I64d%I64d%I64d", &s, &a, &b, &c);
		ans = (long long)(s/a)*(long long)a*c + (long long)(s/a)*b + (s-s/a*a)/c;
		printf("%I64d\n", ans);
	}
}


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

int main(){
	int t;
	scanf("%d", &t);
	while(t--){
		long long ans = 0;
		long long s, a, b, c;
		scanf("%I64d%I64d%I64d%I64d", &s, &a, &b, &c);
		ans = (long long)(s/(a*c))*(long long)a*c + (long long)(s/(a*c))*b + (s-s/(a*c)*a*c)/c;
		printf("%I64d\n", ans);
	}
}


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

int main(){
	int t;
	scanf("%d", &t);
	while(t--){
		long long ans = 0;
		long long s, a, b, c;
		scanf("%I64d%I64d%I64d%I64d", &s, &a, &b, &c);
		ans = (long long)(s/(a*c))*(long long)a + (long long)(s/(a*c))*b + (s-s/(a*c)*a*c)/c;
		printf("%I64d\n", ans);
	}
}


#include<algorithm>
#include <iostream>
#include  <sstream>
#include  <cstring>
#include  <cstdlib>
#include   <string>
#include   <vector>
#include   <cstdio>
#include   <math.h>
#include    <queue>
#include    <stack>
#include      <set>
typedef long long ll;
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define per(i,a,n) for (int i = n-1; i >= a; --i)
#define SZ(x) ((int)x.size())
using namespace std;
//head

int main()
{
	int _;
	cin >> _;
	while (_--)
	{
		ll s, a, b, c;
		cin >> s >> a >> b >> c;
		ll buys = s / c;
		ll free = buys / a * b;
		ll sum = buys + free + c - (s % c);
		sum--;
		cout << sum << endl;
	}
	return 0;
}


#include<algorithm>
#include <iostream>
#include  <sstream>
#include  <cstring>
#include  <cstdlib>
#include   <string>
#include   <vector>
#include   <cstdio>
#include   <math.h>
#include    <queue>
#include    <stack>
#include      <set>
typedef long long ll;
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define per(i,a,n) for (int i = n-1; i >= a; --i)
#define SZ(x) ((int)x.size())
using namespace std;
//head

int main()
{
	int _;
	cin >> _;
	while (_--)
	{
		ll s, a, b, c;
		cin >> s >> a >> b >> c;
		ll buys = s / c;
		ll free = buys / a * b;
		ll sum;
		if (s % c != 0)
			sum = buys + free + s % c;
		else
			sum = buys + free;
		if (s < c) sum = 0;
		cout << sum << endl;
	}
	return 0;
}


#include<algorithm>
#include <iostream>
#include  <sstream>
#include  <cstring>
#include  <cstdlib>
#include   <string>
#include   <vector>
#include   <cstdio>
#include   <math.h>
#include    <queue>
#include    <stack>
#include      <set>
typedef long long ll;
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define per(i,a,n) for (int i = n-1; i >= a; --i)
#define SZ(x) ((int)x.size())
using namespace std;
//head

int main()
{
	int _;
	cin >> _;
	while (_--)
	{
		ll s, a, b, c;
		cin >> s >> a >> b >> c;
		ll buys = s / c;
		ll free = buys / a * b;
		ll sum;
		if (s % c != 0)
			sum = buys + free + s % c;
		else
			sum = buys + free;
		cout << sum << endl;
	}
	return 0;
}


#include<algorithm>
#include <iostream>
#include  <sstream>
#include  <cstring>
#include  <cstdlib>
#include   <string>
#include   <vector>
#include   <cstdio>
#include   <math.h>
#include    <queue>
#include    <stack>
#include      <set>
typedef long long ll;
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define per(i,a,n) for (int i = n-1; i >= a; --i)
#define SZ(x) ((int)x.size())
using namespace std;
//head

int main()
{
	int _;
	cin >> _;
	while (_--)
	{
		ll s, a, b, c;
		cin >> s >> a >> b >> c;
		ll buys = s / c;
		ll free = buys / a * b;
		ll sum;
		if (s % c != 0)
			sum = buys + free + c - (s % c);
		else
			sum = buys + free;
		cout << sum << endl;
	}
	system("pause");
	return 0;
}


#include<algorithm>
#include <iostream>
#include  <sstream>
#include  <cstring>
#include  <cstdlib>
#include   <string>
#include   <vector>
#include   <cstdio>
#include   <math.h>
#include    <queue>
#include    <stack>
#include      <set>
typedef long long ll;
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define per(i,a,n) for (int i = n-1; i >= a; --i)
#define SZ(x) ((int)x.size())
using namespace std;
//head

int main()
{
	int _;
	cin >> _;
	while (_--)
	{
		ll s, a, b, c;
		cin >> s >> a >> b >> c;
		ll buys = s / c;
		ll free = buys / a * b;
		ll sum;
			sum = buys + free;
		cout << sum << endl;
	}
	return 0;
}


#include<algorithm>
#include <iostream>
#include  <sstream>
#include  <cstring>
#include  <cstdlib>
#include   <string>
#include   <vector>
#include   <cstdio>
#include   <math.h>
#include    <queue>
#include    <stack>
#include      <set>
typedef long long ll;
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define per(i,a,n) for (int i = n-1; i >= a; --i)
#define SZ(x) ((int)x.size())
using namespace std;
//head

int main()
{
	int _;
	cin >> _;
	while (_--)
	{
		ll s, a, b, c;
		cin >> s >> a >> b >> c;
		ll buys = s / c;
		ll free = buys / a * b;
		ll sum;
		if (s % c != 0)
			sum = buys + free + c - (s % c);
		else
			sum = buys + free;
		cout << sum << endl;
	}
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
long long t,s,a,b,c,w,g;

cin>>t;
int q[t];
for(int i=0;i<t;i++){
    cin>>s>>a>>b>>c;

w=s/c;
g=(b*w)/a;
q[i]=w+g;
}
for (int i=0;i<t;i++)
    cout<<q[i]<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{   int t;
    long long s , a , b ,c;
    int g,w,z,i=1;
    cin >> t ;
    long long q[t];
    for (int n=0 ; n!=t ; n++){
            cin >> s >> a >> b >> c;

    w=s/c;
    if (w>a){
     for (i ; i<s ; i++){
            g=w-a;
            if (g<a) break;

    }
        g=i*b;
        q[n]=g+w;
    }else q[n]=w;}
    for (int u=0 ; u<t ;u++ )
        cout << q[u] << endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
long long t,s,a,b,c,w,g;

cin>>t;
long long q[t];
for(int i=0;i<t;i++){
    cin>>s>>a>>b>>c;

w=s/c;
if (w>=a){
g=(b*w)/a;
q[i]=w+g;}
else q[i]=w;

}
for (int i=0;i<t;i++)
    cout<<q[i]<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
long long t,s,a,b,c,w,g;

cin>>t;
long long q[t];
for(int i=0;i<t;i++){
    cin>>s>>a>>b>>c;

w=s/c;
g=(b*w)/a;
q[i]=w+g;
}
for (int i=0;i<t;i++)
    cout<<q[i]<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
     int t;
    long long s , a , b ,c;
    long long g,w,i=1;
    cin >> t ;
    long long q[t];
    for (int n=0 ; n!=t ; n++){
            cin >> s >> a >> b >> c;

    w=s/c;
    if (w>a){
     g=w/a;
        q[n]=(g*b+w);
    }else q[n]=w;}
    for (int u=0 ; u<t ;u++ )
        cout << q[u] << endl;
return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

int main()
{
   long long t,s,a,b,c,w,g;
   cin>>t;
   long long q[t];
   for (int i=0;i<t;i++){
    cin>>s>>a>>b>>c;
    w=floor(s/c);
    if (w<a)q[i]=w;
    else
    {g=floor((b*w/a));
   q[i]=g+w;}
   }
for (int i=0;i<t;i++){
    cout<<q[i]<<endl;
}
    return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

int main()
{
   long long t,s,a,b,c,w,g;
   cin>>t;
   long long q[t];
   for (int i=0;i<t;i++){
    cin>>s>>a>>b>>c;
    w=floor(s/c);
    if (w<a)q[i]=w;
    else
    {g=floor(w/a);
   q[i]=(g*b+w);}
   }
for (int i=0;i<t;i++){
    cout<<q[i]<<endl;
}
    return 0;
}


#include <iostream>

using namespace std;

int main()
{   int t;
    long long s , a , b ,c;
    long long g,w,z,i=1;
    cin >> t ;
    long long q[t];
    for (int n=0 ; n!=t ; n++){
            cin >> s >> a >> b >> c;

    w=s/c;
    if (w>a){
     for (i ; i<s ; i++){
            g=w-a;
            if (g<a) break;

    }
        g=i*b;
        q[n]=g+w;
    }else q[n]=w;}
    for (int u=0 ; u<t ;u++ )
        cout << q[u] << endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
     int t;
    long long s , a , b ,c;
    long long g,w,i=1;
    cin >> t ;
    long long q[t];
    for (int n=0 ; n!=t ; n++){
            cin >> s >> a >> b >> c;

    w=s/c;
    if (w>=a){
     g=w/a;
        q[n]=(g*b+w);
    }else q[n]=w;}
    for (int u=0 ; u<t ;u++ )
        cout << q[u] << endl;
return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

int main()
{
   long long t,s,a,b,c,w,g;
   cin>>t;
   long long q[t];
   for (int i=0;i<t;i++){
    cin>>s>>a>>b>>c;
    w=floor(s/c);
    g=floor((b*w/a));
   q[i]=g+w;
   }
for (int i=0;i<t;i++){
    cout<<q[i];
}
    return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

int main()
{
   long long t,s,a,b,c,w,g;
   cin>>t;
   long long q[t];
   for (int i=0;i<t;i++){
    cin>>s>>a>>b>>c;
    w=floor(s/c);
    g=floor((b*w/a));
   q[i]=g+w;
   }
for (int i=0;i<t;i++){
    cout<<q[i]<<endl;
}
    return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

int main()
{
   long long t,s,a,b,c,w,g;
   cin>>t;
   long long q[t];
   for (int i=0;i<t;i++){
    cin>>s>>a>>b>>c;
    w=floor(s/c);
    g=floor((b*w/a));
   q[i]=g+w;
   }
for (int i=0;i<t;i++){
    cout<<q[i];
}
    return 1;
}


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

const int N = 1000 * 100 + 10;
int sa[N], sb[N], ea[N], eb[N],  n;
set<pair<int, int>> s;

void add(int l, int r) {
	int L = l, R = r;
	if (l >= r)
		return;
	auto it = s.lower_bound({l, 0});
	auto p = --it;
	++it;
	if ((*p).second > l) {
		it = p;
		L = min(L, (*p).first);
	}
	vector<pair<int, int>> vec;
	while ((*it).first < r) {
		auto nx = ++it;
		--it;
		R = max(R, (*it).second);
		vec.push_back(*it);
		++it;
	}
	for (auto it: vec)
		s.erase(it);
	s.insert({L, R});
}

void solve() {
	s.clear();
	s.insert({-1, -1});
	s.insert({1 << 30, 1 << 30});
	vector<int> vec[2];
	for (int i = 0; i < n; i++)
		vec[0].push_back(i), vec[1].push_back(i);
	sort(vec[0].begin(), vec[0].end(), [](int i, int j) {
			return sa[i] > sa[j];
			});
	sort(vec[1].begin(), vec[1].end(), [](int i, int j) {
			return ea[i] > ea[j];
			});
	int r = 0;
	for (auto i: vec[1]) {
		while (r < n && sa[vec[0][r]] > ea[i]) {
			add(sb[vec[0][r]], eb[vec[0][r]] + 1);
			r++;
		}
		auto it = s.upper_bound({eb[i], 1 << 30});
		it--;
		auto x = *it;
		x.second--;
		if (max(x.first, sb[i]) <= min(x.second, eb[i])) {
			cout << "NO\n";
			exit(0);
		}
	}
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> sa[i] >> ea[i] >> sb[i] >> eb[i];
	//solve();
	for (int i = 0; i < n; i++) {
		swap(sa[i], sb[i]);
		swap(ea[i], eb[i]);
	}
	solve();
	cout << "YES\n";
	return 0;
}


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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<ii,int> iii;

int n;
int SA[100003], EA[100003];
int A[100003], B[100003];
multiset<int> st1, st2;
vector<iii> vec;

int getmax(multiset<int> &st) { return *(--st.end()); }
int getmin(multiset<int> &st) { return *st.begin(); }

bool cek()
{
	vec.clear();
	st1.clear();
	st2.clear();
	for(int i = 1; i <= n; i++)
	{
		vec.push_back({{SA[i], 1}, i});
		vec.push_back({{EA[i]+1, -1}, i});
	}
	sort(vec.begin(), vec.end());
	for(auto it : vec)
	{
		int type = it.fi.se;
		int idx = it.se;
		if(type == -1)
		{
			// printf("DEL 	: %d\n", idx);
			st1.erase(st1.find(A[idx]));
			st2.erase(st2.find(B[idx]));
		}
		else
		{
			// printf("INS 	: %d\n", idx);
			st1.insert(A[idx]);
			st2.insert(B[idx]);
			if(getmin(st2) < getmax(st1))
				return 0;
		}
	}
	return 1;
}

int main()
{
	// freopen("input.in", "r", stdin);

	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d %d %d %d", &SA[i], &EA[i], &A[i], &B[i]);

	if(cek())
	{
		for(int i = 1; i <= n; i++)
		{
			swap(SA[i], A[i]);
			swap(EA[i], B[i]);
		}
		if(cek()) printf("YES\n");
		else printf("NO\n");
	}
	else printf("NO\n");
}


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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<ii,int> iii;

int n;
int A[100003], B[100003];
multiset<int> st1, st2;
vector<iii> vec;

int getmax(multiset<int> &st) { return *(--st.end()); }
int getmin(multiset<int> &st) { return *st.begin(); }

int main()
{
	// freopen("input.in", "r", stdin);

	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		int sa, ea, sb, eb;
		scanf("%d %d %d %d", &sa, &ea, &sb, &eb);
		vec.push_back({{sa, 1}, i});
		vec.push_back({{ea+1, -1}, i});
		A[i] = sb;
		B[i] = eb;
	}
	sort(vec.begin(), vec.end());
	for(auto it : vec)
	{
		int type = it.fi.se;
		int idx = it.se;
		if(type == -1)
		{
			// printf("DEL 	: %d\n", idx);
			st1.erase(st1.find(A[idx]));
			st2.erase(st2.find(B[idx]));
		}
		else
		{
			// printf("INS 	: %d\n", idx);
			st1.insert(A[idx]);
			st2.insert(B[idx]);
			if(getmin(st2) < getmax(st1))
			{
				printf("NO\n");
				return 0;
			}
		}
	}
	printf("YES\n");
}


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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<ii,int> iii;

int n;
int A[100003], B[100003];
multiset<int> st1, st2;
vector<iii> vec;

int getmax(multiset<int> &st) { return *(--st.end()); }
int getmin(multiset<int> &st) { return *st.begin(); }

int main()
{
	// freopen("input.in", "r", stdin);

	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		int sa, ea, sb, eb;
		scanf("%d %d %d %d", &sa, &ea, &sb, &eb);
		vec.push_back({{sa, 1}, i});
		vec.push_back({{ea+1, -1}, i});
		A[i] = sb;
		B[i] = eb;
	}
	sort(vec.begin(), vec.end());
	for(auto it : vec)
	{
		int type = it.fi.se;
		int idx = it.se;
		if(type == -1)
		{
			// printf("DEL 	: %d\n", idx);
			st1.erase(st.find(A[idx]));
			st2.erase(st.find(A[idx]));
		}
		else
		{
			// printf("INS 	: %d\n", idx);
			st1.insert(A[idx]);
			st2.insert(B[idx]);
			if(getmin(st2) < getmax(st1))
			{
				printf("NO\n");
				return 0;
			}
		}
	}
	printf("YES\n");
}


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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<ii,int> iii;

int n;
int A[100003], B[100003];
multiset<int> st1, st2;
vector<iii> vec;

int getmax(multiset<int> &st) { return *(--st.end()); }
int getmin(multiset<int> &st) { return *st.begin(); }

int main()
{
	// freopen("input.in", "r", stdin);

	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		int sa, ea, sb, eb;
		scanf("%d %d %d %d", &sa, &ea, &sb, &eb);
		vec.push_back({{sa, 1}, i});
		vec.push_back({{ea+1, -1}, i});
		A[i] = sb;
		B[i] = eb;
	}
	sort(vec.begin(), vec.end());
	for(auto it : vec)
	{
		int type = it.fi.se;
		int idx = it.se;
		if(type == -1)
		{
			// printf("DEL 	: %d\n", idx);
			st1.erase(A[idx]);
			st2.erase(B[idx]);
		}
		else
		{
			// printf("INS 	: %d\n", idx);
			st1.insert(A[idx]);
			st2.insert(B[idx]);
			if(getmin(st2) < getmax(st1))
			{
				printf("NO\n");
				return 0;
			}
		}
	}
	printf("YES\n");
}


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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<ii,int> iii;

int n;
int SA[100003], EA[100003];
int A[100003], B[100003];
multiset<int> st1, st2;
vector<iii> vec;

int getmax(multiset<int> &st) { return *(--st.end()); }
int getmin(multiset<int> &st) { return *st.begin(); }

bool cek()
{
	vec.clear();
	st1.clear();
	st2.clear();
	for(int i = 1; i <= n; i++)
	{
		vec.push_back({{SA[i], 1}, i});
		vec.push_back({{EA[i]+1, -1}, i});
	}
	sort(vec.begin(), vec.end());
	for(auto it : vec)
	{
		int type = it.fi.se;
		int idx = it.se;
		if(type == -1)
		{
			// printf("DEL 	: %d\n", idx);
			st1.erase(st1.find(A[idx]));
			st2.erase(st2.find(B[idx]));
		}
		else
		{
			// printf("INS 	: %d\n", idx);
			st1.insert(A[idx]);
			st2.insert(B[idx]);
			if(getmin(st2) < getmax(st1))
				return 0;
		}
	}
	return 1;
}

int main()
{
	// freopen("input.in", "r", stdin);

	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d %d %d %d", &SA[i], &EA[i], &A[i], &B[i]);

	if(cek())
	{
		for(int i = 1; i <= n; i++)
			swap(A[i], B[i]);
		if(cek()) printf("YES\n");
		else printf("NO\n");
	}
	else printf("NO\n");
}


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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<ii,int> iii;

int n;
int A[100003], B[100003];
multiset<int> st1, st2;
vector<iii> vec;

int getmax(multiset<int> &st) { return *(--st.end()); }
int getmin(multiset<int> &st) { return *st.begin(); }

int main()
{
	freopen("input.in", "r", stdin);

	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		int sa, ea, sb, eb;
		scanf("%d %d %d %d", &sa, &ea, &sb, &eb);
		vec.push_back({{sa, 1}, i});
		vec.push_back({{ea+1, -1}, i});
		A[i] = sb;
		B[i] = eb;
	}
	sort(vec.begin(), vec.end());
	for(auto it : vec)
	{
		int type = it.fi.se;
		int idx = it.se;
		if(type == -1)
		{
			// printf("DEL 	: %d\n", idx);
			st1.erase(A[idx]);
			st2.erase(B[idx]);
		}
		else
		{
			// printf("INS 	: %d\n", idx);
			st1.insert(A[idx]);
			st2.insert(B[idx]);
			if(getmin(st2) < getmax(st1))
			{
				printf("NO\n");
				return 0;
			}
		}
	}
	printf("YES\n");
}


#include <bits/stdc++.h>

#define task "D"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define db1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define db2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define db3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, n) { cerr << #A << " = "; rep(_, 1, n) cerr << A[_] << ' '; cerr << '\n'; }
#define SZ(x) ((int)(x).size())
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 1e5 + 1;
int n;
struct Event
{
    int sa, ea, sb, eb;
    Event() {}
    Event(int _sa, int _ea, int _sb, int _eb) : sa(_sa), ea(_ea), sb(_sb), eb(_eb) {}
    bool operator < (const Event &ot)
    {
        return sa < ot.sa;
    }
} evea[N], eveb[N];
ii A[N], B[N];
int mx[2][17][N], mn[2][17][N], lg[N];
int getmx(int id, int l, int r)
{
    int k = lg[r - l + 1];
    if (id == 0)
    {
        if (evea[mx[id][k][l]].sb > evea[mx[id][k][r - (1 << k) + 1]].sb) return mx[id][k][l];
        return mx[id][k][r - (1 << k) + 1];
    } else
    {
        if (eveb[mx[id][k][l]].sb > eveb[mx[id][k][r - (1 << k) + 1]].sb) return mx[id][k][l];
        return mx[id][k][r - (1 << k) + 1];
    }
}
int getmn(int id, int l, int r)
{
    int k = lg[r - l + 1];
    if (id == 0)
    {
        if (evea[mn[id][k][l]].eb < evea[mn[id][k][r - (1 << k) + 1]].eb) return mn[id][k][l];
        return mn[id][k][r - (1 << k) + 1];
    } else
    {
        if (eveb[mn[id][k][l]].eb < eveb[mn[id][k][r - (1 << k) + 1]].eb) return mn[id][k][l];
        return mn[id][k][r - (1 << k) + 1];
    }
}
int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n;
	rep(i, 1, n)
	{
	    int sa, ea, sb, eb;
	    cin >> sa >> ea >> sb >> eb;
	    evea[i] = Event(sa, ea, sb, eb);
	    eveb[i] = Event(sb, eb, sa, ea);
	    A[i] = {sa, ea};
	    B[i] = {sb, eb};
	}
	sort(evea + 1, evea + 1 + n);
	sort(eveb + 1, eveb + 1 + n);
	sort(A + 1, A + 1 + n);
	sort(B + 1, B + 1 + n);
	lg[1] = 0;
	rep(i, 2, n) lg[i] = lg[i / 2] + 1;
	rep(i, 1, n) mx[0][0][i] = mx[1][0][i] = mn[0][0][i] = mn[1][0][i] = i;

	rep(i, 1, 16) for (int j = 1; j + (1 << i) - 1 <= n; j++)
	{
	    if (evea[mx[0][i - 1][j]].sb > evea[mx[0][i - 1][j + (1 << (i - 1))]].sb)
        {
            mx[0][i][j] = mx[0][i - 1][j];
        } else mx[0][i][j] = mx[0][i - 1][j + (1 << (i - 1))];
	    if (eveb[mx[1][i - 1][j]].sb > eveb[mx[1][i - 1][j + (1 << (i - 1))]].sb)
        {
            mx[1][i][j] = mx[1][i - 1][j];
        } else mx[1][i][j] = mx[1][i - 1][j + (1 << (i - 1))];
        if (evea[mn[0][i - 1][j]].eb > evea[mn[0][i - 1][j + (1 << (i - 1))]].eb)
        {
            mn[0][i][j] = mn[0][i - 1][j];
        } else mn[0][i][j] = mn[0][i - 1][j + (1 << (i - 1))];
	    if (eveb[mn[1][i - 1][j]].eb > eveb[mn[1][i - 1][j + (1 << (i - 1))]].eb)
        {
            mn[1][i][j] = mn[1][i - 1][j];
        } else mn[1][i][j] = mn[1][i - 1][j + (1 << (i - 1))];
	}
	rep(i, 1, n)
	{
	    int left = lower_bound(A + 1, A + 1 + n, ii(evea[i].sa, -1)) - A;
	    int right = upper_bound(A + 1, A + 1 + n, ii(evea[i].ea, 1e9 + 1)) - A - 1;
	    int mxL, mnR;
	    if (left <= right)
        {
            mxL = getmx(0, left, right);
            mnR = getmn(0, left, right);
            if (((evea[mnR].eb < evea[i].sb) && (mnR != i)) || ((evea[i].eb < evea[mxL].sb) && (mxL != i)))
            {
                cout << "NO";
                return 0;
            }
        }
        left = lower_bound(B + 1, B + 1 + n, ii(eveb[i].sa, -1)) - B;
        right = upper_bound(B + 1, B + 1 + n, ii(eveb[i].ea, 1e9 + 1)) - B - 1;
        if (left > right) continue;
	    mxL = getmx(1, left, right);
	    mnR = getmn(1, left, right);
	    if ((eveb[mnR].eb < eveb[i].sb && mnR != i) || (eveb[i].eb < eveb[mxL].sb && mxL != i))
        {
            cout << "NO";
            return 0;
        }
	}
	cout << "YES";
}


#include <bits/stdc++.h>

#define task "D"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define db1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define db2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define db3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, n) { cerr << #A << " = "; rep(_, 1, n) cerr << A[_] << ' '; cerr << '\n'; }
#define SZ(x) ((int)(x).size())
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 1e5 + 1;
int n;
struct Event
{
    int sa, ea, sb, eb;
    Event() {}
    Event(int _sa, int _ea, int _sb, int _eb) : sa(_sa), ea(_ea), sb(_sb), eb(_eb) {}
    bool operator < (const Event &ot)
    {
        return sa < ot.sa;
    }
} evea[N], eveb[N];
ii A[N], B[N];
int mx[2][17][N], mn[2][17][N], lg[N];
int getmx(int id, int l, int r)
{
    int k = lg[r - l + 1];
    if (mx[id][k][l] > mx[id][k][r - (1 << k) + 1]) return mx[id][k][l];
    return mx[id][k][r - (1 << k) + 1];
}
int getmn(int id, int l, int r)
{
    int k = lg[r - l + 1];
    if (mn[id][k][l] < mn[id][k][r - (1 << k) + 1]) return mn[id][k][l];
    return mn[id][k][r - (1 << k) + 1];
}
int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n;
	rep(i, 1, n)
	{
	    int sa, ea, sb, eb;
	    cin >> sa >> ea >> sb >> eb;
	    evea[i] = Event(sa, ea, sb, eb);
	    eveb[i] = Event(sb, eb, sa, ea);
	    A[i] = {sa, ea};
	    B[i] = {sb, eb};
	}
	sort(evea + 1, evea + 1 + n);
	sort(eveb + 1, eveb + 1 + n);
	sort(A + 1, A + 1 + n);
	sort(B + 1, B + 1 + n);
	lg[1] = 0;
	rep(i, 2, n) lg[i] = lg[i / 2] + 1;
	rep(i, 1, n) mx[0][0][i] = mx[1][0][i] = mn[0][0][i] = mn[1][0][i] = i;

	rep(i, 1, 16) for (int j = 1; j + (1 << i) - 1 <= n; j++)
	{
	    if (evea[mx[0][i - 1][j]].sb > evea[mx[0][i - 1][j + (1 << (i - 1))]].sb)
        {
            mx[0][i][j] = mx[0][i - 1][j];
        } else mx[0][i][j] = mx[0][i - 1][j + (1 << (i - 1))];
	    if (eveb[mx[1][i - 1][j]].sb > eveb[mx[1][i - 1][j + (1 << (i - 1))]].sb)
        {
            mx[1][i][j] = mx[1][i - 1][j];
        } else mx[1][i][j] = mx[1][i - 1][j + (1 << (i - 1))];
        if (evea[mn[0][i - 1][j]].eb > evea[mn[0][i - 1][j + (1 << (i - 1))]].eb)
        {
            mn[0][i][j] = mn[0][i - 1][j];
        } else mn[0][i][j] = mn[0][i - 1][j + (1 << (i - 1))];
	    if (eveb[mn[1][i - 1][j]].eb > eveb[mn[1][i - 1][j + (1 << (i - 1))]].eb)
        {
            mn[1][i][j] = mn[1][i - 1][j];
        } else mn[1][i][j] = mn[1][i - 1][j + (1 << (i - 1))];
	}
	rep(i, 1, n)
	{
	    int left = lower_bound(A + 1, A + 1 + n, ii(evea[i].sa, -1)) - A;
	    int right = upper_bound(A + 1, A + 1 + n, ii(evea[i].ea, 1e9 + 1)) - A - 1;
	    int mxL, mnR;
	    if (left <= right)
        {
            mxL = getmx(0, left, right);
            mnR = getmn(0, left, right);
            if (((evea[mnR].eb < evea[i].sb) && (mnR != i)) || ((evea[i].eb < evea[mxL].sb) && (mxL != i)))
            {
                cout << "NO";
                return 0;
            }
        }
        left = lower_bound(B + 1, B + 1 + n, ii(eveb[i].sa, -1)) - B;
        right = upper_bound(B + 1, B + 1 + n, ii(eveb[i].ea, 1e9 + 1)) - B - 1;
        if (left > right) continue;
	    mxL = getmx(1, left, right);
	    mnR = getmn(1, left, right);
	    if ((eveb[mnR].eb < eveb[i].sb && mnR != i) || (eveb[i].eb < eveb[mxL].sb && mxL != i))
        {
            cout << "NO";
            return 0;
        }
	}
	cout << "YES";
}


#include <bits/stdc++.h>

#define task "D"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define db1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define db2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define db3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, n) { cerr << #A << " = "; rep(_, 1, n) cerr << A[_] << ' '; cerr << '\n'; }
#define SZ(x) ((int)(x).size())
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vl;
const int N = 1e5 + 5;
int n, sa[N], sb[N], ea[N], eb[N], lofr[N], rofl[N];
viii right, left;
struct ITmx
{
    vi it;
    ITmx(int n) {it.assign(4 * n, 0);}
    void build(int id, int l, int r, int idd)
    {
        if (l == r)
        {
            if (idd == 1) it[id] = ea[left[l].S];
            else it[id] = ea[right[l].S];
            return;
        }
        int m = (l + r) >> 1;
        build(id << 1, l, m, idd);
        build((id << 1) | 1, m + 1, r, idd);
        it[id] = max(it[id << 1], it[(id << 1) | 1]);
    }
    int get(int id, int l, int r, int L, int R)
    {
        if (l > R || r < L || L > R) return 0;
        if (L <= l && r <= R) return it[id];
        int m = (l + r) >> 1;
        return max(get(id << 1, l, m, L, R), get((id << 1) | 1, m + 1, r, L, R));
    }
};
struct ITmn
{
    vi it;
    ITmn(int n) {it.assign(4 * n, 0);}
    void build(int id, int l, int r, int idd)
    {
        if (l == r)
        {
            if (idd == 1) it[id] = eb[left[l].S];
            else it[id] = eb[right[l].S];
            return;
        }
        int m = (l + r) >> 1;
        build(id << 1, l, m, idd);
        build((id << 1) | 1, m + 1, r, idd);
        it[id] = min(it[id << 1], it[(id << 1) | 1]);
    }
    int get(int id, int l, int r, int L, int R)
    {
        if (l > R || r < L || L > R) return 1e9 + 1;
        if (L <= l && r <= R) return it[id];
        int m = (l + r) >> 1;
        return min(get(id << 1, l, m, L, R), get((id << 1) | 1, m + 1, r, L, R));
    }
};
bool check()
{
    right.clear();
    left.clear();
    right.pb({{-1, -1}, 0});
    left.pb({{-1, -1}, 0});
    rep(i, 1, n)
    {
        right.pb({{sb[i], sa[i]}, i});
        left.pb({{sa[i], sb[i]}, i});
    }
    sort(ALL(right));
    sort(ALL(left));
    ITmx stmx1(n), stmx2(n);
    ITmn stmn2(n), stmn1(n);
    stmx1.build(1, 1, n, 0);
    stmx2.build(1, 1, n, 1);
    stmn1.build(1, 1, n, 0);
    stmn2.build(1, 1, n, 1);
    int j = -1;
    for (auto i : right)
    {
        j++;
        if (j == 0) continue;
        //DB(i.S);
        int mnr1 = lower_bound(ALL(right), iii(ii(sa[i.S], 0), 0)) - right.begin();
        int mxr1 = upper_bound(ALL(right), iii(ii(sb[i.S], 1e9 + 1), 0)) - right.begin() - 1;
        int mnr2 = j + 1, mxr2 = mxr1;
        mxr1 = j - 1;
        int mxl = max(stmx1.get(1, 1, n, mnr1, mxr1), stmx1.get(1, 1, n, mnr2, mxr2));
        int mnr = min(stmn1.get(1, 1, n, mnr1, mxr1), stmn1.get(1, 1, n, mnr2, mxr2));
        if (mxl != 0 && ((mnr < ea[i.S] && mnr1 <= mxr1) || (mxl > eb[i.S] && mnr2 <= mxr2)))
        {
            //DB(j);
            return 0;

        }

        int mnl1 = lower_bound(ALL(left), iii(ii(sa[i.S], 0), 0)) - left.begin();
        int mxl1 = upper_bound(ALL(left), iii(ii(sb[i.S], 1e9 + 1), 0)) - left.begin() - 1;
        int mnl2 = j + 1, mxl2 = mxl1;
        mxl1 = j - 1;
        mxl = max(stmx2.get(1, 1, n, mnl1, mxl1), stmx2.get(1, 1, n, mnl2, mxl2));
        mnr = min(stmn2.get(1, 1, n, mnl1, mxl1), stmn2.get(1, 1, n, mnl2, mxl2));
        if (mnr != 1e9 + 1 && ((mnr < ea[i.S] && mnl1 <= mxl1) || (mxl > eb[i.S] && mnl2 <= mxl2)))
        {
            //cout << "Fcuk: " << j << '\n';
            return 0;

        }
    }
    return 1;
}
int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n;
	rep(i, 1, n) cin >> sa[i] >> sb[i] >> ea[i] >> eb[i];
	//build_sort();
	if (!check())
    {
        cout << "NO";
        return 0;
    }
	rep(i, 1, n)
	{
	    int tema = ea[i], temb = eb[i];
	    ea[i] = sa[i], eb[i] = sb[i];
	    sa[i] = tema, sb[i] = temb;
	}
	//build_sort();
	if (check()) cout << "YES";
	else cout << "NO";
}