QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#24403#3505. FlightsQingyu100 ✓71ms6088kbC++2020.0kb2022-03-30 16:31:452023-01-22 10:16:36

Judging History

你现在查看的是测评时间为 2023-01-22 10:16:36 的历史记录

  • [2023-09-14 02:35:14]
  • 管理员手动重测该提交记录
  • 测评结果:100
  • 用时:46ms
  • 内存:6116kb
  • [2023-09-09 22:36:03]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:38ms
  • 内存:6432kb
  • [2023-09-09 22:32:59]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:50ms
  • 内存:6240kb
  • [2023-09-09 22:31:38]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:47ms
  • 内存:6196kb
  • [2023-09-09 22:26:18]
  • 管理员手动重测本题所有提交记录
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-22 10:16:36]
  • 评测
  • 测评结果:100
  • 用时:71ms
  • 内存:6088kb
  • [2022-03-30 16:31:45]
  • 提交

Ali

#include "Ali.h"
#include <bits/stdc++.h>
using namespace std;

namespace {
	
	// Variables
	const int LIMIT1 = 7;
	const int LIMIT2 = 13;
	int Scenario = 0;
	int N;
	int NumVertices;
	int U[20029], V[20029];
	
	// Tree Division & Distance
	int dp[20029], ord[20029]; string dp2[20029];
	int dist[20029], dia1[20029], dia2[20029];
	vector<int> G[20029];
	
	// Grouping
	int Group[20029], GroupID[20029];
	int GroupTree[20029];
	vector<int> S[20029];
	vector<int> Root;
	vector<int> tmp_DFSord;
	
	// List of Tree
	map<string, int> Map;
	string Tree[400]; int Treecnt = 0;
	vector<int> Treeord[400];
	vector<int> Treeds1[400]; int TreeID1[400];
	vector<int> Treeds2[400][15]; int TreeID2[400][15];
	vector<vector<int>> TreeList1, TreeList2;
	
	// List of Small Trees
	vector<string> TreeList7 = {
		"000011100111", // [0]
		"000011011011", // [1]
		"000001101111", // [2]
		"000110110011", // [3]
		"000011011101"  // [4]
	};
	vector<string> TreeList6 = {
		"0001100111",  // Group 0
		"0001011011",  // Group 1
		"0000111011",  // Group 1
		"0000011111",  // Group 2
		"0000101111",  // Group 2
		"0001101101",  // Group 3
		"0010110011",  // Group 3
		"0001110011",  // Group 3
		"0000110111",  // Group 4
		"0000111101",  // Group 4
		"0001011101"   // Group 4
	};
	
	void AllInit() {
		Root.clear(); NumVertices = 0;
		for (int i = 0; i < 20029; i++) {
			U[i] = 0; V[i] = 0;
			dp[i] = 0; ord[i] = 0; dist[i] = 0; G[i].clear();
			Group[i] = 0; GroupID[i] = 0; GroupTree[i] = 0; S[i].clear();
		}
	}
	
	void MakeGraph(int Vertices, string ss) {
		for (int i = 0; i < Vertices; i++) G[i].clear();
		int num = 1; stack<int> S; S.push(0);
		for (int i = 0; i < (int)ss.size(); i++) {
			if (ss[i] == '0') {
				G[S.top()].push_back(num);
				G[num].push_back(S.top());
				S.push(num); num += 1;
			}
			if (ss[i] == '1') S.pop();
		}
	}
	
	void Get_DP(int pos, int par) {
		dp[pos] = 1;
		dp2[pos] = "";
		for (int to : G[pos]) {
			if (to == par) continue;
			Get_DP(to, pos);
			dp2[pos] += ("0" + dp2[to] + "1");
			dp[pos] += dp[to];
		}
	}
	
	void MakeDist1(int Vertices, int stt) {
		for (int i = 0; i < Vertices; i++) dist[i] = -1;
		queue<int> Q; Q.push(stt); dist[stt] = 0;
		int ordcnt = 0;
		while (!Q.empty()) {
			int pos = Q.front(); Q.pop();
			ord[pos] = ordcnt; ordcnt += 1;
			for (int to : G[pos]) {
				if (dist[to] != -1) continue;
				dist[to] = dist[pos] + 1;
				Q.push(to);
			}
		}
	}
	
	void MakeDist2(int Vertices, int stt) {
		for (int i = 0; i < Vertices; i++) dist[i] = -1;
		queue<int> Q; Q.push(stt); dist[stt] = 0;
		while (!Q.empty()) {
			int pos = Q.front(); Q.pop();
			for (int to : G[pos]) {
				if (dist[to] != -1) continue;
				dist[to] = dist[pos] + 1;
				Q.push(to);
			}
		}
	}
	
	void ListUpTree() {
		int Level[11] = {0, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4};
		for (int i = 0; i < 11; i++) {
			for (int j = Level[i]; j < 5; j++) {
				string ss = "";
				ss += "0"; ss += TreeList7[j]; ss += "1";
				ss += "0"; ss += TreeList6[i]; ss += "1";
				
				// EndPoint
				vector<bool> EndPoint(14, false);
				if (j == 1) { EndPoint[3] = true; }
				if (j == 2) { EndPoint[4] = true; }
				if (j == 3) { EndPoint[2] = true; }
				if (j == 4) { EndPoint[1] = true; EndPoint[3] = true; }
				
				// Make Graph
				MakeGraph(14, ss);
				Map[ss] = Treecnt;
				Tree[Treecnt] = ss;
				
				// Get Distance
				MakeDist1(14, 0);
				Treeds1[Treecnt] = vector<int>(14, 0);
				for (int i = 0; i < 14; i++) Treeds1[Treecnt][ord[i]] = dist[i];
				for (int i = 0; i < 14; i++) {
					if (G[i].size() == 3 && EndPoint[i] == false) {
						Treeds2[Treecnt][ord[i]] = vector<int>(14, -1);
					}
					else {
						MakeDist2(14, i);
						Treeds2[Treecnt][ord[i]] = vector<int>(14, 0);
						for (int j = 0; j < 14; j++) Treeds2[Treecnt][ord[i]][ord[j]] = dist[j];
					}
				}
				
				// Record Tree (ord, Treecnt++)
				Treeord[Treecnt] = vector<int>(14, 0);
				for (int i = 0; i < 14; i++) Treeord[Treecnt][i] = ord[i];
				Treecnt += 1;
			}
		}
	}
	
	void Initialize() {
		for (int i = 0; i < 400; i++) {
			TreeID1[i] = -1;
			for (int j = 0; j < 15; j++) TreeID2[i][j] = -1;
		}
		ListUpTree();
		for (int i = 0; i < Treecnt; i++) {
			int Verts = Tree[i].size() / 2 + 1;
			TreeList1.push_back(Treeds1[i]);
			for (int j = 0; j < Verts; j++) {
				if (Treeds2[i][j][0] != -1) TreeList2.push_back(Treeds2[i][j]);
			}
		}
		sort(TreeList1.begin(), TreeList1.end()); TreeList1.erase(unique(TreeList1.begin(), TreeList1.end()), TreeList1.end());
		sort(TreeList2.begin(), TreeList2.end()); TreeList2.erase(unique(TreeList2.begin(), TreeList2.end()), TreeList2.end());
		for (int i = 0; i < Treecnt; i++) {
			int Verts = Tree[i].size() / 2 + 1;
			TreeID1[i] = lower_bound(TreeList1.begin(), TreeList1.end(), Treeds1[i]) - TreeList1.begin();
			for (int j = 0; j < Verts; j++) {
				if (Treeds2[i][j][0] == -1) TreeID2[i][j] = -1;
				else TreeID2[i][j] = lower_bound(TreeList2.begin(), TreeList2.end(), Treeds2[i][j]) - TreeList2.begin();
			}
		}
		//cout << Treecnt << " " << TreeList1.size() << " " << TreeList2.size() << endl;
	}
	
	// Number -> String
	string NumberToString(long long val, int LEN) {
		string str = "";
		for (int i = 0; i < LEN; i++) {
			if ((val & (1LL << i)) == 0) str += "0";
			if ((val & (1LL << i)) != 0) str += "1";
		}
		return str;
	}
	
	// String -> Number
	int StringToNumber(string str, int LEN) {
		long long val = 0;
		for (int i = 0; i < LEN; i++) {
			if (str[i] == '1') val += (1LL << i);
		}
		return val;
	}
	
	// Get Division in Graph G
	void dfs_Division(int pos) {
		dp[pos] = 1;
		for (int to : G[pos]) {
			if (dp[to] != 0) continue;
			dfs_Division(to);
			if (dp[to] >= LIMIT1) Root.push_back(to);
			else {
				dp[pos] += dp[to];
				S[pos].push_back(to);
				S[to].push_back(pos);
			}
		}
	}
	
	// Get String in Graph S
	pair<int, string> dfs_GetString(int pos, int par) {
		vector<tuple<int, string, int>> tmp;
		for (int to : S[pos]) {
			if (to == par) continue;
			pair<int, string> rem = dfs_GetString(to, pos);
			tmp.push_back(make_tuple(rem.first, rem.second, to));
		}
		sort(tmp.begin(), tmp.end());
		reverse(tmp.begin(), tmp.end());
		string str = ""; int dp_tmp = 1;
		for (int i = 0; i < (int)tmp.size(); i++) {
			str += ("0" + get<1>(tmp[i]) + "1");
			dp_tmp += get<0>(tmp[i]);
		}
		S[pos].clear();
		for (int i = 0; i < (int)tmp.size(); i++) S[pos].push_back(get<2>(tmp[i]));
		if (par != -1) S[pos].push_back(par);
		return make_pair(dp_tmp, str);
	}
	
	// Get DFS Order in Graph S
	void DFSOrder(int pos, int par) {
		tmp_DFSord.push_back(pos);
		for (int to : S[pos]) {
			if (to == par) continue;
			DFSOrder(to, pos);
		}
	}
	vector<int> GetDFSOrder(int pos, int par) {
		tmp_DFSord.clear();
		DFSOrder(pos, par);
		return tmp_DFSord;
	}
	
	// Get BFS order in Graph S
	void GetBFSOrder(int gr, int stt) {
		queue<int> Q; Q.push(stt); dist[stt] = 0;
		int ordcnt = 0;
		while(!Q.empty()) {
			int pos = Q.front(); Q.pop();
			Group[pos] = gr;
			GroupID[pos] = ordcnt; ordcnt += 1;
			for (int to : S[pos]) {
				if (dist[to] != -1) continue;
				dist[to] = dist[pos] + 1;
				Q.push(to);
			}
		}
	}
	
};


void Init(int n, vector<int> u, vector<int> v) {
	AllInit();
	if (Scenario == 0) Initialize();
	Scenario += 1;
	
	// Step #1. Copy (N, U, V)
	N = n;
	for (int i = 0; i < N - 1; i++) U[i] = u[i];
	for (int i = 0; i < N - 1; i++) V[i] = v[i];
	for (int i = 0; i < N; i++) G[i].clear();
	for (int i = 0; i < N - 1; i++) {
		G[U[i]].push_back(V[i]);
		G[V[i]].push_back(U[i]);
	}
	
	// Step #2. Get Diameter [Part 1]
	for (int i = 0; i < N; i++) dist[i] = -1;
	MakeDist2(N, 0);
	pair<int, int> e1 = make_pair(-1, -1);
	for (int i = 0; i < N; i++) e1 = max(e1, make_pair(dist[i], i));
	for (int i = 0; i < N; i++) dia1[i] = dist[i];
	
	// Step #3. Get Diameter [Part 2]
	for (int i = 0; i < N; i++) dist[i] = -1;
	MakeDist2(N, e1.second);
	pair<int, int> e2 = make_pair(-1, -1);
	for (int i = 0; i < N; i++) e2 = max(e2, make_pair(dist[i], i));
	for (int i = 0; i < N; i++) dia2[i] = dist[i];
	
	// Step #4. Get Root
	int MainRoot = 0, maxscore = 1000000;
	for (int i = 0; i < N; i++) {
		if (G[i].size() <= 2 && maxscore > max(dia1[i], dia2[i])) {
			maxscore = max(dia1[i], dia2[i]);
			MainRoot = i;
		}
	}
	
	// Step #5. Division of Tree [Part 1]
	for (int i = 0; i < N; i++) dp[i] = 0;
	for (int i = 0; i < N; i++) dist[i] = -1;
	for (int i = 0; i < N; i++) Group[i] = -1;
	for (int i = 0; i < N; i++) GroupID[i] = -1;
	dfs_Division(MainRoot);
	Root.push_back(MainRoot);
	
	// Step #6. Get "Root of Group"
	MakeDist2(N, MainRoot);
	vector<pair<int, int>> Root_tmp;
	for (int i : Root) Root_tmp.push_back(make_pair(dist[i], i));
	sort(Root_tmp.begin(), Root_tmp.end());
	Root.clear();
	for (int i = 0; i < (int)Root_tmp.size(); i++) Root.push_back(Root_tmp[i].second);
	
	// Step #7. Add Vertices to 13
	NumVertices = N;
	for (int i = 0; i < (int)Root.size(); i++) {
		int root = Root[i];
		for (int nex : S[root]) {
			int cx = nex, pa = root;
			while (true) {
				bool flag = false;
				for (int to : S[cx]) {
					if (pa == to) continue;
					pa = cx; cx = to; flag = true; break;
				}
				if (flag == false) break;
			}
			int cur = cx;
			for (int j = 0; j < 6 - dp[nex]; j++) {
				S[cur].push_back(NumVertices);
				S[NumVertices].push_back(cur);
				cur = NumVertices;
				NumVertices += 1;
			}
		}
		while (S[root].size() < 2) {
			int cur = root;
			for (int j = 0; j < 6; j++) {
				S[cur].push_back(NumVertices);
				S[NumVertices].push_back(cur);
				cur = NumVertices;
				NumVertices += 1;
			}
		}
	}
	
	// Step #8. Add Vertices to 14
	for (int i = 0; i < (int)Root.size(); i++) {
		string str = dfs_GetString(Root[i], -1).second;
		int LeftID = -1, RightID = -1;
		for (int j = 0; j < 11; j++) {
			if (str.substr(1, 10) == TreeList6[j]) LeftID = j;
			if (str.substr(13, 10) == TreeList6[j]) RightID = j;
		}
		if (LeftID < RightID) {
			swap(LeftID, RightID);
			swap(S[Root[i]][0], S[Root[i]][1]);
		}
		vector<int> Dord = GetDFSOrder(S[Root[i]][0], Root[i]);
		if (LeftID == 0) { S[Dord[3]].push_back(NumVertices); S[NumVertices].push_back(Dord[3]); NumVertices += 1; }
		if (LeftID == 1) { S[Dord[3]].push_back(NumVertices); S[NumVertices].push_back(Dord[3]); NumVertices += 1; }
		if (LeftID == 2) { S[Dord[2]].push_back(NumVertices); S[NumVertices].push_back(Dord[2]); NumVertices += 1; }
		if (LeftID == 3) { S[Dord[3]].push_back(NumVertices); S[NumVertices].push_back(Dord[3]); NumVertices += 1; }
		if (LeftID == 4) { S[Dord[4]].push_back(NumVertices); S[NumVertices].push_back(Dord[4]); NumVertices += 1; }
		if (LeftID == 5) { S[Dord[5]].push_back(NumVertices); S[NumVertices].push_back(Dord[5]); NumVertices += 1; }
		if (LeftID == 6) { S[Dord[2]].push_back(NumVertices); S[NumVertices].push_back(Dord[2]); NumVertices += 1; }
		if (LeftID == 7) { S[Dord[1]].push_back(NumVertices); S[NumVertices].push_back(Dord[1]); NumVertices += 1; }
		if (LeftID == 8) { S[Dord[0]].push_back(NumVertices); S[NumVertices].push_back(Dord[0]); NumVertices += 1; }
		if (LeftID == 9) { S[Dord[2]].push_back(NumVertices); S[NumVertices].push_back(Dord[2]); NumVertices += 1; }
		if (LeftID ==10) { S[Dord[3]].push_back(NumVertices); S[NumVertices].push_back(Dord[3]); NumVertices += 1; }
	}
	
	// Step #9. Division of Tree [Part 3]
	for (int i = 0; i < NumVertices; i++) dist[i] = -1;
	for (int i = 0; i < (int)Root.size(); i++) {
		string str = dfs_GetString(Root[i], -1).second;
		GroupTree[i] = Map[str];
		GetBFSOrder(i, Root[i]);
	}
	
	// Step #10. Set Value
	for (int i = 0; i < N; i++) {
		SetID(i, Group[i] * 14 + GroupID[i]);
	}
}

string SendA(string S) {
	// Step #1. Get (GroupX, GroupY)
	int Rank = StringToNumber(S, 20);
	int GroupX = -1, GroupY = -1, Rankcnt = 0;
	for (int i = 0; i < 1430; i++) {
		for (int j = i; j < 1430; j++) {
			if (Rankcnt == Rank) { GroupX = i; GroupY = j; }
			Rankcnt += 1;
		}
	}
	
	// Step #2. Send Tree
	if (GroupX == GroupY) {
		return NumberToString(GroupTree[GroupX], 20);
	}
	
	// Step #3. Send when "GroupX != GroupY"
	if (GroupX != GroupY) {
		MakeDist2(N, Root[GroupY]);
		int dst_path = 1000000, dst_id = -1;
		for (int i = 0; i < N; i++) {
			if (Group[i] != GroupX || dst_path <= dist[i]) continue;
			dst_path = dist[i];
			dst_id = GroupID[i];
		}
		int Ret = 0;
		if (dst_path < 5020) {
			int TreeNumX = GroupTree[GroupX];
			int TreeNumY = GroupTree[GroupY];
			Ret += TreeID2[TreeNumX][dst_id];
			Ret += TreeID1[TreeNumY] * 290;
			Ret += dst_path * 290 * 21;
		}
		else {
			int TreeNumX = GroupTree[GroupX];
			int TreeNumY = GroupTree[GroupY];
			Ret = 5020 * 290 * 21;
			Ret += TreeID1[TreeNumX];
			Ret += TreeID1[TreeNumY] * 21;
			Ret += (dst_path - 5020) * 21 * 21;
		}
		
		// Return
		for (int i = 1; i < 30; i++) {
			if (Ret >= (1 << i)) Ret -= (1 << i);
			else return NumberToString(Ret, i);
		}
	}
}

Benjamin

#include "Benjamin.h"
#include <bits/stdc++.h>
using namespace std;

namespace {
	
	// Variables
	const int LIMIT1 = 7;
	const int LIMIT2 = 13;
	int Scenario = 0;
	int N;
	int X, GroupX, NumX;
	int Y, GroupY, NumY;
	
	// Tree Division & Distance
	int ord[20029], dp[20029]; string dp2[20029];
	int dist[20029];
	vector<int> G[20029];
	
	// List of Tree
	map<string, int> Map;
	string Tree[400]; int Treecnt = 0;
	vector<int> Treeord[400];
	vector<int> Treeds1[400]; int TreeID1[400];
	vector<int> Treeds2[400][15]; int TreeID2[400][15];
	vector<vector<int>> TreeList1, TreeList2;
	
	// List of Small Trees
	vector<string> TreeList7 = {
		"000011100111", // [0]
		"000011011011", // [1]
		"000001101111", // [2]
		"000110110011", // [3]
		"000011011101"  // [4]
	};
	vector<string> TreeList6 = {
		"0001100111",  // Group 0
		"0001011011",  // Group 1
		"0000111011",  // Group 1
		"0000011111",  // Group 2
		"0000101111",  // Group 2
		"0001101101",  // Group 3
		"0010110011",  // Group 3
		"0001110011",  // Group 3
		"0000110111",  // Group 4
		"0000111101",  // Group 4
		"0001011101"   // Group 4
	};
	
	void AllInit() {
		for (int i = 0; i < 20029; i++) {
			ord[i] = 0; dist[i] = 0;
			G[i].clear();
		}
	}
	
	void MakeGraph(int Vertices, string ss) {
		for (int i = 0; i < Vertices; i++) G[i].clear();
		int num = 1; stack<int> S; S.push(0);
		for (int i = 0; i < (int)ss.size(); i++) {
			if (ss[i] == '0') {
				G[S.top()].push_back(num);
				G[num].push_back(S.top());
				S.push(num); num += 1;
			}
			if (ss[i] == '1') S.pop();
		}
	}
	
	void Get_DP(int pos, int par) {
		dp[pos] = 1;
		dp2[pos] = "";
		for (int to : G[pos]) {
			if (to == par) continue;
			Get_DP(to, pos);
			dp2[pos] += ("0" + dp2[to] + "1");
			dp[pos] += dp[to];
		}
	}
	
	void MakeDist1(int Vertices, int stt) {
		for (int i = 0; i < Vertices; i++) dist[i] = -1;
		queue<int> Q; Q.push(stt); dist[stt] = 0;
		int ordcnt = 0;
		while (!Q.empty()) {
			int pos = Q.front(); Q.pop();
			ord[pos] = ordcnt; ordcnt += 1;
			for (int to : G[pos]) {
				if (dist[to] != -1) continue;
				dist[to] = dist[pos] + 1;
				Q.push(to);
			}
		}
	}
	
	void MakeDist2(int Vertices, int stt) {
		for (int i = 0; i < Vertices; i++) dist[i] = -1;
		queue<int> Q; Q.push(stt); dist[stt] = 0;
		while (!Q.empty()) {
			int pos = Q.front(); Q.pop();
			for (int to : G[pos]) {
				if (dist[to] != -1) continue;
				dist[to] = dist[pos] + 1;
				Q.push(to);
			}
		}
	}
	
	void ListUpTree() {
		int Level[11] = {0, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4};
		for (int i = 0; i < 11; i++) {
			for (int j = Level[i]; j < 5; j++) {
				string ss = "";
				ss += "0"; ss += TreeList7[j]; ss += "1";
				ss += "0"; ss += TreeList6[i]; ss += "1";
				
				// EndPoint
				vector<bool> EndPoint(14, false);
				if (j == 1) { EndPoint[3] = true; }
				if (j == 2) { EndPoint[4] = true; }
				if (j == 3) { EndPoint[2] = true; }
				if (j == 4) { EndPoint[1] = true; EndPoint[3] = true; }
				
				// Make Graph
				MakeGraph(14, ss);
				Map[ss] = Treecnt;
				Tree[Treecnt] = ss;
				
				// Get Distance
				MakeDist1(14, 0);
				Treeds1[Treecnt] = vector<int>(14, 0);
				for (int i = 0; i < 14; i++) Treeds1[Treecnt][ord[i]] = dist[i];
				for (int i = 0; i < 14; i++) {
					if (G[i].size() == 3 && EndPoint[i] == false) {
						Treeds2[Treecnt][ord[i]] = vector<int>(14, -1);
					}
					else {
						MakeDist2(14, i);
						Treeds2[Treecnt][ord[i]] = vector<int>(14, 0);
						for (int j = 0; j < 14; j++) Treeds2[Treecnt][ord[i]][ord[j]] = dist[j];
					}
				}
				
				// Record Tree (ord, Treecnt++)
				Treeord[Treecnt] = vector<int>(14, 0);
				for (int i = 0; i < 14; i++) Treeord[Treecnt][i] = ord[i];
				Treecnt += 1;
			}
		}
	}
	
	void Initialize() {
		for (int i = 0; i < 400; i++) {
			TreeID1[i] = -1;
			for (int j = 0; j < 15; j++) TreeID2[i][j] = -1;
		}
		ListUpTree();
		for (int i = 0; i < Treecnt; i++) {
			int Verts = Tree[i].size() / 2 + 1;
			TreeList1.push_back(Treeds1[i]);
			for (int j = 0; j < Verts; j++) {
				if (Treeds2[i][j][0] != -1) TreeList2.push_back(Treeds2[i][j]);
			}
		}
		sort(TreeList1.begin(), TreeList1.end()); TreeList1.erase(unique(TreeList1.begin(), TreeList1.end()), TreeList1.end());
		sort(TreeList2.begin(), TreeList2.end()); TreeList2.erase(unique(TreeList2.begin(), TreeList2.end()), TreeList2.end());
		for (int i = 0; i < Treecnt; i++) {
			int Verts = Tree[i].size() / 2 + 1;
			TreeID1[i] = lower_bound(TreeList1.begin(), TreeList1.end(), Treeds1[i]) - TreeList1.begin();
			for (int j = 0; j < Verts; j++) {
				if (Treeds2[i][j][0] == -1) TreeID2[i][j] = -1;
				else TreeID2[i][j] = lower_bound(TreeList2.begin(), TreeList2.end(), Treeds2[i][j]) - TreeList2.begin();
			}
		}
		//cout << Treecnt << " " << TreeList1.size() << " " << TreeList2.size() << endl;
	}
	
	// Number -> String
	string NumberToString(long long val, int LEN) {
		string str = "";
		for (int i = 0; i < LEN; i++) {
			if ((val & (1LL << i)) == 0) str += "0";
			if ((val & (1LL << i)) != 0) str += "1";
		}
		return str;
	}
	
	// String -> Number
	int StringToNumber(string str, int LEN) {
		long long val = 0;
		for (int i = 0; i < LEN; i++) {
			if (str[i] == '1') val += (1LL << i);
		}
		return val;
	}
	
};

string SendB(int n, int x, int y) {
	AllInit();
	if (Scenario == 0) Initialize();
	Scenario += 1;
	
	N = n; X = x; Y = y;
	if (X > Y) swap(X, Y);
	GroupX = X / 14; NumX = X % 14;
	GroupY = Y / 14; NumY = Y % 14;
	
	// Get Rank
	int Rank = 0, Rankcnt = 0;
	for (int i = 0; i < 1430; i++) {
		for (int j = i; j < 1430; j++) {
			if (i == GroupX && j == GroupY) Rank = Rankcnt;
			Rankcnt += 1;
		}
	}
	
	// Send Email
	return NumberToString(Rank, 20);
}

int Answer(string T) {
	// Step #1. When GroupX == GroupY
	if (GroupX == GroupY) {
		int idx = StringToNumber(T, 20);
		int Verts = Tree[idx].size() / 2 + 1;
		int RepX = -1, RepY = -1;
		for (int i = 0; i < Verts; i++) {
			if (Treeord[idx][i] == NumX) RepX = i;
			if (Treeord[idx][i] == NumY) RepY = i;
		}
		MakeGraph(Verts, Tree[idx]);
		MakeDist2(Verts, RepX);
		return dist[RepY];
	}
	
	// If the group is not same
	if (GroupX != GroupY) {
		int Recieve = StringToNumber(T, (int)T.size());
		for (int i = 1; i < (int)T.size(); i++) Recieve += (1 << i);
		
		if (Recieve >= 5020 * 290 * 21) {
			Recieve -= 5020 * 290 * 21;
			int id_X = Recieve % 21;
			int id_Y = (Recieve / 21) % 21;
			int d3 = (Recieve / (21 * 21)) + 5020;
			int d1 = 0, d2 = 0;
			for (int i = 0; i < Treecnt; i++) {
				if (TreeID1[i] == id_Y) d1 = Treeds1[i][NumY];
				if (TreeID1[i] == id_X) d2 = Treeds1[i][NumX];
			}
			return d1 + d2 + d3;
		}
		else {
			int id_X = Recieve % 290;
			int id_Y = (Recieve / 290) % 21;
			int d3 = (Recieve / (290 * 21));
			int d1 = 0, d2 = 0;
			for (int i = 0; i < Treecnt; i++) {
				if (TreeID1[i] == id_Y) d1 = Treeds1[i][NumY];
				int Verts = Tree[i].size() / 2 + 1;
				for (int j = 0; j < Verts; j++) {
					if (TreeID2[i][j] == id_X) d2 = Treeds2[i][j][NumX];
				}
			}
			return d1 + d2 + d3;
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 15
Accepted

Test #1:

score: 15
Accepted
time: 5ms
memory: 5168kb

input:

1
2 2 0
10110000000000000000

output:

00000000000000000000
1

input:


output:

1
20

result:

points 1.0 L = 20 (test case 1)

Test #2:

score: 15
Accepted
time: 0ms
memory: 6088kb

input:

1
3 1 2
10110000000000000000

output:

00000000000000000000
2

input:


output:

2
20

result:

points 1.0 L = 20 (test case 1)

Test #3:

score: 15
Accepted
time: 1ms
memory: 5156kb

input:

1
4 0 2
10110000000000000000

output:

00000000000000000000
1

input:


output:

1
20

result:

points 1.0 L = 20 (test case 1)

Test #4:

score: 15
Accepted
time: 5ms
memory: 5084kb

input:

1
5 4 1
11110000000000000000

output:

00000000000000000000
1

input:


output:

1
20

result:

points 1.0 L = 20 (test case 1)

Test #5:

score: 15
Accepted
time: 5ms
memory: 5108kb

input:

1
10000 7869 2843
10000011001011100

output:

01000010111110000010
28

input:


output:

28
17

result:

points 1.0 L = 17 (test case 1)

Test #6:

score: 15
Accepted
time: 5ms
memory: 5140kb

input:

1
10000 14028 4278
1110010101111001

output:

11101010101011111010
20

input:


output:

20
16

result:

points 1.0 L = 16 (test case 1)

Test #7:

score: 15
Accepted
time: 2ms
memory: 5108kb

input:

1
10000 14112 5759
00110010010100010

output:

00010000100011011110
29

input:


output:

29
17

result:

points 1.0 L = 17 (test case 1)

Test #8:

score: 15
Accepted
time: 5ms
memory: 5144kb

input:

1
10000 911 12252
01001011100000110

output:

00000100011001101000
31

input:


output:

31
17

result:

points 1.0 L = 17 (test case 1)

Test #9:

score: 15
Accepted
time: 5ms
memory: 5172kb

input:

1
10000 2143 480
10000100010110000110

output:

01001100001111010000
240

input:


output:

240
20

result:

points 1.0 L = 20 (test case 1)

Test #10:

score: 15
Accepted
time: 4ms
memory: 5104kb

input:

1
8191 13750 6108
1001111010000111

output:

00110100110010000001
23

input:


output:

23
16

result:

points 1.0 L = 16 (test case 1)

Test #11:

score: 15
Accepted
time: 2ms
memory: 5156kb

input:

1
9996 10174 2877
110001111010111000

output:

10011110100101000010
54

input:


output:

54
18

result:

points 1.0 L = 18 (test case 1)

Test #12:

score: 15
Accepted
time: 5ms
memory: 5164kb

input:

1
9996 11051 3309
011010000100010001

output:

11111000001111010010
70

input:


output:

70
18

result:

points 1.0 L = 18 (test case 1)

Test #13:

score: 15
Accepted
time: 5ms
memory: 5084kb

input:

1
10000 14736 14708
0111010000100010000

output:

10011111100000010111
96

input:


output:

96
19

result:

points 1.0 L = 19 (test case 1)

Test #14:

score: 15
Accepted
time: 5ms
memory: 5028kb

input:

1
10000 19991 20005
100000101101011111001111

output:

00011101001110011111
9999

input:


output:

9999
24

result:

points 1.0 L = 24 (test case 1)

Test #15:

score: 15
Accepted
time: 5ms
memory: 5112kb

input:

1
9997 2921 5857
11011101010000011100

output:

01011001011011000010
218

input:


output:

218
20

result:

points 1.0 L = 20 (test case 1)

Subtask #2:

score: 85
Accepted

Test #16:

score: 85
Accepted
time: 13ms
memory: 5200kb

input:

15
2 0 2
10110000000000000000
3 1 0
10110000000000000000
4 0 4
10110000000000000000
5 4 0
11110000000000000000
10000 6179 6850
1011101101100001
10000 4463 3742
1011110111100101
10000 511 4510
0010111101111110
10000 2566 11300
0111110100011101
10000 8593 4386
00111001011010110011010
8191 15209 3822
1...

output:

00000000000000000000
1
00000000000000000000
1
00000000000000000000
2
00000000000000000000
2
01011001001001000001
20
01110111000100101010
24
00000011111000110000
20
10111001111111011100
21
01101011011010000110
1866
11011000111001101010
20
00101111111011101001
50
10000101001010100010
62
00000001100110...

input:


output:

1
1
2
2
20
24
20
21
1866
20
50
62
172
9999
659
24

result:

points 1.0 L = 24 (test case 15)

Test #17:

score: 85
Accepted
time: 63ms
memory: 5076kb

input:

50
2 2 0
10110000000000000000
3 0 2
10110000000000000000
4 2 4
10110000000000000000
5 1 2
10110000000000000000
6 0 4
10110000000000000000
7 7 3
01110000000000000000
8 9 6
00011000000000000000
9 21 17
01110000000000000000
10 17 19
01011000000000000000
11 15 17
01110000000000000000
12 0 17
01001000010...

output:

00000000000000000000
1
00000000000000000000
1
00000000000000000000
1
00000000000000000000
2
00000000000000000000
2
00000000000000000000
1
00000000000000000000
1
01101001101000000000
1
01101001101000000000
4
01101001101000000000
1
10000000000000000000
3
01101001101000000000
3
00000000000000000000
3
1...

input:


output:

1
1
1
2
2
1
1
1
4
1
3
3
3
6
8
3
3
7
5
8
4
2
4
5
4
6
1
4
3
3
2
6
2
3
4
8
6
1
9
11
3
1
9
1
4
7
4
1
5
7
20

result:

points 1.0 L = 20 (test case 50)

Test #18:

score: 85
Accepted
time: 70ms
memory: 5964kb

input:

50
10000 10882 9552
10111001010001100
10000 766 508
0001000111111100
10000 3494 12985
1110010111010111
10000 5841 8879
10110111000001010
10000 31 3943
0101001111000110
10000 4163 819
0101000101110101
10000 6506 12953
11100101111101000
10000 9496 7996
11000110101101000
10000 7472 2759
111010011010100...

output:

01111011011010101101
29
00101101011000110000
19
00001111000111110010
26
11111010111000111110
32
01000010001100000000
21
01101110011111001000
23
10101000011111100001
29
01110010010111111001
26
00101010010000000010
21
10100010101011011110
29
11110000100000101011
28
11100111000110001011
29
101001000111...

input:


output:

29
19
26
32
21
23
29
26
21
29
28
29
24
16
25
27
27
22
26
23
29
24
30
28
30
23
21
19
19
35
28
34
23
23
30
23
17
24
34
26
21
32
27
36
22
28
28
28
25
15
17

result:

points 1.0 L = 17 (test case 50)

Test #19:

score: 85
Accepted
time: 65ms
memory: 5156kb

input:

50
10000 11116 42
1100110011110111
10000 11764 1278
1011011000011011
10000 10970 12125
11110110000110100
10000 2871 15520
0010101011101010
10000 6946 16226
10110011111110010
10000 10800 8708
10100001101110000
10000 2737 11414
10011111001110100
10000 1471 13809
11111011111010000
10000 9383 3187
11111...

output:

01101011110010000000
21
00000010111101111000
23
00101100010101100011
29
11101111010101000010
18
11110101101011110001
29
01111001000001010101
25
11010011100111111100
30
11000101000111000100
25
01010001100010010010
27
01101011011010001100
26
10111111111111011010
27
00101110111011110010
25
000000011000...

input:


output:

21
23
29
18
29
25
30
25
27
26
27
25
38
21
24
35
34
37
22
23
30
27
26
25
27
39
29
25
26
33
18
25
20
30
20
32
28
29
20
20
25
15
35
28
25
20
20
15
28
30
17

result:

points 1.0 L = 17 (test case 50)

Test #20:

score: 85
Accepted
time: 66ms
memory: 5156kb

input:

50
10000 6037 11235
100110100000011
10000 7411 3713
0101110000001110
10000 14619 8253
01110101000000100
10000 2327 8541
00010010110110000
10000 16568 16024
11011011010100101
10000 1897 4460
1110010101111001
10000 8246 14199
00010110101101000
10000 6501 14156
0110101000100101
10000 10738 13028
111011...

output:

00100000111111111110
14
01010101000000101010
19
11101110111011000101
29
10000001110101101100
25
11001001001111110111
41
00111110111100110100
23
10011010111011000101
25
11010110011111100001
20
00110001100000100011
28
00100100001001111001
21
01100000011100000000
23
01100011001111101101
27
011111000111...

input:


output:

14
19
29
25
41
23
25
20
28
21
23
27
29
27
25
29
18
27
18
27
19
27
20
25
26
18
21
26
23
24
25
16
28
39
22
25
30
23
4
20
29
24
25
19
22
31
30
26
32
27
17

result:

points 1.0 L = 17 (test case 50)

Test #21:

score: 85
Accepted
time: 63ms
memory: 5076kb

input:

50
10000 13782 6607
101111000100111101001011
10000 13746 12478
00100101011110010010
10000 15134 8484
1110011100101000101101
10000 13512 17021
001101000001110101100
10000 13585 1428
10010110011101000011000
10000 12532 7314
01101110110001011000010
10000 15505 14104
00101000000111100010101
10000 6386 1...

output:

01111001000110010001
5096
10111001001001101011
228
00111011011101100101
1178
01111110011011111011
422
10010000100101000100
1510
00100100010010101001
1743
10101011011111000111
2292
11011001111110100001
1293
00011001000100110010
137
01011001000001101010
244
10000011110010100010
562
1101000011110100000...

input:


output:

5096
228
1178
422
1510
1743
2292
1293
137
244
562
433
800
881
782
360
320
697
116
475
216
107
489
724
424
152
365
192
99
333
304
338
476
382
423
99
104
241
347
276
286
346
508
335
198
276
266
153
124
352
24

result:

points 1.0 L = 24 (test case 50)

Test #22:

score: 85
Accepted
time: 71ms
memory: 5080kb

input:

50
10000 379 14398
0110011010011111110
10000 14628 10908
0100100000101011010
10000 9683 4580
111010100101000100
10000 10811 2599
000111010000001100
10000 15123 15736
001101001000100111
10000 6174 12981
110101001001000000
10000 14440 9254
110001101000111000
10000 4606 8170
00011111001110100
10000 136...

output:

00111010100110010000
132
00100011000001100011
122
10001011110010100110
53
10101100100100111100
57
00011111001101010111
83
00001010011001000001
45
01110101100110001101
50
00000000001110100110
28
01101010100100010010
35
11110010001001010010
38
11110101100010010110
46
10001101111010110000
23
0100000110...

input:


output:

132
122
53
57
83
45
50
28
35
38
46
23
20
36
29
34
39
27
18
30
31
28
34
21
21
26
19
35
31
22
24
33
27
29
27
28
32
37
27
18
25
28
26
23
27
31
31
17
17
27
19

result:

points 1.0 L = 19 (test case 50)

Test #23:

score: 85
Accepted
time: 57ms
memory: 5136kb

input:

50
10000 8583 14550
1110000111110111011100
10000 10281 12338
00101000010101000110100
9996 10858 8750
1100011011110111101
10000 14294 12667
0110110100100001011100
10000 13384 7151
001101101010000111001
9996 8680 6005
010001001110111101
9996 5046 1614
0101010000110011110
10000 5566 3620
00110000011111...

output:

01111000101000010101
853
00101011100101111101
1620
00101000010101010101
154
10010011111111101011
849
11110001111001001001
559
01101001010011111110
80
00111101100101100100
131
01101100000001001010
163
10101111100000010101
101
11010000001100000111
91
10001010001010000110
149
10000110010010111010
227
1...

input:


output:

853
1620
154
849
559
80
131
163
101
91
149
227
253
142
194
215
80
167
89
261
185
192
168
87
182
74
98
79
175
64
75
153
34
134
93
155
34
101
187
91
96
105
166
228
143
151
125
115
183
95
23

result:

points 1.0 L = 23 (test case 50)

Test #24:

score: 85
Accepted
time: 58ms
memory: 5152kb

input:

50
10000 14980 4589
000111110110111110011011
10000 3443 2612
01011100000101100011000
9996 2799 14468
01111011100101101010111
10000 1164 10679
1010101111100101001010
10000 11528 10833
0001110000011001011110
9996 18015 13285
0000100011000000011011
9996 690 13570
101000011111100000111
10000 12088 2300
...

output:

00110010101010100110
6135
01000000001100111100
1520
11100111101100000010
2649
01111111001000111000
920
01101001000010100011
1025
00111010111010111011
1280
01101101000010001000
652
10111001010001101100
397
00100010101011000001
457
00001111000010111101
521
00011001011011100010
379
00101011010110010000...

input:


output:

6135
1520
2649
920
1025
1280
652
397
457
521
379
721
359
543
436
283
248
267
99
312
231
178
186
282
95
303
144
129
335
146
267
216
25
119
184
78
269
128
96
137
164
204
125
78
103
72
140
85
182
159
24

result:

points 1.0 L = 24 (test case 50)

Test #25:

score: 85
Accepted
time: 63ms
memory: 5172kb

input:

50
10000 4524 1207
1100101010001110
10000 16624 9368
1001001011101010
10000 15418 14046
10111010111100110
10000 5713 7966
11010100011010100
10000 6922 15434
10110101110101110
10000 6769 14902
01101000001111010
10000 3626 2666
1010000101010110
10000 4820 15241
1000000011101111
10000 15470 1108
001001...

output:

01010000110010111000
18
01110100010011001101
18
10110100000111000111
34
10111010110001011110
26
10010100011101110001
36
00101001101000110001
35
01101110111110111100
17
00100000011110010110
26
11000010100011011000
38
10101100001110111110
24
01110001000011001000
36
01000010100111000000
31
101111000011...

input:


output:

18
18
34
26
36
35
17
26
38
24
36
31
28
22
30
30
35
15
25
36
30
13
31
26
30
34
26
27
4
34
13
34
17
28
29
33
16
23
23
29
27
15
29
26
27
27
23
25
23
25
17

result:

points 1.0 L = 17 (test case 50)

Test #26:

score: 85
Accepted
time: 58ms
memory: 5668kb

input:

48
3 2 0
10110000000000000000
7 6 5
01011000000000000000
15 28 18
1010001010101
31 56 45
1010001010101
63 20 4
001011011011
127 202 88
100000000010001
255 398 272
101010011100111
511 756 84
11000101001111
1023 495 1826
1011110101001010
2047 3794 2732
1011110101001010
4095 2609 3448
1010011110001101
...

output:

00000000000000000000
1
00000000000000000000
2
11101001101000000000
4
00000011000010000000
4
10000000000000000000
5
10111110100001000000
12
00000001100101100000
14
10100101100001000000
5
01110001100000110000
18
11010101111011111100
15
11000000001100111100
22
10111001001001100100
18
000000000000000000...

input:


output:

1
2
4
4
5
12
14
5
18
15
22
18
2
1
5
3
9
7
13
11
13
17
17
18
2
1
3
3
3
9
14
13
16
19
16
22
1
2
4
2
7
2
5
14
13
15
17
21
20

result:

points 1.0 L = 20 (test case 48)

Test #27:

score: 85
Accepted
time: 61ms
memory: 5080kb

input:

48
60 0 43
11110100011110
60 48 38
001000100101000
60 0 57
01110110100101
56 61 71
100000000010001
56 76 99
111000111011
54 87 15
11011000101001
60 72 18
110111011000001
55 31 73
110100111001110
60 6 23
1010010001000
52 17 37
01001100111110
56 47 6
101111011011
60 60 59
01011000000000000000
48 87 85...

output:

11000000000000000000
5
00110100110100000000
12
00100000000000000000
5
11001010011010000000
11
01100111110110000000
6
11011001101000000000
7
01011001101000000000
11
01110100110100000000
11
10000000000000000000
6
11101001101000000000
9
11000000000000000000
6
01001010011010000000
2
10101110100001000000...

input:


output:

5
12
5
11
6
7
11
11
6
9
6
2
1
6
8
7
33
50
52
53
55
49
48
68
68
61
62
48
53
59
65
55
32
44
53
48
32
53
37
55
66
48
38
63
60
55
51
65
20

result:

points 1.0 L = 20 (test case 48)

Test #28:

score: 85
Accepted
time: 61ms
memory: 5844kb

input:

48
60 14 29
1001101000110
60 0 62
01000101000001
60 59 38
0000011001000
56 89 104
100000000010001
56 106 74
1111101011010000
54 18 76
10101011110011
60 45 60
101101000100100
55 25 79
110100111001110
60 70 35
011001111011011
52 45 21
101111111110
56 46 99
101101100010100
60 117 84
101101100010100
48 ...

output:

11101001101000000000
3
00100000000000000000
8
10110100110100000000
9
01101110100001000000
12
01100111110110000000
16
01011001101000000000
7
00000011000010000000
10
01011001101000000000
14
01110100110100000000
13
00011001101000000000
7
11000011000010000000
9
11101110100001000000
8
1000001100001000000...

input:


output:

3
8
9
12
16
7
10
14
13
7
9
8
9
8
7
10
45
67
62
27
51
57
78
60
62
38
78
50
44
29
52
69
46
64
55
59
33
51
20
66
38
68
75
64
53
47
41
67
18

result:

points 1.0 L = 18 (test case 48)

Test #29:

score: 85
Accepted
time: 59ms
memory: 5152kb

input:

50
4 4 3
11110000000000000000
7 4 8
01110000000000000000
10 15 0
101110011011
13 21 15
01011000000000000000
16 1 0
10110000000000000000
19 22 24
10101000000000000000
22 15 21
01110000000000000000
25 15 2
0100100001000
28 0 30
00010111001001
31 20 51
001001101101
34 49 51
11101000000000000000
37 39 5...

output:

00000000000000000000
2
00000000000000000000
1
10000000000000000000
3
01101001101000000000
2
00000000000000000000
1
01101001101000000000
6
01101001101000000000
2
10000000000000000000
3
01000000000000000000
5
00011001101000000000
8
11111101000010000000
4
00110100110100000000
8
11101001101000000000
7
1...

input:


output:

2
1
3
2
1
6
2
3
5
8
4
8
7
8
8
8
4
7
9
8
8
5
6
9
6
5
4
8
10
9
8
9
7
4
9
4
9
6
10
10
8
9
8
8
11
9
10
10
2
6
20

result:

points 1.0 L = 20 (test case 50)

Test #30:

score: 85
Accepted
time: 60ms
memory: 6084kb

input:

50
10000 17094 16164
100011001011100100010111
10000 16288 16645
101111100011000000010111
10000 19922 18032
100100001110000100001111
10000 19704 17504
001011101000001011110111
10000 16797 19628
000010111111011110110111
10000 19950 17200
011010101001010011110111
10000 18782 19697
111010000000011010001...

output:

01110101111000001111
8311
00101000100010001111
8232
11011001101011101111
9483
00011101101110101111
9299
00111011001011001111
9103
11010110101100101111
9284
10011010101100011111
9619
11100001110011101111
9120
10010011110110101111
8821
00110101000110101111
9239
00010100100110011111
9811
11001111010010...

input:


output:

8311
8232
9483
9299
9103
9284
9619
9120
8821
9239
9811
8984
8961
8830
9081
8820
8968
8551
8900
8774
9137
9142
9647
9346
9173
9302
9065
8626
9195
9105
9668
8908
8705
9318
9776
9097
8813
8679
9520
9501
9288
8882
9696
8858
8436
9466
9525
9681
8480
8759
24

result:

points 1.0 L = 24 (test case 50)

Test #31:

score: 85
Accepted
time: 68ms
memory: 5076kb

input:

50
10000 19991 0
100010111001111111110011
10000 1 20005
001101111001111111110011
10000 16097 2094
101000110110001100100010
10000 16822 490
111011000010001101011110
10000 16284 2850
101100100010001111101100
10000 16930 608
111011000010001101011110
10000 17350 3262
111010100101110101100010
10000 19289...

output:

11001001101000000000
4999
00101001101000000000
4999
00100100100110001100
3501
10111101101000110000
4085
11011001100001000010
3357
10011100100011110000
4080
00000111111101010010
3523
10111010111111010100
4363
00100111001111011000
4557
01100001100011110100
4002
11101101110110100010
4121
01110111001000...

input:


output:

4999
4999
3501
4085
3357
4080
3523
4363
4557
4002
4121
3501
3550
3643
3335
4092
3928
3860
4228
3464
3446
3884
3859
3951
4608
3979
3683
4508
4457
4365
4047
4003
3518
4324
4152
4284
4075
4115
4782
3810
1
1
1
1
1
1
1
1
1
1
24

result:

points 1.0 L = 24 (test case 50)

Test #32:

score: 85
Accepted
time: 56ms
memory: 5104kb

input:

50
10000 16986 18453
111010011001001011111011
10000 16428 15596
001110010011001001011011
10000 17739 17004
100100001000101001111011
10000 16037 15926
110100001000001001011011
10000 16396 15240
011010110000010110011011
10000 18253 15050
010001000100000100111011
10000 17925 15140
110110011010100000111...

output:

10000011000000101111
6924
01001010100110110111
6183
01100110100000101111
6782
01100001001011110111
6181
11001111111011010111
6085
11010011011001010111
6513
10001111011101010111
6451
01011000100001010111
6449
10101110000111010111
6450
11101100010000101111
6737
10101100001110110111
6496
01010100100010...

input:


output:

6924
6183
6782
6181
6085
6513
6451
6449
6450
6737
6496
6143
6361
6883
6082
6441
6689
6117
6391
6514
6582
6624
6694
6392
6158
6004
6553
6535
6319
6516
6426
7243
6280
6633
6312
6145
6509
6538
6158
6203
6296
6342
6558
5934
6883
6810
6685
6897
6074
6560
24

result:

points 1.0 L = 24 (test case 50)

Test #33:

score: 85
Accepted
time: 68ms
memory: 5104kb

input:

50
10000 18353 326
011110001111110001001010
10000 115 18409
001011110101000010110010
10000 16442 1812
100101011101110001010000
10000 17209 1220
011010010101111111011000
10000 17754 2597
010100010001001101110000
10000 14855 1506
10000100111100011100111
10000 16905 2147
110000110111000100010000
10000 ...

output:

00100001001000010000
3647
01110101100011000000
3591
11010110001011010100
2870
11001011110110111000
3058
10100100110100111100
2920
10100010110000100100
2623
00011010101101001100
2855
01001111101111000010
2391
00001001000110000010
2999
00101011010100110000
2950
11100001000101011100
2672
11011001111001...

input:


output:

3647
3591
2870
3058
2920
2623
2855
2391
2999
2950
2672
3250
2963
3299
2605
2214
2897
2434
3007
3558
3023
2879
2645
2723
2530
2771
3270
2732
2628
2978
2594
2722
2419
2690
2899
3079
2291
3542
2412
2930
1
3
1
1
1
5
1
1
1
1
24

result:

points 1.0 L = 24 (test case 50)

Test #34:

score: 85
Accepted
time: 61ms
memory: 5156kb

input:

48
100 175 84
111011010000011
100 59 45
101100010001001
96 99 32
1010110111100100
98 17 102
110000111011000
96 159 44
0010100111011110
99 142 31
0000000000110010
100 112 63
11110100011110
99 86 29
11110100011110
96 33 37
10110000000000000000
91 47 42
10110000000000000000
98 162 83
01100111101011
90 ...

output:

11011110100001000000
15
00000011000010000000
12
00001100110100000000
15
00111001101000000000
10
11100011000010000000
19
11001100110100000000
16
01101010011010000000
8
11110100110100000000
6
11010100110100000000
2
11111101000010000000
3
01010111110110000000
14
00000000000000000000
1
01010000111001000...

input:


output:

15
12
15
10
19
16
8
6
2
3
14
1
12
10
9
7
2930
2639
1158
216
614
1622
951
445
608
326
821
767
422
115
6
103
2473
1369
1460
804
1359
572
469
269
370
240
458
400
40
1019
574
309
24

result:

points 1.0 L = 24 (test case 48)

Test #35:

score: 85
Accepted
time: 64ms
memory: 5152kb

input:

48
10000 3980 15392
010101001001011110000101
10000 4580 15960
11100000010001010011101
10000 13976 15578
000110010011001111111011
10000 6078 19097
11110011011100110101110
10000 3228 10844
10110110111011100000110
10000 17195 15642
001100101010100000000111
10000 14709 6948
11000000000001000010010
10000...

output:

10111001000110011010
4501
01001001101010100110
2379
11101011111101000111
7003
10100111001100000001
2016
10100000000001010010
1904
11101100101110110111
7044
01000010101011110001
1773
01001110000101010011
497
10000110011001010010
4349
00101001000100011011
6724
01111100111111100110
1736
000101011101110...

input:


output:

4501
2379
7003
2016
1904
7044
1773
497
4349
6724
1736
1956
5687
5335
3231
446
904
3051
1019
423
613
2333
42
227
3048
3048
2274
42
26
51
21
2947
141
150
43
158
40
40
154
52
49
44
36
39
58
173
44
164
24

result:

points 1.0 L = 24 (test case 48)

Test #36:

score: 85
Accepted
time: 58ms
memory: 5172kb

input:

50
9828 2120 4104
11101001101011000100
9828 5352 5483
0011100101110
9828 4961 5282
0110101011110
9828 9606 9876
0101000011110
9828 2866 3184
0110101011110
9828 10553 10733
0001000011110
9828 8258 8533
1100101011110
9828 10804 10869
1100100101110
9828 8543 8837
1100101011110
9828 316 585
000111110111...

output:

11010011111110001100
199
01011001100111001110
7
01001110101000110110
10
00111100010001101101
6
10111101010001000010
12
11010010001110000011
7
00100011101011000101
9
00100010110100100011
7
00001111100111100101
9
00001000010111100000
12
10110011100110010101
6
01010010001010101001
6
0011101001101101000...

input:


output:

199
7
10
6
12
7
9
7
9
12
6
6
14
423
7
4
5
6
10
7
5
6
6
15
9
7
514
6
4
10
8
13
6
6
7
10
10
7
12
325
5
8
6
6
4
7
7
7
5
12
21

result:

points 1.0 L = 21 (test case 50)

Test #37:

score: 85
Accepted
time: 66ms
memory: 5144kb

input:

50
9828 1459 1837
0111111011110
9828 8161 8589
0100100111110
9828 3893 5034
11010101110110000101
9828 1468 1586
0001100101110
9828 9164 9486
1000101011110
9828 4386 4598
1010000011110
9828 635 914
1000101011110
9828 136 331
1000000011110
9828 10516 10743
1011001011110
9828 4609 4710
1110100101110
98...

output:

11111000000011000100
6
00101101011110000101
5
01110011010111101010
285
10110000000011000100
9
00001100110000001101
13
10011101101010000110
5
00101001111011110000
10
00001100010011000000
9
10000000111010000011
7
10010000110110100110
5
00000010110011001100
6
10011110100101000011
3
11100100111001000110...

input:


output:

6
5
285
9
13
5
10
9
7
5
6
3
10
12
8
588
3
9
12
13
5
9
10
7
7
10
6
6
260
8
10
9
3
9
10
6
2
2
9
3
10
174
8
8
14
7
12
8
4
5
21

result:

points 1.0 L = 21 (test case 50)

Test #38:

score: 85
Accepted
time: 60ms
memory: 5132kb

input:

50
9828 4735 4960
0111101101110
9828 3265 3557
0011010011110
9828 2252 2413
0011110101110
9828 4703 4948
1011111101110
9828 1504 5037
01101110110001001100
9828 7501 7599
0111100101110
9828 7184 7501
1010110011110
9828 2785 3025
0011100011110
9828 7738 8041
1010011011110
9828 7815 8072
0001100011110
...

output:

11000101100000010110
4
11100000001101010010
4
00111000001100101100
10
11001011001011100110
11
11100001000000100100
213
00100001011111101001
9
00110101000011001001
11
11100111101000000010
10
01011110100111011001
12
11011111101100111001
10
11010010111001001101
14
10010000110110100110
3
000100011111111...

input:


output:

4
4
10
11
213
9
11
10
12
10
14
3
10
12
13
1
13
4
5
4
7
7
8
8
11
11
2
1
15
11
295
4
3
6
10
14
10
10
4
8
9
11
9
205
4
9
6
10
10
7
20

result:

points 1.0 L = 20 (test case 50)

Test #39:

score: 85
Accepted
time: 50ms
memory: 5024kb

input:

50
9828 4915 5017
1100100101110
9828 2208 2328
1100100101110
9828 5258 5538
0100101011110
9828 7549 7860
0110001011110
9828 6286 6600
1100001011110
9828 620 866
0101111101110
9828 8753 10952
100100110010101010011
9828 9980 10094
0011100101110
9828 7491 7591
0011100101110
9828 3199 3576
0110111011110...

output:

00000011000111010110
4
10001100101111001100
6
10000111001110001110
8
10010001001100011001
6
00110010110000100001
8
11100100010011110000
12
11011000010101010101
620
10111110001101011101
4
00100001011111101001
5
10111001001010010010
12
01101111110011110101
12
01011110100101000011
10
111010101110010100...

input:


output:

4
6
8
6
8
12
620
4
5
12
12
10
8
5
10
8
6
7
8
118
3
13
12
9
10
5
7
7
7
8
12
13
61
6
7
8
9
10
9
8
5
5
7
8
8
163
7
8
6
10
21

result:

points 1.0 L = 21 (test case 50)

Test #40:

score: 85
Accepted
time: 57ms
memory: 5216kb

input:

50
9828 7733 8042
1110011011110
9828 6004 6229
0010010011110
9828 4694 4876
0011110101110
9828 5773 6045
0111101101110
9828 4187 4433
0111101101110
9828 2555 2829
0011010011110
9828 5927 6168
1110011101110
9828 10579 10716
0011110101110
9828 6078 3147
1001001110100000000
9828 670 759
1100010101110
9...

output:

01011110100111011001
6
01100111100011111110
10
01110011001011100110
3
10000011010011011110
11
00111100000110111010
8
10000110000111011100
5
01100010011110111110
10
10001001100001000011
9
01000001010000010010
88
00011010010000001000
6
10101010001100011100
6
10010101000000000101
6
01101001011010001010...

input:


output:

6
10
3
11
8
5
10
9
88
6
6
6
11
2
9
7
13
8
6
6
13
286
11
3
10
4
9
9
11
12
13
10
3
6
278
5
4
9
12
14
8
9
2
7
14
13
13
555
9
4
21

result:

points 1.0 L = 21 (test case 50)

Test #41:

score: 85
Accepted
time: 62ms
memory: 5136kb

input:

50
9828 1852 2157
0111101011110
9828 8551 8834
1000011011110
9828 7795 8100
0111101011110
9828 1034 1232
1011100011110
9828 10424 10677
1010110011110
9828 2336 2518
1111010101110
9828 3967 4181
0010011101110
9828 7882 8178
1010110011110
9828 2661 3027
0000111011110
9828 5559 5765
0100001101110
9828 ...

output:

00010101111111010100
8
00001111100111100101
3
00110100111000111001
5
10001001101100011000
4
01101010001000000011
13
01001011100101101100
13
01000000100010011010
11
00111111011110111001
6
11010010111110111100
7
01111001011011101110
7
11000100101101110100
19
00011010010000001000
8
00111110101011010100...

input:


output:

8
3
5
4
13
13
11
6
7
7
19
8
5
12
12
11
3
5
6
4
10
9
6
496
4
8
4
10
11
6
7
8
9
10
15
9
267
13
14
6
9
6
6
4
8
2
7
10
6
414
21

result:

points 1.0 L = 21 (test case 50)

Test #42:

score: 85
Accepted
time: 60ms
memory: 5880kb

input:

50
9828 1517 1643
1001100101110
9828 2553 2767
0001110101110
9828 4148 4413
0100000011110
9828 3876 4151
0111001011110
9828 8662 9043
0000000111110
9828 5297 5551
1110000011110
9828 7550 7649
0110100101110
9828 9624 9789
0001110101110
9828 6866 7111
0110111101110
9828 9448 9816
0000000111110
9828 73...

output:

11111101001000100100
8
00111010000111011100
7
11101111010100111010
4
01110001100011101010
6
01011110110010010101
17
10011100100101001110
11
01011110001100011001
7
10111000101001101101
8
00001100101110110001
13
01101000111111001101
2
10000111111010101001
12
01010000001000000101
7
01011111101010110001...

input:


output:

8
7
4
6
17
11
7
8
13
2
12
7
458
11
10
9
13
6
10
7
9
6
9
8
9
529
7
8
9
6
8
7
7
7
6
12
12
7
124
4
6
7
4
2
7
4
7
6
15
9
21

result:

points 1.0 L = 21 (test case 50)

Test #43:

score: 85
Accepted
time: 62ms
memory: 5080kb

input:

50
9828 5713 5965
0111111101110
9828 496 431
01110110011111010
9828 426 562
1111100101110
9828 6971 7170
0111100011110
9828 5193 5429
1001100011110
9828 6623 6929
0000011011110
9828 9602 9944
0110000111110
9828 1401 1645
0111100011110
9828 4153 4272
0011000101110
9828 3390 3610
0111010101110
9828 10...

output:

01110011010001011110
4
01100111101001010000
37
11010111101001010000
6
10110011011011110001
6
00101100000100001110
8
11110100011110010001
12
10011010111110101101
13
11001010110110000100
9
10110111010100111010
5
01001111101010110010
10
10011110100101000011
8
01001111011110000011
9
10000001010011000101...

input:


output:

4
37
6
6
8
12
13
9
5
10
8
9
9
6
168
11
7
6
4
2
6
9
3
10
9
6
10
232
5
6
4
10
13
14
11
8
8
7
8
10
324
8
7
3
11
8
12
9
6
4
20

result:

points 1.0 L = 20 (test case 50)

Test #44:

score: 85
Accepted
time: 62ms
memory: 5220kb

input:

50
9828 10477 10711
1110001011110
9828 9126 9472
0001111011110
9828 1483 1887
1111000111110
9828 2474 5487
00011100010111001110
9828 10627 10746
1101100101110
9828 4966 5153
0101001101110
9828 4441 4660
0010000011110
9828 225 544
0000101011110
9828 6917 7295
0100000111110
9828 5927 6369
110010011111...

output:

11100000111100000011
3
00101000010111110101
6
11110010101011000100
18
11110011110110011100
260
10101000001101000011
7
10010110101000110110
9
11100100111001000110
12
01111111000110100000
12
00100111110101110001
8
00101010011110111110
16
10100001100101010101
7
00001011100001100001
5
111110010101110000...

input:


output:

3
6
18
260
7
9
12
12
8
16
7
5
7
8
11
9
165
6
9
5
5
6
2
10
9
4
11
6
8
403
5
10
7
13
8
8
6
10
15
8
5
8
366
8
7
10
5
12
10
6
21

result:

points 1.0 L = 21 (test case 50)

Test #45:

score: 85
Accepted
time: 61ms
memory: 5092kb

input:

50
9828 4703 4884
0001010101110
9828 1996 2263
1011101101110
9828 3585 3900
1101010011110
9828 9532 9704
1101110101110
9828 10222 10465
0011111101110
9828 8867 5809
1000000001110110000
9828 2464 2596
0100010101110
9828 8739 8935
1000101101110
9828 2245 2486
1101100011110
9828 10253 10539
11000110111...

output:

01110011001011100110
15
00110100010011110100
10
01101001011010001010
8
10001101000010101101
9
00010110011110111101
9
00111110110111011110
92
10000000110110011100
5
01100110011001010101
7
10000100001100101100
6
01000111110001111101
8
11001001010100010000
6
00100011001100010100
9
10011100000010010101
...

input:


output:

15
10
8
9
9
92
5
7
6
8
6
9
4
9
11
9
12
9
64
8
5
3
9
14
8
11
7
10
9
10
11
379
10
11
7
5
5
7
5
7
14
10
8
9
239
8
7
11
10
16
21

result:

points 1.0 L = 21 (test case 50)

Test #46:

score: 85
Accepted
time: 67ms
memory: 5128kb

input:

50
9828 5776 6148
1000000111110
9828 7807 7905
1010100101110
9828 9997 10204
1110110101110
9828 2416 2682
1010111101110
9828 440 819
1001111011110
9828 2483 2850
1101111011110
9828 10097 10463
1001111011110
9828 1238 5026
0011010010101010110
9828 8952 9092
1010010101110
9828 4578 4747
0100101101110
...

output:

10010011010011011110
3
11100001010100111001
10
10111000010011011101
8
10010110111000011100
12
00101110110101010000
13
00011111111110011100
7
00010101101000111101
7
11010101101110111000
124
11001100101010110101
8
10001110010010100110
4
00110111100111100101
2
11100011000100001010
11
101000101001110101...

input:


output:

3
10
8
12
13
7
7
124
8
4
2
11
3
7
9
8
8
6
13
11
283
8
9
11
11
8
8
10
3
12
14
8
11
404
2
6
6
8
7
9
13
9
4
5
7
6
316
9
6
6
21

result:

points 1.0 L = 21 (test case 50)

Test #47:

score: 85
Accepted
time: 60ms
memory: 5232kb

input:

50
9828 9014 9342
1001000111110
9828 1323 1670
0101000111110
9828 3989 4366
1001000111110
9828 3146 3267
1001000101110
9828 2017 2219
1101010101110
9828 2793 2947
0000101101110
9828 1823 2115
0111010011110
9828 7147 7487
0011011011110
9828 10078 10382
1000110011110
9828 2096 1996
0000101111001111110...

output:

11101001100001110101
3
01011000001111111000
5
10010001101010011010
9
10011101100000010010
9
01101100001111110100
6
00001101010100000010
6
00000001101011010100
4
10010111101001001001
14
11101000000000111101
14
00000100010011110100
136
01010010000000010101
3
01111100000010011101
7
01111001000100000110...

input:


output:

3
5
9
9
6
6
4
14
14
136
3
7
7
4
8
4
12
8
5
16
7
10
55
9
5
8
7
9
11
5
13
14
9
7
9
35
13
3
4
11
11
13
5
6
11
12
10
12
173
7
19

result:

points 1.0 L = 19 (test case 50)

Test #48:

score: 85
Accepted
time: 57ms
memory: 5140kb

input:

50
9828 4280 4460
1100001101110
9828 6971 7179
0010100011110
9828 9291 9595
0011101011110
9828 4916 5144
1110100011110
9828 1695 1885
1101101101110
9828 7062 7263
1100001101110
9828 9561 9820
1001011101110
9828 4272 4529
1111011101110
9828 10511 10716
1001011101110
9828 9675 9867
1100001101110
9828 ...

output:

11010101010011111010
10
10110011011011110001
7
11001010011110001101
11
10010011000111010110
6
11101001111000010100
9
01011100000010001001
10
01001001011010101101
11
00001101010011111010
9
00011010001010000011
10
00101101000011101101
7
00010011001000100100
11
00110010110110001101
15
11010000110110011...

input:


output:

10
7
11
6
9
10
11
9
10
7
11
15
5
3
9
7
10
10
10
4
7
7
5
7
169
5
6
5
10
14
10
7
5
15
3
9
13
566
6
14
7
10
4
9
11
7
8
5
15
9
21

result:

points 1.0 L = 21 (test case 50)

Test #49:

score: 85
Accepted
time: 67ms
memory: 5104kb

input:

50
9828 10588 10382
001110001001111100111
9828 5902 6079
0010110101110
9828 7955 8168
0010110101110
9828 1411 1644
0111000011110
9828 3470 3788
1110101011110
9828 7346 7587
0100100011110
9828 10694 10801
0110101101110
9828 5089 5390
1110101011110
9828 3341 3543
0010110101110
9828 10364 10542
1110001...

output:

11000010001111111101
662
10000110011010111110
8
11011011111101111001
4
11001010110110000100
11
00100100101101110010
5
11101011111010101001
14
11010001011011000011
9
10000100110101110110
8
00011010110000110010
7
11110001100111111101
1
10001001111011101001
13
00101111010101101101
14
111000100010010011...

input:


output:

662
8
4
11
5
14
9
8
7
1
13
14
11
196
11
6
7
10
3
5
7
9
11
10
4
5
344
7
12
7
9
6
13
8
9
9
9
1
9
11
7
9
8
15
5
9
9
7
1
7
21

result:

points 1.0 L = 21 (test case 50)

Test #50:

score: 85
Accepted
time: 62ms
memory: 5084kb

input:

50
9828 4038 4416
0010111011110
9828 3993 4281
1000001011110
9828 8142 4465
011111001111100100100
9828 8173 8500
0010111011110
9828 7790 7968
0001001101110
9828 91 279
1000100011110
9828 4816 5056
1011000011110
9828 7909 8093
1010101101110
9828 6498 6735
1110010011110
9828 4075 4305
1011000011110
98...

output:

11010110111001011010
11
00111111100110011010
8
00011110001101000110
403
10111111100001000101
3
11000100111000111001
6
01000001100001000000
13
10110100110110010110
5
00011010010001111001
9
10011010001111100001
4
11111101001011011010
9
00001011100001100001
6
10101100100111011010
6
01010000101101101001...

input:


output:

11
8
403
3
6
13
5
9
4
9
6
6
12
8
4
221
3
9
10
9
9
8
9
8
13
4
9
7
198
13
9
5
13
7
7
11
10
11
7
8
11
194
7
5
9
8
11
5
7
9
21

result:

points 1.0 L = 21 (test case 50)

Test #51:

score: 85
Accepted
time: 63ms
memory: 5104kb

input:

50
9828 3544 3761
1111000011110
9828 7832 8115
0111110011110
9828 9425 9763
1100111011110
9828 2506 2820
1111110011110
9828 10738 198
00011010110100111111
9828 8600 8842
1011011101110
9828 6626 6782
1101001101110
9828 1458 1698
1111000011110
9828 9037 9323
0001101011110
9828 454 658
0010101101110
98...

output:

11100011000100001010
8
10100110100010111001
12
01111000001111001101
7
10111101100101011100
8
01010011000010100000
343
01101101011000010101
8
10100100011110010001
8
10101000000011000100
5
00011101111001110101
14
11111011000011010000
1
01111000011000100011
13
11011010110110101001
10
011110101111001110...

input:


output:

8
12
7
8
343
8
8
5
14
1
13
10
7
6
6
8
8
123
6
5
5
3
3
5
5
8
8
3
13
5
395
12
5
5
10
11
10
5
8
8
8
9
6
172
7
9
9
8
10
9
21

result:

points 1.0 L = 21 (test case 50)

Test #52:

score: 85
Accepted
time: 58ms
memory: 5108kb

input:

50
9828 10534 10780
0111011011110
9828 439 619
1011010101110
9828 1504 1713
0100011101110
9828 9520 9850
0000110011110
9828 2164 2509
0111011011110
9828 1108 1263
0000001101110
9828 8428 10054
010100110011001110101
9828 9372 9514
0000010101110
9828 4527 4683
1111001101110
9828 3114 3221
000001010111...

output:

01010101100110000011
3
01100110110101010000
7
01011001111111000100
4
11011101000010101101
9
00001010011101001100
4
00110010101101011000
6
11010001000001100101
579
01001100000011001101
9
01010100100000100110
5
10010010000111100010
6
11100110111100111010
9
01000011111011000000
12
10101000101101100101
...

input:


output:

3
7
4
9
4
6
579
9
5
6
9
12
3
7
7
10
3
9
14
279
10
5
9
9
12
1
4
4
11
10
6
5
462
9
10
10
7
10
10
10
8
13
4
7
7
344
8
5
9
4
21

result:

points 1.0 L = 21 (test case 50)

Test #53:

score: 85
Accepted
time: 13ms
memory: 5984kb

input:

8
9828 4587 4878
1001101011110
9828 4898 5047
1110101101110
9828 5271 5447
1100110101110
9828 3394 3606
1100110101110
9828 10305 10490
0011001101110
9828 6566 6847
1011110011110
9828 8925 9242
1101110011110
9828 9945 10129
0110001101110

output:

01011110010010100110
12
11001010000011010110
9
10011111000001001110
3
01001111101010110010
9
10111101011101111101
6
00001100111100010001
6
11110000111100110101
3
01000111011001011101
9

input:


output:

12
9
3
9
6
6
3
9
13

result:

points 1.0 L = 13 (test case 8)

Test #54:

score: 85
Accepted
time: 63ms
memory: 5156kb

input:

50
10000 19986 20003
001001011011111010111011
10000 20005 8397
001001011011111010111011
10000 19968 11612
001001011011111010111011
10000 19984 9673
001001011011111010111011
10000 15462 20000
001001011011111010111011
10000 17819 19998
100110000001010111101011
10000 12746 18633
11011010000001101011101...

output:

00011101001110011111
6663
01011001100110100101
6665
10110110001110110011
6659
00100101000011101101
6663
00110011101100110111
6661
00010010001101101111
5795
10111100101100011011
6646
01110111001001001011
5786
01100111111111111001
6355
10011110001110011111
6106
11000101001100101111
5831
10011011001011...

input:


output:

6663
6665
6659
6663
6661
5795
6646
5786
6355
6106
5831
6753
7414
6634
7070
5875
6062
6746
6382
7441
7068
5700
5793
6383
6595
5762
6919
6687
6492
7106
6962
6282
6787
6284
5916
7248
7048
5893
6113
7323
5992
6503
7237
7392
6388
5715
7597
7187
5710
5730
24

result:

points 1.0 L = 24 (test case 50)

Extra Test:

score: 0
Extra Test Passed