#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; struct SegmentTree { private: int n; vector node; public: SegmentTree(vector v){ int sz = (int)v.size(); n = 1; while(n < sz) n *= 2; node.resize(2*n-1,0); for(int i=0;i=0;i--) node[i] = node[2*i+1]+node[2*i+2]; } //x番目の要素にvalを足す。 void add(int x,ll val){ x += n-1; node[x] += val; while(x > 0){ x = (x-1)/2; node[x] = node[2*x+1]+node[2*x+2]; } } //区間[a,b)のwaを求める ll getsum(int a,int b,int k=0,int l=0,int r=-1){ if(r < 0) r = n; if(r <= a || b <= l) return 0; if(a <= l && r <= b) return node[k]; ll vl = getsum(a,b,2*k+1,l,(l+r)/2); ll vr = getsum(a,b,2*k+2,(l+r)/2,r); return vl+vr; } }; struct query{ int id; ll a,b; }; int main(){ int n; cin >> n; vector querys; vector point; rep(i,n){ int c; cin >> c; if(c==0){ ll x,y; cin >> x>> y; querys.push_back(query{c,x,y}); point.push_back(x); }else{ ll l,r; cin >> l >> r; querys.push_back(query{c,l,r}); point.push_back(l); point.push_back(r); } } sort(point.begin(),point.end()); map trans; int j = 0; rep(i,point.size()){ if(i>0){ if(point[i-1] == point[i]) continue; } trans[point[i]] = j++; } SegmentTree seg(vector(point.size(),0)); ll ans = 0; rep(i,n){ if(querys[i].id==0){ seg.add(trans[querys[i].a],querys[i].b); }else{ ans += seg.getsum(trans[querys[i].a],trans[querys[i].b]+1); } } cout << ans << endl; return 0; }