Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.You are a new applicant for his company. Boboniu will test you with the following chess question:Consider a $$$n\times m$$$ grid (rows are numbered from $$$1$$$ to $$$n$$$, and columns are numbered from $$$1$$$ to $$$m$$$). You have a chess piece, and it stands at some cell $$$(S_x,S_y)$$$ which is not on the border (i.e. $$$2 \le S_x \le n-1$$$ and $$$2 \le S_y \le m-1$$$).From the cell $$$(x,y)$$$, you can move your chess piece to $$$(x,y')$$$ ($$$1\le y'\le m, y' \neq y$$$) or $$$(x',y)$$$ ($$$1\le x'\le n, x'\neq x$$$). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.Your goal is to visit each cell exactly once. Can you find a solution?Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.

The only line of the input contains four integers $$$n$$$, $$$m$$$, $$$S_x$$$ and $$$S_y$$$ ($$$3\le n,m\le 100$$$, $$$2 \le S_x \le n-1$$$, $$$2 \le S_y \le m-1$$$) — the number of rows, the number of columns, and the initial position of your chess piece, respectively.

You should print $$$n\cdot m$$$ lines. The $$$i$$$-th line should contain two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \leq x_i \leq n$$$, $$$1 \leq y_i \leq m$$$), denoting the $$$i$$$-th cell that you visited. You should print exactly $$$nm$$$ pairs $$$(x_i, y_i)$$$, they should cover all possible pairs $$$(x_i, y_i)$$$, such that $$$1 \leq x_i \leq n$$$, $$$1 \leq y_i \leq m$$$. We can show that under these constraints there always exists a solution. If there are multiple answers, print any.

// Vicfred
// https://codeforces.com/contest/1395/problem/B
// implementation
import std.stdio;

void main() {
    int n, m, sx, sy;
    readf("%s %s %s %s", &n, &m, &sx, &sy);

    writefln("%s %s", sx, sy);

    for(int i = 1; i <= n; i++)
        if(i != sx)
            writefln("%s %s", i, sy);

    for(int i =1; i <= m; i++) {
        if(i == sy)
            continue;
        int direction = i&1;
        if(i > sy)
            direction ^= 1;
        if(direction == 1)
            for(int j = n; j > 0; j--)
                writefln("%s %s", j, i);
        else
            for(int j = 1; j <= n; j++)
                writefln("%s %s", j, i);
    }
}

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

void main ()
{
	int rows, cols, sRow, sCol;
	while (readf !(" %s %s %s %s") (rows, cols, sRow, sCol) > 0)
	{
		auto r = rows.iota.array;
		swap (r[0], r[sRow - 1]);
		r[] += 1;
		auto c = cols.iota.array;
		swap (c[0], c[sCol - 1]);
		c[] += 1;
		foreach (row; 0..rows)
		{
			if (row & 1)
			{
				foreach_reverse (col; 0..cols)
				{
					writeln (r[row], " ", c[col]);
				}
			}
			else
			{
				foreach (col; 0..cols)
				{
					writeln (r[row], " ", c[col]);
				}
			}
		}
	}
}

import std.container;
import std.algorithm;
import std.range;
import std.array;
import std.stdio;
import std.utf;
import std.math;
import std.typecons;

alias type = single;
struct TestCase
{
  mixin prettyPrinting;

  long n, m, sx, sy;

  void solve(long tc = -1)
  {
    foreach(y; sy .. m + 1)
      {
        writeln(sx, " ", y);
      }
    foreach_reverse(y; 1 .. sy)
      {
        writeln(sx, " ", y);
      }
    bool bottom = true;
    foreach(col; 1 .. n + 1)
      if (col != sx)
      {
        if (bottom)
          {
            foreach(y; 1 .. m + 1)
              {
                writeln(col, " ", y);
              }
          }
        else
          {
            foreach_reverse(y; 1 .. m + 1)
              {
                writeln(col, " ", y);
              }
          }
        bottom = !bottom;
      }
  }
}

struct Interval
{
  long l, h;

  bool empty()
  {
    return l > h;
  }
}

Interval intersect(Interval a, Interval b)
{
  return Interval(max(a.l, b.l), min(a.h, b.h));
}

struct If
{
  string condition;
}
enum ignore = If("false");
struct Dim
{
  string dimensions;
  int levels;
  this(string dimensions)
  {
    this.dimensions = dimensions;
    levels = cast(int)dimensions.count(",") + 1;
  }
}

template getArrayLevel(W)
{
  static if (isDynamicArray!W && !is(W == string))
    enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));
  else
    enum getArrayLevel = 0;
}

static foreach(fieldName; 'a' .. cast(char)('z' + 1))
  {
    static if (fieldName != 'o')
      mixin("enum d", fieldName, " = Dim(\"", fieldName, "\");");
  }

mixin template prettyPrinting()
{
  string toString()
  {
    alias structType = typeof(this);
    auto res = appender!(string)();
    res.put(structType.stringof);
    res.put("(");
    static foreach(fieldName; FieldNameTuple!structType)
      {
        res.put(text(" ", fieldName, ": ", mixin(fieldName)));
      }
    res.put(" )");
    res.put("\n");
    return res[];
  }
}

struct Graph(N)
{
  size_t size;
  this(S)(S size)
  {
    adjacencyList.length = cast(size_t) size;
    this.size = cast(size_t) size;
    this.visited = makeSlice!bool(size);
  }
  N[][] adjacencyList;
  alias ne = neighbours;
  N[] neighbours(N n)
  {
    return adjacencyList.at(n);
  }
  alias bcon = biconnect;
  void biconnect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
    adjacencyList.at(b) ~= a;
  }
  alias con = connect;
  void connect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
  }
  void connect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        connect(edge[0], edge[1]);
      }
  }
  void biconnect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        biconnect(edge[0], edge[1]);
      }
  }
  alias deg = degree!long;
  auto degree(T)(N a)
  {
    return cast(T) adjacencyList.at(a).length;
  }

  auto visited = new bool[0];
  void dfs(Visitor)(long startNode)
  {
    auto visitor = Visitor.init;
    void internalDfs(long node)
    {
      visited.set(node, true);
      static if (is(typeof({visitor.n = node;})))
        visitor.n = node;
      static if (is(typeof({visitor.pre;})))
        visitor.pre;
      foreach(w; ne(node))
        if (!visited.at(w))
          {
            static if (is(typeof({visitor.w = w;})))
              visitor.w = w;
            static if (is(typeof(visitor.pren)))
              visitor.pren;
            internalDfs(w);
            static if (is(typeof(visitor.postn)))
              visitor.postn;
          }
      static if (is(typeof(visitor.post)))
        visitor.post;
    }
    internalDfs(startNode);
  }
  void dfs(long startNode)
  {
    struct DefVisitor {}
    dfs!DefVisitor(startNode);
  }
}

DList!string _words;

template removeArray(W, int times)
{
  static if (times == 0)
    alias removeArray = W;
  else static if (times == 1)
    alias removeArray = typeof(function(){W w; return w[0];}());
  else
    {
      static assert(isDynamicArray!W);
      alias removeArray = removeArray!(removeArray!(W, 1), times - 1);
    }
}

template baseType(W)
{
  static if (isDynamicArray!W && !is(W == string))
    alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));
  else
    alias baseType = W;
}

auto makeSlice(E, W, T...)(W size, T otherSizes)
{
  static if (T.length == 0)
    {
      E[] res;
      res.length = cast(size_t) size;
      return res;
    }
  else
    {
      typeof(makeSlice!E(otherSizes))[] res;
      res.length = cast(size_t) size;
      foreach(ref row; res)
        row = makeSlice!E(otherSizes);
      return res;
    }
}

void read(T...)(ref T t)
{
  void basicTypeRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  void iterableRead(W)(ref W w)
  {
    foreach(ref element; w)
      read(element);
  }
  void tupleRead(W)(ref W w)
  {
    static foreach(j; 0 .. W.length)
      read(w[j]);
  }
  void structRead(W)(ref W readStruct)
  {
    static foreach(fieldName; FieldNameTuple!W)
      {
        with(readStruct)
          {
            alias fieldSymbol = mixin(W.stringof, ".", fieldName);
            alias typeOfField = typeof(mixin(fieldName));
            static if (hasUDA!(fieldSymbol, If))
              enum condition = getUDAs!(fieldSymbol, If)[0].condition;
            else
              enum condition = "true";

            if (mixin(condition))
              {
                static if (hasUDA!(fieldSymbol, Dim))
                  {
                    static assert(isDynamicArray!(typeOfField)
                                  , text(W.stringof, ".", fieldName, " has Dim UDA but isn't a Dynamic Array."));
                    enum uda = getUDAs!(fieldSymbol, Dim)[0];
                    static assert(getArrayLevel!(typeOfField) == uda.levels,
                                  text(W.stringof, ".", fieldName, " has a Dim UDA with different number of dimensions than it's type."));
                    mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});
                  }
                else static if (isDynamicArray!typeOfField && !is(typeOfField == string))
                  {
                    pragma(msg, "Warning: You probably want to add dimension to input ", W.stringof, ".", fieldName);
                  }
                read(mixin(fieldName));
              }
          }
      }
  }
  static foreach(i; 0 .. T.length)
    {
      static if (isBasicType!(T[i]) || is(T[i] == string))
        basicTypeRead(t[i]);
      else static if (is(typeof({foreach(ref e; t[i]){}})))
        iterableRead(t[i]);
      else static if (isTuple!(T[i]))
        tupleRead(t[i]);
      else static if (isAggregateType!(T[i]))
        structRead(t[i]);
    }
}

auto next(T)()
{
  T t;
  read(t);
  return t;
}

size_t ind(T)(T t)
{
  return cast(size_t)t;
}

ref auto at(R, I)(ref R r, I i)
{
  return r[cast(size_t)i];
}

void set(R, I, V)(ref R r, I i, V v)
{
  r[cast(size_t)i] = v;
}

import std.conv;
import std.traits;
import std.meta;
int _loglevel = -1;
void _log(string functionName, argSeq...)()
{
  foreach(i; 0 .. _loglevel * 4)
    write(' ');
  write(functionName);
  static foreach(arg; argSeq)
    {
      write(" ", arg.stringof, " = ", arg);
    }
  writeln;
}
enum logCall =
  q{
    debug
    {
     {
     _loglevel++;
     alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, ".").back));
     static if (_parameterTuple.length > 0)
       mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(", ").array, `);`);
     else
       _log!(__FUNCTION__);
      }
     foreach(i; 0 .. _loglevel * 4) write(' ');
     writeln('{');
     scope(exit)
       {
         foreach(i; 0 .. _loglevel * 4) write(' ');
         writeln('}');
         _loglevel--;
       }
    }
};

void logSym(S...)(int line = __LINE__, string file = __FUNCTION__)
{
  debug
    {
      foreach(i; 0 .. _loglevel * 4) write(' ');
      write(file, "(", line, "):");
      static foreach(s; S)
        write(" ", s.stringof, " = ", s);
      writeln;

    }
}

Array!E makeArray(E, S)(S size, lazy E value)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  foreach(ref ai; a)
    ai = value();
  return a;
}
Array!E makeArray(E, S)(S size)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  return a;
}

template mem(alias F)
{
  ReturnType!F[Tuple!(Parameters!F)] table;
  ReturnType!F mem(Parameters!F args)
  {
    return table.require(tuple(args), F(args));
  }
}

string input(string names, string type = "long")
{
  return text(type, " ", names, "; read(", names, ");");
}

auto pmod(T, W)(T t, W w)
{
  return (t%w + w) % w;
}

void rep(S, F)(F f, S times)
{
  static if (is(typeof(f(i))))
    foreach(i; 0 .. times)
      f(i);
  else
    foreach(i; 0 .. times)
      f();
}

void multi()
{
  foreach(tc; 0 .. next!long)
    next!TestCase.solve(tc);
}

void single()
{
  auto tc = next!TestCase;
  tc.solve;
}

void main()
{
  type;
}

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 n = RD!int;
	auto m = RD!int;
	auto sx = RD!int;
	auto sy = RD!int;

	int[][] ans;
	foreach_reverse (y; 1..sy+1)
	{
		ans ~= [sx, y];
	}
	foreach (y; sy+1..m+1)
	{
		ans ~= [sx, y];
	}
	auto x = sx-1;
	auto y = m;
	ans ~= [x, y];
	int dir = -1;
	while (true)
	{
		//debug writeln(x, " ", y);
		y += dir;
		if (y == 0 || y == m+1)
		{
			dir = -dir;
			y += dir;
			--x;
			if (x == 0) break;
		}
		ans ~= [x, y];
	}

	x = sx+1;
	ans ~= [x, y];
	while (true)
	{
		//debug writeln(x, " ", y);
		y += dir;
		if (y == 0 || y == m+1)
		{
			dir = -dir;
			y += dir;
			++x;
			if (x == n+1) break;
		}
		ans ~= [x, y];
	}

	foreach (e; ans)
	{
		writeln(e[0], " ", e[1]);
	}
	stdout.flush;
	debug readln;
}

// Vicfred
// https://codeforces.com/contest/1395/problem/B
// implementation
import std.stdio;

void main() {
    int n, m, sx, sy;
    readf("%s %s %s %s", &n, &m, &sx, &sy);

    writefln("%s %s", sx, sy);

    for(int i = 1; i <= n; i++)
        if(i != sx)
            writefln("%s %s", i, sx);

    for(int i =1; i <= m; i++) {
        if(i == sy)
            continue;
        int direction = i&1;
        if(i > sy)
            direction ^= 1;
        if(direction == 1)
            for(int j = n; j > 0; j--)
                writefln("%s %s", j, i);
        else
            for(int j = 1; j <= n; j++)
                writefln("%s %s", j, i);
    }
}


Let us call two integers $$$x$$$ and $$$y$$$ adjacent if $$$\frac{lcm(x, y)}{gcd(x, y)}$$$ is a perfect square. For example, $$$3$$$ and $$$12$$$ are adjacent, but $$$6$$$ and $$$9$$$ are not.Here $$$gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$, and $$$lcm(x, y)$$$ denotes the least common multiple (LCM) of integers $$$x$$$ and $$$y$$$.You are given an array $$$a$$$ of length $$$n$$$. Each second the following happens: each element $$$a_i$$$ of the array is replaced by the product of all elements of the array (including itself), that are adjacent to the current value. Let $$$d_i$$$ be the number of adjacent elements to $$$a_i$$$ (including $$$a_i$$$ itself). The beauty of the array is defined as $$$\max_{1 \le i \le n} d_i$$$. You are given $$$q$$$ queries: each query is described by an integer $$$w$$$, and you have to output the beauty of the array after $$$w$$$ seconds.

The first input line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the length of the array. The following line contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — array elements.  The next line contain a single integer $$$q$$$ ($$$1 \le q \le 3 \cdot 10^5$$$) — the number of queries. The following $$$q$$$ lines contain a single integer $$$w$$$ each ($$$0 \le w \le 10^{18}$$$) — the queries themselves. It is guaranteed that the sum of values $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$, and the sum of values $$$q$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$

For each query output a single integer — the beauty of the array at the corresponding moment.

NoteIn the first test case, the initial array contains elements $$$[6, 8, 4, 2]$$$. Element $$$a_4=2$$$ in this array is adjacent to $$$a_4=2$$$ (since $$$\frac{lcm(2, 2)}{gcd(2, 2)}=\frac{2}{2}=1=1^2$$$) and $$$a_2=8$$$ (since $$$\frac{lcm(8,2)}{gcd(8, 2)}=\frac{8}{2}=4=2^2$$$). Hence, $$$d_4=2$$$, and this is the maximal possible value $$$d_i$$$ in this array.In the second test case, the initial array contains elements $$$[12, 3, 20, 5, 80, 1]$$$. The elements adjacent to $$$12$$$ are $$$\{12, 3\}$$$, the elements adjacent to $$$3$$$ are $$$\{12, 3\}$$$, the elements adjacent to $$$20$$$ are $$$\{20, 5, 80\}$$$, the elements adjacent to $$$5$$$ are $$$\{20, 5, 80\}$$$, the elements adjacent to $$$80$$$ are $$$\{20, 5, 80\}$$$, the elements adjacent to $$$1$$$ are $$$\{1\}$$$. After one second, the array is transformed into $$$[36, 36, 8000, 8000, 8000, 1]$$$.

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

int [] prepare (int limit)
{
	auto res = limit.iota.array;
	for (int d = 2; d * d < limit; d++)
	{
		if (res[d] == d)
		{
			for (int e = d * d; e < limit; e += d)
			{
				if (res[e] == e)
				{
					res[e] = d;
				}
			}
		}
	}
	return res;
}

int [] roots (int limit)
{
	auto p = prepare (limit);
	auto res = new int [limit];
	foreach (d; 0..limit)
	{
		int cur = d;
		res[d] = 1;
		while (cur > 1)
		{
			bool parity = 0;
			int x = p[cur];
			while (cur % x == 0)
			{
				cur /= x;
				parity ^= 1;
			}
			if (parity)
			{
				res[d] *= x;
			}
		}
	}
	return res;
}

immutable int limit = 10 ^^ 6 + 5;

void main ()
{
	auto r = roots (limit);

	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;

		int [int] nums;
		foreach (ref c; a)
		{
			nums[r[c]] += 1;
		}

		auto answer = [0, 0, 0];
		foreach (step; 0..3)
		{
			debug {writeln (nums);}
			int [int] next;
			foreach (k, v; nums)
			{
				answer[step] = max (answer[step], v);
				int p = (v & 1) ? k : 1;
				next[p] += v;
			}
			nums = next;
		}

		auto q = readln.strip.to !(int);
		foreach (s; 0..q)
		{
			auto z = readln.strip.to !(long);
			writeln (answer[min (z, $ - 1).to !(int)]);
		}
	}
}

import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void get(Args...)(ref Args args)
{
    import std.traits, std.meta, std.typecons;

    static if (Args.length == 1) {
        alias Arg = Args[0];

        static if (isArray!Arg) {
          static if (isSomeChar!(ElementType!Arg)) {
            args[0] = readln.chomp.to!Arg;
          } else {
            args[0] = readln.split.to!Arg;
          }
        } else static if (isTuple!Arg) {
            auto input = readln.split;
            static foreach (i; 0..Fields!Arg.length) {
                args[0][i] = input[i].to!(Fields!Arg[i]);
            }
        } else {
            args[0] = readln.chomp.to!Arg;
        }
    } else {
        auto input = readln.split;
        assert(input.length == Args.length);

        static foreach (i; 0..Args.length) {
            args[i] = input[i].to!(Args[i]);
        }
    }
}

void get_lines(Args...)(size_t N, ref Args args)
{
    import std.traits, std.range;

    static foreach (i; 0..Args.length) {
        static assert(isArray!(Args[i]));
        args[i].length = N;
    }

    foreach (i; 0..N) {
        static if (Args.length == 1) {
            get(args[0][i]);
        } else {
            auto input = readln.split;
            static foreach (j; 0..Args.length) {
                args[j][i] = input[j].to!(ElementType!(Args[j]));
            }
        }
    }
}

enum PCNT = 10^^3;

bool[PCNT+1] PS;

void prime_init()
{
    PS[] = true;
    PS[0] = false;
    PS[1] = false;
    foreach (i; 2..PCNT+1) {
        if (PS[i]) {
            auto x = i*2;
            while (x <= PCNT) {
                PS[x] = false;
                x += i;
            }
        }
    }
}

void main()
{
    prime_init();
    long[] ps;
    foreach (i; 0..PCNT + 1) if (PS[i]) ps ~= i;

    int T; get(T);
    while (T--) {
        int N; get(N);
        long[] AS; get(AS);

        foreach (ref a; AS) foreach (p; ps) while (a % p^^2 == 0) a /= p^^2;
        sort(AS);
        AS ~= -1;
        long last = -1, cnt, one_and_evens, max_r;
        foreach (i, a; AS) {
            if (a != last) {
                max_r = max(max_r, cnt);
                if (last == 1 || cnt % 2 == 0) one_and_evens += cnt;
                cnt = 1;
                last = a;
            } else {
                ++cnt;
            }
        }
        auto r0 = max_r;
        auto r1 = max(max_r, one_and_evens);

        int Q; get(Q);
        while (Q--) {
            long W; get(W);
            writeln(W == 0 ? r0 : r1);
        }
    }
}

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

int [] prepare (int limit)
{
	auto res = limit.iota.array;
	for (int d = 2; d * d < limit; d++)
	{
		if (res[d] == d)
		{
			for (int e = d * d; e < limit; e += d)
			{
				if (res[e] == e)
				{
					res[e] = d;
				}
			}
		}
	}
	return res;
}

int [] roots (int limit)
{
	auto p = prepare (limit);
	auto res = new int [limit];
	foreach (d; 0..limit)
	{
		int cur = d;
		res[d] = 1;
		while (cur > 1)
		{
			bool parity = 0;
			int x = p[cur];
			while (cur % x == 0)
			{
				cur /= x;
				parity ^= 1;
			}
			if (parity)
			{
				res[d] *= x;
			}
		}
	}
	return res;
}

immutable int limit = 10 ^^ 6;

void main ()
{
	auto r = roots (limit);

	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;

		int [int] nums;
		foreach (ref c; a)
		{
			nums[r[c]] += 1;
		}

		auto answer = [0, 0, 0];
		foreach (step; 0..3)
		{
			debug {writeln (nums);}
			int [int] next;
			foreach (k, v; nums)
			{
				answer[step] = max (answer[step], v);
				int p = (v & 1) ? k : 1;
				next[p] += v;
			}
			nums = next;
		}

		auto q = readln.strip.to !(int);
		foreach (s; 0..q)
		{
			auto z = readln.strip.to !(long);
			writeln (answer[min (z, $ - 1).to !(int)]);
		}
	}
}


You are given a positive integer $$$n$$$. Your task is to find any three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$0 \le a, b, c \le 10^9$$$) for which $$$(a\oplus b)+(b\oplus c)+(a\oplus c)=n$$$, or determine that there are no such integers.Here $$$a \oplus b$$$ denotes the bitwise XOR of $$$a$$$ and $$$b$$$. For example, $$$2 \oplus 4 = 6$$$ and $$$3 \oplus 1=2$$$.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following lines contain the descriptions of the test cases. The only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^9$$$).

For each test case, print any three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$0 \le a, b, c \le 10^9$$$) for which $$$(a\oplus b)+(b\oplus c)+(a\oplus c)=n$$$. If no such integers exist, print $$$-1$$$.

NoteIn the first test case, $$$a=3$$$, $$$b=3$$$, $$$c=1$$$, so $$$(3 \oplus 3)+(3 \oplus 1) + (3 \oplus 1)=0+2+2=4$$$.In the second test case, there are no solutions.In the third test case, $$$(2 \oplus 4)+(4 \oplus 6) + (2 \oplus 6)=6+2+4=12$$$.

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

void solve()
{
    auto n = readln.strip.to!int;
    if (n % 2 == 0)
        writefln!("0 0 %s")(n / 2);
    else
        writeln(-1);
}

void main()
{
    size_t TC = 1;
    TC = readln.strip.to!int;
    foreach (_; 0 .. TC)
        solve();
}


While working at DTL, Ela is very aware of her physical and mental health. She started to practice various sports, such as Archery, Yoga, and Football.Since she started engaging in sports activities, Ela switches to trying a new sport on days she considers being "Luxury" days. She counts the days since she started these activities, in which the day she starts is numbered as day $$$1$$$. A "Luxury" day is the day in which the number of this day is a luxurious number. An integer $$$x$$$ is called a luxurious number if it is divisible by $$${\lfloor \sqrt{x} \rfloor}$$$.Here $$$\lfloor r \rfloor$$$ denotes the "floor" of a real number $$$r$$$. In other words, it's the largest integer not greater than $$$r$$$.For example: $$$8$$$, $$$56$$$, $$$100$$$ are luxurious numbers, since $$$8$$$ is divisible by $$$\lfloor \sqrt{8} \rfloor = \lfloor 2.8284 \rfloor = 2$$$, $$$56$$$ is divisible $$$\lfloor \sqrt{56} \rfloor = \lfloor 7.4833 \rfloor = 7$$$, and $$$100$$$ is divisible by $$$\lfloor \sqrt{100} \rfloor = \lfloor 10 \rfloor = 10$$$, respectively. On the other hand $$$5$$$, $$$40$$$ are not, since $$$5$$$ are not divisible by $$$\lfloor \sqrt{5} \rfloor = \lfloor 2.2361 \rfloor = 2$$$, and $$$40$$$ are not divisible by $$$\lfloor \sqrt{40} \rfloor = \lfloor 6.3246 \rfloor = 6$$$.Being a friend of Ela, you want to engage in these fitness activities with her to keep her and yourself accompanied (and have fun together, of course). Between day $$$l$$$ and day $$$r$$$, you want to know how many times she changes the activities.

Each test contains multiple test cases. The first line has the number of test cases $$$t$$$ ($$$1 \le t \le 10\ 000$$$). The description of the test cases follows. The only line of each test case contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^{18}$$$) — the intervals at which you want to know how many times Ela changes her sports.

For each test case, output an integer that denotes the answer.

NoteIn the first test case, $$$5$$$ luxury numbers in range $$$[8, 19]$$$ are: $$$8, 9, 12, 15, 16$$$.

import std.stdio;
import std.container;
import std.typecons;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void solve() {
    long L, R; readf("%d %d\n", &L, &R);

    long sqrt_floor(long x) {
        long lb = 1, ub = 1_000_000_100;
        while (lb + 1 < ub) {
            long mid = (lb + ub) / 2;
            if (mid * mid <= x) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        return lb;
    }

    long C(long x) {
        if (x == 0L) return 0L;
        long d = sqrt_floor(x);
        long s = d * d;
        return (d - 1L) * 3L + (x - s) / d + 1L;
    }

    writeln(C(R) - C(L-1));
}

void main() {
    int T = readln.chomp.to!int;
    foreach (t; 0 .. T) solve();
}

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

long solve (long n)
{
	long x = cast (long) (sqrt (cast (real) (n)));
	long res = x * 3 - 2;
	res += (x * (x + 1) <= n);
	res += (x * (x + 2) <= n);
	return res;
}

long solve (long lo, long hi)
{
	return solve (hi) - solve (lo - 1);
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		long lo, hi;
		readf !(" %s %s") (lo, hi);
		writeln (solve (lo, hi));
	}
}


Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!

The first line of the input contains single integer n n (1 ≤ n ≤ 100) — the number of game rounds. The next n lines contains rounds description. i-th of them contains pair of integers mi and ci (1 ≤ mi,  ci ≤ 6) — values on dice upper face after Mishka's and Chris' throws in i-th round respectively.

If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.

NoteIn the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris.

module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string read_string() {
                while (tokens.empty) {
                tokens = readln.split;
        }
        auto token = tokens.front;
                tokens.popFront;
                return token;
        }

        int read_int() {
                return read_string.to!int;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // int t = cin.read_int;
        while (t--) {
                int n = cin.read_int;
                int c_a = 0;
                int c_b = 0;
                for (int i = 0; i < n; i++) {
                        int a = cin.read_int;
                        int b = cin.read_int;
                        if (a > b) c_a++;
                        if (b > a) c_b++;
                }
                if (c_a > c_b) writeln("Mishka");
                else if (c_b > c_a) writeln("Chris");
                else writeln("Friendship is magic!^^");
        }
}

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

void main() {

	int n = readln.strip.to!int;

	int Mishka, Chris;

	int mM, mC;
	while (n--) {
		readf(" %s %s", &mM, &mC);
		if (mM > mC)
			++Mishka;
		else if (mM < mC)
			++Chris;
	}

	if (Mishka == Chris)
		writeln("Friendship is magic!^^");
	else if (Mishka > Chris)
		writeln("Mishka");
	else
		writeln("Chris");
}

import std.stdio;
import core.stdc.stdio;
import std.math;

string readline()
{
	string res = readln();
	if (res[$-1] == '\n') res.length--;
	return res;
}

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int m, c;
	foreach (int i; 0..n)
	{
		int md, cd;
		scanf("%d %d", &md, &cd);
		if (md > cd)
			m++;
		else if (cd > md)
			c++;
	}
	if (m > c)
	{
		printf("Mishka");
	} else
	if (m == c)
	{
		printf("Friendship is magic!^^");
	} else
	{
		printf("Chris");
	}
	return 0;
}

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

int mishkaKacKereKazandi = 0;
int chrisKacKereKazandi = 0;

void zarlariKarsilastir( int mishkaninZari, int  chrisinZari )
{
	if ( mishkaninZari > chrisinZari )
		mishkaKacKereKazandi++;
	else if ( chrisinZari > mishkaninZari )
		chrisKacKereKazandi++;
}

void main() {

    auto satirSayisi = stdin.readln.strip.to!int();

    auto zarlarDizisi = stdin
		.byLine()
		.take(satirSayisi)
		.map!(line => line
			  .split
			  .map!(a => to!int(a))
			  .array());

    zarlarDizisi.each!( a=> zarlariKarsilastir(a[0], a[1]) );

	if ( mishkaKacKereKazandi > chrisKacKereKazandi )
		writeln("Mishka");
	else if ( mishkaKacKereKazandi == chrisKacKereKazandi )
		writeln("Friendship is magic!^^");
	else
		writeln( "Chris" );
}

import std.stdio;

int main()
{
	int a=0;
	readf(" %d", &a);
	int d=0;
	int e=0;
	for (int i=0; i<a; i++)
	{
		int b=0;
		int c=0;
		readf(" %d", &b);
		readf(" %d", &c);
		if (b>c)
		{
			d=d+1;
		}
		if (c>b)
		{
			e=e+1;
		}
	}
	if (d>e)
	{
		writeln("Mishka");
	}
	else if (e>d)
	{
		writeln("Chris");
	}
	else
	{
		writeln("Friendship is magic!^^");
	}
	return 0;
}

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

int mishkaKacKereKazandi = 0;

void zarlariKarsilastir( int mishkaninZari, int  chrisinZari )
{
	if ( mishkaninZari > chrisinZari )
		mishkaKacKereKazandi++;
}

void main() {

    auto satirSayisi = stdin.readln.strip.to!int();

    auto zarlarDizisi = stdin
		.byLine()
		.take(satirSayisi)
		.map!(line => line
			  .split
			  .map!(a => to!int(a))
			  .array());

    zarlarDizisi.each!( a=> zarlariKarsilastir(a[0], a[1]) );

	if ( mishkaKacKereKazandi > satirSayisi/2 )
		writeln("Mishka");
	else if ( mishkaKacKereKazandi == satirSayisi/2 )
		writeln("Friendship is magic!^^");
	else
		writeln( "Chris" );
}


DZY loves Fast Fourier Transformation, and he enjoys using it.Fast Fourier Transformation is an algorithm used to calculate convolution. Specifically, if a, b and c are sequences with length n, which are indexed from 0 to n - 1, andWe can calculate c fast using Fast Fourier Transformation.DZY made a little change on this formula. NowTo make things easier, a is a permutation of integers from 1 to n, and b is a sequence only containing 0 and 1. Given a and b, DZY needs your help to calculate c.Because he is naughty, DZY provides a special way to get a and b. What you need is only three integers n, d, x. After getting them, use the code below to generate a and b.//x is 64-bit variable;function getNextX() {    x = (x * 37 + 10007) % 1000000007;    return x;}function initAB() {    for(i = 0; i < n; i = i + 1){        a[i] = i + 1;    }    for(i = 0; i < n; i = i + 1){        swap(a[i], a[getNextX() % (i + 1)]);    }    for(i = 0; i < n; i = i + 1){        if (i < d)            b[i] = 1;        else            b[i] = 0;    }    for(i = 0; i < n; i = i + 1){        swap(b[i], b[getNextX() % (i + 1)]);    }}Operation x % y denotes remainder after division x by y. Function swap(x, y) swaps two values x and y.

The only line of input contains three space-separated integers n, d, x (1 ≤ d ≤ n ≤ 100000; 0 ≤ x ≤ 1000000006). Because DZY is naughty, x can't be equal to 27777500.

Output n lines, the i-th line should contain an integer ci - 1.

NoteIn the first sample, a is [1 3 2], b is [1 0 0], so c0 = max(1·1) = 1, c1 = max(1·0, 3·1) = 3, c2 = max(1·0, 3·0, 2·1) = 2.In the second sample, a is [2 1 4 5 3], b is [1 1 1 0 1].In the third sample, a is [5 2 1 4 3], b is [1 1 1 1 0].

import core.thread;
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;

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

//	chmin/chmax
void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(    const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; }
}
auto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

class Generator {
	int n;
	int d;
	long x;
	int[] a, b;
	this(int n, int d, long x) {
		this.n = n;
		this.d = d;
		this.x = x;
		a = new int[n];
		b = new int[n];
	}
	//x is 64-bit variable;
	long getNextX() {
		x = (x * 37 + 10007) % 1000000007;
		return x;
	}
	void initAB() {
		int i;
		for(i = 0; i < n; i = i + 1){
			a[i] = i + 1;
		}
		for(i = 0; i < n; i = i + 1){
			swap(a[i], a[cast(size_t)(getNextX() % (i + 1))]);
		}
		for(i = 0; i < n; i = i + 1){
			if (i < d)
				b[i] = 1;
			else
				b[i] = 0;
		}
		for(i = 0; i < n; i = i + 1){
			swap(b[i], b[cast(size_t)(getNextX() % (i + 1))]);
		}
	}
}

immutable NUM_BIG = 1000;

int N, D;
long X;
int[] A, B;

void main(string[] args) {
	try {
	for (; ; ) {
		N = readInt;
		D = readInt;
		X = readLong;
		auto gen = new Generator(N, D, X);
		gen.initAB;
		A = gen.a;
		B = gen.b;
debug{
writeln("A = ",A);
writeln("B = ",B);
}

		int[] js;
		foreach (j; 0 .. N) if (B[j]) {
			js ~= j;
		}

		int[] ans = new int[N];
		foreach (i; 0 .. N) if (A[i] >= N - NUM_BIG) {
			foreach (j; js) {
				if (i + j >= N) {
					break;
				}
				chmax(ans[i + j], A[i]);
			}
		}

		foreach (k; 0 .. N) if (!ans[k]) {
			foreach (j; js) {
				if (j > k) {
					break;
				}
				chmax(ans[k], A[k - j]);
			}
		}

		foreach (k; 0 .. N) {
			writeln(ans[k]);
		}
	}
	} catch (EOFException) {}
}


You are given some Tetris field consisting of $$$n$$$ columns. The initial height of the $$$i$$$-th column of the field is $$$a_i$$$ blocks. On top of these columns you can place only figures of size $$$2 \times 1$$$ (i.e. the height of this figure is $$$2$$$ blocks and the width of this figure is $$$1$$$ block). Note that you cannot rotate these figures.Your task is to say if you can clear the whole field by placing such figures.More formally, the problem can be described like this:The following process occurs while at least one $$$a_i$$$ is greater than $$$0$$$:  You place one figure $$$2 \times 1$$$ (choose some $$$i$$$ from $$$1$$$ to $$$n$$$ and replace $$$a_i$$$ with $$$a_i + 2$$$);  then, while all $$$a_i$$$ are greater than zero, replace each $$$a_i$$$ with $$$a_i - 1$$$. And your task is to determine if it is possible to clear the whole field (i.e. finish the described process), choosing the places for new figures properly.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. The next $$$2t$$$ lines describe test cases. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of columns in the Tetris field. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the initial height of the $$$i$$$-th column of the Tetris field.

For each test case, print the answer — "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise.

NoteThe first test case of the example field is shown below:Gray lines are bounds of the Tetris field. Note that the field has no upper bound.One of the correct answers is to first place the figure in the first column. Then after the second step of the process, the field becomes $$$[2, 0, 2]$$$. Then place the figure in the second column and after the second step of the process, the field becomes $$$[0, 0, 0]$$$.And the second test case of the example field is shown below:It can be shown that you cannot do anything to end the process.In the third test case of the example, you first place the figure in the second column after the second step of the process, the field becomes $$$[0, 2]$$$. Then place the figure in the first column and after the second step of the process, the field becomes $$$[0, 0]$$$.In the fourth test case of the example, place the figure in the first column, then the field becomes $$$[102]$$$ after the first step of the process, and then the field becomes $$$[0]$$$ after the second step of the process.

import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        readln;
        auto as = readln.split.to!(int[]);
        auto x = as[0]%2;
        foreach (a; as) if (x != a%2) goto ng;
        writeln("YES");
        continue;
        ng:
        writeln("NO");
    }
}

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 = 998244353;
//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 bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;
		auto last = a[0] % 2;
		ans[ti] = true;
		foreach (e; a[1..$])
		{
			if (e % 2 != last)
				ans[ti] = false;
		}
	}

	foreach (e; ans)
		writeln(e ? "YES" : "NO");
	stdout.flush;
	debug readln;
}


An L-shape is a figure on gridded paper that looks like the first four pictures below. An L-shape contains exactly three shaded cells (denoted by *), which can be rotated in any way.  You are given a rectangular grid. Determine if it contains L-shapes only, where L-shapes can't touch an edge or corner. More formally:   Each shaded cell in the grid is part of exactly one L-shape, and  no two L-shapes are adjacent by edge or corner. For example, the last two grids in the picture above do not satisfy the condition because the two L-shapes touch by corner and edge, respectively.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 50$$$) — the number of rows and columns in the grid, respectively. Then $$$n$$$ lines follow, each containing $$$m$$$ characters. Each of these characters is either '.' or '*' — an empty cell or a shaded cell, respectively.

For each test case, output "YES" if the grid is made up of L-shape that don't share edges or corners, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

import std.stdio;
import std.typecons;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void solve() {
    int H, W; readf("%d %d\n", &H, &W);
    auto F = iota(0, H).map!((x) => readln.chomp).array;

    bool lshape(int y, int x) {
        int count = 0;
        for (int i = y; i <= y + 1; i++) {
            for (int j = x; j <= x + 1; j++) {
                if (F[i][j] == '*') count++;
            }
        }
        return count == 3;
    }
    bool check(int y, int x) {
        int count = 0;
        for (int i = max(0, y - 1); i <= min(H - 1, y + 1); i++) {
            for (int j = max(0, x - 1); j <= min(W - 1, x + 1); j++) {
                if (F[i][j] == '*') count++;
            }
        }
        return count == 3;
    }
    bool check_all() {
        auto C = new int[][](H, W);
        for (int y = 0; y + 1 < H; y++) {
            for (int x = 0; x + 1 < W; x++) {
                if (lshape(y, x)) {
                    for (int dy = 0; dy <= 1; dy++) for (int dx = 0; dx <= 1; dx++) {
                        C[y + dy][x + dx]++;
                    }
                }
            }
        }
        for (int y = 0; y < H; y++) for (int x = 0; x < W; x++) {
            if (C[y][x] >= 2) return false;
            if (F[y][x] == '*') {
                if (C[y][x] == 0) return false;
                if (! check(y, x)) return false;
            }
        }
        return true;
    }
    writeln(check_all() ? "Yes" : "No");
}

void main() {
    int T = readln.chomp.to!int;
    foreach (t; 0 .. T) {
        solve();
    }
}

import std.stdio;
import std.typecons;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void solve() {
    int H, W; readf("%d %d\n", &H, &W);
    auto F = iota(0, H).map!((x) => readln.chomp).array;

    bool check(int y, int x) {
        int ycount = 0, xcount = 0;
        for (int i = max(0, y - 1); i <= min(H - 1, y + 1); i++) {
            if (F[i][x] == '*') ycount++;
        }
        for (int j = max(0, x - 1); j <= min(W - 1, x + 1); j++) {
            if (F[y][j] == '*') xcount++;
        }
        if (! (ycount == 2 || xcount == 2)) return false;
        int count = 0;
        for (int i = max(0, y - 1); i <= min(H - 1, y + 1); i++) {
            for (int j = max(0, x - 1); j <= min(W - 1, x + 1); j++) {
                if (F[i][j] == '*') count++;
            }
        }
        return count == 3;
    }
    bool check_all() {
        for (int y = 0; y < H; y++) {
            for (int x = 0; x < W; x++) {
                if (F[y][x] == '*' && !check(y, x)) {
                    return false;
                }
            }
        }
        return true;
    }
    writeln(check_all() ? "Yes" : "No");
}

void main() {
    int T = readln.chomp.to!int;
    foreach (t; 0 .. T) {
        solve();
    }
}

import std.stdio;
import std.typecons;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void solve() {
    int H, W; readf("%d %d\n", &H, &W);
    auto F = iota(0, H).map!((x) => readln.chomp).array;

    bool check(int y, int x) {
        int count = 0;
        for (int i = max(0, y - 1); i <= min(H - 1, y + 1); i++) {
            for (int j = max(0, x - 1); j <= min(W - 1, x + 1); j++) {
                if (F[i][j] == '*') count++;
            }
        }
        return count == 3;
    }
    bool check_all() {
        for (int y = 0; y < H; y++) {
            for (int x = 0; x < W; x++) {
                if (F[y][x] == '*' && !check(y, x)) {
                    return false;
                }
            }
        }
        return true;
    }
    writeln(check_all() ? "Yes" : "No");
}

void main() {
    int T = readln.chomp.to!int;
    foreach (t; 0 .. T) {
        solve();
    }
}


Vus the Cossack has $$$n$$$ real numbers $$$a_i$$$. It is known that the sum of all numbers is equal to $$$0$$$. He wants to choose a sequence $$$b$$$ the size of which is $$$n$$$ such that the sum of all numbers is $$$0$$$ and each $$$b_i$$$ is either $$$\lfloor a_i \rfloor$$$ or $$$\lceil a_i \rceil$$$. In other words, $$$b_i$$$ equals $$$a_i$$$ rounded up or down. It is not necessary to round to the nearest integer.For example, if $$$a = [4.58413, 1.22491, -2.10517, -3.70387]$$$, then $$$b$$$ can be equal, for example, to $$$[4, 2, -2, -4]$$$. Note that if $$$a_i$$$ is an integer, then there is no difference between $$$\lfloor a_i \rfloor$$$ and $$$\lceil a_i \rceil$$$, $$$b_i$$$ will always be equal to $$$a_i$$$.Help Vus the Cossack find such sequence!

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of numbers. Each of the next $$$n$$$ lines contains one real number $$$a_i$$$ ($$$|a_i| < 10^5$$$). It is guaranteed that each $$$a_i$$$ has exactly $$$5$$$ digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to $$$0$$$.

In each of the next $$$n$$$ lines, print one integer $$$b_i$$$. For each $$$i$$$, $$$|a_i-b_i|<1$$$ must be met. If there are multiple answers, print any.

NoteThe first example is explained in the legend.In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.

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; }
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 = 998244353;
//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 n = RD!int;
	auto a = new double[](n);
	auto ans = new long[](n);
	long diff;
	foreach (i; 0..n)
	{
		a[i]   = RD!double;
		ans[i] = cast(long)a[i];
		diff  += ans[i];
	}

	diff = -diff;
	foreach (i; 0..n)
	{
		if (diff == 0) break;
		if (a[i] == ans[i]) continue;

		if (sgn(a[i]) == sgn(diff))
		{
			ans[i] += sgn(diff);
			diff   -= sgn(diff);
		}
	}

	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.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; }
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 = 998244353;
//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 n = RD!int;
	auto a = new double[](n);
	auto ans = new long[](n);
	long diff;
	foreach (i; 0..n)
	{
		a[i]   = RD!double;
		ans[i] = cast(long)a[i];
		diff  += ans[i];
	}

	diff = -diff;
	foreach (i; 0..n)
	{
		if (diff == 0) break;

		if (sgn(a[i]) == sgn(diff))
		{
			ans[i] += sgn(diff);
			diff   -= sgn(diff);
		}
	}

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


There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos.The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible.

The first line contains a single integer — n (1 ≤ n ≤ 5·105). Each of the next n lines contains an integer si — the size of the i-th kangaroo (1 ≤ si ≤ 105).

Output a single integer — the optimal number of visible kangaroos.

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 = 100_005;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto c = new int [MAX_N + 1];
		c[] = 0;
		foreach (i; 0..n)
		{
			int x;
			readf (" %s", &x);
			c[x]++;
		}
		int [] a;
		foreach (k, b; c)
		{
			foreach (i; 0..b)
			{
				a ~= k;
			}
		}
		enforce (a.length == n);
		debug {writeln (a);}

		bool check (int me)
		{
			foreach (i; 0..me)
			{
				debug {writeln ("compare ", i,
				       " ", n - me + i);}
				if (a[i] * 2 > a[n - me + i])
				{
					return false;
				}
			}
			return true;
		}

		int lo = 0;
		int hi = n >> 1;
		while (lo < hi)
		{
			int me = (lo + hi + 1) >> 1;
			debug {writeln (lo, ' ', hi, ' ', me);}
			if (check (me))
			{
				lo = me;
			}
			else
			{
				hi = me - 1;
			}
		}
		writeln (n - lo);
	}
}

#!/usr/bin/env rdmd
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;

void main()
{
    for(string S; (S=readln().chomp()).length; )
    {
        auto n = S.to!int();
        auto s = new int[n];
        foreach(i;0..n)
            s[i] = readln().chomp().to!int();
        s.sort;
        int c = 0;
        int p = n/2;
        foreach(i;0..n/2)
        {
            auto v = s[i]*2;
            for( ; p<n; ++p)
            {
                if(v<=s[p])
                {
                    ++c;
                    ++p;
                    break;
                }
            }
        }
        writeln(n-c);
    }
}

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 = 100_005;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto c = new int [MAX_N + 1];
		c[] = 0;
		foreach (i; 0..n)
		{
			int x;
			readf (" %s", &x);
			c[x]++;
		}
		int j = 0;
		int res = 0;
		foreach (i; 0..MAX_N)
		{
			j = max (j, i << 1);
			j = min (j, MAX_N);
			while (c[i] > 0)
			{
				while (j < MAX_N && c[j] == 0)
				{
					j++;
				}
				if (c[j] == 0)
				{
					break;
				}
				c[i]--;
				c[j]--;
				res++;
			}
			res += c[i];
		}
		writeln (res);
	}
}

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 = 100_005;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto c = new int [MAX_N];
		c[] = 0;
		foreach (i; 0..n)
		{
			int x;
			readf (" %s", &x);
			c[x]++;
		}
		int j = MAX_N;
		int res = 0;
		foreach_reverse (i; 0..MAX_N)
		{
			j = min (j, i >> 1);
			while (c[i] > 0)
			{
				while (j > 0 && c[j] == 0)
				{
					j--;
				}
				if (c[j] == 0)
				{
					break;
				}
				c[i]--;
				c[j]--;
				res++;
			}
			res += c[i];
		}
		writeln (res);
	}
}

#!/usr/bin/env rdmd
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;

void main()
{
    for(string S; (S=readln().chomp()).length; )
    {
        auto n = S.to!int();
        auto s = new int[n];
        foreach(i;0..n)
            s[i] = readln().chomp().to!int();
        s.sort;
        auto u = new bool[n];
        auto c = n;
        int p = n;
        foreach_reverse(i;1..n)
        {
            auto v = s[i]/2;
            if(!u[i])
            {
                p=min(p,i-1);
                for( ; p>=0; --p)
                {
                    if(v>=s[p])
                    {
                        u[p]=true;
                        --c;
                        --p;
                        break;
                    }
                }
            }

        }
        writeln(c);
    }
}

#!/usr/bin/env rdmd
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;

void main()
{
    for(string S; (S=readln().chomp()).length; )
    {
        auto n = S.to!int();
        auto s = new int[n];
        foreach(i;0..n)
            s[i] = readln().chomp().to!int();
        s.sort;
        auto u = new bool[n];
        auto c = n;
        int p = n;
        foreach_reverse(i;1..n)
        {
            auto v = s[i];
            if(!u[i])
            {
                p=min(p,i-1);
                for( ; p>=0; --p)
                {
                    if(v>s[p]*2)
                    {
                        u[p]=true;
                        --c;
                        --p;
                        break;
                    }
                }
            }

        }
        writeln(c);
    }
}

#!/usr/bin/env rdmd
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;

void main()
{
    for(string S; (S=readln().chomp()).length; )
    {
        auto n = S.to!int();
        auto s = new int[n];
        foreach(i;0..n)
            s[i] = readln().chomp().to!int();
        s.sort;
        auto u = new bool[n];
        auto c = n;
        int p = n-2;
        foreach_reverse(i;1..n)
        {
            auto v = s[i]/2;
            if(!u[i])
            {
                for( ; p>=0; --p)
                {
                    if(v>=s[p])
                    {
                        u[p]=true;
                        --c;
                        --p;
                        break;
                    }
                }
            }

        }
        writeln(c);
    }
}


The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold:  the first letter of $$$a$$$ is less than the first letter of $$$b$$$;  the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that:  Word $$$1$$$: ab  Word $$$2$$$: ac  ...  Word $$$25$$$: az  Word $$$26$$$: ba  Word $$$27$$$: bc  ...  Word $$$649$$$: zx  Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).

For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.

void main() { runSolver(); }

void problem() {
  auto QN = scan!int;

  auto solve() {
    int[string] dict;
    int dictSize;
    foreach(dchar c; 'a'..'z' + 1) foreach(dchar d; 'a'..'z' + 1) {
      if (c == d) continue;

      dictSize++;
      dict[[c, d].to!string] = dictSize;
    }

    auto subSolve() {
      auto S = scan;
      return dict[S];
    }

    foreach(i; 0..QN) {
      subSolve().writeln;
    }
  }

  outputForAtCoder(&solve);
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

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


You are given an array $$$a$$$ of $$$2n$$$ distinct integers. You want to arrange the elements of the array in a circle such that no element is equal to the the arithmetic mean of its $$$2$$$ neighbours.More formally, find an array $$$b$$$, such that: $$$b$$$ is a permutation of $$$a$$$.For every $$$i$$$ from $$$1$$$ to $$$2n$$$, $$$b_i \neq \frac{b_{i-1}+b_{i+1}}{2}$$$, where $$$b_0 = b_{2n}$$$ and $$$b_{2n+1} = b_1$$$. It can be proved that under the constraints of this problem, such array $$$b$$$ always exists.

The first line of input contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of testcases. The description of testcases follows. The first line of each testcase contains a single integer $$$n$$$ $$$(1 \leq n \leq 25)$$$. The second line of each testcase contains $$$2n$$$ integers $$$a_1, a_2, \ldots, a_{2n}$$$ $$$(1 \leq a_i \leq 10^9)$$$ — elements of the array. Note that there is no limit to the sum of $$$n$$$ over all testcases.

For each testcase, you should output $$$2n$$$ integers, $$$b_1, b_2, \ldots b_{2n}$$$, for which the conditions from the statement are satisfied.

// Vicfred
// https://codeforces.com/contest/1526/problem/A
//
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    int t = readln.chomp.to!int;

while(t--) {
    int n = readln.chomp.to!int;

    long[] a = readln.split.map!(to!long).array;
    a.sort;
    for(int i = 0; i < n; ++i) {
        writef("%s %s ", a[i], a[i + n]);
    } "".writeln;
}
}

import std.algorithm, std.array, std.container, std.conv, std.math, std.range, std.stdio, std.string;

void main() {
    foreach(t; 0 .. to!int(readln.strip)) {
        int n = to!int(readln.strip);
        auto ar = readln.split.map!(to!int).array.sort;
        auto r1 = ar[0 .. n], r2 = ar[n .. $];
        foreach(i; 0 .. n) {
            write(r1[i]," ",r2[i]," ");
        }
        writeln();
    }
}

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

bool check(long[] a)
{
  for (int i = 0; i < a.length; i++) {
    int left = (cast(int)(a.length) + i - 1) % cast(int)(a.length);
    int right = (cast(int)(a.length) + i + 1) % cast(int)(a.length);
    if (a[left] + a[right] == 2 * a[i])
      return false;
  }
  return true;
}

void main()
{
  int t;
  readf!" %d "(t);

  foreach (casenum ; 0 .. t) {
    int n;
    readf!" %d "(n);
    auto a = readln.chomp.split.map!(to!long).array;
    long[] b;
    while (true) {
      b = a.randomShuffle;
      if (check(b))
        break;
    }
    writeln(b.map!text.joiner(" "));
  }
}

import std.stdio;
import std.ascii;
import std.algorithm;
import core.stdc.stdio;

int main()
{
    int t = readInt!int;
    while (t--)
    {
        int n = readInt!int;
        auto a = new int[](2 * n);
        foreach(ref ai; a)
            ai = readInt!int;
        sort(a);
        debug writeln(a);
        auto low = a[0 .. n];
        auto high = a[n .. $];
        foreach(i; 0 .. n)
        {
            write(low[i], " ", high[i], " ");
        }
        writeln;
    }
    return 0;
}

/* INPUT ROUTINES */
int currChar;
static this()
{
    currChar = getchar();
}
char topChar()
{
    return cast(char) currChar;
}
void popChar()
{
    currChar = getchar();
}
auto readInt(T)()
{
    T num = 0;
    int sgn = 0;
    while (topChar.isWhite) popChar;
    while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }
    while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }
    if (sgn) return -num; return num;
}
string readString()
{
    string res = "";
    while (topChar.isWhite) popChar;
    while (!topChar.isWhite) { res ~= topChar; popChar; }
    return res;
}

// Vicfred
// https://codeforces.com/contest/1526/problem/A
//
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    int t = readln.chomp.to!int;

while(t--) {
    int n = readln.chomp.to!int;

    long[] a = readln.split.map!(to!long).array;
    for(int i = 0; i < n; ++i) {
        writef("%s %s ", a[i], a[i + n]);
    } "".writeln;
}
}


You have three piles of candies: red, green and blue candies:  the first pile contains only red candies and there are $$$r$$$ candies in it,  the second pile contains only green candies and there are $$$g$$$ candies in it,  the third pile contains only blue candies and there are $$$b$$$ candies in it. Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.

The first line contains integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is given as a separate line of the input. It contains three integers $$$r$$$, $$$g$$$ and $$$b$$$ ($$$1 \le r, g, b \le 10^8$$$) — the number of red, green and blue candies, respectively.

Print $$$t$$$ integers: the $$$i$$$-th printed integer is the answer on the $$$i$$$-th test case in the input.

NoteIn the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.

import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      {
	static foreach(n; 0 .. T[i].Types.length)
	  {
	    read(args[i][n]);
	  }
      }
    else
      readf!" %s "(args[i]);
}
auto brange(alias low, alias high, alias pred, bool value)()
{
  return iota(low, high + 1).map!((a) => cast(int) pred(a)).assumeSorted.equalRange(value);
}
auto ftrue(alias low, alias high, alias pred)()
{
  return brange!(low, high, pred, false).length + low;
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t;
      get(t);
      F(t);
    }
}
alias get = read;
alias w = writeln;

int main()
{
  int t;
  get(t);
  while(t--)
    {
      long[] c = new long[3];
      get(c);
      sort(c);
      long res = 0;
      long d = c[1] - c[0];
      res += d;
      c[1] -= d;
      c[2] -= d;
      auto a = c[0];
      auto b = c[2];
      d = min(a, b - a);
      a -= d;
      b -= 2 * d;
      res += 2 * d;
      res += 3 * (a / 2) + (a % 2);
      w(res);
    }
  return 0;
}

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

void main ()
{
	int tests;
	readf !(" %s") (tests);
	readln;
	foreach (test; 0..tests)
	{
		auto a = readln.splitter.map !(to !(int)).array;
		sort (a);
		writeln (min (a[0] + a[1], sum (a) / 2));
	}
}

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 rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.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;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
	int t = rint;
	foreach(_; 0 .. t){
		long a = rlong, b = rlong, c = rlong;
		long ans = min((a + b + c) / 2, a + b, b + c, c + a);
		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 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; }

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 = 998244353;
//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 t = RD!int;
	auto ans = new long[](t);
	foreach (i; 0..t)
	{
		auto r = RD;
		auto g = RD;
		auto b = RD;
		auto arr = [r, g, b];
		arr.sort();
		auto d = min(arr[2] - arr[1], arr[0]);
		ans[i] += d;
		arr[2] -= d;
		arr[0] -= d;
		ans[i] += arr[0] - arr[0] % 2;
		ans[i] += arr[1] - arr[0] / 2;
	}

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


It is given a positive integer $$$n$$$. In $$$1$$$ move, one can select any single digit and remove it (i.e. one selects some position in the number and removes the digit located at this position). The operation cannot be performed if only one digit remains. If the resulting number contains leading zeroes, they are automatically removed.E.g. if one removes from the number $$$32925$$$ the $$$3$$$-rd digit, the resulting number will be $$$3225$$$. If one removes from the number $$$20099050$$$ the first digit, the resulting number will be $$$99050$$$ (the $$$2$$$ zeroes going next to the first digit are automatically removed).What is the minimum number of steps to get a number such that it is divisible by $$$25$$$ and positive? It is guaranteed that, for each $$$n$$$ occurring in the input, the answer exists. It is guaranteed that the number $$$n$$$ has no leading zeros.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing one integer $$$n$$$ ($$$25 \le n \le 10^{18}$$$). It is guaranteed that, for each $$$n$$$ occurring in the input, the answer exists. It is guaranteed that the number $$$n$$$ has no leading zeros.

For each test case output on a separate line an integer $$$k$$$ ($$$k \ge 0$$$) — the minimum number of steps to get a number such that it is divisible by $$$25$$$ and positive.

NoteIn the first test case, it is already given a number divisible by $$$25$$$.In the second test case, we can remove the digits $$$1$$$, $$$3$$$, and $$$4$$$ to get the number $$$75$$$.In the third test case, it's enough to remove the last digit to get the number $$$325$$$.In the fourth test case, we can remove the three last digits to get the number $$$50$$$.In the fifth test case, it's enough to remove the digits $$$4$$$ and $$$7$$$.

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

void main()
{
    int t;
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        auto str = readln.strip;
        int zero_cnt, five_cnt;
        bool zero_f = false, five_f = false;
        for(int i = cast (int) str.length - 1; i > 0; i--)
        {
            if (str[i] == '0')
            {
                int j = i - 1;
                while((str[j] != '0') && (str[j] != '5') && (!zero_f))
                {
                    zero_cnt++;
                    j--;
                    if (j == -1)
                        break;
                }
                if (j >= 0)
                    zero_f = true;
                if (!five_f)
                    five_cnt++;
            }
            else if (str[i] == '5')
            {
                int j = i - 1;
                while((str[j] != '2') && (str[j] != '7') && (!five_f))
                {
                    five_cnt++;
                    j--;
                    if (j == -1)
                        break;

                }
                if (j >= 0)
                    five_f = true;
                if (!zero_f)
                    zero_cnt++;
            }
            else
            {
                if (!zero_f)
                    zero_cnt++;
                if (!five_f)
                    five_cnt++;
            }
        }
        writeln(min(zero_cnt, five_cnt));
    }
}