Problem: Wall Painting

Here stands a wall made of a number of vertical panels. The panels are not painted yet.

You have a number of robots each of which can paint panels in a single color, either red, green, or blue. Each of the robots, when activated, paints panels between a certain position and another certain position in a certain color. The panels painted and the color to paint them are fixed for each of the robots, but which of them are to be activated and the order of their activation can be arbitrarily decided.

You’d like to have the wall painted to have a high aesthetic value. Here, the aesthetic value of the wall is defined simply as the sum of aesthetic values of the panels of the wall, and the aesthetic value of a panel is defined to be:

* 0, if the panel is left unpainted.
* The bonus value specified, if it is painted only in a single color, no matter how many times it is painted.
* The penalty value specified, if it is once painted in a color and then overpainted in one or more different colors.



Input

The input consists of a single test case of the following format.


$n$ $m$ $x$ $y$
$c_1$ $l_1$ $r_1$
.
.
.
$c_m$ $l_m$ $r_m$


Here, $n$ is the number of the panels ($1 \leq n \leq 10^9$) and $m$ is the number of robots ($1 \leq m \leq 2 \times 10^5$). $x$ and $y$ are integers between $1$ and $10^5$, inclusive. $x$ is the bonus value and $-y$ is the penalty value. The panels of the wall are consecutively numbered $1$ through $n$. The $i$-th robot, when activated, paints all the panels of numbers $l_i$ through $r_i$ ($1 \leq l_i \leq r_i \leq n$) in color with color number $c_i$ ($c_i \in \\{1, 2, 3\\}$). Color numbers 1, 2, and 3 correspond to red, green, and blue, respectively.

Output

Output a single integer in a line which is the maximum achievable aesthetic value of the wall.

Sample Input 1


8 5 10 5
1 1 7
3 1 2
1 5 6
3 1 4
3 6 8


Sample Output 1


70


Sample Input 2


26 3 9 7
1 11 13
3 1 11
3 18 26


Sample Output 2


182


Sample Input 3


21 10 10 5
1 10 21
3 4 16
1 1 7
3 11 21
3 1 16
3 3 3
2 1 17
3 5 18
1 7 11
2 3 14


Sample Output 3


210


Sample Input 4


21 15 8 7
2 12 21
2 1 2
3 6 13
2 13 17
1 11 19
3 3 5
1 12 13
3 2 2
1 12 15
1 5 17
1 2 3
1 1 9
1 8 12
3 8 9
3 2 9


Sample Output 4


153






Example

Input

8 5 10 5
1 1 7
3 1 2
1 5 6
3 1 4
3 6 8


Output

70

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#define N 400500
#define int long long
using namespace std;
int Ans, mx[3][3][N << 2], X, Y, m, n, num[N], cnt;
struct Data{int c, l, r;}d[N];
bool cmpl(Data a, Data b){return a.l < b.l;}
void pushup(int rt, int c){
	for(int i = 0; i < 3; i++)
		mx[c][i][rt] = max(mx[c][i][rt << 1], mx[c][i][rt << 1 | 1]);
}
void build(int rt, int l, int r){
	if(l == r){
		for(int i = 0; i < 3; i++){
			mx[i][0][rt] = 0;
			mx[i][1][rt] = X * (-1 - num[l]);
			mx[i][2][rt] = (X + X + Y) * (-1 - num[l]);
		}
		return ;
	}
	int mid = (l + r) >> 1;
	build(rt << 1, l, mid);
	build(rt << 1 | 1, mid + 1, r);
	pushup(rt, 0);pushup(rt, 1);pushup(rt, 2);
}
void update(int rt, int l, int r, int x, int y, int c){
	if(l == r){
		mx[c][0][rt] = max(mx[c][0][rt], y);
		mx[c][1][rt] = mx[c][0][rt] + X * (-1 - num[l]);
		mx[c][2][rt] = mx[c][0][rt] + (X + X + Y) * (-1 - num[l]);
		return ;
	}
	int mid = (l + r) >> 1;
	if(x <= mid) update(rt << 1, l, mid, x, y, c);
	else update(rt << 1 | 1, mid + 1, r, x, y, c);
	pushup(rt, c);
}
int query(int rt, int l, int r, int x, int y, int c, int d){
	if(x <= l && r <= y) return mx[c][d][rt];
	int mid = (l + r) >> 1;
	if(y <= mid) return query(rt << 1, l, mid, x, y, c, d);
	if(x > mid) return query(rt << 1 | 1, mid + 1, r, x, y, c, d);
	return max(query(rt << 1, l, mid, x, y, c, d),
			   query(rt << 1 | 1, mid + 1, r, x, y, c, d));
}
signed main(){
	scanf("%lld%lld%lld%lld", &n, &m, &X, &Y);
	for(int i = 1; i <= m; i++){
		scanf("%lld%lld%lld", &d[i].c, &d[i].l, &d[i].r);
		d[i].c--;
		num[++cnt] = d[i].l;
		num[++cnt] = d[i].r;
	}
	sort(num + 1, num + cnt + 1);
	cnt = unique(num + 1, num + cnt + 1) - num - 1;
	sort(d + 1, d + m + 1, cmpl);
	for(int i = 1; i <= m; i++){
		d[i].l = lower_bound(num + 1, num + cnt + 1, d[i].l) - num;
		d[i].r = lower_bound(num + 1, num + cnt + 1, d[i].r) - num;
	}
	build(1, 0, cnt);
	for(int i = 1; i <= m; i++){
		int ans = LLONG_MIN;
		for(int j = 0; j < 3; j++){
			ans = max(ans, query(1, 0, cnt, 0, d[i].l - 1, j, 0));
			if(d[i].l < d[i].r){
				if(j == d[i].c) ans = max(ans, query(1, 0, cnt, d[i].l, d[i].r - 1, j, 1) + num[d[i].l] * X);
				else ans = max(ans, query(1, 0, cnt, d[i].l, d[i].r - 1, j, 2) + num[d[i].l] * (X + X + Y));
			}
		}
		ans += (num[d[i].r] - num[d[i].l] + 1) * X;
		update(1, 0, cnt, d[i].r, ans, d[i].c);
	}
	for(int i = 0; i < 3; i++)
		Ans = max(Ans, query(1, 0, cnt, 0, cnt, i, 0));
	printf("%lld\n", Ans);
	return 0;
}