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>
using namespace std;

using ll = long long;
const ll INF = 1e18;

const int S = 1 << 19;
ll seg[7][2*S];
// half-open
ll query(int z, int l, int r) {
	ll ans = -INF;
	for (int a=S+l, b = S+r; a < b; a /= 2, b /= 2) {
		if (a & 1) {
			ans = max(ans, seg[z][a++]);
		}
		if (b & 1) {
			ans = max(ans, seg[z][--b]);
		}
	}
	return ans;
}
void update(int z, int i, ll v) {
	for (int a = S+i; a; a /= 2) {
		seg[z][a] = max(seg[z][a], v);
	}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	ll N; int M; ll X, Y; cin >> N >> M >> X >> Y;

	vector<pair<pair<ll, ll>, int>> robots;
	vector<ll> coords;
	for (int i = 0; i < M; i++) {
		int c; ll l, r; cin >> c >> l >> r; l--; c--;
		robots.push_back({{l,r},c});
		coords.push_back(r);
	}
	sort(robots.begin(), robots.end());
	sort(coords.begin(), coords.end());
	coords.resize(unique(coords.begin(), coords.end()) - coords.begin());

	for (int z = 0; z < 7; z++) {
		for (int i = 0; i < 2 * S; i++) {
			seg[z][i] = -INF;
		}
	}

	ll ans = 0;
	for (auto it : robots) {
		ll l = it.first.first, r = it.first.second; int c = it.second;
		int li = int(upper_bound(coords.begin(), coords.end(), l) - coords.begin());
		int ri = int(upper_bound(coords.begin(), coords.end(), r) - coords.begin());

		ll v = 0;
		v = max(v, query(6, 0, li));
		v = max(v, query(3+c, li, ri) + X * l);
		v = max(v, query((c+1)%3, li, ri) + (X + X + Y) * l);
		v = max(v, query((c+2)%3, li, ri) + (X + X + Y) * l);
		v += (r - l) * X;

		ans = max(ans, v);

		update(6, ri-1, v);
		update(3+c, ri-1, v - X * r);
		update(c, ri-1, v - (X + X + Y) * r);
	}
	cout << ans << '\n';

	return 0;
}