#include<bits/stdc++.h>
using namespace std;
struct node{
map<int, int> cnt;
int delta, prom, lv, rv;
node *left, *right;
node() : left(NULL), right(NULL), delta(0), prom(0) {}
void update(node *a, node *b) {
cnt.clear();
delta = 0;
for (pair<int, int> i : a->cnt) {
cnt[i.first + a->delta] = i.second;
}
for (pair<int, int> i : b->cnt) {
cnt[i.first + b->delta] += i.second;
}
}
void push() {
left->delta += prom;
right->delta += prom;
left->prom += prom;
right->prom += prom;
prom = 0;
/// prom - promise
}
int get(int l, int r, int x) {
if (l > rv || lv > r) {
return 0;
}
if (l <= lv && rv <= r) {
return cnt.find(x - delta) != cnt.end() ? cnt[x - delta] : 0;
/// here we can just write return cnt[x-delta], but it will create empty cell
}
push();
return left->get(l, r, x) + right->get(l, r, x);
}
void inc(int l, int r, int toInc) {
if (l > rv || lv > r) {
return;
}
if (l <= lv && rv <= r) {
delta += toInc;
prom += toInc;
return;
}
left->inc(l, r, toInc);
right->inc(l, r, toInc);
update(left, right);
}
};
main() {
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCgpzdHJ1Y3Qgbm9kZXsKICAgIG1hcDxpbnQsIGludD4gY250OwogICAgaW50IGRlbHRhLCBwcm9tLCBsdiwgcnY7CiAgICBub2RlICpsZWZ0LCAqcmlnaHQ7CiAgICBub2RlKCkgOiBsZWZ0KE5VTEwpLCByaWdodChOVUxMKSwgZGVsdGEoMCksIHByb20oMCkge30KCiAgICB2b2lkIHVwZGF0ZShub2RlICphLCBub2RlICpiKSB7CiAgICAgICAgY250LmNsZWFyKCk7CiAgICAgICAgZGVsdGEgPSAwOwoKICAgICAgICBmb3IgKHBhaXI8aW50LCBpbnQ+IGkgOiBhLT5jbnQpIHsKICAgICAgICAgICAgY250W2kuZmlyc3QgKyBhLT5kZWx0YV0gPSBpLnNlY29uZDsKICAgICAgICB9CiAgICAgICAgZm9yIChwYWlyPGludCwgaW50PiBpIDogYi0+Y250KSB7CiAgICAgICAgICAgIGNudFtpLmZpcnN0ICsgYi0+ZGVsdGFdICs9IGkuc2Vjb25kOwogICAgICAgIH0KICAgIH0KCiAgICB2b2lkIHB1c2goKSB7CiAgICAgICAgbGVmdC0+ZGVsdGEgKz0gcHJvbTsKICAgICAgICByaWdodC0+ZGVsdGEgKz0gcHJvbTsKICAgICAgICBsZWZ0LT5wcm9tICs9IHByb207CiAgICAgICAgcmlnaHQtPnByb20gKz0gcHJvbTsKICAgICAgICBwcm9tID0gMDsKICAgICAgICAvLy8gcHJvbSAtIHByb21pc2UKICAgIH0KCiAgICBpbnQgZ2V0KGludCBsLCBpbnQgciwgaW50IHgpIHsKICAgICAgICBpZiAobCA+IHJ2IHx8IGx2ID4gcikgewogICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgaWYgKGwgPD0gbHYgJiYgcnYgPD0gcikgewogICAgICAgICAgICByZXR1cm4gY250LmZpbmQoeCAtIGRlbHRhKSAhPSBjbnQuZW5kKCkgPyBjbnRbeCAtIGRlbHRhXSA6IDA7CiAgICAgICAgICAgIC8vLyBoZXJlIHdlIGNhbiBqdXN0IHdyaXRlIHJldHVybiBjbnRbeC1kZWx0YV0sIGJ1dCBpdCB3aWxsIGNyZWF0ZSBlbXB0eSBjZWxsCiAgICAgICAgfQogICAgICAgIHB1c2goKTsKICAgICAgICByZXR1cm4gbGVmdC0+Z2V0KGwsIHIsIHgpICsgcmlnaHQtPmdldChsLCByLCB4KTsKICAgIH0KCiAgICB2b2lkIGluYyhpbnQgbCwgaW50IHIsIGludCB0b0luYykgewogICAgICAgIGlmIChsID4gcnYgfHwgbHYgPiByKSB7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgaWYgKGwgPD0gbHYgJiYgcnYgPD0gcikgewogICAgICAgICAgICBkZWx0YSArPSB0b0luYzsKICAgICAgICAgICAgcHJvbSArPSB0b0luYzsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICBsZWZ0LT5pbmMobCwgciwgdG9JbmMpOwogICAgICAgIHJpZ2h0LT5pbmMobCwgciwgdG9JbmMpOwogICAgICAgIHVwZGF0ZShsZWZ0LCByaWdodCk7CiAgICB9Cn07CgoKbWFpbigpIHsKICAgIHJldHVybiAwOwp9Cg==