#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
struct trio {
  long long x, y, s;
  bool operator<(const trio &o) const { return x < o.x; }
};
void solve() {
  long long n;
  cin >> n;
  vector<trio> a(n);
  for (long long i = 0; i < n; ++i) {
    cin >> a[i].x >> a[i].y >> a[i].s;
  }
  sort(a.begin(), a.end());
  long long ans = (a.back().x + 1) % MOD;
  vector<long long> jump(n, 0);
  long long curs = 0;
  map<long long, long long> delta;
  for (long long i = n - 1; i >= 0; --i) {
    while (!delta.empty() && delta.rbegin()->first >= a[i].x) {
      auto it = delta.end();
      it--;
      curs = (curs + it->second) % MOD;
      delta.erase(it);
    }
    jump[i] = (a[i].s + curs) % MOD;
    delta[a[i].y] = (delta[a[i].y] - jump[i] + MOD) % MOD;
    curs = (curs + jump[i]) % MOD;
    long long res = jump[i] * ((a[i].x - a[i].y + MOD) % MOD) % MOD;
    ans = (ans + res) % MOD;
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t = 1;
  while (t--) {
    solve();
    cout << '\n';
  }
}
