import java.util.*; import java.io.*; public class Main { public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] types = new int[n]; int[] lefts = new int[n]; int[] rights = new int[n]; TreeMap map = new TreeMap<>(); for (int i = 0; i < n; i++) { String[] line = br.readLine().split(" ", 3); types[i] = Integer.parseInt(line[0]); lefts[i] = Integer.parseInt(line[1]); rights[i] = Integer.parseInt(line[2]); if (types[i] == 0) { map.put(lefts[i], 0); } } int idx = 1; for (int x : map.keySet()) { map.put(x, idx); idx++; } BinaryIndexedTree bit = new BinaryIndexedTree(idx); long total = 0; for (int i = 0; i < n; i++) { if (types[i] == 0) { bit.add(map.get(lefts[i]), rights[i]); } else { if (map.firstKey() > rights[i] || map.lastKey() < lefts[i]) { continue; } int min = map.ceilingEntry(lefts[i]).getValue(); int max = map.floorEntry(rights[i]).getValue(); total += bit.getSum(min, max); } } System.out.println(total); } } class BinaryIndexedTree { int size; int[] tree; public BinaryIndexedTree(int size) { this.size = size; tree = new int[size]; } public void add(int idx, int value) { int mask = 1; while (idx < size) { if ((idx & mask) != 0) { tree[idx] += value; idx += mask; } mask <<= 1; } } public int getSum(int from, int to) { return getSum(to) - getSum(from - 1); } public int getSum(int x) { int mask = 1; int ans = 0; while (x > 0) { if ((x & mask) != 0) { ans += tree[x]; x -= mask; } mask <<= 1; } return ans; } }