#include using namespace std; using ll = long long; #include using namespace atcoder; template struct CompressedBIT { private: fenwick_tree f; vector p; int id(S x) const { return ranges::lower_bound(p, x) - p.begin(); } public: CompressedBIT() = default; CompressedBIT(int N) { p.reserve(N); } void use(S x) { p.emplace_back(x); } void build() { ranges::sort(p); p.erase(unique(p.begin(), p.end()), p.end()); f = fenwick_tree(p.size()); } void add(S i, T x) { f.add(id(i), x); } T sum(S l, S r) { return f.sum(id(l), id(r)); } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin >> N; CompressedBIT S; vector> Q(N); for(auto &[type, l, r] : Q) { cin >> type >> l >> r; if(!type) { S.use(l); } } S.build(); ll ans = 0; for(auto &[type, l, r] : Q) { if(!type) { S.add(l, r); } else { ans += S.sum(l, ++r); } } cout << ans << "\n"; }