#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
const long long N = 2e5 + 5;
int ID;
int n;
long long a[N];
bool check_same()
{
for (int i = 2; i <= n; i++)
if (a[i] != a[i - 1])
return false;
return true;
}
bool check_diff()
{
static long long b[N];
memcpy(b, a, sizeof(a));
sort(b + 1, b + n + 1);
for (int i = 2; i <= n; i++)
if (a[i] == a[i - 1])
return false;
return true;
}
void init(int _n, const vector<long long> &_a)
{
n = _n;
for (int i = 1; i <= n; i++) a[i] = _a[i - 1];
if (check_same())
ID = 1;
else if (check_diff())
ID = 2;
else if (n <= 1000)
ID = 3;
else
ID = 4;
}
long long ask(int l, int r) { return 0; }
long long solve1(int l, int r) { return a[l] + (r - l + 1); }
long long solve3(int l, int r)
{
static map<long long, int> cnt;
cnt.clear();
long long power = 1, id = 0;
for (int i = l; i <= r; i++)
{
cnt[a[i]]++;
while (power * 2 < a[i])
{
power *= 2;
id++;
}
}
cnt.insert({ power, 0 });
long long sum = 0, maxd = 0;
for (auto it = ++cnt.find(power); it != cnt.end(); it++)
{
sum += it->second;
maxd = max(maxd, sum - it->first + power);
}
return power + sum + r - l + 1 - maxd;
}
vector<long long> askAll(int q, const vector<int> &l, const vector<int> &r)
{
vector<long long> ans(q);
for (int i = 0; i < q; i++)
{
ans[i] = a[1] + (r[i] - l[i] + 1);
}
return ans;
}