You are given an array $$$a$$$, consisting of $$$n$$$ positive integers.Let's call a concatenation of numbers $$$x$$$ and $$$y$$$ the number that is obtained by writing down numbers $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, a concatenation of numbers $$$12$$$ and $$$3456$$$ is a number $$$123456$$$.Count the number of ordered pairs of positions $$$(i, j)$$$ ($$$i \neq j$$$) in array $$$a$$$ such that the concatenation of $$$a_i$$$ and $$$a_j$$$ is divisible by $$$k$$$.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$2 \le k \le 10^9$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$).

Print a single integer — the number of ordered pairs of positions $$$(i, j)$$$ ($$$i \neq j$$$) in array $$$a$$$ such that the concatenation of $$$a_i$$$ and $$$a_j$$$ is divisible by $$$k$$$.

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

void main() {
    auto s = readln.split.map!(to!int);
    auto n = s[0];
    auto m = s[1];
    auto A = readln.split.map!(to!long).array;

    long ans = 0;
    auto cnt = new long[long][](11);
    foreach (a; A) {
        auto v = a;
        foreach (i; 0..11) {
            cnt[i][v] += 1;
            v = v * 10 % m;
        }
    }

    foreach (a; A) {
        long keta = a.to!string.length.to!long;
        long target = (m - a % m) % m;
        if (target in cnt[keta.to!int]) ans += cnt[keta.to!int][target];
        if ((powmod(10, keta, m) * a % m + a) % m == 0) ans -= 1;
    }

    ans.writeln;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}

import std.stdio, std.string;
import std.math;

int calcLength(int num)
{
    auto res = 0;
    while (num)
    {
        num /= 10;
        ++ res;
    }
    return res;
}

void solve(int[] a, int n, int k)
{
    auto h = new int[int][10];
    foreach (i; 0 .. n)
    {
        foreach (j; 0 .. 10)
        {
            auto num = cast(int)((cast(long)a[i] * (cast(long)pow(10L, j + 1) % k)) % k);
            if (num !in h[j])
            {
                h[j][num] = 1;
            }
            else
            {
                ++ h[j][num];
            }
        }
    }
    long res = 0;
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        auto L = calcLength(a[i]);
        auto target = (k - num) % k;
        if (target in h[L - 1])
        {
            res += h[L - 1][target];
        }
        num = cast(int)((cast(long)a[i] * (cast(long)pow(10L, L) % k)) % k);
        num = (num + (a[i] % k)) % k;
        if (num == 0)
        {
            -- res;
        }
    }
    writeln(res);
}

int main(string[] args)
{
    int n, k;
    while (readf("%d %d\n", &n, &k) == 2)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a, n, k);
    }
    return 0;
}

import std.stdio, std.string;
import std.math;

int calcLength(int num)
{
    auto res = 0;
    while (num)
    {
        num /= 10;
        ++ res;
    }
    return res;
}

void solve(int[] a, int n, int k)
{
    auto h = new int[int][10];
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        foreach (j; 0 .. 10)
        {
            num = cast(int)((cast(long)num * 10) % k);
            if (num !in h[j])
            {
                h[j][num] = 1;
            }
            else
            {
                ++ h[j][num];
            }
        }
    }
    long res = 0;
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        auto L = calcLength(a[i]);
        auto target = (k - num) % k;
        if (target in h[L - 1])
        {
            res += h[L - 1][target];
        }
        num = cast(int)((cast(long)a[i] * (cast(long)pow(10L, L) % k)) % k);
        num = (num + (a[i] % k)) % k;
        if (num == 0)
        {
            -- res;
        }
    }
    writeln(res);
}

int main(string[] args)
{
    int n, k;
    while (readf("%d %d\n", &n, &k) == 2)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a, n, k);
    }
    return 0;
}

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

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

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

    int [int][int] cnt;
    void add(int e, int v) { cnt[e.to!string.length.to!int][e % k] += v; }

    foreach (e; arr) {
        add(e, 1);
    }

    debug { cnt.writeln; }

    auto ans = 0L;
    foreach (e; arr) {
        add(e, -1);
        auto r = e % k;
        foreach (d; 1 .. 11) {
            r = cast(long)r * 10 % k;
            debug { r.writeln; }
            if (d in cnt && ((k-r) % k) in cnt[d]) ans += cnt[d][(k-r) % k];
        }
        add(e, 1);
    }

    ans.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;
import std.variant;
import std.concurrency;

void main(string[] args)
{
  auto n = next!int;
  auto k = next!long;
  auto a = next!long(n);
  auto origA = a.dup;
  int[11] pot;
  pot[0] = 1;
  foreach(i; 1 .. 11)
    {
      pot[i] = (pot[i - 1] * 10) % k;
    }
  int[int][11] cnt;
  foreach(p; 0 .. 11)
    {
      foreach(ref ai; a)
	{
	  ai %= k;
	}
      foreach(ref ai; a)
	{
	  cnt[p].require(cast(int)ai, 0)++;
	  ai *= 10;
	}
    }
  long totalCount = 0;
  foreach(ref ai; origA)
    {
      auto digs = noDigs(ai);
      long req = (((-ai) % k + k))%k;
      debug writeln("I require ", req, " in ", digs);
      if (cast(int)req in cnt[digs])
	{
	  totalCount += cnt[digs][cast(int)req];
	  if ((pot[digs] * (ai % k) + ai % k) % k == 0)
	    totalCount --;
	}
    }
  totalCount.writeln;
}

auto noDigs(long num)
{
  auto res = int(0);
  while(num)
    {
      num /= 10;
      res++;
    }
  return res;
}

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, std.string;
import std.math;

int calcLength(int num)
{
    auto res = 0;
    while (num)
    {
        num /= 10;
        ++ res;
    }
    return res;
}

void solve(int[] a, int n, int k)
{
    auto h = new int[int][10];
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        foreach (j; 0 .. 10)
        {
            num = cast(int)((cast(long)num * 10) % k);
            if (num !in h[j])
            {
                h[j][num] = 1;
            }
            else
            {
                ++ h[j][num];
            }
        }
    }
    long res = 0;
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        auto L = calcLength(a[i]);
        auto target = (k - num) % k;
        if (target in h[L - 1])
        {
            res += h[L - 1][target];
        }
        num = cast(int)((cast(long)a[i] * (pow(10, L) % k)) % k);
        num = (num + (a[i] % k)) % k;
        if (num == 0)
        {
            -- res;
        }
    }
    writeln(res);
}

int main(string[] args)
{
    int n, k;
    while (readf("%d %d\n", &n, &k) == 2)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a, n, k);
    }
    return 0;
}

import std.stdio, std.string;
import std.math;

int calcLength(int num)
{
    auto res = 0;
    while (num)
    {
        num /= 10;
        ++ res;
    }
    return res;
}

void solve(int[] a, int n, int k)
{
    auto h = new int[int][10];
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        foreach (j; 0 .. 10)
        {
            num = (num * 10) % k;
            if (num !in h[j])
            {
                h[j][num] = 1;
            }
            else
            {
                ++ h[j][num];
            }
        }
    }
    long res = 0;
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        auto L = calcLength(a[i]);
        auto target = (k - num) % k;
        if (target in h[L - 1])
        {
            res += h[L - 1][target];
        }
        num = cast(int)((cast(long)a[i] * (pow(10, L) % k)) % k);
        num = (num + (a[i] % k)) % k;
        if (num == 0)
        {
            -- res;
        }
    }
    writeln(res);
}

int main(string[] args)
{
    int n, k;
    while (readf("%d %d\n", &n, &k) == 2)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a, n, k);
    }
    return 0;
}

import std.stdio, std.string;
import std.math;

int calcLength(int num)
{
    auto res = 0;
    while (num)
    {
        num /= 10;
        ++ res;
    }
    return res;
}

void solve(int[] a, int n, int k)
{
    auto h = new int[int][10];
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        foreach (j; 0 .. 10)
        {
            num = cast(int)((cast(long)num * 10) % k);
            if (num !in h[j])
            {
                h[j][num] = 1;
            }
            else
            {
                ++ h[j][num];
            }
        }
    }
    long res = 0;
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        auto L = calcLength(a[i]);
        auto target = (k - num) % k;
        if (target in h[L - 1])
        {
            res += h[L - 1][target];
        }
        num = cast(int)((cast(long)(a[i] % k) * (cast(long)pow(10, L) % k)) % k);
        num = (num + (a[i] % k)) % k;
        if (num == 0)
        {
            -- res;
        }
    }
    writeln(res);
}

int main(string[] args)
{
    int n, k;
    while (readf("%d %d\n", &n, &k) == 2)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a, n, k);
    }
    return 0;
}

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

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

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

    int [int][int] cnt;
    void add(int e, int v) { cnt[e.to!string.length.to!int][e % k] += v; }

    foreach (e; arr) {
        add(e, 1);
    }

    debug { cnt.writeln; }

    auto ans = 0L;
    foreach (e; arr) {
        add(e, -1);
        auto r = e % k;
        foreach (d; 1 .. 10) {
            r = r * 10 % k;
            if (d in cnt && ((k-r) % k) in cnt[d]) ans += cnt[d][(k-r) % k];
        }
        add(e, 1);
    }

    ans.writeln;
}

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

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

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

    int [int][int] cnt;
    void add(int e, int v) { cnt[e.to!string.length.to!int][e % k] += v; }

    foreach (e; arr) {
        add(e, 1);
    }

    debug { cnt.writeln; }

    auto ans = 0L;
    foreach (e; arr) {
        add(e, -1);
        auto r = e % k;
        foreach (d; 1 .. 11) {
            r = r * 10 % k;
            if (d in cnt && ((k-r) % k) in cnt[d]) ans += cnt[d][(k-r) % k];
        }
        add(e, 1);
    }

    ans.writeln;
}


There are $$$n$$$ warriors in a row. The power of the $$$i$$$-th warrior is $$$a_i$$$. All powers are pairwise distinct.You have two types of spells which you may cast:   Fireball: you spend $$$x$$$ mana and destroy exactly $$$k$$$ consecutive warriors;  Berserk: you spend $$$y$$$ mana, choose two consecutive warriors, and the warrior with greater power destroys the warrior with smaller power. For example, let the powers of warriors be $$$[2, 3, 7, 8, 11, 5, 4]$$$, and $$$k = 3$$$. If you cast Berserk on warriors with powers $$$8$$$ and $$$11$$$, the resulting sequence of powers becomes $$$[2, 3, 7, 11, 5, 4]$$$. Then, for example, if you cast Fireball on consecutive warriors with powers $$$[7, 11, 5]$$$, the resulting sequence of powers becomes $$$[2, 3, 4]$$$.You want to turn the current sequence of warriors powers $$$a_1, a_2, \dots, a_n$$$ into $$$b_1, b_2, \dots, b_m$$$. Calculate the minimum amount of mana you need to spend on it.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the length of sequence $$$a$$$ and the length of sequence $$$b$$$ respectively. The second line contains three integers $$$x, k, y$$$ ($$$1 \le x, y, \le 10^9; 1 \le k \le n$$$) — the cost of fireball, the range of fireball and the cost of berserk respectively. The third line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$). It is guaranteed that all integers $$$a_i$$$ are pairwise distinct. The fourth line contains $$$m$$$ integers $$$b_1, b_2, \dots, b_m$$$ ($$$1 \le b_i \le n$$$). It is guaranteed that all integers $$$b_i$$$ are pairwise distinct.

Print the minimum amount of mana for turning the sequnce $$$a_1, a_2, \dots, a_n$$$ into $$$b_1, b_2, \dots, b_m$$$, or $$$-1$$$ if it is impossible.

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

void main ()
{
	int n, m;
	while (readf !(" %s %s") (n, m) > 0)
	{
		int x, k, y;
		readf !(" %s %s %s") (x, k, y);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto b = readln.splitter.map !(to !(int)).array;

		a = int.min ~ a ~ int.min;
		b = int.min ~ b ~ int.min;
		n += 2;
		m += 2;

		long solve ()
		{
			long res = 0;
			int i = 0;
			foreach (j; 1..m)
			{
				int r = i;
				while (r < n && a[r] != b[j])
				{
					r += 1;
				}
				if (r >= n)
				{
					return -1;
				}
				auto hi = maxElement (a[i + 1..r], int.min);
				int len = r - i - 1;
				auto canBerserk = (max (a[i], a[r]) > hi);
				if (!canBerserk && 0 < len && len < k)
				{
					return -1;
				}

				auto rem = len % k;
				res += y * 1L * rem;
				len -= rem;

				while (len > 0)
				{
					long cur = x;
					if (canBerserk || len > k)
					{
						cur = min (cur, y * 1L * k);
					}
					res += cur;
					len -= k;
				}
				i = r;
			}
			return res;
		}

		writeln (solve ());
	}
}

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

void main ()
{
	int n, m;
	while (readf !(" %s %s") (n, m) > 0)
	{
		int x, k, y;
		readf !(" %s %s %s") (x, k, y);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto b = readln.splitter.map !(to !(int)).array;

		a = int.min ~ a ~ int.min;
		b = int.min ~ b ~ int.min;
		n += 2;
		m += 2;

		long solve ()
		{
			long res = 0;
			int i = 0;
			foreach (j; 1..m)
			{
				int r = i;
				while (r < n && a[r] != b[j])
				{
					r += 1;
				}
				if (r >= n)
				{
					return -1;
				}
				auto hi = maxElement (a[i + 1..r], int.min);
				int len = r - i - 1;
				auto canBerserk = (max (a[i], a[r]) <= hi);
				if (canBerserk && 0 < len && len < k)
				{
					return -1;
				}

				auto rem = len % k;
				res += y * 1L * rem;
				len -= rem;

				while (len > 0)
				{
					long cur = x;
					if ((canBerserk || len > k) &&
					    y * 1L * k < x)
					{
						cur = min (cur, y * 1L * k);
					}
					res += cur;
					len -= k;
				}
				i = r;
			}
			return res;
		}

		writeln (solve ());
	}
}


To celebrate your birthday you have prepared a festive table! Now you want to seat as many guests as possible.The table can be represented as a rectangle with height $$$h$$$ and width $$$w$$$, divided into $$$h \times w$$$ cells. Let $$$(i, j)$$$ denote the cell in the $$$i$$$-th row and the $$$j$$$-th column of the rectangle ($$$1 \le i \le h$$$; $$$1 \le j \le w$$$).Into each cell of the table you can either put a plate or keep it empty.As each guest has to be seated next to their plate, you can only put plates on the edge of the table — into the first or the last row of the rectangle, or into the first or the last column. Formally, for each cell $$$(i, j)$$$ you put a plate into, at least one of the following conditions must be satisfied: $$$i = 1$$$, $$$i = h$$$, $$$j = 1$$$, $$$j = w$$$.To make the guests comfortable, no two plates must be put into cells that have a common side or corner. In other words, if cell $$$(i, j)$$$ contains a plate, you can't put plates into cells $$$(i - 1, j)$$$, $$$(i, j - 1)$$$, $$$(i + 1, j)$$$, $$$(i, j + 1)$$$, $$$(i - 1, j - 1)$$$, $$$(i - 1, j + 1)$$$, $$$(i + 1, j - 1)$$$, $$$(i + 1, j + 1)$$$.Put as many plates on the table as possible without violating the rules above.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Each of the following $$$t$$$ lines describes one test case and contains two integers $$$h$$$ and $$$w$$$ ($$$3 \le h, w \le 20$$$) — the height and the width of the table.

For each test case, print $$$h$$$ lines containing $$$w$$$ characters each. Character $$$j$$$ in line $$$i$$$ must be equal to $$$1$$$ if you are putting a plate into cell $$$(i, j)$$$, and $$$0$$$ otherwise. If there are multiple answers, print any. All plates must be put on the edge of the table. No two plates can be put into cells that have a common side or corner. The number of plates put on the table under these conditions must be as large as possible. You are allowed to print additional empty lines.

NoteFor the first test case, example output contains the only way to put $$$6$$$ plates on the table.For the second test case, there are many ways to put $$$4$$$ plates on the table, example output contains one of them.Putting more than $$$6$$$ plates in the first test case or more than $$$4$$$ plates in the second test case is impossible.

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

void main()
{
	int t = readInt!int;
	while (t--) solve;

}

void solve()
{
	int h = readInt!int;
	int w = readInt!int;
	if (w % 2 == 1 && h % 2 == 1)
	{
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
				{
					write((i + j + 1)%2);
				}
				else write(0);
			}
			writeln;
		}
		writeln;
		return;
	}
	else if (w % 2 == 0 && h % 2 == 0)
	{
		auto ans = new int[][](h, w);
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if(i == 0 || i == h - 1)
				{
					ans[i][j] = (i + j)%2;
					continue;
				}
				if (j == 0 || j == w - 1)
				{
					ans[i][j] = (i + j + 1)%2;
				}
			}
		}
		ans[0][0] = ans[0][w-1] = ans[h-1][0] = ans[h-1][w-1] = 0;
		foreach(row; ans) { row.each!write; writeln; }
		writeln;
		return;
	}
	foreach(i; 0 .. h)
	{
		foreach(j; 0 .. w)
		{
			if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
			{
				int ch = w%2;
				if (i == 0 && j == 0 || i == h - 1 &&  j == w - 1) {0.write; continue;}
				if (i == 0 || j == w - 1)
				{
					((i+j+ch)%2).write;
				}
				else
				{
					((i + j + 1+ch)%2).write;
				}
			}
			else 0.write;
		}
		writeln;
	}
	writeln;
}

/* INPUT ROUTINES */
int currChar;
static this()
{
	currChar = getchar();
}

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

void popChar()
{
	currChar = getchar();
}

auto readInt(T)()
{
	T num = 0;
	int sgn = 0;
	while (topChar.isWhite)
		popChar;
	while (topChar == '-' || topChar == '+')
	{
		sgn ^= (topChar == '-');
		popChar;
	}
	while (topChar.isDigit)
	{
		num *= 10;
		num += (topChar - '0');
		popChar;
	}
	if (sgn)
		return -num;
	return num;
}

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
/**MODULAR SYSTEM*/
struct Z(immutable long m)
{
	long rep;
	this(long num)
	{
		rep = num;
	}

	Z!m opBinary(string operator)(Z!m rhs)
	{
		static if (operator == "+")
		{
			long result = rhs.rep + this.rep;
			if (result >= m)
				result -= m;
			return Z!m(result);
		}
		else static if (operator == "-")
		{
			long result = this.rep - rhs.rep;
			if (result < 0)
				result += m;
			return Z!m(result);
		}
		else static if (operator == "*")
		{
			long result = this.rep * rhs.rep;
			if (result >= m)
				result %= m;
			return Z!m(result);
		}
		else
			static assert(text("Operator ", operator, " not supported"));
	}

	Z!m opBinary(string operator)(long exponent) if (operator == "^^")
	{
		assert(exponent >= 0);
		Z!m base = this;
		Z!m result = 1;
		while (exponent)
		{
			if (exponent & 1)
				result = result * base;
			base = base * base;
			exponent >>= 1;
		}
		return result;
	}

	invariant
	{
		assert(rep >= 0 && rep < m);
	}
}

import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,
       std.container, std.typecons, std.conv, std.random, std.bigint;

void read(S...)(ref S args) {
  auto input = readln.split;
  assert(input.length == args.length);
  foreach (i, ref arg; args) {
    arg = input[i].to!(S[i]);
  }
}

auto list(T)() { return readln.split.map!(e => e.to!T); }

void main() {
  int t;
  read(t);

  while (t--) {
    int h, w;
    read(h, w);

    auto table = new int[][](h, w);

    table[0][0] = table[0][w - 1] = table[h - 1][0] = table[h - 1][w - 1] = 1;

    foreach (i; 0 .. (h - 3) / 2) {
      table[i * 2 + 2][0] = table[i * 2 + 2][w - 1] = 1;
    }

    foreach (i; 0 .. (w - 3) / 2) {
      table[0][i * 2 + 2] = table[h - 1][i * 2 + 2] = 1;
    }

    foreach (i; 0 .. h) {
      foreach (j; 0 .. w) {
        write(table[i][j]);
      }
      writeln;
    }
    writeln;
  }
}

// code by cutx64

module main;

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

void main() {

  int tests; readf!"%s\n"(tests);
  while(tests--) {
    int n, m;
    readf!"%s %s\n"(n, m);
    bool[][] a = new bool[][](n, m);
    foreach(i; 0 .. n) {
      foreach(j; 0 .. m) {
        if (i == 0 || i == n - 1 || j == 0 || j == m - 1) {
          if (i > 0 && a[i - 1][j]) continue;
          if (i > 0 && j > 0 && a[i - 1][j - 1]) continue;
          if (j > 0 && a[i][j - 1]) continue;
          if (i > 0 && j + 1 < m && a[i - 1][j + 1]) continue;
          a[i][j] = true;
        }
      }
    }
    writefln!"%(%(%d%)\n%)"(a);
  }

} // main

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

bool good(int x, int y, int w, int h, int[][] a)
{
  if (x > 0 && a[x - 1][y])
    return false;
  if (x + 1 < w && a[x + 1][y])
    return false;
  if (y > 0 && a[x][y - 1])
    return false;
  if (y + 1 < h && a[x][y + 1])
    return false;

  if (x > 0 && y > 0 && a[x - 1][y - 1])
    return false;
  if (x + 1 < w && y > 0 && a[x + 1][y - 1])
    return false;
  if (x > 0 && y + 1 < h && a[x - 1][y + 1])
    return false;
  if (x + 1 < w && y + 1 < h && a[x + 1][y + 1])
    return false;

  return true;
}

long solve(int x, int y, int w, int h, int[][] a)
{
  long result = 0;
  while (x < w) {
    if (good(x, y, w, h, a)) {
      result++;
      a[x][y] = 1;
    }
    x++;
  }
  x = w - 1;
  while (y < h) {
    if (good(x, y, w, h, a)) {
      result++;
      a[x][y] = 1;
    }
    y++;
  }
  y = h - 1;
  while (x >= 0) {
    if (good(x, y, w, h, a)) {
      result++;
      a[x][y] = 1;
    }
    x--;
  }
  x = 0;
  while (y >= 0) {
    if (good(x, y, w, h, a)) {
      result++;
      a[x][y] = 1;
    }
    y--;
  }
  return result;
}

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    int h, w;
    readf!" %d %d "(h, w);
    auto a1 = new int[][](w, h);
    auto a2 = new int[][](w, h);
    a1[0][0] = 1;
    a2[1][0] = 1;
    long result1 = solve(0, 0, w, h, a1);
    long result2 = solve(0, 0, w, h, a2);
    if (result1 > result2) {
      foreach (row ; a1.transposed) {
        writeln(row.map!text.joiner(""));
      }
      writeln;
    } else {
      foreach (row ; a2.transposed) {
        writeln(row.map!text.joiner(""));
      }
      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)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

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

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

		ans[ti].length = h;
		foreach (i; 0..h)
		{
			ans[ti][i].length = w;
			foreach (j; 0..w)
			{
				ans[ti][i][j] = '0';
			}
		}
		foreach (i; 0..w)
		{
			if (i % 2 == 0)
			{
				ans[ti][0][i] = '1';
				ans[ti][h-1][i] = '1';
			}
		}
		foreach (i; 2..h-2)
		{
			if (i % 2 == 0)
			{
				ans[ti][i][0] = '1';
				ans[ti][i][w-1] = '1';
			}
		}
	}

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

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const M = readInt();
        const N = readInt();

        auto ans = new char[][](M, N);
        foreach (x; 0 .. M) {
          ans[x][] = '0';
        }
        ans[0][0] = ans[0][N - 1] = ans[M - 1][0] = ans[M - 1][N - 1] = '1';
        for (int y = 2; y < N - 2; y += 2) {
          ans[0][y] = ans[M - 1][y] = '1';
        }
        for (int x = 2; x < M - 2; x += 2) {
          ans[x][0] = ans[x][N - 1] = '1';
        }

        foreach (x; 0 .. M) {
          writeln(ans[x]);
        }
        writeln;
      }
    }
  } catch (EOFException e) {
  }
}

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 rows, cols;
		readf !(" %s %s") (rows, cols);
		auto s = new bool [] [] (rows, cols);
		foreach (row; 0..rows)
		{
			foreach (col; 0..cols)
			{
				if (row == 0 || row == rows - 1 ||
				    col == 0 || col == cols - 1)
				{
					if (row > 0 && s[row - 1][col])
					{
						continue;
					}
					if (row > 0 && col > 0 &&
					    s[row - 1][col - 1])
					{
						continue;
					}
					if (col > 0 && s[row][col - 1])
					{
						continue;
					}
					if (row > 0 && col + 1 < cols &&
					    s[row - 1][col + 1])
					{
						continue;
					}
					s[row][col] = true;
				}
			}
		}
		writefln !("%(%(%d%)\n%)\n") (s);
	}
}

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

void main()
{
	int t = readInt!int;
	while (t--) solve;

}

void solve()
{
	int h = readInt!int;
	int w = readInt!int;
	if (w % 2 == 1 && h % 2 == 1)
	{
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
				{
					write((i + j + 1)%2);
				}
				else write(0);
			}
			writeln;
		}
		writeln;
		return;
	}
	else if (w % 2 == 0 && h % 2 == 0)
	{
		auto ans = new int[][](h, w);
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if(i == 0 || i == h - 1)
				{
					ans[i][j] = (i + j)%2;
					continue;
				}
				if (j == 0 || j == w - 1)
				{
					ans[i][j] = (i + j + 1)%2;
				}
			}
		}
		ans[0][0] = ans[0][w-1] = ans[h-1][0] = ans[h-1][w-1] = 0;
		foreach(row; ans) { row.each!write; writeln; }
		writeln;
		return;
	}
	foreach(i; 0 .. h)
	{
		foreach(j; 0 .. w)
		{
			if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
			{
				int ch = w%2;
				if (j > i)
				{
					((i+j+ch)%2).write;
				}
				else if (i > j)
				{
					((i + j + 1+ch)%2).write;
				}
				else
				{
					0.write;
				}
			}
			else 0.write;
		}
		writeln;
	}
	writeln;
}

/* INPUT ROUTINES */
int currChar;
static this()
{
	currChar = getchar();
}

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

void popChar()
{
	currChar = getchar();
}

auto readInt(T)()
{
	T num = 0;
	int sgn = 0;
	while (topChar.isWhite)
		popChar;
	while (topChar == '-' || topChar == '+')
	{
		sgn ^= (topChar == '-');
		popChar;
	}
	while (topChar.isDigit)
	{
		num *= 10;
		num += (topChar - '0');
		popChar;
	}
	if (sgn)
		return -num;
	return num;
}

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
/**MODULAR SYSTEM*/
struct Z(immutable long m)
{
	long rep;
	this(long num)
	{
		rep = num;
	}

	Z!m opBinary(string operator)(Z!m rhs)
	{
		static if (operator == "+")
		{
			long result = rhs.rep + this.rep;
			if (result >= m)
				result -= m;
			return Z!m(result);
		}
		else static if (operator == "-")
		{
			long result = this.rep - rhs.rep;
			if (result < 0)
				result += m;
			return Z!m(result);
		}
		else static if (operator == "*")
		{
			long result = this.rep * rhs.rep;
			if (result >= m)
				result %= m;
			return Z!m(result);
		}
		else
			static assert(text("Operator ", operator, " not supported"));
	}

	Z!m opBinary(string operator)(long exponent) if (operator == "^^")
	{
		assert(exponent >= 0);
		Z!m base = this;
		Z!m result = 1;
		while (exponent)
		{
			if (exponent & 1)
				result = result * base;
			base = base * base;
			exponent >>= 1;
		}
		return result;
	}

	invariant
	{
		assert(rep >= 0 && rep < m);
	}
}

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

void main()
{
	int t = readInt!int;
	while (t--) solve;

}

void solve()
{
	int h = readInt!int;
	int w = readInt!int;
	if (w % 2 == 1 && h % 2 == 1)
	{
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
				{
					write((i + j + 1)%2);
				}
				else write(0);
			}
			writeln;
		}
		writeln;
		return;
	}
	else if (w % 2 == 0 && h % 2 == 0)
	{
		auto ans = new int[][](h, w);
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if(i == 0 || i == h - 1)
				{
					ans[i][j] = (i + j)%2;
					continue;
				}
				if (j == 0 || j == w - 1)
				{
					ans[i][j] = (i + j + 1)%2;
				}
			}
		}
		ans[0][0] = ans[0][w-1] = ans[h-1][0] = ans[h-1][w-1] = 0;
		foreach(row; ans) { row.each!write; writeln; }
		writeln;
		return;
	}
	foreach(i; 0 .. h)
	{
		foreach(j; 0 .. w)
		{
			if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
			{
				if (j > i)
				{
					((i+j)%2).write;
				}
				else if (i > j)
				{
					((i + j + 1)%2).write;
				}
				else
				{
					0.write;
				}
			}
			else 0.write;
		}
		writeln;
	}
	writeln;
}

/* INPUT ROUTINES */
int currChar;
static this()
{
	currChar = getchar();
}

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

void popChar()
{
	currChar = getchar();
}

auto readInt(T)()
{
	T num = 0;
	int sgn = 0;
	while (topChar.isWhite)
		popChar;
	while (topChar == '-' || topChar == '+')
	{
		sgn ^= (topChar == '-');
		popChar;
	}
	while (topChar.isDigit)
	{
		num *= 10;
		num += (topChar - '0');
		popChar;
	}
	if (sgn)
		return -num;
	return num;
}

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
/**MODULAR SYSTEM*/
struct Z(immutable long m)
{
	long rep;
	this(long num)
	{
		rep = num;
	}

	Z!m opBinary(string operator)(Z!m rhs)
	{
		static if (operator == "+")
		{
			long result = rhs.rep + this.rep;
			if (result >= m)
				result -= m;
			return Z!m(result);
		}
		else static if (operator == "-")
		{
			long result = this.rep - rhs.rep;
			if (result < 0)
				result += m;
			return Z!m(result);
		}
		else static if (operator == "*")
		{
			long result = this.rep * rhs.rep;
			if (result >= m)
				result %= m;
			return Z!m(result);
		}
		else
			static assert(text("Operator ", operator, " not supported"));
	}

	Z!m opBinary(string operator)(long exponent) if (operator == "^^")
	{
		assert(exponent >= 0);
		Z!m base = this;
		Z!m result = 1;
		while (exponent)
		{
			if (exponent & 1)
				result = result * base;
			base = base * base;
			exponent >>= 1;
		}
		return result;
	}

	invariant
	{
		assert(rep >= 0 && rep < m);
	}
}

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

void main()
{
	int t = readInt!int;
	while (t--) solve;

}

void solve()
{
	int h = readInt!int;
	int w = readInt!int;
	if (w % 2 == 1 && h % 2 == 1)
	{
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
				{
					write((i + j + 1)%2);
				}
				else write(0);
			}
			writeln;
		}
		writeln;
		return;
	}
	else if (w % 2 == 0 && h % 2 == 0)
	{
		auto ans = new int[][](h, w);
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if(i == 0 || i == h - 1)
				{
					ans[i][j] = (i + j)%2;
					continue;
				}
				if (j == 0 || j == w - 1)
				{
					ans[i][j] = (i + j + 1)%2;
				}
			}
		}
		ans[0][0] = ans[0][h-1] = ans[w-1][0] = ans[w-1][h-1] = 0;
		foreach(row; ans) { row.each!write; writeln; }
		writeln;
	}
	foreach(i; 0 .. h)
	{
		foreach(j; 0 .. w)
		{
			if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
			{
				if (j > i)
				{
					((i+j)%2).write;
				}
				else if (i > j)
				{
					((i + j + 1)%2).write;
				}
				else
				{
					0.write;
				}
			}
			else 0.write;
		}
		writeln;
	}
	writeln;
}

/* INPUT ROUTINES */
int currChar;
static this()
{
	currChar = getchar();
}

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

void popChar()
{
	currChar = getchar();
}

auto readInt(T)()
{
	T num = 0;
	int sgn = 0;
	while (topChar.isWhite)
		popChar;
	while (topChar == '-' || topChar == '+')
	{
		sgn ^= (topChar == '-');
		popChar;
	}
	while (topChar.isDigit)
	{
		num *= 10;
		num += (topChar - '0');
		popChar;
	}
	if (sgn)
		return -num;
	return num;
}

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
/**MODULAR SYSTEM*/
struct Z(immutable long m)
{
	long rep;
	this(long num)
	{
		rep = num;
	}

	Z!m opBinary(string operator)(Z!m rhs)
	{
		static if (operator == "+")
		{
			long result = rhs.rep + this.rep;
			if (result >= m)
				result -= m;
			return Z!m(result);
		}
		else static if (operator == "-")
		{
			long result = this.rep - rhs.rep;
			if (result < 0)
				result += m;
			return Z!m(result);
		}
		else static if (operator == "*")
		{
			long result = this.rep * rhs.rep;
			if (result >= m)
				result %= m;
			return Z!m(result);
		}
		else
			static assert(text("Operator ", operator, " not supported"));
	}

	Z!m opBinary(string operator)(long exponent) if (operator == "^^")
	{
		assert(exponent >= 0);
		Z!m base = this;
		Z!m result = 1;
		while (exponent)
		{
			if (exponent & 1)
				result = result * base;
			base = base * base;
			exponent >>= 1;
		}
		return result;
	}

	invariant
	{
		assert(rep >= 0 && rep < m);
	}
}

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

void main()
{
	int t = readInt!int;
	while (t--) solve;

}

void solve()
{
	int h = readInt!int;
	int w = readInt!int;
	int l = 2 * h + 2 * w - 4;
	int m = l - l/2;
	int[][] fm;
	bool tryF(int x)
	{
		int t = 0;
		fm = new int[][](h, w);
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
				{
					fm[i][j] = (i + j + x)%2;
					t += fm[i][j];
				}
			}
		}
		if (t == m) return true;
		return false;
	}
	if (tryF(1)) goto print;
	if (tryF(0)) goto print;
	assert(0);
print:
	foreach(row; fm)
	{
		row.each!write; writeln;
	}
	writeln;
}

/* INPUT ROUTINES */
int currChar;
static this()
{
	currChar = getchar();
}

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

void popChar()
{
	currChar = getchar();
}

auto readInt(T)()
{
	T num = 0;
	int sgn = 0;
	while (topChar.isWhite)
		popChar;
	while (topChar == '-' || topChar == '+')
	{
		sgn ^= (topChar == '-');
		popChar;
	}
	while (topChar.isDigit)
	{
		num *= 10;
		num += (topChar - '0');
		popChar;
	}
	if (sgn)
		return -num;
	return num;
}

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
/**MODULAR SYSTEM*/
struct Z(immutable long m)
{
	long rep;
	this(long num)
	{
		rep = num;
	}

	Z!m opBinary(string operator)(Z!m rhs)
	{
		static if (operator == "+")
		{
			long result = rhs.rep + this.rep;
			if (result >= m)
				result -= m;
			return Z!m(result);
		}
		else static if (operator == "-")
		{
			long result = this.rep - rhs.rep;
			if (result < 0)
				result += m;
			return Z!m(result);
		}
		else static if (operator == "*")
		{
			long result = this.rep * rhs.rep;
			if (result >= m)
				result %= m;
			return Z!m(result);
		}
		else
			static assert(text("Operator ", operator, " not supported"));
	}

	Z!m opBinary(string operator)(long exponent) if (operator == "^^")
	{
		assert(exponent >= 0);
		Z!m base = this;
		Z!m result = 1;
		while (exponent)
		{
			if (exponent & 1)
				result = result * base;
			base = base * base;
			exponent >>= 1;
		}
		return result;
	}

	invariant
	{
		assert(rep >= 0 && rep < m);
	}
}

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

void main()
{
	int t = readInt!int;
	while (t--) solve;

}

void solve()
{
	int h = readInt!int;
	int w = readInt!int;
	int l = 2 * h + 2 * w - 4;
	int m = l - l/2;
	int[][] fm;
	bool tryF(int x)
	{
		int t = 0;
		fm = new int[][](h, w);
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
				{
					fm[i][j] = (i + j + x)%2;
					t += fm[i][j];
				}
			}
		}
		if (t == m) return true;
		return false;
	}
	if (tryF(0)) goto print;
	if (tryF(1)) goto print;
	assert(0);
print:
	foreach(row; fm)
	{
		row.each!write; writeln;
	}
	writeln;
}

/* INPUT ROUTINES */
int currChar;
static this()
{
	currChar = getchar();
}

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

void popChar()
{
	currChar = getchar();
}

auto readInt(T)()
{
	T num = 0;
	int sgn = 0;
	while (topChar.isWhite)
		popChar;
	while (topChar == '-' || topChar == '+')
	{
		sgn ^= (topChar == '-');
		popChar;
	}
	while (topChar.isDigit)
	{
		num *= 10;
		num += (topChar - '0');
		popChar;
	}
	if (sgn)
		return -num;
	return num;
}

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
/**MODULAR SYSTEM*/
struct Z(immutable long m)
{
	long rep;
	this(long num)
	{
		rep = num;
	}

	Z!m opBinary(string operator)(Z!m rhs)
	{
		static if (operator == "+")
		{
			long result = rhs.rep + this.rep;
			if (result >= m)
				result -= m;
			return Z!m(result);
		}
		else static if (operator == "-")
		{
			long result = this.rep - rhs.rep;
			if (result < 0)
				result += m;
			return Z!m(result);
		}
		else static if (operator == "*")
		{
			long result = this.rep * rhs.rep;
			if (result >= m)
				result %= m;
			return Z!m(result);
		}
		else
			static assert(text("Operator ", operator, " not supported"));
	}

	Z!m opBinary(string operator)(long exponent) if (operator == "^^")
	{
		assert(exponent >= 0);
		Z!m base = this;
		Z!m result = 1;
		while (exponent)
		{
			if (exponent & 1)
				result = result * base;
			base = base * base;
			exponent >>= 1;
		}
		return result;
	}

	invariant
	{
		assert(rep >= 0 && rep < m);
	}
}


During the hypnosis session, Nicholas suddenly remembered a positive integer $$$n$$$, which doesn't contain zeros in decimal notation. Soon, when he returned home, he got curious: what is the maximum number of digits that can be removed from the number so that the number becomes not prime, that is, either composite or equal to one?For some numbers doing so is impossible: for example, for number $$$53$$$ it's impossible to delete some of its digits to obtain a not prime integer. However, for all $$$n$$$ in the test cases of this problem, it's guaranteed that it's possible to delete some of their digits to obtain a not prime number.Note that you cannot remove all the digits from the number.A prime number is a number that has no divisors except one and itself. A composite is a number that has more than two divisors. $$$1$$$ is neither a prime nor a composite number.

Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 10^3$$$), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$k$$$ ($$$1 \le k \le 50$$$) — the number of digits in the number. The second line of each test case contains a positive integer $$$n$$$, which doesn't contain zeros in decimal notation ($$$10^{k-1} \le n < 10^{k}$$$). It is guaranteed that it is always possible to remove less than $$$k$$$ digits to make the number not prime. It is guaranteed that the sum of $$$k$$$ over all test cases does not exceed $$$10^4$$$.

For every test case, print two numbers in two lines. In the first line print the number of digits, that you have left in the number. In the second line print the digits left after all delitions.  If there are multiple solutions, print any.

NoteIn the first test case, you can't delete $$$2$$$ digits from the number $$$237$$$, as all the numbers $$$2$$$, $$$3$$$, and $$$7$$$ are prime. However, you can delete $$$1$$$ digit, obtaining a number $$$27 = 3^3$$$.In the second test case, you can delete all digits except one, as $$$4 = 2^2$$$ is a composite number.

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)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

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

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

		auto cnt = new long[](10);
		foreach (c; s)
		{
			++cnt[c-'0'];
		}

		auto set = [1:true, 4:true, 6:true, 8:true, 9:true];
		bool ok;
		foreach (i; 0..10)
		{
			if (set.get(i, false) == false) continue;
			if (cnt[i] > 0)
			{
				ok = true;
				ans[ti] = [cast(char)('0'+i)];
				break;
			}
		}
		if (ok) continue;

		foreach (i; 0..10)
		{
			if (cnt[i] >= 2)
			{
				ok = true;
				ans[ti] ~= [cast(char)('0'+i)];
				ans[ti] ~= [cast(char)('0'+i)];
				break;
			}
		}
		if (ok) continue;

		foreach (i; 1..2^^k)
		{
			string str;
			foreach (j; 0..k)
			{
				auto bit = 1L << j;
				if (i & bit)
				{
					str ~= s[j];
				}
			}
			auto x = str.to!long;
			for (long j = 2; j*j <= x; ++j)
			{
				if (x % j) continue;
				ok = true;
				ans[ti] = str;
				break;
			}
			if (ok) break;
		}
	}
	debug writeln(ans);

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

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

bool check_subsequence(string main, string sub)
{
  int i, j;
  while (i < main.length && j < sub.length) {
    if (main[i] == sub[j]) {
      i++;
      j++;
      continue;
    }
    i++;
  }
  return j == sub.length;
}

void main()
{
  auto nonprimes = ["1", "4", "6", "8", "9", "20", "22", "25", "27", "30", "32", "33", "35", "50", "52", "55", "57", "70", "72", "75", "77"];
  long t;
  readf!" %d "(t);
  while (t--) {
    long n;
    readln.formattedRead!" %d "(n);
    string s = readln.strip;
    bool good = false;
    foreach (nonprime ; nonprimes) {
      if (check_subsequence(s, nonprime)) {
        writeln(nonprime.length);
        writeln(nonprime);
        good = true;
        break;
      }
    }
    if (!good)
      writeln(-1);
  }
}

// Cheese-Cracker: cheese-cracker.github.io
int[] primes;
void prime_sieve(){
    const int sz = 100;
    auto isPrime = new bool[](sz + 1);
    isPrime[] = 1;
    foreach(p; 2..15){
        if(isPrime[p]){
            for(ll divi = p*p; divi <= sz; divi += p){
                isPrime[divi.to!int] = 0;
            }
        }
    }
    isPrime[0] = 0; isPrime[1] = 0;
    primes = isPrime.enumerate.filter!(a => a[1]).map!(a => a[0].to!(int)).array;
    foreach(k; 2..sz+1){
        if(isPrime[k]) primes ~= k;
    }
}

void theCode(){
    ll k = scan;
    auto n = scan!(dchar[]);
    auto w = "2357".to!(dchar[]);
    ll[4] freq;
    foreach(c; n){
        bool f = 1;
        for(int i = 0; i < 4; ++i){
            dchar d = w[i];
            if(c == d){
                ++freq[i];
                f = 0;
                break;
            }
        }
        if(f){
            writeln(1);
            writeln(c);
            return;
        }
    }
    for(int i = 0; i < k; ++i){
        int d1 = n[i] - '0';
        for(int j = i+1; j < k; ++j){
            int d2 = n[j] - '0';
            int num = d1* 10 + d2;
            bool f = 1;
            foreach(pm; primes){
                if(num == pm){
                    f = 0;
                }
            }
            if(f){
                writeln(2);
                writeln(num);
                return;
            }
        }
    }
}

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

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

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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

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

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

		auto cnt = new long[](10);
		foreach (c; s)
		{
			++cnt[c-'0'];
		}

		auto set = [1:true, 4:true, 6:true, 8:true];
		bool ok;
		foreach (i; 0..10)
		{
			if (set.get(i, false) == false) continue;
			if (cnt[i] > 0)
			{
				ok = true;
				ans[ti] = [cast(char)('0'+i)];
				break;
			}
		}
		if (ok) continue;

		foreach (i; 0..10)
		{
			if (cnt[i] >= 2)
			{
				ok = true;
				ans[ti] ~= [cast(char)('0'+i)];
				ans[ti] ~= [cast(char)('0'+i)];
				break;
			}
		}
		if (ok) continue;

		foreach (i; 1..2^^k)
		{
			string str;
			foreach (j; 0..k)
			{
				auto bit = 1L << j;
				if (i & bit)
				{
					str ~= s[j];
				}
			}
			auto x = str.to!long;
			for (long j = 2; j*j <= x; ++j)
			{
				if (x % j) continue;
				ok = true;
				ans[ti] = str;
				break;
			}
			if (ok) break;
		}
	}
	debug writeln(ans);

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


Let's call the following process a transformation of a sequence of length $$$n$$$.If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements of the sequence to the result and remove one arbitrary element from the sequence. Thus, when the process ends, we have a sequence of $$$n$$$ integers: the greatest common divisors of all the elements in the sequence before each deletion.You are given an integer sequence $$$1, 2, \dots, n$$$. Find the lexicographically maximum result of its transformation.A sequence $$$a_1, a_2, \ldots, a_n$$$ is lexicographically larger than a sequence $$$b_1, b_2, \ldots, b_n$$$, if there is an index $$$i$$$ such that $$$a_j = b_j$$$ for all $$$j < i$$$, and $$$a_i > b_i$$$.

The first and only line of input contains one integer $$$n$$$ ($$$1\le n\le 10^6$$$).

Output $$$n$$$ integers  — the lexicographically maximum result of the transformation.

NoteIn the first sample the answer may be achieved this way:  Append GCD$$$(1, 2, 3) = 1$$$, remove $$$2$$$.  Append GCD$$$(1, 3) = 1$$$, remove $$$1$$$.  Append GCD$$$(3) = 3$$$, remove $$$3$$$. We get the sequence $$$[1, 1, 3]$$$ as the result.

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

void Add(int n, ref int[] arr, int m) {
    if (n / m == 0) return;
    Add(n, arr, m*2);
    auto v = n / m;
    while (arr.length < v) arr ~= m;
}

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

    if (n <= 3) {
        auto ans = [n].padLeft(1, n);

        ans.writefln!("%(%s %)");
        return;
    }

    int[] ans;
    Add(n, ans, 1);
    if (ans[1] == ans[2]) ans[0] += ans[1];
    ans.reverse();

    ans.writefln!("%(%s %)");
}

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

void main() {
    int n;
    scan(n);

    int m = n;
    int p = 1;
    int[] ans;

    while (m > 0) {
        if (m == 3) {
            ans ~= p;
            ans ~= p;
            ans ~= p * 3;
            break;
        }
        foreach (i ; 0 .. (m + 1) / 2) {
            ans ~= p;
        }
        m -= (m + 1) / 2;
        p *= 2;
    }

    writefln("%(%s %)", ans);
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n;
  rd(n);
  int g = 1;
  int[] ans;
  while (n) {
    if (n == 3) {
      ans ~= g;
      ans ~= g;
      ans ~= g * 3;
      break;
    }
    int k = (n + 1) / 2;
    n -= k;
    foreach (_; 0 .. k)
      ans ~= g;
    g *= 2;
  }
  writefln("%(%s %)", ans);

}

// 5 => 1 1 1 2 4
// 6 => 1 1 1 2 2 6
// 7 => 1 1 1 1 2 2 6
// 8 => 1 1 1 1 2 2 4 8
// 10 => 1 1 1 1 1 2 2 2 4 8
// 12 => 1 1 1 1 1 1 2 2 2 4 4 12

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}

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

immutable int MD = 998244353;

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

    if (n <= 3) {
        auto ans = [n].padLeft(1, n);

        ans.writefln!("%(%s %)");
        return;
    }

    auto pws = recurrence!((a,n) => a[n-1] * 2)(2).until!(x => x > n).array;

    auto ans = pws.padLeft(1, n);

    ans.writefln!("%(%s %)");
}

void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n;
  rd(n);
  import std.range : iota;
  import std.array : array;
  import std.numeric : gcd;

  auto a = iota(1, n + 1).filter!((val) => val % 2 == 0).array;
  int[] result;
  foreach (_; 0 .. (n - a.length))
    result ~= 1;
  while (result.length < n) {
    int[] b;
    if (a.length <= 2) {
      auto g = gcd(a[0], a[$ - 1]);
      result ~= g;
      if (a.length > 1) {
        b ~= a[$ - 1];
      }
    } else {
      auto g = reduce!((gg, val) => gcd(gg, val))(0, a);
      result ~= g;
      foreach (val; a[1 .. $]) {
        if (val % g == 0) {
          b ~= val;
        }
      }
      int[] b2;
      foreach (val; a[1 .. $]) {
        if (val % a[1] == 0) {
          b2 ~= val;
        }
      }
      if (b2.length >= 2) {
        b = b2.dup;
      }
      foreach (_; 0 .. (a.length - b.length - 1)) {
        result ~= g;
      }
    }
    a.swap(b);
  }
  writefln("%(%s %)", result);
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


An array $$$b$$$ of length $$$k$$$ is called good if its arithmetic mean is equal to $$$1$$$. More formally, if $$$$$$\frac{b_1 + \cdots + b_k}{k}=1.$$$$$$Note that the value $$$\frac{b_1+\cdots+b_k}{k}$$$ is not rounded up or down. For example, the array $$$[1,1,1,2]$$$ has an arithmetic mean of $$$1.25$$$, which is not equal to $$$1$$$.You are given an integer array $$$a$$$ of length $$$n$$$. In an operation, you can append a non-negative integer to the end of the array. What's the minimum number of operations required to make the array good?We have a proof that it is always possible with finitely many operations.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$) — the length of the initial array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1,\ldots,a_n$$$ ($$$-10^4\leq a_i \leq 10^4$$$), the elements of the array.

For each test case, output a single integer — the minimum number of non-negative integers you have to append to the array so that the arithmetic mean of the array will be exactly $$$1$$$.

NoteIn the first test case, we don't need to add any element because the arithmetic mean of the array is already $$$1$$$, so the answer is $$$0$$$.In the second test case, the arithmetic mean is not $$$1$$$ initially so we need to add at least one more number. If we add $$$0$$$ then the arithmetic mean of the whole array becomes $$$1$$$, so the answer is $$$1$$$.In the third test case, the minimum number of elements that need to be added is $$$16$$$ since only non-negative integers can be added.In the fourth test case, we can add a single integer $$$4$$$. The arithmetic mean becomes $$$\frac{-2+4}{2}$$$ which is equal to $$$1$$$.

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

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

while(t--) {
    long n = readln.chomp.to!long;
    long[] a = readln.split.map!(to!long).array;
    long sum = a.sum;

    if(sum < n) {
        "1".writeln;
        continue;
    }
    writefln("%s", sum - n);
}
}

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

void main()
{
  long t, n;
  readf!" %d "(t);

  while (t--) {
    readf!" %d "(n);
    auto a = readln.strip.split.map!(to!long);
    long sum = a.sum;
    long result = 0;
    if (sum - n >= 0) {
      writeln(sum - n);
    } else {
      writeln(1);
    }
  }
}

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

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

while(t--) {
    long n = readln.chomp.to!long;
    long[] a = readln.split.map!(to!long).array;
    long sum = a.sum;

    if(sum <= 0) {
        "1".writeln;
        continue;
    }
    writefln("%s", sum - n);
}
}

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

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

while(t--) {
    int n = readln.chomp.to!int;
    int[] a = readln.split.map!(to!int).array;
    long sum = a.sum;

    if(sum <= 0) {
        "1".writeln;
        continue;
    }
    writefln("%s", sum - n);
}
}


Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Roma's got n positive integers. He wonders, how many of those integers have not more than k lucky digits? Help him, write the program that solves the problem.

The first line contains two integers n, k (1 ≤ n, k ≤ 100). The second line contains n integers ai (1 ≤ ai ≤ 109) — the numbers that Roma has.  The numbers in the lines are separated by single spaces.

In a single line print a single integer — the answer to the problem.

NoteIn the first sample all numbers contain at most four lucky digits, so the answer is 3.In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2.

import std.stdio;

int main() {
    int N, K;
    readf(" %s %s", &N, &K);
    int ans = 0;
    foreach (i; 0..N) {
        int n;
        readf(" %s", &n);
        int nd = 0;
        while (n > 0) {
            int d = n % 10;
            n /= 10;
            if (d == 4 || d == 7) {
                nd++;
            }
        }
        if (nd <= K) {
            ans++;
        }
    }
    writefln("%s", ans);
    return 0;
}

import std.stdio : write, writeln, writefln, stdin;
import std.array;
import std.range;
import std.typecons;
import std.algorithm : max, min;

int n;
int k;
void main(){
	n.next;
	k.next;

	int cnt;
	foreach(i; n.iota){
		string str = next!string();
		int con;
		foreach(c; str){
			if( c == '4' || c == '7' ) ++con;
		}
		if( con <= k ) ++cnt;
	}

	cnt.writeln;
}

import std.stdio : readln;
import std.conv : to;
import std.string : split, chomp;
shared string[] input;
shared string delim = " ";
T next(T)()
in
{
	assert(hasNext());
}
out
{
	input.popFront;
}
body
{
	return input.front.to!T;
}

void next(T)(ref T v){
	v = next!T();
}

bool hasNext(){
	if(input.length > 0){
		return true;
	}

	string str = readln;
	if(str.length > 0){
		input ~= str.chomp.split(delim);
		return true;
	}else{
		return false;
	}
}

void dbg(T...)(T vs)
{
	import std.stdio : stderr;
	foreach(v; vs)
		stderr.write(v.to!string ~ " ");
	stderr.write("\n");
}

T clone(T)(T v){
	T v_;
	static if(isInputRange!(T)){
		foreach(ite; v){
			v_ ~= ite.clone;
		}
	}else{
		v_ = v;
	}

	return v_;
}


While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s.  He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.

The first line of input contains string s containing lowercase English letters (1 ≤ |s| ≤ 1000). The second line contains integer k (1 ≤ k ≤ 1000).

Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.

NotePalindrome is a string reading the same forward and backward.In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".

import std.math,
       std.conv,
       std.stdio,
       std.ascii,
       std.range,
       std.array,
       std.regex,
       std.format,
       std.bigint,
       std.traits,
       std.string,
       std.numeric,
       std.variant,
       std.typecons,
       std.algorithm,
       std.typetuple,
       std.exception;

void main() {

	char[] s = readln.strip.dup;
	int k = readln.strip.to!int;

	if (s.length < k || s.length % k != 0) {
		writeln("NO");
		return;
	}

	int ans, i, it = s.length / k, idx = s.length / k;
	while (it <= s.length) {
		debug writeln("s = ", s[i .. it]);
		if (s[i .. it] == s[i .. it].retro.text) {
			++ans;
		}
		else {
			break;
		}
		i = it;
		it += idx;
		debug writefln("i = %s, it = %s, s.len = %s", i, it, s.length);
	}

	writeln(ans == k ? "YES" : "NO");
}

import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInt() {
	return readInts()[0];
}
auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}

bool isPalindrome(string s) {
	foreach(i; 0..s.length) {
		if(s[i] != s[$-i-1]){
			return false;
		}
	}
	return true;
}
void main() {
	auto s = readln().strip();
	auto k = readInt();
	if(s.length%k != 0) {
		writeln("NO");
		return;
	}
	foreach(i; 0..k) {
		auto t = s[s.length/k*i..s.length/k*(i+1)];
		if(!isPalindrome(t)){
			writeln("NO");
			return;
		}
	}
	writeln("YES");
}

import std.math,
       std.conv,
       std.stdio,
       std.ascii,
       std.range,
       std.array,
       std.regex,
       std.format,
       std.bigint,
       std.traits,
       std.string,
       std.numeric,
       std.variant,
       std.typecons,
       std.algorithm,
       std.typetuple,
       std.exception;

void main() {

	char[] s = readln.strip.dup;
	int k = readln.strip.to!int;

	if (s.length < k) {
		writeln("NO");
		return;
	}

	int ans, i, it = s.length / k, idx = s.length / k;
	while (it <= s.length) {
		debug writeln("s = ", s[i .. it]);
		if (s[i .. it] == s[i .. it].retro.text) {
			++ans;
		}
		else {
			break;
		}
		i = it;
		it += idx;
		debug writefln("i = %s, it = %s, s.len = %s", i, it, s.length);
	}

	writeln(ans == k ? "YES" : "NO");
}

import std.math,
       std.conv,
       std.stdio,
       std.ascii,
       std.range,
       std.array,
       std.regex,
       std.format,
       std.bigint,
       std.traits,
       std.string,
       std.numeric,
       std.variant,
       std.typecons,
       std.algorithm,
       std.typetuple,
       std.exception;

void main() {

	char[] s = readln.strip.dup;
	int k = readln.strip.to!int;

	int ans, i, it = s.length / k;
	while (it <= s.length) {
		debug writeln("s = ", s[i .. it]);
		if (s[i .. it] == s[i .. it].retro.to!string) {
			++ans;
		}
		i = it;
		it += k;
		debug writefln("i = %s, it = %s, s.len = %s", i, it, s.length);
	}

	writeln(ans == k ? "YES" : "NO");
}


A positive integer is called composite if it can be represented as a product of two positive integers, both greater than $$$1$$$. For example, the following numbers are composite: $$$6$$$, $$$4$$$, $$$120$$$, $$$27$$$. The following numbers aren't: $$$1$$$, $$$2$$$, $$$3$$$, $$$17$$$, $$$97$$$.Alice is given a sequence of $$$n$$$ composite numbers $$$a_1,a_2,\ldots,a_n$$$.She wants to choose an integer $$$m \le 11$$$ and color each element one of $$$m$$$ colors from $$$1$$$ to $$$m$$$ so that:  for each color from $$$1$$$ to $$$m$$$ there is at least one element of this color;  each element is colored and colored exactly one color;  the greatest common divisor of any two elements that are colored the same color is greater than $$$1$$$, i.e. $$$\gcd(a_i, a_j)>1$$$ for each pair $$$i, j$$$ if these elements are colored the same color. Note that equal elements can be colored different colors — you just have to choose one of $$$m$$$ colors for each of the indices from $$$1$$$ to $$$n$$$.Alice showed already that if all $$$a_i \le 1000$$$ then she can always solve the task by choosing some $$$m \le 11$$$.Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some $$$m$$$ from $$$1$$$ to $$$11$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then the descriptions of the test cases follow. The first line of the test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the amount of numbers in a sequence $$$a$$$. The second line of the test case contains $$$n$$$ composite integers $$$a_1,a_2,\ldots,a_n$$$ ($$$4 \le a_i \le 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^4$$$.

For each test case print $$$2$$$ lines. The first line should contain a single integer $$$m$$$ ($$$1 \le m \le 11$$$) — the number of used colors. Consider colors to be numbered from $$$1$$$ to $$$m$$$. The second line should contain any coloring that satisfies the above conditions. Print $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le m$$$), where $$$c_i$$$ is the color of the $$$i$$$-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some $$$m$$$ from $$$1$$$ to $$$11$$$. Remember that each color from $$$1$$$ to $$$m$$$ should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than $$$1$$$).

NoteIn the first test case, $$$\gcd(6,10)=2$$$, $$$\gcd(6,15)=3$$$ and $$$\gcd(10,15)=5$$$. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case.In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.

// problem: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_A
// require: graph/articulation_points.d

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;

const int[] P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31];

void solve() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto B = new int[](N);

    foreach (i, a; A) foreach (j, p; P) {
        if (a % p == 0) {
            B[i.to!int] = j.to!int + 1;
            break;
        }
    }

    auto X = B.dup.sort().uniq.array;
    int[int] Y;
    foreach (i; 0..X.length.to!int) Y[X[i]] = i + 1;
    foreach (i; 0..N) B[i] = Y[B[i]];
    X.length.writeln;
    B.map!(to!string).join(" ").writeln;
}

void main() {
    auto T = readln.chomp.to!int;
    while (T--) {
        solve();
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		ans[ti].length = n;
		bool[int] set;
		foreach (i; 0..n)
		{
			for (int j = 2; j*j <= a[i]; ++j)
			{
				if (a[i] % j == 0)
				{
					set[j] = true;
					ans[ti][i] = j;
					break;
				}
			}
		}
		auto keys = set.keys;
		m[ti] = cast(int)keys.length;
		int[int] keyToNum;
		foreach (i, key; keys)
		{
			keyToNum[key] = cast(int)(i+1);
		}
		foreach (i; 0..n)
		{
			ans[ti][i] = keyToNum[ans[ti][i]];
		}
	}

	foreach (ti, e; ans)
	{
		writeln(m[ti]);
		e.map!(to!string).join(" ").writeln;
	}
	stdout.flush;
	debug readln;
}

// problem: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_A
// require: graph/articulation_points.d

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;

const int[] P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31];

void solve() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto B = new int[](N);

    foreach (i, a; A) foreach (j, p; P) {
        if (a % p == 0) {
            B[i.to!int] = j.to!int + 1;
            break;
        }
    }

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

void main() {
    auto T = readln.chomp.to!int;
    while (T--) {
        solve();
    }
}


You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 to n, such that equality holds.

The only line of the input contains a rebus. It's guaranteed that it contains no more than 100 question marks, integer n is positive and doesn't exceed 1 000 000, all letters and integers are separated by spaces, arithmetic operations are located only between question marks.

The first line of the output should contain "Possible" (without quotes) if rebus has a solution and "Impossible" (without quotes) otherwise. If the answer exists, the second line should contain any valid rebus with question marks replaced by integers from 1 to n. Follow the format given in the samples.

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

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		auto t = s.split;
		auto n = t.back.to !(int);
		auto cur = +1;
		auto sign = [cur];
		auto lo = [0];
		auto hi = [0];
		foreach (r; t)
		{
			if (r == "?")
			{
				sign ~= cur;
				lo ~= lo.back + min (1 * cur, n * cur);
				hi ~= hi.back + max (1 * cur, n * cur);
			}
			else if (r == "+")
			{
				cur = +1;
			}
			else if (r == "-")
			{
				cur = -1;
			}
		}
		sign ~= cur;
		if (lo.back <= n && n <= hi.back)
		{
			writeln ("Possible");
			int value = n;
			foreach_reverse (ref r; t)
			{
				if (r == "?")
				{
					sign.popBack ();
					lo.popBack ();
					hi.popBack ();

					int delta = uniform (1, n + 1);
					if (value - delta * sign.back <
					    lo.back)
					{
						delta = sign.back *
						    (value - lo.back);
					}
					if (value - delta * sign.back >
					    hi.back)
					{
						delta = sign.back *
						    (value - hi.back);
					}
					assert (1 <= delta && delta <= n);
					value -= delta * sign.back;
					assert (lo.back <= value &&
					    value <= hi.back);
					r = delta.text;
				}
			}
			t.join (" ").writeln;
		}
		else
		{
			writeln ("Impossible");
		}
	}
}


Nikolay has only recently started in competitive programming, but already qualified to the finals of one prestigious olympiad. There going to be $$$n$$$ participants, one of whom is Nikolay. Like any good olympiad, it consists of two rounds. Tired of the traditional rules, in which the participant who solved the largest number of problems wins, the organizers came up with different rules.Suppose in the first round participant A took $$$x$$$-th place and in the second round — $$$y$$$-th place. Then the total score of the participant A is sum $$$x + y$$$. The overall place of the participant A is the number of participants (including A) having their total score less than or equal to the total score of A. Note, that some participants may end up having a common overall place. It is also important to note, that in both the first and the second round there were no two participants tying at a common place. In other words, for every $$$i$$$ from $$$1$$$ to $$$n$$$ exactly one participant took $$$i$$$-th place in first round and exactly one participant took $$$i$$$-th place in second round.Right after the end of the Olympiad, Nikolay was informed that he got $$$x$$$-th place in first round and $$$y$$$-th place in the second round. Nikolay doesn't know the results of other participants, yet he wonders what is the minimum and maximum place he can take, if we consider the most favorable and unfavorable outcome for him. Please help Nikolay to find the answer to this question.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases to solve. Each of the following $$$t$$$ lines contains integers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \leq n \leq 10^9$$$, $$$1 \le x, y \le n$$$) — the number of participants in the olympiad, the place that Nikolay took in the first round and the place that Nikolay took in the second round.

Print two integers — the minimum and maximum possible overall place Nikolay could take.

NoteExplanation for the first example:Suppose there were 5 participants A-E. Let's denote Nikolay as A. The the most favorable results for Nikolay could look as follows:  However, the results of the Olympiad could also look like this:  In the first case Nikolay would have taken first place, and in the second — third place.

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.ascii, std.typecons;

void main()
{
    auto t = readln.chomp.to!int;
    while (t--) {
        auto v = readln.chomp.split.map!(to!int);
        auto n = v[0], x = v[1], y = v[2];

        int mn = n - min(n-1, max(0,
            max(0, n-x-1) + max(0, n-y-1) + (max(x, y) < n ? 1 : 0)));
        int mx = min(n, x-1 + y-1 + 1);

        writeln(mn, ' ', mx);
    }
}

module main;

import std.stdio : writeln;

struct IO {
    string readToken() {
        import std.range : empty, front, popFront, split;
        import std.stdio : readln;

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

    int readInt() {
        import std.conv : to;

        return readToken.to!int;
    }

    string[] tokens;
}

void main() {
    import std.algorithm : max, min;

    IO io;
    int T = io.readInt;
    while (T--) {
        int n = io.readInt;
        int x = io.readInt;
        int y = io.readInt;
        writeln(min(max(x + y - n + 1, 1), n), " ", min(x + y - 1, n));
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		if (x + y < n + 1)
		{
			ans[ti][0] = 1;
		}
		else
		{
			ans[ti][0] = min((x+y) - (n+1) + 2, n);
		}
		ans[ti][1] = min(x+y-1, n);
	}

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

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.ascii, std.typecons;

void main()
{
    auto t = readln.chomp.to!int;
    while (t--) {
        auto v = readln.chomp.split.map!(to!int);
        auto n = v[0], x = v[1], y = v[2];

        int mn = n - min(n-1, n-x-1 + n-y-1 + (max(x, y) < n ? 1 : 0));
        int mx = min(n, x-1 + y-1 + 1);

        writeln(mn, ' ', mx);
    }
}

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.ascii, std.typecons;

void main()
{
    auto t = readln.chomp.to!int;
    while (t--) {
        auto v = readln.chomp.split.map!(to!int);
        auto n = v[0], x = v[1], y = v[2];

        int mn = n - min(n-1, max(0, n-x-1 + n-y-1 + (max(x, y) < n ? 1 : 0)));
        int mx = min(n, x-1 + y-1 + 1);

        writeln(mn, ' ', mx);
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		if (x + y < n + 1)
		{
			ans[ti][0] = 1;
		}
		else
		{
			ans[ti][0] = min((x+y) - (n+1) + 2, n);
		}
		ans[ti][1] = x+y-1;
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

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

		if (x + y < n + 1)
		{
			ans[ti][0] = 1;
		}
		else
		{
			ans[ti][0] = (x+y) - (n+1) + 2;
		}
		ans[ti][1] = x+y-1;
	}

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