#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long MAX = 2005, mod = 1e9 + 7;
using ii = pair<long long, long long>;
ii a[MAX];
ii b[MAX];
long long c[MAX];
long long A[MAX], B[MAX];
vector<long long> pr[MAX], ad[MAX];
long long pre[MAX];
long long cnt[MAX];
ll ST[MAX * 4];
long long MX[MAX * 4], LZ[MAX * 4];
long long val;
long long pos[MAX];
void build(long long id, long long l, long long r) {
  LZ[id] = 0;
  if (l == r) {
    MX[id] = pos[l];
    ST[id] = (B[pos[l]] + 1) * (B[r + 1] - B[r]);
    return;
  }
  long long mid = l + r >> 1;
  build(id << 1 | 1, mid + 1, r);
  build(id << 1, l, mid);
  ST[id] = ST[id << 1] + ST[id << 1 | 1];
  MX[id] = max(MX[id << 1], MX[id << 1 | 1]);
}
bool tt = 0;
void upd(long long x, long long id, long long l, long long r) {
  if (tt) {
    if (r <= x) {
      MX[id] = val;
      ST[id] = (B[val] + 1) * (B[r + 1] - B[l]);
      LZ[id] = val;
      return;
    }
    long long mid = l + r >> 1;
    if (LZ[id]) {
      MX[id << 1] = MX[id << 1 | 1] = LZ[id];
      LZ[id << 1] = LZ[id << 1 | 1] = LZ[id];
      ST[id << 1] = (B[LZ[id]] + 1) * (B[mid + 1] - B[l]);
      ST[id << 1 | 1] = (B[LZ[id]] + 1) * (B[r + 1] - B[mid + 1]);
      LZ[id] = 0;
    }
    upd(x, id << 1, l, mid);
    if (x > mid) upd(x, id << 1 | 1, mid + 1, r);
    ST[id] = ST[id << 1] + ST[id << 1 | 1];
    MX[id] = max(MX[id << 1], MX[id << 1 | 1]);
    return;
  }
  if (l == r) {
    tt = 1;
    MX[id] = val;
    ST[id] = (B[val] + 1) * (B[r + 1] - B[r]);
    return;
  }
  long long mid = l + r >> 1;
  if (LZ[id]) {
    MX[id << 1] = MX[id << 1 | 1] = LZ[id];
    LZ[id << 1] = LZ[id << 1 | 1] = LZ[id];
    ST[id << 1] = (B[LZ[id]] + 1) * (B[mid + 1] - B[l]);
    ST[id << 1 | 1] = (B[LZ[id]] + 1) * (B[r + 1] - B[mid + 1]);
    LZ[id] = 0;
  }
  if (MX[id << 1] > val) upd(x, id << 1, l, mid);
  if (x > mid) upd(x, id << 1 | 1, mid + 1, r);
  ST[id] = ST[id << 1] + ST[id << 1 | 1];
  MX[id] = max(MX[id << 1], MX[id << 1 | 1]);
}
long long N, M;
void down(long long lim, long long vall) {
  if (MX[1] <= vall) return;
  val = vall;
  tt = 0;
  upd(lim, 1, 1, M);
}
multiset<long long> col[MAX];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, K, L;
  cin >> n >> K >> L;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i].first >> a[i].second >> c[i];
    b[i] = ii(a[i].first, i);
  }
  sort(b + 1, b + 1 + n);
  N = 0;
  A[0] = -1;
  for (long long i = 1; i <= n; i++) {
    if (b[i].first != A[N]) A[++N] = b[i].first;
    a[b[i].second].first = N;
    b[i] = ii(a[i].second, i);
  }
  A[N + 1] = L;
  sort(b + 1, b + 1 + n);
  M = 0;
  B[0] = -1;
  for (long long i = 1; i <= n; i++)
    if (b[i].first != B[M]) {
      B[++M] = b[i].first;
      a[b[i].second].second = M;
    } else
      a[b[i].second].second = M;
  B[M + 1] = L;
  for (long long i = 1; i <= n; i++) {
    pr[a[i].first].push_back(i);
    ad[a[i].second].push_back(i);
  }
  ll ans = 0;
  for (long long cs = 1; cs <= N; cs++) {
    memset(pre, 0, sizeof pre);
    memset(cnt, 0, sizeof cnt);
    cnt[0] = K;
    long long poi = 0;
    for (long long i = 1; i <= K; i++) {
      col[i].clear();
      col[i].insert(M + 1);
    }
    for (long long i = 1; i <= M; i++) {
      for (long long u : ad[i])
        if (a[u].first <= cs) {
          cnt[pre[c[u]]]--;
          pre[c[u]] = i;
          cnt[i]++;
          col[c[u]].insert(i);
        }
      while (cnt[poi] == 0) poi++;
      pos[i] = poi;
    }
    build(1, 1, M);
    ans = (ans + ST[1] % mod * (A[cs + 1] - A[cs]) % mod * (A[1] + 1)) % mod;
    for (long long i = 1; i < cs; i++) {
      for (long long u : pr[i]) {
        long long x = c[u];
        col[x].erase(col[x].find(a[u].second));
        auto it = col[x].upper_bound(a[u].second);
        if (it != col[x].begin())
          down((*it) - 1, (*prev(it)));
        else {
          down((*it) - 1, 0);
        }
      }
      ans =
          (ans + ST[1] % mod * (A[cs + 1] - A[cs]) % mod * (A[i + 1] - A[i])) %
          mod;
    }
  }
  ans = (ans % mod + mod) % mod;
  cout << ans << '\n';
}
