module main;
__gshared:
import core.bitop, std.algorithm, std.bigint, std.bitmanip, std.complex,
	std.container, std.conv, std.datetime, std.functional, std.math, std.meta;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.parallelism, std.random, std.range, std.regex, std.stdio, std.string,
	std.traits, std.typecons, std.uni, std.variant;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
enum mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///lcm
		T lcm(T)(auto ref T a, auto ref T b)
		{
			return a / gcd(a, b) * b;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///BigInt greatest common divizor
		BigInt gcd(BigInt a, BigInt b)
		{
			while (b)
			{
				a %= b;
				swap(a, b);
			}
			return a;
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///integer size
		int sz(T)(T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			size_t l, r = a.length;
			while (r - l > 1)
			{
				auto m = (l + r) >> 1;
				if (!(a[m] < g))
					r = m;
				else
					l = m;
			}
			return (!(a[l] < g)) ? l : r;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			size_t l, r = a.length;
			while (r - l > 1)
			{
				auto m = (l + r) >> 1;
				if (g < a[m])
					r = m;
				else
					l = m;
			}
			return (g < a[l]) ? l : r;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return binf(a, g) != a.length;
		}
	}
	///write an array
	void putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)
	{
		writefln("%(%s" ~ ch ~ "%)", a);
	}
	///write a matrix
	void putarr(X)(in X a)
			if (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))
	{
		writefln("%(%(%s %)\n%)", a);
	}
	///get an array
	bool getarr(X)(X a, in size_t n)
	{
		bool b = 1;
		foreach (ref i; a[0 .. n])
			b = input(&i);
		return b;
	}
	///read without format
	bool input(T...)(ref T ptrs) if (ptrs.length > 0)
	{
		size_t s;
		foreach (ref e; ptrs)
		{
			if (isSomeChar!(Unqual!(typeof(e))))
				s += readf(" %c", &e);
			else
				s += readf(" %s", &e);
		}
		return s == ptrs.length;
	}
	///readln without format
	bool read(T...)(ref T ptrs) if (ptrs.length > 0)
	{
		size_t s;
		foreach (ref e; ptrs)
		{
			if (isSomeChar!(Unqual!(typeof(e))))
				s += readf(" %c", &e);
			else
				s += readf(" %s", &e);
		}
		readln;
		return s == ptrs.length;
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------

void main()
{
	version (home)
	{
		freopen("input.txt", "r", core.stdc.stdio.stdin);
		//freopen("output.txt", "w", core.stdc.stdio.stdout);
		/*StopWatch sw;
		sw.start;
		scope (exit)
		{
			sw.stop;
			stderr.writefln("\nTime: %d ms", sw.peek.msecs);
		}*/
	}
	int n;
	loop: while (read(n))
	{
		auto a = arread!int;
		int[][int] g;
		foreach (x; a)
		{
			for (int i = 2; i * i <= x; i++)
			{
				if (x % i == 0)
				{
					int cnt;
					while (x % i == 0)
					{
						cnt++;
						x /= i;
					}
					g[i] ~= cnt;
				}
			}
			if (x > 1)
				g[x] ~= 1;
		}
		int[int[]] q;
		int grandi(int[] v)
		{
			if (v.empty)
				return 0;
			if (v in q)
				return q[v];
			int[int] mex;
			foreach (c; 1 .. v.back + 1)
			{
				int[] v1;
				foreach (x; v)
				{
					if (x < c)
						v1 ~= x;
					else if (x > c)
						v1 ~= x - c;
				}
				mex[grandi(v1.sort().uniq().array)] = 1;
			}
			for (int x;; x++)
			{
				if (x !in mex)
					return q[v.idup] = x;
			}
			assert(0);
		}

		int ans;
		foreach (z; g)
		{
			ans ^= grandi(z.sort().uniq().array);
		}
		writeln(ans ? "Mojtaba" : "Arpa");
	}
}

import std.algorithm, std.array, std.conv, std.functional, std.range, std.stdio;
alias T = int, g = memoize!h;
T [T] f, x;
T h (T v) {
	T s;
	foreach (k; 1..30) if (v >= 1 << k) s |= 1 << g ((v >> k) | (v & ((1 << k) - 1)));
	return 30.iota.countUntil !(r => !(s & (1 << r)));
}
void main () {
	readln;
	foreach (c; readln.split.map !(to!T)) {
		foreach (d; 2..8 ^^ 5) if (!(c % d)) f[d] |= 1 << (1 + 30.iota.countUntil !(k => !!((c /= d) % d)));
		if (c > 1) x[c] = 1;
	}
	writeln (f.byValue.map!g.fold!q{a ^ b} (0) - (x.length & 1) ? "Mojtaba" : "Arpa");
}

import std.algorithm, std.array, std.conv, std.functional, std.stdio, std.string;
immutable int limit = 1 << 16;

alias g = memoize !(gImpl);
int gImpl (int v) {
	int s;
	foreach (k; 1..30)
		if (v >= 1 << k)
			s |= 1 << g ((v >> k) | (v & ((1 << k) - 1)));
	int r = 0;
	while (s & (1 << r))
		r += 1;
	return r;
}

void main () {
	int n = readln.strip.to !(int);
	auto a = readln.splitter.map !(to !(int)).array;
	auto f = new int [limit];
	bool [int] once;

	foreach (c; a) {
		for (int d = 2; d < limit; d++)
			if (c % d == 0) {
				int k = 0;
				while (c % d == 0) {
					c /= d;
					k += 1;
				}
				f[d] |= 1 << k;
			}
		if (c > 1)
			once[c] = true;
	}

	int res = once.length & 1;
	foreach (v; f)
		res ^= g (v);
	writeln (res ? "Mojtaba" : "Arpa");
}

import std.algorithm, std.array, std.conv, std.range, std.stdio;
alias T = int;
T [T] f, x, g;
T h (T v) {
	if (v !in g) {
		T s;
		foreach (k; 1..30) if (v >= 1 << k) s |= 1 << h ((v >> k) | (v & ((1 << k) - 1)));
		g[v] = 30.iota.countUntil !(r => !(s & (1 << r)));
	}
	return g[v];
}
void main () {
	readln;
	foreach (c; readln.split.map !(to!T)) {
		foreach (d; 2..8 ^^ 5) if (!(c % d)) f[d] |= 1 << (1 + 30.iota.countUntil !(k => !!((c /= d) % d)));
		if (c > 1) x[c] = 1;
	}
	writeln (f.byValue.map!h.fold!q{a ^ b} (0) - (x.length & 1) ? "Mojtaba" : "Arpa");
}

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

immutable int limit = 1 << 16;

alias g = memoize !(gImpl);

int gImpl (int v)
in
{
	debug {writeln (v);}
}
out (res)
{
	debug {writeln ("g (", v, ") = ", res);}
}
body
{
	int s;
	foreach (k; 1..30)
	{
		if (v >= 1 << k)
		{
			s |= 1 << g ((v >> k) | (v & ((1 << k) - 1)));
		}
	}

	int r = 0;
	while (s & (1 << r))
	{
		r += 1;
	}
	return r;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto f = new int [limit];
		bool [int] once;

		foreach (c; a)
		{
			for (int d = 2; d < limit; d++)
			{
				if (c % d == 0)
				{
					int k = 0;
					while (c % d == 0)
					{
						c /= d;
						k += 1;
					}
					debug {writeln (d, ": ", k);}
					f[d] |= 1 << k;
				}
			}
			if (c > 1)
			{
				once[c] = true;
			}
		}

		int res = once.length & 1;
		foreach (v; f)
		{
			res ^= g (v);
		}

		writeln (res ? "Mojtaba" : "Arpa");
	}
}

import std.algorithm, std.conv, std.range, std.stdio;
int [int] f, x, g;
int h (int v) {
	if (v !in g) {
		int s, k;
		for (k = 2; v >= k; k <<= 1) s |= 1 << h (v / k | (v & (k - 1)));
		g[v] = 30.iota.countUntil !(r => !(s & (1 << r)));
	}
	return g[v];
}
void main () {
	readln;
	foreach (c; readln.split.map !(to!int)) {
		foreach (d; 2..8 ^^ 5) if (!(c % d)) f[d] |= 1 << (1 + 30.iota.countUntil !(k => !!((c /= d) % d)));
		if (c > 1) x[c] = 1;
	}
	writeln (f.byValue.map!h.fold!q{a ^ b} (x.length & 1) ? "Mojtaba" : "Arpa");
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }

      int[int] fs;
      foreach (i; 0 .. N) {
        int a = A[i];
        for (int p = 2; p^^2 <= a; ++p) {
          if (a % p == 0) {
            int e;
            do {
              ++e;
              a /= p;
            } while (a % p == 0);
            fs[p] |= 1 << e;
          }
        }
        if (a > 1) {
          fs[a] |= 1 << 1;
        }
      }
      debug {
        writeln("fs = ", fs);
      }

      long[int] cache;
      long calc(int f) {
        long ret;
        cache.update(f, {
          long app;
          if (f) {
            foreach (e; 1 .. bsr(f) + 1) {
              const ff = ((f & ((1 << e) - 1)) | (f >> e)) & ~1;
              app |= 1L << calc(ff);
            }
          }
          ret = bsf(~app);
          debug {
            writefln("calc %b = %s", f, ret);
          }
          return ret;
        }, (ref long r) {
          return ret = r;
        });
        return ret;
      }

      long ans;
      foreach (p, f; fs) {
        ans ^= calc(f);
      }
      writeln(ans ? "Mojtaba" : "Arpa");
    }
  } catch (EOFException e) {
  }
}

import std.algorithm, std.array, std.conv, std.functional, std.range, std.stdio;
alias T = int, g = memoize!h;
T [T] f, x;
T h (T v) {
	T s;
	foreach (k; 1..30) if (v >= 1 << k) s |= 1 << g ((v >> k) | (v & ((1 << k) - 1)));
	return 30.iota.countUntil !(r => !(s & (1 << r)));
}
void main () {
	readln;
	foreach (c; readln.split.map !(to!T)) {
		foreach (d; 2..8 ^^ 5) if (!(c % d)) f[d] |= 1 << 30.iota.countUntil !(k => !!((c /= d) % d));
		if (c > 1) x[c] = 1;
	}
	writeln (f.byValue.map!g.fold!q{a ^ b} (0) - (x.length & 1) ? "Mojtaba" : "Arpa");
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }

      int[int] fs;
      foreach (i; 0 .. N) {
        int a = A[i];
        for (int p = 2; p^^2 <= a; ++p) {
          if (a % p == 0) {
            int e;
            do {
              ++e;
              a /= p;
            } while (a % p == 0);
            fs[p] |= 1 << e;
          }
        }
        if (a > 1) {
          fs[a] |= 1 << 1;
        }
      }
      debug {
        writeln("fs = ", fs);
      }

      int[int] cache;
      int calc(int f) {
        int ret;
        cache.update(f, {
          int app;
          if (f) {
            foreach (e; 1 .. bsf(f) + 1) {
              const ff = ((f & ((1 << e) - 1)) | (f >> e)) & ~1;
              app |= 1 << calc(ff);
            }
          }
          ret = bsf(~app);
          debug {
            writefln("calc %b = %s", f, ret);
          }
          return ret;
        }, (ref int r) {
          return ret = r;
        });
        return ret;
      }

      int ans;
      foreach (p, f; fs) {
        ans ^= calc(f);
      }
      writeln(ans ? "Mojtaba" : "Arpa");
    }
  } catch (EOFException e) {
  }
}


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

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

		int [] d;
		int i = 0;
		while (i < n * 2)
		{
			int j = i;
			do
			{
				i += 1;
			}
			while (i < n * 2 && a[i] < a[j]);
			d ~= i - j;
		}

		auto f = new bool [n * 2 + 1];
		f[0] = true;
		foreach (ref c; d)
			for (int p = n * 2; p >= c; p--)
				f[p] |= f[p - c];

		writeln (f[n] ? "YES" : "NO");
	}
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const N = readInt();
        auto P = new int[2 * N + 1];
        foreach (i; 0 .. 2 * N) {
          P[i] = readInt();
        }
        P[2 * N] = 2 * N + 1;

        auto dp = new int[][](N + 1, N + 1);
        dp[0][0] = P[2 * N];
        foreach (s; 0 .. 2 * N) {
          foreach (a; 0 .. N + 1) {
            const b = s - a;
            if (0 <= b && b <= N) {
              if (dp[a][b] > 0) {
                const p = P[2 * N - (a + b) - 1];
                if (a < N && P[2 * N - (a + b) - 1] < dp[a][b]) {
                  chmax(dp[a + 1][b], dp[a][b]);
                }
                if (b < N && P[2 * N - (a + b) - 1] < P[2 * N - (a + b)]) {
                  chmax(dp[b + 1][a], P[2 * N - (a + b)]);
                }
              }
            }
          }
        }
        debug {
          foreach (a; 0 .. N + 1) {
            writeln(a, ": ", dp[a]);
          }
        }
        writeln((dp[N][N] > 0) ? "YES" : "NO");
      }
    }
  } catch (EOFException e) {
  }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		int[] arr;
		int num, cnt;
		foreach (i; 0..n*2)
		{
			if (p[i] > num)
			{
				if (cnt != 0)
				{
					arr ~= cnt;
				}
				num = p[i];
				cnt = 0;
			}
			++cnt;
		}
		arr ~= cnt;
		debug writeln(arr);

		auto dp = new bool[](n+1);
		dp[0] = true;
		foreach (e; arr)
		{
			foreach_reverse (i; 0..dp.length)
			{
				if (!dp[i]) continue;
				auto ni = i + e;
				if (ni < n+1)
				{
					dp[ni] = true;
				}
			}
		}
		ans[ti] = dp[n];
	}

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

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

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

		int [] d;
		int i = 0;
		while (i < n * 2)
		{
			int j = i;
			do
			{
				i += 1;
			}
			while (i < n * 2 && a[i] < a[j]);
			d ~= i - j;
		}

		auto f = new int [n * 2 + 1];
		f[] = int.max;
		f[0] = -1;
		foreach (int k, ref c; d)
		{
			for (int p = c; p <= n * 2; p++)
			{
				if (f[p] == int.max && f[p - c] < k)
				{
					f[p] = k;
				}
			}
		}
		writeln (f[n] < int.max ? "YES" : "NO");
	}
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = 0 ~ readln.splitter.map !(to !(int)).array;
		auto f = new bool [] [] (2, n * 2 + 1);
		int b = 0;
		f[b][0] = true;
		foreach (i; 1..n * 2 + 1)
		{
			b ^= 1;
			f[b][] = false;
			foreach (j; 0..i)
			{
/*
				if (i - j > n)
				{
					continue;
				}
*/
				if (f[!b][j])
				{
					if (a[i - 1] < a[i] && i - j <= n)
					{
						f[b][j] = true;
					}
					if (a[j] < a[i])
					{
						f[b][i - 1] = true;
					}
				}
			}
		}
		writeln (f[b].any ? "YES" : "NO");
	}
}


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		sort (a);
		auto c = a.group.map !(q{a[1].to !(int)}).array;
		sort (c);
		int res = n;
		int k = c.length.to !(int);
		foreach (i; 0..k)
		{
			res = min (res, n - (k - i) * c[i]);
		}
		writeln (res);
	}
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		sort (a);
		auto c = a.group.map !(q{a[1].to !(int)}).array;
		sort (c);
		int res = n;
		int i = 0;
		int k = c.length.to !(int);
		foreach (num; 1..n + 1)
		{
			while (i < k && c[i] < num)
			{
				i += 1;
			}
			res = min (res, n - (k - i) * num);
		}
		writeln (res);
	}
}

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

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

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

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

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

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

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

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

void main()
{
    int T; get(T); while (T--) {
        int N; get(N);
        int[] AA; get(AA);
        int[int] memo;
        foreach (a; AA) ++memo[a];
        int[] ps;
        foreach (_, v; memo) ps ~= v;
        sort!"a > b"(ps);
        int res = int.max, pre, s;
        foreach (i, p; ps) {
            s += p;
            if (i) pre += i.to!int * (ps[i - 1] - p);
            res = min(res, pre + N - s);
        }
        writeln(res);
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		int[int] cnt;
		foreach (i; 0..n)
			++cnt[a[i]];

		int[int] cnt2;
		foreach (value; cnt.values)
			++cnt2[value];

		auto keys = cnt2.keys.sort;
		auto b = new long[](keys.length+1);
		auto c = new long[](keys.length+1);
		foreach (i; 0..keys.length)
		{
			auto key = keys[i];
			b[i+1] = b[i] + cnt2[key] * key;
			c[i+1] = c[i] + cnt2[key];
		}

		ans[ti] = long.max;
		foreach (i; 0..keys.length)
		{
			auto key = keys[i];
			long del = b[i] + b[$-1] - b[i+1];
			del -= (c[$-1] - c[i+1]) * key;
			ans[ti].chmin(del);
		}
	}

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


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

immutable int MN = 2010;
immutable int MK = 2010;
immutable long MD = 10^^9+7;

int main() {
    int n, k;
    string s;
    long[][] dp = new long[][](MN, MK);
    long[] sum = new long[](MK);
    readf("%d %d\n", &n, &k);
    s = chomp(readln());
    s ~= 'a';
    for (int i = 0; i <= n; i++) {
        dp[i][0] = 1;
    }
    for (int i = n; i >= 0; i--) {
        for (int u = 0; u <= k; u++) {
            sum[u] += dp[i+1][u]*(s[i]-'a');
            sum[u] %= MD;
            dp[i][u] += sum[u];
            dp[i][u] %= MD;
            for (int j = i-1; j >= 0; j--) {
                int d = u+(i-j)*(n-i+1);
                if (d > k) break;
                dp[j][d] += dp[i][u] * ('z'-s[i-1]);
                dp[j][d] %= MD;
            }
        }
    }
    writeln(dp[0][k]%MD);
    return 0;
}

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

immutable int MN = 2010;
immutable int MK = 2010;
immutable long MD = 10^^9+7;

int main() {
    int n, k;
    string s;
    long[MK][] dp = new long[MK][](MN);
    long[] sum = new long[](MK);
    readf("%d %d\n", &n, &k);
    s = chomp(readln());
    s ~= 'a';
    for (int i = 0; i <= n; i++) {
        dp[i][0] = 1;
    }
    for (int i = n; i >= 0; i--) {
        for (int u = 0; u <= k; u++) {
            sum[u] += dp[i+1][u]*(s[i]-'a');
            sum[u] %= MD;
            dp[i][u] += sum[u];
            dp[i][u] %= MD;
            for (int j = i-1; j >= 0; j--) {
                int d = u+(i-j)*(n-i+1);
                if (d > k) break;
                dp[j][d] += dp[i][u] * ('z'-s[i-1]);
                dp[j][d] %= MD;
            }
        }
    }
    writeln(dp[0][k]%MD);
    return 0;
}

import std.stdio, std.string, std.conv, std.algorithm, std.functional;
immutable int MN = 2010;
immutable long MD = 1^^9+7;
int n, k;
string s;

long[][] dp;
bool[][] used;

long solve(int i, int u) {
    if (i > n) return 0;
    if (u < 0) return 0;
    if (i == n) {
        if (u) {
            return 0;
        } else {
            return 1;
        }
    }
    if (used[i][u]) return dp[i][u];
    long r = 0;
    for (int j = i; j < n; j++) {
        r += solve(j+1, u-(j-i+1)*(n-j))*('z'-s[j]);
        r += solve(j+1, u)*(s[j]-'a');
    }
    if (!u) r++;
    r %= MD;
    dp[i][u] = r;
    used[i][u] = true;
    return r;
}

int main() {
    dp = new long[][](MN, MN);
    used = new bool[][](MN, MN);
    readf("%d %d\n", &n, &k);
    s = readln();
    writeln(solve(0, k));
    return 0;
}

import std.stdio, std.string, std.conv, std.algorithm, std.functional;
immutable int MN = 2010;
immutable long MD = 1^^9+7;
int n, k;
string s;

long[][] dp;
bool[][] used;

long solve(int i, int u) {
    if (i > n) return 0;
    if (u < 0) return 0;
    if (i == n) {
        if (u) {
            return 0;
        } else {
            return 1;
        }
    }
    if (used[i][u]) return dp[i][u];
    long r = 0;
    for (int j = i; j < n; j++) {
        r += solve(j+1, u-(j-i+1)*(n-j))*('z'-s[j]);
        r += solve(j+1, u)*(s[j]-'a');
    }
    if (!u) r++;
    dp[i][u] = r;
    used[i][u] = true;
    return r;
}

int main() {
    dp = new long[][](MN, MN);
    used = new bool[][](MN, MN);
    readf("%d %d\n", &n, &k);
    s = readln();
    writeln(solve(0, k));
    return 0;
}


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

string FMT_F = "%.10f";

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

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

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

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

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

		bool allX = true;
		bool hasX;
		foreach (i; 0..n)
		{
			if (a[i] != x)
				allX = false;
			else
				hasX = true;
		}
		if (allX) continue;

		if (hasX)
		{
			ans[ti] = 1;
		}
		else
		{
			long tot;
			foreach (i; 0..n)
				tot += a[i];
			if (tot / n == x && tot % n == 0)
				ans[ti] = 1;
			else
				ans[ti] = 2;
		}
	}

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

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

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

void solve(){
    long n = rd;
    long x = rd;
    ll[] arr = rdarr;
    ll summ = 0;
    bool aleq = 1, oneq = 0;
    foreach(el; arr){
        summ += el;
        if(el != x) aleq = 0;
        else oneq = 1;
    }
    if(aleq){
        writeln(0);
    }else if(summ == n*x || oneq){
        writeln(1);
    }else{
        writeln(2);
    }
}

void main(){
    long t = 1;
    t = rd;
    while(t--) solve();
    stdout.flush;
}

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

void solve()
{
    auto nx = readln.split.to!(int[]);
    auto N = nx[0];
    auto X = nx[1];
    int sum_a, infected;
    bool all_same = true;
    foreach (a; readln.split.to!(int[])) {
        if (a != X) all_same = false;
        if (a == X) ++infected;
        sum_a += a;
    }
    if (all_same) {
        writeln(0);
    } else if (X*N == sum_a) {
        writeln(1);
    } else if (infected == 0) {
        writeln(2);
    } else {
        writeln(1);
    }
}

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

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

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

void solve(){
    long n = rd;
    long x = rd;
    ll[] arr = rdarr;
    ll summ = 0;
    bool aleq = 1;
    foreach(el; arr){
        summ += el;
        if(el != x) aleq = 0;
    }
    if(aleq){
        writeln(0);
    }else if(summ == n*x){
        writeln(1);
    }else{
        writeln(2);
    }
}

void main(){
    long t = 1;
    t = rd;
    while(t--) solve();
    stdout.flush;
}


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 a, b;
		readf !(" %s %s") (a, b);
		writeln (min (a, b, (a + b) / 4));
	}
}

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

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    long a, b;
    readf!" %d %d "(a, b);
    if (a > b)
      swap(a, b);
    writeln(min((a + b) / 4, a));
  }
}


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

immutable int MAX_N = 100_005;
immutable int MAX_C = 0x3F3F3F3F;
immutable int NA    = -1;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new int [n];
		foreach (i; 0..n)
		{
			readf (" %s", &a[i]);
		}

		auto h = new int [n + 2];
		h[0] = -1;
		h[1..$] = n + 1;
		int res = 0;
		foreach (i; 0..n)
		{
			int lo = 0;
			int hi = n;
			while (lo < hi)
			{
				int me = (lo + hi + 1) >> 1;
				if (h[me] > a[i])
				{
					hi = me - 1;
				}
				else
				{
					lo = me;
				}
			}
			lo++;
			enforce (h[lo] > a[i]);
			h[lo] = a[i];
			res = max (res, lo);
			debug {writefln ("%s %s", h, lo);}
		}

		writeln (res);
	}
}

import std.stdio;

int[100000] b;
int c = 0;

void main() {
  int n;
  for (readf("%d", &n); n >= 1; --n) {
    int a;
    readf(" %d", &a);
    int l = 0;
    int r = c;
    while (l < r) {
      int m = l + r >> 1;
      if (a < b[m])
        r = m;
      else
        l = m + 1;
    }
    if (r == c)
      ++c;
    b[r] = a;
  }
  writeln(c);
}


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;

immutable int MX_SZ = 100;

int binCoef(int n, int k) {
    int ans = 1;
    foreach (i; 1 .. k+1) {
        ans *= n - i + 1;
        ans /= i;
    }

    return ans;
}

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

    auto ans = new int[MX_SZ][MX_SZ];

    int cqSz = 3;
    while (binCoef(cqSz+1, 3) <= k) { ++cqSz; }

    foreach (i; 0 .. cqSz) {
        foreach (j; 0 .. cqSz) {
            if (i == j) { continue; }
            ans[i][j] = 1;
        }
    }

    int lft = k - binCoef(cqSz, 3);

    int idx = cqSz;
    while (lft > 0) {
        ans[0][idx] = ans[idx][0] = 1;

        debug { writeln(lft, ' ', idx); }

        int p = 1, cur = 1;
        while (cur <= lft && p < cqSz) {
            ans[p][idx] = ans[idx][p] = 1;
            lft -= cur;
            ++p;
            cur = p;

            debug { writeln("in ", cur, ' ', lft); }
        }

        ++idx;
    }

    writeln(MX_SZ);
    ans.each!(line => line.writefln!"%(%s%)");
}

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;

immutable int MX_SZ = 100;

int binCoef(int n, int k) {
    int ans = 1;
    foreach (i; 1 .. k+1) {
        ans *= n - i + 1;
        ans /= i;
    }

    return ans;
}

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

    auto ans = new int[MX_SZ][MX_SZ];

    int cqSz = 3;
    while (binCoef(cqSz+1, 3) <= k) { ++cqSz; }

    foreach (i; 0 .. cqSz) {
        foreach (j; 0 .. cqSz) {
            if (i == j) { continue; }
            ans[i][j] = 1;
        }
    }

    int lft = k - binCoef(cqSz, 3);

    int idx = cqSz;
    while (lft > 0) {
        ans[0][idx] = ans[idx][0] = 1;

        debug { writeln(lft, ' ', idx); }

        int pos = 1;
        while (pos <= lft && pos < cqSz) {
            ans[pos][idx] = ans[idx][pos] = 1;
            lft -= pos;
            ++pos;
        }

        ++idx;
    }

    writeln(MX_SZ);
    ans.each!(line => line.writefln!"%(%s%)");
}

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;

int binCoef(int n, int k) {
    int ans = 1;
    foreach (i; 1 .. k+1) {
        ans *= n - i + 1;
        ans /= i;
    }

    return ans;
}

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

    auto ans = new int[100][100];

    int cqSz = 3;
    while (binCoef(cqSz+1, 3) <= k) { ++cqSz; }

    foreach (i; 0 .. cqSz) {
        foreach (j; 0 .. cqSz) {
            if (i == j) { continue; }
            ans[i][j] = 1;
        }
    }

    int lft = k - binCoef(cqSz, 3);

    int idx = cqSz;
    while (lft > 0) {
        ans[0][idx] = ans[idx][0] = 1;

        int p = 1, cur = 1;
        while (cur <= lft && p < cqSz) {
            ans[p][idx] = ans[idx][p] = 1;
            lft -= cur;
            ++p;
            cur = binCoef(p+1, 2);
        }

        ++idx;
    }

    writeln(100);
    ans.each!(line => line.writefln!"%(%s%)");
}


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

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

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

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

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      auto P = new int[N];
      foreach (i; 0 .. N) {
        P[i] = readInt() - 1;
      }

      long ans = long.max;
      int km = -1;

      long now;
      long posi, nega;
      int offset;
      auto cnt = new int[4 * N + 1];
      void add(int val) {
        now += abs(offset + val);
        (offset + val >= 0) ? ++posi : ++nega;
        ++cnt[2 * N + val];
      }
      void rem(int val) {
        now -= abs(offset + val);
        (offset + val >= 0) ? --posi : --nega;
        --cnt[2 * N + val];
      }

      foreach (i; 0 .. N) {
        add(P[i] - i);
      }
      foreach (k; 0 .. N) {
        debug {
          writeln(k, ": ", now);
        }
        if (chmin(ans, now)) {
          km = k;
        }
        rem(P[N - 1 - k] - (N - 1 - k));
        posi -= cnt[2 * N - offset];
        nega += cnt[2 * N - offset];
        now -= posi;
        now += nega;
        --offset;
        add(P[N - 1 - k] - (N - 1 - k) + N);
      }
      writeln(ans, " ", km);

      debug {
        long brt = long.max;
        int brtkm = -1;
        foreach (k; 0 .. N) {
          long cost;
          foreach (i; 0 .. N) {
            cost += abs(P[i] - (k + i) % N);
          }
          debug {
            writeln("brt ", k, ": ", cost);
          }
          if (chmin(brt, cost)) {
            brtkm = k;
          }
        }
        writeln("brt: ", brt, " ", brtkm);
      }
    }
  } catch (EOFException e) {
  }
}

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

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);
  alias Ev = Tuple!(int, long, long);
  auto n = next!long;
  auto p = next!long(n);
  p[] -= 1;
  auto dpt = new long[](cast(size_t)n); // delta per time
  void calcdpt(long i, long pi)
  {
    auto ts = redBlackTree!long([0]);
    if (pi >= i) ts.insert(pi - i);
    else ts.insert(n - i + pi);
    ts.insert(n - 1 - i);
    ts.insert(n - i);
    auto pd = long(0);
    debug auto tdpt = new long[](cast(size_t) n);
    foreach(t; ts)
      if (t < n)
	{
	  auto val = abs((i + 1 + t) % n - pi) - abs((i + t) % n - pi);
	  auto toadd = val - pd;
	  dpt[cast(size_t)t] += toadd;
	  debug tdpt[cast(size_t)t] += toadd;
	  pd = val;
	}
    long delta = 0;
    debug writeln("after adding ", i, " ", pi);
    debug foreach(t; 0 .. n)
      {
	write(abs((i + 1 + t)%n - pi) - abs((i + t)%n - pi), " ");
      }
    debug writeln;
    debug foreach(t; 0 .. n)
      {
	delta += tdpt[cast(size_t)t];
	write(delta, " ");
      }
    debug writeln;
  }
  foreach(i, pi; p)
    calcdpt(cast(long) i, pi);
  long deviation = iota(0, n).map!(i => abs(i - p[cast(size_t)i])).sum;
  long bestdeviation = deviation;
  long besttime = 0;
  long delta = dpt[0];

  long dev = deviation;
  long accdelta = dpt[0];
  debug write(dev, " ");
  debug foreach(t; 1 .. n)
    {
      dev += accdelta;
      write(dev, "(", iota(0, n).map!(i => abs((i + t) % n - p[cast(size_t)i])).sum, ") ");
      accdelta += dpt[cast(size_t)t];
    }
  writeln;
  foreach(t; 1 .. n)
    {
      deviation += delta;
      if (deviation < bestdeviation)
	{
	  bestdeviation = deviation;
	  besttime = t;
	}
      delta += dpt[cast(size_t)t];
    }
  writeln(bestdeviation, " ", besttime);
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

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

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);
  alias Ev = Tuple!(int, int, int);
  auto n = next!int;
  auto p = next!int(n);
  p[] -= 1;
  auto dpt = new int[](n); // delta per time
  void calcdpt(int i, int pi)
  {
    auto ts = redBlackTree!int([0]);
    if (pi >= i) ts.insert(pi - i);
    else ts.insert(n - i + pi);
    ts.insert(n - 1 - i);
    ts.insert(n - i);
    auto pd = int(0);
    foreach(t; ts)
      if (t < n)
	{
	  dpt[t] += abs((i + 1 + t) % n - pi) - abs((i + t) % n - pi) - pd;
	  pd = dpt[t];
	}
  }
  foreach(i, pi; p)
    calcdpt(cast(int) i, pi);
  long deviation = iota(0, n).map!(i => abs(i - p[i])).sum;
  long bestdeviation = deviation;
  int besttime = 0;
  long delta = 0;
  foreach(t; 0 .. n)
    {
      deviation += delta;
      if (deviation < bestdeviation)
	{
	  bestdeviation = deviation;
	  besttime = t;
	}
      delta += dpt[t];
    }
  writeln(bestdeviation, " ", besttime);
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

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

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);
  alias Ev = Tuple!(int, int, int);
  auto n = next!int;
  auto p = next!int(n);
  p[] -= 1;
  auto dpt = new int[](n); // delta per time
  void calcdpt(int i, int pi)
  {
    auto ts = redBlackTree!int([0]);
    if (pi >= i) ts.insert(pi - i);
    else ts.insert(n - i + pi);
    ts.insert(n - 1 - i);
    ts.insert(n - i);
    auto pd = int(0);
    debug auto tdpt = new int[](n);
    foreach(t; ts)
      if (t < n)
	{
	  auto val = abs((i + 1 + t) % n - pi) - abs((i + t) % n - pi);
	  auto toadd = val - pd;
	  dpt[t] += toadd;
	  debug tdpt[t] += toadd;
	  pd = val;
	}
    long delta = 0;
    debug writeln("after adding ", i, " ", pi);
    debug foreach(t; 0 .. n)
      {
	write(abs((i + 1 + t)%n - pi) - abs((i + t)%n - pi), " ");
      }
    debug writeln;
    debug foreach(t; 0 .. n)
      {
	delta += tdpt[t];
	write(delta, " ");
      }
    debug writeln;
  }
  foreach(i, pi; p)
    calcdpt(cast(int) i, pi);
  long deviation = iota(0, n).map!(i => abs(i - p[i])).sum;
  long bestdeviation = deviation;
  int besttime = 0;
  long delta = dpt[0];

  long dev = deviation;
  long accdelta = dpt[0];
  debug write(dev, " ");
  debug foreach(t; 1 .. n)
    {
      dev += accdelta;
      write(dev, "(", iota(0, n).map!(i => abs((i + t) % n - p[i])).sum, ") ");
      accdelta += dpt[t];
    }
  writeln;
  foreach(t; 1 .. n)
    {
      deviation += delta;
      if (deviation < bestdeviation)
	{
	  bestdeviation = deviation;
	  besttime = t;
	}
      delta += dpt[t];
    }
  writeln(bestdeviation, " ", besttime);
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}


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

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

int[] di = [1, 1, -1, -1];
int[] dj = [1, -1, 1, -1];

void main() {
    int n;
    scan(n);
    auto m = iota(n).map!(i => readln.chomp).array;
    int ans;

    foreach (i ; 1 .. n - 1) {
        foreach (j ; 1 .. n - 1) {
            if (m[i][j] != 'X') continue;
            bool ok = true;
            foreach (k ; 0 .. 4) {
                int ni = i + di[k];
                int nj = j + dj[k];
                if (m[ni][nj] != 'X') {
                    ok = false;
                    break;
                }
            }
            ans += ok;
        }
    }

    writeln(ans);
}

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

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

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

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

immutable long MOD = 998244353;

void main() {
    auto N = readln.chomp.to!int;
    auto S = N.iota.map!(_ => readln.chomp).array;
    int ans = 0;
    int[] dr = [0, -1, -1, 1, 1];
    int[] dc = [0, -1, 1, -1, 1];

    foreach (r; 1..N-1) {
        foreach (c; 1..N-1) {
            int ok = 1;
            foreach (k; 0..5) {
                int nr = r + dr[k];
                int nc = c + dc[k];
                if (S[nr][nc] == '.') {
                    ok = 0;
                    break;
                }
            }
            ans += ok;
        }
    }

    ans.writeln;
}

//ahmat
import core.stdc.stdio:scanf,printf,puts;
import core.bitop;
import std.stdio;
import std.string;
import std.algorithm;
import std.functional;
import std.array;
import std.container;
import std.conv;
import std.container;
import std.typecons;
import std.math;
import std.numeric;
pragma(inline,true);

void main(){
    int n=readln.chomp.to!int;
    auto a=new string[n];
    foreach(i;0..n)
        a[i]=readln.strip;
    int ans=0;
    foreach(i;1..n-1)
        foreach(j;1..n-1)
            if(a[i][j]=='X'
                && a[i-1][j-1]=='X'
                && a[i-1][j+1]=='X'
                && a[i+1][j-1]=='X'
                && a[i+1][j+1]=='X')
                ans++;
    writeln(ans);
}


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

struct Interval
{
  long l, h;

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

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

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

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

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

  long n, d;
  @dn long[] a;

  void solve(long tc = -1)
  {
    logSym!(this);
    long total = 0;
    foreach(i, ai; a)
      {
        if (i == 0)
          {
            total += ai;
            continue;
          }
        auto taken = min(ai, d / i);
        d -= taken * i;
        total += taken;
      }
    writeln(total);
  }
}

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

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

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

DList!string _words;

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

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

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

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

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

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

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

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

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

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

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

    }
}

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

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

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

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

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

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

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

void main()
{
  type;
}

import std.stdio : writeln;

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

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

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

        return readToken.to!int;
    }

    string[] tokens;
}

long binom2(int n) {
    return n * (n + 1L) >> 1;
}

void main() {
    IO io;
    int T = io.readInt;
    while (T--) {
        int n = io.readInt;
        int m = io.readInt;
        int result = 0;
        for (int i = 0; i < n; ++i) {
            int a = io.readInt;
            while (m >= i && a) {
                result++, m -= i, a--;
            }
        }
        writeln(result);
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto d = RD!int;
		auto a = RDA;
		ans[ti] = a[0];
		foreach (i; 1..n)
		{
			auto x = min(d/i, a[i]);
			ans[ti] += x;
			d -= i*x;
		}
	}

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

import std.stdio;

void main() {
    int t, n, d, v, res; readf("%d", &t); while(t--) {
        scanf("%d %d", &n, &d); scanf("%d", &res);
        for (int i = 1; i < n; i++) { scanf("%d", &v); if (d > 0) { res+= (i*v<=d ? v : (d/i)); d-=i*v; } }
        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;

final class InputReader {
  private:
  ubyte[] p, buffer;
  bool eof;
  bool rawRead () {
    if (eof) {
      return false;
    }
    p = stdin.rawRead (buffer);
    if (p.empty) {
      eof = true;
      return false;
    }
    return true;
  }
  ubyte nextByte(bool check) () {
    static if (check) {
      if (p.empty) {
        if (!rawRead ()) {
          return 0;
        }
      }
    }
    auto r = p.front;
    p.popFront ();
    return r;
  }
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
  }
  bool seekByte (in ubyte lo) {
    while (true) {
      p = p.find! (c => c >= lo);
      if (!p.empty) {
        return false;
      }
      if (!rawRead ()) {
        return true;
      }
    }
  }
  template next(T) if (isSigned!T) {
    T next ()  {
      if (seekByte (45)) {
        return 0;
      }
      T res;
      ubyte b = nextByte!false ();
      if (b == 45) {
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    T next () {
      if (seekByte (48)) {
        return 0;
      }
      T res = nextByte!false () - 48;
      while (true) {
        ubyte b = nextByte!true ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  T[] nextA(T) (in int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

void main() {
  auto r = new InputReader ();
  immutable nt = r.next!uint ();
  foreach (tid; 0 .. nt) {
    const n = r.next!uint ();
    auto d = r.next!uint ();
    auto a = r.nextA!uint (n);
    foreach (i; 1 .. n) {
      while (d >= i && a[i] > 0) {
        d -= i;
        a[0]++;
        a[i]--;
      }
    }
    writeln (a[0]);
  }
}


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

void main()
{
    auto n = strip(readln());
    auto x = to!string(n.retro());
    auto res = n ~ x;
    writeln(res);

}

import std.stdio;
import std.range;
import std.string;

void main() {

	string nstr = readln.strip;

    writeln(nstr, nstr.retro);
}


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip;
		writeln (s[0..$ / 2].sum == s[$ / 2..$].sum ? "YES" : "NO");
	}
}

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

int[] rtln(T)() { return to!(T[])(strip(readln).split("")); }

void main() {
    int t, n, m;
    readf("%d\n", t);
    while(t--) {
        auto arr = rtln!int;
		if ((arr[0] + arr[1] + arr[2]) == (arr[3]+arr[4]+arr[5]))
			writeln("YES");
		else
			writeln("NO");
    }
}

void main() { runSolver(); }

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

  auto solve() {
    auto subSolve() {
      auto N = scan.map!(c => c - '0').array;

      auto a = N[0..3].sum;
      auto b = N[3..6].sum;

      return a == b ? "YES" : "NO";
    }

    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"];

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


import std.algorithm, std.bigint, std.conv, std.stdio, std.string;
void main () {
	auto n = readln.strip.to!int, s = readln.strip, i = n / 2, j = n - i;
	while (s[i] == '0') i -= 1;
	while (j < n && s[j] == '0') j += 1;
	auto res = BigInt (s);
	if (i > 0) res = min (res, BigInt (s[0..i]) + BigInt (s[i..$]));
	if (j < n) res = min (res, BigInt (s[0..j]) + BigInt (s[j..$]));
	writeln (res);
}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto s = readln.strip;
		int i = n / 2;
		int j = n - i;
		while (s[i] == '0')
		{
			i -= 1;
		}
		while (j < n && s[j] == '0')
		{
			j += 1;
		}
		auto res = BigInt (s);
		if (i > 0)
		{
			res = min (res, BigInt (s[0..i]) + BigInt (s[i..$]));
		}
		if (j < n)
		{
			res = min (res, BigInt (s[0..j]) + BigInt (s[j..$]));
		}
		writeln (res);
	}
}

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

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto n = readNum!int;
  string s = readStr;

  BigInt ret = s;

  auto c = s.length / 2;
  auto found = false;
  auto d = s.length % 2 == 1 ? 1 : 0;
  auto p = s.length % 2 == 1 ? 1 : 0;

  while(1){
    if(s[c-d+p] != '0'){
      BigInt l = s[0 .. c-d+p];
      BigInt r = s[c-d+p .. $];

      ret = min(ret, l+r);
      found = true;
    }

    if(s[c+d] != '0'){
      BigInt l = s[0 .. c+d];
      BigInt r = s[c+d .. $];

      ret = min(ret, l+r);
      found = true;
    }

    if(found) break;
    else d++;
  }

  writeln(ret);
}

import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm : sort, each, maxElement, minElement;
import std.conv : to;
import std.range : iota, tee, enumerate;
import std.algorithm.comparison : equal, max, min;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;
import std.math;
import std.bigint;

alias Tree = RBT!int;
alias ll = long;

void main() {
  GC.disable();

  int l;
  readf(" %s\n", l);
  string s =  readln.strip;

  int idx = s.length/2;
  while(idx >= 0 && idx < s.length) {
    if (s[idx] != '0') break;
    idx--;
  }

  BigInt ans = s;
  if (idx > 0 && idx < s.length) {
    BigInt a = s[0 ..  idx];
    BigInt b = s[idx .. $];
    BigInt ss = a + b;
    ans = min(ans, ss);
  }

  idx = s.length/2+1;

  while(idx >= 0 && idx < s.length) {
    if (s[idx] != '0') break;
    idx++;
  }

  if (idx > 0 && idx < s.length) {
    BigInt a = s[0 ..  idx];
    BigInt b = s[idx .. $];
    BigInt ss = a + b;
    ans = min(ans, ss);
  }

  writeln(ans);

}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto s = readln.strip;
		int i = n / 2;
		int j = n - i;
		while (s[i] == '0')
		{
			i -= 1;
		}
		while (j < n && s[j] == '0')
		{
			j += 1;
		}
		writeln (i, " ", j);
		auto res = BigInt (s);
		if (i > 0)
		{
			res = min (res, BigInt (s[0..i]) + BigInt (s[i..$]));
		}
		if (j < n)
		{
			res = min (res, BigInt (s[0..j]) + BigInt (s[j..$]));
		}
		writeln (res);
	}
}


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

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

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

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

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

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

int[][] solve() {
	int[][] as = new int[][2];
	foreach (a; A) {
		as[a % 2] ~= a;
	}
	if (as[1].length < K - P) {
		return null;
	}
	int[][][] rets = new int[][][2];

	int[] rs;
	foreach (idx, a; as[1]) {
		if (idx < K - P) {
			rets[1] ~= [ a ];
		} else {
			rs ~= a;
		}
	}
	if (rs.length % 2 != 0) {
		return null;
	}

	int[][] groups;
	foreach (a; as[0]) {
		groups ~= [ a ];
	}
	for (int j = 0; j < rs.length; j += 2) {
		groups ~= rs[j .. j + 2];
	}
	if (groups.length < P) {
		return null;
	}
	foreach (idx, group; groups) {
		if (idx < P) {
			rets[0] ~= group;
		} else {
			rets[(0 < P) ? 0 : 1][0] ~= group;
		}
	}
	return rets[0] ~ rets[1];
}

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

		if (auto res = solve) {
			writeln("YES");
			foreach (line; res) {
				writeln(line.length, " ", line.to!string.removechars("[],"));
			}
		} else {
			writeln("NO");
		}
	}
	} catch (EOFException) {}
}

module main;

import std.stdio, std.string;

void solve(int[] a, int n, int k, int p)
{
    int[] odd, even;
    foreach (val; a)
    {
        if (val & 1)
        {
            odd ~= val;
        }
        else
        {
            even ~= val;
        }
    }
    auto evenAns = new int[][p + 1];
    auto oddAns = new int[][k - p + 1];
    int i, j, t, oddIdx, evenIdx;
    for (i = 0, j = 0; i < p && j < even.length; ++ i, ++ j)
    {
        evenAns[i] ~= even[j];
    }
    evenIdx = j;
    for (t = 0, j = 0; t < k - p && j < odd.length; ++ t, ++ j)
    {
        oddAns[t] ~= odd[j];
    }
    oddIdx = j;
    if (t < k - p)
    {
        writeln("NO");
        return;
    }
    else if (i < p)
    {
        auto evenNeed = p - i;
        auto oddLeft = odd.length - oddIdx;
        if (oddLeft % 2 != 0 || (oddLeft >> 1) < evenNeed)
        {
            writeln("NO");
            return;
        }
        j = oddIdx;
        while (i < p)
        {
            evenAns[i] ~= odd[j];
            evenAns[i] ~= odd[j + 1];
            ++ i;
            j += 2;
        }
        while (j < odd.length)
        {
            evenAns[p - 1] ~= odd[j];
            ++ j;
        }
    }
    else
    {
        auto oddLeft = odd.length - oddIdx;
        if (oddLeft & 1)
        {
            writeln("NO");
            return;
        }
        for (j = oddIdx; j < odd.length; j += 2)
        {
            if (p > 0)
            {
                evenAns[p - 1] ~= odd[j];
                evenAns[p - 1] ~= odd[j + 1];
            }
            else
            {
                oddAns[k - p - 1] ~= odd[j];
                oddAns[k - p - 1] ~= odd[j + 1];
            }
        }
        for (j = evenIdx; j < even.length; ++ j)
        {
            if (p > 0)
            {
                evenAns[p - 1] ~= even[j];
            }
            else
            {
                oddAns[k - p - 1] ~= even[j];
            }
        }
    }
    writeln("YES");
    foreach (idx; 0 .. p)
    {
        writef("%d ", evenAns[idx].length);
        foreach (val; evenAns[idx])
        {
            writef("%d ", val);
        }
        writeln();
    }
    foreach (idx; 0 .. k - p)
    {
        writef("%d ", oddAns[idx].length);
        foreach (val; oddAns[idx])
        {
            writef("%d ", val);
        }
        writeln();
    }
}

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

module main;

import std.stdio, std.string;

void solve(int[] a, int n, int k, int p)
{
    int[] odd, even;
    foreach (i, val; a)
    {
        if (val & 1)
        {
            odd ~= val;
        }
        else
        {
            even ~= val;
        }
    }
    auto evenAns = new int[][p];
    auto oddAns = new int[][k - p];
    int i, j, t, oddIdx, evenIdx;
    for (i = 0, j = 0; i < p && j < even.length; ++ i, ++ j)
    {
        evenAns[i] ~= even[j];
    }
    evenIdx = j;
    for (t = 0, j = 0; t < k - p && j < odd.length; ++ t, ++ j)
    {
        oddAns[t] ~= odd[j];
    }
    oddIdx = j;
    if (t < k - p)
    {
        writeln("NO");
        return;
    }
    else if (i < p)
    {
        auto evenNeed = p - i;
        auto oddLeft = odd.length - oddIdx;
        if (oddLeft % 2 != 0 || (oddLeft >> 1) < evenNeed)
        {
            writeln("NO");
            return;
        }
        j = oddIdx;
        while (i < p)
        {
            evenAns[i] ~= odd[j];
            evenAns[i] ~= odd[j + 1];
            ++ i;
            ++ j;
        }
        while (j < odd.length)
        {
            evenAns[$ - 1] ~= odd[j];
            ++ j;
        }
    }
    else
    {
        auto oddLeft = odd.length - oddIdx;
        if (oddLeft & 1)
        {
            writeln("NO");
            return;
        }
        for (j = oddIdx; j < odd.length; j += 2)
        {
            evenAns[$ - 1] ~= odd[j];
            evenAns[$ - 1] ~= odd[j + 1];
        }
        for (j = evenIdx; j < even.length; ++ j)
        {
            evenAns[$ - 1] ~= even[j];
        }
    }
    writeln("YES");
    foreach (idx; 0 .. p)
    {
        writef("%d ", evenAns[idx].length);
        foreach (val; evenAns[idx])
        {
            writef("%d ", val);
        }
        writeln();
    }
    foreach (idx; 0 .. k - p)
    {
        writef("%d ", oddAns[idx].length);
        foreach (val; oddAns[idx])
        {
            writef("%d ", val);
        }
        writeln();
    }
}

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

module main;

import std.stdio, std.string;

void solve(int[] a, int n, int k, int p)
{
    int[] odd, even;
    foreach (i, val; a)
    {
        if (val & 1)
        {
            odd ~= val;
        }
        else
        {
            even ~= val;
        }
    }
    auto evenAns = new int[][p];
    auto oddAns = new int[][k - p];
    int i, j, t, oddIdx, evenIdx;
    for (i = 0, j = 0; i < p && j < even.length; ++ i, ++ j)
    {
        evenAns[i] ~= even[j];
    }
    evenIdx = j;
    for (t = 0, j = 0; t < k - p && j < odd.length; ++ t, ++ j)
    {
        oddAns[t] ~= odd[j];
    }
    oddIdx = j;
    if (t < k - p)
    {
        writeln("NO");
        return;
    }
    else if (i < p)
    {
        auto evenNeed = p - i;
        auto oddLeft = odd.length - oddIdx;
        if (oddLeft % 2 != 0 || (oddLeft << 1) < evenNeed)
        {
            writeln("NO");
            return;
        }
        j = oddIdx;
        while (i < p)
        {
            evenAns[i] ~= odd[j];
            evenAns[i] ~= odd[j + 1];
            ++ i;
            ++ j;
        }
        while (j < odd.length)
        {
            evenAns[$ - 1] ~= odd[j];
            ++ j;
        }
    }
    else
    {
        auto oddLeft = odd.length - oddIdx;
        if (oddLeft & 1)
        {
            writeln("NO");
            return;
        }
        for (j = oddIdx; j < odd.length; j += 2)
        {
            evenAns[$ - 1] ~= odd[j];
            evenAns[$ - 1] ~= odd[j + 1];
        }
        for (j = evenIdx; j < even.length; ++ j)
        {
            evenAns[$ - 1] ~= even[j];
        }
    }
    writeln("YES");
    foreach (idx; 0 .. p)
    {
        writef("%d ", evenAns[idx].length);
        foreach (val; evenAns[idx])
        {
            writef("%d ", val);
        }
        writeln();
    }
    foreach (idx; 0 .. k - p)
    {
        writef("%d ", oddAns[idx].length);
        foreach (val; oddAns[idx])
        {
            writef("%d ", val);
        }
        writeln();
    }
}

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

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

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

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

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

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

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

int[][] solve() {
	int[][] as = new int[][2];
	foreach (a; A) {
		as[a % 2] ~= a;
	}
	if (as[1].length < K - P) {
		return null;
	}
	if ((as[1].length - (K - P)) % 2 != 0) {
		return null;
	}
	int[][][] rets = new int[][][2];
	int[] rs = as[0];
	foreach (idx, a; as[1]) {
		if (idx < K - P) {
			rets[1] ~= [ a ];
		} else {
			rs ~= a;
		}
	}
	foreach (idx, a; rs) {
		if (idx < P) {
			rets[0] ~= [ a ];
		} else {
			rets[0][0] ~= a;
		}
	}
	return rets[0] ~ rets[1];
}

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

		if (auto res = solve) {
			writeln("YES");
			foreach (line; res) {
				writeln(line.length, " ", line.to!string.removechars("[],"));
			}
		} else {
			writeln("NO");
		}
	}
	} catch (EOFException) {}
}


immutable multi = true;

void solve(int tc)
{
  auto n = readInt!int;
  auto a = ma(n, readInt!int);
  sort(a);
  foreach(i; 1 .. 1 + n/2)
    {
      writeln(a[i], " ", a[0]);
    }
  writeln;
}

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

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

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

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

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

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

void solve(){
    auto n = scan!int;
    auto arr = scanArray;
    arr.sort;
    auto k = arr[0];
    for(int i = n/2 + (n % 2 != 0); i < n; ++i){
        writeln(arr[i], " ", k);
    }
}

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

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

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

struct S { int x, y; };

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    int n;
    readf!" %d "(n);
    auto a = readln.splitter.map!(to!int).array.sort.array;
    bool[int] nums;
    foreach (x ; a)
      nums[x] = true;
    bool[S] used;
    S[] ans;

    while (ans.length < n / 2) {
      int x = a[uniform(0, a.length)];
      int y = a[uniform(0, a.length)];
again:
      if (x < y)
        swap(x, y);
      if (x == y || (S(x, y) in used))
        continue;
      int z = x % y;
      if (!(z in nums)) {
        ans ~= S(x, y);
        used[S(x, y)] = true;
      } else {
        y = z;
        goto again;
      }
    }
    foreach (tmp ; ans) {
      writefln("%d %d", tmp.x, tmp.y);
    }
  }
}

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;

struct S { int x, y; };

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    int n;
    readf!" %d "(n);
    auto a = readln.splitter.map!(to!int).array.sort.array;
    bool[int] nums;
    foreach (x ; a)
      nums[x] = true;
    bool[S] used;
    S[] ans;
    foreach_reverse (j ; 0 .. a.length) {
      foreach (i ; 0 .. j) {
        int x = a[j];
        int y = a[i];
        if ((S(x, y) in used) || ((x % y) in nums))
          continue;
        ans ~= S(x, y);
        used[S(x, y)] = true;
      }
    }
/*
    while (ans.length < n / 2) {
      int x = a[uniform(0, a.length)];
      int y = a[uniform(0, a.length)];
      if (x < y)
        swap(x, y);
      if (x == y || (S(x, y) in used) || ((x % y) in nums))
        continue;
      ans ~= S(x, y);
      used[S(x, y)] = true;
    }
*/
    foreach (tmp ; ans) {
      writefln("%d %d", tmp.x, tmp.y);
    }
  }
}