#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REPD(i, a, b) for(int i = a; i > b; i--)
#define REPLL(i, a, b) for(ll i = a; i < b; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORD(i, a, b) for(int i = a; i >= b; i--)
#define FORLL(i, a, b) for(ll i = a; i <= b; i++)
#define INF 2000000001
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;
typedef map<int, int>::iterator mit;
typedef vector<int> vi;
typedef vector<pii > vpii;
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define EPS 1e-9
#define PI acos(-1.0)
#define MAXN 200007
int z, n, t, a, b, c;
int ans[MAXN<<4];
int kroot[MAXN];
int root[MAXN];
int lt[MAXN<<4];
int rt[MAXN<<4];
int next_free;
void build(int v, int l, int r) {
if(l==r) return;
lt[v] = next_free++;
rt[v] = next_free++;
int mid = (l+r)/2;
build(lt[v], l, mid);
build(rt[v], mid+1, r);
}
int insert(int v, int x, int l, int r) {
int nv = next_free++;
if(l == r) {
ans[nv] = 1;
return nv;
}
int mid = (l+r)/2;
lt[nv] = lt[v];
rt[nv] = rt[v];
if(x <= mid) lt[nv] = insert(lt[v], x, l, mid);
else rt[nv] = insert(rt[v], x, mid+1, r);
ans[nv] = ans[lt[nv]] + ans[rt[nv]];
return nv;
}
int query(int v, int x, int y, int l, int r) {
if(l>=x && r<=y) {
return ans[v];
}
int mid = (l+r)/2;
int ret = 0;
if(x <= mid) ret += query(lt[v], x, y, l, mid);
if(y>mid) ret += query(rt[v], x, y, mid+1, r);
return ret;
}
vpii v;
int qr;
int main()
{
next_free = 1;
kroot[n] = INF;
root[n] = next_free++;
build(1,1,n);
FOR(i, 1, n) {
v.pb(mp(t, i));
}
sort(ALL(v));
FORD(i, n-1, 0) {
kroot[i] = v[i].st;
root[i] = insert(root[i+1], v[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iNkZWZpbmUgc3QgZmlyc3QKI2RlZmluZSBuZCBzZWNvbmQKCiNkZWZpbmUgRVBTIDFlLTkKI2RlZmluZSBQSSBhY29zKC0xLjApCiNkZWZpbmUgTUFYTiAyMDAwMDcKCmludCB6LCBuLCB0LCBhLCBiLCBjOwppbnQgYW5zW01BWE48PDRdOwppbnQga3Jvb3RbTUFYTl07CmludCByb290W01BWE5dOwppbnQgbHRbTUFYTjw8NF07CmludCBydFtNQVhOPDw0XTsKaW50IG5leHRfZnJlZTsKCnZvaWQgYnVpbGQoaW50IHYsIGludCBsLCBpbnQgcikgewogICAgaWYobD09cikgcmV0dXJuOwogICAgbHRbdl0gPSBuZXh0X2ZyZWUrKzsKICAgIHJ0W3ZdID0gbmV4dF9mcmVlKys7CiAgICBpbnQgbWlkID0gKGwrcikvMjsKICAgIGJ1aWxkKGx0W3ZdLCBsLCBtaWQpOwogICAgYnVpbGQocnRbdl0sIG1pZCsxLCByKTsKfQoKaW50IGluc2VydChpbnQgdiwgaW50IHgsIGludCBsLCBpbnQgcikgewogICAgaW50IG52ID0gbmV4dF9mcmVlKys7CiAgICBpZihsID09IHIpIHsKICAgICAgICBhbnNbbnZdID0gMTsKICAgICAgICByZXR1cm4gbnY7CiAgICB9CiAgICBpbnQgbWlkID0gKGwrcikvMjsKICAgIGx0W252XSA9IGx0W3ZdOwogICAgcnRbbnZdID0gcnRbdl07CiAgICBpZih4IDw9IG1pZCkgbHRbbnZdID0gaW5zZXJ0KGx0W3ZdLCB4LCBsLCBtaWQpOwogICAgZWxzZSBydFtudl0gPSBpbnNlcnQocnRbdl0sIHgsIG1pZCsxLCByKTsKICAgIGFuc1tudl0gPSBhbnNbbHRbbnZdXSArIGFuc1tydFtudl1dOwogICAgcmV0dXJuIG52Owp9CgppbnQgcXVlcnkoaW50IHYsIGludCB4LCBpbnQgeSwgaW50IGwsIGludCByKSB7CiAgICBpZihsPj14ICYmIHI8PXkpIHsKICAgICAgICByZXR1cm4gYW5zW3ZdOwogICAgfQogICAgaW50IG1pZCA9IChsK3IpLzI7CiAgICBpbnQgcmV0ID0gMDsKICAgIGlmKHggPD0gbWlkKSByZXQgKz0gcXVlcnkobHRbdl0sIHgsIHksIGwsIG1pZCk7CiAgICBpZih5Pm1pZCkgcmV0ICs9IHF1ZXJ5KHJ0W3ZdLCB4LCB5LCBtaWQrMSwgcik7CiAgICByZXR1cm4gcmV0Owp9Cgp2cGlpIHY7CmludCBxcjsKCmludCBtYWluKCkKewogICAgc2NhbmYoIiVkIiwgJm4pOwogICAgbmV4dF9mcmVlID0gMTsKICAgIGtyb290W25dID0gSU5GOwogICAgcm9vdFtuXSA9IG5leHRfZnJlZSsrOwogICAgYnVpbGQoMSwxLG4pOwogICAgRk9SKGksIDEsIG4pIHsKICAgICAgICBzY2FuZigiJWQiLCAmdCk7CiAgICAgICAgdi5wYihtcCh0LCBpKSk7CiAgICB9CiAgICBzb3J0KEFMTCh2KSk7CiAgICBGT1JEKGksIG4tMSwgMCkgewogICAgICAgIGtyb290W2ldID0gdltpXS5zdDsKICAgICAgICByb290W2ldID0gaW5zZXJ0KHJvb3RbaSsxXSwgdltpXS5uZCwgMSwgbik7CiAgICB9CiAgICBzY2FuZigiJWQiLCAmcXIpOwogICAgUkVQKGksIDAsIHFyKSB7CiAgICAgICAgc2NhbmYoIiVkJWQlZCIsICZhLCAmYiwgJmMpOwogICAgICAgIGludCBpdCA9IGxvd2VyX2JvdW5kKGtyb290LCBrcm9vdCtuKzEsIGMrMSkta3Jvb3Q7CiAgICAgICAgcHJpbnRmKCIlZFxuIiwgcXVlcnkocm9vdFtpdF0sIGEsIGIsIDEsIG4pKTsKICAgIH0KICAgIHJldHVybiAwOwp9CgoK