Sho has an array $$$a$$$ consisting of $$$n$$$ integers. An operation consists of choosing two distinct indices $$$i$$$ and $$$j$$$ and removing $$$a_i$$$ and $$$a_j$$$ from the array.For example, for the array $$$[2, 3, 4, 2, 5]$$$, Sho can choose to remove indices $$$1$$$ and $$$3$$$. After this operation, the array becomes $$$[3, 2, 5]$$$. Note that after any operation, the length of the array is reduced by two.After he made some operations, Sho has an array that has only distinct elements. In addition, he made operations such that the resulting array is the longest possible. More formally, the array after Sho has made his operations respects these criteria:   No pairs such that ($$$i < j$$$) and $$$a_i = a_j$$$ exist.  The length of $$$a$$$ is maximized. Output the length of the final array.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_i$$$ ($$$1 \leq a_i \leq 10^4$$$) — the elements of the array.

For each test case, output a single integer — the length of the final array. Remember that in the final array, all elements are different, and its length is maximum.

NoteFor the first test case Sho can perform operations as follows:   Choose indices $$$1$$$ and $$$5$$$ to remove. The array becomes $$$[2, 2, 2, 3, 3, 3] \rightarrow [2, 2, 3, 3]$$$.  Choose indices $$$1$$$ and $$$4$$$ to remove. The array becomes $$$[2, 2, 3, 3] \rightarrow [2, 3]$$$.  The final array has a length of $$$2$$$, so the answer is $$$2$$$. It can be proven that Sho cannot obtain an array with a longer length.For the second test case Sho can perform operations as follows:   Choose indices $$$3$$$ and $$$4$$$ to remove. The array becomes $$$[9, 1, 9, 9, 1] \rightarrow [9, 1, 1]$$$.  Choose indices $$$1$$$ and $$$3$$$ to remove. The array becomes $$$[9, 1, 1] \rightarrow [1]$$$.  The final array has a length of $$$1$$$, so the answer is $$$1$$$. It can be proven that Sho cannot obtain an array with a longer length.

void main() { runSolver(); }

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

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

      auto g = A.sort.group;
      auto evens = g.count!"a[1] % 2 == 0";
      auto odds = g.count!"a[1] % 2 == 1";

      return evens + odds - evens%2;
    }

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

  outputForAtCoder(&solve);
}

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

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

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


Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice". So now Ilya wants to compare his robots' performance in a simple game called "1-2-3". This game is similar to the "Rock-Paper-Scissors" game: both robots secretly choose a number from the set {1, 2, 3} and say it at the same moment. If both robots choose the same number, then it's a draw and noone gets any points. But if chosen numbers are different, then one of the robots gets a point: 3 beats 2, 2 beats 1 and 1 beats 3. Both robots' programs make them choose their numbers in such a way that their choice in (i + 1)-th game depends only on the numbers chosen by them in i-th game. Ilya knows that the robots will play k games, Alice will choose number a in the first game, and Bob will choose b in the first game. He also knows both robots' programs and can tell what each robot will choose depending on their choices in previous game. Ilya doesn't want to wait until robots play all k games, so he asks you to predict the number of points they will have after the final game.

The first line contains three numbers k, a, b (1 ≤ k ≤ 1018, 1 ≤ a, b ≤ 3).  Then 3 lines follow, i-th of them containing 3 numbers Ai, 1, Ai, 2, Ai, 3, where Ai, j represents Alice's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Ai, j ≤ 3).  Then 3 lines follow, i-th of them containing 3 numbers Bi, 1, Bi, 2, Bi, 3, where Bi, j represents Bob's choice in the game if Alice chose i in previous game and Bob chose j (1 ≤ Bi, j ≤ 3).

Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after k games.

NoteIn the second example game goes like this:The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice.

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

void main()
{
    long k;
    int a, b;
    readf("%s %s %s", &k, &a, &b);
    readln;

    auto mx = new int[][][] (2, 3, 3);
    foreach (i; 0 .. 2) {
        foreach (j; 0 .. 3) {
            auto rw = readln.chomp.split.map!(to!int).map!(x => x-1).array;
            mx[i][j] = rw;
        }
    }

    debug { mx.writeln; }

    void updScore(int a, int b, ref long sca, ref long scb) {
        if (a == b+1 || a+3 == b+1) { sca += 1; }
        else if (a != b) { scb += 1; }
    }

    void proceedToNextGame(ref int a, ref int b, ref long played) {
        int na = mx[0][a][b], nb = mx[1][a][b];
        a  = na, b = nb;

        ++played;
    }

    long alice = 0, bob = 0;
    int[Tuple!(int, int)] hist;
    int[] histalice, histbob;
    histalice ~= 0;
    histbob ~= 0;
    long played = 0;
    --a, --b;
    do {
        debug { writeln(played, ' ', a, ' ', b); }

        hist[tuple(a, b)] = played.to!int + 1;

        updScore(a, b, alice, bob);

        histalice ~= alice.to!int;
        histbob ~= bob.to!int;

        proceedToNextGame(a, b, played);
    } while (played < k && hist.get(tuple(a, b), -1) == -1);

    if (played < k) {
        debug { writeln("cycle"); }

        int prev = hist[tuple(a, b)] - 1;
        int cycleLen = played.to!int - prev;

        long fits = (k - played) / cycleLen;

        int aliceInCycle = alice.to!int - histalice[prev];
        int bobInCycle = bob.to!int - histbob[prev];

        debug { writeln(played, ' ', cycleLen, ' ', fits, ' ', aliceInCycle, ' ', bobInCycle); }

        alice += fits * aliceInCycle;
        bob += fits * bobInCycle;
        played += fits * cycleLen;
    }

    while (played < k) {
        debug { writeln("played ", played); }

        updScore(a, b, alice, bob);

        proceedToNextGame(a, b, played);
    }

    writeln(alice, ' ', bob);
}


You're given the centers of three equal sides of a strictly convex tetragon. Your task is to restore the initial tetragon.

The first input line contains one number T — amount of tests (1 ≤ T ≤ 5·104). Each of the following T lines contains numbers x1, y1, x2, y2, x3, y3 — coordinates of different points that are the centers of three equal sides (non-negative integer numbers, not exceeding 10).

For each test output two lines. If the required tetragon exists, output in the first line YES, in the second line — four pairs of numbers — coordinates of the polygon's vertices in clockwise or counter-clockwise order. Don't forget, please, that the tetragon should be strictly convex, i.e. no 3 of its points lie on one line. Output numbers with 9 characters after a decimal point. If the required tetragon doen't exist, output NO in the first line, and leave the second line empty.

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

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

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

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

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

immutable EPS = 1e-10;
immutable INF = 1e+10;
int sig(in real r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
real arg(in creal a) { return atan2(a.im, a.re); }
real dot(in creal a, in creal b) { return a.re * b.re + a.im * b.im; }
real det(in creal a, in creal b) { return a.re * b.im - a.im * b.re; }
real tri(in creal a, in creal b, in creal c) { return (b - a).det(c - a); }

creal circumcenter(in creal a, in creal b, in creal c) {
	const bc = c - b, ca = a - c, ab = b - a;
	return (b + c - bc * 1i * ca.dot(ab) / ca.det(ab)) / 2.0;
}

creal[] check(creal p, creal q, creal r) {
// writeln("check ",p," ",q," ",r);
	creal s = q * 2.0 - r;
	if (sig(tri(p, q, s)) == 0) {
		return null;
	}
	creal[] as = new creal[4];
	as[1] = circumcenter(p, q, s);
	as[0] = p * 2.0 - as[1];
	as[2] = q * 2.0 - as[1];
	as[3] = r * 2.0 - as[2];
// writeln("  as = ",as);
	foreach (i; 0 .. 4) {
		if (sig(abs(as[(i + 1) % 4] - as[i])) == 0) {
			return null;
		}
	}
	real area = 0.0;
	foreach (i; 0 .. 4) {
		area += as[i].det(as[(i + 1) % 4]);
	}
	if (area < 0) {
		as[1 .. $].reverse;
	}
// writeln("  as = ",as);
	foreach (i; 0 .. 4) {
		if (sig((as[(i + 2) % 4] - as[(i + 1) % 4]).det(as[i] - as[(i + 1) % 4])) <= 0) {
			return null;
		}
	}
// writeln("  as = ",as);
	return as;
}

creal[] P;

creal[] solve() {
// writeln(P);
	if (auto res = check(P[1], P[0], P[2])) return res;
	if (auto res = check(P[0], P[1], P[2])) return res;
	if (auto res = check(P[0], P[2], P[1])) return res;
	return null;
}

void main(string[] args) {
	// try {
	for (int TC = readInt; TC--; ) {
		P = new creal[3];
		foreach (i; 0 .. 3) {
			const x = readReal;
			const y = readReal;
			P[i] = x + y * 1i;
		}

		const res = solve;
		if (res) {
			writeln("YES");
			foreach (i; 0 .. 4) {
				if (i > 0) {
					write(" ");
				}
				writef("%.9f %.9f", res[i].re, res[i].im);
			}
			writeln;
		} else {
			writeln("NO");
			writeln;
		}
	}
	// } catch (EOFException) {}
}


Given an array of $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 1000$$$). Find the maximum value of $$$i + j$$$ such that $$$a_i$$$ and $$$a_j$$$ are coprime,$$$^{\dagger}$$$ or $$$-1$$$ if no such $$$i$$$, $$$j$$$ exist.For example consider the array $$$[1, 3, 5, 2, 4, 7, 7]$$$. The maximum value of $$$i + j$$$ that can be obtained is $$$5 + 7$$$, since $$$a_5 = 4$$$ and $$$a_7 = 7$$$ are coprime.$$$^{\dagger}$$$ Two integers $$$p$$$ and $$$q$$$ are coprime if the only positive integer that is a divisor of both of them is $$$1$$$ (that is, their greatest common divisor is $$$1$$$).

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 2\cdot10^5$$$) — the length of the array. The following line contains $$$n$$$ space-separated positive integers $$$a_1$$$, $$$a_2$$$,..., $$$a_n$$$ ($$$1 \leq a_i \leq 1000$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

For each test case, output a single integer  — the maximum value of $$$i + j$$$ such that $$$i$$$ and $$$j$$$ satisfy the condition that $$$a_i$$$ and $$$a_j$$$ are coprime, or output $$$-1$$$ in case no $$$i$$$, $$$j$$$ satisfy the condition.

NoteFor the first test case, we can choose $$$i = j = 3$$$, with sum of indices equal to $$$6$$$, since $$$1$$$ and $$$1$$$ are coprime.For the second test case, we can choose $$$i = 7$$$ and $$$j = 5$$$, with sum of indices equal to $$$7 + 5 = 12$$$, since $$$7$$$ and $$$4$$$ are coprime.

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()
{
  auto coprimes = new byte[1001][1001];
  foreach (i ; 1 .. 1001) {
    foreach (j ; i .. 1001) {
      if (gcd(i, j) == 1) {
        coprimes[i][j] = 1;
        coprimes[j][i] = 1;
      }
    }
  }
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    int n;
    readf!" %d "(n);
    auto a = readln.splitter.map!(to!int).array;
    auto b = zip(iota(1, a.length + 1), a).array.sort!((x, y) => x[1] == y[1] ? x[0] > y[0] : x[1] > y[1]);
    auto c = b.uniq!((x, y) => x[1] == y[1]).array;
    long ans = -1;
    foreach (i ; 0 .. c.length) {
      foreach (j ; 0 .. c.length) {
        if (coprimes[c[i][1]][c[j][1]])
          ans = max(ans, c[i][0] + c[j][0]);
      }
    }
    writeln(ans);
  }
}

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

T read(T)() { return readln.chomp.to!T; }
T[] readarray(T)() { return readln.chomp.split(" ").map!(to!T).array; }

void solve() {
    int N = read!int;
    auto A = readarray!int;
    int[int] last;
    for (int i = 0; i < N; i++) {
        last[A[i]] = i;
    }
    int ans = -1;
    foreach (v, i; last) {
        foreach (u, j; last) {
            if (gcd(v, u) == 1) {
                ans = max(ans, i + j + 2);
            }
        }
    }
    writeln(ans);
}

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


$$$n$$$ students attended the first meeting of the Berland SU programming course ($$$n$$$ is even). All students will be divided into two groups. Each group will be attending exactly one lesson each week during one of the five working days (Monday, Tuesday, Wednesday, Thursday and Friday), and the days chosen for the groups must be different. Furthermore, both groups should contain the same number of students.Each student has filled a survey in which they told which days of the week are convenient for them to attend a lesson, and which are not. Your task is to determine if it is possible to choose two different week days to schedule the lessons for the group (the first group will attend the lesson on the first chosen day, the second group will attend the lesson on the second chosen day), and divide the students into two groups, so the groups have equal sizes, and for each student, the chosen lesson day for their group is convenient.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. Then the descriptions of $$$t$$$ testcases follow. The first line of each testcase contains one integer $$$n$$$ ($$$2 \le n \le 1\,000$$$) — the number of students. The $$$i$$$-th of the next $$$n$$$ lines contains $$$5$$$ integers, each of them is $$$0$$$ or $$$1$$$. If the $$$j$$$-th integer is $$$1$$$, then the $$$i$$$-th student can attend the lessons on the $$$j$$$-th day of the week. If the $$$j$$$-th integer is $$$0$$$, then the $$$i$$$-th student cannot attend the lessons on the $$$j$$$-th day of the week.  Additional constraints on the input: for each student, at least one of the days of the week is convenient, the total number of students over all testcases doesn't exceed $$$10^5$$$.

For each testcase print an answer. If it's possible to divide the students into two groups of equal sizes and choose different days for the groups so each student can attend the lesson in the chosen day of their group, print "YES" (without quotes). Otherwise, print "NO" (without quotes).

NoteIn the first testcase, there is a way to meet all the constraints. For example, the first group can consist of the first and the third students, they will attend the lessons on Thursday (the fourth day); the second group can consist of the second and the fourth students, and they will attend the lessons on Tuesday (the second day).In the second testcase, it is impossible to divide the students into groups so they attend the lessons on different days.

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

void main()
{
    int t;
    scanf("%d", &t);
    foreach(_; 0..t)
    {
        int n;
        scanf("%d", &n);
        getchar();
        int[] carr = new int[n];
        for (int k = 0; k < n; k++)
            carr[k] = k;
        int[][5] a;
        for (int k=0; k < n; k++)
        {
            auto tmp = readln.split().to!(int[]);
            for (int z = 0; z < 5; z++)
            {
                if (tmp[z] == 1)
                    a[z] ~= k;
            }
        }
        // writeln(a);
        bool flag = false;
        outer: for (int x = 0; x < 5; x++)
        {
            for (int z = x + 1; z < 5; z++)
            {
                // writeln("X:",x," Z:", z);
                auto tmp = (a[x] ~ a[z]);
                // writeln(tmp);
                tmp.sort();
                if ((a[x].length >= n / 2) && (a[z].length >= n / 2) && (equal(uniq(tmp), carr[])))
                {
                    writeln("YES");
                    flag = true;
                    break outer;
                }
                // writeln((uniq(a[x] ~a[z])));
            }
        }
        if (!flag)
            writeln("NO");
    }
}


You are given a number $$$k$$$ and a string $$$s$$$ of length $$$n$$$, consisting of the characters '.' and '*'. You want to replace some of the '*' characters with 'x' characters so that the following conditions are met:   The first character '*' in the original string should be replaced with 'x';  The last character '*' in the original string should be replaced with 'x';  The distance between two neighboring replaced characters 'x' must not exceed $$$k$$$ (more formally, if you replaced characters at positions $$$i$$$ and $$$j$$$ ($$$i < j$$$) and at positions $$$[i+1, j-1]$$$ there is no "x" symbol, then $$$j-i$$$ must be no more than $$$k$$$). For example, if $$$n=7$$$, $$$s=$$$.**.*** and $$$k=3$$$, then the following strings will satisfy the conditions above:   .xx.*xx;  .x*.x*x;  .xx.xxx.  But, for example, the following strings will not meet the conditions:   .**.*xx (the first character '*' should be replaced with 'x');  .x*.xx* (the last character '*' should be replaced with 'x');  .x*.*xx (the distance between characters at positions $$$2$$$ and $$$6$$$ is greater than $$$k=3$$$). Given $$$n$$$, $$$k$$$, and $$$s$$$, find the minimum number of '*' characters that must be replaced with 'x' in order to meet the above conditions.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 500$$$). Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 50$$$). The second line of each test case contains a string $$$s$$$ of length $$$n$$$, consisting of the characters '.' and '*'. It is guaranteed that there is at least one '*' in the string $$$s$$$. It is guaranteed that the distance between any two neighboring '*' characters does not exceed $$$k$$$.

For each test case output the minimum number of '*' characters that must be replaced with 'x' characters in order to satisfy the conditions above.

// Vicfred
// https://codeforces.com/contest/1506/problem/B
// greedy
import std.algorithm;
import std.stdio;

void main() {
    long t;
    readf("%s\n", &t);

while(t--) {
    long n, k;
    string s;

    readf("%s %s\n", &n, &k);
    readf("%s\n", &s);

    long idx = -1;
    for(int i = 0; i < n; ++i) {
        if(s[i] == '*') {
            idx = i;
            break;
        }
    }

    long ans = 1;

    while(true) {
        long j = min(n - 1, idx + k);
        while(s[cast(uint)j] == '.')
            j -= 1;
        if(idx == j)
            break;
        idx = j;
        ans += 1;
    }

    ans.writeln;
}
}


This problem is same as the previous one, but has larger constraints.It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic.At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $$$(x_i, y_i)$$$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire.Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem?

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — the number of electric poles. Each of the following $$$n$$$ lines contains two integers $$$x_i$$$, $$$y_i$$$ ($$$-10^4 \le x_i, y_i \le 10^4$$$) — the coordinates of the poles. It is guaranteed that all of these $$$n$$$ points are distinct.

Print a single integer — the number of pairs of wires that are intersecting.

NoteIn the first example:  In the second example:  Note that the three poles $$$(0, 0)$$$, $$$(0, 2)$$$ and $$$(0, 4)$$$ are connected by a single wire.In the third example:

import std.typecons;
import std.stdio;
T gcd(T)(T a, T b) {
	if (a % b == 0) return b;
	return gcd(b, a % b);
}
struct Rat(T) {
	import std.math : abs;
	T n, d;
	this(T n_, T d_) {
		if (d_ == 0) {
			n = 1;
			d = 0;
		} else if (n_ == 0) {
			d = 1;
			n = 0;
		} else {
			auto c = gcd(abs(n_), abs(d_));
			bool neg = (n_ < 0) ^ (d_ < 0);
			n = abs(n_ / c);
			d = abs(d_ / c);
			if (neg) {
				n = -n;
			}
		}
	}
	Rat!T opBinary(string op)(T o) if (op == "*"){
		if (d == 0) {
			return this;
		}
		return Rat!T(n * o, d);
	}
	Rat!T opBinary(string op)(T o) if (op == "/"){
		if (d == 0) {
			return this;
		}
		return Rat!T(n, d * o);
	}
	Rat!T opBinary(string op)(T o) if (op == "+"){
		if (d == 0) {
			return this;
		}
		return Rat!T(n + d * o, d);
	}
}
int[2][1000] points;
void main() {
	bool[Tuple!(Rat!long, Rat!long)] lines;
	int n;
	scanf("%d ", &n);

	foreach(i; 0..n) {
		scanf("%d %d ", &points[i][0], &points[i][1]);
	}

	debug writeln(points);

	foreach(i; 0..n) {
		foreach(j; 0..i) {
			auto t = Rat!long(points[i][1]-points[j][1], points[i][0]-points[j][0]);
			auto d = t.d ? (t * -points[i][0]) + points[i][1] : Rat!long(points[i][0], 1);
			debug writeln(t, d, t == d);
			lines[tuple(t, d)] = true;
		}
	}

	debug writeln(lines);
	long[Rat!long] tgroup;
	foreach(t, d; lines.byKey) {
		tgroup[t]++;
	}
	long ans = lines.length * (lines.length - 1UL) / 2UL;
	foreach(t; tgroup.byKey) {
		ans -= tgroup[t] * (tgroup[t]-1UL) / 2UL;
	}
	writeln(ans);
}

import std.typecons;
import std.stdio;
T gcd(T)(T a, T b) {
	if (a % b == 0) return b;
	return gcd(b, a % b);
}
struct Rat(T) {
	import std.math : abs;
	T n, d;
	this(T n_, T d_) {
		if (d_ == 0) {
			n = 1;
			d = 0;
		} else if (n_ == 0) {
			d = 1;
			n = 0;
		} else {
			auto c = gcd(abs(n_), abs(d_));
			bool neg = (n_ < 0) ^ (d_ < 0);
			n = abs(n_ / c);
			d = abs(d_ / c);
			if (neg) {
				n = -n;
			}
		}
	}
	Rat!T opBinary(string op)(T o) if (op == "*"){
		if (d == 0) {
			return this;
		}
		return Rat!T(n * o, d);
	}
	Rat!T opBinary(string op)(T o) if (op == "/"){
		if (d == 0) {
			return this;
		}
		return Rat!T(n, d * o);
	}
	Rat!T opBinary(string op)(T o) if (op == "+"){
		if (d == 0) {
			return this;
		}
		return Rat!T(n + d * o, d);
	}
}
int[2][1000] points;
void main() {
	bool[Tuple!(Rat!long, Rat!long)] lines;
	int n;
	scanf("%d ", &n);

	foreach(i; 0..n) {
		scanf("%d %d ", &points[i][0], &points[i][1]);
	}

	debug writeln(points);

	foreach(i; 0..n) {
		foreach(j; 0..i) {
			auto t = Rat!long(points[i][1]-points[j][1], points[i][0]-points[j][0]);
			auto d = t.d ? (t * -points[i][0]) + points[i][1] : Rat!long(points[i][0], 1);
			debug writeln(t, d, t == d);
			lines[tuple(t, d)] = true;
		}
	}

	debug writeln(lines);
	long[Rat!long] tgroup;
	foreach(t, d; lines.byKey) {
		tgroup[t]++;
	}
	long ans = lines.length * (lines.length - 1) / 2;
	foreach(t; tgroup.byKey) {
		ans -= tgroup[t] * (tgroup[t]-1) / 2;
	}
	writeln(ans);
}

import std.typecons;
import std.stdio;
T gcd(T)(T a, T b) {
	if (a % b == 0) return b;
	return gcd(b, a % b);
}
struct Rat(T) {
	import std.math : abs;
	T n, d;
	this(T n_, T d_) {
		if (d_ == 0) {
			n = 1;
			d = 0;
		} else if (n_ == 0) {
			d = 1;
			n = 0;
		} else {
			auto c = gcd(abs(n_), abs(d_));
			bool neg = (n_ < 0) ^ (d_ < 0);
			n = abs(n_ / c);
			d = abs(d_ / c);
			if (neg) {
				n = -n;
			}
		}
	}
	Rat!T opBinary(string op)(T o) if (op == "*"){
		if (d == 0) {
			return this;
		}
		return Rat!T(n * o, d);
	}
	Rat!T opBinary(string op)(T o) if (op == "/"){
		if (d == 0) {
			return this;
		}
		return Rat!T(n, d * o);
	}
	Rat!T opBinary(string op)(T o) if (op == "+"){
		if (d == 0) {
			return this;
		}
		return Rat!T(n + d * o, d);
	}
}
int[2][1000] points;
void main() {
	bool[Tuple!(Rat!long, Rat!long)] lines;
	int n;
	scanf("%d ", &n);

	foreach(i; 0..n) {
		scanf("%d %d ", &points[i][0], &points[i][1]);
	}

	debug writeln(points);

	foreach(i; 0..n) {
		foreach(j; 0..i) {
			auto t = Rat!long(points[i][1]-points[j][1], points[i][0]-points[j][0]);
			auto d = t.d ? (t * -points[i][0]) + points[i][1] : Rat!long(points[i][0], 1);
			debug writeln(t, d, t == d);
			lines[tuple(t, d)] = true;
		}
	}

	debug writeln(lines);
	int[Rat!long] tgroup;
	foreach(t, d; lines.byKey) {
		tgroup[t]++;
	}
	long ans = lines.length * (lines.length - 1) / 2;
	foreach(t; tgroup.byKey) {
		ans -= tgroup[t] * (tgroup[t]-1) / 2;
	}
	writeln(ans);
}


You are given three points on a plane. You should choose some segments on the plane that are parallel to coordinate axes, so that all three points become connected. The total length of the chosen segments should be the minimal possible.Two points $$$a$$$ and $$$b$$$ are considered connected if there is a sequence of points $$$p_0 = a, p_1, \ldots, p_k = b$$$ such that points $$$p_i$$$ and $$$p_{i+1}$$$ lie on the same segment.

The input consists of three lines describing three points. Each line contains two integers $$$x$$$ and $$$y$$$ separated by a space — the coordinates of the point ($$$-10^9 \le x, y \le 10^9$$$). The points are pairwise distinct.

On the first line output $$$n$$$ — the number of segments, at most 100. The next $$$n$$$ lines should contain descriptions of segments. Output four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ on a line — the coordinates of the endpoints of the corresponding segment ($$$-10^9 \le x_1, y_1, x_2, y_2 \le 10^9$$$). Each segment should be either horizontal or vertical. It is guaranteed that the solution with the given constraints exists.

NoteThe points and the segments from the example are shown below.

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

void main() {
    auto X = new int[3];
    auto Y = new int[3];
    foreach (i; 0 .. 3) {
        readf("%d %d\n", &X[i], &Y[i]);
    }
    auto I = iota(3).array.sort!((a, b) => Y[a] < Y[b]).array;
    writeln(3);
    auto SegA = [X.reduce!min, Y[I[1]], X.reduce!max, Y[I[1]]];
    auto SegB = [X[I[0]], Y[I[0]], X[I[0]], Y[I[1]]];
    auto SegC = [X[I[2]], Y[I[2]], X[I[2]], Y[I[1]]];
    writefln("%(%s %)", SegA);
    writefln("%(%s %)", SegB);
    writefln("%(%s %)", SegC);
}


You have a team of N people. For a particular task, you can pick any non-empty subset of people. The cost of having x people for the task is xk. Output the sum of costs over all non-empty subsets of people.

Only line of input contains two integers N (1 ≤ N ≤ 109) representing total number of people and k (1 ≤ k ≤ 5000).

Output the sum of costs for all non empty subsets modulo 109 + 7.

NoteIn the first example, there is only one non-empty subset {1} with cost 11 = 1.In the second example, there are seven non-empty subsets.- {1} with cost 12 = 1- {2} with cost 12 = 1- {1, 2} with cost 22 = 4- {3} with cost 12 = 1- {1, 3} with cost 22 = 4- {2, 3} with cost 22 = 4- {1, 2, 3} with cost 32 = 9The total cost is 1 + 1 + 4 + 1 + 4 + 4 + 9 = 24.

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

struct ModInt(int M_) {
  alias M = M_;
  int x;
  this(ModInt a) { x = a.x; }
  this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }
  ref ModInt opAssign(long a) { return (this = ModInt(a)); }
  ref ModInt opOpAssign(string op)(ModInt a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x < 0) x += M; }
    else static if (op == "*") { x = cast(int)((cast(long)(x) * a.x) % M); }
    else static if (op == "/") { this *= a.inv(); }
    else static assert(false);
    return this;
  }
  ref ModInt opOpAssign(string op)(long a) {
    static if (op == "^^") {
      ModInt t2 = this, te = ModInt(1);
      for (long e = a; e; e >>= 1) {
        if (e & 1) te *= t2;
        t2 *= t2;
      }
      x = cast(int)(te.x);
      return this;
    } else return mixin("this " ~ op ~ "= ModInt(a)");
  }
  ModInt inv() const {
    int a = x, b = M, y = 1, z = 0, t;
    for (; ; ) {
      t = a / b; a -= t * b;
      if (a == 0) {
        assert(b == 1 || b == -1);
        return ModInt(b * z);
      }
      y -= t * z;
      t = b / a; b -= t * a;
      if (b == 0) {
        assert(a == 1 || a == -1);
        return ModInt(a * y);
      }
      z -= t * y;
    }
  }
  ModInt opUnary(string op)() const if (op == "-") { return ModInt(-x); }
  ModInt opBinary(string op, T)(T a) const { return mixin("ModInt(this) " ~ op ~ "= a"); }
  ModInt opBinaryRight(string op)(long a) const { return mixin("ModInt(a) " ~ op ~ "= this"); }
  string toString() const { return x.to!string; }
}

enum MO = 10^^9 + 7;
alias Mint = ModInt!MO;

enum LIM = 10010;
Mint[] inv, fac, invFac;
void prepare() {
  inv = new Mint[LIM];
  fac = new Mint[LIM];
  invFac = new Mint[LIM];
  inv[1] = 1;
  foreach (i; 2 .. LIM) {
    inv[i] = -(Mint.M / i) * inv[cast(size_t)(Mint.M % i)];
  }
  fac[0] = invFac[0] = 1;
  foreach (i; 1 .. LIM) {
    fac[i] = fac[i - 1] * i;
    invFac[i] = invFac[i - 1] * inv[i];
  }
}
Mint binom(long n, long k) {
  if (0 <= k && k <= n) {
    assert(n < LIM);
    return fac[cast(size_t)(n)] * invFac[cast(size_t)(k)] * invFac[cast(size_t)(n - k)];
  } else {
    return Mint(0);
  }
}

void main() {
  prepare();

  try {
    for (; ; ) {
      const N = readLong();
      const K = readInt();

      auto dp = new Mint[][](K + 1, K + 1);
      dp[0][0] = 1;
      foreach (i; 0 .. K) {
        foreach (j; 0 .. i + 1) {
          dp[i + 1][j] += dp[i][j] * j;
          dp[i + 1][j + 1] += dp[i][j] * (N - j);
        }
      }
      Mint ans;
      foreach (j; 0 .. K + 1) {
        if (j <= N) {
          ans += dp[K][j] * Mint(2)^^(N - j);
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


There are $$$n$$$ programmers that you want to split into several non-empty teams. The skill of the $$$i$$$-th programmer is $$$a_i$$$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $$$x$$$.Each programmer should belong to at most one team. Some programmers may be left without a team.Calculate the maximum number of teams that you can assemble.

The first line contains the integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 10^5; 1 \le x \le 10^9$$$) — the number of programmers and the restriction of team skill respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th programmer. The sum of $$$n$$$ over all inputs does not exceed $$$10^5$$$.

For each test case print one integer — the maximum number of teams that you can assemble.

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, x;
		readf !(" %s %s") (n, x);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		sort (a);
		int res = 0;
		while (!a.empty)
		{
			auto prev = a.length;
			while (!a.empty)
			{
				auto cur = a.back;
				a.popBack ();
				if (cur * (prev - a.length) >= x)
				{
					res += 1;
					break;
				}
			}
		}
		writeln (res);
	}
}


Tom loves vowels, and he likes long words with many vowels. His favorite words are vowelly words. We say a word of length $$$k$$$ is vowelly if there are positive integers $$$n$$$ and $$$m$$$ such that $$$n\cdot m = k$$$ and when the word is written by using $$$n$$$ rows and $$$m$$$ columns (the first row is filled first, then the second and so on, with each row filled from left to right), every vowel of the English alphabet appears at least once in every row and every column.You are given an integer $$$k$$$ and you must either print a vowelly word of length $$$k$$$ or print $$$-1$$$ if no such word exists.In this problem the vowels of the English alphabet are 'a', 'e', 'i', 'o' ,'u'.

Input consists of a single line containing the integer $$$k$$$ ($$$1\leq k \leq 10^4$$$) — the required length.

The output must consist of a single line, consisting of a vowelly word of length $$$k$$$ consisting of lowercase English letters if it exists or $$$-1$$$ if it does not. If there are multiple possible words, you may output any of them.

NoteIn the second example, the word "agoeuioaeiruuimaeoieauoweouoiaouimae" can be arranged into the following $$$6 \times 6$$$ grid:  It is easy to verify that every row and every column contain all the vowels.

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		int u, v;
		for (int i = 1; i * i <= n; i++)
		{
			if (n % i == 0 && i >= 5 && n / i >= 5)
			{
				u = i;
				v = n / i;
				break;
			}
		}
		if (u == 0 && v == 0)
		{
			writeln (-1);
			continue;
		}
		string res;
		foreach (i; 0..u)
		{
			foreach (j; 0..v)
			{
				res ~= "aeiou"[(i + j) % 5];
			}
		}
		writeln (res);
	}
}

//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;

enum string vowels = "aeiou";

void main() {
  int k = readln.strip.to!int;
  char[] z;
  z.reserve (k);
  for (int h = 5; h * h <= k; ++h) {
    if (k % h == 0) {
      int w = k / h;
      foreach (i; 0 .. h) {
        foreach (j; 0 .. w) {
          z ~= vowels[(i + j) % 5];
        }
      }
      writeln (z);
      return;
    }
  }
  writeln (-1);
}

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

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

//long mod = 10^^9 + 7;
long mod = 998244353;
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 K = RD!int;

	int a, b;
	for (int i = 5; i*i <= K; ++i)
	{
		if (K % i == 0)
		{
			if (K / i >= 5)
			{
				a = i;
				b = K / i;
				break;
			}
		}
	}
	if (a == 0)
		writeln(-1);
	else
	{
		auto str = "aiueo";
		foreach (i; 0..a)
		{
			foreach (j; 0..b)
			{
				write(str[((i%5)+j)%5]);
			}
		}
		writeln();
	}
	stdout.flush();
	debug readln();
}

module _;
void main() {
	import std.stdio;
	int n;
	readf("%s ", &n);
	string vowels = "aeiou";
	int x = 0, y;
	for(int i = 5; i * i <= n; i++){
		if (n % i == 0) {
			x = i;
			y = n/i;
		}
	}
	if (!x) {
		writeln("-1");
		return;
	}
	foreach(i; 0..5) {
		string pat = vowels[i..5] ~ vowels[0..i];
		foreach(j; 0..y/5) {
			write(pat);
		}
		write(pat[0..y%5]);
	}
	foreach(i; 5..x) {
		write(vowels);
		foreach(j; 5..y) {
			write("x");
		}
	}
	writeln;
}


The flag of Berland is such rectangular field n × m that satisfies following conditions:  Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.  Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.  Each color should be used in exactly one stripe. You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).

The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.

Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).

6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB

NoteThe field in the third example doesn't have three parralel stripes.Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.

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;

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto B = H.iota.map!(_ => readln.chomp).array;

    if (H % 3 == 0) {
        dchar[] used;
        bool ok = true;
        foreach (k; 0..3) {
            char c = B[H / 3 * k][0];
            used ~= c;
            foreach (i; H/3*k..H/3*(k+1)) foreach (j; 0..W) if (B[i][j] != c) ok = false;
        }
        used.sort();
        if (ok && used == ['B', 'G', 'R'].to!(dchar[])) {
            "YES".writeln;
            return;
        }
    }

    if (W % 3 == 0) {
        dchar[] used;
        bool ok = true;
        foreach (k; 0..3) {
            char c = B[0][W / 3 * k];
            used ~= c;
            foreach (j; W/3*k..W/3*(k+1)) foreach (i; 0..H) if (B[i][j] != c) ok = false;
        }
        used.sort();
        if (ok && used == ['B', 'G', 'R'].to!(dchar[])) {
            "YES".writeln;
            return;
        }
    }

    "NO".writeln;
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
import std.stdio, std.string, std.array, std.algorithm, std.conv;

void main() {
    auto nm = to!(int[])(split(chomp(readln())));
    int n = nm[0], m = nm[1];
    auto xss = appender!(string[])();
    for (int i = 0; i < n; i++) {
        xss.put(chomp(readln()));
        if (!xss.data[i].count!( (a) => a == 'R' || a == 'G' || a == 'B' )) {
            writeln("NO");
            return;
        }
    }
    auto ans = false;
    if (n % 3 == 0) {
        int u = n / 3;
        bool flag = true;
        for (int x = 0; x < m; x++) {
            for (int y = 0; y < n; y++) {
                auto p = xss.data[y][x];
                auto a = xss.data[y/u*u][x];
                auto b = xss.data[(y/u+1)%3*u][x];
                auto c = xss.data[(y/u+2)%3*u][x];
                flag = flag && (p == a && p != b && p != c) && (x == 0 || p == xss.data[y][x-1]);
            }
        }
        ans = ans || flag;
    }
    if (m % 3 == 0) {
        int u = m / 3;
        bool flag = true;
        for (int y = 0; y < n; y++) {
            for (int x = 0; x < m; x++) {
                auto p = xss.data[y][x];
                auto a = xss.data[y][x/u*u];
                auto b = xss.data[y][(x/u+1)%3*u];
                auto c = xss.data[y][(x/u+2)%3*u];
                flag = flag && (p == a && p != b && p != c) && (y == 0 || p == xss.data[y-1][x]);
            }
        }
        ans = ans || flag;
    }
    writeln(ans ? "YES" : "NO");
}

import std.stdio;
import std.string;
import std.uni;
import std.array;
import std.algorithm;

string[] flag;

char[] get(int x0, int y0, int x1, int y1) {
	auto app = appender!(char[])();
	bool R = false, G = false, B = false;
	for (int i = x0; i < x1; i++) for (int j = y0; j < y1; j++) {
		if (flag[i][j] == 'R') {
			if (!R) {
				R = true;
				app.put('R');
			}
		} else if (flag[i][j] == 'G') {
			if (!G) {
				G = true;
				app.put('G');
			}
		} else {
			if (!B) {
				B = true;
				app.put('B');
			}
		}
	}
	return app.data;
}

void main() {
	int n, m;
	readf("%d %d\n", &n, &m);
	flag = new string[n];
	for (int i = 0; i < n; i++) flag[i] = readln();
	bool ans = false;
	if (n % 3 == 0) {
		auto app = appender!(char[])();
		int d = n / 3;
		app.put(get(0, 0, d, m));
		app.put(get(d, 0, 2 * d, m));
		app.put(get(2 * d, 0, n, m));
		char[] data = app.data;
		sort(data.representation);
		if (data == "BGR") ans = true;
	}
	if (m % 3 == 0) {
		auto app = appender!(char[])();
		int d = m / 3;
		app.put(get(0, 0, n, d));
		app.put(get(0, d, n, 2 * d));
		app.put(get(0, 2 * d, n, m));
		char[] data = app.data;
		sort(data.representation);
		if (data == "BGR") ans = true;
	}
	writeln(ans ? "YES" : "NO");
}

// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.datetime, std.bigint;

int n, m;
char[][] flag;

void main() {
    scan(n, m);

    if (n % 3 && m % 3) {
        writeln("NO");
        return;
    }

    flag = new char[][](n, m);
    iota(n).each!(i => flag[i][] = readln.chomp);

    debug {
        writefln("%(%(%s %)\n%)", flag);
    }

    int r, c;

    if (n % 3 == 0) {
        r = n / 3;

        auto rgb = new int[](3);

        bool ok = true;

        foreach (k ; 0 .. 3) {
            char ch = flag[k * r][0];

            if (ch == 'R') rgb[0]++;
            else if (ch == 'G') rgb[1]++;
            else rgb[2]++;

            foreach (i ; k * r .. k * r + r) {
                foreach (j ; 0 .. m) {
                    if (flag[i][j] != ch) ok = false;
                }
            }
        }

        if (rgb == [1, 1, 1] && ok) {
            writeln("YES");
            return;
        }
    }

    if (m % 3 == 0) {
        c = m / 3;

        auto rgb = new int[](3);

        bool ok = true;

        foreach (k ; 0 .. 3) {
            char ch = flag[0][k * c];

            if (ch == 'R') rgb[0]++;
            else if (ch == 'G') rgb[1]++;
            else rgb[2]++;

            foreach (j ; k * c .. k * c + c) {
                foreach (i ; 0 .. n) {
                    if (flag[i][j] != ch) ok = false;
                }
            }

            if (rgb == [1, 1, 1] && ok) {
                writeln("YES");
                return;
            }
        }
    }

    writeln("NO");
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

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

// Try Codeforces
// author: Leonardone @ NEETSDKASU
import std.stdio, std.string, std.array, std.algorithm, std.conv;

void main() {
    auto nm = to!(int[])(split(chomp(readln())));
    int n = nm[0], m = nm[1];
    auto xss = appender!(string[])();
    for (int i = 0; i < n; i++) {
        xss.put(chomp(readln()));
        if (!xss.data[i].count!( (a) => a == 'R' || a == 'G' || a == 'B' )) {
            writeln("NO");
            return;
        }
    }
    auto ans = false;
    if (n % 3 == 0) {
        int u = n / 3;
        bool flag = true;
        for (int x = 0; x < m; x++) {
            for (int y = 0; y < n; y++) {
                auto p = xss.data[y][x];
                auto a = xss.data[y/u*u][x];
                auto b = xss.data[(y/u+1)%3*u][x];
                auto c = xss.data[(y/u+2)%3*u][x];
                flag = flag && (p == a && p != b && p != c);
            }
        }
        ans = ans || flag;
    }
    if (m % 3 == 0) {
        int u = m / 3;
        bool flag = true;
        for (int y = 0; y < n; y++) {
            for (int x = 0; x < m; x++) {
                auto p = xss.data[y][x];
                auto a = xss.data[y][x/u*u];
                auto b = xss.data[y][(x/u+1)%3*u];
                auto c = xss.data[y][(x/u+2)%3*u];
                flag = flag && (p == a && p != b && p != c);
            }
        }
        ans = ans || flag;
    }
    writeln(ans ? "YES" : "NO");
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
import std.stdio, std.string, std.array, std.algorithm, std.conv;

void main() {
    auto nm = to!(int[])(split(chomp(readln())));
    int n = nm[0], m = nm[1];
    auto xss = appender!(string[])();
    for (int i = 0; i < n; i++) {
        xss.put(chomp(readln()));
    }
    auto ans = false;
    if (n % 3 == 0) {
        int u = n / 3;
        bool flag = true;
        for (int x = 0; x < m; x++) {
            for (int y = 0; y < n; y++) {
                auto p = xss.data[y][x];
                auto a = xss.data[y/u*u][x];
                auto b = xss.data[(y/u+1)%3*u][x];
                auto c = xss.data[(y/u+2)%3*u][x];
                flag = flag && (p == a && p != b && p != c);
            }
        }
        ans = ans || flag;
    }
    if (m % 3 == 0) {
        int u = m / 3;
        bool flag = true;
        for (int y = 0; y < n; y++) {
            for (int x = 0; x < m; x++) {
                auto p = xss.data[y][x];
                auto a = xss.data[y][x/u*u];
                auto b = xss.data[y][(x/u+1)%3*u];
                auto c = xss.data[y][(x/u+2)%3*u];
                flag = flag && (p == a && p != b && p != c);
            }
        }
        ans = ans || flag;
    }
    writeln(ans ? "YES" : "NO");
}


n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.

The first line contains integer n (2 ≤ n ≤ 100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heights are given in clockwise or counterclockwise direction.

Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.

module cf_34a;

import std.stdio;
import std.math;

void main() {
  int n;
  int[] heights;

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

  int spyFirst, spySecond, minDiff = int.max;
  for (int i = 0; i < n; ++i) {
    int j = (i - 1 < 0)? n - 1: i - 1;
    int diff = abs(heights[i] - heights[j]);

    if (diff < minDiff) {
      minDiff = diff;
      spyFirst = i;
      spySecond = j;
    }
  }

  writefln("%d %d", spyFirst + 1, spySecond + 1);
}

module cf_34a;

import std.stdio;
import std.math;

void main() {
  int n;
  int[] heights;

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

  int spyFirst, spySecond, minDiff = int.max;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int diff = abs(heights[i] - heights[j]);

      if (i != j && diff < minDiff) {
    minDiff = diff;
    spyFirst = i;
    spySecond = j;
      }
    }
  }

  writefln("%d %d", spyFirst + 1, spySecond + 1);
}


Multiset —is a set of numbers in which there can be equal elements, and the order of the numbers does not matter. Two multisets are equal when each value occurs the same number of times. For example, the multisets $$$\{2,2,4\}$$$ and $$$\{2,4,2\}$$$ are equal, but the multisets $$$\{1,2,2\}$$$ and $$$\{1,1,2\}$$$ — are not.You are given two multisets $$$a$$$ and $$$b$$$, each consisting of $$$n$$$ integers.In a single operation, any element of the $$$b$$$ multiset can be doubled or halved (rounded down). In other words, you have one of the following operations available for an element $$$x$$$ of the $$$b$$$ multiset:   replace $$$x$$$ with $$$x \cdot 2$$$,  or replace $$$x$$$ with $$$\lfloor \frac{x}{2} \rfloor$$$ (round down).  Note that you cannot change the elements of the $$$a$$$ multiset.See if you can make the multiset $$$b$$$ become equal to the multiset $$$a$$$ in an arbitrary number of operations (maybe $$$0$$$).For example, if $$$n = 4$$$, $$$a = \{4, 24, 5, 2\}$$$, $$$b = \{4, 1, 6, 11\}$$$, then the answer is yes. We can proceed as follows:   Replace $$$1$$$ with $$$1 \cdot 2 = 2$$$. We get $$$b = \{4, 2, 6, 11\}$$$.  Replace $$$11$$$ with $$$\lfloor \frac{11}{2} \rfloor = 5$$$. We get $$$b = \{4, 2, 6, 5\}$$$.  Replace $$$6$$$ with $$$6 \cdot 2 = 12$$$. We get $$$b = \{4, 2, 12, 5\}$$$.  Replace $$$12$$$ with $$$12 \cdot 2 = 24$$$. We get $$$b = \{4, 2, 24, 5\}$$$.  Got equal multisets $$$a = \{4, 24, 5, 2\}$$$ and $$$b = \{4, 2, 24, 5\}$$$.

The first line of input data contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases. Each test case consists of three lines. The first line of the test case contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) —the number of elements in the multisets $$$a$$$ and $$$b$$$. The second line gives $$$n$$$ integers: $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_1 \le a_2 \le \dots \le a_n \le 10^9$$$) —the elements of the multiset $$$a$$$. Note that the elements may be equal. The third line contains $$$n$$$ integers: $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_1 \le b_2 \le \dots \le b_n \le 10^9$$$) — elements of the multiset $$$b$$$. Note that the elements may be equal. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print on a separate line:   YES if you can make the multiset $$$b$$$ become equal to $$$a$$$,  NO otherwise.  You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as positive answer).

NoteThe first example is explained in the statement.In the second example, it is impossible to get the value $$$31$$$ from the numbers of the multiset $$$b$$$ by available operations.In the third example, we can proceed as follows:   Replace $$$2$$$ with $$$2 \cdot 2 = 4$$$. We get $$$b = \{4, 14, 14, 26, 42\}$$$.  Replace $$$14$$$ with $$$\lfloor \frac{14}{2} \rfloor = 7$$$. We get $$$b = \{4, 7, 14, 26, 42\}$$$.  Replace $$$26$$$ with $$$\lfloor \frac{26}{2} \rfloor = 13$$$. We get $$$b = \{4, 7, 14, 13, 42\}$$$.  Replace $$$42$$$ with $$$\lfloor \frac{42}{2} \rfloor = 21$$$. We get $$$b = \{4, 7, 14, 13, 21\}$$$.  Replace $$$21$$$ with $$$\lfloor \frac{21}{2} \rfloor = 10$$$. We get $$$b = \{4, 7, 14, 13, 10\}$$$.  Got equal multisets $$$a = \{4, 7, 10, 13, 14\}$$$ and $$$b = \{4, 7, 14, 13, 10\}$$$.

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

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

    bool C() {
        int[int] aps;
        foreach (a; A) {
            while (a % 2 == 0) a /= 2;
            aps[a] = aps.get(a, 0) + 1;
        }
        foreach (b; B) {
            while (b % 2 == 0) b /= 2;
            while (b > 0) {
                if (aps.get(b, 0) > 0) {
                    aps[b] -= 1;
                    break;
                } else {
                    b /= 2;
                }
            }
        }
        return aps.values.all!((x) => x == 0);
    }
    writeln(C() ? "YES" : "NO");
}

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

import std;

int t,n,m;
long[] answers;

void main()
{
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        scanf("%d", &n);
        getchar();
        auto a = readln.split.to!(int[]);

        auto rbt = redBlackTree!true(0);
        rbt.removeKey(0);

        for (int i = 0; i < n; i++){
            while (a[i] % 2 == 0){
                a[i] /= 2;
            }

            rbt.stableInsert(a[i]);
        }

        //writefln("%(%d %)", rbt[]);

        bool good = true;
        auto b = readln.split.to!(int[]);
        for (int i = 0; i < n; i++){
            while (b[i] != 0){
                if (b[i] in rbt){
                    rbt.removeKey(b[i]);
                    break;
                }

                b[i] /= 2;
            }

            if (b[i] == 0){
                good = false;
                break;
            }
        }

        if (good != false){
            writefln("YES");
        } else {
            writefln("NO");
        }
    }
    //writefln("%(%s \n%)", answers);
}


You are given an array $$$a$$$ of length $$$n$$$.You are also given a set of distinct positions $$$p_1, p_2, \dots, p_m$$$, where $$$1 \le p_i < n$$$. The position $$$p_i$$$ means that you can swap elements $$$a[p_i]$$$ and $$$a[p_i + 1]$$$. You can apply this operation any number of times for each of the given positions.Your task is to determine if it is possible to sort the initial array in non-decreasing order ($$$a_1 \le a_2 \le \dots \le a_n$$$) using only allowed swaps.For example, if $$$a = [3, 2, 1]$$$ and $$$p = [1, 2]$$$, then we can first swap elements $$$a[2]$$$ and $$$a[3]$$$ (because position $$$2$$$ is contained in the given set $$$p$$$). We get the array $$$a = [3, 1, 2]$$$. Then we swap $$$a[1]$$$ and $$$a[2]$$$ (position $$$1$$$ is also contained in $$$p$$$). We get the array $$$a = [1, 3, 2]$$$. Finally, we swap $$$a[2]$$$ and $$$a[3]$$$ again and get the array $$$a = [1, 2, 3]$$$, sorted in non-decreasing order.You can see that if $$$a = [4, 1, 2, 3]$$$ and $$$p = [3, 2]$$$ then you cannot sort the array.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le m < n \le 100$$$) — the number of elements in $$$a$$$ and the number of elements in $$$p$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$). The third line of the test case contains $$$m$$$ integers $$$p_1, p_2, \dots, p_m$$$ ($$$1 \le p_i < n$$$, all $$$p_i$$$ are distinct) — the set of positions described in the problem statement.

For each test case, print the answer — "YES" (without quotes) if you can sort the initial array in non-decreasing order ($$$a_1 \le a_2 \le \dots \le a_n$$$) using only allowed swaps. Otherwise, print "NO".

import std.stdio : readln, writeln;

struct IO {
  import std.conv : to;
  import std.range : empty, front, popFront, split;

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

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

  string[] tokens;
}

void main() {
  import core.stdc.limits : INT_MAX;
  import std.algorithm : max, min, fill;

  IO io;
  int T = io.readInt;
  while (T--) {
    int n = io.readInt;
    int m = io.readInt;
    int[] a = new int[n];
    for (int i = 0; i < n; ++i) {
      a[i] = io.readInt;
    }
    bool[] gap = new bool[n - 1];
    fill(gap, true);
    for (int i = 0; i < m; ++i) {
      gap[io.readInt - 1] = false;
    }
    int[] suffixMin = new int[n + 1];
    suffixMin[n] = INT_MAX;
    for (int i = n; i--;) {
      suffixMin[i] = min(a[i], suffixMin[i + 1]);
    }
    int prefixMax = 0;
    bool ok = true;
    for (int i = 0; i + 1 < n; ++i) {
      prefixMax = max(prefixMax, a[i]);
      ok &= !gap[i] || prefixMax <= suffixMin[i + 1];
    }
    writeln(ok ? "YES" : "NO");
  }
}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
    A: foreach(_; 0 .. rint){
        int n = rint, m = rint;
        int[] as = rint(n), ps = rint(m);

        bool[] xs = new bool[](n);
        foreach(p; ps) xs[p - 1] = 1;

        int mina = 999, maxa = -1;
        int oldmaxa = -1;
        foreach(int i, a; as){
            mina.chmin(a), maxa.chmax(a);
            if(! xs[i]){
                if(mina < oldmaxa){
                    "NO".writeln;
                    continue A;
                }
                oldmaxa = maxa;
                mina = 999, maxa = -1;
            }
        }
        "YES".writeln;

    }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto m = RD!int;
		auto a = RDA;
		auto p = RDA!int(-1);
		p.sort();
		int[][] lr;
		int last = p[0], l = p[0];
		foreach (i; 1..m)
		{
			if (p[i] != last+1)
			{
				lr ~= [l, last+1];
				l = p[i];
			}
			last = p[i];
		}
		lr ~= [l, last+1];
		foreach (e; lr)
		{
			a[e[0]..e[1]+1].sort();
		}
		bool ok = true;
		foreach (i; 1..n)
		{
			if (a[i-1] > a[i])
				ok = false;
		}
		ans[ti] = ok;
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto m = RD!int;
		auto a = RDA;
		auto p = RDA!int(-1);
		int[][] lr;
		int last = p[0], l = p[0];
		foreach (i; 1..m)
		{
			if (p[i] != last+1)
			{
				lr ~= [l, last+1];
				l = p[i];
			}
			last = p[i];
		}
		lr ~= [l, last+1];
		foreach (e; lr)
		{
			a[e[0]..e[1]+1].sort();
		}
		bool ok = true;
		foreach (i; 1..n)
		{
			if (a[i-1] > a[i])
				ok = false;
		}
		ans[ti] = ok;
	}

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


There are n integers b1, b2, ..., bn written in a row. For all i from 1 to n, values ai are defined by the crows performing the following procedure:  The crow sets ai initially 0.  The crow then adds bi to ai, subtracts bi + 1, adds the bi + 2 number, and so on until the n'th number. Thus, ai = bi - bi + 1 + bi + 2 - bi + 3.... Memory gives you the values a1, a2, ..., an, and he now wants you to find the initial numbers b1, b2, ..., bn written in the row? Can you do it?

The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of integers written in the row. The next line contains n, the i'th of which is ai ( - 109 ≤ ai ≤ 109) — the value of the i'th number.

Print n integers corresponding to the sequence b1, b2, ..., bn. It's guaranteed that the answer is unique and fits in 32-bit integer type.

NoteIn the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and  - 4 = 4 - 6 + 1 - 3.In the second sample test, the sequence 1,  - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.

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

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

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

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // int t = cin.read_int;
        while (t--) {
                int n = cin.read_int;
                int[] arr = new int[n];
                foreach (ref i; arr) {
                        i = cin.read_int;
                }

                int[] ans = new int[n];

                for (int i = n - 1; i >= 0; i--) {
                        if (i == n - 1) ans[i] = arr[i];
                        else ans[i] = arr[i] + arr[i + 1];
                }

                foreach (i; ans) {
                        write(i, " ");
                }

                writeln();
        }
}


Bob got a job as a system administrator in X corporation. His first task was to connect n servers with the help of m two-way direct connection so that it becomes possible to transmit data from one server to any other server via these connections. Each direct connection has to link two different servers, each pair of servers should have at most one direct connection. Y corporation, a business rival of X corporation, made Bob an offer that he couldn't refuse: Bob was asked to connect the servers in such a way, that when server with index v fails, the transmission of data between some other two servers becomes impossible, i.e. the system stops being connected. Help Bob connect the servers.

The first input line contains 3 space-separated integer numbers n, m, v (3 ≤ n ≤ 105, 0 ≤ m ≤ 105, 1 ≤ v ≤ n), n — amount of servers, m — amount of direct connections, v — index of the server that fails and leads to the failure of the whole system.

If it is impossible to connect the servers in the required way, output -1. Otherwise output m lines with 2 numbers each — description of all the direct connections in the system. Each direct connection is described by two numbers — indexes of two servers, linked by this direct connection. The servers are numbered from 1. If the answer is not unique, output any.

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

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

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

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

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

int N, M, S;

int[] A, B;

void main(string[] args) {
	try {
	for (; ; ) {
		N = readInt;
		M = readInt;
		S = readInt - 1;

		int[][] us = new int[][2];
		foreach (u; 0 .. N) if (u != S) {
			if (us[0].empty) {
				us[0] ~= u;
			} else {
				us[1] ~= u;
			}
		}

		const minM = N - 1;
		int maxM;
		foreach (s; 0 .. 2) {
			maxM += us[s].length * (us[s].length + 1) / 2;
		}

		if (minM <= M && M <= maxM) {
			A.clear;
			B.clear;
			foreach (u; 0 .. N) if (u != S) {
				A ~= S;
				B ~= u;
			}
			foreach (s; 0 .. 2) {
				foreach (u; us[s]) foreach (v; us[s]) if (u < v) {
					if (A.length == M) {
						goto done;
					}
					A ~= u;
					B ~= v;
				}
			}
		done:
			foreach (i; 0 .. M) {
				writeln(A[i] + 1, " ", B[i] + 1);
			}
		} else {
			writeln(-1);
		}
	}
	} catch (EOFException) {}
}

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

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

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

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

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

int N, M, S;

int[] A, B;

void main(string[] args) {
	try {
	for (; ; ) {
		N = readInt;
		M = readInt;
		S = readInt - 1;

		int[][] us = new int[][2];
		{
			int s;
			foreach (u; 0 .. N) if (u != S) {
				us[s] ~= u;
				s ^= 1;
			}
		}

		const minM = N - 1;
		int maxM;
		foreach (s; 0 .. 2) {
			maxM += us[s].length * (us[s].length + 1) / 2;
		}

		if (minM <= M && M <= maxM) {
			A.clear;
			B.clear;
			foreach (u; 0 .. N) if (u != S) {
				A ~= S;
				B ~= u;
			}
			foreach (s; 0 .. 2) {
				foreach (u; us[s]) foreach (v; us[s]) if (u < v) {
					if (A.length == M) {
						goto done;
					}
					A ~= u;
					B ~= v;
				}
			}
		done:
			foreach (i; 0 .. M) {
				writeln(A[i] + 1, " ", B[i] + 1);
			}
		} else {
			writeln(-1);
		}
	}
	} catch (EOFException) {}
}


While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).The gift bundle also includes a square scoop of size r × r, designed for fishing. If the lower-left corner of the scoop-net is located at cell (x, y), all fishes inside the square (x, y)...(x + r - 1, y + r - 1) get caught. Note that the scoop-net should lie completely inside the pond when used.Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release k fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put k fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (n - r + 1)·(m - r + 1) possible positions, the average number of caught fishes is as high as possible.

The only line contains four integers n, m, r, k (1 ≤ n, m ≤ 105, 1 ≤ r ≤ min(n, m), 1 ≤ k ≤ min(n·m, 105)).

Print a single number — the maximum possible expected number of caught fishes. You answer is considered correct, is its absolute or relative error does not exceed 10 - 9. Namely, let your answer be a, and the jury's answer be b. Your answer is considered correct, if .

NoteIn the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value.

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

alias Data = Tuple!(long, "val", long, "num", int, "x", int, "y");
int n, m, r, k;

void main() {
    scan(n, m, r, k);

    auto imosx = new int[](n + 1);
    auto imosy = new int[](m + 1);

    foreach (i ; 0 .. n - r + 1) {
        imosx[i]++, imosx[i + r]--;
    }
    foreach (i ; 0 .. m - r + 1) {
        imosy[i]++, imosy[i + r]--;
    }
    foreach (i ; 1 .. n + 1) {
        imosx[i] += imosx[i-1];
    }
    foreach (i ; 1 .. m + 1) {
        imosy[i] += imosy[i-1];
    }

    auto cntx = new int[](r + 1);
    auto cnty = new int[](r + 1);

    int maxy;

    foreach (i ; 0 .. n + 1) {
        cntx[imosx[i]]++;
    }
    foreach (i ; 0 .. m + 1) {
        cnty[imosy[i]]++;
        maxy = max(imosy[i], maxy);
    }

    debug {
        //writeln(cntx);
        //writeln(cnty);
    }

    auto bh = new BinaryHeap!(Array!Data, "a.val < b.val")();

    foreach (i ; 1 .. r + 1) {
        if (cntx[i] > 0) {
            bh.insert(Data(1L * i * maxy, 1L * cntx[i] * cnty[maxy], i, maxy));
        }
    }

    debug {
        //writeln(bh);
    }

    long tot;

    while (true) {
        auto d = bh.front;
        bh.popFront;

        debug {
            writeln(d);
            writeln(k);
        }

        if (k <= d.num) {
            tot += 1L * d.val * k;
            break;
        }

        tot += 1L * d.val * d.num;
        k -= d.num;
        if (d.y - 1 > 0) {
            bh.insert(Data(1L * d.x * (d.y - 1), 1L * cntx[d.x] * cnty[d.y - 1], d.x, d.y - 1));
        }
    }

    debug {
        writeln(tot);
    }

    real ans = 1.0 * tot / (1.0 * (n - r + 1) * (m - r + 1));

    writefln("%.10f", ans);

}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

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

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

alias Data = Tuple!(long, "val", long, "num", int, "x", int, "y");
int n, m, r, k;

void main() {
    scan(n, m, r, k);

    auto imosx = new int[](n + 1);
    auto imosy = new int[](m + 1);

    foreach (i ; 0 .. n - r + 1) {
        imosx[i]++, imosx[i + r]--;
    }
    foreach (i ; 0 .. m - r + 1) {
        imosy[i]++, imosy[i + r]--;
    }
    foreach (i ; 1 .. n + 1) {
        imosx[i] += imosx[i-1];
    }
    foreach (i ; 1 .. m + 1) {
        imosy[i] += imosy[i-1];
    }

    auto cntx = new int[](r + 1);
    auto cnty = new int[](r + 1);

    int maxy;

    foreach (i ; 0 .. n + 1) {
        cntx[imosx[i]]++;
    }
    foreach (i ; 0 .. m + 1) {
        cnty[imosy[i]]++;
        maxy = max(imosy[i], maxy);
    }

    debug {
        //writeln(cntx);
        //writeln(cnty);
    }

    auto bh = new BinaryHeap!(Array!Data, "a.val < b.val")();

    foreach (i ; 1 .. r + 1) {
        if (cntx[i] > 0) {
            bh.insert(Data(1L * i * r, 1L * cntx[i] * cnty[maxy], i, maxy));
        }
    }

    debug {
        //writeln(bh);
    }

    long tot;

    while (true) {
        auto d = bh.front;
        bh.popFront;

        debug {
            writeln(k);
        }

        if (k <= d.num) {
            tot += 1L * d.val * k;
            break;
        }

        tot += 1L * d.val * d.num;
        k -= d.num;
        if (d.y - 1 > 0) {
            bh.insert(Data(1L * d.x * (d.y - 1), 1L * cntx[d.x] * cnty[d.y - 1], d.x, d.y - 1));
        }
    }

    debug {
        writeln(tot);
    }

    real ans = 1.0 * tot / (1.0 * (n - r + 1) * (m - r + 1));

    writefln("%.10f", ans);

}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

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


A chess tournament will be held soon, where $$$n$$$ chess players will take part. Every participant will play one game against every other participant. Each game ends in either a win for one player and a loss for another player, or a draw for both players.Each of the players has their own expectations about the tournament, they can be one of two types:  a player wants not to lose any game (i. e. finish the tournament with zero losses);  a player wants to win at least one game. You have to determine if there exists an outcome for all the matches such that all the players meet their expectations. If there are several possible outcomes, print any of them. If there are none, report that it's impossible.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$2 \le n \le 50$$$) — the number of chess players. The second line contains the string $$$s$$$ ($$$|s| = n$$$; $$$s_i \in \{1, 2\}$$$). If $$$s_i = 1$$$, then the $$$i$$$-th player has expectations of the first type, otherwise of the second type.

For each test case, print the answer in the following format: In the first line, print NO if it is impossible to meet the expectations of all players. Otherwise, print YES, and the matrix of size $$$n \times n$$$ in the next $$$n$$$ lines. The matrix element in the $$$i$$$-th row and $$$j$$$-th column should be equal to:   +, if the $$$i$$$-th player won in a game against the $$$j$$$-th player;  -, if the $$$i$$$-th player lost in a game against the $$$j$$$-th player;  =, if the $$$i$$$-th and $$$j$$$-th players' game resulted in a draw;  X, if $$$i = j$$$.

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

void main()
{
    int t;
    scanf("%d", &t);
    foreach(_; 0..t)
    {
        int str_len;
        scanf("%d", &str_len);
        getchar();
        // auto str = readln.strip();
        // writeln(str);
        int[] players = new int[str_len];
        int[] first_players, second_players;
        for (int i = 0; i < str_len; i++)
        {
            char tmp;
            scanf("%c", &tmp);
            if (tmp == '1')
            {
                players[i] = 1;
                first_players ~= i;
            }
            else
            {
                players[i] = 2;
                second_players ~= i;
            }
        }
        getchar();
        if (second_players.length == 1 || second_players.length == 2)
        {
            writeln("NO");
            continue;
        }
        else
        {
            writeln("YES");
            if (!second_players.empty)
            {
                second_players ~= second_players.front();
                second_players.popFront();
            }
            int last_win = -1;
            int last_loss = -1;
            for(int i = 0; i < str_len; i++)
            {
                string line;
                if (!second_players.empty)
                {
                    last_win = second_players.front();
                }
                debug{
                    writeln("cur:", i);
                    writeln("win:", last_win);
                    writeln("loss:", last_loss);
                }
                for(int j = 0; j < str_len; j++)
                {
                    if (i == j)
                        line ~= 'X';
                    else if (players[i] == 1)
                        line ~= '=';
                    else if (players[i] == 2 && players[j] == 1)
                        line ~= '=';
                    else if (players[i] == 2 && players[j] == 2)
                    {
                        if (j == last_loss)
                        {
                            // writeln("last loss=", last_loss);
                            line ~= '-';
                        }
                        else if (j == last_win)
                        {
                            line ~= '+';
                            if (second_players.length > 1)
                                last_loss = i;
                        }
                        else if (i > j && j != last_loss)
                            line ~= '+';
                        else
                            line ~= '-';
                    }
                }
                if (!second_players.empty && players[i] == 2)
                {
                    // writeln("before pop:", second_players);
                    second_players.popFront();
                }
                writeln(line);
            }
        }
    }
}

immutable multi = true;

void solve(int tc)
{
	int n = readInt!int;
	auto s = readString;
	int[][2] types;
	foreach(i, si; s) types[int(si == '2')] ~= cast(int)i;
	auto matches = new char[][](n, n);
	foreach(ref row; matches) row[] = '=';
	foreach(i; 0 .. n) matches[i][i] = 'X';
	if (types[1].length >= 1 && types[1].length <= 2)
	{
		writeln("NO");
		writeln;
		return;
	}
	writeln("YES");
	void setWin(int i, int j)
	{
		matches[i][j] = '+';
		matches[j][i] = '-';
	}
	foreach(i; 0 .. types[1].length) setWin(types[1][i], types[1][(i+1)%(types[1].length)]);
	foreach(row; matches) writeln(row);
	writeln;
}

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

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

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

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

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

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

void main()
{
    int t;
    scanf("%d", &t);
    foreach(_; 0..t)
    {
        int str_len;
        scanf("%d", &str_len);
        getchar();
        // auto str = readln.strip();
        // writeln(str);
        int[] players = new int[str_len];
        int[] first_players, second_players;
        for (int i = 0; i < str_len; i++)
        {
            char tmp;
            scanf("%c", &tmp);
            if (tmp == '1')
            {
                players[i] = 1;
                first_players ~= i;
            }
            else
            {
                players[i] = 2;
                second_players ~= i;
            }
        }
        getchar();
        if (second_players.length == 1 || second_players.length == 2)
        {
            writeln("NO");
            continue;
        }
        else
        {
            writeln("YES");
            if (!second_players.empty)
            {
                second_players ~= second_players.front();
                second_players.popFront();
            }
            int cur_second_player = -1;
            for(int i = 0; i < str_len; i++)
            {
                string line;
                if (!second_players.empty)
                {
                    cur_second_player = second_players.front();

                }
                debug{
                    writeln("cur:", i);
                    writeln("cur_2:", cur_second_player);
                    writeln("2pl:", second_players);
                }
                for(int j = 0; j < str_len; j++)
                {
                    if (i == j)
                        line ~= 'X';
                    else if (players[i] == 1)
                        line ~= '=';
                    else if (players[i] == 2 && players[j] == 1)
                        line ~= '=';
                    else if (players[i] == 2 && players[j] == 2)
                    {
                        if (j == cur_second_player)
                            line ~= '+';
                        else
                            line ~= '-';
                    }
                }
                if (!second_players.empty && players[i] == 2)
                {
                    // writeln("before pop:", second_players);
                    second_players.popFront();
                }
                writeln(line);
            }
        }
    }
}


Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length.A block with side a has volume a3. A tower consisting of blocks with sides a1, a2, ..., ak has the total volume a13 + a23 + ... + ak3.Limak is going to build a tower. First, he asks you to tell him a positive integer X — the required total volume of the tower. Then, Limak adds new blocks greedily, one by one. Each time he adds the biggest block such that the total volume doesn't exceed X.Limak asks you to choose X not greater than m. Also, he wants to maximize the number of blocks in the tower at the end (however, he still behaves greedily). Secondarily, he wants to maximize X.Can you help Limak? Find the maximum number of blocks his tower can have and the maximum X ≤ m that results this number of blocks.

The only line of the input contains one integer m (1 ≤ m ≤ 1015), meaning that Limak wants you to choose X between 1 and m, inclusive.

Print two integers — the maximum number of blocks in the tower and the maximum required total volume X, resulting in the maximum number of blocks.

NoteIn the first sample test, there will be 9 blocks if you choose X = 23 or X = 42. Limak wants to maximize X secondarily so you should choose 42.In more detail, after choosing X = 42 the process of building a tower is:  Limak takes a block with side 3 because it's the biggest block with volume not greater than 42. The remaining volume is 42 - 27 = 15.  The second added block has side 2, so the remaining volume is 15 - 8 = 7.  Finally, Limak adds 7 blocks with side 1, one by one. So, there are 9 blocks in the tower. The total volume is is 33 + 23 + 7·13 = 27 + 8 + 7 = 42.

import std.algorithm;
import std.math;
import std.stdio;
import std.typecons;

alias Result = Tuple !(long, q{num}, long, q{start});

Result [long] mm;

Result fun (long m)
{
	if (m < 8)
	{
		return Result (m, m);
	}

	if (m !in mm)
	{
		long s3m = cast (long) (pow (m, 1.0 / 3.0));
		while (s3m * s3m * s3m <= m)
		{
			s3m++;
		}
		s3m--;
		auto cm = s3m * s3m * s3m;

		auto cur = fun (m - s3m * s3m * s3m);
		cur = Result (1 + cur.num, s3m * s3m * s3m + cur.start);

		s3m--;
		auto prev = fun (cm - 1 - s3m * s3m * s3m);
		prev = Result (1 + prev.num, s3m * s3m * s3m + prev.start);

		mm[m] = max (prev, cur);
	}
	return mm[m];
}

void main ()
{
	long m;
	while (readf (" %s", &m) > 0)
	{
		auto res = fun (m);
		writeln (res.num, " ", res.start);
	}
}