We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array:  The array consists of $$$n$$$ distinct positive (greater than $$$0$$$) integers.  The array contains two elements $$$x$$$ and $$$y$$$ (these elements are known for you) such that $$$x < y$$$.  If you sort the array in increasing order (such that $$$a_1 < a_2 < \ldots < a_n$$$), differences between all adjacent (consecutive) elements are equal (i.e. $$$a_2 - a_1 = a_3 - a_2 = \ldots = a_n - a_{n-1})$$$. It can be proven that such an array always exists under the constraints given below.Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize $$$\max(a_1, a_2, \dots, a_n)$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$2 \le n \le 50$$$; $$$1 \le x < y \le 50$$$) — the length of the array and two elements that are present in the array, respectively.

For each test case, print the answer: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter). It can be proven that such an array always exists under the given constraints.

// Cheese-Cracker: cheese-cracker.github.io
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.range;

alias ll = long;

void play(){
    ll n, x, y;
    readf(" %s %s %s ", &n, &x, &y);
    ll diff = y - x;
    ll minmax = long.max / 10;
    ll mind = -1, mina = -1;
    foreach(ll d; 1 .. diff+1){
        if(diff % d == 0){
            ll minn = y - (n - 1) * d;
            while(minn <= 0){
                minn += d;
            }
            if(minn > x) continue;
            ll curmax = minn + (n - 1) * d;
            if(curmax < minmax){
                minmax = curmax;
                mind = d;
                mina = minn;
            }
        }
    }
    foreach(ll i; 0 .. n){
        writef("%s ", mina + i * mind);
    }
    writeln;
}

int main(){
    ll t = 1;
    readf(" %s ", &t);        // Toggle!
    while(t--) play();  // Let's play!
    return 0;
}

import std.stdio;
import std.range;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);
  auto nt = next!int;
  foreach(t; 0 .. nt)
    {
      auto n = next!int;
      auto x = next!int;
      auto y = next!int;
      auto diff = y - x;
      int bestjump = -1;
      int bestjumpmax = int.max;
      foreach(jump; 1 .. diff + 1)
        {
          if (diff % jump == 0)
            {
              if (diff / jump + 1 > n)
                continue;
              int rem = n - (diff / jump + 1);
              int lessthan = cast(int) iota(1, x).count!(num => num % jump == x % jump);
              rem -= min(rem, lessthan);
              int jumpmax = y + rem * jump;
              if (jumpmax < bestjumpmax)
                {
                  bestjump = jump;
                  bestjumpmax = jumpmax;
                }
            }
        }
      foreach(i; 0 .. n)
        {
          write(bestjumpmax - bestjump * i, " ");
        }
      writeln;
    }
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new long[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD;
		auto x = RD;
		auto y = RD;

		auto d = y-x;
		foreach_reverse (i; 1..n)
		{
			if (d % i) continue;
			auto cnt = d / i;
			auto begin = x;
			while (begin <= y)
			{
				ans[ti] ~= begin;
				begin += cnt;
			}

			begin = x - cnt;
			while (begin >= 1 && ans[ti].length < n)
			{
				ans[ti] ~= begin;
				begin -= cnt;
			}
			begin = y + cnt;
			while (ans[ti].length < n)
			{
				ans[ti] ~= begin;
				begin += cnt;
			}

			break;
		}
	}

	foreach (e; ans)
		e.map!(to!string).join(" ").writeln;
	stdout.flush;
	debug readln;
}


Young wilderness explorers set off to their first expedition led by senior explorer Russell. Explorers went into a forest, set up a camp and decided to split into groups to explore as much interesting locations as possible. Russell was trying to form groups, but ran into some difficulties...Most of the young explorers are inexperienced, and sending them alone would be a mistake. Even Russell himself became senior explorer not long ago. Each of young explorers has a positive integer parameter $$$e_i$$$ — his inexperience. Russell decided that an explorer with inexperience $$$e$$$ can only join the group of $$$e$$$ or more people.Now Russell needs to figure out how many groups he can organize. It's not necessary to include every explorer in one of the groups: some can stay in the camp. Russell is worried about this expedition, so he asked you to help him.

The first line contains the number of independent test cases $$$T$$$($$$1 \leq T \leq 2 \cdot 10^5$$$). Next $$$2T$$$ lines contain description of test cases. The first line of description of each test case contains the number of young explorers $$$N$$$ ($$$1 \leq N \leq 2 \cdot 10^5$$$). The second line contains $$$N$$$ integers $$$e_1, e_2, \ldots, e_N$$$ ($$$1 \leq e_i \leq N$$$), where $$$e_i$$$ is the inexperience of the $$$i$$$-th explorer. It's guaranteed that sum of all $$$N$$$ doesn't exceed $$$3 \cdot 10^5$$$.

Print $$$T$$$ numbers, each number on a separate line. In $$$i$$$-th line print the maximum number of groups Russell can form in $$$i$$$-th test case.

NoteIn the first example we can organize three groups. There will be only one explorer in each group. It's correct because inexperience of each explorer equals to $$$1$$$, so it's not less than the size of his group.In the second example we can organize two groups. Explorers with inexperience $$$1$$$, $$$2$$$ and $$$3$$$ will form the first group, and the other two explorers with inexperience equal to $$$2$$$ will form the second group.This solution is not unique. For example, we can form the first group using the three explorers with inexperience equal to $$$2$$$, and the second group using only one explorer with inexperience equal to $$$1$$$. In this case the young explorer with inexperience equal to $$$3$$$ will not be included in any group.

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto e = RDA!int;
		e.sort();

		int cnt;
		while (!e.empty)
		{
			auto x = e.front; e.popFront;
			++cnt;
			if (x <= cnt)
			{
				++ans[ti];
				cnt = 0;
			}
		}
	}

	foreach (e; ans)
	{
		writeln(e);
	}

	stdout.flush;
	debug readln;
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto e = RDA!int;
		e.sort!"a > b"();

		while (!e.empty)
		{
			auto x = e.front;
			if (e.length >= x)
			{
				++ans[ti];
			}
			e = e[min(x, e.length)..$];
		}
	}

	foreach (e; ans)
	{
		writeln(e);
	}

	stdout.flush;
	debug readln;
}


Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is given in two lines. The first line contains two integers $$$a_1$$$ and $$$b_1$$$ ($$$1 \le a_1, b_1 \le 100$$$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length). The second line contains two integers $$$a_2$$$ and $$$b_2$$$ ($$$1 \le a_2, b_2 \le 100$$$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).

Print $$$t$$$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto p = readln.splitter.map !(to !(int)).array;
		sort (p);
		auto q = readln.splitter.map !(to !(int)).array;
		sort (q);
		bool ok = false;
		do
		{
			do
			{
				if (p[0] + q[0] == p[1] &&
				    p[0] + q[0] == q[1])
				{
					ok = true;
				}
			}
			while (nextPermutation (q));
		}
		while (nextPermutation (p));
		writeln (ok ? "Yes" : "No");
	}
}


You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.You are a coach at a very large university and you know that $$$c$$$ of your students are coders, $$$m$$$ are mathematicians and $$$x$$$ have no specialization.What is the maximum number of full perfect teams you can distribute them into? Note that some students can be left without a team and each student can be a part of no more than one team.You are also asked to answer $$$q$$$ independent queries.

The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries.  Each of the next $$$q$$$ lines contains three integers $$$c$$$, $$$m$$$ and $$$x$$$ ($$$0 \le c, m, x \le 10^8$$$) — the number of coders, mathematicians and students without any specialization in the university, respectively. Note that the no student is both coder and mathematician at the same time.

Print $$$q$$$ integers — the $$$i$$$-th of them should be the answer to the $$$i$$$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.

NoteIn the first example here are how teams are formed:  the only team of 1 coder, 1 mathematician and 1 without specialization;  all three teams consist of 1 coder and 2 mathematicians;  no teams can be formed;  no teams can be formed;  one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team;  one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int q = rint;
	foreach(_; 0 .. q){
		long c = rlong, m = rlong, x = rlong;
		long total = c + m + x;
		long ans = min(c, m, total / 3);
		ans.writeln;
	}
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto q = RD!int;
	auto ans = new long[](q);
	foreach (i; 0..q)
	{
		auto c = RD;
		auto m = RD;
		auto x = RD;
		auto a = c + m + x;
		ans[i] = min(min(c, m), a/3);
	}

	foreach (e; ans)
	{
		writeln(e);
	}
	stdout.flush();
	debug readln();
}


Recall that a permutation of length $$$n$$$ is an array where each element from $$$1$$$ to $$$n$$$ occurs exactly once.For a fixed positive integer $$$d$$$, let's define the cost of the permutation $$$p$$$ of length $$$n$$$ as the number of indices $$$i$$$ $$$(1 \le i < n)$$$ such that $$$p_i \cdot d = p_{i + 1}$$$.For example, if $$$d = 3$$$ and $$$p = [5, 2, 6, 7, 1, 3, 4]$$$, then the cost of such a permutation is $$$2$$$, because $$$p_2 \cdot 3 = p_3$$$ and $$$p_5 \cdot 3 = p_6$$$.Your task is the following one: for a given value $$$n$$$, find the permutation of length $$$n$$$ and the value $$$d$$$ with maximum possible cost (over all ways to choose the permutation and $$$d$$$). If there are multiple answers, then print any of them.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$). The sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print the value $$$d$$$ in the first line, and $$$n$$$ integers in the second line — the permutation itself. If there are multiple answers, then print any of them.

import std;

void main()
{
    int t;
    scanf("%d", &t);
    foreach(_; 0..t)
    {
        int n;
        scanf("%d", &n);
        int[] arr = [1];
        bool[int] set;
        set[1] = true;
        for (int i = 2; i <= n; i++) {
            for (int j = 0; i * 2 ^^ j <= n; j++)
                if ((i * 2 ^^ j in set) == null) {
                    arr ~= i * 2 ^^ j;
                    set[i * 2 ^^ j] = true;
                }
        }
        writeln(2);
        writefln("%(%s %)", arr);
    }
}

// cheese-cracker [2022-07-08]

void solve(){
    int n = scan!int;
    auto seen = new bool[](n+1);
    int d = 2;
    writeln(d);
    for(int i = 1; i <= n; ++i){
        if(!seen[i]){
            int num = i;
            while(num <= n){
                seen[num] = 1;
                write(num, " ");
                num *= 2;
            }
        }
    }
    writeln;
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/*_________________________*That's All Folks!*__________________________*/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm;
import std.container, std.math, std.numeric, std.functional;
string[] tk; alias tup = Tuple!(long, long);
T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }


Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this orb being of any kind is equal. As the north of wall is full of dangers, he wants to know the minimum number of days he should wait before sending a ranger to collect the orbs such that the probability of him getting at least one of each kind of orb is at least , where ε < 10 - 7.To better prepare himself, he wants to know the answer for q different values of pi. Since he is busy designing the battle strategy with Sam, he asks you for your help.

First line consists of two space separated integers k, q (1 ≤ k, q ≤ 1000) — number of different kinds of orbs and number of queries respectively. Each of the next q lines contain a single integer pi (1 ≤ pi ≤ 1000) — i-th query.

Output q lines. On i-th of them output single integer — answer for i-th query.

import core.bitop;
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int limit = 2000;
immutable int half = limit / 2;
immutable int NA = -1;
// immutable real eps = 1E-7 - 1E-17;
immutable real eps = 0;

void main ()
{
	int k, q;
	while (readf (" %s %s", &k, &q) > 0)
	{
		auto t = new int [limit + 1];
		t[1..$] = NA;
		t[0] = 0;

		auto f = new real [] [] (2, k + 1);
		int b = 0;
		f[b][1..$] = 0.0;
		f[b][0] = 1.0;
		real invK = 1.0 / k;
		for (int step = 1; t[half] == NA; step++)
		{
			b ^= 1;
			f[b][] = 0.0;
			foreach (i; 0..k + 1)
			{
				f[b][i] += f[!b][i] * i * invK;
			}
			foreach (i; 0..k)
			{
				f[b][i + 1] += f[!b][i] * (k - i) * invK;
			}
			int cur = cast (int) ((f[b][k] + eps) * limit);
			debug {writeln (step, ": ", f[b][k]);}
			while (t[cur] == NA)
			{
				t[cur] = step;
				cur -= 1;
			}
		}

		foreach (j; 0..q)
		{
			int x;
			readf (" %s", &x);
			writeln (t[x]);
		}
	}
}

import core.bitop;
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int limit = 2000;
immutable int half = limit / 2;
immutable int NA = -1;
immutable real eps = 1E-7 - 1E-17;

void main ()
{
	int k, q;
	while (readf (" %s %s", &k, &q) > 0)
	{
		auto t = new int [limit + 1];
		t[1..$] = NA;
		t[0] = 0;

		auto f = new real [] [] (2, k + 1);
		int b = 0;
		f[b][1..$] = 0.0;
		f[b][0] = 1.0;
		real invK = 1.0 / k;
		for (int step = 1; t[half] == NA; step++)
		{
			b ^= 1;
			f[b][] = 0.0;
			foreach (i; 0..k + 1)
			{
				f[b][i] += f[!b][i] * i * invK;
			}
			foreach (i; 0..k)
			{
				f[b][i + 1] += f[!b][i] * (k - i) * invK;
			}
			int cur = cast (int) ((f[b][k] + eps) * limit);
			debug {writeln (step, ": ", f[b][k]);}
			while (t[cur] == NA)
			{
				t[cur] = step;
				cur -= 1;
			}
		}

		foreach (j; 0..q)
		{
			int x;
			readf (" %s", &x);
			writeln (t[x]);
		}
	}
}

import core.bitop;
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int limit = 2000;
immutable int half = limit / 2;
immutable int NA = -1;
immutable real eps = 1E-7 - 1E-17;

void main ()
{
	int k, q;
	while (readf (" %s %s", &k, &q) > 0)
	{
		auto t = new int [limit + 1];
		t[1..$] = NA;
		t[0] = 0;

		auto f = new real [] [] (2, k + 1);
		int b = 0;
		f[b][1..$] = 0.0;
		f[b][0] = 1.0;
		real invK = 1.0 / k;
		for (int step = 1; t[half] == NA; step++)
		{
			b ^= 1;
			f[b][] = 0.0;
			foreach (i; 0..k + 1)
			{
				f[b][i] += f[!b][i] * i * invK;
			}
			foreach (i; 0..k)
			{
				f[b][i + 1] += f[!b][i] * (k - i) * invK;
			}
			int cur = cast (int) ((f[b][k] - eps) * limit);
			debug {writeln (step, ": ", f[b][k]);}
			while (t[cur] == NA)
			{
				t[cur] = step;
				cur -= 1;
			}
		}

		foreach (j; 0..q)
		{
			int x;
			readf (" %s", &x);
			writeln (t[x]);
		}
	}
}


Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge). Makes has chosen n problems to solve on Decoforces with difficulties a1, a2, ..., an. He can solve these problems in arbitrary order. Though he can solve problem i with difficulty ai only if he had already solved some problem with difficulty  (no matter on what online judge was it).Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty k.With given conditions it's easy to see that Makes sometimes can't solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list. For every positive integer y there exist some problem with difficulty y on at least one judge besides Decoforces.Makes can solve problems on any judge at any time, it isn't necessary to do problems from the chosen list one right after another.Makes doesn't have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces.

The first line contains two integer numbers n, k (1 ≤ n ≤ 103, 1 ≤ k ≤ 109). The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).

Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.

NoteIn the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.In the second example he can solve every problem right from the start.

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1].to!long * 2;
    auto A = readln.split.map!(to!long).array;
    A.sort();

    long ans = 0;
    foreach (i; 0..N) {
        while (K < A[i]) K *= 2, ans += 1;
        K = max(K, A[i] * 2);
    }

    ans.writeln;
}

import std.stdio, std.string, std.algorithm, std.conv, std.array;

void main(){
	auto nk=readln.strip.split.map!(to!int).array;
	int n=nk[0],k=nk[1];
	auto a=readln.strip.split.map!(to!int).array;
	sort(a);
	int cur=k,r=0;
	foreach(x;a){
		while(cur<(x+1)/2){
			r++;
			cur*=2;
		}
		cur=max(cur,x);
	}
	writeln(r);
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1].to!long * 2;
    auto A = readln.split.map!(to!long).array;
    A.sort();
    auto X = A[$-1];

    foreach (i; 0..N) {
        if (A[i] <= K) K = max(K, A[i] * 2);
    }

    long ans = 0;
    while (K <= X) K *= 4, ans += 1;

    ans.writeln;
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1].to!long * 2;
    auto A = readln.split.map!(to!long).array;
    A.sort();
    auto X = A[$-1];

    foreach (i; 0..N) {
        if (A[i] <= K) K = max(K, A[i] * 2);
    }

    long ans = 0;
    while (K < X) K *= 2, ans += 1;

    ans.writeln;
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1].to!long * 2;
    auto A = readln.split.map!(to!long).array;
    A.sort();
    auto X = A[$-1];

    foreach (i; 0..N) {
        if (A[i] <= K) K = max(K, A[i] * 2);
    }

    long ans = 0;
    while (K < X) K *= 4, ans += 1;

    ans.writeln;
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1].to!long * 2;
    auto A = readln.split.map!(to!long).array;
    A.sort();
    auto X = A[$-1];

    foreach (i; 0..N) {
        if (A[i] <= K) K = max(K, A[i] * 2);
    }

    long ans = 0;
    while (K <= X) K *= 2, ans += 1;

    ans.writeln;
}

import std.stdio, std.string, std.algorithm, std.conv, std.array;

void main(){
	auto nk=readln.strip.split.map!(to!int).array;
	int n=nk[0],k=nk[1];
	auto a=readln.strip.split.map!(to!int).array;
	sort(a);
	int cur=k,r=0;
	foreach(x;a){
		while(cur<(x+1)/2){
			r++;
			cur=cur*2+1;
		}
		cur=max(cur,x);
	}
	writeln(r);
}


Let's call left cyclic shift of some string $$$t_1 t_2 t_3 \dots t_{n - 1} t_n$$$ as string $$$t_2 t_3 \dots t_{n - 1} t_n t_1$$$.Analogically, let's call right cyclic shift of string $$$t$$$ as string $$$t_n t_1 t_2 t_3 \dots t_{n - 1}$$$.Let's say string $$$t$$$ is good if its left cyclic shift is equal to its right cyclic shift.You are given string $$$s$$$ which consists of digits 0–9.What is the minimum number of characters you need to erase from $$$s$$$ to make it good?

The first line contains single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Next $$$t$$$ lines contains test cases — one per line. The first and only line of each test case contains string $$$s$$$ ($$$2 \le |s| \le 2 \cdot 10^5$$$). Each character $$$s_i$$$ is digit 0–9. It's guaranteed that the total length of strings doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print the minimum number of characters you need to erase from $$$s$$$ to make it good.

NoteIn the first test case, you can erase any $$$3$$$ characters, for example, the $$$1$$$-st, the $$$3$$$-rd, and the $$$4$$$-th. You'll get string 51 and it is good.In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.In the third test case, the given string $$$s$$$ is already good.

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

immutable char [] digits = "0123456789";

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip;
		int res = 0;
		foreach (char c; digits)
		{
			res = max (res, s.count (c).to !(int));
		}
		foreach (char c; digits)
		{
			foreach (char d; digits)
			{
				int pos = 0;
				int cur = 0;
				while (true)
				{
					while (pos < s.length && s[pos] != c)
					{
						pos += 1;
					}
					pos += 1;
					while (pos < s.length && s[pos] != d)
					{
						pos += 1;
					}
					if (pos >= s.length)
					{
						break;
					}
					pos += 1;
					cur += 2;
				}
				res = max (res, cur);
			}
		}
		writeln (s.length - res);
	}
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto s = RD!string;
		int n = cast(int)s.length;
		auto a = new int[](s.length);
		auto cnt = new int[](10);
		foreach (i; 0..s.length)
		{
			a[i] = s[i] - '0';
			++cnt[a[i]];
		}
		int best;
		foreach (i; 0..10)
			best.chmax(cnt[i]);
		ans[ti] = n - best;

		foreach (i; 0..10)
		{
			foreach (j; i+1..10)
			{
				int last = -1;
				int c;
				foreach (e; a)
				{
					if (last != e && (e == i || e == j))
					{
						++c;
						last = e;
					}
				}
				if (c % 2)
					--c;
				ans[ti].chmin(n - c);
			}
		}
	}

	foreach (e; ans)
	{
		writeln(e);
	}
	stdout.flush;
	debug readln;
}


This is an interactive problem.Note: the XOR-sum of an array $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) is defined as $$$a_1 \oplus a_2 \oplus \ldots \oplus a_n$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.Little Dormi received an array of $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ for Christmas. However, while playing with it over the winter break, he accidentally dropped it into his XOR machine, and the array got lost.The XOR machine is currently configured with a query size of $$$k$$$ (which you cannot change), and allows you to perform the following type of query: by giving the machine $$$k$$$ distinct indices $$$x_1, x_2, \ldots, x_k$$$, it will output $$$a_{x_1} \oplus a_{x_2} \oplus \ldots \oplus a_{x_k}$$$.As Little Dormi's older brother, you would like to help him recover the XOR-sum of his array $$$a_1, a_2, \ldots, a_n$$$ by querying the XOR machine.Little Dormi isn't very patient, so to be as fast as possible, you must query the XOR machine the minimum number of times to find the XOR-sum of his array. Formally, let $$$d$$$ be the minimum number of queries needed to find the XOR-sum of any array of length $$$n$$$ with a query size of $$$k$$$. Your program will be accepted if you find the correct XOR-sum in at most $$$d$$$ queries.Lastly, you also noticed that with certain configurations of the machine $$$k$$$ and values of $$$n$$$, it may not be possible to recover the XOR-sum of Little Dormi's lost array. If that is the case, you should report it as well.The array $$$a_1, a_2, \ldots, a_n$$$ is fixed before you start querying the XOR machine and does not change with the queries.

The only line of input contains the integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 500$$$, $$$1 \le k \le n$$$), the length of the lost array and the configured query size of the XOR machine. Elements of the original array satisfy $$$1 \le a_i \le 10^9$$$. It can be proven that that if it is possible to recover the XOR sum under the given constraints, it can be done in at most $$$500$$$ queries. That is, $$$d \le 500$$$. After taking $$$n$$$ and $$$k$$$, begin interaction.

If it is impossible to recover the XOR-sum of the array, output $$$-1$$$ immediately after taking $$$n$$$ and $$$k$$$. Do not begin interaction. Otherwise, when your program finds the XOR-sum of the lost array $$$a_1, a_2, \ldots, a_n$$$, report the answer in the following format: "! x", where $$$x$$$ is the XOR sum of the array $$$a_1, a_2, \ldots, a_n$$$, and terminate your program normally immediately after flushing the output stream.  Note that answering does not count as a query.

NoteIn the first example interaction, the array $$$a_1, a_2, \ldots, a_n$$$ is $$$2, 1, 7, 5, 6$$$ and its XOR-sum is $$$7$$$. The first query made asks for indices $$$1,2,3$$$, so the response is $$$a_1 \oplus a_2 \oplus a_3 = 2 \oplus 1 \oplus 7 = 4$$$.The second query made asks for indices $$$2,3,5$$$, so the response is $$$a_2 \oplus a_3 \oplus a_5 = 1 \oplus 7 \oplus 6 = 0$$$.The third query made asks for indices $$$4,1,5$$$, so the response is $$$a_4 \oplus a_1 \oplus a_5 = 5 \oplus 2 \oplus 6 = 1$$$. Note that the indices may be output in any order.Additionally, even though three queries were made in the example interaction, it is just meant to demonstrate the interaction format and does not necessarily represent an optimal strategy.In the second example interaction, there is no way to recover the XOR-sum of Little Dormi's array no matter what is queried, so the program immediately outputs $$$-1$$$ and exits.

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int limit = 500;

alias Plan = Tuple !(int, q{x}, int, q{y}, int, q{p}, int, q{q}, int, q{r});

int [] [] go (int n, int k, Plan plan)
{
	auto nv = plan.r + n + 2;
	auto start = nv - 2;
	auto finish = nv - 1;

	auto c = new int [] [] (nv, nv);
	foreach (i; 0..plan.r)
	{
		foreach (j; 0..n)
		{
			c[i + n][j] = 1;
		}
	}
	foreach (i; 0..plan.r)
	{
		c[start][i + n] = k;
	}
	foreach (j; 0..n)
	{
		c[j][finish] = (j < plan.x) ? plan.p : plan.q;
	}

	auto vis = new bool [nv];

	bool flow (int v)
	{
		if (v == finish)
		{
			return true;
		}
		if (vis[v])
		{
			return false;
		}
		vis[v] = true;
		foreach_reverse (i; 0..nv)
		{
			if (c[v][i] > 0 && flow (i))
			{
				c[v][i] -= 1;
				c[i][v] += 1;
				return true;
			}
		}
		return false;
	}

	foreach (step; 0..plan.r * k)
	{
		vis[start] = false;
		vis[finish] = false;
		if (!flow (start))
		{
			vis[] = false;
			if (!flow (start))
			{
				assert (false);
			}
		}
	}

	int [] [] res;
	foreach (i; 0..plan.r)
	{
		res ~= n.iota.filter !(j => c[j][i + n] != 0).array;
	}
	return res;
}

void main ()
{
	int n, k;
	while (readf !(" %s %s") (n, k) > 0)
	{
		readln;

		Plan res;
		res.r = int.max;
		for (int y = 1; y <= n; y += 1)
		{
			int x = n - y;
			for (int p = 1; p <= limit; p += 2)
			{
				for (int q = p; q <= limit; q += 2)
				{
					int value = x * p + y * q;
					if (value % k != 0)
					{
						continue;
					}
					int r = value / k;
					if (r < p || r < q)
					{
						continue;
					}
					assert (x * p + y * q == r * k);
					if (res.r > r)
					{
						res = Plan (x, y, p, q, r);
					}
				}
			}
		}
		if (res.r == int.max)
		{
			writeln (-1);
			stdout.flush ();
			continue;
		}

		debug {writeln (res);}

		int ask (int [] a)
		{
			writefln !("? %(%s %)") (a.map !(q{a + 1}));
			stdout.flush ();

			auto temp = readln.strip.to !(int);
			return temp;
		}

		auto answer = go (n, k, res);
		int total = 0;
		foreach (ref line; answer)
		{
			total ^= ask (line);
		}

		writeln ("! ", total);
		stdout.flush ();
	}
}


Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. Recently Xenia has bought $$$n_r$$$ red gems, $$$n_g$$$ green gems and $$$n_b$$$ blue gems. Each of the gems has a weight.Now, she is going to pick three gems.Xenia loves colorful things, so she will pick exactly one gem of each color.Xenia loves balance, so she will try to pick gems with little difference in weight.Specifically, supposing the weights of the picked gems are $$$x$$$, $$$y$$$ and $$$z$$$, Xenia wants to find the minimum value of $$$(x-y)^2+(y-z)^2+(z-x)^2$$$. As her dear friend, can you help her?

The first line contains a single integer $$$t$$$ ($$$1\le t \le 100$$$)  — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains three integers $$$n_r,n_g,n_b$$$ ($$$1\le n_r,n_g,n_b\le 10^5$$$)  — the number of red gems, green gems and blue gems respectively. The second line of each test case contains $$$n_r$$$ integers $$$r_1,r_2,\ldots,r_{n_r}$$$ ($$$1\le r_i \le 10^9$$$)  — $$$r_i$$$ is the weight of the $$$i$$$-th red gem. The third line of each test case contains $$$n_g$$$ integers $$$g_1,g_2,\ldots,g_{n_g}$$$ ($$$1\le g_i \le 10^9$$$)  — $$$g_i$$$ is the weight of the $$$i$$$-th green gem. The fourth line of each test case contains $$$n_b$$$ integers $$$b_1,b_2,\ldots,b_{n_b}$$$ ($$$1\le b_i \le 10^9$$$)  — $$$b_i$$$ is the weight of the $$$i$$$-th blue gem. It is guaranteed that $$$\sum n_r \le 10^5$$$, $$$\sum n_g \le 10^5$$$, $$$\sum n_b \le 10^5$$$ (the sum for all test cases).

For each test case, print a line contains one integer  — the minimum value which Xenia wants to find.

NoteIn the first test case, Xenia has the following gems:If she picks the red gem with weight $$$7$$$, the green gem with weight $$$6$$$, and the blue gem with weight $$$4$$$, she will achieve the most balanced selection with $$$(x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14$$$.

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional, std.meta;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int t;
    readf("%s", &t);
    readln;

    while (t--) {
        auto lens = readln.chomp.split.map!(to!int).array;

        int[][] arr;
        foreach (i; 0 .. 3) {
            arr ~= readln.chomp.split.map!(to!int).array;
            arr[i].sort();
        }

        ulong ans = ulong.max;
        foreach (ps; iota(3).permutations) {
            int smallidx = 0, bigidx = 0;
            foreach (e; arr[ps[0]]) {
                while (smallidx + 1 < lens[ps[1]] && arr[ps[1]][smallidx + 1] <= e) { ++smallidx; }
                while (bigidx < lens[ps[2]] && arr[ps[2]][bigidx] < e) { ++bigidx; }

                if (bigidx == lens[ps[2]]) { continue; }

                auto sm = arr[ps[1]][smallidx];
                auto bg = arr[ps[2]][bigidx];
                auto cur = (e.to!ulong - sm)^^2 + (sm.to!ulong - bg)^^2 + (bg.to!ulong - e)^^2;

                ans = min(ans, cur);
            }
        }

        ans.writeln;
    }
}

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int total = 3;

void main ()
{
	int tests;
	readf !(" %s") (tests);
	foreach (test; 0..tests)
	{
		int [total] n;
		foreach (ref c; n)
		{
			readf !(" %s") (c);
		}
		readln;
		int [] [total] a;
		foreach (ref c; a)
		{
			c = readln.splitter.map !(to !(int)).array;
			sort (c);
		}
		long res = long.max;
		foreach (i; 0..total)
		{
			foreach (j; 0..total)
			{
				if (j != i)
				{
					auto k = total - i - j;
					int v = 0;
					int w = 0;
					foreach (u; 0..n[i])
					{
						while (v < n[j] &&
						    a[j][v] <= a[i][u])
						{
							v += 1;
						}
						if (v > 0)
						{
							v -= 1;
						}
						while (w + 1 < n[k] &&
						    a[k][w] < a[j][v])
						{
							w += 1;
						}
						res = min (res,
						    (cast (long)
						    (a[i][u] - a[j][v])) ^^ 2 +
						    (cast (long)
						    (a[j][v] - a[k][w])) ^^ 2 +
						    (cast (long)
						    (a[k][w] - a[i][u])) ^^ 2);
	                        	}
				}
			}
		}
		writeln (res);
	}
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        auto N = new int[3];
        foreach (h; 0 .. 3) {
          N[h] = readInt();
        }
        auto A = new long[][3];
        foreach (h; 0 .. 3) {
          A[h] = new long[N[h]];
          foreach (i; 0 .. N[h]) {
            A[h][i] = readLong();
          }
          A[h].sort;
        }

        long ans = long.max;

        void check(long x, long y, long z) {
          debug {
            writeln("check ", x, " ", y, " ", z);
          }
          const score = (y - z)^^2 + (z - x)^^2 + (x - y)^^2;
          chmin(ans, score);
        }
        void checkH(int h, long y, long z) {
          const pos = A[h].upperBound((y + z) / 2);
          if (pos < N[h]) {
            check(A[h][pos], y, z);
          }
          if (pos - 1 >= 0) {
            check(A[h][pos - 1], y, z);
          }
        }

        foreach (h; 0 .. 3) {
          const h1 = (h + 1) % 3;
          const h2 = (h + 2) % 3;
          for (int i1 = 0, i2 = 0; i1 < N[h1] && i2 < N[h2]; ) {
            debug {
              writeln(h1, " ", h2, "; ", i1, " ", i2);
            }
            checkH(h, A[h1][i1], A[h2][i2]);
            if (A[h1][i1] < A[h2][i2]) {
              ++i1;
            } else {
              ++i2;
            }
          }
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}

//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;

final class InputReader {
  private:
  ubyte[] p, buffer;
  bool eof;
  bool rawRead () {
    if (eof) {
      return false;
    }
    p = stdin.rawRead (buffer);
    if (p.empty) {
      eof = true;
      return false;
    }
    return true;
  }
  ubyte nextByte(bool check) () {
    static if (check) {
      if (p.empty) {
        if (!rawRead ()) {
          return 0;
        }
      }
    }
    auto r = p.front;
    p.popFront ();
    return r;
  }
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
  }
  bool seekByte (in ubyte lo) {
    while (true) {
      p = p.find! (c => c >= lo);
      if (!p.empty) {
        return false;
      }
      if (!rawRead ()) {
        return true;
      }
    }
  }
  template next(T) if (isSigned!T) {
    T next ()  {
      if (seekByte (45)) {
        return 0;
      }
      T res;
      ubyte b = nextByte!false ();
      if (b == 45) {
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    T next () {
      if (seekByte (48)) {
        return 0;
      }
      T res = nextByte!false () - 48;
      while (true) {
        ubyte b = nextByte!true ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  T[] nextA(T) (in int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

void main() {
  auto r = new InputReader ();
  immutable nt = r.next!uint ();
  int[] ra (int n) {
    auto a = r.nextA!int (n);
    sort (a);
    return a;
  }
  foreach (tid; 0 .. nt) {
    long res = long.max;
    auto a = r.nextA!uint (3);
    auto t = new int[][3];
    foreach (k; 0 .. 3) t[k] = ra (a[k]);
    void check (long u, long v, long w) {
      long q = (u - v) * (u - v);
      q += (u - w) * (u - w);
      q += (v - w) * (v - w);
      if (res > q) res = q;
    }
    void f (in int[] x, in int[] y, in int[] z) {
      size_t j, k;
      foreach (i; 0 .. x.length) {
        int xv = x[i];
        while (j < y.length && y[j] < xv) ++j;
        while (k < z.length && z[k] < xv) ++k;
        void go (size_t u, size_t v) {
          if (u < y.length && v < z.length)
            check (xv, y[u], z[v]);
        }
        go (j, k);
        if (k > 0) {
          go (j, k - 1);
        }
        if (j > 0) {
          go (j - 1, k);
          if (k > 0) {
            go (j - 1, k - 1);
          }
        }
      }
    }
    f (t[0], t[1], t[2]);
    f (t[1], t[0], t[2]);
    f (t[2], t[0], t[1]);
    writeln (res);
  }
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

T binarySearch(alias pred, T)(T ok, T ng)
{
	while (abs(ok-ng) > 1)
	{
		auto mid = (ok+ng)/2;
		if (unaryFun!pred(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto nr = RD!int;
		auto ng = RD!int;
		auto nb = RD!int;
		auto r = RDA;
		auto g = RDA;
		auto b = RDA;
		r.sort();
		g.sort();
		b.sort();
		auto arr = new long[][](nr+ng+nb);
		foreach (i; 0..nr)
		{
			arr[i] = [r[i], 0];
		}
		foreach (i; 0..ng)
		{
			arr[nr+i] = [g[i], 1];
		}
		foreach (i; 0..nb)
		{
			arr[nr+ng+i] = [b[i], 2];
		}
		arr.sort!"a[0] < b[0]"();

		ans[ti] = long.max;
		long lr, lg, lb;
		long search(in long[] _arr, long d)
		{
			auto p = binarySearch!((int a) => _arr[a] >= d)(cast(int)_arr.length-1, -1);
			long res = _arr[p];
			if (p != 0)
			{
				if (abs(d - _arr[p-1]) < abs(res - d))
					res = _arr[p-1];
			}
			return res;
		}
		long eval(long rr, long gg, long bb)
		{
			return (rr-gg)^^2 + (gg-bb)^^2 + (bb-rr)^^2;
		}
		foreach (i; 0..arr.length)
		{
			if (arr[i][1] == 0)
			{
				lr = arr[i][0];
				if (lg != 0 && lb != 0)
				{
					long x;
					if (lg <= lb)
					{
						auto d = (lr+lg+1) / 2;
						x = search(b, d);
						ans[ti].chmin(eval(lr, lg, x));
					}
					else
					{
						auto d = (lr+lb+1) / 2;
						x = search(g, d);
						ans[ti].chmin(eval(lr, x, lb));
					}
				}
			}
			else if (arr[i][1] == 1)
			{
				lg = arr[i][0];
				if (lr != 0 && lb != 0)
				{
					long x;
					if (lr <= lb)
					{
						auto d = (lr+lg+1) / 2;
						x = search(b, d);
						ans[ti].chmin(eval(lr, lg, x));
					}
					else
					{
						auto d = (lg+lb+1) / 2;
						x = search(r, d);
						ans[ti].chmin(eval(x, lg, lb));
					}
				}
			}
			else
			{
				lb = arr[i][0];
				if (lr != 0 && lg != 0)
				{
					long x;
					if (lr <= lg)
					{
						auto d = (lr+lb+1) / 2;
						x = search(g, d);
						ans[ti].chmin(eval(lr, x, lb));
						debug writeln(arr[i], " d:", d, " x:", x);
					}
					else
					{
						auto d = (lg+lb+1) / 2;
						x = search(r, d);
						ans[ti].chmin(eval(x, lg, lb));
					}
				}
			}
		}
	}

	foreach (e; ans)
		writeln(e);
	stdout.flush;
	debug readln;
}

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int total = 3;

void main ()
{
	int tests;
	readf !(" %s") (tests);
	foreach (test; 0..tests)
	{
		int [total] n;
		foreach (ref c; n)
		{
			readf !(" %s") (c);
		}
		readln;
		int [] [total] a;
		foreach (ref c; a)
		{
			c = readln.splitter.map !(to !(int)).array;
			sort (c);
		}
		long res = long.max;
		foreach (i; 0..total)
		{
			foreach (j; 0..total) if (j != i)
			{
				auto k = total - i - j;
				int v = 0;
				int w = 0;
				foreach (u; 0..n[i])
				{
					while (v + 1 < n[j] &&
					    a[j][v] < a[i][u])
					{
						v += 1;
					}
					while (w + 1 < n[k] &&
					    a[k][w] < a[j][v])
					{
						w += 1;
					}
					res = min (res,
					    (cast (long)
					    (a[i][u] - a[j][v])) ^^ 2 +
					    (cast (long)
					    (a[j][v] - a[k][w])) ^^ 2 +
					    (cast (long)
					    (a[k][w] - a[i][u])) ^^ 2);
				}
			}
		}
		writeln (res);
	}
}


Lee was planning to get closer to Mashtali's heart to proceed with his evil plan(which we're not aware of, yet), so he decided to beautify Mashtali's graph. But he made several rules for himself. And also he was too busy with his plans that he didn't have time for such minor tasks, so he asked you for help.Mashtali's graph is an undirected weighted graph with $$$n$$$ vertices and $$$m$$$ edges with weights equal to either $$$1$$$ or $$$2$$$. Lee wants to direct the edges of Mashtali's graph so that it will be as beautiful as possible.Lee thinks that the beauty of a directed weighted graph is equal to the number of its Oddysey vertices. A vertex $$$v$$$ is an Oddysey vertex if $$$|d^+(v) - d^-(v)| = 1$$$, where $$$d^+(v)$$$ is the sum of weights of the outgoing from $$$v$$$ edges, and $$$d^-(v)$$$ is the sum of the weights of the incoming to $$$v$$$ edges.Find the largest possible beauty of a graph that Lee can achieve by directing the edges of Mashtali's graph. In addition, find any way to achieve it.Note that you have to orient each edge.

The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n \le 10^5;\; 1 \le m \le 10^5)$$$ — the numbers of vertices and edges in the graph. The $$$i$$$-th line of the following $$$m$$$ lines contains three integers $$$u_i$$$, $$$v_i$$$ and $$$w_i$$$ $$$( 1 \le u_i , v_i \le n;\; u_i \neq v_i;\; \bf{w_i \in \{1, 2\}} )$$$ — the endpoints of the $$$i$$$-th edge and its weight. Note that the graph doesn't have to be connected, and it might contain multiple edges.

In the first line print a single integer — the maximum beauty of the graph Lee can achieve. In the second line print a string of length $$$m$$$ consisting of $$$1$$$s and $$$2$$$s — directions of the edges. If you decide to direct the $$$i$$$-th edge from vertex $$$u_i$$$ to vertex $$$v_i$$$, $$$i$$$-th character of the string should be $$$1$$$. Otherwise, it should be $$$2$$$.

NoteExplanation for the first sample:  vertices $$$2$$$ and $$$5$$$ are Oddyseys. Explanation for the third sample:  vertices $$$1$$$ and $$$6$$$ are Oddyseys.

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

uint xrand() {
  static uint x = 314159265, y = 358979323, z = 846264338, w = 327950288;
  uint t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8;
}

int N, M;
int[] A, B, W;

alias Edge = Tuple!(int, "i", int, "v");
Edge[][][] G;

int[][] uss, iss;
int[] see;
bool[] used;
void dfs(int w, int u) {
  for (; see[u] < G[w][u].length; ) {
    const i = G[w][u][see[u]].i;
    const v = G[w][u][see[u]].v;
    ++see[u];
    if (!used[i]) {
      used[i] = true;
      debug {
        // writefln("euler(%s); %s -> %s", w, u, v);
      }
      dfs(w, v);
      iss[w] ~= i;
    }
  }
  uss[w] ~= u;
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      M = readInt();
      A = new int[M];
      B = new int[M];
      W = new int[M];
      foreach (i; 0 .. M) {
        A[i] = readInt() - 1;
        B[i] = readInt() - 1;
        W[i] = readInt();
      }

      auto deg = new int[][](3, N);
      foreach (i; 0 .. M) {
        ++deg[W[i]][A[i]];
        ++deg[W[i]][B[i]];
      }

      G = new Edge[][][](3, N + 1);
      foreach (i; 0 .. M) {
        G[W[i]][A[i]] ~= Edge(i, B[i]);
        G[W[i]][B[i]] ~= Edge(i, A[i]);
      }
      foreach (w; [1, 2]) {
        foreach (u; 0 .. N) {
          if (deg[w][u] & 1) {
            G[w][u] ~= Edge(M + u, N);
            G[w][N] ~= Edge(M + u, u);
          }
        }
      }

      uss = new int[][](3);
      iss = new int[][](3);
      foreach (w; [1, 2]) {
        see = new int[N + 1];
        used = new bool[M + N];
        foreach_reverse (u; 0 .. N + 1) {
          dfs(w, u);
          iss[w] ~= -1;
        }
        debug {
          writefln("uss[%s] = %s", w, uss[w]);
          writefln("iss[%s] = %s", w, iss[w]);
        }
      }

      alias Entry = Tuple!(int, "to", int, "j", int, "k");
      auto ess = new Entry[][](3, N);
      foreach (w; [1, 2]) {
        ess[w][] = Entry(-1, -1, -1);
        const len = cast(int)(iss[w].length);
        for (int j = 0, k; j < len; j = k) {
          for (k = j + 1; k < len && uss[w][k] != N; ++k) {}
          if (k == len) {
            break;
          }
          const u = uss[w][j + 1];
          const v = uss[w][k - 1];
          debug {
            writefln("waf %s; %s -> %s", w, u, v);
          }
          ess[w][u] = Entry(v, j + 1, k - 1);
          ess[w][v] = Entry(u, k - 1, j + 1);
        }
      }

      auto ans = new char[M];
      ans[] = '?';
      foreach (w; [1, 2]) {
        const len = cast(int)(iss[w].length);
        foreach (j; 0 .. len - 1) {
          const i = iss[w][j];
          const u = uss[w][j];
          const v = uss[w][j + 1];
          if (0 <= i && i < M) {
            if (u == A[i] && v == B[i]) {
              ans[i] = '1';
            } else if (u == B[i] && v == A[i]) {
              ans[i] = '2';
            } else {
              assert(false);
            }
          }
        }
      }
      void flip(int w, int j, int k) {
        debug {
          writefln("flip %s [%s, %s]", w, j, k);
        }
        if (j > k) {
          swap(j, k);
        }
        foreach (l; j .. k) {
          const i = iss[w][l];
          if (0 <= i && i < M) {
            ans[i] ^= '1' ^ '2';
          }
        }
      }

      auto vis = new bool[N];
      foreach (r; 0 .. N) if (!vis[r]) {
        foreach (w0; [1, 2]) {
          for (int w = w0, u = r; ; ) {
            vis[u] = true;
            const v = ess[w][u].to;
            const j = ess[w][u].j;
            const k = ess[w][u].k;
            if (!~v) {
              break;
            }
            ess[w][u] = ess[w][v] = Entry(-1, -1, -1);
            debug {
              writefln("%s %s; %s; %s -> %s [%s, %s]", r, w0, w, u, v, j, k);
            }
            if ((w0 == 1) != (j < k)) {
              flip(w, j, k);
            }
            if (v == r) {
              break;
            }
            w ^= 1 ^ 2;
            u = v;
          }
        }
      }

      const score = deg[1].count!((a) => (a % 2 != 0));
      writeln(score);
      writeln(ans);

      auto vals = new int[N];
      foreach (i; 0 .. M) {
        final switch (ans[i]) {
          case '1': vals[A[i]] += W[i]; vals[B[i]] -= W[i]; break;
          case '2': vals[B[i]] += W[i]; vals[A[i]] -= W[i]; break;
        }
      }
      debug {
        writeln("vals = ", vals);
      }
      assert(score == vals.count!((a) => abs(a) == 1));
    }
  } catch (EOFException e) {
  }
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

uint xrand() {
  static uint x = 314159265, y = 358979323, z = 846264338, w = 327950288;
  uint t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8;
}

int N, M;
int[] A, B, W;

alias Edge = Tuple!(int, "i", int, "v");
Edge[][][] G;

int[][] uss, iss;
int[] see;
bool[] used;
void dfs(int w, int u) {
  for (; see[u] < G[w][u].length; ) {
    const i = G[w][u][see[u]].i;
    const v = G[w][u][see[u]].v;
    ++see[u];
    if (!used[i]) {
      used[i] = true;
      debug {
        writefln("euler(%s); %s -> %s", w, u, v);
      }
      dfs(w, v);
      iss[w] ~= i;
    }
  }
  uss[w] ~= u;
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      M = readInt();
      A = new int[M];
      B = new int[M];
      W = new int[M];
      foreach (i; 0 .. M) {
        A[i] = readInt() - 1;
        B[i] = readInt() - 1;
        W[i] = readInt();
      }

      auto deg = new int[][](3, N);
      foreach (i; 0 .. M) {
        ++deg[W[i]][A[i]];
        ++deg[W[i]][B[i]];
      }

      G = new Edge[][][](3, N + 1);
      foreach (i; 0 .. M) {
        G[W[i]][A[i]] ~= Edge(i, B[i]);
        G[W[i]][B[i]] ~= Edge(i, A[i]);
      }
      foreach (w; [1, 2]) {
        foreach (u; 0 .. N) {
          if (deg[w][u] & 1) {
            G[w][u] ~= Edge(M + u, N);
            G[w][N] ~= Edge(M + u, u);
          }
        }
      }

      uss = new int[][](3);
      iss = new int[][](3);
      foreach (w; [1, 2]) {
        see = new int[N + 1];
        used = new bool[M + N];
        dfs(w, N);
        foreach (u; 0 .. N) {
          dfs(w, u);
        }
        debug {
          writefln("uss[%s] = %s", w, uss[w]);
          writefln("iss[%s] = %s", w, iss[w]);
        }
      }

      alias Entry = Tuple!(int, "to", int, "j", int, "k");
      auto ess = new Entry[][](3, N);
      foreach (w; [1, 2]) {
        ess[w][] = Entry(-1, -1, -1);
        const len = cast(int)(iss[w].length);
        for (int j = 0, k; j < len; j = k) {
          for (k = j + 1; k < len && uss[w][k] != N; ++k) {}
          if (uss[w][k] != N) {
            break;
          }
          const u = uss[w][j + 1];
          const v = uss[w][k - 1];
          debug {
            writefln("waf %s; %s -> %s", w, u, v);
          }
          ess[w][u] = Entry(v, j + 1, k - 1);
          ess[w][v] = Entry(u, k - 1, j + 1);
        }
      }

      auto ans = new char[M];
      ans[] = '?';
      foreach (w; [1, 2]) {
        const len = cast(int)(iss[w].length);
        foreach (j; 0 .. len) {
          const i = iss[w][j];
          const u = uss[w][j];
          const v = uss[w][j + 1];
          if (i < M) {
            if (u == A[i] && v == B[i]) {
              ans[i] = '1';
            } else if (u == B[i] && v == A[i]) {
              ans[i] = '2';
            } else {
              assert(false);
            }
          }
        }
      }
      void flip(int w, int j, int k) {
        debug {
          writefln("flip %s [%s, %s]", w, j, k);
        }
        if (j > k) {
          swap(j, k);
        }
        foreach (l; j .. k) {
          const i = iss[w][l];
          if (i < M) {
            ans[i] ^= '1' ^ '2';
          }
        }
      }

      auto vis = new bool[N];
      foreach (r; 0 .. N) if (!vis[r]) {
        foreach (w0; [1, 2]) {
          for (int w = w0, u = r; ; ) {
            vis[u] = true;
            const v = ess[w][u].to;
            const j = ess[w][u].j;
            const k = ess[w][u].k;
            debug {
              writefln("%s %s; %s -> %s [%s, %s]", r, w0, u, v, j, k);
            }
            if (!~v) {
              break;
            }
            if ((w0 == 1) != (j < k)) {
              flip(w, j, k);
            }
            if (v == r) {
              break;
            }
            w ^= 1 ^ 2;
            u = v;
          }
        }
      }

      const score = deg[1].count!((a) => (a % 2 != 0));
      writeln(score);
      writeln(ans);

      auto vals = new int[N];
      foreach (i; 0 .. M) {
        final switch (ans[i]) {
          case '1': vals[A[i]] += W[i]; vals[B[i]] -= W[i]; break;
          case '2': vals[B[i]] += W[i]; vals[A[i]] -= W[i]; break;
        }
      }
      debug {
        writeln("vals = ", vals);
      }
      assert(score == vals.count!((a) => abs(a) == 1));
    }
  } catch (EOFException e) {
  }
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

int N, M;
int[] A, B, W;

char[] ans;

alias Edge = Tuple!(int, "i", int, "v");
Edge[][][] G;

int[] poss;
bool[] used;
void euler(int w) {
  void dfs(int u) {
    for (; poss[u] < G[w][u].length; ) {
      const i = G[w][u][poss[u]].i;
      const v = G[w][u][poss[u]].v;
      ++poss[u];
      if (!used[i]) {
        used[i] = true;
        debug {
          writefln("euler(%s); %s -> %s", w, u, v);
        }
        // u -> v
        if (i < M) {
          if (u == A[i] && v == B[i]) {
            ans[i] = '1';
          } else if (v == A[i] && u == B[i]) {
            ans[i] = '2';
          } else {
            assert(false);
          }
        }
        dfs(v);
      }
    }
  }
  poss = new int[N + 1];
  used = new bool[M + N];
  dfs(N);
  foreach (u; 0 .. N) {
    dfs(u);
  }
  debug {
    writefln("euler(%s); used = %s", w, used);
  }
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      M = readInt();
      A = new int[M];
      B = new int[M];
      W = new int[M];
      foreach (i; 0 .. M) {
        A[i] = readInt() - 1;
        B[i] = readInt() - 1;
        W[i] = readInt();
      }

      auto deg = new int[][](3, N);
      foreach (i; 0 .. M) {
        ++deg[W[i]][A[i]];
        ++deg[W[i]][B[i]];
      }
      auto uss = new int[][4];
      foreach (u; 0 .. N) {
        int p;
        if (deg[1][u] & 1) p |= 1;
        if (deg[2][u] & 1) p |= 2;
        uss[p] ~= u;
      }
      debug {
        writeln("deg = ", deg);
        writeln("uss = ", uss);
      }
      G = new Edge[][][](3, N + 1);
      foreach (i; 0 .. M) {
        G[W[i]][A[i]] ~= Edge(i, B[i]);
        G[W[i]][B[i]] ~= Edge(i, A[i]);
      }
      foreach (w; [1, 2]) {
        bool s = (w == 2);
        foreach (u; uss[3] ~ uss[w]) {
          if (s) {
            G[w][N] ~= Edge(M + u, u);
          } else {
            G[w][u] ~= Edge(M + u, N);
          }
          s = !s;
        }
      }
      ans = new char[M];
      ans[] = '?';
      foreach (w; [1, 2]) {
        debug {
          writefln("G[%s] = %s", w, G[w]);
        }
        euler(w);
      }

      writeln(uss[1].length + uss[3].length);
      writeln(ans);

      auto vals = new int[N];
      foreach (i; 0 .. M) {
        final switch (ans[i]) {
          case '1': vals[A[i]] += W[i]; vals[B[i]] -= W[i]; break;
          case '2': vals[B[i]] += W[i]; vals[A[i]] -= W[i]; break;
        }
      }
      debug {
        writeln("vals = ", vals);
      }
      assert(uss[1].length + uss[3].length == vals.count!((a) => abs(a) == 1));
    }
  } catch (EOFException e) {
  }
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

int N, M;
int[] A, B, W;

char[] ans;

alias Edge = Tuple!(int, "i", int, "v");
Edge[][][] G;

int[] poss;
bool[] used;
void euler(int w) {
  void dfs(int u) {
    for (; poss[u] < G[w][u].length; ) {
      const i = G[w][u][poss[u]].i;
      const v = G[w][u][poss[u]].v;
      ++poss[u];
      if (!used[i]) {
        used[i] = true;
        dfs(v);
        // u -> v
        if (i < M) {
          if (u == A[i] && v == B[i]) {
            ans[i] = '1';
          } else if (v == A[i] && u == B[i]) {
            ans[i] = '2';
          } else {
            assert(false);
          }
        }
      }
    }
  }
  poss = new int[N + 1];
  used = new bool[M + N];
  foreach (u; 0 .. N + 1) {
    dfs(u);
  }
  debug {
    writefln("euler(%s); used = %s", w, used);
  }
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      M = readInt();
      A = new int[M];
      B = new int[M];
      W = new int[M];
      foreach (i; 0 .. M) {
        A[i] = readInt() - 1;
        B[i] = readInt() - 1;
        W[i] = readInt();
      }

      auto deg = new int[][](3, N);
      foreach (i; 0 .. M) {
        ++deg[W[i]][A[i]];
        ++deg[W[i]][B[i]];
      }
      auto uss = new int[][4];
      foreach (u; 0 .. N) {
        int p;
        if (deg[1][u] & 1) p |= 1;
        if (deg[2][u] & 1) p |= 2;
        uss[p] ~= u;
      }
      debug {
        writeln("deg = ", deg);
        writeln("uss = ", uss);
      }
      G = new Edge[][][](3, N + 1);
      foreach (i; 0 .. M) {
        G[W[i]][A[i]] ~= Edge(i, B[i]);
        G[W[i]][B[i]] ~= Edge(i, A[i]);
      }
      foreach (w; [1, 2]) {
        bool s = (w == 2);
        foreach (u; uss[3] ~ uss[w]) {
          if (s) {
            G[w][N] ~= Edge(M + u, u);
          } else {
            G[w][u] ~= Edge(M + u, N);
          }
          s = !s;
        }
      }
      ans = new char[M];
      ans[] = '?';
      foreach (w; [1, 2]) {
        debug {
          writefln("G[%s] = %s", w, G[w]);
        }
        euler(w);
      }

      writeln(uss[1].length + uss[3].length);
      writeln(ans);

      auto vals = new int[N];
      foreach (i; 0 .. M) {
        final switch (ans[i]) {
          case '1': vals[A[i]] += W[i]; vals[B[i]] -= W[i]; break;
          case '2': vals[B[i]] += W[i]; vals[A[i]] -= W[i]; break;
        }
      }
      debug {
        writeln("vals = ", vals);
      }
      assert(uss[1].length + uss[3].length == vals.count!((a) => abs(a) == 1));
    }
  } catch (EOFException e) {
  }
}


Diamond Miner is a game that is similar to Gold Miner, but there are $$$n$$$ miners instead of $$$1$$$ in this game.The mining area can be described as a plane. The $$$n$$$ miners can be regarded as $$$n$$$ points on the y-axis. There are $$$n$$$ diamond mines in the mining area. We can regard them as $$$n$$$ points on the x-axis. For some reason, no miners or diamond mines can be at the origin (point $$$(0, 0)$$$). Every miner should mine exactly one diamond mine. Every miner has a hook, which can be used to mine a diamond mine. If a miner at the point $$$(a,b)$$$ uses his hook to mine a diamond mine at the point $$$(c,d)$$$, he will spend $$$\sqrt{(a-c)^2+(b-d)^2}$$$ energy to mine it (the distance between these points). The miners can't move or help each other.The object of this game is to minimize the sum of the energy that miners spend. Can you find this minimum?

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of miners and mines. Each of the next $$$2n$$$ lines contains two space-separated integers $$$x$$$ ($$$-10^8 \le x \le 10^8$$$) and $$$y$$$ ($$$-10^8 \le y \le 10^8$$$), which represent the point $$$(x,y)$$$ to describe a miner's or a diamond mine's position. Either $$$x = 0$$$, meaning there is a miner at the point $$$(0, y)$$$, or $$$y = 0$$$, meaning there is a diamond mine at the point $$$(x, 0)$$$. There can be multiple miners or diamond mines at the same point. It is guaranteed that no point is at the origin. It is guaranteed that the number of points on the x-axis is equal to $$$n$$$ and the number of points on the y-axis is equal to $$$n$$$. It's guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$10^5$$$.

For each test case, print a single real number — the minimal sum of energy that should be spent. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-9}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-9}$$$.

NoteIn the first test case, the miners are at $$$(0,1)$$$ and $$$(0,-1)$$$, while the diamond mines are at $$$(1,0)$$$ and $$$(-2,0)$$$. If you arrange the miners to get the diamond mines in the way, shown in the picture, you can get the sum of the energy $$$\sqrt2 + \sqrt5$$$.

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new double[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;

		long[] a, b;
		foreach (i; 0..n*2)
		{
			auto x = RD;
			auto y = RD;
			if (x == 0)
				a ~= y.abs;
			else
				b ~= x.abs;
		}
		a.sort();
		b.sort();

		ans[ti] = 0.0;
		foreach (i; 0..n)
		{
			ans[ti] += sqrt(cast(double)a[i]^^2 + b[i]^^2);
		}
	}

	foreach (e; ans)
		writefln("%.15f", e);
	stdout.flush;
	debug readln;
}

// Cheese-Cracker: cheese-cracker.github.io

void theCode(){
    int n;
    n = scan!int;
    ll[] miner;
    ll[] diam;
    ll x, y;
    for(int i = 0; i < 2*n; ++i) {
        x = scan; y = scan;
        if(x == 0){
            miner ~= abs(y);
        }else{
            diam ~= abs(x);
        }
    }
    miner.sort;
    diam.sort;
    double res = 0;
    for(int i = 0; i < n; ++i){
        double curres = miner[i]*miner[i] + diam[i]*diam[i];
        curres = sqrt(curres);
        res += curres;
    }
    writefln("%.12f", res);
}

void main(){
    long tests = 1;
    tests = scan;        // Toggle!
    while(tests--) theCode();
}

/*********  That's All Folks!  *********/
import std.stdio, std.random, std.functional, std.container, std.algorithm;
import std.numeric, std.range, std.typecons, std.string, std.math, std.conv;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new double[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;

		int[] a, b;
		foreach (i; 0..n*2)
		{
			auto x = RD!int;
			auto y = RD!int;
			if (x == 0)
				a ~= y.abs;
			else
				b ~= x.abs;
		}
		a.sort();
		b.sort();

		ans[ti] = 0.0;
		foreach (i; 0..n)
		{
			ans[ti] += sqrt(cast(double)a[i]^^2 + b[i]^^2);
		}
	}

	foreach (e; ans)
		writefln("%.15f", e);
	stdout.flush;
	debug readln;
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new double[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;

		int[] a, b;
		foreach (i; 0..n*2)
		{
			auto x = RD!int;
			auto y = RD!int;
			if (x == 0)
				a ~= y.abs;
			else
				b ~= x.abs;
		}
		a.sort();
		b.sort();

		ans[ti] = 0.0;
		foreach (i; 0..n)
		{
			ans[ti] += sqrt(cast(double)a[i]^^2 + b[i]^^2);
		}
	}

	foreach (e; ans)
		writefln(FMT_F, e);
	stdout.flush;
	debug readln;
}


There are $$$n$$$ piranhas with sizes $$$a_1, a_2, \ldots, a_n$$$ in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.Scientists of the Berland State University want to find if there is dominant piranha in the aquarium. The piranha is called dominant if it can eat all the other piranhas in the aquarium (except itself, of course). Other piranhas will do nothing while the dominant piranha will eat them.Because the aquarium is pretty narrow and long, the piranha can eat only one of the adjacent piranhas during one move. Piranha can do as many moves as it needs (or as it can). More precisely:   The piranha $$$i$$$ can eat the piranha $$$i-1$$$ if the piranha $$$i-1$$$ exists and $$$a_{i - 1} < a_i$$$.  The piranha $$$i$$$ can eat the piranha $$$i+1$$$ if the piranha $$$i+1$$$ exists and $$$a_{i + 1} < a_i$$$. When the piranha $$$i$$$ eats some piranha, its size increases by one ($$$a_i$$$ becomes $$$a_i + 1$$$).Your task is to find any dominant piranha in the aquarium or determine if there are no such piranhas.Note that you have to find any (exactly one) dominant piranha, you don't have to find all of them.For example, if $$$a = [5, 3, 4, 4, 5]$$$, then the third piranha can be dominant. Consider the sequence of its moves:   The piranha eats the second piranha and $$$a$$$ becomes $$$[5, \underline{5}, 4, 5]$$$ (the underlined piranha is our candidate).  The piranha eats the third piranha and $$$a$$$ becomes $$$[5, \underline{6}, 5]$$$.  The piranha eats the first piranha and $$$a$$$ becomes $$$[\underline{7}, 5]$$$.  The piranha eats the second piranha and $$$a$$$ becomes $$$[\underline{8}]$$$. You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$) — the number of piranhas in the aquarium. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the size of the $$$i$$$-th piranha. It is guaranteed that the sum of $$$n$$$ does not exceed $$$3 \cdot 10^5$$$ ($$$\sum n \le 3 \cdot 10^5$$$).

For each test case, print the answer: -1 if there are no dominant piranhas in the aquarium or index of any dominant piranha otherwise. If there are several answers, you can print any.

NoteThe first test case of the example is described in the problem statement.In the second test case of the example, there are no dominant piranhas in the aquarium.In the third test case of the example, the fourth piranha can firstly eat the piranha to the left and the aquarium becomes $$$[4, 4, 5, 4]$$$, then it can eat any other piranha in the aquarium.

// Cheese-Cracker: cheese-cracker.github.io

void play(){
    int n;
    n = rd!int;
    ll[] arr = rdarr;
    ll maxx = arr.maxElement;
    ll maxi = -1;
    foreach(i; 0..n){
        if(arr[i] == maxx){
            if(i > 0 && arr[i-1] < maxx){
                maxi = i + 1;
                break;
            }else if(i < n - 1 && arr[i+1] < maxx){
                maxi = i + 1;
                break;
            }
        }
    }
    writeln(maxi);
}

int main(){
    long t = 1;
    t = rd;        // Toggle!
    while(t--) play();  // Let's play!
    stdout.flush;
    return 0;
}

/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }
void show(A...)(A a) { debug{ a.each!(w => write(w, "| ")); writeln; } }
alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
T max(T = long)(T a, T b){ return (a > b) ? a : b; }
T min(T = long)(T a, T b){ return (a < b) ? a : b; }

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
multitest_loop:
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		auto m = a.maxElement;
		foreach (i; 0..n)
		{
			if (a[i] == m && ((i > 0 && a[i - 1] < a[i]) ||
			    (i + 1 < n && a[i + 1] < a[i])))
			{
				writeln (i + 1);
				continue multitest_loop;
			}
		}
		writeln (-1);
	}
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;

		long x;
		foreach (i; 0..n)
		{
			x.chmax(a[i]);
		}

		ans[ti] = -1;
		foreach (i; 0..n)
		{
			if (a[i] != x) continue;
			if (i != 0)
			{
				if (a[i] > a[i-1])
				{
					ans[ti] = i+1;
					break;
				}
			}
			if (i != n-1)
			{
				if (a[i] > a[i+1])
				{
					ans[ti] = i+1;
					break;
				}
			}
		}
	}

	foreach (e; ans)
		writeln(e);
	stdout.flush;
	debug readln;
}


As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i ≠ j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.

The first line contains integer n (1 ≤ n ≤ 106), that sets the size of set A. The second line contains n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 106) — elements of subset A. The numbers in the line follow in the ascending order.

Print a single number — the maximum size of a clique in a divisibility graph for set A.

NoteIn the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph.

import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import core.bitop;

immutable int MAX_N = 1_000_006;

void main ()
{
	int n;
	while (readf (" %s ", &n) > 0)
	{
		auto b = new bool [MAX_N];
		foreach (x; readln.split.map !(to !(int)))
		{
			b[x] = true;
		}

		auto f = new int [MAX_N];
		foreach (i; 0..MAX_N)
		{
			f[i] = b[i];
		}

		int res = 0;
		for (int x = 1; x < MAX_N; x++)
		{
			if (!b[x])
			{
				continue;
			}
			for (int y = x * 2; y < MAX_N; y += x)
			{
				if (!b[y])
				{
					continue;
				}
				f[y] = max (f[y], f[x] + 1);
			}
			res = max (res, f[x]);
		}
		writeln (res);
	}
}

import std.algorithm, std.conv, std.stdio, std.range;
immutable int MAX_N = 1_000_006;
void main ()
{
    int n;
    while (readf (" %s ", &n) > 0)
    {
        auto f = new int [MAX_N];
        foreach (x; readln.split.map !(to !(int)))
            f[x] = 1;
        for (int x = 1; x < MAX_N; x++) if (f[x])
            for (int y = x * 2; y < MAX_N; y += x) if (f[y])
                f[y] = max (f[y], f[x] + 1);
        f.minPos !(q{a > b}).front.writeln;
    }
}

import std.algorithm, std.conv, std.stdio, std.range;
immutable int MAX_N = 1_000_006;
void main ()
{
	int n;
	readf (" %s ", &n);
	auto f = new int [MAX_N];
	foreach (x; readln.split.map!(to!int))
		for (int y = x * 2; y < MAX_N; y += x)
			f[y] = max (f[y], f[x] + 1);
	f.minPos!q{a > b}.front.writeln;
}