import sys input = sys.stdin.readline class Node: def __init__(self): self.val = 0 self.left = None self.right = None class BinaryTrie: def __init__(self,max_size): self.s = max_size.bit_length() self.root = Node() def __getitem__(self,x): node = self.root tmp = 1<<(self.s-1) for i in range(self.s): if x&tmp: if node.right is None: return 0 node = node.right else: if node.left is None: return 0 node = node.left tmp >>= 1 return node.val def add(self,x,val): node = self.root tmp = 1<<(self.s-1) for i in range(self.s): node.val += val if x&tmp: if node.right is None: node.right = Node() node = node.right else: if node.left is None: node.left = Node() node = node.left tmp >>= 1 node.val += val def fold_(self,r): node = self.root res = 0 tmp = 1<<(self.s-1) for i in range(self.s): if r&tmp: if node.right is None: return res+node.left.val res += node.val-node.right.val node = node.right else: if node.left is None: return res node = node.left tmp >>= 1 return res def fold(self,l,r): return self.fold_(r)-self.fold_(l) def all_prod(self): return self.root.val N = int(input()) trie = BinaryTrie(10**9+1) trie.add(0,0) ans = 0 for q in range(N): op,x,y = map(int,input().split()) if op: ans += trie.fold(x,y+1) else: trie.add(x,y) print(ans)