human
An ant moves on the real line with constant speed of 1 unit per second. It starts at 0 and always moves to the right (so its position increases by 1 each second).

There are n portals, the i-th of which is located at position x_i and teleports to position y_i < x_i. Each portal can be either active or inactive. The initial state of the i-th portal is determined by s_i: if s_i=0 then the i-th portal is initially inactive, if s_i=1 then the i-th portal is initially active. When the ant travels through a portal (i.e., when its position coincides with the position of a portal): 

  * if the portal is inactive, it becomes active (in this case the path of the ant is not affected).

  * if the portal is active, it becomes inactive and the ant is instantly teleported to the position y_i, where it keeps on moving as normal. 


How long (from the instant it starts moving) does it take for the ant to reach the position x_n + 1? It can be shown that this happens in a finite amount of time. Since the answer may be very large, compute it modulo 998 244 353.

Input

The first line contains the integer n (1≤ n≤ 2⋅ 10^5) — the number of portals.

The i-th of the next n lines contains three integers x_i, y_i and s_i (1≤ y_i < x_i≤ 10^9, s_i∈\{0,1\}) — the position of the i-th portal, the position where the ant is teleported when it travels through the i-th portal (if it is active), and the initial state of the i-th portal.

The positions of the portals are strictly increasing, that is x_1<x_2<⋅⋅⋅<x_n. It is guaranteed that the 2n integers x_1,   x_2,   ...,   x_n,   y_1,   y_2,   ...,   y_n are all distinct.

Output

Output the amount of time elapsed, in seconds, from the instant the ant starts moving to the instant it reaches the position x_n+1. Since the answer may be very large, output it modulo 998 244 353.

Examples

Input

4
3 2 0
6 5 1
7 4 0
8 1 1

Output

23

Input

1
454971987 406874902 1

Output

503069073

Input

5
243385510 42245605 0
644426565 574769163 0
708622105 208990040 0
786625660 616437691...

def
assistant
#Here is Python program to compute it modulo 998 244 353.
naiveSolve():
    
    
    
    return


def main():
    
    n=int(input())
    x=[]
    y=[]
    s=[]
    for _ in range(n):
        xx,yy,ss=readIntArr()
        x.append(xx)
        y.append(yy)
        s.append(ss)
    # when ant is at x[i], all prev. x[i] are active.
    # let t[i] be time to get back to x[i] after stepping on it while it is active
    # is x[i] is active, time it takes to go on x[i]=x[i]-y[i]+sum(t[i] for all x between y[i] and x[i])
    t=[0]*n
    p=[0]*n # prefix sums for t
    def update(i,time):
        time%=MOD
        t[i]=time
        p[i]=time
        if i-1>=0:
            p[i]+=p[i-1]
            p[i]%=MOD
    def rangeQuery(tLeft,tRight): # returns the sum of t[i] for tLeft<time<tRight
        iLeft=-1
        b=n
        while b>0:
            while b+iLeft<n and x[b+iLeft]<=tLeft:
                iLeft+=b
            b//=2
        iLeft+=1
        
        iRight=-1
        b=n
        while b>0:
            while b+iRight<n and x[b+iRight]<tRight:
                iRight+=b
            b//=2
        if iRight==-1:
            return 0
        # print('iLeft:{} iRight:{}'.format(iLeft,iRight))
        if iLeft==0: return p[iRight]
        else: return p[iRight]-p[iLeft-1]
    
    for i in range(n):
        # print('i:{}'.format(i))
        time=x[i]-y[i]+rangeQuery(y[i],x[i])
        update(i,time)
    pos=0
    ans=1 # xn + 1
    for i in range(n):
        ans+=x[i]-pos
        ans%=MOD
        pos=x[i]
        if s[i]==1:
            ans+=t[i]
            ans%=MOD
    print(ans)
    
    # print('t:{}'.format(t))
    
    return


import sys
input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
# input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS.

def oneLineArrayPrint(arr):
    print(' '.join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
    print('\n'.join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
    print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))
 
def...