#include <bits/stdc++.h>
using namespace std;
const int maxn = 500009;
int y[maxn];
vector<pair<int, int>> arr[maxn];
pair<int, int> Q[maxn];
int L = 0, R = 0;
long long area = 0;
void remAbove(int y) {
  int prev_x = 0;
  while (L < R && Q[L].second >= y) {
    if (L + 1 < R) {
      area -= 1LL * (Q[L].second - Q[L + 1].second) * Q[L].first;
      prev_x = Q[L].first;
      L++;
    } else {
      area -= 1LL * Q[L].second * Q[L].first;
      prev_x = Q[L].first;
      L++;
    }
  }
  if (prev_x > 0) {
    area += 1LL * prev_x * (y - (L < R ? Q[L].second : 0));
    L--;
    Q[L] = {prev_x, y};
  }
}
void remRight(int x) {
  int prev_y = 0;
  while (L < R && Q[R - 1].first >= x) {
    if (L + 1 < R) {
      area -= 1LL * Q[R - 1].second * (Q[R - 1].first - Q[R - 2].first);
      prev_y = Q[R - 1].second;
      R--;
    } else {
      area -= 1LL * Q[R - 1].second * Q[R - 1].first;
      prev_y = Q[R - 1].second;
      R--;
    }
  }
  if (prev_y > 0) {
    area += 1LL * prev_y * (x - (L < R ? Q[R - 1].first : 0));
    Q[R] = {x, prev_y};
    R++;
  }
}
int main() {
  ios::sync_with_stdio(false);
  int n, p, q, r;
  cin >> n >> p >> q >> r;
  for (int i = 0; i <= p; i++) y[i] = q;
  for (int i = 0; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a = p + 1 - a;
    b = q + 1 - b;
    y[a] = min(y[a], b - 1);
    arr[c].push_back({a - 1, b - 1});
  }
  for (int i = 1; i <= p + 1; i++) {
    y[i] = min(y[i], y[i - 1]);
    if (i > 1 && y[i] < y[i - 1]) {
      area += 1LL * (i - 1 - (L == R ? 0 : Q[R - 1].first)) * y[i - 1];
      Q[R++] = {i - 1, y[i - 1]};
    }
  }
  long long ans = 0;
  for (int c = r; c >= 1; c--) {
    for (auto p : arr[c]) {
      remAbove(p.second);
      remRight(p.first);
    }
    ans += area;
  }
  cout << ans << endl;
}
