from bisect import bisect_left n=int(input()) l=[] X=[] for i in range(n): a,x,y=map(int,input().split()) l.append((a,x,y)) if a: X.append(x) X.append(y) else: X.append(x) X.sort() No=2**18 tree=[0]*(2*No) def add(k,x): k+=No-1 while k>=0: tree[k]+=x k=(k-1)//2 def qsum(l,r): L=l+No-1 R=r+No-1 s=0 while L<=R: if R&1: s+=tree[R] R=(R-2)//2 else: R=(R-1)//2 if L&1: L=(L-1)//2 else: s+=tree[L] L//=2 return s ans=0 for i in l: a,x,y=i if a: x=bisect_left(X,x) y=bisect_left(X,y) ans+=qsum(x,y) else: x=bisect_left(X,x) add(x,y) print(ans)