class BinaryIndexedTree(): #1-indexed def __init__(self, n): self.n = n self.tree = [0 for _ in range(n + 1)] def sum(self, idx): res = 0 while idx: res += self.tree[idx] idx -= idx & -idx return res def add(self, idx, x): while idx <= self.n: self.tree[idx] += x idx += idx & -idx def bisect_left(self, x): if x <= 0: return 0 res, tmp = 0, 2**((self.n).bit_length() - 1) while tmp: if res + tmp <= self.n and self.tree[res + tmp] < x: x -= self.tree[res + tmp] res += tmp tmp >>= 1 return res + 1 N = int(input()) Q = [] V = set() for i in range(N): q, x, y = map(int, input().split()) if q == 0: V.add(x) else: V.add(x) V.add(y) Q.append((q, x, y)) comp = {v : k for k, v in enumerate(V, 1)} res = 0 bit = BinaryIndexedTree(N) for q, x, y in Q: if q == 0: bit.add(comp[x], y) else: res += bit.sum(comp[y]) - bit.sum(comp[x] - 1) print(res)