from bisect import bisect_right from heapq import * import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def main(): def connect(j,l,r,sl=0,sr=-1,si=0): if sr==-1:sr=w if r<=sl or sr<=l:return if l<=sl and sr<=r: to[j+w-1].append(si) return sm=(sl+sr)//2 connect(j,l,r,sl,sm,si*2+1) connect(j,l,r,sm,sr,si*2+2) def dfs(u,start=-1): if start==-1:start=u for v in to[u]: if vis[v]==start: dp[u]=inf break if vis[v]==-1: vis[v]=start dfs(v,start) if dp[v]==inf: dp[u]=inf break dp[u]=max(dp[u],dp[v]) if u>=w-1: _,b,_,i=abci[u-w+1] if dp[u]!=inf:dp[u]+=b ans[i]=dp[u] inf=10**15 n=II() abci=[] w=1<<(n-1).bit_length() to=[[] for _ in range(w-1+n)] for i in range(w-2+n,0,-1):to[(i-1)//2].append(i) for i in range(n): a,b,c=MI() abci.append((a,b,c,i)) # aの小さい順に見ていってセグメント木に辺を張る abci.sort() aa=[] hp=[] for j,(a,b,c,i) in enumerate(abci): while hp and hp[0][0]