#include using namespace std; // SegmentTree on range sum, single value modification. template class SegTreeSum{ size_t n; vector data; public: SegTreeSum(size_t _n): n(_n), data(2 * _n, 0) {} SegTreeSum(const vector &src): n(src.size()), data(2 * n, 0) {init(src);} void init(const vector &src){ for (size_t i = 0; i != n; ++i) data[n + i] = src[i]; for (size_t i = n - 1; i != 0; --i) data[i] = data[i*2] + data[i*2+1]; } void modify(size_t i, T v){ // set value at index i to v. for (data[i += n] = v; i > 1; i >>= 1) data[i>>1] = data[i] + data[i^1]; } void add(size_t i, T v){ modify(i, v + data[i + n]); } T query(size_t L, size_t R){ // sum on interval [L, R) T ret = 0; for (L += n, R += n; L < R; L >>= 1, R >>= 1){ if (L & 1) ret += data[L++]; if (R & 1) ret += data[--R]; } return ret; } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector q(n, 0); vector a(n, 0); vector b(n, 0); for (int i = 0; i < n; ++i) cin >> q[i] >> a[i] >> b[i]; vector xs; for (int i = 0; i < n; ++i) if (q[i] == 0) xs.push_back(a[i]); xs.push_back(-1); xs.push_back(1e9+1); sort(xs.begin(), xs.end()); xs.erase(unique(xs.begin(), xs.end()), xs.end()); int N = xs.size(); if (N == 2){ cout << 0 << endl; return 0; } SegTreeSum seg(N); long long ans = 0; for (int i = 0; i < n; ++i){ if (q[i] == 0){ int x = lower_bound(xs.begin(), xs.end(), a[i]) - xs.begin(); seg.add(x, b[i]); }else{ int L = lower_bound(xs.begin(), xs.end(), a[i]) - xs.begin(); int R = upper_bound(xs.begin(), xs.end(), b[i]) - xs.begin(); ans += seg.query(L, R); } } cout << ans << endl; return 0; }