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()) if a == 0: lsQ.append((0,x,y)) indexls.add(x) else: lsQ.append((1,x,y)) indexls.add(x) indexls.add(y) indexls = list(indexls) indexls.sort() dic = dict() for i in range(len(indexls)): dic[indexls[i]] = i+1 ans = 0 BI = BIT(len(indexls)+1) for i in range(N): a,x,y = lsQ[i] if a == 0: BI.add(dic[x],y) else: ans += BI.get(dic[x]-1, dic[y]) print(ans)