#include "coreputer.h"
#include "bits/stdc++.h"
using namespace std;
std::vector<int> malfunctioning_cores(int n) {
int l = 0, r = n - 1, pos = -1;
vector<int> res(n, -1), st(n);
while (l <= r) {
int mid = (l + r) >> 1;
vector<int> cand(mid);
iota(cand.begin(), cand.end(), 0);
st[mid] = run_diagnostic(cand);
if (st[mid] >= 0) {
pos = mid;
r = mid - 1;
} else l = mid + 1;
}
res[pos] = 1;
if (pos != n - 1) {
vector<int> cand(pos);
iota(cand.begin(), cand.end(), 0);
for (int i = pos + 1; i < n; ++i) {
cand.push_back(i);
res[i] = run_diagnostic(cand) >= 0;
cand.pop_back();
}
cand.resize(n - pos - 1);
iota(cand.begin(), cand.end(), pos + 1);
for (int i = pos - 1; i >= 0; --i) {
cand.push_back(i);
res[i] = run_diagnostic(cand) > -st[pos];
cand.pop_back();
}
}
return res;
}