#include "bits/stdc++.h" #define LF '\n' #define ALL(x) x.begin(), x.end() #define LEN(x) (int)x.size() #define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0) using namespace std; typedef int64_t i64; typedef pair pii; templateinline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;} templateinline bool chmin(A &a, const B &b){return bvoid dump(Itr begin, Itr end) { for(;begin != end; ++begin) clog << ' ' << *begin; clog << LF; } struct FenwickTree { const int N; vector dat; explicit FenwickTree(int n): N(n), dat(N+1, 0) {} i64 sum(int l, int r) { return sum(r) - sum(l-1); } i64 sum(int i) { return (i>0)? (sum(i - (i&-i)) + dat[i]) : 0; } void add(int i, i64 v) { for(; i <= N; i += i&-i) dat[i] += v; } }; using P = tuple; int N; P query[100100]; vector points; inline int index(int orgIndex) { return lower_bound(ALL(points), orgIndex) - points.begin(); } signed main() { iostreamBooster(); cin >> N; for (int i = 0; i < N; ++i) { int a, b, c; cin >> a >> b >> c; query[i] = make_tuple(a, b, c); if (a) { points.push_back(b); } else { points.push_back(b); points.push_back(c); } } points.push_back(0); points.push_back(-1); points.push_back(1'000'000'001); sort(ALL(points)); points.erase(unique(ALL(points)), points.end()); FenwickTree ft(points.size() + 5); i64 ans = 0; for (int i = 0; i < N; ++i) { int com, a, b; tie(com, a, b) = query[i]; if (com == 0) { ft.add(index(a), b); } else { const i64 tmp = ft.sum(index(a), index(b)); ans += tmp; } } cout << ans << endl; return 0; }