#include int main(){ using namespace std; unordered_map segtree; unsigned long max_n{1}; const auto& set = [&segtree, &max_n](unsigned long i, unsigned long a) -> void { (i *= 2) += 1; segtree[i] += a; unsigned long k{1}; while(__builtin_popcount(i) != 1 || i <= max_n){ auto j = (i ^ k) | (k << 1); k <<= 1; if(segtree.count(j)){ segtree[j] += a; }else{ segtree[j] = segtree[i]; if(segtree.count(i ^ k))segtree[j] += segtree[i ^ k]; } i = j; } i >>= 1; while((max_n <<= 1) < i)segtree[max_n] = segtree[max_n >> 1]; segtree[max_n] = segtree[max_n >> 1] + segtree[(max_n >> 1) * 3]; }; const auto& fold = [&segtree, &max_n](unsigned long l, unsigned long r) -> unsigned long { (l *= 2) += 1; (r *= 2) += 1; unsigned long k{2}, ret{0}; while(l != r){ if(l & k){ if(segtree.count(l))ret += segtree[l]; l += k; } if(r & k){ r -= k; if(segtree.count(r))ret += segtree[r]; } l += k >> 1; r += k >> 1; k <<= 1; } return ret; }; unsigned long n; cin >> n; unsigned long ans{0}; for(unsigned long _ = 0, c, x, y; _ < n; ++_){ cin >> c >> x >> y; if(c)ans += fold(x, y + 1); else set(x, y); } cout << ans << endl; return 0; }