#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
int n, p, q, r;
int T[N << 2], lz[N << 2];
long long S[N << 2];
vector<pair<int, int> > vec[N];
int bb[N], cc[N];
void push(int v, int l, int r) {
  if (lz[v] == 0) return;
  if (l < r)
    lz[v << 1] = max(lz[v << 1], lz[v]),
            lz[v << 1 | 1] = max(lz[v << 1 | 1], lz[v]);
  if (lz[v] > T[v]) {
    T[v] = lz[v];
    S[v] = 1LL * T[v] * (r - l + 1);
  }
  lz[v] = 0;
}
void upd(int v, int l, int r, int L, int R, int val) {
  push(v, l, r);
  if (l > r || R < l || L > r) return;
  if (L <= l && r <= R) {
    lz[v] = val;
    push(v, l, r);
    return;
  }
  upd(v << 1, l, ((l + r) >> 1), L, R, val);
  upd(v << 1 | 1, ((l + r) >> 1) + 1, r, L, R, val);
  T[v] = max(T[v << 1], T[v << 1 | 1]);
  S[v] = S[v << 1] + S[v << 1 | 1];
}
long long get(int v, int l, int r, int L, int R) {
  push(v, l, r);
  if (l > r || R < l || L > r) return 0;
  if (L <= l && r <= R) return S[v];
  return get(v << 1, l, ((l + r) >> 1), L, R) +
         get(v << 1 | 1, ((l + r) >> 1) + 1, r, L, R);
}
int far(int v, int l, int r, int c) {
  if (l == r) {
    if (T[v] >= c)
      return l;
    else
      return 0;
  }
  push(v << 1, l, ((l + r) >> 1));
  push(v << 1 | 1, ((l + r) >> 1) + 1, r);
  if (T[v << 1 | 1] >= c)
    return far(v << 1 | 1, ((l + r) >> 1) + 1, r, c);
  else
    return far(v << 1, l, ((l + r) >> 1), c);
}
long long ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> p >> q >> r;
  for (int i = 1; i <= n; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    vec[a].push_back(make_pair(b, c));
  }
  for (int i = p; i >= 0; --i) {
    bb[i] = bb[i + 1], cc[i] = cc[i + 1];
    for (auto cur : vec[i])
      bb[i] = max(bb[i], cur.first), cc[i] = max(cc[i], cur.second);
  }
  int mxb = 1;
  for (int P = 1; P <= p; ++P) {
    for (auto cur : vec[P - 1]) {
      int b = cur.first, c = cur.second;
      if (c > r) mxb = max(mxb, b + 1);
      if (b > q) b = q;
      int fart = far(1, 1, q, c);
      upd(1, 1, q, fart + 1, b, c);
    }
    int B = max(mxb, bb[P] + 1);
    int fart = far(1, 1, q, cc[P]);
    if (fart < B) fart = B - 1;
    ans += 1LL * (q - B + 1) * r;
    ans -= (get(1, 1, q, B, fart) + 1LL * cc[P] * (q - fart));
  }
  cout << ans << endl;
}
