#include "Memory2_lib.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> dk;
vector<int> ans[55];
void Solve(int T, int N){
	int n=N;
	for(int i=0; i<2*n; i++) dk.push_back(i);
	while(dk.size()>2){
		vector<int> tst;
		for(int i=0; i<3; i++){
			tst.push_back(dk.back());
			dk.pop_back();
		}
		vector<int> res;
		for(int i=0; i<2; i++){
			for(int j=i+1; j<3; j++){
				res.push_back(Flip(tst[i],tst[j]));
			}
		}
		assert((int)res.size()==3);
		if(!(res[0]==res[1]&&res[1]==res[2])){
			if(res[0]==res[1]){
				ans[res[0]].push_back(tst[0]);
				tst[0]=-1;
			}
			else if(res[0]==res[2]){
				ans[res[0]].push_back(tst[1]);
				tst[1]=-1;
			}
			else{
				ans[res[1]].push_back(tst[2]);
				tst[2]=-1;
			}
			for(int i:tst) if(i!=-1) dk.push_back(i);
		}
		else{
			while(true){
				assert(!dk.empty());
				vector<int> boo;
				int hm=dk.back();
				dk.pop_back();
				boo.push_back(Flip(hm,tst[0]));
				boo.push_back(Flip(hm,tst[1]));
				if(boo[0]==boo[1]){
					if(boo[0]!=res[0]){
						ans[boo[0]].push_back(hm);
						continue;
					}
					else{
						ans[res[0]].push_back(tst[0]);
						ans[res[0]].push_back(tst[1]);
						dk.push_back(tst[2]); dk.push_back(hm);
						break;
					}
				}
				else{
					if(boo[0]==res[0]){
						ans[res[0]].push_back(tst[0]);
						ans[res[0]].push_back(tst[2]);
						dk.push_back(tst[1]); dk.push_back(hm);
						break;
					}
					else{
						ans[res[0]].push_back(tst[1]);
						ans[res[0]].push_back(tst[2]);
						dk.push_back(tst[0]); dk.push_back(hm);
						break;
					}
				}
			}
		}
	}
	for(int i:dk) ans[N-1].push_back(i);
	for(int i=0; i<N; i++){
		assert((int)ans[i].size()==2);
		Answer(ans[i][0],ans[i][1],i);
	}
	return;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |