#include "minerals.h"
#include <cstdio>
#include <cstdlib>
#include <algorithm>
constexpr int MAX_N = 43000;
constexpr int MAX_CALLS = 1000000;
namespace {
void WrongAnswer(int code) {
printf("Wrong Answer [%d]\n", code);
exit(0);
}
int N;
int counterpart[2 * MAX_N + 1];
int num_queries;
int num_kinds;
int on[2 * MAX_N + 1];
int count[2 * MAX_N + 1];
int num_answers;
int answer[2 * MAX_N + 1];
} // namespace
int Query(int x) {
printf("%d\n",num_queries/N);
//printf("%d\n",x);
if (!(1 <= x && x <= 2 * N)) {
WrongAnswer(1);
}
if (++num_queries > MAX_CALLS && false) {
WrongAnswer(2);
}
const int type = std::min(x, counterpart[x]);
if (on[x]) {
--on[x];
--count[type];
if (count[type] == 0) {
--num_kinds;
}
} else {
++on[x];
++count[type];
if (count[type] == 1) {
++num_kinds;
}
}
return num_kinds;
}
void Answer(int a, int b) {
if (++num_answers > N) {
WrongAnswer(6);
}
if (!(1 <= a && a <= 2 * N && 1 <= b && b <= 2 * N)) {
WrongAnswer(3);
}
if (answer[a] != 0) {
WrongAnswer(4);
}
answer[a] = b;
if (answer[b] != 0) {
WrongAnswer(4);
}
answer[b] = a;
if (!(counterpart[a] == b && counterpart[b] == a)) {
WrongAnswer(5);
}
}
#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
void Solve(int N) {
int v = Query(1);
int v1;
vector<int> ve = {1};
vector<int> co = {};
vector<pair<int,int>> ans = {};
for(int i = 2; i <= 2 * N; i++){
v1 = Query(i);
ve.push_back(i);
if(v1 == v){
ve.pop_back();
co.push_back(i);
}
v = v1;
}
vector<pair<pair<int,int>,vector<int>>> steck = {{{0, N - 1}, co}};
bool can = true;
int m = (N - 1) /2;
int sise;
for(int i = m + 1; i < N; i++){
sise = Query(ve[i]);
}
int num = 0;
while(!steck.empty() && (num < 500||true) ){
num++;
pair<int,int> r = steck.back().first;
vector<int> guys = steck.back().second;
int s = r.first;
int e = r.second;
int m = (s + e)/2;
//printf("%d %d %d\n",s,e,guys.size());
if(guys.size() == e - s + 1){
if(s == e){
ans.push_back({ve[s],guys[0]});
steck.pop_back();
continue;
}
else{
if(!can){
for(int i = s; i <= m; i++){
sise = Query(ve[i]);
}
}
can = false;
vector<int> v1,v2;
for(int i : guys){
int temp = Query(i);
if(temp == sise){
v1.push_back(i);
}
else{
v2.push_back(i);
}
sise = temp;
}
steck.back().second = v1;
steck.push_back({{m+1,e},v2});
}
}
else{
for(int i = (s+m)/2+1; i <= m; i++){
sise = Query(ve[i]);
}
can = true;
steck.pop_back();
steck.push_back({{s,m},guys});
}
}
for(pair<int,int> ii : ans){
Answer(ii.first,ii.second);
}
}
int main() {
if (scanf("%d", &N) != 1) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}
for (int i = 1; i <= N; ++i) {
int x, y;
/* if (scanf("%d%d", &x, &y) != 2) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}*/
x = i;
y = i + N;
counterpart[x] = y;
counterpart[y] = x;
}
Solve(N);
if (num_answers != N) {
WrongAnswer(6);
}
printf("Accepted: %d\n", num_queries);
return 0;
}