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(); long[][] q = new long[n][3]; HashSet set = new HashSet(); ArrayList list = new ArrayList(); for(int i = 0; i < n; i++) { q[i][0] = sc.nextLong(); q[i][1] = sc.nextLong(); q[i][2] = sc.nextLong(); if(q[i][0] == 0) { set.add((int)q[i][1]); } else { set.add((int)q[i][1]); set.add((int)q[i][2]); } } for(Iterator it = set.iterator(); it.hasNext();) { int t = it.next(); list.add(t); } Collections.sort(list); HashMap map = new HashMap(); int p = 0; for(int i = 0; i < list.size(); i++) { map.put(list.get(i), p); p++; } int len = list.size(); init(len); long ans = 0; for(int i = 0; i < n; i++) { if(q[i][0] == 0) { update((int)q[i][1], q[i][2]); } else { ans += query(map.get((int)q[i][1]), map.get((int)q[i][2]) + 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; } } }