#define dbg(x) cerr << #x"=" << x << endl; typedeflonglong LL; int n; const LL MOD = 998244353; typedef pair<LL, LL> P; #define len first #define cnt second #define val first #define id second constint MAX_N = 5*1e5+100; const LL INF = 1e9; P a[MAX_N]; P bit[MAX_N]; int dp[MAX_N]; P L[MAX_N], R[MAX_N];