A permutation of length $$$n$$$ is an array $$$p=[p_1,p_2,\dots,p_n]$$$, which contains every integer from $$$1$$$ to $$$n$$$ (inclusive) and, moreover, each number appears exactly once. For example, $$$p=[3,1,4,2,5]$$$ is a permutation of length $$$5$$$.For a given number $$$n$$$ ($$$n \ge 2$$$), find a permutation $$$p$$$ in which absolute difference (that is, the absolute value of difference) of any two neighboring (adjacent) elements is between $$$2$$$ and $$$4$$$, inclusive. Formally, find such permutation $$$p$$$ that $$$2 \le |p_i - p_{i+1}| \le 4$$$ for each $$$i$$$ ($$$1 \le i < n$$$).Print any such permutation for the given integer $$$n$$$ or determine that it does not exist.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is described by a single line containing an integer $$$n$$$ ($$$2 \le n \le 1000$$$).

Print $$$t$$$ lines. Print a permutation that meets the given requirements. If there are several such permutations, then print any of them. If no such permutation exists, print -1.

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_t; 0..T) {
        auto N = readln.chomp.to!int;
        if (N <= 3) {
            writeln(-1);
            continue;
        }

        auto rs = new int[](N);
        auto i = (N-1)/2;
        rs[i] = N;
        rs[i-1] = N-2;
        rs[i+1] = N-3;
        rs[i+2] = N-1;
        size_t l = i-2, r = i+3;
        auto n = N-4;
        for (;;) {
            if (n <= 0) break;
            rs[l--] = n--;
            if (n <= 0) break;
            rs[r++] = n--;
        }
        writeln(rs.to!(string[]).join(" "));
    }
}

// Author: Ivan Kazmenko (gassa@mail.ru)
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	int [] [int] loops;
	loops[4] = [2, 4, 1, 3];
	loops[5] = [2, 5, 3, 1, 4];
	loops[6] = [2, 6, 4, 1, 3, 5];
	loops[7] = [2, 5, 7, 3, 1, 4, 6];

	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		if (n < 4)
		{
			writeln (-1);
		}
		else
		{
			int [] res;
			while (n > 0)
			{
				int k = (n >= 8) ? 4 : n;
				auto cur = loops[k].dup;
				cur[] += res.length.to !(int);
				res ~= cur;
				n -= k;
			}
			writefln !("%(%s %)") (res);
		}
	}
}

// Author: Ivan Kazmenko (gassa@mail.ru)
// permute at the center
import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
multitest_loop:
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto p = iota (1, n + 1).array;
		p = p.stride (2).array ~ p.drop (1).stride (2).retro.array;
		int lo = max (0, n / 2 - 2);
		int hi = min (n, n / 2 + 2);
		sort (p[lo..hi]);
		do
		{
			if (iota (1, n).all !(i =>
			    abs (p[i] - p[i - 1]) >= 2 &&
			    abs (p[i] - p[i - 1]) <= 4))
			{
				writefln !("%(%s %)") (p);
				continue multitest_loop;
			}
		}
		while (nextPermutation (p[lo..hi]));
		writeln (-1);
	}
}

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

void main() {
	int t = readln.chomp.to!int;
	foreach (tt; 0 .. t) {
		int n = readln.chomp.to!int;
		if (n <= 3) {
			writeln(-1);
			continue;
		}
		int[] res;
		res.assumeSafeAppend ~= iota((n + 1) / 2 + 1)[1 .. $]
			.map!(x => x * 2 - n % 2).array;
		res.assumeSafeAppend ~= [n - 3, n - 1];
		res.assumeSafeAppend ~= iota((n + 1) / 2 - 2, -1, -1)[1 .. $]
			.map!(x => x * 2 - n % 2 + 1).array;
		if (res[$ - 1] == 0) {
			res = res[0 .. $ - 1];
		}
		writeln(res.map!(to!string).join(" "));
	}
}

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

alias type = multi;
struct TestCase
{
  mixin prettyPrinting;

  long n;

  void solve(long tc = -1)
  {
    if (n <= 3)
      return writeln(-1);
    long k = n % 2 == 1? 1 : 2;
    while(k <= n)
      {
        write(k, " ");
        k += 2;
      }
    k = n - 3;
    auto walk = chain([long(+2), long(-4)], repeat(long(-2)));
    while(k >= 1)
      {
        write(k, " ");
        k += walk.front;
        walk.popFront;
      }
    writeln;
  }
}

struct Interval
{
  long l, h;

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

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

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

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

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

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

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

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

DList!string _words;

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

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

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

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

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

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

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

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

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

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

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

    }
}

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

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

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

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

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

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

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

void main()
{
  type;
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		if (n <= 3) continue;
		if (n % 2)
		{
			foreach (i; 0..n/2-2)
			{
				ans[ti] ~= (i+1)*2;
			}
			ans[ti] ~= [n-1, n-3];
			while (n > 0)
			{
				ans[ti] ~= n;
				n -= 2;
			}
		}
		else
		{
			foreach (i; 0..n/2-2)
			{
				ans[ti] ~= i*2+1;
			}
			ans[ti] ~= [n-1, n-3];
			while (n > 0)
			{
				ans[ti] ~= n;
				n -= 2;
			}
		}
	}

	foreach (e; ans)
	{
		if (e.empty)
			writeln(-1);
		else
			e.map!(to!string).join(" ").writeln;
	}
	stdout.flush;
	debug readln;
}


Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").Galya has already made k shots, all of them were misses.Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.It is guaranteed that there is at least one valid ships placement.

The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made. The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.

In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship. In the second line print the cells Galya should shoot at. Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left. If there are multiple answers, you can print any of them.

NoteThere is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.

// Cheese-Cracker: cheese-cracker.github.io
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;

alias ll = long;
alias to!int isz;
alias rbt = redBlackTree;
static string[] inp;
T rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
alias pair = Tuple!(int, int);
/*******************************It's a Me, Mario!**********************************************/

void play(){
    int n, a, b, k;
    n = rd!int; a = rd!int; b = rd!int; k = rd!int;
    dchar[] shots = rd!(dchar[]);
    int cnt = 0;
    int boatmax = 0;
    foreach(i; 0..n){
        if(shots[i] == '1'){
            boatmax += (cnt/b);
            cnt = 0;
        }else{
            ++cnt;
        }
    }
    boatmax += cnt/b;
    debug writeln("boatmax: ", boatmax);
    auto meep = rbt!(true, pair);

    int[] shoot;
    int[int] breaks;
    foreach(i; 0..b-1){
        meep.insert(pair(shots[i]-'0', i));
    }
    foreach(i; b-1..n){
        meep.insert(pair(shots[i]-'0', i));

        if(meep.back[0] != 1){
            meep.removeKey(pair(0, i));
            meep.insert(pair(1, i));
            shots[i] = '1';
            shoot ~= i;
            /* ++breaks[shoot.back]; */
        }else if(shoot.length && meep.back[1] == shoot.back){
            /* breaks[shoot.back] = breaks.get(shoot.back, 0) + 1; */
            /* ++breaks[shoot.back]; */
        }
        meep.removeKey(pair(shots[i-b+1]-'0', i-b+1));
        if(boatmax - shoot.length < a) break;
    }
    writeln(shoot.length);
    foreach(cr; shoot){
        write(cr+1, " ");
    }
    writeln;
}

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

import core.bitop;
import core.checkedint;
import core.simd;
import core.stdc.stdlib;
import core.stdc.string;
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.bitmanip;
import std.complex;
import std.container;
import std.conv;
import std.datetime;
import std.format;
import std.functional;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.regex;
import std.stdio;
import std.string;
import std.typecons;
import std.variant;

__gshared:

bool read(T...)(T ptrs) if (ptrs.length > 0) {
    return readf(' ' ~ replicate("%s ", ptrs.length), ptrs) == ptrs.length;
}

auto pairwise(R)(R range) if (isForwardRange!R) {
    return lockstep(range, dropOne(range));
}

int n, shipCount, shipLen, k;
char[200_003] _s;

void main() {
    while (read(&n, &shipCount, &shipLen, &k)) {
        auto s = _s[ ];
        readln(s);
        s = s[0 .. $ - 1];
        int possible = 0;
        int cur = 0;
        foreach (c; s)
            if (c == '0') {
                if (++cur == shipLen) {
                    possible++;
                    cur = 0;
                }
            } else
                cur = 0;
        assert(possible >= shipCount);
        int need = possible - shipCount + 1;
        writeln(need);
        cur = 0;
        foreach (i, c; s)
            if (c == '0') {
                if (++cur == shipLen) {
                    write(i + 1, ' ');
                    cur = 0;
                    if (!--need)
                        break;
                }
            } else
                cur = 0;
        writeln();
    }
}

// Cheese-Cracker: cheese-cracker.github.io
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;

alias ll = long;
alias to!int isz;
alias rbt = redBlackTree;
static string[] inp;
T rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
/*******************************It's a Me, Mario!**********************************************/

void play(){
    int n, a, b, k;
    n = rd!int; a = rd!int; b = rd!int; k = rd!int;
    dchar[] shots = rd!(dchar[]);
    auto meep = rbt!(true, Tuple!(int, int, int));
    int cnt = 0, firsti = 1, lasti = 1;
    int boatmax = 0;
    foreach(i; 0..n){
        if(shots[i] == '1'){
            if(cnt/b) meep.insert(tuple(cnt, firsti, lasti));
            boatmax += cnt/b;
            firsti = i+2;
            cnt = 0;
        }else{
            ++cnt;
            lasti = i+1;
        }
    }
    if(cnt/b) meep.insert(tuple(cnt, firsti, lasti));
    boatmax += cnt/b;
    int part1, part2;
    int[] shoot;
    while(boatmax >= a && shoot.length < 20){
        // Select Max Broken
        int maxbreak = 0;
        Tuple!(int, int, int) shootout;
        foreach(tup; meep){
            part1 = tup[0]/2;
            part2 = tup[0] - part1 - 1;
            int breaks = (tup[0]/b) - (part1/b) - (part2/b);
            /* debug writeln("Parts: ", part1, " ", part2, " ", breaks); */
            if(breaks >= maxbreak){
                maxbreak = breaks;
                shootout = tup;
            }
        }

        // Break Interval
        meep.removeKey(shootout);
        part1 = shootout[0]/2;
        part2 = shootout[0] - part1 - 1;
        if(part1 >= b) meep.insert(tuple(part1, shootout[1], shootout[1] + part1 - 1));
        if(part2 >= b) meep.insert(tuple(part2, shootout[2] - part2 + 1, shootout[2]));
        // Take the shot
        shoot ~= shootout[2] - part2;
        // Update boatmax
        boatmax -= maxbreak;
        debug writeln(meep);
    }
    writeln(shoot.length);
    foreach(cr; shoot){
        write(cr, " ");
    }
    writeln;
}

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


Anna is a girl so brave that she is loved by everyone in the city and citizens love her cookies. She is planning to hold a party with cookies. Now she has $$$a$$$ vanilla cookies and $$$b$$$ chocolate cookies for the party.She invited $$$n$$$ guests of the first type and $$$m$$$ guests of the second type to the party. They will come to the party in some order. After coming to the party, each guest will choose the type of cookie (vanilla or chocolate) to eat. There is a difference in the way how they choose that type:If there are $$$v$$$ vanilla cookies and $$$c$$$ chocolate cookies at the moment, when the guest comes, then  if the guest of the first type: if $$$v>c$$$ the guest selects a vanilla cookie. Otherwise, the guest selects a chocolate cookie.  if the guest of the second type: if $$$v>c$$$ the guest selects a chocolate cookie. Otherwise, the guest selects a vanilla cookie. After that:  If there is at least one cookie of the selected type, the guest eats one.  Otherwise (there are no cookies of the selected type), the guest gets angry and returns to home. Anna wants to know if there exists some order of guests, such that no one guest gets angry. Your task is to answer her question.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case, the only line contains four integers $$$a$$$, $$$b$$$, $$$n$$$, $$$m$$$ ($$$0 \le a,b,n,m \le 10^{18}, n+m \neq 0$$$).

For each test case, print the answer in one line. If there exists at least one valid order, print "Yes". Otherwise, print "No". You can print each letter in any case (upper or lower).

NoteIn the first test case, let's consider the order $$$\{1, 2, 2\}$$$ of types of guests. Then:  The first guest eats a chocolate cookie. After that, there are $$$2$$$ vanilla cookies and $$$1$$$ chocolate cookie.  The second guest eats a chocolate cookie. After that, there are $$$2$$$ vanilla cookies and $$$0$$$ chocolate cookies.  The last guest selects a chocolate cookie, but there are no chocolate cookies. So, the guest gets angry. So, this order can't be chosen by Anna.Let's consider the order $$$\{2, 2, 1\}$$$ of types of guests. Then:  The first guest eats a vanilla cookie. After that, there is $$$1$$$ vanilla cookie and $$$2$$$ chocolate cookies.  The second guest eats a vanilla cookie. After that, there are $$$0$$$ vanilla cookies and $$$2$$$ chocolate cookies.  The last guest eats a chocolate cookie. After that, there are $$$0$$$ vanilla cookies and $$$1$$$ chocolate cookie. So, the answer to this test case is "Yes".In the fifth test case, it is illustrated, that the number of cookies ($$$a + b$$$) can be equal to zero, but the number of guests ($$$n + m$$$) can't be equal to zero.In the sixth test case, be careful about the overflow of $$$32$$$-bit integer type.

import std.algorithm, std.stdio, std.string;
void main () {
	readln;
	long a, b, n, m;
	while (readf !(" %s %s %s %s") (a, b, n, m) > 0) {
		writeln (min (a, b) >= m && a + b >= n + m ? "Yes" : "No");
	}
}

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

DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

void main()
{
  int t;
  read(t);
 testCase:while(t--)
    {
      long[2] a;
      long n, m;
      read(a[0]), read(a[1]), read(n), read(m);
      sort(a[]);
      if (a[0] >= m)
        {
          long rem = a[0] - m + a[1];
          if (rem >= n)
            {
              writeln("Yes");
              continue testCase;
            }
        }
      writeln("No");
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		if (a+b < n+m) continue;
		if (min(a, b) >= m)
			ans[ti] = true;
	}

	foreach (e; ans)
		writeln(e ? "Yes" : "No");

	stdout.flush;
	debug readln;
}


Three swimmers decided to organize a party in the swimming pool! At noon, they started to swim from the left side of the pool.It takes the first swimmer exactly $$$a$$$ minutes to swim across the entire pool and come back, exactly $$$b$$$ minutes for the second swimmer and $$$c$$$ minutes for the third. Hence, the first swimmer will be on the left side of the pool after $$$0$$$, $$$a$$$, $$$2a$$$, $$$3a$$$, ... minutes after the start time, the second one will be at $$$0$$$, $$$b$$$, $$$2b$$$, $$$3b$$$, ... minutes, and the third one will be on the left side of the pool after $$$0$$$, $$$c$$$, $$$2c$$$, $$$3c$$$, ... minutes.You came to the left side of the pool exactly $$$p$$$ minutes after they started swimming. Determine how long you have to wait before one of the swimmers arrives at the left side of the pool.

The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Next $$$t$$$ lines contains test case descriptions, one per line. Each line contains four integers $$$p$$$, $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \leq p, a, b, c \leq 10^{18}$$$), time in minutes after the start, when you came to the pool and times in minutes it take the swimmers to cross the entire pool and come back.

For each test case, output one integer — how long you have to wait (in minutes) before one of the swimmers arrives at the left side of the pool.

NoteIn the first test case, the first swimmer is on the left side in $$$0, 5, 10, 15, \ldots$$$ minutes after the start time, the second swimmer is on the left side in $$$0, 4, 8, 12, \ldots$$$ minutes after the start time, and the third swimmer is on the left side in $$$0, 8, 16, 24, \ldots$$$ minutes after the start time. You arrived at the pool in $$$9$$$ minutes after the start time and in a minute you will meet the first swimmer on the left side.In the second test case, the first swimmer is on the left side in $$$0, 6, 12, 18, \ldots$$$ minutes after the start time, the second swimmer is on the left side in $$$0, 10, 20, 30, \ldots$$$ minutes after the start time, and the third swimmer is on the left side in $$$0, 9, 18, 27, \ldots$$$ minutes after the start time. You arrived at the pool $$$2$$$ minutes after the start time and after $$$4$$$ minutes meet the first swimmer on the left side.In the third test case, you came to the pool $$$10$$$ minutes after the start time. At the same time, all three swimmers are on the left side. A rare stroke of luck!In the fourth test case, all swimmers are located on the left side in $$$0, 9, 18, 27, \ldots$$$ minutes after the start time. You arrived at the pool $$$10$$$ minutes after the start time and after $$$8$$$ minutes meet all three swimmers on the left side.

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

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

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

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

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

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

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

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

void main()
{
    int T; get(T); while (T--) {
        long P, A, B, C; get(P, A, B, C);
        writeln([A, B, C].map!(x => P <= x ? x - P : P % x == 0 ? 0 : x - P % x).minElement());
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		auto ap = (a - (p % a)) % a;
		auto bp = (b - (p % b)) % b;
		auto cp = (c - (p % c)) % c;
		ans[ti] = min(ap, bp, cp);
	}

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

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

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

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

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

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

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

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

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

void main()
{
    int T; get(T); while (T--) {
        long P, A, B, C; get(P, A, B, C);
        writeln([A, B, C].map!(x => P <= x ? x - P : x - P % x).minElement());
    }
}


British mathematician John Littlewood once said about Indian mathematician Srinivasa Ramanujan that "every positive integer was one of his personal friends."It turns out that positive integers can also be friends with each other! You are given an array $$$a$$$ of distinct positive integers. Define a subarray $$$a_i, a_{i+1}, \ldots, a_j$$$ to be a friend group if and only if there exists an integer $$$m \ge 2$$$ such that $$$a_i \bmod m = a_{i+1} \bmod m = \ldots = a_j \bmod m$$$, where $$$x \bmod y$$$ denotes the remainder when $$$x$$$ is divided by $$$y$$$.Your friend Gregor wants to know the size of the largest friend group in $$$a$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2\cdot 10^4$$$).  Each test case begins with a line containing the integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$), the size of the array $$$a$$$. The next line contains $$$n$$$ positive integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le {10}^{18}$$$), representing the contents of the array $$$a$$$. It is guaranteed that all the numbers in $$$a$$$ are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases is less than $$$2\cdot 10^5$$$.

Your output should consist of $$$t$$$ lines. Each line should consist of a single integer, the size of the largest friend group in $$$a$$$.

NoteIn the first test case, the array is $$$[1,5,2,4,6]$$$. The largest friend group is $$$[2,4,6]$$$, since all those numbers are congruent to $$$0$$$ modulo $$$2$$$, so $$$m=2$$$.In the second test case, the array is $$$[8,2,5,10]$$$. The largest friend group is $$$[8,2,5]$$$, since all those numbers are congruent to $$$2$$$ modulo $$$3$$$, so $$$m=3$$$.In the third case, the largest friend group is $$$[1000,2000]$$$. There are clearly many possible values of $$$m$$$ that work.

import std.stdio;
import std.numeric;
import std.math;
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 n = readInt!int;
	auto a = new long[](n);
	foreach(ref ai; a) ai = readInt!long;
	auto da = new long[](n - 1);
	foreach(i; 0 .. n - 1)
	{
		da[i] = abs(a[i + 1] - a[i]);
	}
	int mxp2 = cast(int)log2(n);
	auto gcdTable = new long[][](mxp2 + 1, n - 1);
	gcdTable[0][] = da[];
	foreach(p; 1 .. mxp2 + 1)
	{
		foreach(i; 0 .. n - 1)
		{
			if (i + (1 << p) <= n - 1)
				gcdTable[p][i] = gcd(gcdTable[p-1][i], gcdTable[p-1][i+(1<<(p-1))]);
		}
	}
	long getGcd(int s, int e)
	{
		if (s > e) return 0;
		int len = e - s + 1;
		int mxp = cast(int)log2(len);
		int mxpn = (1 << mxp);
		long p1 = gcdTable[mxp][s];
		long p2 = gcdTable[mxp][e + 1 - mxpn];
		return gcd(p1, p2);
	}
	debug
	{
		foreach(i; 0 .. n - 1)
		{
			foreach(j; i .. n - 1)
			{
				assert(getGcd(i, j) == da[i .. j + 1].fold!gcd(0L));
			}
		}
	}
	int j = 0;
	int maxlen = 1;
	foreach(i; 0 .. n - 1)
	{
		while (j <= i && getGcd(j, i) == 1) j++;
		maxlen = max(maxlen, i - j + 2);
	}
	maxlen.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;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;

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

		long [] b;
		foreach (i; 1..n)
		{
			b ~= abs (a[i] - a[i - 1]);
		}

		int res = 1;
		int lo = 0;
		long cur = 0;
		for (int hi = 0; hi < n - 1; hi++)
		{
			long next = gcd (cur, b[hi]);
			if (next == 1)
			{
				next = 0;
				lo = hi + 1;
				while (lo > 0)
				{
					long temp = gcd (next, b[lo - 1]);
					if (temp == 1)
					{
						break;
					}
					lo -= 1;
					next = temp;
				}
			}
			cur = next;
			res = max (res, hi - lo + 2);
		}
		writeln (res);
	}
}

import std.stdio;
import std.numeric;
import std.math;
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 n = readInt!int;
	auto a = new long[](n);
	foreach(ref ai; a) ai = readInt!long;
	auto da = new long[](n - 1);
	foreach(i; 0 .. n - 1)
	{
		da[i] = abs(a[i + 1] - a[i]);
	}
	int mxp2 = cast(int)log2(n);
	auto gcdTable = new long[][](mxp2 + 1, n - 1);
	gcdTable[0][] = da[];
	foreach(p; 1 .. mxp2 + 1)
	{
		foreach(i; 0 .. n - 1)
		{
			if (i + (1 << p) <= n - 1)
				gcdTable[p][i] = gcd(gcdTable[p-1][i], gcdTable[p-1][i+(1<<(p-1))]);
		}
	}
	long getGcd(int s, int e)
	{
		if (s > e) return 0;
		int len = e - s + 1;
		int mxp = cast(int)log2(len);
		int mxpn = (1 << mxp);
		long p1 = gcdTable[mxp][s];
		long p2 = gcdTable[mxp][e + 1 - mxpn];
		return gcd(p1, p2);
	}
	int j = 0;
	int maxlen = int.min;
	foreach(i; 0 .. n - 1)
	{
		while (j <= i && getGcd(j, i) == 1) j++;
		maxlen = max(maxlen, i - j + 1);
	}
	(maxlen + 1).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);
	}
}


Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew multiple queries of type "di → ti", that means "replace all digits di in string s with substrings equal to ti". For example, if s = 123123, then query "2 → 00" transforms s to 10031003, and query "3 → " ("replace 3 by an empty string") transforms it to s = 1212. After all the queries Eugene asks Andrew to find the remainder after division of number with decimal representation equal to s by 1000000007 (109 + 7). When you represent s as a decimal number, please ignore the leading zeroes; also if s is an empty string, then it's assumed that the number equals to zero.Andrew got tired of processing Eugene's requests manually and he asked you to write a program for that. Help him!

The first line contains string s (1 ≤ |s| ≤ 105), consisting of digits — the string before processing all the requests. The second line contains a single integer n (0 ≤ n ≤ 105) — the number of queries. The next n lines contain the descriptions of the queries. The i-th query is described by string "di->ti", where di is exactly one digit (from 0 to 9), ti is a string consisting of digits (ti can be an empty string). The sum of lengths of ti for all queries doesn't exceed 105. The queries are written in the order in which they need to be performed.

Print a single integer — remainder of division of the resulting number by 1000000007 (109 + 7).

NoteNote that the leading zeroes are not removed from string s after the replacement (you can see it in the third sample).

import std.stdio, std.getopt, std.random, std.range, std.string, std.conv;
import std.algorithm, std.container, std.datetime, std.typecons;

const MD = 10^^9+7;

alias Tl = Tuple!(long, long);

long powMod(long x, long n, long md) {
    long r = 1;
    while (n) {
        if (n & 1) r *= x; r %= md;
        x *= x; x %= md;
        n >>= 1;
    }
    return r;
}

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

int n;
int[] d;
string[] t;

Tl[][] dp;
bool[][] used;
Tl calc(int ad, int c) {
	if (ad == n) return Tl(c, 1);
	if (d[ad] != c) return calc(ad+1, c);
	if (used[ad][c]) return dp[ad][c];
	used[ad][c] = true;
	Tl res = [0,0];
	foreach_reverse (u; t[ad]) {
		auto r = calc(ad+1, u-'0');
		res[0] += r[0]*powMod(10, res[1], MD) % MD;
		res[1] += r[1];
		res[0] %= MD;
		res[1] %= MD-1;
	}
	dp[ad][c] = res;
	return res;
}

long solve() {
	auto s = readln().strip();
	readf("%d\n", &n); n++;
	d = new int[n]; t = new string[n];
	d[0] = 0; t[0] = s;
	foreach (i; 1..n) {
//		readf("%d", &d[i]);
		readf("%d->%s\n", &d[i], &t[i]);
	}

	dp = new Tl[][](n, 10);
	used = new bool[][](n, 10);
	return calc(0, 0)[0]%MD;
}

int main() {
    writeln(solve());
    return 0;
}

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

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

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

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

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

immutable long MO = 1000000007;
immutable L = 10;

string S;
int N;
string[] A;

void main(string[] args) {
	try {
	for (; ; ) {
		S = readToken;
		N = readInt;
		A = new string[N];
		foreach (i; 0 .. N) {
			A[i] = readToken;
		}

		long[][] vals = new long[][](N + 1, L);
		long[][] muls = new long[][](N + 1, L);
		foreach (x; 0 .. L) {
			vals[N][x] = x;
			muls[N][x] = L;
		}

		foreach_reverse (i; 0 .. N) {
			foreach (x; 0 .. L) {
				if (x == A[i][0] - '0') {
					vals[i][x] = 0;
					muls[i][x] = 1;
					foreach (c; A[i][3 .. $]) {
						const int y = c - '0';
						vals[i][x] = (vals[i][x] * muls[i + 1][y] + vals[i + 1][y]) % MO;
						muls[i][x] = (muls[i][x] * muls[i + 1][y]) % MO;
					}
				} else {
					vals[i][x] = vals[i + 1][x];
					muls[i][x] = muls[i + 1][x];
				}
			}
		}

		long ans;
		foreach (c; S) {
			const int y = c - '0';
			ans = (ans * muls[0][y] + vals[0][y]) % MO;
		}
		writeln(ans);
	}
	} catch (EOFException) {}
}

import std.stdio, std.getopt, std.random, std.range, std.string, std.conv;
import std.algorithm, std.container, std.datetime, std.typecons;

const MD = 10^^9+7;

alias Tl = Tuple!(long, long);

long powMod(long x, long n, long md) {
    long r = 1;
    while (n) {
        if (n & 1) r *= x; r %= md;
        x *= x; x %= md;
        n >>= 1;
    }
    return r;
}

void powModTable(long[] d, long b, long md) {
	assert(d.length > 0);
	d[0] = 1;
	foreach (i; 1..d.length) {
		d[i] = (d[i-1]*b)%md;
	}
}
//-------------------------------------------------------//

int n;
int[] d;
string[] t;

Tl[][] dp;
bool[][] used;
Tl calc(int ad, int c) {
	if (ad == n) return Tl(c, 1);
	if (d[ad] != c) return calc(ad+1, c);
	if (used[ad][c]) return dp[ad][c];
	Tl res = [0,0];
	foreach_reverse (u; t[ad]) {
		auto r = calc(ad+1, u-'0');
		res[0] += r[0]*powMod(10, res[1], MD);
		res[1] += r[1];
	}
	dp[ad][c] = res;
	return res;
}

long solve() {
	auto s = readln().strip();
	readf("%d\n", &n); n++;
	d = new int[n]; t = new string[n];
	d[0] = 0; t[0] = s;
	foreach (i; 1..n) {
//		readf("%d", &d[i]);
		readf("%d->%s\n", &d[i], &t[i]);
	}

	dp = new Tl[][](n, 10);
	used = new bool[][](n, 10);
	return calc(0, 0)[0]%MD;
}

int main() {
    writeln(solve());
    return 0;
}

import std.stdio, std.getopt, std.random, std.range, std.string, std.conv;
import std.algorithm, std.container, std.datetime, std.typecons;

const MD = 10^^9+7;

alias Tl = Tuple!(long, long);

long powMod(long x, long n, long md) {
    long r = 1;
    while (n) {
        if (n & 1) r *= x; r %= md;
        x *= x; x %= md;
        n >>= 1;
    }
    return r;
}

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

int n;
int[] d;
string[] t;

Tl[][] dp;
bool[][] used;
Tl calc(int ad, int c) {
	if (ad == n) return Tl(c, 1);
	if (d[ad] != c) return calc(ad+1, c);
	if (used[ad][c]) return dp[ad][c];
	used[ad][c] = true;
	Tl res = [0,0];
	foreach_reverse (u; t[ad]) {
		auto r = calc(ad+1, u-'0');
		res[0] += r[0]*powMod(10, res[1], MD) % MD;
		res[1] += r[1];
		res[0] %= MD;
		res[1] %= MD;
	}
	dp[ad][c] = res;
	return res;
}

long solve() {
	auto s = readln().strip();
	readf("%d\n", &n); n++;
	d = new int[n]; t = new string[n];
	d[0] = 0; t[0] = s;
	foreach (i; 1..n) {
//		readf("%d", &d[i]);
		readf("%d->%s\n", &d[i], &t[i]);
	}

	dp = new Tl[][](n, 10);
	used = new bool[][](n, 10);
	return calc(0, 0)[0]%MD;
}

int main() {
    writeln(solve());
    return 0;
}


Baby Ehab is known for his love for a certain operation. He has an array $$$a$$$ of length $$$n$$$, and he decided to keep doing the following operation on it:   he picks $$$2$$$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR. Note that the length of the array decreases by one. Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $$$2$$$ elements remaining.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 15$$$) — the number of test cases you need to solve. The first line of each test case contains an integers $$$n$$$ ($$$2 \le n \le 2000$$$) — the number of elements in the array $$$a$$$. The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$0 \le a_i < 2^{30}$$$) — the elements of the array $$$a$$$.

If Baby Ehab can make all elements equal while leaving at least $$$2$$$ elements standing, print "YES". Otherwise, print "NO".

NoteIn the first sample, he can remove the first $$$2$$$ elements, $$$0$$$ and $$$2$$$, and replace them by $$$0 \oplus 2=2$$$. The array will be $$$[2,2]$$$, so all the elements are equal.In the second sample, there's no way to make all the elements equal.

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

string FMT_F = "%.10f";

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

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

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

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

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

		long tot;
		foreach (i; 0..n)
			tot ^= a[i];
		if (tot == 0)
		{
			ans[ti] = true;
			continue;
		}
		foreach (i; 1..n)
		{
			long x, y;
			long cx, cy;
			foreach (j; 0..i)
			{
				x ^= a[j];
				if (x == tot)
				{
					++cx;
					x = 0;
				}
			}
			foreach (j; i..n)
			{
				y ^= a[j];
				if (y == tot)
				{
					++cy;
					y = 0;
				}
			}
			if (x == 0 && y == 0 && (cx != 0 && cy != 0))
			{
				ans[ti] = true;
				break;
			}
		}
	}

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

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

string solve(int[] a)
{
    auto n = to!int(a.length);
    int tmask;
    foreach (i; 0 .. n - 1)
    {
        tmask ^= a[i];
        int mask;
        bool matched, occured;
        foreach (j; i + 1 .. n)
        {
            mask ^= a[j];
            if (mask != tmask) matched = false;
            else mask = 0, matched = occured = true;
        }
        if (matched || occured && mask == 0) return "YES";
    }
    return "NO";
}

int main(string[] args)
{
    auto t = to!int(readln.strip);
    foreach (_; 0 .. t)
    {
        readln;
        auto a = map!(to!int)(readln.strip.split(" ")).array;
        auto ret = solve(a);
        writeln(ret);
    }
    return 0;
}

// Vicfred
// https://codeforces.com/contest/1516/problem/B
//
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;
    a = 0 ~ a;

    int[] cum = new int[n + 1];
    for(int i = 1; i <= n; ++i) {
        cum[i] = cum[i - 1] ^ a[i];
    }

    bool found = !cum[n];
    for(int i = 1; i <= n; ++i) {
        for(int j = i + 1; j < n; ++j) {
            found |= (cum[i] == (cum[j]^cum[i]) &&
                      cum[i] == (cum[n]^cum[j]));
        }
    }
    if(found)
        "YES".writeln;
    else
        "NO".writeln;
}
}

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

string FMT_F = "%.10f";

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

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

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

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(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 bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;

		long tot;
		foreach (i; 0..n)
			tot ^= a[i];
		if (tot == 0)
		{
			ans[ti] = true;
			continue;
		}
		foreach (i; 1..n)
		{
			long x, y;
			foreach (j; 0..i)
				x ^= a[j];
			foreach (j; i..n)
				y ^= a[j];
			if (x == y)
			{
				ans[ti] = true;
				break;
			}
		}
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

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

		foreach (i; 1..n)
		{
			long x, y;
			foreach (j; 0..i)
				x ^= a[j];
			foreach (j; i..n)
				y ^= a[j];
			if (x == y)
			{
				ans[ti] = true;
				break;
			}
		}
	}

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

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

string solve(int[] a)
{
    auto n = to!int(a.length);
    int tmask;
    foreach (i; 0 .. n - 1)
    {
        tmask ^= a[i];
        int mask;
        bool f;
        foreach (j; i + 1 .. n)
        {
            mask ^= a[j];
            if (mask != tmask) f = false;
            else mask = 0, f = true;
        }
        if (f) return "YES";
    }
    return "NO";
}

int main(string[] args)
{
    auto t = to!int(readln.strip);
    foreach (_; 0 .. t)
    {
        readln;
        auto a = map!(to!int)(readln.strip.split(" ")).array;
        auto ret = solve(a);
        writeln(ret);
    }
    return 0;
}


String x is an anagram of string y, if we can rearrange the letters in string x and get exact string y. For example, strings "DOG" and "GOD" are anagrams, so are strings "BABA" and "AABB", but strings "ABBAC" and "CAABA" are not.You are given two strings s and t of the same length, consisting of uppercase English letters. You need to get the anagram of string t from string s. You are permitted to perform the replacing operation: every operation is replacing some character from the string s by any other character. Get the anagram of string t in the least number of replacing operations. If you can get multiple anagrams of string t in the least number of operations, get the lexicographically minimal one.The lexicographic order of strings is the familiar to us "dictionary" order. Formally, the string p of length n is lexicographically smaller than string q of the same length, if p1 = q1, p2 = q2, ..., pk - 1 = qk - 1, pk < qk for some k (1 ≤ k ≤ n). Here characters in the strings are numbered from 1. The characters of the strings are compared in the alphabetic order.

The input consists of two lines. The first line contains string s, the second line contains string t. The strings have the same length (from 1 to 105 characters) and consist of uppercase English letters.

In the first line print z — the minimum number of replacement operations, needed to get an anagram of string t from string s. In the second line print the lexicographically minimum anagram that could be obtained in z operations.

NoteThe second sample has eight anagrams of string t, that can be obtained from string s by replacing exactly two letters: "ADBADC", "ADDABC", "CDAABD", "CDBAAD", "CDBADA", "CDDABA", "DDAABC", "DDBAAC". These anagrams are listed in the lexicographical order. The lexicographically minimum anagram is "ADBADC".

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

void main()
{
    auto inp = File("input.txt", "r");

    void getData(ref string s, int[] cnt) {
        foreach (e; s) { cnt[e] += 1; }
    }

    string s, t;
    int[300] sCnt, origCnt;
    foreach (i; 0 .. 2) {
        auto line = inp.readln();
        if (i == 0) {
            s = line.chomp;
            getData(s, sCnt);
        } else {
            t = line.chomp;
            getData(t, origCnt);
        }
    }

    inp.close();

    debug { sCnt['A' .. 'Z' + 1].writeln; origCnt['A' .. 'Z' + 1].writeln; }

    int diff = 0;
    dchar nxt = 'A';
    dchar[] ans;
    foreach (e; s) {
        while (nxt <= 'Z' && origCnt[nxt] <= sCnt[nxt]) { ++nxt; }

        if (sCnt[e] > origCnt[e]
                && (nxt < e || sCnt[e] - 1 < sCnt[e] - origCnt[e])) {
            diff += 1;
            ans ~= nxt;
            --sCnt[e];
            --origCnt[nxt];
        } else {
            ans ~= e;
            --sCnt[e];
            --origCnt[e];
        }
    }

   auto outp = File("output.txt", "w");
   outp.writeln(diff);
   outp.writeln(ans);
   outp.close();
}

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

void main()
{
    void getData(ref string s, int[] cnt) {
        s = readln.chomp;
        foreach (e; s) { cnt[e] += 1; }
    }

    string s, t;
    int[300] sCnt, origCnt;

    getData(s, sCnt);
    getData(t, origCnt);

    debug { sCnt['A' .. 'Z' + 1].writeln; origCnt['A' .. 'Z' + 1].writeln; }

    int diff = 0;
    dchar nxt = 'A';
    dchar[] ans;
    foreach (e; s) {
        while (nxt <= 'Z' && origCnt[nxt] <= sCnt[nxt]) { ++nxt; }

        if (sCnt[e] > origCnt[e]
                && (nxt < e || sCnt[e] - 1 < sCnt[e] - origCnt[e])) {
            diff += 1;
            ans ~= nxt;
            --sCnt[e];
            --origCnt[nxt];
        } else {
            ans ~= e;
            --sCnt[e];
            --origCnt[e];
        }
    }

    diff.writeln;
    ans.writeln;
}

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

void main()
{
    auto inp = File("input.txt", "r");

    void getData(ref string s, int[] cnt) {
        foreach (e; s) { cnt[e] += 1; }
    }

    string s, t;
    int[300] sCnt, origCnt;
    foreach (i; 0 .. 2) {
        auto line = inp.readln();
        if (i == 0) {
            s = line.chomp;
            getData(s, sCnt);
        } else {
            t = line.chomp;
            getData(t, origCnt);
        }
    }

    inp.close();

    debug { sCnt['A' .. 'Z' + 1].writeln; origCnt['A' .. 'Z' + 1].writeln; }

    int diff = 0;
    dchar nxt = 'A';
    dchar[] ans;
    foreach (e; s) {
        while (nxt <= 'Z' && origCnt[nxt] <= sCnt[nxt]) { ++nxt; }

        if (sCnt[e] > origCnt[e]
                && (nxt < e || sCnt[e] - 1 < sCnt[e] - origCnt[e])) {
            diff += 1;
            ans ~= nxt;
            --sCnt[e];
            --origCnt[nxt];
        } else {
            ans ~= e;
            --sCnt[e];
            --origCnt[e];
        }
    }

   auto outp = File("output.txt", "w");
   outp.writeln("hello");
   outp.writeln(diff);
   outp.writeln(ans);
   outp.close();
}


Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel, so he can make no more than two turns on his way to his office in bank.Bankopolis looks like a grid of n rows and m columns. Igor should find a way from his home to the bank that has no more than two turns and doesn't contain cells with road works, or determine that it is impossible and he should work from home. A turn is a change in movement direction. Igor's car can only move to the left, to the right, upwards and downwards. Initially Igor can choose any direction. Igor is still sleepy, so you should help him.

The first line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the grid. Each of the next n lines contains m characters denoting the corresponding row of the grid. The following characters can occur:    "." — an empty cell;  "*" — a cell with road works;  "S" — the cell where Igor's home is located;  "T" — the cell where Igor's office is located.  It is guaranteed that "S" and "T" appear exactly once each.

In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.

NoteThe first sample is shown on the following picture:  In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture:

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

immutable int dirs = 4;
immutable int [dirs] dRow = [-1,  0, +1,  0];
immutable int [dirs] dCol = [ 0, -1,  0, +1];
immutable int infinity = int.max / 4;

alias Coord = Tuple !(int, q{row}, int, q{col});

void main ()
{
	int rows, cols;
	while (readf (" %s %s", &rows, &cols) > 0)
	{
		string [] board;
		readln;
		Coord s, t;
		foreach (row; 0..rows)
		{
			board ~= readln.strip;
			foreach (col; 0..cols)
			{
				if (board[row][col] == 'S')
				{
					s = Coord (row, col);
				}
				if (board[row][col] == 'T')
				{
					t = Coord (row, col);
				}
			}
		}

		bool isValid (int row, int col)
		{
			return 0 <= row && row < rows &&
			    0 <= col && col < cols &&
			    board[row][col] != '*';
		}

		auto f = new int [] [] (rows, cols);
		Coord [] q;
		foreach (ref fLine; f)
		{
			fLine[] = infinity;
		}
		f[s.row][s.col] = 0;
		q ~= s;
		while (!q.empty)
		{
			auto cur = q.front;
			q.popFront ();
			q.assumeSafeAppend ();

			foreach (dir; 0..dirs)
			{
				auto next = cur;
				while (true)
				{
					next.row += dRow[dir];
					next.col += dCol[dir];
					if (!isValid (next.row, next.col) ||
					    f[next.row][next.col] < infinity)
					{
						break;
					}
					f[next.row][next.col] =
					    f[cur.row][cur.col] + 1;
					q ~= next;
				}
			}
		}

		debug {writeln (f[t.row][t.col]);}
		writeln (f[t.row][t.col] <= 3 ? "YES" : "NO");
	}
}


Recently, Berland faces federalization requests more and more often. The proponents propose to divide the country into separate states. Moreover, they demand that there is a state which includes exactly k towns.Currently, Berland has n towns, some pairs of them are connected by bilateral roads. Berland has only n - 1 roads. You can reach any city from the capital, that is, the road network forms a tree.The Ministry of Roads fears that after the reform those roads that will connect the towns of different states will bring a lot of trouble.Your task is to come up with a plan to divide the country into states such that:  each state is connected, i.e. for each state it is possible to get from any town to any other using its roads (that is, the roads that connect the state towns),  there is a state that consisted of exactly k cities,  the number of roads that connect different states is minimum.

The first line contains integers n, k (1 ≤ k ≤ n ≤ 400). Then follow n - 1 lines, each of them describes a road in Berland. The roads are given as pairs of integers xi, yi (1 ≤ xi, yi ≤ n; xi ≠ yi) — the numbers of towns connected by the road. Assume that the towns are numbered from 1 to n.

The the first line print the required minimum number of "problem" roads t. Then print a sequence of t integers — their indices in the found division. The roads are numbered starting from 1 in the order they follow in the input. If there are multiple possible solutions, print any of them. If the solution shows that there are no "problem" roads at all, print a single integer 0 and either leave the second line empty or do not print it at all.

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

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

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

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

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

int N, K;
int[] A, B;

int[][] G;
int[] ipar;
int[][] vs;
int[] sz;
int[][][] dp;
int[][][] prv;

void solve(int u, int ip) {
	ipar[u] = ip;
	sz[u] = 1;
	foreach (i; G[u]) if (i != ip) {
		const v = A[i] ^ B[i] ^ u;
		vs[u] ~= v;
		solve(v, i);
		sz[u] += sz[v];
	}
	dp[u] = new int[][](vs[u].length + 1, sz[u] + 1);
	prv[u] = new int[][](vs[u].length + 1, sz[u] + 1);
	foreach (j; 0 .. vs[u].length + 1) {
		dp[u][j][] = N;
	}
	dp[u][0][1] = 0;
	foreach (j, v; vs[u]) {
		foreach (x; 0 .. sz[u] + 1) if (dp[u][j][x] < N) {
			//	connect
			foreach (y; 0 .. sz[v] + 1) if (x + y <= sz[u]) {
				if (dp[u][j + 1][x + y] > dp[u][j][x] + dp[v][$ - 1][y]) {
					dp[u][j + 1][x + y] = dp[u][j][x] + dp[v][$ - 1][y];
					prv[u][j + 1][x + y] = y;
				}
			}
			//	cut
			if (dp[u][j + 1][x] > dp[u][j][x] + 1) {
				dp[u][j + 1][x] = dp[u][j][x] + 1;
				prv[u][j + 1][x] = -2;
			}
		}
	}
}

int[] ans;
void recover(int u, int k) {
debug{
writeln("recover ",u," ",k);stdout.flush;
}
	assert(k <= sz[u]);
	int j = vs[u].length;
	int x = k;
	foreach_reverse (i; G[u]) if (i != ipar[u]) {
		const v = A[i] ^ B[i] ^ u;
		const y = prv[u][j][x];
		if (y == -2) {
			ans ~= i;
			--j;
		} else {
			recover(v, y);
			--j;
			x -= y;
		}
	}
	assert(j == 0);
	assert(x == 1);
}

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

		G = new int[][N];
		foreach (i; 0 .. N - 1) {
			G[A[i]] ~= i;
			G[B[i]] ~= i;
		}
		ipar = new int[N];
		ipar[] = -1;
		vs = new int[][N];
		sz = new int[N];
		dp = new int[][][N];
		prv = new int[][][N];
		solve(0, -1);
debug{
writeln("ipar = ",ipar);
writeln("vs = ",vs);
writeln("sz = ",sz);
writeln("dp = ",dp);
}
		int opt = dp[0][$ - 1][K];
		int um = 0;
		foreach (u; 1 .. N) {
			if (K <= sz[u]) {
				if (opt > 1 + dp[u][$ - 1][K]) {
					opt = 1 + dp[u][$ - 1][K];
					um = u;
				}
			}
		}

		ans.clear;
		if (um != 0) {
			ans ~= ipar[um];
		}
		recover(um, K);
debug{
writeln("ans = ",ans);
}
		writeln(ans.length);
		ans[] += 1;
		writeln(ans.to!string.removechars("[],"));
	}
	} catch (EOFException) {}
}


A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex $$$v$$$ (different from root) is the previous to $$$v$$$ vertex on the shortest path from the root to the vertex $$$v$$$. Children of the vertex $$$v$$$ are all vertices for which $$$v$$$ is the parent.You are given a rooted tree with $$$n$$$ vertices. The vertex $$$1$$$ is the root. Initially, all vertices are healthy.Each second you do two operations, the spreading operation and, after that, the injection operation:   Spreading: for each vertex $$$v$$$, if at least one child of $$$v$$$ is infected, you can spread the disease by infecting at most one other child of $$$v$$$ of your choice.  Injection: you can choose any healthy vertex and infect it. This process repeats each second until the whole tree is infected. You need to find the minimal number of seconds needed to infect the whole tree.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of the vertices in the given tree. The second line of each test case contains $$$n - 1$$$ integers $$$p_2, p_3, \ldots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the ancestor of the $$$i$$$-th vertex in the tree. It is guaranteed that the given graph is a tree. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case you should output a single integer — the minimal number of seconds needed to infect the whole tree.

NoteThe image depicts the tree from the first test case during each second.A vertex is black if it is not infected. A vertex is blue if it is infected by injection during the previous second. A vertex is green if it is infected by spreading during the previous second. A vertex is red if it is infected earlier than the previous second.  Note that you are able to choose which vertices are infected by spreading and by injections.

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

void solve() {
    int N = readln.chomp.to!int;
    auto P = [0] ~ readln.chomp.split(" ").map!(x => x.to!int).array;

    auto C = new int[N+1];
    for (int i = 0; i < N; i++) {
        C[P[i]]++;
    }
    int[] xs;
    foreach (c; C) {
        if (c > 0) xs ~= c;
    }

    int n = cast(int)(xs.length);
    reverse(sort(xs));
    bool f(int t) {
        int r = 0;
        for (int i = 0; i < n; i++) {
            r += max(0, - (t - i - xs[i]));
        }
        return r <= (t - n);
    }
    int lb = 0, ub = 5*N;
    while (lb + 1 < ub) {
        int mid = (lb + ub) / 2;
        (f(mid) ? ub : lb) = mid;
    }
    writeln(ub);

}

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


Convexity of a set of points on the plane is the size of the largest subset of points that form a convex polygon. Your task is to build a set of n points with the convexity of exactly m. Your set of points should not contain three points that lie on a straight line.

The single line contains two integers n and m (3 ≤ m ≤ 100, m ≤ n ≤ 2m).

If there is no solution, print "-1". Otherwise, print n pairs of integers — the coordinates of points of any set with the convexity of m. The coordinates shouldn't exceed 108 in their absolute value.

import std.algorithm;
import std.container;
import std.exception;
import std.math;
import std.stdio;
import std.string;
import std.typecons;

void point (int i, int n, int c, double d)
{
	double angle = i * 2.0 * PI / n;
	int x = cast (int) (cos (angle + d) * 1_000_000);
	int y = cast (int) (sin (angle + d) * 1_000_000);
	writefln ("%s %s", c * x, c * y);
}

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		if (m == 3 && n >= 5)
		{
			writefln ("-1");
			continue;
		}
		foreach (i; 0..m)
		{
			point (i, m, 4, 0.0);
		}
		foreach (i; m..n)
		{
			point (i, m, 1, 0.0001);
		}
		debug {writeln ();}
	}
}

import std.algorithm;
import std.container;
import std.exception;
import std.math;
import std.stdio;
import std.string;
import std.typecons;

void point (int i, int n, int c)
{
	double angle = i * 2.0 * PI / n;
	int x = cast (int) (cos (angle) * 1_000_000);
	int y = cast (int) (sin (angle) * 1_000_000);
	writefln ("%s %s", c * x, c * y);
}

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		if ((m == 3 && n >= 5) ||
		    (m == 4 && n >= 8))
		{
			writefln ("-1");
			continue;
		}
		if (m == 4 && n == 7)
		{
			writefln ("176166 6377");
			writefln ("709276 539564");
			writefln ("654734 174109");
			writefln ("910147 434207");
			writefln ("790497 366519");
			writefln ("606663 21061");
			writefln ("859328 886001");
			continue;
		}
		foreach (i; 0..m)
		{
			point (i, m, 4);
		}
		foreach (i; m..n)
		{
			point (i, m, 1);
		}
		debug {writeln ();}
	}
}

import std.algorithm;
import std.container;
import std.exception;
import std.math;
import std.stdio;
import std.string;
import std.typecons;

void point (int i, int n, int c)
{
	double angle = i * 2.0 * PI / n;
	int x = cast (int) (cos (angle) * 1_000_000);
	int y = cast (int) (sin (angle) * 1_000_000);
	writefln ("%s %s", c * x, c * y);
}

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		if (m == 3 && n == 6)
		{
			writefln ("-1");
			continue;
		}
		foreach (i; 0..m)
		{
			point (i, m, 4);
		}
		foreach (i; m..n)
		{
			point (i, m, 1);
		}
		debug {writeln ();}
	}
}


Fox Ciel is going to travel to New Foxland during this summer.New Foxland has n attractions that are linked by m undirected roads. Two attractions are called adjacent if they are linked by a road. Fox Ciel has k days to visit this city and each day she will visit exactly one attraction.There is one important rule in New Foxland: you can't visit an attraction if it has more than one adjacent attraction that you haven't visited yet.At the beginning Fox Ciel haven't visited any attraction. During her travelling she may move aribtrarly between attraction. After visiting attraction a, she may travel to any attraction b satisfying conditions above that hasn't been visited yet, even if it is not reachable from a by using the roads (Ciel uses boat for travelling between attractions, so it is possible). She wants to know how many different travelling plans she can make. Calculate this number modulo 109 + 9 for every k from 0 to n since she hasn't decided for how many days she is visiting New Foxland.

First line contains two integers: n, m (1 ≤ n ≤ 100, ), the number of attractions and number of undirected roads. Then next m lines each contain two integers ai and bi (1 ≤ ai, bi ≤ n and ai ≠ bi), describing a road. There is no more than one road connecting each pair of attractions.

Output n + 1 integer: the number of possible travelling plans modulo 109 + 9 for all k from 0 to n.

NoteIn the first sample test for k = 3 there are 4 travelling plans: {1, 2, 3}, {1, 3, 2}, {3, 1, 2}, {3, 2, 1}.In the second sample test Ciel can't visit any attraction in the first day, so for k > 0 the answer is 0.In the third sample test Foxlands look like this:

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

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

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

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

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

int root(int[] uf, int u) {
	return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));
}
bool conn(int[] uf, int u, int v) {
	u = uf.root(u);
	v = uf.root(v);
	if (u == v) return false;
	if (uf[u] > uf[v]) swap(u, v);
	uf[u] += uf[v];
	uf[v] = u;
	return true;
}

immutable MO = 10L^^9 + 9;
immutable LIM = 205;
long[][] bn;

void prepare() {
	bn = new long[][](LIM, LIM);
	foreach (i; 0 .. LIM) {
		bn[i][0] = bn[i][i] = 1;
		foreach (j; 1 .. i) {
			bn[i][j] = (bn[i - 1][j - 1] + bn[i - 1][j]) % MO;
		}
	}
}

long[] solve(in int V, in int[] ids, in int[] sizes, in bool[][] g) {
debug{
writeln("solve ",V," ",ids," ",sizes);
}
	auto dist = new int[][](V, V);
	foreach (u; 0 .. V) {
		dist[u][] = V;
		dist[u][u] = 0;
	}
	foreach (u; 0 .. V) foreach (v; u + 1 .. V) if (g[u][v]) {
		chmin(dist[u][v], 1);
		chmin(dist[v][u], 1);
	}
	foreach (w; 0 .. V) foreach (u; 0 .. V) foreach (v; 0 .. V) {
		chmin(dist[u][v], dist[u][w] + dist[w][v]);
	}
	bool[] freeze = new bool[V];
	foreach (u; 0 .. V) foreach (v; 0 .. V) {
		if (sizes[u] > 1 && sizes[v] > 1) {
			foreach (w; 0 .. V) {
				if (dist[u][v] == dist[u][w] + dist[w][v]) {
					freeze[w] = true;
				}
			}
		}
	}
debug{
writeln("freeze = ",freeze);
}
	int[] deg = new int[V];
	foreach (u; 0 .. V) foreach (v; u + 1 .. V) if (g[u][v]) {
		++deg[u];
		++deg[v];
	}

	long[][][] cache = new long[][][](V + 1, V + 1);
	long[] calc(int u, int p) {
		if (cache[u][p].empty) {
			long[][] ress;
			foreach (v; 0 .. V) if (g[u][v] && !freeze[v] && v != p) {
				ress ~= calc(v, u);
			}
			int sz = 1;
			foreach (res; ress) {
				const int szV = res.length - 1;
				sz += szV;
			}
			long[] dp = new long[sz + 1];
			dp[0] = 1;
			foreach (res; ress) {
				const int szV = res.length - 1;
				foreach_reverse (x; 0 .. sz + 1) {
					foreach_reverse (dx; 1 .. min(sz - x, szV) + 1) {
						(dp[x + dx] += bn[x + dx][dx] * dp[x] % MO * res[dx]) %= MO;
					}
				}
			}
			dp[sz] = dp[sz - 1];
			cache[u][p] = dp;
		}
		return cache[u][p];
	}

	bool[] vis = new bool[V];
	int[] us;
	void dfs(int u) {
		vis[u] = true;
		us ~= u;
		foreach (v; 0 .. V) if (g[u][v] && !freeze[v]) {
			if (!vis[v]) {
				dfs(v);
			}
		}
	}

	long[][] dps;
	foreach (u; 0 .. V) if (!freeze[u]) {
		bool cold;
		foreach (v; 0 .. V) if (g[u][v]) {
			if (freeze[v]) {
				cold = true;
			}
		}
		if (cold) {
			assert(!vis[u]);
			dfs(u);
			dps ~= calc(u, V);
		}
	}
	foreach (u; 0 .. V) if (!freeze[u]) {
		if (!vis[u]) {
			us = new int[0];
			dfs(u);
			long[] sum = calc(u, V);
			foreach (v; us) if (v != u) {
				sum[] += calc(v, V)[];
			}
			const int sz = sum.length - 1;
			foreach (x; 0 .. sz) {
				for (; sum[x] % (sz - x) != 0; sum[x] += MO) {}
				sum[x] /= (sz - x);
			}
			dps ~= sum;
		}
	}
debug{
writeln("dps = ",dps);
}

	long[] DP = new long[V + 1];
	DP[0] = 1;
	foreach (dp; dps) {
		foreach_reverse (x; 0 .. V + 1) {
			foreach_reverse (dx; 1 .. min(V - x, cast(int)(dp.length - 1)) + 1) {
				(DP[x + dx] += bn[x + dx][dx] * DP[x] % MO * dp[dx]) %= MO;
			}
		}
debug{
writeln("DP = ",DP);
}
	}
	return DP;
}

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

bool[][] G;
bool[] vis;
bool[][] isBridge;

void dfs(int u) {
	vis[u] = true;
	foreach (v; 0 .. N) if (G[u][v]) {
		if (!vis[v]) {
			isBridge[u][v] = true;
			isBridge[v][u] = true;
			dfs(v);
		}
	}
}

int numComps() {
	int[] uf = new int[N];
	uf[] = -1;
	foreach (u; 0 .. N) foreach (v; u + 1 .. N) if (G[u][v]) {
		uf.conn(u, v);
	}
	return uf.count!(a => (a < 0));
}

void main(string[] args) {
	prepare;

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

		G = new bool[][](N, N);
		foreach (i; 0 .. M) {
			G[A[i]][B[i]] = true;
			G[B[i]][A[i]] = true;
		}
		vis = new bool[N];
		isBridge = new bool[][](N, N);
		foreach (u; 0 .. N) {
			if (!vis[u]) {
				dfs(u);
			}
		}
		const orig = numComps;
		foreach (u; 0 .. N) foreach (v; u + 1 .. N) if (G[u][v]) {
			if (isBridge[u][v]) {
				G[u][v] = G[v][u] = false;
				isBridge[u][v] = (orig < numComps);
				G[u][v] = G[v][u] = true;
			}
		}
debug{
foreach(u;0..N)foreach(v;u+1..N)if(isBridge[u][v])writeln("bridge ",u," ",v);
}

		int[] uf = new int[N];
		uf[] = -1;
		foreach (u; 0 .. N) foreach (v; u + 1 .. N) if (G[u][v]) {
			if (!isBridge[u][v]) {
				uf.conn(u, v);
			}
		}

		int V;
		int[] ids = new int[N];
		ids[] = -1;
		foreach (u; 0 .. N) if (uf[u] < 0) {
			ids[u] = V++;
		}
		foreach (u; 0 .. N) {
			ids[u] = ids[uf.root(u)];
		}
		int[] sz = new int[V];
		foreach (u; 0 .. N) {
			++sz[ids[u]];
		}
		auto g = new bool[][](V, V);
		foreach (u; 0 .. N) foreach (v; u + 1 .. N) if (G[u][v]) {
			if (ids[u] != ids[v]) {
				g[ids[u]][ids[v]] = true;
				g[ids[v]][ids[u]] = true;
			}
		}

		const res = solve(V, ids, sz, g);
		foreach (k; 0 .. N + 1) {
			long ans = (k < res.length) ? res[k] : 0;
			ans = (ans % MO + MO) % MO;
			writeln(ans);
		}

debug{
writeln("====");
}
	}
	} catch (EOFException) {}
}