#line 1 "a.cpp" #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define PROBLEM "" #line 2 "/home/kuhaku/kuhaku/github/atcoder-lib/lib/template/template.hpp" #include using namespace std; template bool chmax(T &a, const U &b) { return a < b ? a = b, true : false; } template bool chmin(T &a, const U &b) { return b < a ? a = b, true : false; } constexpr int64_t INF = 1000000000000000003; constexpr int Inf = 1000000003; constexpr int MOD = 1000000007; constexpr int MOD_N = 998244353; constexpr double EPS = 1e-7; const double PI = acos(-1.0); #line 3 "/home/kuhaku/kuhaku/github/atcoder-lib/lib/template/atcoder.hpp" using ll = int64_t; using ld = long double; #define FOR(i, m, n) for(int i = (m); i < (n); ++i) #define FORR(i, m, n) for(int i = (m)-1; i >= (n); --i) #define rep(i, n) FOR(i, 0, n) #define repn(i, n) FOR(i, 1, n+1) #define repr(i, n) FORR(i, n, 0) #define repnr(i, n) FORR(i, n+1, 1) #define all(s) (s).begin(), (s).end() template istream &operator>>(istream &is, vector &v) { for (T &i : v) is>>i; return is; } template ostream &operator<<(ostream &os, const vector &v) { for (auto it=v.begin(); it!=v.end(); ++it) { os<<(it==v.begin()?"":" ")<<*it; } return os; } template void co(Head&& head, Tail&&... tail) { if constexpr(sizeof...(tail)==0) cout<(tail)...); } template void ce(Head&& head, Tail&&... tail) { if constexpr(sizeof...(tail)==0) cerr<(tail)...); } template auto make_vector(T x, int arg, Args ...args) { if constexpr(sizeof...(args)==0) return vector(arg, x); else return vector(arg,make_vector(x, args...)); } void sonic() { ios::sync_with_stdio(false); cin.tie(nullptr); } void setp(const int n) { cout << fixed << setprecision(n); } #line 6 "a.cpp" template struct segment_tree { int N; const T e; const F op; unordered_map data; segment_tree() {} segment_tree(int _n, T _e, F &&_op) : e(_e), op(_op) { init(_n); } segment_tree(int _n, T _e, const F &_op) : e(_e), op(_op) { init(_n); } const T &operator[](int i) const { return data[i + N]; } T at(int k) const { assert(0 <= k && k < N); return data[k + N]; } T get(int k) const { return at(k); } void init(int n) { for (N = 1; N < n; N <<= 1) {} } template void build(const vector &v) { int n = v.size(); for (int i = 0; i < n; ++i) data[N + i] = T(v[i]); for (int i = N - 1; i >= 1; --i) data[i] = op(data[i * 2], data[i * 2 + 1]); } void update(int k, T x) { data[k += N] = x; while ((k >>= 1) >= 1) { if (data.count(k * 2) && data.count(k * 2 + 1)) data[k] = op(data[k * 2], data[k * 2 + 1]); else if (data.count(k * 2)) data[k] = data[k * 2]; else if (data.count(k * 2 + 1)) data[k] = data[k * 2 + 1]; } } T query(int a, int b) { T l = e, r = e; for (a += N, b += N; a < b; a >>= 1, b >>= 1) { if (a & 1) { if (data.count(a)) l = op(l, data[a]); ++a; } if (b & 1) { --b; if (data.count(b)) r = op(data[b], r); } } return op(l, r); } }; int main(void) { sonic(); auto op = [](auto a, auto b) { return a + b; }; segment_tree st(1e9 + 1, 0L, op); int n; cin >> n; ll ans = 0; unordered_map mp; rep(i, n) { int a, b, c; cin >> a >> b >> c; if (!a) { st.update(b, mp[b] + c); mp[b] += c; } else { ans += st.query(b, c + 1); } } co(ans); return 0; }