#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;
const long long N = 2e5 + 100;
long long long long mod = 998244353;
long long long long x[N];
long long long long y[N];
long long long long s[N];
long long long long dp[N];
long long long long par[N];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> x[i] >> y[i] >> s[i];
  }
  for (long long i = 1; i <= n; i++) {
    dp[i] = x[i] - y[i];
    long long long long z = upper_bound(x + 1, x + n + 1, y[i]) - x;
    dp[i] += par[i - 1] - par[z - 1];
    dp[i] += mod;
    dp[i] %= mod;
    par[i] = par[i - 1] + dp[i];
    par[i] %= mod;
  }
  long long long long ans = x[n] + 1;
  for (long long i = 1; i <= n; i++) {
    if (s[i]) ans += dp[i];
    ans %= mod;
  }
  cout << ans << endl;
}
