#pragma GCC optimize ("Ofast") #pragma GCC optimize ("O3") #pragma GCC target ("avx") #include #include #include #include using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) inline int gc()noexcept { return getchar_unlocked(); } inline int input()noexcept { int v = 0; char c = gc(); for (; isdigit(c); c = gc()) { v *= 10; v += c - '0'; } return v; } using LL = long long; const int MAX_N = 100005; int m, bit[MAX_N]; inline void add(int i, int x)noexcept { while(i <= m) { bit[i] += x; i += i & -i; } } inline int sum(int i)noexcept { int res = 0; while (i > 0) { res += bit[i]; i -= i & -i; } return res; } bool f[MAX_N]; int a[MAX_N], b[MAX_N], v[MAX_N]; int main() { int n = input(); rep(i, n) { f[i] = gc() == '1'; gc(); a[i] = input(); b[i] = input(); } rep(i, n)if (!f[i]) { v[m++] = a[i]; } sort(v, v + m); m = unique(v, v + m) - v; LL ans = 0; rep(i, n) { if (!f[i]) { int pos = lower_bound(v, v + m, a[i]) - v; add(pos + 1, b[i]); } else { int l = lower_bound(v, v + m, a[i]) - v; int r = upper_bound(v, v + m, b[i]) - v; ans += sum(r) - sum(l); } } printf("%lld\n", ans); }