class BIT(): def __init__(self, n): self.n = n self.data = [0]*(n+1) self.el = [0]*(n+1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & -i return s def add(self, i, x): # assert i > 0 self.el[i] += x while i <= self.n: self.data[i] += x i += i & -i def get(self, i, j=None): if j is None: return self.el[i] return self.sum(j) - self.sum(i) N = int(input()) lsQ = [] indexls = set() indexls.add(0) for i in range(N): a,x,y = map(int,input().split()) lsQ.append((a,x,y)) if a == 0: indexls.add(x) else: indexls.add(x) indexls.add(y) indexls = sorted(indexls) dic = {x:i+1 for i,x in enumerate(indexls)} ans = 0 BI = BIT(len(indexls)+1) for a,x,y in lsQ: if a == 0: BI.add(dic[x],y) else: ans += BI.get(dic[x]-1, dic[y]) print(ans)