#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define REP(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define SZ(i) int(i.size())
#define eb emplace_back
#define ALL(i) i.begin(),i.end()
#define X first
#define Y second
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"#%d: %s = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
template<typename It> ostream& _printRng(ostream &os,It bg,It ed)
{
    os<<"{";
    for(It it=bg;it!=ed;it++) {
        os<<(it==bg?"":",")<<*it;
    }
    os<<"}";
    return os;
}
template<typename T> ostream &operator << (ostream &os,vector<T> &v){return _printRng(os,v.begin(), v.end());}
template<typename T> void pary(T bg, T ed){_printRng(cerr,bg,ed);cerr<<endl;}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#define pary(...)
#endif

const int MAXN = 200005;
const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;

int n, m;
ll x, y;
vector<array<int,3> > rb; // robot

void ckmax (ll &X, ll Y) {
    X = max(X, Y);
}

struct Segment_Tree {
    ll seg[MAXN*2];

    void init () {
        fill(seg,seg+2*m,-INF);
    }

    ll rqry (int l, int r) {
        ll mx = -INF;
        for (l+=m,r+=m;l<r;l>>=1,r>>=1) {
            if (l&1) {
                ckmax(mx, seg[l++]);
            }
            if (r&1) {
                ckmax(mx, seg[--r]);
            }
        }
        return mx;
    }

    void schg (int X, ll v) {
        for (seg[X+=m]=v; X>1; X>>=1) {
            seg[X>>1] = max(seg[X], seg[X^1]);
        }
    }

    void rchg (int l, int r, ll v) {
        for (l+=m,r+=m;l<r;l>>=1,r>>=1) {
            if (l&1) {
                ckmax(seg[l++], v);
            }
            if (r&1) {
                ckmax(seg[--r], v);
            }
        }
    }

    ll sqry (int X) {
        ll ret = -INF;
        for (X+=m; X>0; X>>=1) {
            ckmax(ret, seg[X]);
        }
        return ret;
    }

} dp[3][3];

vector<int> lval;

int rbd (int X) {
    array<int,3> q = {X, -iNF, -iNF};
    return lower_bound(ALL(rb), q)-rb.begin();
}

int lbd (int x) {
    return lower_bound(ALL(lval),x)-lval.begin();
}


ll pd[3][MAXN];
/*********************GoodLuck***********************/
int main () {
    IOS();

    cin >> n >> m >> x >> y;
    REP (i, m) {
        int c, l, r;
        cin >> c >> l >> r;
        lval.eb(l);
        c--;
        rb.push_back({r, l, c});
    }

    REP (i, 3) {
        REP (j, 3) {
            dp[i][j].init();
        }
    }

    sort(ALL(rb));
    sort(ALL(lval));

    ll ans = 0, cans = 0;
    REP (i, m) {
        int l, r, c;
        r = rb[i][0];
        l = rb[i][1];
        c = rb[i][2];

        ll cur = (r-l+1)*x;
        ll cc = (r-l+1)*x;

        int L = rbd(l), R = i;
        int lid = lbd(l), rid = lbd(r+1);
        REP (v, 3) {
            ckmax(cur, dp[v][0].rqry(0,L) + (r-l+1)*x);
            debug(v);
            debug(dp[v][0].rqry(0,L) + (r-l+1)*x);
            if (v == c) {
                ckmax(cur, dp[v][1].sqry(lid) + r*x);
                debug(dp[v][1].sqry(lid) + r*x);
            } else {
                ckmax(cur, dp[v][2].sqry(lid) + r*x + (l-1)*(x+y));
                debug(dp[v][2].sqry(lid) + r*x + (l-1)*(x+y));
            }

#ifdef tmd

            REP (j, i) {
                int jl = rb[j][1], jr = rb[j][0];
                if (rb[j][0] < rb[i][1]) {
                    ckmax(cc, pd[v][j] + (r-l+1)*x);
                } else if (jl < rb[i][1] && rb[i][1] <= jr) {
                    if (v == c) {
                        ckmax(cc, pd[v][j] + (r-rb[j][0])*x);
                    } else {
                        ckmax(cc, pd[v][j]+(r-jr)*x-(jr-l+1)*(x+y));
                    }
                }

            }
/*
dp[c][i] = cover <= r[i] with r[i] covered c
dp[c][i] = dp[*][j] + (r[i]-l[i]+1)*x for r[j] < r[i]
dp[c][i] = dp[c][j] + (r[i]-r[j])*x for r[j] in [l[i],r[i]]
         = dp[c][j] -r[j]*x + r[i]*x
dp[c][i] = dp[!c][j] + (r[i]-r[j])*x - (r[j]-l[i]+1)*(x+y) for r[j] in [l[i],r[i]]
         = dp[!c][j] -r[j]*(2*x+y) + r[i]*x + (l[i]+1)*(x+y)
*/

#endif // tmd
        }

        debug(i, c, l, r, L, R, cur, cc);
        dp[c][0].schg(i,cur);
        dp[c][1].rchg(lid, rid, cur-r*x);
        dp[c][2].rchg(lid, rid, cur-r*(2*x+y));

        ckmax(ans, cur);
#ifdef tmd
        ckmax(cans, cc);
        assert(cc == cur);
        REP (j, 3) {
            pd[j][i] = -INF;
        }
        pd[c][i] = cc;

#endif // tmd
    }

    cout << ans << endl;
    debug(cans);

}
/*
21 6 8 7
2 1 2
3 3 5
3 2 2
1 2 3
1 1 9
3 2 9
*/


### 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;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define REP(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define SZ(i) int(i.size())
#define eb emplace_back
#define ALL(i) i.begin(),i.end()
#define X first
#define Y second
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"#%d: %s = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
template<typename It> ostream& _printRng(ostream &os,It bg,It ed)
{
    os<<"{";
    for(It it=bg;it!=ed;it++) {
        os<<(it==bg?"":",")<<*it;
    }
    os<<"}";
    return os;
}
template<typename T> ostream &operator << (ostream &os,vector<T> &v){return _printRng(os,v.begin(), v.end());}
template<typename T> void pary(T bg, T ed){_printRng(cerr,bg,ed);cerr<<endl;}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#define pary(...)
#endif

const int MAXN = 200005;
const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;

int n, m;
ll x, y;
vector<array<int,3> > rb; // robot

void ckmax (ll &X, ll Y) {
    X = max(X, Y);
}

struct Segment_Tree {
    ll seg[MAXN*2];

    void init () {
        fill(seg,seg+2*m,-INF);
    }

    ll rqry (int l, int r) {
        ll mx = -INF;
        for (l+=m,r+=m;l<r;l>>=1,r>>=1) {
            if (l&1) {
                ckmax(mx, seg[l++]);
            }
            if (r&1) {
                ckmax(mx, seg[--r]);
            }
        }
        return mx;
    }

    void schg (int X, ll v) {
        for (seg[X+=m]=v; X>1; X>>=1) {
            seg[X>>1] = max(seg[X], seg[X^1]);
        }
    }

    void rchg (int l, int r, ll v) {
        for (l+=m,r+=m;l<r;l>>=1,r>>=1) {
            if (l&1) {
                ckmax(seg[l++], v);
            }
            if (r&1) {
                ckmax(seg[--r], v);
            }
        }
    }

    ll sqry (int X) {
        ll ret = -INF;
        for (X+=m; X>0; X>>=1) {
            ckmax(ret, seg[X]);
        }
        return ret;
    }

} dp[3][3];

vector<int> lval;

int rbd (int X) {
    array<int,3> q = {X, -iNF, -iNF};
    return lower_bound(ALL(rb), q)-rb.begin();
}

int lbd (int x) {
    return lower_bound(ALL(lval),x)-lval.begin();
}


ll pd[3][MAXN];
/*********************GoodLuck***********************/
int main () {
    IOS();

    cin >> n >> m >> x >> y;
    REP (i, m) {
        int c, l, r;
        cin >> c >> l >> r;
        lval.eb(l);
        c--;
        rb.push_back({r, l, c});
    }

    REP (i, 3) {
        REP (j, 3) {
            dp[i][j].init();
        }
    }

    sort(ALL(rb));
    sort(ALL(lval));

    ll ans = 0, cans = 0;
    REP (i, m) {
        int l, r, c;
        r = rb[i][0];
        l = rb[i][1];
        c = rb[i][2];

        ll cur = (r-l+1)*x;
        ll cc = (r-l+1)*x;

        int L = rbd(l), R = i;
        int lid = lbd(l), rid = lbd(r+1);
        REP (v, 3) {
            ckmax(cur, dp[v][0].rqry(0,L) + (r-l+1)*x);
            debug(v);
            debug(dp[v][0].rqry(0,L) + (r-l+1)*x);
            if (v == c) {
                ckmax(cur, dp[v][1].sqry(lid) + r*x);
                debug(dp[v][1].sqry(lid) + r*x);
            } else {
                ckmax(cur, dp[v][2].sqry(lid) + r*x + (l-1)*(x+y));
                debug(dp[v][2].sqry(lid) + r*x + (l-1)*(x+y));
            }

#ifdef tmd

            REP (j, i) {
                int jl = rb[j][1], jr = rb[j][0];
                if (rb[j][0] < rb[i][1]) {
                    ckmax(cc, pd[v][j] + (r-l+1)*x);
                } else if (jl < rb[i][1] && rb[i][1] <= jr) {
                    if (v == c) {
                        ckmax(cc, pd[v][j] + (r-rb[j][0])*x);
                    } else {
                        ckmax(cc, pd[v][j]+(r-jr)*x-(jr-l+1)*(x+y));
                    }
                }

            }
/*
dp[c][i] = cover <= r[i] with r[i] covered c
dp[c][i] = dp[*][j] + (r[i]-l[i]+1)*x for r[j] < r[i]
dp[c][i] = dp[c][j] + (r[i]-r[j])*x for r[j] in [l[i],r[i]]
         = dp[c][j] -r[j]*x + r[i]*x
dp[c][i] = dp[!c][j] + (r[i]-r[j])*x - (r[j]-l[i]+1)*(x+y) for r[j] in [l[i],r[i]]
         = dp[!c][j] -r[j]*(2*x+y) + r[i]*x + (l[i]+1)*(x+y)
*/

#endif // tmd
        }

        debug(i, c, l, r, L, R, cur, cc);
        dp[c][0].schg(i,cur);
        dp[c][1].rchg(lid, rid, cur-r*x);
        dp[c][2].rchg(lid, rid, cur-r*(2*x+y));

        ckmax(ans, cur);
#ifdef tmd
        ckmax(cans, cc);
        assert(cc == cur);
        REP (j, 3) {
            pd[j][i] = -INF;
        }
        pd[c][i] = cc;

#endif // tmd
    }

    cout << ans << endl;
    debug(cans);

}
/*
21 6 8 7
2 1 2
3 3 5
3 2 2
1 2 3
1 1 9
3 2 9
*/


```