#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
/*static inline constexpr int kMaxQueries = 40000;
static int N;
// Insect types are compressed to colors in the range [0, N).
static std::vector<int> color;
static std::vector<bool> in_box;
static std::vector<int> color_occurrences;
static std::multiset<int> max_occurrences;
static std::vector<int> op_counter(3, 0);
static inline void protocol_violation(std::string message) {
printf("Protocol Violation: %s\n", message.c_str());
exit(0);
}
void move_inside(int i) {
if (i < 0 || i >= N) {
protocol_violation("invalid parameter");
}
++op_counter[0];
if (op_counter[0] > kMaxQueries) {
protocol_violation("too many calls");
}
if (!in_box[i]) {
in_box[i] = true;
max_occurrences.erase(max_occurrences.find(color_occurrences[color[i]]));
++color_occurrences[color[i]];
max_occurrences.insert(color_occurrences[color[i]]);
}
}
void move_outside(int i) {
if (i < 0 || i >= N) {
protocol_violation("invalid parameter");
}
++op_counter[1];
if (op_counter[1] > kMaxQueries) {
protocol_violation("too many calls");
}
if (in_box[i]) {
in_box[i] = false;
max_occurrences.erase(max_occurrences.find(color_occurrences[color[i]]));
--color_occurrences[color[i]];
max_occurrences.insert(color_occurrences[color[i]]);
}
}
int press_button() {
++op_counter[2];
if (op_counter[2] > kMaxQueries) {
protocol_violation("too many calls");
}
return *(max_occurrences.rbegin());
}*/
int n,num;
int ch(int x) {
int cnt = n;
vector<int> vv;
vector<bool> mark(n,1);
for(int i= 0 ; i<n; ++i) {
move_inside(i);
if(press_button() > x) move_outside(i),mark[i] = 0,cnt--;
}
for(int i =0 ; i<n; ++i) if(mark[i]) move_outside(i);
return cnt;
} // num feq <= x
int min_cardinality(int N) {
n = num = N;
vector<bool> mark(n,1);
for(int i = 0 ; i<n; ++i) {
move_inside(i);
if(press_button() > 1) move_outside(i),mark[i] = 0,num--;
}
for(int i = 0 ; i<n ;++i) if(mark[i]) move_outside(i);
int r = n/num;
while(r>1) {
int get = ch(r);
if(get == r*num) return r;
else r = get/num;
}
return r;
}