#include <bits/stdc++.h>
using namespace std;
const int N = 5e5;
const int M = 1 << 19;
int n, p, q, r;
int a[N];
int b[N];
int c[N];
long long col[N];
long long tree[2 * M];
long long sum[2 * M];
long long need[2 * M];
long long inf = 1e18;
void push(int i, int l, int r) {
  if (l < r) {
    if (need[i] != -1) {
      tree[2 * i] = tree[2 * i + 1] = need[i];
      sum[2 * i] = sum[2 * i + 1] = need[i] * (r - l + 1) / 2;
      need[2 * i] = need[2 * i + 1] = need[i];
      need[i] = -1;
    }
  }
}
int fnd(long long d, int i = 1, int l = 0, int r = M - 1) {
  push(i, l, r);
  if (l == r) return l;
  int m = (l + r) / 2;
  if (tree[2 * i] > d) return fnd(d, 2 * i, l, m);
  return fnd(d, 2 * i + 1, m + 1, r);
}
void upd(int tl, int tr, long long d, int i = 1, int l = 0, int r = M - 1) {
  push(i, l, r);
  if (l > tr || r < tl) return;
  if (l >= tl && r <= tr) {
    need[i] = d;
    tree[i] = d;
    sum[i] = d * (r - l + 1);
    return;
  }
  int m = (l + r) / 2;
  upd(tl, tr, d, 2 * i, l, m);
  upd(tl, tr, d, 2 * i + 1, m + 1, r);
  tree[i] = max(tree[2 * i], tree[2 * i + 1]);
  sum[i] = sum[2 * i] + sum[2 * i + 1];
}
long long res(int tl, int tr, int i = 1, int l = 0, int r = M - 1) {
  push(i, l, r);
  if (l > tr || r < tl) return 0;
  if (l >= tl && r <= tr) return sum[i];
  int m = (l + r) / 2;
  return res(tl, tr, 2 * i, l, m) + res(tl, tr, 2 * i + 1, m + 1, r);
}
int main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> p >> q >> r;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    c[i]--;
  }
  vector<pair<int, int> > v;
  for (int i = 0; i < n; i++) v.push_back(make_pair(b[i], c[i]));
  sort(v.begin(), v.end());
  int j = n - 1;
  int mn = 0;
  for (int i = q - 1; i >= 0; i--) {
    while (j >= 0 && v[j].first == i) {
      mn = max(mn, v[j].second + 1);
      j--;
    }
    col[i] = r - mn;
  }
  fill(tree, tree + 2 * M, -1);
  fill(sum, sum + 2 * M, 0);
  fill(need, need + 2 * M, -1);
  for (int i = 0; i < q; i++) sum[M + i] = tree[M + i] = col[i];
  for (int i = M - 1; i >= 1; i--) {
    tree[i] = max(tree[2 * i], tree[2 * i + 1]);
    sum[i] = sum[2 * i] + sum[2 * i + 1];
  }
  vector<pair<pair<int, int>, int> > w;
  for (int i = 0; i < n; i++)
    w.push_back(make_pair(make_pair(a[i], b[i]), c[i]));
  sort(w.begin(), w.end());
  j = n - 1;
  mn = 0;
  long long ans = 0;
  int mn1 = 0;
  for (int i = p - 1; i >= 0; i--) {
    while (j >= 0 && w[j].first.first == i) {
      mn = max(mn, w[j].first.second + 1);
      mn1 = max(mn1, w[j].second + 1);
      j--;
    }
    int k = fnd(r - mn1);
    if (k < q) upd(k, q - 1, r - mn1);
    if (mn < q) ans += res(mn, q - 1);
  }
  cout << ans << endl;
  return 0;
}
