#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



struct Info{

	bool operator<(const struct Info &arg) const{
		if(left != arg.left){

			return left < arg.left;
		}else{

			return right < arg.right;
		}
	};

	ll color,left,right;
};

int N;
ll table[7][2000005];
map<int,int> MAP;
Info info[200005];


void init(int first_N){
	while(N < first_N)N *= 2;
}

void update(int index,int loc,ll value){
	loc += N-1;

	if(table[index][loc] >= value)return;

	table[index][loc] = value;

	if(N == 1)return;

	int parent = (loc-1)/2;

	while(true){
		table[index][parent] = max(table[index][2*parent+1],table[index][2*parent+2]); //親は左右の子の大きい方の値を持つ

		if(parent == 0)break;
		else{
			parent = (parent-1)/2;
		}
	}
}


ll query(int index,int search_left,int search_right,int node_id,int node_left,int node_right){

	if(search_right < node_left || search_left > node_right)return -HUGE_NUM;

	if(search_left <= node_left && search_right >= node_right){
		return table[index][node_id];
	}

	ll left_max = query(index,search_left,search_right,2*node_id+1,node_left,(node_left+node_right)/2);
	ll right_max = query(index,search_left,search_right,2*node_id+2,(node_left+node_right)/2+1,node_right);

	return max(left_max,right_max);
}


int main(){

	int num_panel,num_robot;
	ll X,Y;

	scanf("%d %d %lld %lld",&num_panel,&num_robot,&X,&Y);

	vector<int> V;
	V.push_back(0);

	for(int i = 0; i < num_robot; i++){

		scanf("%lld %lld %lld",&info[i].color,&info[i].left,&info[i].right);
		V.push_back(info[i].left);
		V.push_back(info[i].right);
	}

	sort(V.begin(),V.end());
	V.erase(unique(V.begin(),V.end()),V.end());

	for(int i = 0; i < V.size(); i++){

		MAP[V[i]] = i;
	}

	int first_N = V.size();
	N = 1;
	init(first_N);

	for(int i = 0; i < 7; i++){
		for(int k = 0; k <= 2*N-2; k++){

			table[i][k] = -HUGE_NUM;
		}
	}

	update(0,0,0);

	sort(info,info+num_robot);

	ll ans = 0;
	ll tmp_value;

	for(int i = 0; i < num_robot; i++){

		tmp_value = query(0,0,MAP[info[i].left]-1,0,0,N-1)+(info[i].right-info[i].left+1)*X; //過去最大値+今回の値(重なりなし)

		//重なりあり
		for(int k = 1; k <= 3; k++){
			if(k == info[i].color){

				tmp_value = max(tmp_value,query(k,MAP[info[i].left],MAP[info[i].right]-1,0,0,N-1)+info[i].right*X);

			}else{

				tmp_value = max(tmp_value,query(k+3,MAP[info[i].left],MAP[info[i].right]-1,0,0,N-1)+
						(info[i].left+info[i].right-1)*X+(info[i].left-1)*Y);
			}
		}

		ans = max(ans,tmp_value);

		update(0,MAP[info[i].right],tmp_value); //全体
		update(info[i].color,MAP[info[i].right],tmp_value-info[i].right*X);
		update(info[i].color+3,MAP[info[i].right],tmp_value-info[i].right*(2*X+Y));
	}

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

	return 0;
}

