There is a robot on a coordinate plane. Initially, the robot is located at the point $$$(0, 0)$$$. Its path is described as a string $$$s$$$ of length $$$n$$$ consisting of characters 'L', 'R', 'U', 'D'.Each of these characters corresponds to some move:   'L' (left): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x - 1, y)$$$;  'R' (right): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x + 1, y)$$$;  'U' (up): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y + 1)$$$;  'D' (down): means that the robot moves from the point $$$(x, y)$$$ to the point $$$(x, y - 1)$$$. The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point $$$(x_e, y_e)$$$, then after optimization (i.e. removing some single substring from $$$s$$$) the robot also ends its path at the point $$$(x_e, y_e)$$$.This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string $$$s$$$).Recall that the substring of $$$s$$$ is such string that can be obtained from $$$s$$$ by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The next $$$2t$$$ lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the robot's path. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ characters 'L', 'R', 'U', 'D' — the robot's path. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers $$$l$$$ and $$$r$$$ such that $$$1 \le l \le r \le n$$$ — endpoints of the substring you remove. The value $$$r-l+1$$$ should be minimum possible. If there are several answers, print any of them.

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;
import std.algorithm.mutation;
import std.container.array;

string[] tokens;

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

int readInt()
{
    return readToken.to!int;
}

void main()
{
    int T = readInt;
    while (T--)
    {
        int n = readInt;
        auto s = readToken;
        int[Tuple!(int, int)] tbl;
        tbl[tuple(0, 0)] = 0;
        int x = 0, y = 0;
        auto best = tuple(n + 1, 0, 0);
        for (int i = 0; i < n; ++i)
        {
            final switch (s[i])
            {
            case 'L':
                x--;
                break;
            case 'R':
                x++;
                break;
            case 'D':
                y--;
                break;
            case 'U':
                y++;
            }
            int idx = tbl.get(tuple(x, y), -1);
            if (idx != -1)
                best = min(best, tuple(i - idx + 1, idx + 1, i + 1));
            tbl[tuple(x, y)] = i + 1;
        }
        if (best[0] <= n)
        {
            writeln(best[1], " ", best[2]);
        }
        else
        {
            writeln(-1);
        }

    }
}

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

DList!string _words;

void read(T...)(ref T t)
{
  void singleRead(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);
  }
  static foreach(i; 0 .. T.length)
    {
      static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))
        {
          foreach(ref element; t[i])
            read(element);
        }
      else
        {
          singleRead(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 = E.init)
{
  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));
  }
}

void main()
{
  auto t = next!int;
  foreach(tc; 0 .. t)
    {
      auto n = next!long;
      auto path = next!string;
      long[Tuple!(long, long)] lastPosition;
      auto acc = tuple!(long, long)(0, 0);
      lastPosition[acc] = 0;
      long lp, cp;
      foreach(i; 1 .. n + 1)
        {
          switch(path[(i - 1).ind])
            {
            case 'L':
              acc[0]--;
              break;
            case 'R':
              acc[0]++;
              break;
            case 'U':
              acc[1]++;
              break;
            case 'D':
              acc[1]--;
              break;
            default:
              assert(0);
            }
          if (acc in lastPosition)
            {
              if (cast(long) i - lastPosition[acc] < cp - lp || cp == lp)
                {
                  cp = cast(long) i;
                  lp = lastPosition[acc];
                }
            }
          lastPosition[acc] = cast(long) i;
        }
      if (lp == cp)
        {
          writeln(-1);
        }
      else
        {
          writeln(lp + 1, " ", cp);
        }
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new int[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto s = RD!string;
		int[int[2]] set;
		set[[0, 0]] = 0;
		int[2] cnt;
		int len = int.max;
		foreach (i; 0..n)
		{
			if (s[i] == 'L')
				--cnt[0];
			else if (s[i] == 'R')
				++cnt[0];
			else if (s[i] == 'U')
				--cnt[1];
			else
				++cnt[1];

			int[2] x = cnt.dup;
			auto pos = set.get(x, -1);
			if (pos != -1)
			{
				if (i - pos < len)
				{
					len = i - pos;
					ans[ti] = [pos+1, i+1];
				}
			}
			auto y = set.get(cnt, 0);
			set[cnt] = max(y, i+1);
		}
		debug writeln(set);
	}

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


Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches. The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.

Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.

NoteIn the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0.

import std.stdio;
import std.algorithm;

///solve
void solve() {
    int n;
    readf(" %s\n", &n);
    string s = readln();
    int rb, br;
    rb = 0; br = 0;
    // 0-r
    foreach(int idx; 0 .. n) {
        if (idx % 2 == 0 && s[idx] == 'b') {
            br++;
        }
        else if (idx % 2 != 0 && s[idx] == 'r') {
            rb++;
        }
    }
    int actions_nr = n;
    int curr_actions_nr = 0;
    while (true) {
        if (rb == 0) {
            curr_actions_nr += br;
            break;
        }
        if (br == 0) {
            curr_actions_nr += rb;
            break;
        }
        rb--;
        br--;
        curr_actions_nr++;
    }
    actions_nr = min(actions_nr, curr_actions_nr);
    rb = 0; br = 0;
    // 0-b
    foreach(int idx; 0 .. n) {
        if (idx % 2 != 0 && s[idx] == 'b') {
            br++;
        }
        else if (idx % 2 == 0 && s[idx] == 'r') {
            rb++;
        }
    }
    curr_actions_nr = 0;
    while (true) {
        if (rb == 0) {
            curr_actions_nr += br;
            break;
        }
        if (br == 0) {
            curr_actions_nr += rb;
            break;
        }
        rb--;
        br--;
        curr_actions_nr++;
    }
    actions_nr = min(actions_nr, curr_actions_nr);
    writeln(actions_nr);
}
void main() {
    solve();
}


You have a square chessboard of size $$$n \times n$$$. Rows are numbered from top to bottom with numbers from $$$1$$$ to $$$n$$$, and columns — from left to right with numbers from $$$1$$$ to $$$n$$$. So, each cell is denoted with pair of integers $$$(x, y)$$$ ($$$1 \le x, y \le n$$$), where $$$x$$$ is a row number and $$$y$$$ is a column number.You have to perform $$$q$$$ queries of three types:  Put a new rook in cell $$$(x, y)$$$.  Remove a rook from cell $$$(x, y)$$$. It's guaranteed that the rook was put in this cell before.  Check if each cell of subrectangle $$$(x_1, y_1) - (x_2, y_2)$$$ of the board is attacked by at least one rook. Subrectangle is a set of cells $$$(x, y)$$$ such that for each cell two conditions are satisfied: $$$x_1 \le x \le x_2$$$ and $$$y_1 \le y \le y_2$$$.Recall that cell $$$(a, b)$$$ is attacked by a rook placed in cell $$$(c, d)$$$ if either $$$a = c$$$ or $$$b = d$$$. In particular, the cell containing a rook is attacked by this rook.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le q \le 2 \cdot 10^5$$$) — the size of the chessboard and the number of queries, respectively. Each of the following $$$q$$$ lines contains description of a query. Description begins with integer $$$t$$$ ($$$t \in \{1, 2, 3\}$$$) which denotes type of a query:   If $$$t = 1$$$, two integers $$$x$$$ and $$$y$$$ follows ($$$1 \le x, y \le n$$$) — coordinated of the cell where the new rook should be put in. It's guaranteed that there is no rook in the cell $$$(x, y)$$$ at the moment of the given query.  If $$$t = 2$$$, two integers $$$x$$$ and $$$y$$$ follows ($$$1 \le x, y \le n$$$) — coordinates of the cell to remove a rook from. It's guaranteed that there is a rook in the cell $$$(x, y)$$$ at the moment of the given query.  If $$$t = 3$$$, four integers $$$x_1, y_1, x_2$$$ and $$$y_2$$$ follows ($$$1 \le x_1 \le x_2 \le n$$$, $$$1 \le y_1 \le y_2 \le n$$$) — subrectangle to check if each cell of it is attacked by at least one rook.  It's guaranteed that among $$$q$$$ queries there is at least one query of the third type.

Print the answer for each query of the third type in a separate line. Print "Yes" (without quotes) if each cell of the subrectangle is attacked by at least one rook. Otherwise print "No" (without quotes).

NoteConsider example. After the first two queries the board will look like the following picture (the letter $$$R$$$ denotes cells in which rooks are located, the subrectangle of the query of the third type is highlighted in green):  Chessboard after performing the third and the fourth queries:  Chessboard after performing the fifth and the sixth queries:  Chessboard after performing the seventh and the eighth queries:  Chessboard after performing the last two queries:

import std;
import std.outbuffer;

const int MAXN = 100005;

int n,q;

struct Bit
{
    int[MAXN] t;

    int lowbit(int x) {
        return x & (-x);
    }

    void update(int x, int k) {
        while (x <= n) {
            t[x] += k;
            x += lowbit(x);
        }
    }

    int ask(int x) {
        int res = 0;
        while (x > 0) {
            res += t[x];
            x -= lowbit(x);
        }
        return res;
    }

    int query(int l, int r) {
        return ask(r) - ask(l - 1);
    }
}

Bit bx, by;

int[MAXN] cntRows, cntCols;

void main()
{
    OutBuffer buf = new OutBuffer();
    scanf("%d %d", &n, &q);
    getchar();
    outer: foreach(_; 0..q)
    {
        int op, x1, x2, y1, y2;
        scanf("%d ", &op);
        if (op == 3) {
            scanf("%d %d %d %d\n", &x1, &y1, &x2, &y2);
            if (bx.query(x1,x2) == x2 - x1 + 1 || by.query(y1, y2) == y2 - y1 + 1)
                buf.printf("Yes\n");
            else
                buf.printf("No\n");
        }
        else {
            scanf("%d %d\n", &x1, &y1);
            if (op == 1) {
                if (cntRows[x1]++ == 0)
                    bx.update(x1,1);
                if (cntCols[y1]++ == 0)
                    by.update(y1,1);
            }
            else if (op == 2) {
                if (cntRows[x1]-- == 1)
                    bx.update(x1,-1);
                if (cntCols[y1]-- == 1)
                    by.update(y1,-1);
            }
        }
    }
    writeln(buf);
}

import std;
import core.stdc.stdio;

const int MAXN = 100005;

int n,q;

struct Bit
{
    int[MAXN] t;

    int lowbit(int x) {
        return x & (-x);
    }

    void update(int x, int k) {
        while (x <= n) {
            t[x] += k;
            x += lowbit(x);
        }
    }

    int ask(int x) {
        int res = 0;
        while (x > 0) {
            res += t[x];
            x -= lowbit(x);
        }
        return res;
    }

    int query(int l, int r) {
        return ask(r) - ask(l - 1);
    }
}

Bit bx, by;

int[MAXN] cntRows, cntCols;

void main()
{
    scanf("%d %d", &n, &q);
    getchar();
    outer: foreach(_; 0..q)
    {
        int op, x1, x2, y1, y2;
        scanf("%d ", &op);
        if (op == 3) {
            scanf("%d %d %d %d\n", &x1, &y1, &x2, &y2);
            if (bx.query(x1,x2) == x2 - x1 + 1 || by.query(y1, y2) == y2 - y1 + 1)
                printf("Yes\n");
            else
                printf("No\n");
        }
        else {
            scanf("%d %d\n", &x1, &y1);
            if (op == 1) {
                if (cntRows[x1]++ == 0)
                    bx.update(x1,1);
                if (cntCols[y1]++ == 0)
                    by.update(y1,1);
            }
            else if (op == 2) {
                if (cntRows[x1]-- == 1)
                    bx.update(x1,-1);
                if (cntCols[y1]-- == 1)
                    by.update(y1,-1);
            }
        }
    }
}

void main() { runSolver(); }

void problem() {
  auto QN = 1;

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto Q = scan!int;

      auto xt = SegTree!("min(a, b)", int)(new int[](N + 1), int.max/2);
      auto yt = SegTree!("min(a, b)", int)(new int[](N + 1), int.max/2);

      foreach(qi; 0..Q) {
        auto q = scan!int;
        if (q == 1 || q == 2) {
          auto x = scan!int;
          auto y = scan!int;
          if (q == 1) {
            xt.update(x, xt.get(x) + 1);
            yt.update(y, yt.get(y) + 1);
            // xt.get(x).deb;
          } else {
            xt.update(x, xt.get(x) - 1);
            yt.update(y, yt.get(y) - 1);
            // xt.get(x).deb;
          }
        } else {
          auto x1 = scan!int;
          auto y1 = scan!int;
          auto x2 = scan!int;
          auto y2 = scan!int;

          // [x1, xt.get(x1)].deb;
          // [y1, y2, yt.get(y1)].deb;
          // [xt.sum(x1, x2), yt.sum(y1, y2)].deb;

          auto ans = max(xt.sum(x1, x2 + 1), yt.sum(y1, y2 + 1));
          writeln(ans == 0 ? "No" : "Yes");
        }
      }
    }

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

  outputForAtCoder(&solve);
}

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

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

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

struct SegTree(alias pred = "a + b", T = long) {
  alias predFun = binaryFun!pred;
  int size;
  T[] data;
  T monoid;

  this(T[] src, T monoid = T.init) {
    this.monoid = monoid;

    for(int i = 2; i < 2L^^32; i *= 2) {
      if (src.length <= i) {
        size = i;
        break;
      }
    }

    data = new T[](size * 2);
    foreach(i, s; src) data[i + size] = s;
    foreach_reverse(b; 1..size) {
      data[b] = predFun(data[b * 2], data[b * 2 + 1]);
    }
  }

  void update(int index, T value) {
    int i = index + size;
    data[i] = value;
    while(i > 0) {
      i /= 2;
      data[i] = predFun(data[i * 2], data[i * 2 + 1]);
    }
  }

  T get(int index) {
    return data[index + size];
  }

  T sum(int a, int b, int k = 1, int l = 0, int r = -1) {
    if (r < 0) r = size;

    if (r <= a || b <= l) return monoid;
    if (a <= l && r <= b) return data[k];

    T leftValue = sum(a, b, 2*k, l, (l + r) / 2);
    T rightValue = sum(a, b, 2*k + 1, (l + r) / 2, r);
    return predFun(leftValue, rightValue);
  }
}

import std;
import core.stdc.stdio;

void main()
{
    int n, q;
    scanf("%d %d", &n, &q);
    getchar();
    auto freeRows = redBlackTree(iota(n+1));
    auto freeCols = redBlackTree(iota(n+1));
    int[] cntRows = new int[](n+1);
    int[] cntCols = new int[](n+1);
    outer: foreach(_; 0..q)
    {
        int qtype, x1, x2, y1, y2;
        scanf("%d ", &qtype);
        if (qtype == 3) {
            scanf("%d %d %d %d\n", &x1, &y1, &x2, &y2);
            auto l1 = freeRows.lowerBound(x2 + 1).array;
            auto u1 = freeRows.upperBound(x1 - 1).array;
            auto l2 = freeCols.lowerBound(y2 + 1).array;
            auto u2 = freeCols.upperBound(y1 - 1).array;
            if (l1[$-1]==u1[0] || l2[$-1]==u2[0])
                printf("No\n");
            else
                printf("Yes\n");
        }
        else {
            scanf("%d %d\n", &x1, &y1);
            if (qtype == 1) {
                if (cntRows[x1] == 0)
                    freeRows.removeKey(x1);
                cntRows[x1]++;
                if (cntCols[y1] == 0)
                    freeCols.removeKey(y1);
                cntCols[y1]++;
            }
            else {
                cntRows[x1]--;
                cntCols[y1]--;
                if (cntRows[x1] == 0)
                    freeRows.insert(x1);
                if (cntCols[y1] == 0)
                    freeCols.insert(y1);
            }
        }
    }
}

import std;
import core.stdc.stdio;

void main()
{
    int n, q;
    scanf("%d %d", &n, &q);
    getchar();
    auto freeRows = redBlackTree(iota(n));
    auto freeCols = redBlackTree(iota(n));
    int[] cntRows = new int[](n+1);
    int[] cntCols = new int[](n+1);
    outer: foreach(_; 0..q)
    {
        int qtype, x1, x2, y1, y2;
        scanf("%d ", &qtype);
        if (qtype == 3) {
            scanf("%d %d %d %d\n", &x1, &y1, &x2, &y2);
            auto ll = freeRows.lowerBound(x2 + 1);
            auto uu = freeRows.upperBound(x1 - 1);
            bool t1 = setIntersection(ll, uu).array.length == 0;
            ll = freeCols.lowerBound(y2 + 1);
            uu = freeCols.upperBound(y1 - 1);
            bool t2 = setIntersection(ll, uu).array.length == 0;
            if (t1 || t2)
                printf("Yes\n");
            else
                printf("No\n");
        }
        else {
            scanf("%d %d\n", &x1, &y1);
            if (qtype == 1) {
                if (cntRows[x1] == 0)
                    freeRows.removeKey(x1);
                cntRows[x1]++;
                if (cntCols[y1] == 0)
                    freeCols.removeKey(y1);
                cntCols[y1]++;
            }
            else {
                cntRows[x1]--;
                cntCols[y1]--;
                if (cntRows[x1] == 0)
                    freeRows.insert(x1);
                if (cntCols[y1] == 0)
                    freeCols.insert(y1);
            }
        }
    }
}


You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.Number a doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resulting number also mustn't contain any leading zeroes.

The first line contains positive integer a in the decimal record. It is guaranteed that the record of number a contains digits: 1, 6, 8, 9. Number a doesn't contain any leading zeroes. The decimal representation of number a contains at least 4 and at most 106 characters.

Print a number in the decimal notation without leading zeroes — the result of the permutation. If it is impossible to rearrange the digits of the number a in the required manner, print 0.

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

immutable int BASE = 10;

int mod7 (int [] s, int start)
{
	int res = start;
	foreach (c; s)
	{
		res = (res * BASE + c) % 7;
	}
	return res;
}

void main ()
{
	string s;
	while ((s = readln ().strip ()) != "")
	{
		auto a = new int [BASE];
		a[] = 0;
		foreach (c; s)
		{
			a[c - '0']++;
		}
		a[1]--;
		a[6]--;
		a[8]--;
		a[9]--;

		int [] res;
		for (int i = 1; i <= 9; i++)
		{
			foreach (k; 0..a[i])
			{
				res ~= i;
			}
		}
		int start = mod7 (res, 0);
		int p = res.length;
		res ~= [1, 6, 8, 9];
		foreach (k; 0..a[0])
		{
			res ~= 0;
		}
		int [] t = res[p..p + 4];
		while (mod7 (t, start) != 0)
		{
			bool ok = nextPermutation !("a < b", int []) (t);
			enforce (ok);
		}

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


Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$): the number of bags for which you need to solve the problem. The first line of each bag description contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$): the number of patty-cakes in it. The second line of the bag description contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.  It is guaranteed that the sum of $$$n$$$ over all bags does not exceed $$$10^5$$$.

For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.

NoteFor the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): $$$1$$$, $$$6$$$, $$$4$$$, $$$7$$$, $$$1$$$, $$$6$$$, $$$4$$$ (in this way, the minimum distance is equal to $$$3$$$).For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): $$$1$$$, $$$4$$$, $$$6$$$, $$$7$$$, $$$4$$$, $$$1$$$, $$$6$$$, $$$4$$$ (in this way, the minimum distance is equal to $$$2$$$).

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

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

    while (t--) {
        int n;
        readf("%s", &n);
        readln;

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

        int[int] cnt;
        foreach (e; arr) { cnt[e] += 1; }

        auto rbt = make!(RedBlackTree!(
            Tuple!(int, int),
            "a[1] != b[1] ? a[1] > b[1] : a[0] > b[0]",
            false));
        foreach (k; cnt.keys) {
            //debug { writeln(k, ' ', cnt[k]); }
            rbt.insert(tuple(k, cnt[k]));
        }

        debug { rbt.writeln; }

        bool isOk(int d) {
            auto crbt = rbt.dup;
            int[int] rest;
            int[] arr;
            foreach (i; n.iota) {
                if (i-1 >= d && rest.get(arr[i-1-d], 0) > 0) { crbt.insert(tuple(arr[i-1-d], rest[arr[i-1-d]])); }

                if (crbt.empty()) { return false; }

                auto kv = crbt.front;

                arr ~= kv[0];

                crbt.removeFront();

                rest[kv[0]] = kv[1] - 1;
            }

            return true;
        }

        int le = 0, r = n;
        while (le < r) {
            int m = (le + r) / 2 + 1;
            if (isOk(m)) { le = m; }
            else { r = m - 1; }
        }

        le.writeln;
    }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		sort (a);
		auto s = a.group.map !(c => c[1]).array;
		auto hi = s.maxElement;
		auto num = s.count (hi);
		writeln ((n - num) / (hi - 1) - 1);
	}
}

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;
  @Dim("n") long[] a;

  void solve(long tc = -1)
  {
    long[long] cnt;
    long mx = long.min;
    foreach(ai; a)
      if (++cnt.require(ai, 0) > mx)
        {
          mx = cnt[ai];
        }
    long ts = 0;
    foreach(a, c; cnt)
      {
        if (c == mx)
          {
            ts++;
          }
      }
    writeln((n - ts * mx) / (mx - 1) + (ts - 1));
  }
}

struct Interval
{
  long l, h;

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

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

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

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

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

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

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

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

DList!string _words;

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

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

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

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

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

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

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

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

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

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

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

    }
}

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

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

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

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

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

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

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

void main()
{
  type;
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		auto cnt = new int[](n);
		foreach (i; 0..n)
		{
			++cnt[a[i]];
		}
		cnt.sort!"a > b";
		int cntcnt = 1;
		foreach (i; 1..n)
		{
			if (cnt[0] != cnt[i]) break;
			++cntcnt;
		}
		ans[ti] = (n-cntcnt) / (cnt[0]-1) - 1;
	}

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


Since Sonya has just learned the basics of matrices, she decided to play with them a little bit.Sonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one zero, while all other cells have the Manhattan distance to the cell containing the zero. The cells with equal numbers have the form of a rhombus, that is why Sonya called this type so.The Manhattan distance between two cells ($$$x_1$$$, $$$y_1$$$) and ($$$x_2$$$, $$$y_2$$$) is defined as $$$|x_1 - x_2| + |y_1 - y_2|$$$. For example, the Manhattan distance between the cells $$$(5, 2)$$$ and $$$(7, 1)$$$ equals to $$$|5-7|+|2-1|=3$$$.    Example of a rhombic matrix. Note that rhombic matrices are uniquely defined by $$$n$$$, $$$m$$$, and the coordinates of the cell containing the zero.She drew a $$$n\times m$$$ rhombic matrix. She believes that you can not recreate the matrix if she gives you only the elements of this matrix in some arbitrary order (i.e., the sequence of $$$n\cdot m$$$ numbers). Note that Sonya will not give you $$$n$$$ and $$$m$$$, so only the sequence of numbers in this matrix will be at your disposal.Write a program that finds such an $$$n\times m$$$ rhombic matrix whose elements are the same as the elements in the sequence in some order.

The first line contains a single integer $$$t$$$ ($$$1\leq t\leq 10^6$$$) — the number of cells in the matrix. The second line contains $$$t$$$ integers $$$a_1, a_2, \ldots, a_t$$$ ($$$0\leq a_i< t$$$) — the values in the cells in arbitrary order.

In the first line, print two positive integers $$$n$$$ and $$$m$$$ ($$$n \times m = t$$$) — the size of the matrix. In the second line, print two integers $$$x$$$ and $$$y$$$ ($$$1\leq x\leq n$$$, $$$1\leq y\leq m$$$) — the row number and the column number where the cell with $$$0$$$ is located. If there are multiple possible answers, print any of them. If there is no solution, print the single integer $$$-1$$$.

NoteYou can see the solution to the first example in the legend. You also can choose the cell $$$(2, 2)$$$ for the cell where $$$0$$$ is located. You also can choose a $$$5\times 4$$$ matrix with zero at $$$(4, 2)$$$.In the second example, there is a $$$3\times 6$$$ matrix, where the zero is located at $$$(2, 3)$$$ there.In the third example, a solution does not exist.

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

Tuple!(int, int) getCenter(int n, int mx, int rw) {
    int x = rw, y = 1 + mx - (n - x);
    return tuple(x, y);
}

bool solve(int n, int m, int mx, int rw, int[] cnt) {
    auto t = getCenter(n, mx, rw);
    int x = t[0], y = t[1];

    if (n == 4 && m == 5) debug { t.writeln; }

    if (x < 1 || x > n || y < 1 || y > m) return false;

    auto curcnt = new int[] (n*m);
    curcnt[] = 0;

    foreach (int i; 1 .. n + 1) foreach (int j; 1 .. m + 1) ++curcnt[abs(i-x) + abs(j-y)];

    if (n == 4 && m == 5) debug { curcnt.take(10).writeln; }

    return curcnt == cnt[0 .. n*m];
}

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

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

    auto cnt = new int[10 ^^ 6 + 1];
    cnt[] = 0;
    arr.each!(x => ++cnt[x]);

    debug { cnt.take(10).writeln; }

    if (t == 1) {
        if (arr[0] == 0) {
            writeln("1 1");
            writeln("1 1");
            return;
        }

        writeln("-1");
        return;
    }

    if (!cnt.dropOne.canFind!(x => x % 4 != 0)) {
        writeln("-1");
        return;
    }

    debug { cnt.enumerate.dropOne.take(10).writeln; }

    auto rw = cast(int) cnt.enumerate.dropOne.find!(t => t[1] % 4 != 0).front.index;
    auto mx = arr.maxElement;

    foreach (n; t.iota.dropOne.until!(v => v > t / v)) {
        if (t % n != 0) continue;

        debug { n.writeln; }

        void writeAns(int n, int m) {
            writeln(n, ' ', m);
            auto c = getCenter(n, mx, rw);
            writeln(c[0], ' ', c[1]);
        }

        if (solve(n, t/n, mx, rw, cnt)) {
            writeAns(n, t/n);
            return;
        }
        if (solve(t/n, n, mx, rw, cnt)) {
            writeAns(t/n, n);
            return;
        }
    }

    writeln("-1");
}

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

Tuple!(int, int) getCenter(int n, int mx, int rw) {
    int x = rw, y = 1 + mx - (n - x);
    return tuple(x, y);
}

bool solve(int n, int m, int mx, int rw, int[] cnt) {
    auto t = getCenter(n, mx, rw);
    int x = t[0], y = t[1];

    if (x < 1 || x > n || y < 1 || y > m) return false;

    auto curcnt = new int[] (n*m);
    curcnt[] = 0;
    foreach (int i; 1 .. n + 1) foreach (int j; 1 .. m + 1) ++curcnt[abs(i-x) + abs(j-y)];

    return curcnt == cnt[0 .. n*m];
}

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

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

    auto cnt = new int[10 ^^ 6 + 1];
    cnt[] = 0;
    arr.each!(x => ++cnt[x]);

    if (t == 1) {
        if (arr[0] == 0) {
            writeln("1 1");
            writeln("1 1");
            return;
        }

        writeln("-1");
        return;
    }

    if (!cnt.dropOne.canFind!(x => x % 4 != 0)) {
        writeln("-1");
        return;
    }

    auto rw = cast(int) cnt.enumerate.dropOne.find!(t => t[1] % 4 != 0).front.index;
    auto mx = arr.maxElement;

    foreach (n; t.iota.dropOne.until!(v => v > t / v)) {
        if (t % n != 0) continue;

        void writeAns(int n, int m) {
            writeln(n, ' ', m);
            auto c = getCenter(n, mx, rw);
            writeln(c[0], ' ', c[1]);
        }

        if (solve(n, t/n, mx, rw, cnt)) {
            writeAns(n, t/n);
            return;
        }
        if (solve(t/n, n, mx, rw, cnt)) {
            writeAns(t/n, n);
            return;
        }
    }

    writeln("-1");
}

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

Tuple!(int, int) getCenter(int n, int mx, int rw) {
    int x = rw, y = 1 + mx - (n - x);
    return tuple(x, y);
}

bool solve(int n, int m, int mx, int rw, int[] cnt) {
    auto t = getCenter(n, mx, rw);
    int x = t[0], y = t[1];

    if (n == 4 && m == 5) debug { t.writeln; }

    if (x < 1 || x > n || y < 1 || y > m) return false;

    auto curcnt = new int[] (n*m);
    curcnt[] = 0;

    foreach (int i; 1 .. n + 1) foreach (int j; 1 .. m + 1) ++curcnt[abs(i-x) + abs(j-y)];

    if (n == 4 && m == 5) debug { curcnt.take(10).writeln; }

    return curcnt == cnt[0 .. n*m];
}

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

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

    auto cnt = new int[10 ^^ 6 + 1];
    cnt[] = 0;
    arr.each!(x => ++cnt[x]);

    debug { cnt.take(10).writeln; }

    if (!cnt.dropOne.canFind!(x => x % 4 != 0)) {
        writeln("-1");
        return;
    }

    debug { cnt.enumerate.dropOne.take(10).writeln; }

    auto rw = cast(int) cnt.enumerate.dropOne.find!(t => t[1] % 4 != 0).front.index;
    auto mx = arr.maxElement;

    foreach (n; t.iota.dropOne.until!(v => v > t / v)) {
        if (t % n != 0) continue;

        debug { n.writeln; }

        void writeAns(int n, int m) {
            writeln(n, ' ', m);
            auto c = getCenter(n, mx, rw);
            writeln(c[0], ' ', c[1]);
        }

        if (solve(n, t/n, mx, rw, cnt)) {
            writeAns(n, t/n);
            return;
        }
        if (solve(t/n, n, mx, rw, cnt)) {
            writeAns(t/n, n);
            return;
        }
    }

    writeln("-1");
}


Given a positive integer $$$k$$$, two arrays are called $$$k$$$-similar if:  they are strictly increasing;  they have the same length;  all their elements are positive integers between $$$1$$$ and $$$k$$$ (inclusive);  they differ in exactly one position. You are given an integer $$$k$$$, a strictly increasing array $$$a$$$ and $$$q$$$ queries. For each query, you are given two integers $$$l_i \leq r_i$$$. Your task is to find how many arrays $$$b$$$ exist, such that $$$b$$$ is $$$k$$$-similar to array $$$[a_{l_i},a_{l_i+1}\ldots,a_{r_i}]$$$.

The first line contains three integers $$$n$$$, $$$q$$$ and $$$k$$$ ($$$1\leq n, q \leq 10^5$$$, $$$n\leq k \leq 10^9$$$) — the length of array $$$a$$$, the number of queries and number $$$k$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots,a_n$$$ ($$$1 \leq a_i \leq k$$$). This array is strictly increasing  — $$$a_1 < a_2 < \ldots < a_n$$$. Each of the following $$$q$$$ lines contains two integers $$$l_i$$$, $$$r_i$$$ ($$$1 \leq l_i \leq r_i \leq n$$$).

Print $$$q$$$ lines. The $$$i$$$-th of them should contain the answer to the $$$i$$$-th query.

NoteIn the first example:In the first query there are $$$4$$$ arrays that are $$$5$$$-similar to $$$[2,4]$$$: $$$[1,4],[3,4],[2,3],[2,5]$$$.In the second query there are $$$3$$$ arrays that are $$$5$$$-similar to $$$[4,5]$$$: $$$[1,5],[2,5],[3,5]$$$.

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 N, Q; long K; get(N, Q, K);
    long[] aa; get(aa);
    auto cs = new long[](N);
    foreach (i; 1..N-1) cs[i] = cs[i-1] + aa[i+1] - aa[i-1] - 2;

    while (Q--) {
        int l, r; get(l, r); --l; --r;
        writeln(l == r ? K-1 : aa[l+1] - 2 + K - aa[r-1] - 1 + cs[r-1] - cs[l]);
    }
}

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 n = RD!int;
	auto q = RD!int;
	auto k = RD!int;
	auto a = RDA;
	auto w = new long[](n);
	a = 0L ~ a ~ (k+1L);
	foreach (i; 0..n)
	{
		w[i] += a[i+1] - a[i] - 1;
		w[i] += a[i+2] - a[i+1] - 1;
	}
	auto ww = new long[](n+1);
	foreach (i; 0..n)
	{
		ww[i+1] = ww[i] + w[i];
	}
	debug writeln("ww:", ww);

	auto ans = new long[](q);
	foreach (i; 0..q)
	{
		auto l = RD!int-1;
		auto r = RD!int-1;
		ans[i] = a[l] + a[$-1] - a[r+2];
		debug writeln("a[l]:", a[l] , " a[r+2]:", a[r+2] );
		ans[i] += ww[r+1] - ww[l];
		debug writeln("ww[r]:", ww[r+1], " ww[l]:", ww[l]);
	}

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

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

void main ()
{
	int n, q, k;
	while (readf !(" %s %s %s") (n, q, k) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		a = 0 ~ a ~ (k + 1);
		foreach (s; 0..q)
		{
			int l, r;
			readf !(" %s %s") (l, r);
			int res = a[l];
			res += k - a[r] - 1;
			res += 2 * (a[r] - a[l] - r + l);
			writeln (res);
		}
	}
}

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 N, Q; long K; get(N, Q, K);
    long[] aa; get(aa);
    auto cs = new long[](N);
    foreach (i; 1..N-1) cs[i] = cs[i-1] + aa[i+1] - aa[i-1] - 2;

    while (Q--) {
        int l, r; get(l, r); --l; --r;
        writeln(aa[l+1] - 2 + K - aa[r-1] - 1 + cs[r-1] - cs[l]);
    }
}

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 N, Q, K; get(N, Q, K);
    int[] aa; get(aa);
    auto cs = new long[](N);
    foreach (i; 1..N-1) {
        cs[i] = cs[i-1];
        cs[i] += aa[i+1] - aa[i-1] - 2;
    }

    while (Q--) {
        int l, r; get(l, r); --l; --r;
        writeln(aa[l+1] - 2 + K - aa[r-1] - 1 + cs[r-1] - cs[l]);
    }
}


Phoenix is playing with a new puzzle, which consists of $$$n$$$ identical puzzle pieces. Each puzzle piece is a right isosceles triangle as shown below.    A puzzle piece The goal of the puzzle is to create a square using the $$$n$$$ pieces. He is allowed to rotate and move the pieces around, but none of them can overlap and all $$$n$$$ pieces must be used (of course, the square shouldn't contain any holes as well). Can he do it?

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the number of puzzle pieces.

For each test case, if Phoenix can create a square with the $$$n$$$ puzzle pieces, print YES. Otherwise, print NO.

NoteFor $$$n=2$$$, Phoenix can create a square like this:    For $$$n=4$$$, Phoenix can create a square like this:    For $$$n=6$$$, it is impossible for Phoenix to create a square.

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

bool isSquare (int n)
{
	auto p = cast (int) (sqrt (n * 1.0) + 0.5);
	return p * p == n;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		while (true)
		{
			if (n & 1)
			{
				writeln ("NO");
				break;
			}
			n /= 2;
			if (isSquare (n))
			{
				writeln ("YES");
				break;
			}
		}
	}
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		if (n % 2) continue;
		for (long i = 1; i*i <= n; ++i)
		{
			if (n % i) continue;
			if (i*i*2 == n || i*i*4 == n)
			{
				ans[ti] = true;
			}
		}
	}

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

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

void main()
{
	int t = readInt!int;
	while (t--)
	{
		long n = readInt!int;
		bool isSquare(long q) { long r = cast(long) sqrt(cast(real)q); return r * r == q; }
		bool can = only(2, 4).any!(d => n % d == 0 && isSquare(n/d));
		if (can) "YES".writeln; else "NO".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.range;
import std.stdio;
import std.string;

bool isSquare (int n)
{
	auto p = cast (int) (sqrt (n * 1.0) + 0.5);
	return p * p == n;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		foreach (j; 0..2)
		{
			if (n & 1)
			{
				writeln ("NO");
				break;
			}
			n /= 2;
			if (isSquare (n))
			{
				writeln ("YES");
				break;
			}
		}
	}
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		if (n == 1) continue;
		ans[ti] = popcnt(n) == 1;
	}

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


You are given a table consisting of n rows and m columns.Numbers in each row form a permutation of integers from 1 to m.You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to n + 1 actions in total. Operations can be performed in any order.You have to check whether it's possible to obtain the identity permutation 1, 2, ..., m in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order.

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 20) — the number of rows and the number of columns in the given table.  Each of next n lines contains m integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to m.

If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).

NoteIn the first sample, one can act in the following way:   Swap second and third columns. Now the table is 1 2 3 4 1 4 3 2  In the second row, swap the second and the fourth elements. Now the table is 1 2 3 4 1 2 3 4

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, m;
int[20][20] a;

bool check(const(int)[ ] where) {
    debug writeln(where);
    int[20][20] b = a;
    foreach (ref line; b[0 .. n]) {
        bool swapped = false;
    again:
        debug writeln("Line: ", line[0 .. m]);
        foreach (i; 0 .. m) {
            const what = line[i] - 1;
            debug writeln(i, ' ', what, ' ', where[what], ' ', i);
            if (where[what] != i) {
                if (swapped)
                    return false;
                foreach (j; 0 .. m)
                    if (where[line[j] - 1] == i) {
                        swap(line[i], line[j]);
                        debug writefln("Swapped %d and %d", i, j);
                        swapped = true;
                        goto again;
                    }
            }
        }
    }
    return true;
}

void main() {
    while (read(&n, &m)) {
        int[20] _trg;
        int[ ] trg = _trg[0 .. m];
        foreach (i; 0 .. m)
            trg[i] = i;
        foreach (ref line; a[0 .. n])
            foreach (ref x; line[0 .. m])
                read(&x);
        foreach (i; 0 .. n) {
            foreach (j; 0 .. m)
                debug write(a[i][j], ' ');
            debug writeln();
        }
        if (check(trg))
            write("YES\n");
        else {
            foreach (i, ref x; trg)
                foreach (ref y; trg[i + 1 .. m]) {
                    swap(x, y);
                    if (check(trg)) {
                        write("YES\n");
                        goto nextCase;
                    }
                    swap(x, y);
                }
            write("NO\n");
        }
    nextCase:
        ;
    }
}

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

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

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

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

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

bool check(int y0, int y1) {
  foreach (x; 0 .. M) {
    int cnt;
    foreach (y; 0 .. N) {
      const a = A[x][(y == y0) ? y1 : (y == y1) ? y0 : y];
      if (a != y) {
        ++cnt;
      }
    }
    if (cnt > 2) {
      return false;
    }
  }
  debug {
    writeln("ok ", y0, " ", y1);
  }
  return true;
}

bool solve() {
  if (check(-1, -1)) {
    return true;
  }
  foreach (y0; 0 .. N) foreach (y1; y0 + 1 .. N) {
    if (check(y0, y1)) {
      return true;
    }
  }
  return false;
}

void main() {
  try {
    for (; ; ) {
      M = readInt();
      N = readInt();
      A = new int[][](M, N);
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        A[x][y] = readInt() - 1;
      }

      const ans = solve();
      writeln(ans ? "YES" : "NO");
    }
  } catch (EOFException e) {
  }
}


Walking along a riverside, Mino silently takes a note of something."Time," Mino thinks aloud."What?""Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this.""And what are you recording?""You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.Doubtfully, Kanno peeks at Mino's records. The records are expressed as a string $$$s$$$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $$$p$$$ is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.In this problem, a positive integer $$$p$$$ is considered a period of string $$$s$$$, if for all $$$1 \leq i \leq \lvert s \rvert - p$$$, the $$$i$$$-th and $$$(i + p)$$$-th characters of $$$s$$$ are the same. Here $$$\lvert s \rvert$$$ is the length of $$$s$$$.

The first line contains two space-separated integers $$$n$$$ and $$$p$$$ ($$$1 \leq p \leq n \leq 2000$$$) — the length of the given string and the supposed period, respectively. The second line contains a string $$$s$$$ of $$$n$$$ characters — Mino's records. $$$s$$$ only contains characters '0', '1' and '.', and contains at least one '.' character.

Output one line — if it's possible that $$$p$$$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).

NoteIn the first example, $$$7$$$ is not a period of the resulting string because the $$$1$$$-st and $$$8$$$-th characters of it are different.In the second example, $$$6$$$ is not a period of the resulting string because the $$$4$$$-th and $$$10$$$-th characters of it are different.In the third example, $$$9$$$ is always a period because the only constraint that the first and last characters are the same is already satisfied.Note that there are multiple acceptable answers for the first two examples, you can print any of them.

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

immutable long MOD = 10^^9+7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto p = s[1];
    auto S = readln.chomp.to!(dchar[]);

    bool ans = false;

    for (int i = 0; i + p < N; ++i) {
        int j = i + p;
        if (S[i] == '.') {
            ans = true;
            if (S[i] == S[j]) {
                S[i] = '0';
                S[j] = '1';
            } else {
                S[i] = S[j] == '0' ? '1' : '0';
            }
        } else if (S[j] == '.') {
            ans = true;
            S[j] = S[i] == '0' ? '1' : '0';
        } else if (S[i] == '0' && S[j] == '1') {
            ans = true;
        } else if (S[i] == '1' && S[j] == '0') {
            ans = true;
        }
    }

    if (ans) {
        foreach (i; 0..N) if (S[i] == '.') S[i] = '0';
        S.writeln;
    } else {
        writeln("No");
    }
}

import std.algorithm;
import std.array;
import std.bitmanip;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

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

    auto a = readln.chomp.to!(dchar[]);
    auto b = a.dup;
    foreach (ref e; b) if (e == '.') e = '0';

    auto c = b.dup;
    auto pos = a.indexOf('.');
    if (pos != -1) c[pos] = '1';

    auto d = b.dup;
    pos = a.lastIndexOf('.');
    if (pos != -1) d[pos] = '1';

    debug { b.writeln; c.writeln; d.writeln; }

    bool check(const dchar[] s, immutable int p) {
        foreach (st; 0..p) {
            auto sq = s.drop(st).stride(p);
            foreach (a, b; lockstep(sq, sq.dropOne)) {
                if (a != b) return true;
            }
        }
        return false;
    }

    writeln(check(b, p) ? b : check(c, p) ? c : check(d, p) ? d : "No");
}

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

immutable long MOD = 10^^9+7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto p = s[1];
    auto S = readln.chomp.to!(dchar[]);

    bool ans = false;

    for (int i = 0; i + p < N; ++i) {
        int j = i + p;
        if (S[i] == '.') {
            ans = true;
            if (S[i] == S[j]) {
                S[i] = '0';
                S[j] = '1';
            } else {
                S[i] = S[j] == '0' ? '1' : '0';
            }
        } else if (S[j] == '.') {
            ans = true;
            S[j] = S[i] == '0' ? '1' : '0';
        } else if (S[i] == '0' && S[j] == '1') {
            ans = true;
        } else if (S[i] == '1' && S[j] == '0') {
            ans = true;
        }
    }

    if (ans) {
        writeln("Yes");
        foreach (i; 0..N) if (S[i] == '.') S[i] = '0';
        S.writeln;
    } else {
        writeln("No");
    }
}

import std.algorithm;
import std.array;
import std.bitmanip;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

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

    auto a = readln.chomp.to!(dchar[]);
    auto b = a.dup;
    foreach (ref e; b) if (e == '.') e = '0';

    auto c = b.dup;
    auto pos = a.lastIndexOf('.');
    if (pos != -1) c[pos] = '1';

    debug { b.writeln; c.writeln; }

    bool check(const dchar[] s, immutable int p) {
        foreach (st; 0..p) {
            auto sq = s.drop(st).stride(p);
            foreach (a, b; lockstep(sq, sq.dropOne)) {
                if (a != b) return true;
            }
        }
        return false;
    }

    writeln(check(b, p) ? b : check(c, p) ? c : "No");
}

import std.algorithm;
import std.array;
import std.bitmanip;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

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

    auto a = readln.chomp.to!(dchar[]);
    auto b = a.dup;
    foreach (ref e; b) if (e == '.') e = '0';

    auto c = b.dup;
    auto pos = a.indexOf('.');
    if (pos != -1) c[pos] = '1';

    debug { b.writeln; c.writeln; }

    bool check(const dchar[] s, immutable int p) {
        foreach (st; 0..p) {
            auto sq = s.drop(st).stride(p);
            foreach (a, b; lockstep(sq, sq.dropOne)) {
                if (a != b) return true;
            }
        }
        return false;
    }

    writeln(check(b, p) ? b : check(c, p) ? c : "No");
}


Polycarp has come up with a new game to play with you. He calls it "A missing bigram".A bigram of a word is a sequence of two adjacent letters in it.For example, word "abbaaba" contains bigrams "ab", "bb", "ba", "aa", "ab" and "ba".The game goes as follows. First, Polycarp comes up with a word, consisting only of lowercase letters 'a' and 'b'. Then, he writes down all its bigrams on a whiteboard in the same order as they appear in the word. After that, he wipes one of them off the whiteboard.Finally, Polycarp invites you to guess what the word that he has come up with was.Your goal is to find any word such that it's possible to write down all its bigrams and remove one of them, so that the resulting sequence of bigrams is the same as the one Polycarp ended up with.The tests are generated in such a way that the answer exists. If there are multiple answers, you can print any of them.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$3 \le n \le 100$$$) — the length of the word Polycarp has come up with. The second line of each testcase contains $$$n-2$$$ bigrams of that word, separated by a single space. Each bigram consists of two letters, each of them is either 'a' or 'b'. Additional constraint on the input: there exists at least one string such that it is possible to write down all its bigrams, except one, so that the resulting sequence is the same as the sequence in the input. In other words, the answer exists.

For each testcase print a word, consisting of $$$n$$$ letters, each of them should be either 'a' or 'b'. It should be possible to write down all its bigrams and remove one of them, so that the resulting sequence of bigrams is the same as the one Polycarp ended up with. The tests are generated in such a way that the answer exists. If there are multiple answers, you can print any of them.

4
7
ab bb ba aa ba
7
ab ba aa ab ba
3
aa
5
bb ab bb

NoteThe first two testcases from the example are produced from the word "abbaaba". As listed in the statement, it contains bigrams "ab", "bb", "ba", "aa", "ab" and "ba".In the first testcase, the $$$5$$$-th bigram is removed. In the second testcase, the $$$2$$$-nd bigram is removed. However, that sequence could also have been produced from the word "abaabaa". It contains bigrams "ab", "ba", "aa", "ab", "ba" and "aa". The missing bigram is the $$$6$$$-th one.In the third testcase, all of "baa", "aab" and "aaa" are valid answers.

immutable multi = true;

void solve(int tc)
{
  auto n = readInt!int;
  auto s = ma(n - 2, cast(byte[])readString);
  byte[] word;
  word ~= s[0][0];
  bool incident = false;
  foreach(i; 1 .. n - 2)
    {
      word ~= s[i-1][1];
      if (s[i][0] != s[i-1][1]) { assert(!incident); word ~= s[i][0]; incident = true; }
    }
  word ~= s[$-1][1];
  if (!incident) word ~= s[$-1][1];
  (cast(string)word).writeln;
}

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

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

void popChar()
{
	import core.stdc.stdio;
	currChar = getchar();
}

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

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

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

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    long n;
    readf!" %d "(n);
    auto a = readln.splitter.array;
    string ans = a[0];
    string missing;
    int[] candel;
    foreach (x ; a[1 .. $]) {
      if (ans[$ - 1] == x[0]) {
        ans ~= x[1];
      } else if (missing == "") {
        missing ~= ans[$ - 1];
        missing ~= x[0];
        ans ~= missing[1];
        ans ~= x[1];
      } else {
        assert(false);
      }
    }
    if (missing == "") {
      ans ~= ans[$ - 1];
    }
    assert(n == ans.length);
    writeln(ans);
  }
}

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

void solve(){
    long n = scan;
    dchar[][] arr;
    for(int i = 0; i < n-2; ++i){
        arr ~= scan!(dchar[]);
    }
    show(arr);
    dchar[] w;
    w ~= arr[0];
    bool f = 0;
    for(int i = 1; i < n - 2; ++i){
        if(w.back == arr[i][0]){
            w ~= arr[i][1];
        }else{
            f = 1;
            w ~= arr[i];
        }
    }
    if(!f){
        w ~= 'a';
    }
    writeln(w);
}

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

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


There are $$$n$$$ blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed $$$3 \cdot n$$$. If it is impossible to find such a sequence of operations, you need to report it.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 200$$$) — the number of blocks. The second line contains one string $$$s$$$ consisting of $$$n$$$ characters, each character is either "W" or "B". If the $$$i$$$-th character is "W", then the $$$i$$$-th block is white. If the $$$i$$$-th character is "B", then the $$$i$$$-th block is black.

If it is impossible to make all the blocks having the same color, print $$$-1$$$. Otherwise, print an integer $$$k$$$ ($$$0 \le k \le 3 \cdot n$$$) — the number of operations. Then print $$$k$$$ integers $$$p_1, p_2, \dots, p_k$$$ $$$(1 \le p_j \le n - 1)$$$, where $$$p_j$$$ is the position of the left block in the pair of blocks that should be affected by the $$$j$$$-th operation. If there are multiple answers, print any of them.

NoteIn the first example, it is possible to make all blocks black in $$$3$$$ operations. Start with changing blocks $$$6$$$ and $$$7$$$, so the sequence is "BWWWWBBB". Then change blocks $$$2$$$ and $$$3$$$, so the sequence is "BBBWWBB". And finally, change blocks $$$4$$$ and $$$5$$$, so all blocks are black.It is impossible to make all colors equal in the second example.All blocks are already white in the third example.In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks $$$2$$$ and $$$3$$$ (so the sequence is "BBW"), and then change blocks $$$1$$$ and $$$2$$$ (so all blocks are white).

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto n = RD!int;
	auto ss = RD!(char[]);
	int[] ans;
	bool ok1 = true;
	bool ok2 = true;
	foreach (i; 0..n)
	{
		if (ss[i] == 'B')
			ok1 = false;
		if (ss[i] == 'W')
			ok2 = false;
	}
	if (ok1 || ok2)
		writeln(0);
	else
	{
		auto keys1 = ["WW", "BB"];
		auto keys2 = ["WB", "BW"];
		auto keys3 = ['B', 'W'];
		auto keys4 = ['W', 'B'];
		foreach (pat; 0..2)
		{
			auto s = ss.dup;
			foreach (i; 1..n)
			{
				if (s[i-1..i+1] == keys1[pat])
				{
					ans ~= i;
					s[i-1] = keys3[pat];
					s[i] = keys3[pat];
				}
				else if (s[i-1..i+1] == keys2[pat])
				{
					ans ~= i;
					s[i-1] = keys3[pat];
					s[i] = keys4[pat];
				}
			}
			if (s[$-1] == keys4[pat])
			{
				ans.length = 0;
				continue;
			}
			else
				break;
		}
		if (ans.empty)
			writeln(-1);
		else
		{
			writeln(ans.length);
			ans.map!(to!string).join(" ").writeln;
		}
	}

	stdout.flush;
	debug readln;
}