#include <bits/stdc++.h>

using namespace std;

#define For(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define sz(a) ((int)a.size())
#define Rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
const int maxn = 200000 + 123;
long long n, m;
const long long INF = 1e18;
long long x, y;

struct node {
	long long value[maxn * 12];
	int n;
	void build(int ign, int n) {
		this->n = n;
		fill(value, value + (maxn * 12), -INF);
	}
	/*
	node() {}
	node(int new_lo, int new_hi) {
		lo = new_lo;
		hi = new_hi;
		left = nullptr;
		right = nullptr;
		value = -INF;
	}*/
	void update(int cur, int L, int R, int pos, long long new_value) {
		if (L > pos || R < pos) return;
		if (L == R) {
			value[cur] = max(value[cur], new_value);
			return;
		}
		int mid = (L + R) / 2;
		update(cur * 2, L, mid, pos, new_value);
		update(cur * 2 + 1, mid + 1, R, pos, new_value);
		value[cur] = max(value[cur * 2], value[cur * 2 + 1]);
	}
	void update(int pos, long long new_value) {
		update(1, 0, n - 1, pos, new_value); 
	}
	
	long long query(int cur, int L, int R, int l, int r) {
		if (L > r || R < l) return -INF;
		if (l <= L && R <= r) return value[cur];
		int mid = (L + R) / 2;
		return max(query(cur * 2, L, mid, l, r), 
			query(cur * 2 + 1, mid + 1, R, l, r));
	}
	long long query(int L, int R) {
		return query(1, 0, n - 1, L, R);
	}

} treeFirst[3], treeSecond[3], tree;

typedef pair<int,int> pt;
struct segment{
	int color;
	long long u, v;
	
	void read() {
		cin >> color >> u >> v;
		--color;
		++v;
	}
	
	bool operator < (const segment b) const {
		return u < b.u;
	}
} a[maxn];

vector<int> coor;
int nc;
void readData() {
	cin >> n >> m >> x >> y; y += x;
	For(i,1,m) a[i].read();
	
	coor.push_back(n);
	coor.push_back(n + 1);
	coor.push_back(1);
	for(int i = 1; i <= m; i++) {
		coor.push_back(a[i].u);
		coor.push_back(a[i].v);
		coor.push_back(a[i].v - 1);
	}
	sort(coor.begin(), coor.end());
	nc = unique(coor.begin(), coor.end()) - coor.begin();
	coor.resize(nc);
	
}


long long dp[maxn];

void maximize(long long &a, long long b) {
	if (a < b) a = b;
}


int l[maxn], r[maxn];

void process() {
	//cout << n << endl;
	sort(a + 1, a + 1 + m);
	Rep(i, 3) treeFirst[i].build(0, nc - 1);
	Rep(i, 3) treeSecond[i].build(0, nc - 1);
	tree.build(0, nc - 1);
	
	For(i,1,m) dp[i] = -INF;
	For(i,1,m) l[i] = a[i].u, r[i] = a[i].v;

	For(i,1,m) {
		long long mx = 0;
		
		int cL = lower_bound(coor.begin(), coor.end(), a[i].u) 
			- coor.begin();
		int cR = lower_bound(coor.begin(), coor.end(), a[i].v) 
			- coor.begin();
		Rep(c, 3) {
			maximize(mx, tree.query(0, cL));
		}
		mx += (r[i] - l[i]) * x;
		maximize(dp[i], mx);
		//cout << i << ' ' << dp[i] << endl;
		
		
		Rep(c, 3) {
			if (c != a[i].color) {
				maximize(dp[i], treeFirst[c].query(cL, cR - 1) 
						+ r[i] * x + l[i] * y);
			}  else {
				maximize(dp[i], treeSecond[c].query(cL, cR - 1)
						+ r[i] * x);
			}
			//cout << i << ' ' << dp[i] << endl;
		}
		//cout << i << ' ' << dp[i] << endl;
		
		tree.update(cR, dp[i]);
		treeFirst[a[i].color].update(cR, dp[i] - r[i] * (x + y));
		treeSecond[a[i].color].update(cR, dp[i] - r[i] * x);
	}
	
	long long ans = 0;
	For(i,1,m) maximize(ans, dp[i]);
	
	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	//freopen("input.txt", "r", stdin);
	readData();
	process();
	
	return 0;
}


### Prompt

Please create a solution in cpp to the following 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

### Response

```cpp
#include <bits/stdc++.h>

using namespace std;

#define For(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define sz(a) ((int)a.size())
#define Rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
const int maxn = 200000 + 123;
long long n, m;
const long long INF = 1e18;
long long x, y;

struct node {
	long long value[maxn * 12];
	int n;
	void build(int ign, int n) {
		this->n = n;
		fill(value, value + (maxn * 12), -INF);
	}
	/*
	node() {}
	node(int new_lo, int new_hi) {
		lo = new_lo;
		hi = new_hi;
		left = nullptr;
		right = nullptr;
		value = -INF;
	}*/
	void update(int cur, int L, int R, int pos, long long new_value) {
		if (L > pos || R < pos) return;
		if (L == R) {
			value[cur] = max(value[cur], new_value);
			return;
		}
		int mid = (L + R) / 2;
		update(cur * 2, L, mid, pos, new_value);
		update(cur * 2 + 1, mid + 1, R, pos, new_value);
		value[cur] = max(value[cur * 2], value[cur * 2 + 1]);
	}
	void update(int pos, long long new_value) {
		update(1, 0, n - 1, pos, new_value); 
	}
	
	long long query(int cur, int L, int R, int l, int r) {
		if (L > r || R < l) return -INF;
		if (l <= L && R <= r) return value[cur];
		int mid = (L + R) / 2;
		return max(query(cur * 2, L, mid, l, r), 
			query(cur * 2 + 1, mid + 1, R, l, r));
	}
	long long query(int L, int R) {
		return query(1, 0, n - 1, L, R);
	}

} treeFirst[3], treeSecond[3], tree;

typedef pair<int,int> pt;
struct segment{
	int color;
	long long u, v;
	
	void read() {
		cin >> color >> u >> v;
		--color;
		++v;
	}
	
	bool operator < (const segment b) const {
		return u < b.u;
	}
} a[maxn];

vector<int> coor;
int nc;
void readData() {
	cin >> n >> m >> x >> y; y += x;
	For(i,1,m) a[i].read();
	
	coor.push_back(n);
	coor.push_back(n + 1);
	coor.push_back(1);
	for(int i = 1; i <= m; i++) {
		coor.push_back(a[i].u);
		coor.push_back(a[i].v);
		coor.push_back(a[i].v - 1);
	}
	sort(coor.begin(), coor.end());
	nc = unique(coor.begin(), coor.end()) - coor.begin();
	coor.resize(nc);
	
}


long long dp[maxn];

void maximize(long long &a, long long b) {
	if (a < b) a = b;
}


int l[maxn], r[maxn];

void process() {
	//cout << n << endl;
	sort(a + 1, a + 1 + m);
	Rep(i, 3) treeFirst[i].build(0, nc - 1);
	Rep(i, 3) treeSecond[i].build(0, nc - 1);
	tree.build(0, nc - 1);
	
	For(i,1,m) dp[i] = -INF;
	For(i,1,m) l[i] = a[i].u, r[i] = a[i].v;

	For(i,1,m) {
		long long mx = 0;
		
		int cL = lower_bound(coor.begin(), coor.end(), a[i].u) 
			- coor.begin();
		int cR = lower_bound(coor.begin(), coor.end(), a[i].v) 
			- coor.begin();
		Rep(c, 3) {
			maximize(mx, tree.query(0, cL));
		}
		mx += (r[i] - l[i]) * x;
		maximize(dp[i], mx);
		//cout << i << ' ' << dp[i] << endl;
		
		
		Rep(c, 3) {
			if (c != a[i].color) {
				maximize(dp[i], treeFirst[c].query(cL, cR - 1) 
						+ r[i] * x + l[i] * y);
			}  else {
				maximize(dp[i], treeSecond[c].query(cL, cR - 1)
						+ r[i] * x);
			}
			//cout << i << ' ' << dp[i] << endl;
		}
		//cout << i << ' ' << dp[i] << endl;
		
		tree.update(cR, dp[i]);
		treeFirst[a[i].color].update(cR, dp[i] - r[i] * (x + y));
		treeSecond[a[i].color].update(cR, dp[i] - r[i] * x);
	}
	
	long long ans = 0;
	For(i,1,m) maximize(ans, dp[i]);
	
	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	//freopen("input.txt", "r", stdin);
	readData();
	process();
	
	return 0;
}


```