#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int N = 2e5 + 10, mod = 998244353;
int f[N], sum[N];
int first[N], second[N], s[N];
int n;
int main() {
  scanf("%d", &n);
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", &first[i], &second[i], &s[i]);
    int pos = lower_bound(first + 1, first + 1 + i, second[i]) - first;
    f[i] =
        ((sum[i - 1] - sum[pos - 1] + first[i] - second[i]) % mod + mod) % mod;
    sum[i] = (sum[i - 1] + f[i]) % mod;
    if (s[i]) ans = (ans + f[i]) % mod;
  }
  ans = (ans + first[n] + 1) % mod;
  printf("%d\n", ans);
  return 0;
}
