import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); 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++) { types[i] = sc.nextInt(); lefts[i] = sc.nextInt(); rights[i] = sc.nextInt(); 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; } }