#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; typedef long double ld; const ld INF = (ld)10000000000000; typedef pair P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i=0;i--) #define Rep(i,sta,n) for(int i=sta;i=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef complex Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair LDP; typedef pair LP; struct SegT { private: int sz; vector node; const ll init_c = 0; public: SegT(int n) { sz = 1; while (sz < n)sz *= 2; node.resize(2 * sz - 1, init_c); } ll f(ll a, ll b) { return a + b; } void add(int k, ll a) { k += sz - 1; node[k] += a; while (k > 0) { k = (k - 1) / 2; node[k] = f(node[k * 2 + 1], node[k * 2 + 2]); } } ll query(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0)r = sz; if (r <= a || b <= l)return init_c; else if (a <= l && r <= b)return node[k]; else { ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2); ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return f(vl, vr); } } }; map mp; int n; struct query { int t, l, r; }; int main() { cin >> n; vector q(n); vector v; rep(i, n) { cin >> q[i].t >> q[i].l >> q[i].r; v.push_back(q[i].l); if(q[i].t==1)v.push_back(q[i].r); } sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); rep(i, v.size()) { mp[v[i]] = i; } SegT st(v.size()); ll ans = 0; rep(i, n) { if (q[i].t == 0) { q[i].l = mp[q[i].l]; st.add(q[i].l, q[i].r); } else { q[i].l = mp[q[i].l]; q[i].r = mp[q[i].r]; ans += st.query(q[i].l, q[i].r + 1); } } cout << ans << endl; //stop return 0; }