#include "light.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> cur;
void prepare() {
cur = {1};
}
pair<ll, vector<ll>> join(ll p) {
ll cz = cur.back() + p;
vector<ll> newcur;
newcur.push_back(1);
for (ll i = 1; cz-i+1 > 1; i *= 2) newcur.push_back(cz-i+1);
sort(newcur.begin(), newcur.end());
newcur.resize(unique(newcur.begin(), newcur.end()) - newcur.begin());
vector<ll> actual;
ll t = 5*p;
for (ll i : newcur) {
ll gap = i - *(upper_bound(cur.begin(), cur.end(), i) - 1);
if (gap <= t) actual.push_back(i);
}
cur = actual;
return make_pair(t, cur);
}
pair<ll, vector<ll>> leave(ll p){
ll cz = cur.back() - p;
vector<ll> newcur;
newcur.push_back(1);
for (ll i = 1; cz-i+1 > 1; i *= 2) newcur.push_back(cz-i+1);
sort(newcur.begin(), newcur.end());
newcur.resize(unique(newcur.begin(), newcur.end()) - newcur.begin());
vector<ll> actual;
ll t = 5*p;
for (ll i : newcur) {
ll gap = i - *(upper_bound(cur.begin(), cur.end(), i) - 1);
if (gap <= t) actual.push_back(i);
}
cur = actual;
return make_pair(t, cur);
}