#include "advisor.h"
#include<bits/stdc++.h>
using namespace std;
void ComputeAdvice(int *C, int n, int k, int m)
{
vector<int> c;
for(int i = 0; i < k; i++) c.push_back(i);
for(int i = 0; i < n; i++) c.push_back(C[i]);
vector<bool> data(c.size());
//We will send k+n bits
vector<int> ne(c.size());
map<int, int> f;
for(int i = c.size()-1; i >= 0; i--){
int &val = f[c[i]];
if(val == 0) ne[i] = 1e9;
else ne[i] = val;
val = i;
}
vector<int> last(n); fill(last.begin(), last.end(), -1);
set<pair<int, int>> st;
for(int i = 0; i < c.size(); i++){
if(st.count({i, c[i]}) == 1){
if(last[c[i]] >= 0){
data[last[c[i]]] = 1;
}
st.erase({i, c[i]});
}
else if(st.size() == k){
pair<int, int> val = *st.rbegin();
st.erase(val);
}
st.insert({ne[i], c[i]});
last[c[i]] = i;
}
for(int i : data) WriteAdvice(i);
for(int i : data) cerr<<i<<" ";
cerr<<endl;
}
#include<bits/stdc++.h>
#include "assistant.h"
using namespace std;
void Assist(unsigned char *A, int n, int k, int r)
{
set<int> cur; vector<int> will_del;
for(int i = 0; i < k; i++){
cur.insert(i);
if(A[i] == 0) will_del.push_back(i);
}
int sz = k-1;
for(int i = 1; i <= n; i++){
int x = GetRequest();
if(cur.count(x) == 1){
if(A[++sz] == 0) will_del.push_back(x);
}
else{
int y = will_del.back(); will_del.pop_back();
PutBack(y);
if(A[++sz] == 0) will_del.push_back(x);
cur.insert(x); cur.erase(y);
}
}
}