#include <bits/stdc++.h>
using namespace std;
int n, mod = 998244353;
vector<int> x, y, s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  x.resize(n);
  y.resize(n);
  s.resize(n);
  vector<int> u(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> u[i];
  }
  for (int i = n - 1; i >= 0; i--) {
    if (i + 1 < n) s[i] = (s[i] + s[i + 1]) % mod;
    u[i] = (u[i] + s[i]) % mod;
    int idx = upper_bound(x.begin(), x.end(), y[i]) - x.begin();
    if (i > 0 && idx < i) {
      s[i - 1] = (s[i - 1] + u[i]) % mod;
      if (idx > 0) s[idx - 1] = (s[idx - 1] - u[i] + mod) % mod;
    }
  }
  int ans = (x[n - 1] + 1) % mod;
  for (int i = 0; i < n; i++) {
    ans = (ans + 1LL * (x[i] - y[i]) * u[i]) % mod;
  }
  cout << ans << endl;
}
