#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int add(int x, int y) {
  x += y;
  while (x >= MOD) {
    x -= MOD;
  }
  while (x < 0) {
    x += MOD;
  }
  return x;
}
int mul(int x, int y) { return (x * 1ll * y) % MOD; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> rt(n + 1), lt(n + 1), s(n + 1), freq(n + 1);
  vector<pair<pair<int, int>, int>> vp;
  for (int i = 1; i <= n; i++) {
    cin >> rt[i] >> lt[i] >> s[i];
    vp.push_back({{rt[i], 1}, i});
    vp.push_back({{lt[i], 2}, i});
  }
  sort(vp.begin(), vp.end());
  reverse(vp.begin(), vp.end());
  int sol = rt[n] + 1;
  int x = 1;
  for (auto e : vp) {
    int pos = e.first.first;
    int type = e.first.second;
    int idx = e.second;
    if (type == 1) {
      int z = add(add(x, s[idx]), -1);
      sol = add(sol, mul(z, rt[idx] - lt[idx]));
      freq[idx] = z;
      x = add(x, z);
    } else {
      x = add(x, -freq[idx]);
    }
  }
  cout << sol << "\n";
  return 0;
}
