You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.Initially, you have an integer $$$x = 0$$$. During one move, you can do one of the following two operations:  Choose exactly one $$$i$$$ from $$$1$$$ to $$$n$$$ and increase $$$a_i$$$ by $$$x$$$ ($$$a_i := a_i + x$$$), then increase $$$x$$$ by $$$1$$$ ($$$x := x + 1$$$).  Just increase $$$x$$$ by $$$1$$$ ($$$x := x + 1$$$). The first operation can be applied no more than once to each $$$i$$$ from $$$1$$$ to $$$n$$$.Your task is to find the minimum number of moves required to obtain such an array that each its element is divisible by $$$k$$$ (the value $$$k$$$ is given).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 two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$$$) — the length of $$$a$$$ and the required divisior. The second line of the test case contains $$$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 $$$a$$$. It is guaranteed that the sum of $$$n$$$ does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer — the minimum number of moves required to obtain such an array that each its element is divisible by $$$k$$$.

NoteConsider the first test case of the example:  $$$x=0$$$, $$$a = [1, 2, 1, 3]$$$. Just increase $$$x$$$;  $$$x=1$$$, $$$a = [1, 2, 1, 3]$$$. Add $$$x$$$ to the second element and increase $$$x$$$;  $$$x=2$$$, $$$a = [1, 3, 1, 3]$$$. Add $$$x$$$ to the third element and increase $$$x$$$;  $$$x=3$$$, $$$a = [1, 3, 3, 3]$$$. Add $$$x$$$ to the fourth element and increase $$$x$$$;  $$$x=4$$$, $$$a = [1, 3, 3, 6]$$$. Just increase $$$x$$$;  $$$x=5$$$, $$$a = [1, 3, 3, 6]$$$. Add $$$x$$$ to the first element and increase $$$x$$$;  $$$x=6$$$, $$$a = [6, 3, 3, 6]$$$. We obtained the required array. Note that you can't add $$$x$$$ to the same element more than once.

import std.stdio;
import std.string : split, strip;
import std.conv : to;
import std.algorithm : map;
import std.array;

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

  foreach (i; 0..t) {
    int n;
    long k;
    readf!"%d %d\n"(n, k);

    auto a = readln.strip.split.map!(to!long);
    auto d = a.map!(a => a % k == 0 ? 0 : k - a % k);

    int[long] f;
    foreach (e; d) {
      f[e]++;
    }
    f.remove(0);

    long m = 0;
    int c;
    foreach (key, occ; f) {
      if (m == 0 || occ > c || (occ == c && key > m)) {
        m = key;
        c = occ;
      }
    }

    if (m == 0) {
      writeln(0);
    } else {
      writeln(k * (c - 1) + m + 1);
    }
  }
}

import std.algorithm, std.conv, std.stdio;
void main () {
	readln;
	int n, k;
	while (readf !(" %s %s") (n, k) > 0) {
		readln;
		int [int] b;
		readln.splitter.map !(to !(int)).filter !(x => x % k > 0).map !(x => k - x % k).each !(x => b[x + 1] += 1);
		b.byKeyValue.map !(s => s.key + k * (s.value - 1L)).maxElement (0L).writeln;
	}
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		readln;
		int [int] b;
		readln.splitter.map !(to !(int)).filter !(x => x % k > 0)
		    .map !(x => k - x % k).each !(x => b[x + 1] += 1);
		b.byKeyValue.map !(s => s.key + k * (s.value - 1L))
		    .maxElement (0L).writeln;
	}
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		a[] = (k - a[] % k) % k;
		sort (a);
		long res = 0;
		long cur = 0;
		foreach (i; 0..n)
		{
			if (i > 0 && a[i] == a[i - 1])
			{
				cur += k;
			}
			else
			{
				cur = 0;
			}
			if (a[i] > 0)
			{
				res = max (res, cur + a[i] + 1);
			}
		}
		writeln (res);
	}
}

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 = multi;
struct TestCase
{
  mixin prettyPrinting;

  long n, k;
  @Dim("n") long[] a;

  void solve(long tc = -1)
  {
    long[long] cnt;
    foreach(ai; a)
      if (ai % k != 0)
      {
        cnt.require((-ai%k + k)%k, 0)++;
      }
    if (cnt.length == 0)
      {
        writeln(0);
        return;
      }
    long ops = 0;
    foreach(m, c; cnt)
      {
        ops = max(ops, m + (c - 1) * k);
      }
    writeln(ops + 1);
  }
}

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;
}


The Central Company has an office with a sophisticated security system. There are $$$10^6$$$ employees, numbered from $$$1$$$ to $$$10^6$$$.The security system logs entrances and departures. The entrance of the $$$i$$$-th employee is denoted by the integer $$$i$$$, while the departure of the $$$i$$$-th employee is denoted by the integer $$$-i$$$.The company has some strict rules about access to its office:  An employee can enter the office at most once per day.  He obviously can't leave the office if he didn't enter it earlier that day.  In the beginning and at the end of every day, the office is empty (employees can't stay at night). It may also be empty at any moment of the day. Any array of events satisfying these conditions is called a valid day.Some examples of valid or invalid days:  $$$[1, 7, -7, 3, -1, -3]$$$ is a valid day ($$$1$$$ enters, $$$7$$$ enters, $$$7$$$ leaves, $$$3$$$ enters, $$$1$$$ leaves, $$$3$$$ leaves).  $$$[2, -2, 3, -3]$$$ is also a valid day.  $$$[2, 5, -5, 5, -5, -2]$$$ is not a valid day, because $$$5$$$ entered the office twice during the same day.  $$$[-4, 4]$$$ is not a valid day, because $$$4$$$ left the office without being in it.  $$$[4]$$$ is not a valid day, because $$$4$$$ entered the office and didn't leave it before the end of the day. There are $$$n$$$ events $$$a_1, a_2, \ldots, a_n$$$, in the order they occurred. This array corresponds to one or more consecutive days. The system administrator erased the dates of events by mistake, but he didn't change the order of the events.You must partition (to cut) the array $$$a$$$ of events into contiguous subarrays, which must represent non-empty valid days (or say that it's impossible). Each array element should belong to exactly one contiguous subarray of a partition. Each contiguous subarray of a partition should be a valid day.For example, if $$$n=8$$$ and $$$a=[1, -1, 1, 2, -1, -2, 3, -3]$$$ then he can partition it into two contiguous subarrays which are valid days: $$$a = [1, -1~ \boldsymbol{|}~ 1, 2, -1, -2, 3, -3]$$$.Help the administrator to partition the given array $$$a$$$ in the required way or report that it is impossible to do. Find any required partition, you should not minimize or maximize the number of parts.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^6 \le a_i \le 10^6$$$ and $$$a_i \neq 0$$$).

If there is no valid partition, print $$$-1$$$. Otherwise, print any valid partition in the following format:   On the first line print the number $$$d$$$ of days ($$$1 \le d \le n$$$).  On the second line, print $$$d$$$ integers $$$c_1, c_2, \ldots, c_d$$$ ($$$1 \le c_i \le n$$$ and $$$c_1 + c_2 + \ldots + c_d = n$$$), where $$$c_i$$$ is the number of events in the $$$i$$$-th day.  If there are many valid solutions, you can print any of them. You don't have to minimize nor maximize the number of days.

NoteIn the first example, the whole array is a valid day.In the second example, one possible valid solution is to split the array into $$$[1, -1]$$$ and $$$[1, 2, -1, -2, 3, -3]$$$ ($$$d = 2$$$ and $$$c = [2, 6]$$$). The only other valid solution would be to split the array into $$$[1, -1]$$$, $$$[1, 2, -1, -2]$$$ and $$$[3, -3]$$$ ($$$d = 3$$$ and $$$c = [2, 4, 2]$$$). Both solutions are accepted.In the third and fourth examples, we can prove that there exists no valid solution. Please note that the array given in input is not guaranteed to represent a coherent set of events.

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 N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto X = new bool[](10^^6+10);
    int[] Y;
    auto zero = 0;
    auto one = 0;
    int last = 0;
    int[] ans;

    foreach (i, a; A) {
        if (a > 0) {
            if (X[a]) {
                writeln(-1);
                return;
            }
            X[a] = true;
            zero -= 1;
            one += 1;
        } else {
            a *= -1;
            if (!X[a]) {
                writeln(-1);
                return;
            }
            Y ~= a;
            zero += 1;
            one -= 1;
            if (one == 0) {
                ans ~= (i.to!int + 1) - last;
                last = i.to!int + 1;
                foreach (y; Y) X[y] = false;
                Y = [];
            }
        }
    }

    if (X.any) {
        writeln(-1);
        return;
    }

    writeln(ans.length.to!int);
    ans.map!(to!string).join(" ").writeln;
}

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;

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

void solve(){
	int n  = rint;
	int[] as = rint(n);

	int[] xs = new int[](1_000_999);
	long[] ys = new long[](1_000_999);
	int cnt = 0;
	int[] ans;

	int an = 0;
	foreach(a; as){
		an += 1;
		if(a > 0){
			if(xs[a] > 0){
				"-1".writeln;
				return;
			}
			xs[a] = 1;
			if(ys[a] == ans.length + 1){
				"-1".writeln;
				return;
			}
			ys[a] = ans.length + 1;
			cnt += 1;
		}
		else{
			if(xs[-a] == 0){
				"-1".writeln;
				return;
			}
			xs[-a] = 0;
			cnt -= 1;
			if(cnt == 0){
				ans ~= an;
				an = 0;
			}
		}
		log("a:", a, "cnt:", cnt, "an:", an, "ans:", ans);
		log("xs:", xs[0..10]);
		log("ys:", ys[0..10]);
	}

	if(cnt > 0){
		"-1".writeln;
		return;
	}

	ans.length.writeln;
	ans.map!(to!string).array.join(" ").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 N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto X = new bool[](10^^6+10);
    int[] Y;
    auto zero = 0;
    auto one = 0;
    int last = 0;
    int[] ans;

    foreach (i, a; A) {
        if (a > 0) {
            if (X[a]) {
                writeln(-1);
                return;
            }
            X[a] = true;
            zero -= 1;
            one += 1;
        } else {
            a *= -1;
            if (!X[a]) {
                writeln(-1);
                return;
            }
            Y ~= a;
            zero += 1;
            one -= 1;
            if (one == 0) {
                ans ~= (i.to!int + 1) - last;
                last = i.to!int + 1;
                foreach (y; Y) X[y] = false;
                Y = [];
            }
        }
    }

    writeln(ans.length.to!int);
    ans.map!(to!string).join(" ").writeln;
}


Bob has a string $$$s$$$ consisting of lowercase English letters. He defines $$$s'$$$ to be the string after removing all "a" characters from $$$s$$$ (keeping all other characters in the same order). He then generates a new string $$$t$$$ by concatenating $$$s$$$ and $$$s'$$$. In other words, $$$t=s+s'$$$ (look at notes for an example).You are given a string $$$t$$$. Your task is to find some $$$s$$$ that Bob could have used to generate $$$t$$$. It can be shown that if an answer exists, it will be unique.

The first line of input contains a string $$$t$$$ ($$$1 \leq |t| \leq 10^5$$$) consisting of lowercase English letters.

Print a string $$$s$$$ that could have generated $$$t$$$. It can be shown if an answer exists, it is unique. If no string exists, print ":(" (without double quotes, there is no space between the characters).

NoteIn the first example, we have $$$s = $$$ "aaaaa", and $$$s' = $$$ "".In the second example, no such $$$s$$$ can work that will generate the given $$$t$$$.In the third example, we have $$$s = $$$ "ababacac", and $$$s' = $$$ "bbcc", and $$$t = s + s' = $$$ "ababacacbbcc".

import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.range, 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;
string T;

void main() {
  try {
    for (; ; ) {
      T = readToken();
      N = cast(int)(T.length);

      int cnt;
      foreach (i; 0 .. N) {
        if (T[i] != 'a') {
          ++cnt;
        }
      }

      string ans;
      if (cnt % 2 == 0) {
        const string s = T[0 .. N - cnt / 2];
        string ss;
        foreach (c; s) {
          if (c != 'a') {
            ss ~= c;
          }
        }
        if (s ~ ss == T) {
          ans = s;
        }
      }
      writeln((ans == "") ? ":(" : ans);
    }
  } catch (EOFException e) {
  }
}


CQXYM found a rectangle $$$A$$$ of size $$$n \times m$$$. There are $$$n$$$ rows and $$$m$$$ columns of blocks. Each block of the rectangle is an obsidian block or empty. CQXYM can change an obsidian block to an empty block or an empty block to an obsidian block in one operation.A rectangle $$$M$$$ size of $$$a \times b$$$ is called a portal if and only if it satisfies the following conditions:  $$$a \geq 5,b \geq 4$$$.  For all $$$1 < x < a$$$, blocks $$$M_{x,1}$$$ and $$$M_{x,b}$$$ are obsidian blocks.  For all $$$1 < x < b$$$, blocks $$$M_{1,x}$$$ and $$$M_{a,x}$$$ are obsidian blocks.  For all $$$1<x<a,1<y<b$$$, block $$$M_{x,y}$$$ is an empty block.  $$$M_{1, 1}, M_{1, b}, M_{a, 1}, M_{a, b}$$$ can be any type.  Note that the there must be $$$a$$$ rows and $$$b$$$ columns, not $$$b$$$ rows and $$$a$$$ columns.Note that corners can be any typeCQXYM wants to know the minimum number of operations he needs to make at least one sub-rectangle a portal.

The first line contains an integer $$$t$$$ ($$$t \geq 1$$$), which is the number of test cases. For each test case, the first line contains two integers $$$n$$$ and $$$m$$$ ($$$5 \le n \le 400$$$, $$$4 \le m \le 400$$$).  Then $$$n$$$ lines follow, each line contains $$$m$$$ characters $$$0$$$ or $$$1$$$. If the $$$j$$$-th character of $$$i$$$-th line is $$$0$$$, block $$$A_{i,j}$$$ is an empty block. Otherwise, block $$$A_{i,j}$$$ is an obsidian block. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$400$$$. It is guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$400$$$.

Output $$$t$$$ answers, and each answer in a line.

NoteIn the first test case, the final portal is like this:11101001100110010111

immutable multi = true;

int[400][400] mat, rowSum;
int[400] railsSum, bodySum, pileRemove;

void solve(int tc)
{
	auto n = readInt!int;
	auto m = readInt!int;
	foreach(i; 0 .. n)
	{
		auto str = readString;
		foreach(j; 0 .. m)
			mat[i][j] = int(str[j] == '1');
	}
	foreach(j; 0 .. m)
	{
		rowSum[j][0] = mat[0][j];
	}
	foreach(j; 0 .. m)
	{

		foreach(i; 1 .. n)
		{
			rowSum[j][i] = rowSum[j][i-1] + mat[i][j];
		}
	}
	auto ans = int.max;
	foreach(i1; 0 .. n)
	{
		foreach(i2; i1 + 4 .. n)
		{
			auto minTail = int.max;
			auto height = i2 - i1 - 1;
			railsSum[0] = (1-mat[i1][0]) + (1-mat[i2][0]);
			bodySum[0] = rowSum[0][i2-1] - rowSum[0][i1];
			pileRemove[0] = height - (rowSum[0][i2-1] - rowSum[0][i1]);
			foreach(j; 1 .. m)
			{
				railsSum[j] = (1-mat[i1][j]) + (1-mat[i2][j]) + railsSum[j-1];
				bodySum[j] = (rowSum[j][i2-1] - rowSum[j][i1]) + bodySum[j-1];
				pileRemove[j] = height - (rowSum[j][i2-1] - rowSum[j][i1]);
			}
			foreach(j; 3 .. m)
			{
				minTail = min(minTail, -railsSum[j-3]+pileRemove[j-3]-bodySum[j-3]);
				auto localOperations = minTail + pileRemove[j] + railsSum[j-1] + bodySum[j-1];
				ans = min(ans, localOperations);
			}
		}
	}
	ans.writeln;
}

//{{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
//}}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

char topChar()
{
	return cast(char) currChar;
}

void popChar()
{
	import core.stdc.stdio;
	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;
}
void writes(T...)(T t)
{
	static foreach(i, ti; t)
	{
		static if (isIterable!(T[i]))
		{
			foreach(e; ti)
			{
				write(e, " ");
			}
		}
	}
}
auto ra(V)()
{
	int n = readInt!int;
	return ma(n, readInt!V);
}
auto rt(V)()
{
	int n = readInt!int;
	int m = readInt!int;
	return ma(n, ma(m, readInt!V));
}
auto rbg()
{
	int n = readInt!int;
	int m = readInt!int;
	auto adj = new int[][](n);
	foreach(i; 0 .. m)
	{
		auto u = readInt!int - 1;
		auto v = readInt!int - 1;
		adj[u] ~= v;
		adj[v] ~= u;
	}
	return adj;
}
auto ma(V)(size_t n, lazy V v)
{
	auto arr = new V[](n);
	foreach(ref ai; arr) ai = v;
	return arr;
}
// }}}
// imports {{{
import std.stdio;
import std.algorithm;
import std.typecons;
import std.math;
import std.numeric;
import std.container;
import std.range;
import std.array;
import std.ascii;
// }}}

immutable multi = true;

void solve(int tc)
{
	auto n = readInt!int;
	auto m = readInt!int;
	auto mat = ma(n, readString.map!(c => c == '0'? int(0) : int(1)).array);
	auto rowSum = new int[][](m, n);
	foreach(j; 0 .. m)
	{
		rowSum[j][0] = mat[0][j];
	}
	foreach(j; 0 .. m)
	{

		foreach(i; 1 .. n)
		{
			rowSum[j][i] = rowSum[j][i-1] + mat[i][j];
		}
	}
	auto railsSum = new int[](m);
	auto bodySum = new int[](m);
	auto pileRemove = new int[](m);
	auto ans = int.max;
	foreach(i1; 0 .. n)
	{
		foreach(i2; i1 + 4 .. n)
		{
			auto minTail = int.max;
			auto height = i2 - i1 - 1;
			railsSum[0] = (1-mat[i1][0]) + (1-mat[i2][0]);
			bodySum[0] = rowSum[0][i2-1] - rowSum[0][i1];
			pileRemove[0] = height - (rowSum[0][i2-1] - rowSum[0][i1]);
			foreach(j; 1 .. m)
			{
				railsSum[j] = (1-mat[i1][j]) + (1-mat[i2][j]) + railsSum[j-1];
				bodySum[j] = (rowSum[j][i2-1] - rowSum[j][i1]) + bodySum[j-1];
				pileRemove[j] = height - (rowSum[j][i2-1] - rowSum[j][i1]);
			}
			foreach(j; 3 .. m)
			{
				minTail = min(minTail, -railsSum[j-3]+pileRemove[j-3]-bodySum[j-3]);
				auto localOperations = minTail + pileRemove[j] + railsSum[j-1] + bodySum[j-1];
				ans = min(ans, localOperations);
			}
		}
	}
	ans.writeln;
}

//{{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
//}}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

char topChar()
{
	return cast(char) currChar;
}

void popChar()
{
	import core.stdc.stdio;
	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;
}
void writes(T...)(T t)
{
	static foreach(i, ti; t)
	{
		static if (isIterable!(T[i]))
		{
			foreach(e; ti)
			{
				write(e, " ");
			}
		}
	}
}
auto ra(V)()
{
	int n = readInt!int;
	return ma(n, readInt!V);
}
auto rt(V)()
{
	int n = readInt!int;
	int m = readInt!int;
	return ma(n, ma(m, readInt!V));
}
auto rbg()
{
	int n = readInt!int;
	int m = readInt!int;
	auto adj = new int[][](n);
	foreach(i; 0 .. m)
	{
		auto u = readInt!int - 1;
		auto v = readInt!int - 1;
		adj[u] ~= v;
		adj[v] ~= u;
	}
	return adj;
}
auto ma(V)(size_t n, lazy V v)
{
	auto arr = new V[](n);
	foreach(ref ai; arr) ai = v;
	return arr;
}
// }}}
// imports {{{
import std.stdio;
import std.algorithm;
import std.typecons;
import std.math;
import std.numeric;
import std.container;
import std.range;
import std.array;
import std.ascii;
// }}}

immutable multi = true;

void solve(int tc)
{
	auto n = readInt!int;
	auto m = readInt!int;
	auto mat = ma(n, readString.map!(c => c == '0'? int(0) : int(1)).array);
	auto rowSum = new int[][](m, n);
	auto colSum = new int[][](n, m);
	foreach(j; 0 .. m)
	{
		rowSum[j][0] = mat[0][j];
	}
	foreach(j; 0 .. m)
	{

		foreach(i; 1 .. n)
		{
			rowSum[j][i] = rowSum[j][i-1] + mat[i][j];
		}
	}
	foreach(i; 0 .. n)
	{
		colSum[i][0] = mat[i][0];
	}
	foreach(i; 0 .. n)
	{
		foreach(j; 1 .. m)
		{
			colSum[i][j] = colSum[i][j-1] + mat[i][j];
		}
	}
	auto railsSum = new int[](m);
	auto bodySum = new int[](m);
	auto pileRemove = new int[](m);
	auto ans = int.max;
	foreach(i1; 0 .. n)
	{
		foreach(i2; i1 + 4 .. n)
		{
			auto minTail = int.max;
			auto height = i2 - i1 - 1;
			railsSum[0] = (1-mat[i1][0]) + (1-mat[i2][0]);
			bodySum[0] = rowSum[0][i2-1] - rowSum[0][i1];
			pileRemove[0] = height - (rowSum[0][i2-1] - rowSum[0][i1]);
			foreach(j; 1 .. m)
			{
				railsSum[j] = (1-mat[i1][j]) + (1-mat[i2][j]) + railsSum[j-1];
				bodySum[j] = (rowSum[j][i2-1] - rowSum[j][i1]) + bodySum[j-1];
				pileRemove[j] = height - (rowSum[j][i2-1] - rowSum[j][i1]);
			}
			foreach(j; 3 .. m)
			{
				minTail = min(minTail, -railsSum[j-3]+pileRemove[j-3]-bodySum[j-3]);
				auto localOperations = minTail + pileRemove[j] + railsSum[j-1] + bodySum[j-1];
				ans = min(ans, localOperations);
			}
		}
	}
	ans.writeln;
}

//{{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
//}}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

char topChar()
{
	return cast(char) currChar;
}

void popChar()
{
	import core.stdc.stdio;
	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;
}
void writes(T...)(T t)
{
	static foreach(i, ti; t)
	{
		static if (isIterable!(T[i]))
		{
			foreach(e; ti)
			{
				write(e, " ");
			}
		}
	}
}
auto ra(V)()
{
	int n = readInt!int;
	return ma(n, readInt!V);
}
auto rt(V)()
{
	int n = readInt!int;
	int m = readInt!int;
	return ma(n, ma(m, readInt!V));
}
auto rbg()
{
	int n = readInt!int;
	int m = readInt!int;
	auto adj = new int[][](n);
	foreach(i; 0 .. m)
	{
		auto u = readInt!int - 1;
		auto v = readInt!int - 1;
		adj[u] ~= v;
		adj[v] ~= u;
	}
	return adj;
}
auto ma(V)(size_t n, lazy V v)
{
	auto arr = new V[](n);
	foreach(ref ai; arr) ai = v;
	return arr;
}
// }}}
// imports {{{
import std.stdio;
import std.algorithm;
import std.typecons;
import std.math;
import std.numeric;
import std.container;
import std.range;
import std.array;
import std.ascii;
// }}}

immutable multi = true;

void solve(int tc)
{
	auto n = readInt!int;
	auto m = readInt!int;
	auto mat = ma(n, readString.map!(c => c == '0'? int(0) : int(1)).array);
	auto rowSum = new int[][](m, n);
	auto colSum = new int[][](n, m);
	foreach(j; 0 .. m)
	{
		rowSum[j][0] = mat[0][j];
	}
	foreach(j; 0 .. m)
	{

		foreach(i; 1 .. n)
		{
			rowSum[j][i] = rowSum[j][i-1] + mat[i][j];
		}
	}
	foreach(i; 0 .. n)
	{
		colSum[i][0] = mat[i][0];
	}
	foreach(i; 0 .. n)
	{
		foreach(j; 1 .. m)
		{
			colSum[i][j] = colSum[i][j-1] + mat[i][j];
		}
	}
	auto ans = int.max;
	foreach(i1; 0 .. n)
	{
		foreach(i2; i1 + 4 .. n)
		{
			auto minTail = int.max;
			auto height = i2 - i1 - 1;
			auto railsSum = new int[](m);
			auto bodySum = new int[](m);
			auto pileRemove = new int[](m);

			railsSum[0] = (1-mat[i1][0]) + (1-mat[i2][0]);
			bodySum[0] = rowSum[0][i2-1] - rowSum[0][i1];
			pileRemove[0] = height - (rowSum[0][i2-1] - rowSum[0][i1]);
			foreach(j; 1 .. m)
			{
				railsSum[j] = (1-mat[i1][j]) + (1-mat[i2][j]) + railsSum[j-1];
				bodySum[j] = (rowSum[j][i2-1] - rowSum[j][i1]) + bodySum[j-1];
				pileRemove[j] = height - (rowSum[j][i2-1] - rowSum[j][i1]);

				debug writeln("body sum ", i1, " ", i2, " ", j, " = ", bodySum[j]);
				debug writeln("pile remove ", i1, " ", i2, " ", j, " = ", pileRemove[j]);
			}

			foreach(j; 3 .. m)
			{
				minTail = min(minTail, -railsSum[j-3]+pileRemove[j-3]-bodySum[j-3]);
				auto localOperations = minTail + pileRemove[j] + railsSum[j-1] + bodySum[j-1];
				ans = min(ans, localOperations);
			}
		}
	}
	ans.writeln;
}

//{{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
//}}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

char topChar()
{
	return cast(char) currChar;
}

void popChar()
{
	import core.stdc.stdio;
	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;
}
void writes(T...)(T t)
{
	static foreach(i, ti; t)
	{
		static if (isIterable!(T[i]))
		{
			foreach(e; ti)
			{
				write(e, " ");
			}
		}
	}
}
auto ra(V)()
{
	int n = readInt!int;
	return ma(n, readInt!V);
}
auto rt(V)()
{
	int n = readInt!int;
	int m = readInt!int;
	return ma(n, ma(m, readInt!V));
}
auto rbg()
{
	int n = readInt!int;
	int m = readInt!int;
	auto adj = new int[][](n);
	foreach(i; 0 .. m)
	{
		auto u = readInt!int - 1;
		auto v = readInt!int - 1;
		adj[u] ~= v;
		adj[v] ~= u;
	}
	return adj;
}
auto ma(V)(size_t n, lazy V v)
{
	auto arr = new V[](n);
	foreach(ref ai; arr) ai = v;
	return arr;
}
// }}}
// imports {{{
import std.stdio;
import std.algorithm;
import std.typecons;
import std.math;
import std.numeric;
import std.container;
import std.range;
import std.array;
import std.ascii;
// }}}

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)); }

enum INF = 10^^9;

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const M = readInt();
        const N = readInt();
        auto A = new string[M];
        foreach (x; 0 .. M) {
          A[x] = readToken();
        }

        auto ASums = new int[][](M, N + 1);
        foreach (x; 0 .. M) {
          foreach (y; 0 .. N) {
            ASums[x][y + 1] = ASums[x][y] + (A[x][y] - '0');
          }
        }

        int ans = INF;
        auto fs = new int[M + 1];
        foreach (y0; 0 .. N) foreach (y1; y0 + 3 .. N) {
          foreach (x; 0 .. M) {
            fs[x + 1] = fs[x];
            fs[x + 1] += 1 - (A[x][y0] - '0');
            fs[x + 1] += 1 - (A[x][y1] - '0');
            fs[x + 1] += (ASums[x][y1] - ASums[x][y0 + 1]);
          }
          int mn = INF;
          foreach (x; 0 .. M) {
            if (x >= 4) {
              int cost;
              cost += (y1 - y0 - 1) - (ASums[x - 4][y1] - ASums[x - 4][y0 + 1]);
              cost -= fs[x - 4 + 1];
              chmin(mn, cost);
            }
            {
              int cost = mn;
              cost += (y1 - y0 - 1) - (ASums[x][y1] - ASums[x][y0 + 1]);
              cost += fs[x];
              chmin(ans, cost);
            }
          }
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}


Two players decided to play one interesting card game.There is a deck of $$$n$$$ cards, with values from $$$1$$$ to $$$n$$$. The values of cards are pairwise different (this means that no two different cards have equal values). At the beginning of the game, the deck is completely distributed between players such that each player has at least one card. The game goes as follows: on each turn, each player chooses one of their cards (whichever they want) and puts on the table, so that the other player doesn't see which card they chose. After that, both cards are revealed, and the player, value of whose card was larger, takes both cards in his hand. Note that as all cards have different values, one of the cards will be strictly larger than the other one. Every card may be played any amount of times. The player loses if he doesn't have any cards.For example, suppose that $$$n = 5$$$, the first player has cards with values $$$2$$$ and $$$3$$$, and the second player has cards with values $$$1$$$, $$$4$$$, $$$5$$$. Then one possible flow of the game is:The first player chooses the card $$$3$$$. The second player chooses the card $$$1$$$. As $$$3>1$$$, the first player gets both cards. Now the first player has cards $$$1$$$, $$$2$$$, $$$3$$$, the second player has cards $$$4$$$, $$$5$$$.The first player chooses the card $$$3$$$. The second player chooses the card $$$4$$$. As $$$3<4$$$, the second player gets both cards. Now the first player has cards $$$1$$$, $$$2$$$. The second player has cards $$$3$$$, $$$4$$$, $$$5$$$.The first player chooses the card $$$1$$$. The second player chooses the card $$$3$$$. As $$$1<3$$$, the second player gets both cards. Now the first player has only the card $$$2$$$. The second player has cards $$$1$$$, $$$3$$$, $$$4$$$, $$$5$$$.The first player chooses the card $$$2$$$. The second player chooses the card $$$4$$$. As $$$2<4$$$, the second player gets both cards. Now the first player is out of cards and loses. Therefore, the second player wins.Who will win if both players are playing optimally? It can be shown that one of the players has a winning strategy.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The description of the test cases follows. The first line of each test case contains three integers $$$n$$$, $$$k_1$$$, $$$k_2$$$ ($$$2 \le n \le 100, 1 \le k_1 \le n - 1, 1 \le k_2 \le n - 1, k_1 + k_2 = n$$$) — the number of cards, number of cards owned by the first player and second player correspondingly. The second line of each test case contains $$$k_1$$$ integers $$$a_1, \dots, a_{k_1}$$$ ($$$1 \le a_i \le n$$$) — the values of cards of the first player. The third line of each test case contains $$$k_2$$$ integers $$$b_1, \dots, b_{k_2}$$$ ($$$1 \le b_i \le n$$$) — the values of cards of the second player. It is guaranteed that the values of all cards are different.

For each test case, output "YES" in a separate line, if the first player wins. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower).

NoteIn the first test case of the example, there is only one possible move for every player: the first player will put $$$2$$$, the second player will put $$$1$$$. $$$2>1$$$, so the first player will get both cards and will win.In the second test case of the example, it can be shown that it is the second player who has a winning strategy. One possible flow of the game is illustrated in the statement.

void main() {
	auto t = ri;
	foreach(_; 0..t) {
		auto ip = readAs!(int[]);
		auto a = readAs!(int[]);
		auto b = readAs!(int[]);
		a.sort!"a > b"();
		b.sort!"a > b"();
		if(a[0] > b[0]) writeln("YES");
		else writeln("NO");
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

import std.stdio;
import std.algorithm : map, maxElement;
import std.string : strip, split;
import std.conv : to;

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

  foreach (i; 0..t) {
    int n, k1, k2;
    readf!"%d %d %d\n"(n, k1, k2);

    auto maxa = readln.strip.split.map!(to!int).maxElement;
    auto maxb = readln.strip.split.map!(to!int).maxElement;

    writeln(maxa > maxb ? "YES" : "NO");
  }
}

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

void main ()
{
	int tests;
	readf !(" %s") (tests);
	foreach (test; 0..tests)
	{
		int n, k1, k2;
		readf !(" %s %s %s") (n, k1, k2);
		readln;
		auto a = readln.splitter.map !(to !(int));
		auto b = readln.splitter.map !(to !(int));
		writeln (a.maxElement > b.maxElement ? "YES" : "NO");
	}
}

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(){
	foreach(_; 0 .. rint){
		int n = rint, k1 = rint, k2 = rint;
		int[] as = rint(k1);
		int[] bs = rint(k2);

		string ans = "NO";
		foreach(a; as) if(a == n) ans = "YES";

		ans.writeln;
	}
}

import std.stdio;
import std.algorithm;
int main()
{
	int t=0;
	readf(" %d", &t);
	for (int i=0; i<t; i++)
	{
		int a=0;
		int b=0;
		int c=0;
		readf(" %d", &a);
		readf(" %d", &b);
		readf(" %d", &c);
		int max1=-1;
		int max2=-1;
		for (int j=0; j<b; j++)
		{
			int d=0;
			readf(" %d", &d);
			if (d>max1)
			{
				max1=d;
			}
		}
		for (int j=0; j<c; j++)
		{
			int d=0;
			readf(" %d", &d);
			if (d>max2)
			{
				max2=d;
			}
		}
		if (max1>max2)
		{
			writeln("YES");
		}
		else
		{
			writeln("NO");
		}
	}
	return 0;
}

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; }
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 bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto k1 = RD!int;
		auto k2 = RD!int;
		auto a = RDA;
		auto b = RDA;
		foreach (i; 0..k1)
		{
			if (a[i] == n)
			{
				ans[ti] = true;
				break;
			}
		}
	}

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


You are given an array consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, and a positive integer $$$m$$$. It is guaranteed that $$$m$$$ is a divisor of $$$n$$$.In a single move, you can choose any position $$$i$$$ between $$$1$$$ and $$$n$$$ and increase $$$a_i$$$ by $$$1$$$.Let's calculate $$$c_r$$$ ($$$0 \le r \le m-1)$$$ — the number of elements having remainder $$$r$$$ when divided by $$$m$$$. In other words, for each remainder, let's find the number of corresponding elements in $$$a$$$ with that remainder.Your task is to change the array in such a way that $$$c_0 = c_1 = \dots = c_{m-1} = \frac{n}{m}$$$.Find the minimum number of moves to satisfy the above requirement.

The first line of input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le m \le n$$$). It is guaranteed that $$$m$$$ is a divisor of $$$n$$$. The second line of input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$), the elements of the array.

In the first line, print a single integer — the minimum number of moves required to satisfy the following condition: for each remainder from $$$0$$$ to $$$m - 1$$$, the number of elements of the array having this remainder equals $$$\frac{n}{m}$$$. In the second line, print any array satisfying the condition and can be obtained from the given array with the minimum number of moves. The values of the elements of the resulting array must not exceed $$$10^{18}$$$.

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 n, m;
    readf("%s %s", &n, &m);
    readln;

    auto arr = readln.chomp.split.map!(to!int).array;

    auto rm = new int[][] (m);

    foreach (i, e; arr) { rm[e % m] ~= i.to!int; }

    debug { rm.each!writeln; }

    long ans = 0;
    int[] totake;
    foreach (i; 0 .. 2 * m) {
        int cr = i % m;
        while (rm[cr].length < n / m && !totake.empty()) {
            int idx = totake.back;
            totake.popBack();

            int newval = (arr[idx] / m) * m + cr;
            if (newval <= arr[idx]) { newval += m; }
            ans += newval - arr[idx];
            arr[idx] = newval;
            rm[cr] ~= idx;
        }

        while (rm[cr].length > n / m) {
            totake ~= rm[cr].back;
            rm[cr].popBack();
        }
    }

    ans.writeln;
    arr.map!(to!string).join(" ").writeln;
}

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

void main(string[] args)
{
  auto n = next!int;
  auto m = next!int;
  auto a = next!int(n);
  auto cnt = new int[](m);
  auto byclass = new int[][](m);
  foreach(i, ai; a)
    {
      auto aim = ai % m;
      cnt[aim]++;
      byclass[aim] ~= cast(int) i;
    }
  auto toFill = redBlackTree!int();
  foreach(i; 0 .. m)
    if (cnt[i] < n / m)
      toFill.insert(cast(int)i);
  long moves = 0;
  foreach(mclass; 0 .. m)
    {
      debug writeln("working with class ", mclass, " with indices ", byclass[mclass]);
      if (cnt[mclass] < n / m) continue;
      auto tomove = cnt[mclass] - n / m;
      debug writeln("will move ", tomove);
      foreach(i; 0 .. tomove)
	{
	  auto index = byclass[mclass][i];
	  int fill;
	  auto upper = toFill.upperBound(mclass);
	  if (upper.empty)
	    {
	      fill = toFill.upperBound(-1).front;
	    }
	  else
	    {
	      fill = upper.front;
	    }
	  int delta;
	  if (fill > mclass)
	    {
	      delta = fill - mclass;
	    }
	  else
	    {
	      delta = m - mclass + fill;
	    }
	  moves += delta;
	  a[index] = a[index] + delta;
	  assert(a[index] % m == fill);
	  assert(cnt[fill] < n / m);
	  cnt[fill]++;
	  if (cnt[fill] >= n / m)
	    toFill.removeKey(fill);
	}
    }
  writeln(moves);
  foreach(ai; a)
    write(ai, " ");
  writeln;
}

static this()
{
  popChar;
}

struct Any(T)
{
  static auto read()
  {
    static if (is(T == char))
      {
	auto res = frontChar;
	popChar;
	return res;
      }
  }
}

struct Unsigned(T)
{
  auto read()
  {
    auto res = T(0);
    while(!frontChar.isDigit) popChar;
    do
      {
	res = res * T(10) + T(frontChar - '0');
	popChar;
      }
    while(frontChar.isDigit);
    return res;
  }
}

struct Matrix(T, alias rows, alias cols)
{
  T[][] _cell;
  alias _cell this;
  // Ring constructor
  this(int n)
  {
    final switch(n)
      {
      case 0:
	_cell = new T[][](rows, cols);
	break;
      case 1:
	debug assert(rows == cols);
	_cell = new T[][](rows, cols);
	foreach(i; 0 .. rows)
	  _cell[i][i] = T(1);
	break;
      }
  }
  // Copy constructor
  this(Matrix!(T, rows, cols) other)
  {
    _cell = new T[][](rows, cols);
    foreach(i; 0 .. rows)
      _cell[i][] = other[i][];
  }
  auto opBinary(string op)(Matrix!(T, rows, cols) other)
       if (op == "+" || op == "-")
	 {
	   auto res = Matrix!(T, rows, cols)(0);
	   foreach(i; 0 .. rows)
	     foreach(j; 0 .. cols)
	       res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});
	   return res;
	 }
  auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)
       if (op == "*")
	 {
	   debug assert(cols == otherRows);
	   auto res = Matrix!(T, rows, otherCols)(0);
	   foreach(i; 0 .. rows)
	     foreach(k; 0 .. cols)
	       foreach(j; 0 .. otherCols)
		 res[i][j] += this[i][k] * other[k][j];
	   return res;
	 }
  ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)
  {
    static if (op == "*")
      {
	debug assert(rows == cols);
	alias n = rows;
	auto res = Matrix!(T, n, n)(0);
	T factor;
	foreach(i; 0 .. n)
	  foreach(k; 0 .. n)
	    foreach(j; 0 .. n)
	      res[i][j] += this[i][k] * other[k][j];
	foreach(i; 0 .. n)
	  this[i][] = res[i][];
      }
    else
      {
	foreach(i; 0 .. rows)
	  foreach(j; 0 .. cols)
	    mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});
      }
    return this;
  }
  mixin powMethod;
}

struct Mod(T, alias mod)
{
  alias This = Mod!(T, mod);
  T _rep;
  this(T t)
  {
    _rep = t % mod;
    if (_rep < 0) _rep += mod;
  }
  static auto plain(T t)
  {
    auto res = Mod!(T, mod)();
    res._rep = t;
    return res;
  }
  static auto fromPositive(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod);
  }
  static auto fromNegative(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod + mod);
  }
  string toString()
  {
    return to!string(_rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plain(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plain(resrep);
      }
    else static if (op == "*")
      {
	return This.fromPositive(_rep * b._rep);
      }
  }
  auto opOpAssign(string op)(This b)
  {
    mixin(q{_rep }, text(op, "="), q{b._rep;});
    static if (op == "+")
      {
	if (_rep >= mod) _rep -= mod;
      }
    else static if (op == "-")
      {
	if (_rep < 0) _rep += mod;
      }
    else static if (op == "*")
      {
	_rep %= mod;
      }
    return this;
  }

  auto opBinary(string op)(long exp)
       if (op == "^^")
	 {
	   return pow(exp);
	 }
  mixin powMethod;
}

mixin template powMethod()
{
  auto pow(this ThisType)(long exp)
    {
      auto res = ThisType(1);
      auto pow = ThisType(this);
      while(exp)
	{
	  if (exp & 1) res *= pow;
	  pow *= pow;
	  exp >>= 1;
	}
      return res;
    }
}
// INPUT
char frontChar;
void popChar()
{
  import core.stdc.stdio;
  frontChar = cast(char) getchar;
  if (feof(stdin)) frontChar = ' ';
}
auto makeArray(T, S...)(S s)
{
  enum brackets = () {
    string res;
    foreach(i; 0 .. s.length)
      res ~= "[]";
    return res;
  } ();
  mixin(q{alias Type = T}, brackets, q{;});
  return new Type(s);
}
template isNumberLike(T)
{
  enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));
}
void popWhite()
{
  import std.ascii;
  while (frontChar.isWhite) popChar;
}
void print(T...)(T t)
{
  static foreach(ti; t)
    {
      static if (is(typeof(ti) == string))
	{
	  write(ti, " ");
	}
      else static if (isArray!(typeof(ti)))
	{
	  foreach(e; ti) print(e);
	}
      else static if (isTuple!(typeof(ti)))
	{
	  static foreach(i; ti.length) writesp(ti[i]);
	}
      else
	{
	  write(ti, " ");
	}
    }
}
void println(T...)(T t)
{
  static if (t.length == 0)
    writeln;
  static foreach(ti; t)
    {
      print(ti);
      writeln;
    }
}
auto next(alias T, S...)(S s)
{
  pragma(inline, true);
  static if (s.length > 0)
    {
      auto res = makeArray!(typeof(next!T()))(s);
      S t;
      enum loops = () {
	string res;
	foreach(i; 0 .. s.length)
	  {
	    auto ti = text(q{t[}, i, q{]});
	    res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});
	  }
	return res;
      } ();
      enum indexing = () {
	string res = "res";
	foreach(i; 0 .. s.length)
	  res ~= text(q{[t[}, i, q{]]});
	return res;
      } ();
      mixin(loops, indexing, q{ = next!T;});
      return res;
    }
  else
    {
      static if (isNumberLike!T)
	{
	  import std.ascii: isDigit;
	  T res;
	  while(frontChar.isWhite) popChar;
	  T multiplier = T(1);
	  if (frontChar == '-')
	    {
	      multiplier = T(-1);
	      popChar;
	    }
	  else if (frontChar == '+')
	    {
	      popChar;
	    }
	  debug assert(frontChar.isDigit);
	  do
	    {
	      res = res * T(10) + T(frontChar - '0');
	      popChar;
	    }
	  while(frontChar.isDigit);
	  return multiplier * res;
	}
      else static if (is(T == string))
	{
	  import std.ascii: isWhite;
	  string res;
	  while(frontChar.isWhite)
	    popChar;
	  while(!frontChar.isWhite)
	    {
	      res ~= frontChar;
	      popChar;
	    }
	  return res;
	}
      else static if (is(T == char))
	{
	  while(frontChar.isWhite) popChar;
	  auto res = frontChar;
	  popChar;
	  return res;
	}
      else
	{
	  return T.read;
	}
    }
}

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

void main(string[] args)
{
  auto n = next!int;
  auto m = next!int;
  auto nom = n / m;
  auto a = next!int(n);
  auto cnt = new int[](m);
  auto byclass = new int[][](m);
  foreach(i, ai; a)
    {
      auto aim = ai % m;
      cnt[aim]++;
      byclass[aim] ~= cast(int) i;
    }
  auto toFill = redBlackTree!int();
  foreach(i; 0 .. m)
    if (cnt[i] < nom)
      toFill.insert(cast(int)i);
  long moves = 0;
  foreach(mclass; 0 .. m)
    {
      if (cnt[mclass] < nom) continue;
      auto tomove = cnt[mclass] - nom;
      foreach(i; 0 .. tomove)
	{
	  auto index = byclass[mclass][i];
	  auto upper = toFill.upperBound(mclass);
	  int fill = upper.empty? toFill.upperBound(-1).front : upper.front;
	  int delta = fill - mclass + int(fill < mclass) * m;
	  moves += delta;
	  a[index] = a[index] + delta;
	  assert(a[index] % m == fill);
	  assert(cnt[fill] < nom);
	  cnt[fill]++;
	  if (cnt[fill] == nom)
	    toFill.removeKey(fill);
	}
    }
  writeln(moves);
  foreach(ai; a)
    write(ai, " ");
  writeln;
}

static this()
{
  popChar;
}

struct Any(T)
{
  static auto read()
  {
    static if (is(T == char))
      {
	auto res = frontChar;
	popChar;
	return res;
      }
  }
}

struct Unsigned(T)
{
  auto read()
  {
    auto res = T(0);
    while(!frontChar.isDigit) popChar;
    do
      {
	res = res * T(10) + T(frontChar - '0');
	popChar;
      }
    while(frontChar.isDigit);
    return res;
  }
}

struct Matrix(T, alias rows, alias cols)
{
  T[][] _cell;
  alias _cell this;
  // Ring constructor
  this(int n)
  {
    final switch(n)
      {
      case 0:
	_cell = new T[][](rows, cols);
	break;
      case 1:
	debug assert(rows == cols);
	_cell = new T[][](rows, cols);
	foreach(i; 0 .. rows)
	  _cell[i][i] = T(1);
	break;
      }
  }
  // Copy constructor
  this(Matrix!(T, rows, cols) other)
  {
    _cell = new T[][](rows, cols);
    foreach(i; 0 .. rows)
      _cell[i][] = other[i][];
  }
  auto opBinary(string op)(Matrix!(T, rows, cols) other)
       if (op == "+" || op == "-")
	 {
	   auto res = Matrix!(T, rows, cols)(0);
	   foreach(i; 0 .. rows)
	     foreach(j; 0 .. cols)
	       res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});
	   return res;
	 }
  auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)
       if (op == "*")
	 {
	   debug assert(cols == otherRows);
	   auto res = Matrix!(T, rows, otherCols)(0);
	   foreach(i; 0 .. rows)
	     foreach(k; 0 .. cols)
	       foreach(j; 0 .. otherCols)
		 res[i][j] += this[i][k] * other[k][j];
	   return res;
	 }
  ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)
  {
    static if (op == "*")
      {
	debug assert(rows == cols);
	alias n = rows;
	auto res = Matrix!(T, n, n)(0);
	T factor;
	foreach(i; 0 .. n)
	  foreach(k; 0 .. n)
	    foreach(j; 0 .. n)
	      res[i][j] += this[i][k] * other[k][j];
	foreach(i; 0 .. n)
	  this[i][] = res[i][];
      }
    else
      {
	foreach(i; 0 .. rows)
	  foreach(j; 0 .. cols)
	    mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});
      }
    return this;
  }
  mixin powMethod;
}

struct Mod(T, alias mod)
{
  alias This = Mod!(T, mod);
  T _rep;
  this(T t)
  {
    _rep = t % mod;
    if (_rep < 0) _rep += mod;
  }
  static auto plain(T t)
  {
    auto res = Mod!(T, mod)();
    res._rep = t;
    return res;
  }
  static auto fromPositive(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod);
  }
  static auto fromNegative(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod + mod);
  }
  string toString()
  {
    return to!string(_rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plain(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plain(resrep);
      }
    else static if (op == "*")
      {
	return This.fromPositive(_rep * b._rep);
      }
  }
  auto opOpAssign(string op)(This b)
  {
    mixin(q{_rep }, text(op, "="), q{b._rep;});
    static if (op == "+")
      {
	if (_rep >= mod) _rep -= mod;
      }
    else static if (op == "-")
      {
	if (_rep < 0) _rep += mod;
      }
    else static if (op == "*")
      {
	_rep %= mod;
      }
    return this;
  }

  auto opBinary(string op)(long exp)
       if (op == "^^")
	 {
	   return pow(exp);
	 }
  mixin powMethod;
}

mixin template powMethod()
{
  auto pow(this ThisType)(long exp)
    {
      auto res = ThisType(1);
      auto pow = ThisType(this);
      while(exp)
	{
	  if (exp & 1) res *= pow;
	  pow *= pow;
	  exp >>= 1;
	}
      return res;
    }
}
// INPUT
char frontChar;
void popChar()
{
  import core.stdc.stdio;
  frontChar = cast(char) getchar;
  if (feof(stdin)) frontChar = ' ';
}
auto makeArray(T, S...)(S s)
{
  enum brackets = () {
    string res;
    foreach(i; 0 .. s.length)
      res ~= "[]";
    return res;
  } ();
  mixin(q{alias Type = T}, brackets, q{;});
  return new Type(s);
}
template isNumberLike(T)
{
  enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));
}
void popWhite()
{
  import std.ascii;
  while (frontChar.isWhite) popChar;
}
void print(T...)(T t)
{
  static foreach(ti; t)
    {
      static if (is(typeof(ti) == string))
	{
	  write(ti, " ");
	}
      else static if (isArray!(typeof(ti)))
	{
	  foreach(e; ti) print(e);
	}
      else static if (isTuple!(typeof(ti)))
	{
	  static foreach(i; ti.length) writesp(ti[i]);
	}
      else
	{
	  write(ti, " ");
	}
    }
}
void println(T...)(T t)
{
  static if (t.length == 0)
    writeln;
  static foreach(ti; t)
    {
      print(ti);
      writeln;
    }
}
auto next(alias T, S...)(S s)
{
  pragma(inline, true);
  static if (s.length > 0)
    {
      auto res = makeArray!(typeof(next!T()))(s);
      S t;
      enum loops = () {
	string res;
	foreach(i; 0 .. s.length)
	  {
	    auto ti = text(q{t[}, i, q{]});
	    res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});
	  }
	return res;
      } ();
      enum indexing = () {
	string res = "res";
	foreach(i; 0 .. s.length)
	  res ~= text(q{[t[}, i, q{]]});
	return res;
      } ();
      mixin(loops, indexing, q{ = next!T;});
      return res;
    }
  else
    {
      static if (isNumberLike!T)
	{
	  import std.ascii: isDigit;
	  T res;
	  while(frontChar.isWhite) popChar;
	  T multiplier = T(1);
	  if (frontChar == '-')
	    {
	      multiplier = T(-1);
	      popChar;
	    }
	  else if (frontChar == '+')
	    {
	      popChar;
	    }
	  debug assert(frontChar.isDigit);
	  do
	    {
	      res = res * T(10) + T(frontChar - '0');
	      popChar;
	    }
	  while(frontChar.isDigit);
	  return multiplier * res;
	}
      else static if (is(T == string))
	{
	  import std.ascii: isWhite;
	  string res;
	  while(frontChar.isWhite)
	    popChar;
	  while(!frontChar.isWhite)
	    {
	      res ~= frontChar;
	      popChar;
	    }
	  return res;
	}
      else static if (is(T == char))
	{
	  while(frontChar.isWhite) popChar;
	  auto res = frontChar;
	  popChar;
	  return res;
	}
      else
	{
	  return T.read;
	}
    }
}

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 n, m;
    readf("%s %s", &n, &m);
    readln;

    auto arr = readln.chomp.split.map!(to!int).array;

    auto rm = new int[][] (m);

    foreach (i, e; arr) { rm[e % m] ~= i.to!int; }

    debug { rm.each!writeln; }

    int ans = 0;
    int[] totake;
    foreach (i; 0 .. 3 * m) {
        int cr = i % m;
        while (rm[cr].length < n / m && !totake.empty()) {
            int idx = totake.back;
            totake.popBack();

            int newval = (arr[idx] / m) * m + cr;
            if (newval <= arr[idx]) { newval += m; }
            ans += newval - arr[idx];
            arr[idx] = newval;
            rm[cr] ~= idx;
        }

        while (rm[cr].length > n / m) {
            totake ~= rm[cr].back;
            rm[cr].popBack();
        }
    }

    ans.writeln;
    arr.map!(to!string).join(" ").writeln;
}

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 n, m;
    readf("%s %s", &n, &m);
    readln;

    auto arr = readln.chomp.split.map!(to!int).array;

    auto rm = new int[][] (m);

    foreach (i, e; arr) { rm[e % m] ~= i.to!int; }

    debug { rm.each!writeln; }

    int ans = 0;
    int[] totake;
    foreach (i; 0 .. 2 * m) {
        int cr = i % m;
        while (rm[cr].length < n / m && !totake.empty()) {
            int idx = totake.back;
            totake.popBack();

            int newval = (arr[idx] / m) * m + cr;
            ans += newval - arr[idx];
            arr[idx] = newval;
            rm[cr] ~= idx;
        }

        while (rm[cr].length > n / m) {
            totake ~= rm[cr].back;
            rm[cr].popBack();
        }
    }

    ans.writeln;
    arr.map!(to!string).join(" ").writeln;
}

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 n, m;
    readf("%s %s", &n, &m);
    readln;

    auto arr = readln.chomp.split.map!(to!int).array;

    auto rm = new int[][] (m);

    foreach (i, e; arr) { rm[e % m] ~= i.to!int; }

    debug { rm.each!writeln; }

    int ans = 0;
    int[] totake;
    foreach (i; 0 .. 3 * m) {
        int cr = i % m;
        while (rm[cr].length < n / m && !totake.empty()) {
            int idx = totake.back;
            totake.popBack();

            int newval = (arr[idx] / m) * m + cr;
            ans += newval - arr[idx];
            arr[idx] = newval;
            rm[cr] ~= idx;
        }

        while (rm[cr].length > n / m) {
            totake ~= rm[cr].back;
            rm[cr].popBack();
        }
    }

    ans.writeln;
    arr.map!(to!string).join(" ").writeln;
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i. e. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below:  $$$[1], [2], [3, 4, 5]$$$;  $$$[1], [2, 3], [4, 5]$$$;  $$$[1], [2, 3, 4], [5]$$$;  $$$[1, 2], [3], [4, 5]$$$;  $$$[1, 2], [3, 4], [5]$$$;  $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries.

The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) — the number of elements in the array and the number of subsegments, respectively. The second line of the query contains $$$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 $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $$$k$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_k$$$ such that $$$1 \le r_1 < r_2 < \dots < r_k = n$$$, where $$$r_j$$$ is the right border of the $$$j$$$-th segment (the index of the last element that belongs to the $$$j$$$-th segment), so the array is divided into subsegments $$$[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$$$. Note that $$$r_k$$$ is always $$$n$$$ but you should print it anyway.

import std.stdio;
import std.algorithm;

void solve() {
    int n, k;
    readf(" %s %s", n, k);

    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
        readf(" %s", a[i]);
    }

    auto numOfOdds = fold!((s, x) => s + x % 2)(a, 0);
    if ((numOfOdds - k) % 2 == 0 && numOfOdds >= k) {
        writeln("YES");
        for (int i = 0, j = 1; i < n; i++) {
            if (a[i] % 2 == 1) {
                if (j == k) {
                    write(n);
                    break;
                } else {
                    write(i+1, " ");
                    j += 1;
                }
            }
        }
        writeln();
    } else {
        writeln("NO");
    }
}

void main(){
    int numOfTests;
    readf(" %s", numOfTests);
    for (int i = 0; i < numOfTests; i++) {
        solve();
    }
}

module main;

import std.stdio;
import std.container.array;

void main(string[] args){
    long n, a, b, sum, input;
    scanf("%lld", &n);
    while (n--) {
        auto arr = Array!int();
        scanf("%lld %lld", &a, &b);
        sum = 0;
        for (int i = 0; i < a; i++) {
            scanf("%lld", &input);
            sum += input;
            if (sum & 1) {
                arr.insertBack(i + 1);
                sum = 0;
            } else if (i == a - 1) {
                if (!arr.empty()) {
                    arr.back() = i + 1;
                }
            }
        }
        int len = arr.length;
        int start = 0;
        while (len > b) {
            len -= 2;
            start += 2;
        }
        if (len == b) {
            printf("YES\n");
            for (int i = start; i < arr.length; i++ ) {
                printf("%d ", arr[i]);
            }
            printf("\n");
        } else {
            printf("NO\n");
        }
    }
}

import std.stdio;
void main()
{
    int q;
    readf(" %s", &q);

    for(int i = 0; i < q; i++){
    	int k = 0;
    	int n = 0;
    	readf(" %s %s", &n, &k);
    	long[] array = new long[] (n);
    	int totalParity = 0;
    	int numOdd = 0;

    	for(int j = 0; j < n; j++){
    		readf(" %s", &array[j]);
    		totalParity += array[j];
    		totalParity %= 2;
    		if(array[j] % 2 == 1)
    			numOdd++;
    	}

    	if(totalParity == (k % 2) && numOdd >= k){
    		write("YES\n");
    		int currentParity = 0;
    		int numSegments = 1;

    		for(int j = 0; j < n && numSegments < k; j++){
    			currentParity += array[j];
    			currentParity %= 2;
    			if(currentParity % 2 == 1){
    				write(j + 1);
    				write(" ");
    				currentParity = 0;
    				numSegments++;
    			}
    		}
    		write((n));
    		write("\n");
    	}else{
    		write("NO\n");
    	}
    }
}

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 n = RD!int;
		auto k = RD!int;
		auto a = RDA;
		long[] tmp;
		long cnt;
		foreach (j; 0..n)
		{
			cnt += a[j];
			if (tmp.length == k-1) continue;
			if (cnt % 2 == 1)
			{
				tmp ~= j + 1;
				cnt = 0;
			}
		}
		if (cnt != 0)
		{
			if (cnt % 2 == 1)
				tmp ~= n;
			else
				tmp.length = 0;
		}
		if (tmp.length != k)
		{
			tmp.length = 0;
		}
		ans[i] = tmp;
	}

	foreach (e; ans)
	{
		if (e.length == 0)
		{
			writeln("NO");
		}
		else
		{
			writeln("YES");
			e.map!(to!string).join(" ").writeln();
		}
	}
	stdout.flush();
	debug readln();
}

module main;

import std.stdio;
import std.container.array;

void main(string[] args){
    long n, a, b, sum, input;
    scanf("%lld", &n);
    while (n--) {
        auto arr = Array!int();
        scanf("%lld %lld", &a, &b);
        sum = 0;
        for (int i = 0; i < a; i++) {
            scanf("%lld", &input);
            sum += input;
            if (sum & 1) {
                arr.insertBack(i + 1);
                sum = 0;
            }
        }
        int len = arr.length;
        while (len > b) {
            len -= 2;
        }
        if (len == b) {
            printf("YES\n");
            for (int i =0; i < b; i++ ) {
                printf("%d ", arr[i]);
            }
            printf("\n");
        } else {
            printf("NO\n");
        }
    }
}

import std.stdio;
void main()
{
    int q;
    readf(" %s", &q);

    for(int i = 0; i < q; i++){
    	int k = 0;
    	int n = 0;
    	readf(" %s %s", &n, &k);
    	int[] array = new int[] (n);
    	int totalParity = 0;

    	for(int j = 0; j < n; j++){
    		readf(" %s", &array[j]);
    		totalParity += array[j];
    		totalParity %= 2;
    	}

    	if(totalParity == (k % 2)){
    		write("YES\n");
    		int currentParity = 0;
    		int numSegments = 1;

    		for(int j = 0; j < n && numSegments < k; j++){
    			currentParity += array[j];
    			currentParity %= 2;
    			if(currentParity % 2 == 1){
    				write(j);
    				write(" ");
    			}
    		}
    		write((n - 1));
    		write("\n");
    	}else{
    		write("NO\n");
    	}
    }
}

import std.stdio;
void main()
{
    int q;
    readf(" %s", &q);

    for(int i = 0; i < q; i++){
    	int k = 0;
    	int n = 0;
    	readf(" %s %s", &n, &k);
    	int[] array = new int[] (n);
    	int totalParity = 0;

    	for(int j = 0; j < n; j++){
    		readf(" %s", &array[j]);
    		totalParity += array[j];
    		totalParity %= 2;
    	}

    	if(totalParity == (k % 2)){
    		write("YES\n");
    		int currentParity = 0;
    		int numSegments = 1;

    		for(int j = 0; j < n && numSegments < k; j++){
    			currentParity += array[j];
    			currentParity %= 2;
    			if(currentParity % 2 == 1){
    				write(j + 1);
    				write(" ");
    				currentParity = 0;
    				numSegments++;
    			}
    		}
    		write((n));
    		write("\n");
    	}else{
    		write("NO\n");
    	}
    }
}

import std.stdio;
void main()
{
    int q;
    readf(" %s", &q);

    for(int i = 0; i < q; i++){
    	int k = 0;
    	int n = 0;
    	readf(" %s %s", &n, &k);
    	long[] array = new long[] (n);
    	int totalParity = 0;

    	for(int j = 0; j < n; j++){
    		readf(" %s", &array[j]);
    		totalParity += array[j];
    		totalParity %= 2;
    	}

    	if(totalParity == (k % 2)){
    		write("YES\n");
    		int currentParity = 0;
    		int numSegments = 1;

    		for(int j = 0; j < n && numSegments < k; j++){
    			currentParity += array[j];
    			currentParity %= 2;
    			if(currentParity % 2 == 1){
    				write(j + 1);
    				write(" ");
    				currentParity = 0;
    				numSegments++;
    			}
    		}
    		write((n));
    		write("\n");
    	}else{
    		write("NO\n");
    	}
    }
}

import std.stdio;
void main()
{
    int q;
    readf(" %s", &q);

    for(int i = 0; i < q; i++){
    	int k = 0;
    	int n = 0;
    	readf(" %s %s", &n, &k);
    	int[] array = new int[] (n);
    	int totalParity = 0;

    	for(int j = 0; j < n; j++){
    		readf(" %s", &array[j]);
    		totalParity += array[j];
    		totalParity %= 2;
    	}

    	if(totalParity == (k % 2)){
    		writeln("YES\n");
    		int currentParity = 0;
    		int numSegments = 1;

    		for(int j = 0; j < n && numSegments < k; j++){
    			currentParity += array[j];
    			currentParity %= 2;
    			if(currentParity % 2 == 1){
    				write(j);
    				write(" ");
    			}
    		}
    		write((n - 1));
    		write("\n");
    	}else{
    		write("NO\n");
    	}
    }
}


Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.For each opponent Arya knows his schedule — whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.

The first line of the input contains two integers n and d (1 ≤ n, d ≤ 100) — the number of opponents and the number of days, respectively. The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.

Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents.

NoteIn the first and the second samples, Arya will beat all present opponents each of the d days.In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.

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 d = cin.read_int;

                char[][] att = new char[][d];

                int beat_streak = 0;
                int count = 0;
                for (int i = 0; i < d; i++) {
                        att[i] = new char[n];
                        att[i] = cin.read_string.dup;
                        if (canFind(att[i][0..n], '0')) count++;
                        else count = 0;
                        beat_streak = max(beat_streak, count);
                }
                writeln(beat_streak);
        }
}

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

void main() {

    auto nd = readln.split.map!(to!int).array;

    int max_ans1, max_ans2;
    foreach (idx; 0 .. nd[1]) {
        bool d_idx = readln.strip.map!(to!char).array.any!(d => d == '0');
        if (d_idx) {
            ++max_ans1;
            if (max_ans1 > max_ans2) {
                max_ans2 = max_ans1;
            }
        } else {
            max_ans1 = 0;
        }
    }

    writeln(max_ans2);
}

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

void main()
{
    auto n = split(strip(readln()));
    auto d = to!int(n[1]);
    int maxi;
    int count;
    foreach (i; 0 .. d)
    {
        auto x = strip(readln());
        if (indexOf(x, '0') >= 0)
            count++;
        else
        {
            maxi = max(maxi, count);
            count = 0;
        }
    }
    maxi = max(maxi, count);
    writeln(maxi);
}

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

void main()
{
    auto n = split(strip(readln()));
    auto d = to!int(n[1]);
    int maxi;
    int count;
    foreach (i; 0 .. d)
    {
        auto x = strip(readln());
        if (indexOf(x, '0') >= 0)
            count++;
        else
        {
            maxi = max(maxi, count);
            count = 0;
        }
    }
    writeln(maxi);
}


You are given two positive integers $$$a$$$ and $$$b$$$. In one move you can increase $$$a$$$ by $$$1$$$ (replace $$$a$$$ with $$$a+1$$$). Your task is to find the minimum number of moves you need to do in order to make $$$a$$$ divisible by $$$b$$$. It is possible, that you have to make $$$0$$$ moves, as $$$a$$$ is already divisible by $$$b$$$. You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9$$$).

For each test case print the answer — the minimum number of moves you need to do in order to make $$$a$$$ divisible by $$$b$$$.

import std.stdio;
int main()
{
	int t=0;
	readf(" %d", &t);
	for (int i=0; i<t; i++)
	{
		int a=0;
		int b=0;
		readf(" %d", &a);
		readf(" %d", &b);
		writeln((b-a%b)%b);
	}
	return 0;
}

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 long[](t);
	foreach (ti; 0..t)
	{
		auto a = RD;
		auto b = RD;

		ans[ti] = (b - (a % b)) % b;
	}

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


Young boy Artem tries to paint a picture, and he asks his mother Medina to help him. Medina is very busy, that's why she asked for your help.Artem wants to paint an $$$n \times m$$$ board. Each cell of the board should be colored in white or black. Lets $$$B$$$ be the number of black cells that have at least one white neighbor adjacent by the side. Let $$$W$$$ be the number of white cells that have at least one black neighbor adjacent by the side. A coloring is called good if $$$B = W + 1$$$. The first coloring shown below has $$$B=5$$$ and $$$W=4$$$ (all cells have at least one neighbor with the opposite color). However, the second coloring is not good as it has $$$B=4$$$, $$$W=4$$$ (only the bottom right cell doesn't have a neighbor with the opposite color).  Please, help Medina to find any good coloring. It's guaranteed that under given constraints the solution always exists. If there are several solutions, output any of them.

Each test contains multiple test cases.  The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 20$$$). Each of the next $$$t$$$ lines contains two integers $$$n, m$$$ ($$$2 \le n,m \le 100$$$) — the number of rows and the number of columns in the grid.

For each test case print $$$n$$$ lines, each of length $$$m$$$, where $$$i$$$-th line is the $$$i$$$-th row of your colored matrix (cell labeled with 'B' means that the cell is black, and 'W' means white). Do not use quotes. It's guaranteed that under given constraints the solution always exists.

NoteIn the first testcase, $$$B=3$$$, $$$W=2$$$.In the second testcase, $$$B=5$$$, $$$W=4$$$. You can see the coloring in the statement.

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)
	{
		int n, m;
		readf !(" %s %s") (n, m);
		auto board = new char [] [] (n, m);
		foreach (i, ref line; board)
		{
			foreach (j, ref square; line)
			{
				square = "BW"[i + 1 == n && j + 1 == m];
			}
		}
		writefln !("%-(%s\n%)") (board);
	}
}

//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 ();
  foreach (tid; 0 .. nt) {
    const uint h = r.next!uint ();
    const uint w = r.next!uint ();
    auto a = new char[][](h, w);
    foreach (j; 0 .. h) {
      foreach (i; 0 .. w) {
        if (i || j) write ('B'); else write('W');
      }
      writeln;
    }
  }
}

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(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
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)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
    foreach(_; 0 .. scan!int){
        int n = scan!int, m = scan!int;
        foreach(i; 0 .. n){
            if(i == 0) "W".write;
            else "B".write;
            foreach(j; 0 .. m - 1) "B".write;
            "".writeln;
        }
    }
}

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 string[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto m = RD!int;
		ans[ti].length = n;
		foreach (y; 0..n-1)
		{
			foreach (x; 0..m-1)
			{
				ans[ti][y] ~= 'W';
			}
			ans[ti][y] ~= 'B';
		}
		foreach (i; 0..m)
		{
			ans[ti][$-1] ~= 'B';
		}
	}

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