#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    int t, x, y;
};

struct BIT {
    BIT(int n) : b(n + 1), n(n) {}
    void add(int i, int v) {
        for (int k = i + 1; k <= n; k += k & -k) b[k] += v;
    }
    int sum(int k) {
        int s = 0;
        for (; k > 0; k -= k & -k) s += b[k];
        return s;
    }
    vector<int> b;
    int n;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<P> p(n);
    int m = n;
    for (int i = 0; i < n; i++) {
        cin >> p[i].t >> p[i].x >> p[i].y;
        if (p[i].t == 1) p[i].y++, m++;
    }

    vector<pair<int, int>> t(m);
    int j = 0;
    for (int i = 0; i < n; i++) {
        t[j++] = { p[i].x, i * 2 };
        if (p[i].t == 1) t[j++] = { p[i].y, i * 2 + 1 };
    }
    sort(t.begin(), t.end());
    int k = 0;
    for (int i = 0; i < m; i++) {
        if (i > 0 && t[i].first != t[i - 1].first) k++;
        P& q = p[t[i].second / 2];
        if (t[i].second % 2 == 0) q.x = k; else q.y = k;
    }

    k++;
    BIT bt(k);
    ll ans = 0;

    for (int i = 0; i < n; i++) {
        if (p[i].t == 0) {
            bt.add(p[i].x, p[i].y);
        } else {
            ans += bt.sum(p[i].y) - bt.sum(p[i].x);
        }
    }

    cout << ans << endl;

    return 0;
}