#include <stdlib.h>
#include <string.h>
#include "floppy.h"
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;
const ll INF = 100005, LONGBOI = 100000000005, BITSMAX = 16;
string ToStr(ll x){
string ans="";
for(int i=BITSMAX-1; i >= 0; i--){
ans += '0' + ((x>>i)&1);
}
return ans;
}
ll FromStr(string s){
ll x = 0;
for(int i=0; i < BITSMAX; i++){
x <<= 1;
x += s[i]-'0';
}
return x;
}
void read_array(int subtask_id, const vector<int> &v) {
vl vec;
map<ll, ll> newNums;
ll n = v.size();
for(auto x : v) { vec.push_back(x); }
sort(vec.begin(), vec.end());
for(auto x : vec){
if(newNums.count(x) == false){
newNums[x] = newNums.size();
}
}
string bits = "";
for(auto x : v) { bits += ToStr(newNums[x]); /*cout << bits << endl;*/ }
//cout << bits << endl;
save_to_floppy(bits);
}
vector<int> solve_queries(int subtask_id, int N, const string &bits, const vector<int> &a, const vector<int> &b) {
vl h;
ll n = bits.length();
//cout << n << endl;
for(int i=0; i < n; i+=BITSMAX) { h.push_back(FromStr(bits.substr(i, BITSMAX))); }
//for(int i=0; i <= maxpos; i++) { cout << "i = " << i << " t[i] = " << t[i].first << " second = " << t[i].second << endl; }
vl ans;
ll m = a.size();
for(int i=0; i < m; i++){
ans.push_back(max_element(h.begin()+a[i], h.begin()+b[i]+1) - h.begin());
//cout << GetMax(0, 1, N, a[i]+1, b[i]+1, t) << endl;
//ans.push_back(GetMax(0, 1, N, a[i]+1, b[i]+1, t).second);
}
//for(auto x : ans) cout << x << " ";
//cout << endl;
//vl ans = {0, 0, 0, 0, 1, 2, 2, 2, 2, 3};
return ans;
}