#include using ll = long long; using ld = long double; template constexpr T MOD() { return 1000000007; } template constexpr T INF() { return std::numeric_limits::max() / 16; } class Fenwick { static std::size_t SZ(const std::size_t n) { std::size_t ans = 1; for (; ans < n; ans <<= 1) {} return ans; } public: using T = ll; Fenwick(const std::size_t n) : size(n), cap(SZ(n)), value(cap + 1, 0) {} template Fenwick(const InIt first, const InIt last) : size(std::distance(first, last)), cap(SZ(size)), value(cap + 1, 0) { std::copy(first, last, value.begin() + 1); for (std::size_t x = 1; x < cap; x++) { value[x + (x & -x)] += value[x]; } } void add(const std::size_t a, const T& val) { for (std::size_t ind = a + 1; ind <= cap; ind += ind & (-ind)) { value[ind] += val; } } T accumulate(const std::size_t a) const { T sum = 0; for (std::size_t ind = a + 1; ind != 0; ind &= ind - 1) { sum += value[ind]; } return sum; } T accumulate(const std::size_t l, const std::size_t r) const { return accumulate(r - 1) - (l == 0 ? 0 : accumulate(l - 1)); } std::size_t partitionPoint(const T val) const { if (val < 0) { return 0; } std::size_t x = 0; T offset = 0; for (std::size_t k = ((cap == size) ? cap : cap / 2); k != 0; k >>= 1) { if (x + k <= cap and value[x + k] + offset <= val) { offset += value[x + k], x += k; } } return std::min(x, size); } std::vector data() const { std::vector ans(size); for (std::size_t i = 0; i < size; i++) { ans[i] = accumulate(i, i + 1); } return ans; } private: const std::size_t size, cap; std::vector value; }; std::ostream& operator<<(std::ostream& os, const Fenwick& bit) { const auto v = bit.data(); os << "["; for (const auto e : v) { os << e << ","; } return (os << "]\n"); } int main() { int N; std::cin >> N; using P = std::pair; using PP = std::pair; std::vector Q(N); std::set st; for (int i = 0; i < N; i++) { int t; std::cin >> t; if (t == 0) { int x, y; std::cin >> x >> y, x--; Q[i] = {t, {x, y}}; st.insert(x); } else { int l, r; std::cin >> l >> r, l--; Q[i] = {t, {l, r}}; st.insert(l), st.insert(r - 1), st.insert(r); } } std::map mp; int ind = 0; for (const int p : st) { mp[p] = ind, ind++; } const int L = st.size(); Fenwick bit(L); ll ans = 0; for (int i = 0; i < N; i++) { const int t = Q[i].first; if (t == 0) { const int x = mp[Q[i].second.first], y = Q[i].second.second; bit.add(x, y); } else { const int l = mp[Q[i].second.first], r = mp[Q[i].second.second]; ans += bit.accumulate(l, r); } } std::cout << ans << std::endl; return 0; }