import java.util.*; public class Main { static int N; static long[] dat; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] q = new int[n]; int[] q2 = new int[n]; long[] q3 = new long[n]; ArrayList list = new ArrayList(); for(int i = 0; i < n; i++) { q[i] = sc.nextInt(); q2[i] = sc.nextInt(); q3[i] = sc.nextLong(); if(q[i] == 0) { if(!list.contains((int)q2[i])) list.add((int)q2[i]); } else { if(!list.contains((int)q2[i])) list.add((int)q2[i]); if(!list.contains((int)q3[i])) list.add((int)q3[i]); } } Collections.sort(list); HashMap map = new HashMap(); for(int i = 0; i < list.size(); i++) { map.put(list.get(i), i); } int len = list.size(); init(len); long ans = 0; for(int i = 0; i < n; i++) { if(q[i] == 0) { update(map.get(q2[i]), q3[i]); } else { ans += query(map.get(q2[i]), map.get((int)q3[i]) + 1, 0, 0, N); } } System.out.println(ans); } public static void init(int n_) { int n = 1; while(n < n_) { n *= 2; } N = n; dat = new long[2 * N - 1]; } public static void update(int k, long x) { int a = k + N - 1; dat[a] += x; while(a > 0) { a = (a - 1) / 2; dat[a] = dat[2 * a + 1] + dat[2 * a + 2]; } } public static long query(int a, int b, int k, int l, int r) { if((r <= a) || (l >= b)) return 0; if((a <= l) && (r <= b)) { return dat[k]; } else { long vl = query(a, b, 2 * k + 1, l, (l + r) / 2); long vr = query(a, b, 2 * k + 2, (l + r) / 2, r); return vl + vr; } } }