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

void main()
{
  ulong n, k, x;
  readf!" %d %d %d "(n, k, x);
  auto a = readln.chomp.split.map!(to!ulong).array.sort.array;
  ulong[] gaps;
  foreach (i ; 1 .. a.length) {
    if (a[i] - a[i - 1] > x) {
      gaps ~= a[i] - a[i - 1];
    }
  }
  ulong n_groups = gaps.length + 1;
  gaps.sort;
  foreach (gap ; gaps) {
    ulong n_filler = (gap - 1) / x;
    if (k >= n_filler) {
      n_groups -= 1;
      k -= n_filler;
    }
  }
  writeln(n_groups);
}

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

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

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

void main() {
  long n, k, x;
  read(n, k, x);

  auto arr = list!long.sort;

  long[] breakPoints;

  foreach (i; 1 .. n.to!int) {
    if (arr[i] - arr[i - 1] > x) {
      breakPoints ~= arr[i] - arr[i - 1];
    }
  }

  sort(breakPoints);

  long answer = breakPoints.length + 1;

  foreach (b; breakPoints) {
    auto req = (b - 1) / x;
    if (req <= k) {
      k -= req;
      answer--;
    } else {
      break;
    }
  }

  writeln(answer);
}

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

void main()
{
  ulong n, k, x;
  readf!" %d %d %d "(n, k, x);
  auto a = readln.chomp.split.map!(to!ulong).array.sort.array;
  ulong[] gaps;
  foreach (i ; 1 .. a.length) {
    if (a[i] - a[i - 1] > x) {
      gaps ~= a[i] - a[i - 1];
    }
  }
  ulong n_groups = gaps.length + 1;
  gaps.sort;
  foreach (gap ; gaps) {
    ulong n_filler = gap / x;
    if (k >= n_filler) {
      n_groups -= 1;
      k -= n_filler;
    }
  }
  writeln(n_groups);
}

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

void main()
{
  ulong n, k, x;
  readf!" %d %d %d "(n, k, x);
  auto a = readln.chomp.split.map!(to!ulong).array.sort.array;
  ulong[] gaps;
  foreach (i ; 1 .. a.length) {
    if (a[i] - a[i - 1] > x) {
      gaps ~= a[i] - a[i - 1];
    }
  }
  ulong n_groups = gaps.length + 1;
  gaps.sort;
  foreach (gap ; gaps) {
    ulong n_filler = gap / (x + 1);
    if (k >= n_filler) {
      if (n_groups > 0)
        n_groups -= 1;
      k -= n_filler;
    } else {
      break;
    }
  }
  writeln(n_groups);
}

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

void main()
{
  ulong n, k, x;
  readf!" %d %d %d "(n, k, x);
  auto a = readln.chomp.split.map!(to!ulong).array.sort.array;
  ulong[] gaps;
  foreach (i ; 1 .. a.length) {
    if (a[i] - a[i - 1] > x) {
      gaps ~= a[i] - a[i - 1];
    }
  }
  ulong n_groups = gaps.length + 1;
  gaps.sort;
  foreach (gap ; gaps) {
    ulong n_filler = gap / (x + 1);
    if (k >= n_filler) {
      n_groups -= 1;
      k -= n_filler;
    } else {
      break;
    }
  }
  writeln(n_groups);
}

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

void main()
{
  ulong n, k, x;
  readf!" %d %d %d "(n, k, x);
  auto a = readln.chomp.split.map!(to!ulong).array.sort.array;
  ulong[] gaps;
  foreach (i ; 1 .. a.length) {
    if (a[i] - a[i - 1] > x) {
      gaps ~= a[i] - a[i - 1];
    }
  }
  ulong n_groups = gaps.length + 1;
  gaps.sort;
  foreach (gap ; gaps) {
    ulong n_filler = 0;
/*
    while (gap > x) {
      n_filler++;
      gap -= x + 1;
    }
*/
    n_filler = (gap + x) / (x + 1);

    if (k >= n_filler) {
      n_groups -= 1;
      k -= n_filler;
    } else {
      break;
    }
  }
  writeln(n_groups);
}


import std.stdio;

void main() {
  int t;
  readf!"%d\n"(t);
  for(int i = 0; i < t; i++) {
    int k;
    readf!"%d\n"(k);
    int max = 0;
    int cur = 0;
    bool calm = true;
    for(int j = 0; j < k; j++) {
      char c;
      readf!"%c"(c);
      if(c == 'P') {
        if(calm) continue;
        cur++;
        if(cur > max) max = cur;
      }
      if(c == 'A') {
        calm = false;
        cur = 0;
      }
    }
    readf!"\n"();
    writeln(max);
  }
}

import std.algorithm;
import std.conv : to;
import std.container;
import std.numeric : gcd;
import std.range;
import std.stdio;
import std.typecons : Tuple, tuple;

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

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

void main() {
    int T = readInt;
    while (T--) {
        int n = readInt;
        string s = readToken;
        int result = 0, count = 0;
        for (int i = n; i--;) {
            if (s[i] == 'P') {
                count++;
            }
            else {
                result = max(result, count), count = 0;
            }
        }
        writeln(result);
    }
}

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

DList!string _words;

void read(T...)(ref T t)
{
  void singleRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  static foreach(i; 0 .. T.length)
    {
      static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))
        {
          foreach(ref element; t[i])
            read(element);
        }
      else
        {
          singleRead(t[i]);
        }
    }
}

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

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

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

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

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

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

    }
}

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

void main()
{
  int t;
  read(t);
  foreach(tc; 0 .. t)
    {
      int k;
      string s;
      read(k, s);
      s ~= 'A';
      size_t last = -1;
      size_t maxspace = 0;
      foreach(i, c; s)
        {
          if (c == 'A')
            {
              if (last != -1)
                maxspace = max(maxspace, i - last - 1);
              last = i;
            }
        }
      writeln(maxspace);
    }
}

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

string FMT_F = "%.10f";

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

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

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

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void 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 main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto k = RD!int;
		auto s = RD!string;
		bool hasA;
		int streak;
		foreach (i; 0..k)
		{
			if (!hasA)
			{
				if (s[i] == 'A')
					hasA = true;
			}
			else if (s[i] == 'P')
			{
				++streak;
			}
			else
			{
				ans[ti].chmax(streak);
				streak = 0;
			}
		}
		ans[ti].chmax(streak);
	}

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


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;

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		string a = ".";
		string b = ".";
		ubyte cur = 0;
		foreach (c; s.representation)
		{
			while (c != cur)
			{
				cur -= 1;
				a ~= "X.";
				b ~= "..";
			}
			a ~= ".X..";
			b ~= "XXX.";
		}
		writeln (a);
		writeln (b);
	}
}

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

void main(){

	string s;
	while ((s = readln.strip) != ""){
		string a = ".";
		string b = ".";
		ubyte cur = 0;
		foreach (c; s.representation){
			while (c != cur){
				cur -= 1;
				a ~= "X.";
				b ~= "..";
			}
			a ~= ".X..";
			b ~= "XXX.";
		}
		writeln (a);
		writeln (b);
	}
}


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

string FMT_F = "%.10f";

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

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

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

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

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

		foreach (i; 0..n-1)
		{
			ans[ti].chmax(a[i]*a[i+1]);
		}
	}

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

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

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

void solve()
{
	int n = readInt!int;
	auto a = new int[](n); foreach(ref ai; a) ai = readInt!int;
	iota(0, n - 1).map!(i => cast(long)a[i] * a[i+1]).fold!max.writeln;
}

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

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

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

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

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

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

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

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


//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;
import std.typecons;

class InputReader {
  private:
  ubyte[] p;
  ubyte[] buffer;
  size_t cur;
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
    p = stdin.rawRead (buffer);
  }
  final ubyte skipByte (ubyte lo) {
    while (true) {
      auto a = p[cur .. $];
      auto r = a.find! (c => c >= lo);
      if (!r.empty) {
        cur += a.length - r.length;
        return p[cur++];
      }
      p = stdin.rawRead (buffer);
      cur = 0;
      if (p.empty) return 0;
    }
  }
  final ubyte nextByte () {
    if (cur < p.length) {
       return p[cur++];
    }
    p = stdin.rawRead (buffer);
    if (p.empty) return 0;
    cur = 1;
    return p[0];
  }

  template next(T) if (isSigned!T) {
    final T next ()  {
      T res;
      ubyte b = skipByte (45);
      if (b == 45) {
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    final T next () {
      T res = skipByte (48) - 48;
      while (true) {
        ubyte b = nextByte ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  final T[] nextA(T) (int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

alias T = Tuple!(int, int);

void main() {
  auto r = new InputReader;
  immutable n = r.next!int;
  auto p = r.nextA!int(n);
  p[] -= 1;
  auto q = new int[n];
  foreach (i; 0 .. n) {
    q[p[i]] = i;
  }
  int m = n / 2;
  T[] res;
  int s (int i, int j) {
    debug stderr.writefln ("swap: %d %d\n", i + 1, j + 1);
    if (i == j) {
      return j;
    }
    debug stderr.writefln ("%d %d", 2 * abs (i - j), n);
    assert (2 * abs (i - j) >= n);
    res ~= tuple (i + 1, j + 1);
    swap (p[i], p[j]);
    q[p[i]] = i;
    q[p[j]] = j;
    return j;
  }
  immutable last = n - 1;
  debug stderr.writeln ("m = ", m);
  foreach_reverse (i; 1 .. m) {
    int pos = m - i;
    int u = q[pos];
    debug stderr.writeln ("p = ", p, ", pos = ", pos, ", u = ", u);
    if (u != pos) {
      if (u < m) {
        u = s (u, last);
      } else {
        u = s (u, 0);
        u = s (0, last);
      }
      assert (u == last);
      s (last, pos);
    }
    pos = m + i - 1;
    u = q[pos];
    debug stderr.writeln ("p = ", p, ", pos = ", pos, ", u = ", u);
    if (u != pos) {
      if (u >= m) {
        u = s (u, 0);
      } else {
        u = s (u, last);
        u = s (last, 0);
      }
      assert (u == 0);
      s (0, pos);
    }
  }
  if (p[0] != 0) {
    s (0, last);
  }
  writeln (res.length);
  foreach (t; res) {
    writeln (t[0], ' ', t[1]);
  }
  debug {
    stderr.writeln (p);
    foreach (i; 0 .. n) {
      assert (p[i] == i);
    }
  }
}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		int half = n / 2;
		readln;
		auto p = readln.splitter.map !(to !(int)).array;
		p[] -= 1;
		auto q = new int [n];
		foreach (i, v; p)
		{
			q[v] = i;
		}

		int [] [] ans;

		void doSwap (int i, int j)
		{
			ans ~= [i + 1, j + 1];
			p.swapAt (i, j);
			q.swapAt (p[i], p[j]);
		}

		foreach (i; 0..half)
		{
			int j = i + half;
			int last = n - 1;

			if (q[j] < j)
			{
				doSwap (q[j], last);
			}
			if (q[j] > j)
			{
				doSwap (q[j], i);
			}
			if (q[j] == i)
			{
				doSwap (q[j], j);
			}
			if (q[j] != j)
			{
				assert (false);
			}

			if (q[i] > i && q[i] < j)
			{
				doSwap (q[i], last);
			}
			if (q[i] > j)
			{
				doSwap (q[i], i);
			}
			if (q[i] != i)
			{
				assert (false);
			}
		}

		writeln (ans.length);
		writefln ("%(%(%s %)\n%)", ans);
	}
}

import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}

	int n = read.to!int;

	int[] as;
	foreach(i; 0 .. n) as ~= read.to!int - 1;
	print!1("as:", as);

	int[] bs = new int[](n);
	foreach(int i, a; as) bs[a] = i;
	print!1("bs:", bs);

	int[2][] ans;
	void swap(int i, int j){
		print!1("i:", i, " j:", j);
		if(i == j) return;
		else if(i > j){
			swap(j, i);
			return;
		}
		else if(j - i >= n / 2){
			ans ~= [i + 1, j + 1];
			int x = as[i], y = as[j];
			as[i] = y, as[j] = x;
			bs[y] = i, bs[x] = j;
			print!1("-> i:", i, " j:", j, " as:", as);
			return;
		}
		else if(i < n  / 2 && j < n / 2){
			swap(i, n - 1);
			swap(j, n - 1);
			swap(i, n - 1);
			return;
		}
		else if(i < n / 2 && j >= n / 2){
			swap(i, n - 1);
			swap(0, j);
			swap(0, n - 1);
			swap(i, n - 1);
			swap(0, j);
			return;
		}
		else if(i >= n / 2 && j >= n / 2){
			swap(0, i);
			swap(0, j);
			swap(0, i);
			return;
		}
		assert(0);
	}

	foreach(i; 0 .. n){
		if(as[i] == i) continue;
		int j = bs[i];
		swap(i, j);
	}

	ans.length.writeln;
	foreach(an; ans){
		writeln(an[0], " ", an[1]);
	}

}


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

void main ()
{
	foreach (test; 0..readln.strip.to !(int))
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		auto b = readln.splitter.map !(to !(int)).array;
		auto ok = a.isSorted || (0 < b.sum && b.sum < n);
		writeln (ok ? "Yes" : "No");
	}
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		long cnt, cnt0, cnt1;
		long last0, last1;
		foreach (i; 0..n)
		{
			if (b[i] == 0)
			{
				if (a[i] < last0)
				{
					++cnt0;
				}
				last0 = a[i];
				++cnt;
			}
			else
			{
				if (a[i] < last1)
				{
					++cnt1;
				}
				last1 = a[i];
			}
		}
		if (min(cnt, n-cnt) == 0)
			ans[ti] = max(cnt0, cnt1) == 0;
		else
			ans[ti] = true;
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

		long cnt, cnt0, cnt1;
		long last0, last1;
		foreach (i; 0..n)
		{
			if (b[i] == 0)
			{
				if (a[i] < last0)
				{
					++cnt0;
				}
				last0 = a[i];
				++cnt;
			}
			else
			{
				if (a[i] < last1)
				{
					++cnt1;
				}
				last1 = a[i];
			}
		}
		ans[ti] = max(cnt0, cnt1) <= min(cnt, n-cnt);
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

		bool ok = true;
		long last0, last1;
		foreach (i; 0..n)
		{
			if (b[i] == 0)
			{
				if (a[i] < last0)
				{
					ok = false;
					break;
				}
				last0 = a[i];
			}
			else
			{
				if (a[i] < last1)
				{
					ok = false;
					break;
				}
				last1 = a[i];
			}
		}
		ans[ti] = ok;
	}

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


// cheese-cracker [2022-01-26]

void solve(){
    int n = scan!int;
    int m = scan!int;
    auto arr = scanArray;
    auto pref = arr.cumulativeFold!((a, b) => a + b)(0L).array;
    tup[] selects;
    selects ~= tup(pref.front, 0L);
    for(int i = 1; i < n; ++i){
        if(pref[i] > selects.back[0]){
            selects ~= tup(pref[i], i.to!long);
        }
    }

    long summ = pref.back;
    long maxk = selects.back[0];

    long[] res;
    auto qrs = scanArray;
    foreach(x; qrs){
        // Rotations is ceil of this
        long num = x - maxk;
        long rots = 0;
        if(summ > 0 && num > 0){
            rots = num / summ + (num % summ != 0);
        }else{
            rots = 0;
        }
        /* show(x, num, summ, rots); */

        // Soln Exists

        long left = x - summ * rots;
        if(selects.back[0] < left){
            res ~= -1;
            continue;
        }
        /* show(left); */

        int lo = -1, hi = selects.length.to!int - 1;
        while(hi - lo > 1){
            int midd = (lo + hi)/2;
            /* show(lo, midd, hi); */
            ( (selects[midd][0] >= left ) ?  hi : lo ) = midd;
        }
        res ~= (rots * n + selects[hi][1]);
    }
    res.each!(a => write(a, " "));
    writeln;
}

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

/*_________________________*That's All Folks!*__________________________*/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
string[] tk; alias tup = Tuple!(long, long);
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; } }

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, M; get(N, M);
        long[] AA; get(AA);
        long[] XX; get(XX);

        auto ss = new long[](N);
        ss[0] = AA[0];
        foreach (i; 1..N) ss[i] += ss[i - 1] + AA[i];

        auto ms = new long[](N);
        ms[0] = ss[0];
        foreach (i; 1..N) ms[i] = max(ms[i-1], ss[i]);

        long[] res;
        foreach (x; XX) {
            if (ss[$-1] <= 0 && x > ms[$-1]) {
                res ~= -1;
                continue;
            }
            auto min_a = max(0, x - ms[$-1]);
            auto c = ss[$-1] <= 0 ? 0 : (min_a + ss[$-1] - 1) / ss[$-1];
            auto d = ss[$-1] * c;
            if (d + AA[0] >= x) {
                res ~= c * N;
                continue;
            }
            int l, r = (N-1).to!int;
            while (l + 1 < r) {
                auto m = (l + r) / 2;
                if (d + ms[m] >= x) {
                    r = m;
                } else {
                    l = m;
                }
            }
            res ~= c * N + r;
        }
        writefln!"%(%d %)"(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)
	{
		int n, m;
		readf !(" %s %s") (n, m);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto s = [0L];
		foreach (ref c; a)
		{
			s ~= s.back + c;
		}
		auto t = s.dup;
		foreach (i; 0..n)
		{
			t[i + 1] = max (t[i + 1], t[i]);
		}
		auto x = readln.splitter.map !(to !(int)).array;
		long [] ans;
		foreach (long y; x)
		{
			if (t[n] < y && s[n] <= 0)
			{
				ans ~= -1;
				continue;
			}
			long steps = 0;
			if (t[n] < y)
			{
				steps = (y + s[n] - 1 - t[n]) / s[n];
			}
			y -= steps * s[n];
			auto shift = t[1..n].assumeSorted.lowerBound (y)
			    .length.to !(int);
			ans ~= steps * n + shift;
		}
		writefln !("%(%s %)") (ans);
	}
}


import std.stdio: writeln, readln;
import std.array: array, split;
import std.string: chomp, count;
import std.conv: to;
import std.algorithm: map;

string multi_str(string a, ulong times) {
    string result;
    foreach (ulong i; 0..times) {
        result ~= a;
    }
    return result;
}
// 7 6 --> 0001100
void main() {
    int t = readln.chomp.to!int;
    foreach (int _; 0..t) {
        int[2] words = readln.split.map!(to!int).array;
        int[] a = [1];
        int i;
        while (a[$-1] <= words[1]) {
            a ~= ++i + a[$-1];
        }
        writeln(multi_str("a", words[0] - a.count) ~ "b" ~ multi_str("a", a.count - words[1] + a[$-2] - 2) ~ "b" ~ multi_str("a", words[1] - a[$-2]));
    }
}

// https://codeforces.com/problemset/problem/1328/B
import std.stdio;
import std.string;
import std.conv;

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

    int n, k;
foreach(kase; 0..t) {
    readf("%d %d\n", &n, &k);

    char[] ans = "".dup;

    foreach(ch; 0..n) ans ~= "a";

    for(int idx = n-2; idx >= 0; idx--) {
        if(k <= (n-idx-1)) {
            ans[idx] = 'b';
            ans[n-k] = 'b';
            break;
        }
        k -= n-idx-1;
    }
    ans.writeln;
}

}

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

string FMT_F = "%.10f";

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

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

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

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

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

		int x;
		size_t pos1, pos2;
		foreach (i; 0..n)
		{
			x += i+1;
			if (x >= k)
			{
				pos1 = n-2-i;
				pos2 = pos1 + 1 + x - k;
				break;
			}
		}
		debug writeln("pos:", pos1, ", ", pos2);
		foreach (i; 0..n)
		{
			if (i == pos1 || i == pos2)
				ans[ti] ~= 'b';
			else
				ans[ti] ~= 'a';
		}
	}

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


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

alias Point = Tuple !(int, q{x}, int, q{y});

immutable int mod = 107;
immutable int mod2 = mod ^^ 2;

void main ()
{
	int n;
	long s;
multitest_loop:
	while (readf (" %s %s", &n, &s) > 0)
	{
		s *= 2;
		int sp = (+s % mod + mod) % mod;
		int sn = (-s % mod + mod) % mod;
		auto b = new bool [mod2 * 2];
		foreach (i; -mod2..mod2)
		{
			if ((i % mod + mod) % mod == (sp % mod + mod) % mod ||
			    (i % mod + mod) % mod == (sn % mod + mod) % mod)
			{
				b[i + mod2] = true;
			}
		}
		auto p = new Point [n];
		foreach (ref c; p)
		{
			readf (" %s %s", &c.x, &c.y);
		}
		auto q = new Point [n];
		foreach (i; 0..n)
		{
			foreach (j; i + 1..n)
			{
				p[j].x -= p[i].x;
				p[j].y -= p[i].y;
				q[j].x = (p[j].x % mod + mod) % mod;
				q[j].y = (p[j].y % mod + mod) % mod;
			}
			foreach (j; i + 1..n)
			{
				int qjx = q[j].x;
				int qjy = q[j].y;
				int k;
				enum span = 4;
				for (k = j + 1; k + span <= n; k += span)
				{
					bool ok = false;
					static foreach (r; 0..span)
					{{
						auto t = qjx * q[k + r].y -
						    qjy * q[k + r].x;
						ok |= b[t + mod2];
					}}
					if (!ok)
					{
						continue;
					}
					foreach (r; 0..span)
					{{
						auto t = cast (long) (p[j].x) *
						    p[k + r].y -
						    cast (long) (p[k + r].x) *
						    p[j].y;
						if (t == +s || t == -s)
						{
							writeln ("Yes");
							writeln (p[i].x, " ", p[i].y);
							writeln (p[j].x + p[i].x, " ",
							    p[j].y + p[i].y);
							writeln (p[k + r].x + p[i].x, " ",
							    p[k + r].y + p[i].y);
							continue multitest_loop;
						}
					}}
				}
				for ( ; k < n; k++)
				{
					auto t = cast (long) (p[j].x) *
					    p[k].y -
					    cast (long) (p[k].x) *
					    p[j].y;
					if (t == +s || t == -s)
					{
						writeln ("Yes");
						writeln (p[i].x, " ", p[i].y);
						writeln (p[j].x + p[i].x, " ",
						    p[j].y + p[i].y);
						writeln (p[k].x + p[i].x, " ",
						    p[k].y + p[i].y);
						continue multitest_loop;
					}
				}
			}
			foreach (j; i + 1..n)
			{
				p[j].x += p[i].x;
				p[j].y += p[i].y;
			}
		}
		writeln ("No");
	}
}

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

alias Point = Tuple !(int, q{x}, int, q{y});

void main ()
{
	int n;
	long s;
multitest_loop:
	while (readf (" %s %s", &n, &s) > 0)
	{
		s *= 2;
		int sp = cast (int) (s);
		int sn = -sp;
		auto p = new Point [n];
		foreach (ref c; p)
		{
			readf (" %s %s", &c.x, &c.y);
		}
		foreach (i; 0..n)
		{
			foreach (j; i + 1..n)
			{
				p[j].x -= p[i].x;
				p[j].y -= p[i].y;
			}
			foreach (j; i + 1..n)
			{
				int pjx = p[j].x;
				int pjy = p[j].y;
				int v;
				bool ok = false;
				enum span = 4;
				for (v = j + 1; v + span <= n; v += span)
				{
					static foreach (r; 0..span)
					{{
						auto t = pjx * p[v + r].y -
						    pjy * p[v + r].x;
						ok |= (t == sp) || (t == sn);
					}}
				}
				for ( ; v < n; v++)
				{
					auto t = pjx * p[v].y - pjy * p[v].x;
					ok |= (t == sp || t == sn);
				}
				if (!ok)
				{
					continue;
				}
				foreach (k; j + 1..n)
				{
					auto t = cast (long) (p[j].x) *
					    p[k].y -
					    cast (long) (p[k].x) *
					    p[j].y;
					if (t == +s || t == -s)
					{
						writeln ("Yes");
						writeln (p[i].x, " ", p[i].y);
						writeln (p[j].x + p[i].x, " ",
						    p[j].y + p[i].y);
						writeln (p[k].x + p[i].x, " ",
						    p[k].y + p[i].y);
						continue multitest_loop;
					}
				}
//				assert (false);
			}
			foreach (j; i + 1..n)
			{
				p[j].x += p[i].x;
				p[j].y += p[i].y;
			}
		}
		writeln ("No");
	}
}

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

alias Point = Tuple !(int, q{x}, int, q{y});

immutable int mod = 44_221;
immutable int mod2 = mod ^^ 2;

void main ()
{
	int n;
	long s;
multitest_loop:
	while (readf (" %s %s", &n, &s) > 0)
	{
		s *= 2;
		int sp = cast (int) (s);
		int sn = -sp;
		sp = (sp % mod2 + mod2) % mod2;
		sn = (sn % mod2 + mod2) % mod2;
		int msp = -sp;
		int msn = -sn;
		auto q = new Point [n];
		foreach (ref c; q)
		{
			readf (" %s %s", &c.x, &c.y);
		}
		auto p = new Point [n];
		foreach (i; 0..n)
		{
			foreach (j; i + 1..n)
			{
				p[j].x = ((q[j].x - q[i].x) % mod + mod) % mod;
				p[j].y = ((q[j].y - q[i].y) % mod + mod) % mod;
			}
			foreach (j; i + 1..n)
			{
				int pjx = p[j].x;
				int pjy = p[j].y;
				int v;
				bool ok = false;
				enum span = 4;
				for (v = j + 1; v + span <= n; v += span)
				{
					static foreach (r; 0..span)
					{{
						auto t = pjx * p[v + r].y -
						    pjy * p[v + r].x;
						ok |= (t == sp) || (t == sn) ||
						    (-t == sp) || (-t == sn);
					}}
				}
				for ( ; v < n; v++)
				{
					auto t = pjx * p[v].y - pjy * p[v].x;
					ok |= (t == sp) || (t == sn) ||
					    (-t == sp) || (-t == sn);
				}
				if (!ok)
				{
					continue;
				}
				foreach (k; j + 1..n)
				{
					auto t = cast (long) (q[j].x) *
					    q[k].y -
					    cast (long) (q[k].x) *
					    q[j].y;
					if (t == +s || t == -s)
					{
						writeln ("Yes");
						writeln (q[i].x, " ", q[i].y);
						writeln (q[j].x + q[i].x, " ",
						    q[j].y + q[i].y);
						writeln (q[k].x + q[i].x, " ",
						    q[k].y + q[i].y);
						continue multitest_loop;
					}
				}
//				assert (false);
			}
			foreach (j; i + 1..n)
			{
				p[j].x += p[i].x;
				p[j].y += p[i].y;
			}
		}
		writeln ("No");
	}
}

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

alias Point = Tuple !(int, q{x}, int, q{y});

immutable int mod = 31627;
immutable int mod2 = mod ^^ 2;
immutable int mod2x2 = mod2 * 2;

void main ()
{
	int n;
	long s;
multitest_loop:
	while (readf (" %s %s", &n, &s) > 0)
	{
		s *= 2;
		int sp = (+s % mod2x2 + 1L * mod2x2) % mod2x2;
		int sn = (-s % mod2x2 + 1L * mod2x2) % mod2x2;
		auto p = new Point [n];
		foreach (ref c; p)
		{
			readf (" %s %s", &c.x, &c.y);
		}
		auto q = new Point [n];
		foreach (i; 0..n)
		{
			foreach (j; i + 1..n)
			{
				p[j].x -= p[i].x;
				p[j].y -= p[i].y;
				q[j].x = (p[j].x % mod + mod) % mod;
				q[j].y = (p[j].y % mod + mod) % mod;
			}
			foreach (j; i + 1..n)
			{
				int qjx = q[j].x;
				int qjy = q[j].y;
				int v;
				bool ok = false;
				enum span = 8;
				for (v = j + 1; v + span <= n; v += span)
				{
					static foreach (r; 0..span)
					{{
						auto t = qjx * q[v + r].y -
						    qjy * q[v + r].x;
						ok |= (t == sp) || (t == sn) ||
						    (-t == sp) || (-t == sn);
					}}
				}
				for ( ; v < n; v++)
				{
					auto t = qjx * q[v].y - qjy * q[v].x;
					ok |= (t == sp) || (t == sn) ||
					    (-t == sp) || (-t == sn);
				}
				if (!ok)
				{
					continue;
				}
				foreach (k; j + 1..n)
				{
					auto t = cast (long) (p[j].x) *
					    p[k].y -
					    cast (long) (p[k].x) *
					    p[j].y;
					if (t == +s || t == -s)
					{
						writeln ("Yes");
						writeln (p[i].x, " ", p[i].y);
						writeln (p[j].x + p[i].x, " ",
						    p[j].y + p[i].y);
						writeln (p[k].x + p[i].x, " ",
						    p[k].y + p[i].y);
						continue multitest_loop;
					}
				}
//				assert (false);
			}
			foreach (j; i + 1..n)
			{
				p[j].x += p[i].x;
				p[j].y += p[i].y;
			}
		}
		writeln ("No");
	}
}

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

alias Point = Tuple !(int, q{x}, int, q{y});

immutable int mod = 31627;
immutable int mod2 = mod ^^ 2;

void main ()
{
	int n;
	long s;
multitest_loop:
	while (readf (" %s %s", &n, &s) > 0)
	{
		s *= 2;
		int sp = cast (int) (s);
		int sn = -sp;
		sp = (sp % mod2 + mod2) % mod2;
		sn = (sn % mod2 + mod2) % mod2;
		int msp = -sp;
		int msn = -sn;
		auto q = new Point [n];
		foreach (ref c; q)
		{
			readf (" %s %s", &c.x, &c.y);
		}
		auto p = new Point [n];
		foreach (i; 0..n)
		{
			foreach (j; i + 1..n)
			{
				q[j].x -= q[i].x;
				q[j].y -= q[i].y;
				p[j].x = (q[j].x % mod + mod) % mod;
				p[j].y = (q[j].y % mod + mod) % mod;
			}
			foreach (j; i + 1..n)
			{
				int pjx = p[j].x;
				int pjy = p[j].y;
				int v;
				bool ok = false;
				enum span = 4;
				for (v = j + 1; v + span <= n; v += span)
				{
					static foreach (r; 0..span)
					{{
						auto t = pjx * p[v + r].y -
						    pjy * p[v + r].x;
						ok |= (t == sp) || (t == sn) ||
						    (-t == sp) || (-t == sn);
					}}
				}
				for ( ; v < n; v++)
				{
					auto t = pjx * p[v].y - pjy * p[v].x;
					ok |= (t == sp) || (t == sn) ||
					    (-t == sp) || (-t == sn);
				}
				if (!ok)
				{
					continue;
				}
				foreach (k; j + 1..n)
				{
					auto t = cast (long) (q[j].x) *
					    q[k].y -
					    cast (long) (q[k].x) *
					    q[j].y;
					if (t == +s || t == -s)
					{
						writeln ("Yes");
						writeln (q[i].x, " ", q[i].y);
						writeln (q[j].x + q[i].x, " ",
						    q[j].y + q[i].y);
						writeln (q[k].x + q[i].x, " ",
						    q[k].y + q[i].y);
						continue multitest_loop;
					}
				}
//				assert (false);
			}
			foreach (j; i + 1..n)
			{
				q[j].x += q[i].x;
				q[j].y += q[i].y;
			}
		}
		writeln ("No");
	}
}

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

alias Point = Tuple !(int, q{x}, int, q{y});

immutable int mod = 31627;
immutable int mod2 = mod ^^ 2 * 2;

void main ()
{
	int n;
	long s;
multitest_loop:
	while (readf (" %s %s", &n, &s) > 0)
	{
		s *= 2;
		int sp = (+s % mod2 + mod2) % mod2;
		int sn = (-s % mod2 + mod2) % mod2;
		auto q = new Point [n];
		foreach (ref c; q)
		{
			readf (" %s %s", &c.x, &c.y);
		}
		auto p = new Point [n];
		foreach (i; 0..n)
		{
			foreach (j; i + 1..n)
			{
				q[j].x -= q[i].x;
				q[j].y -= q[i].y;
				p[j].x = (q[j].x % mod + mod) % mod;
				p[j].y = (q[j].y % mod + mod) % mod;
			}
			foreach (j; i + 1..n)
			{
				int pjx = p[j].x;
				int pjy = p[j].y;
				int v;
				bool ok = false;
				enum span = 4;
				for (v = j + 1; v + span <= n; v += span)
				{
					static foreach (r; 0..span)
					{{
						auto t = pjx * p[v + r].y -
						    pjy * p[v + r].x;
						ok |= (t == sp) || (t == sn) ||
						    (-t == sp) || (-t == sn);
					}}
				}
				for ( ; v < n; v++)
				{
					auto t = pjx * p[v].y - pjy * p[v].x;
					ok |= (t == sp) || (t == sn) ||
					    (-t == sp) || (-t == sn);
				}
				if (!ok)
				{
					continue;
				}
				foreach (k; j + 1..n)
				{
					auto t = cast (long) (q[j].x) *
					    q[k].y -
					    cast (long) (q[k].x) *
					    q[j].y;
					if (t == +s || t == -s)
					{
						writeln ("Yes");
						writeln (q[i].x, " ", q[i].y);
						writeln (q[j].x + q[i].x, " ",
						    q[j].y + q[i].y);
						writeln (q[k].x + q[i].x, " ",
						    q[k].y + q[i].y);
						continue multitest_loop;
					}
				}
//				assert (false);
			}
			foreach (j; i + 1..n)
			{
				q[j].x += q[i].x;
				q[j].y += q[i].y;
			}
		}
		writeln ("No");
	}
}

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

alias Point = Tuple !(int, q{x}, int, q{y});

immutable int mod = 31627;
immutable int mod2 = mod ^^ 2 * 2;

void main ()
{
	int n;
	long s;
multitest_loop:
	while (readf (" %s %s", &n, &s) > 0)
	{
		s *= 2;
		int sp = cast (int) (s);
		int sn = -sp;
		sp = (sp % mod2 + mod2) % mod2;
		sn = (sn % mod2 + mod2) % mod2;
		int msp = -sp;
		int msn = -sn;
		auto q = new Point [n];
		foreach (ref c; q)
		{
			readf (" %s %s", &c.x, &c.y);
		}
		auto p = new Point [n];
		foreach (i; 0..n)
		{
			foreach (j; i + 1..n)
			{
				q[j].x -= q[i].x;
				q[j].y -= q[i].y;
				p[j].x = (q[j].x % mod + mod) % mod;
				p[j].y = (q[j].y % mod + mod) % mod;
			}
			foreach (j; i + 1..n)
			{
				int pjx = p[j].x;
				int pjy = p[j].y;
				int v;
				bool ok = false;
				enum span = 4;
				for (v = j + 1; v + span <= n; v += span)
				{
					static foreach (r; 0..span)
					{{
						auto t = pjx * p[v + r].y -
						    pjy * p[v + r].x;
						ok |= (t == sp) || (t == sn) ||
						    (-t == sp) || (-t == sn);
					}}
				}
				for ( ; v < n; v++)
				{
					auto t = pjx * p[v].y - pjy * p[v].x;
					ok |= (t == sp) || (t == sn) ||
					    (-t == sp) || (-t == sn);
				}
				if (!ok)
				{
					continue;
				}
				foreach (k; j + 1..n)
				{
					auto t = cast (long) (q[j].x) *
					    q[k].y -
					    cast (long) (q[k].x) *
					    q[j].y;
					if (t == +s || t == -s)
					{
						writeln ("Yes");
						writeln (q[i].x, " ", q[i].y);
						writeln (q[j].x + q[i].x, " ",
						    q[j].y + q[i].y);
						writeln (q[k].x + q[i].x, " ",
						    q[k].y + q[i].y);
						continue multitest_loop;
					}
				}
//				assert (false);
			}
			foreach (j; i + 1..n)
			{
				q[j].x += q[i].x;
				q[j].y += q[i].y;
			}
		}
		writeln ("No");
	}
}

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

alias Point = Tuple !(int, q{x}, int, q{y});

immutable int mod = 44_221;
immutable int mod2 = mod ^^ 2;

void main ()
{
	int n;
	long s;
multitest_loop:
	while (readf (" %s %s", &n, &s) > 0)
	{
		s *= 2;
		int sp = cast (int) (s);
		int sn = -sp;
		sp = (sp % mod2 + mod2) % mod2;
		sn = (sn % mod2 + mod2) % mod2;
		int msp = -sp;
		int msn = -sn;
		auto q = new Point [n];
		foreach (ref c; q)
		{
			readf (" %s %s", &c.x, &c.y);
		}
		auto p = new Point [n];
		foreach (i; 0..n)
		{
			foreach (j; i + 1..n)
			{
				q[j].x -= q[i].x;
				q[j].y -= q[i].y;
				p[j].x = (q[j].x % mod + mod) % mod;
				p[j].y = (q[j].y % mod + mod) % mod;
			}
			foreach (j; i + 1..n)
			{
				int pjx = p[j].x;
				int pjy = p[j].y;
				int v;
				bool ok = false;
				enum span = 4;
				for (v = j + 1; v + span <= n; v += span)
				{
					static foreach (r; 0..span)
					{{
						auto t = pjx * p[v + r].y -
						    pjy * p[v + r].x;
						ok |= (t == sp) || (t == sn) ||
						    (-t == sp) || (-t == sn);
					}}
				}
				for ( ; v < n; v++)
				{
					auto t = pjx * p[v].y - pjy * p[v].x;
					ok |= (t == sp) || (t == sn) ||
					    (-t == sp) || (-t == sn);
				}
				if (!ok)
				{
					continue;
				}
				foreach (k; j + 1..n)
				{
					auto t = cast (long) (q[j].x) *
					    q[k].y -
					    cast (long) (q[k].x) *
					    q[j].y;
					if (t == +s || t == -s)
					{
						writeln ("Yes");
						writeln (q[i].x, " ", q[i].y);
						writeln (q[j].x + q[i].x, " ",
						    q[j].y + q[i].y);
						writeln (q[k].x + q[i].x, " ",
						    q[k].y + q[i].y);
						continue multitest_loop;
					}
				}
//				assert (false);
			}
			foreach (j; i + 1..n)
			{
				q[j].x += q[i].x;
				q[j].y += q[i].y;
			}
		}
		writeln ("No");
	}
}


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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto q = RD!int;
	auto ans = new long[](q);
	foreach (i; 0..q)
	{
		auto n = RD!int;
		auto k = RD!int;
		auto a = RDR.ARR;
		a.sort();
		if (a[0] + k < a[$-1] - k)
		{
			ans[i] = -1;
		}
		else
		{
			ans[i] = a[0] + k;
		}
	}

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

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 INF = 1L << 59;

void main() {
    auto T = readln.chomp.to!int;
    while (T--) {
        auto s = readln.split.map!(to!int);
        auto N = s[0];
        auto K = s[1].to!long;
        auto A = readln.split.map!(to!long).array;
        long hi = INF;
        long lo = -INF;
        foreach (a; A) {
            hi = min(hi, a + K);
            lo = max(lo, a - K);
        }
        writeln(hi >= lo ? hi : -1);
    }
}

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

  int q;
  rd(q);
  while (q--) {
    int n, k;
    rd(n, k);
    auto a = readln.split.to!(int[]);
    a.sort;
    auto lb = a[n - 1] - k, ub = a[0] + k;
    if (lb <= ub) {
      writeln(ub);
    } else {
      writeln(-1);
    }
  }
}

// [a[n - 1] - k, a[0] + k]

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

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


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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new size_t[2][][](t);
	foreach (i; 0..t)
	{
		auto n = RD!int;
		auto K = RD!int;
		auto s = RD!(char[]);
		int cnt = n/2 - K;
		foreach (j; 0..cnt+1)
		{
			if (s[j] == '(') continue;
			foreach (k; j+1..n)
			{
				if (s[k] == ')') continue;
				auto d = k - j;
				ans[i] ~= [j, k];
				foreach (l; j..j+(d+1)/2)
				{
					auto r = k-(l-j);
					swap(s[l], s[r]);
				}
				break;
			}
		}
		foreach (j; cnt+1..(cnt+1)*2)
		{
			if (s[j] == ')') continue;
			foreach (k; j+1..n)
			{
				if (s[k] == '(') continue;
				auto d = k - j;
				ans[i] ~= [j, k];
				foreach (l; j..j+(d+1)/2)
				{
					auto r = k-(l-j);
					swap(s[l], s[r]);
				}
				break;
			}
		}
		foreach (j; (cnt+1)*2..n)
		{
			auto c = j % 2 == 0 ? '(' : ')';
			if (s[j] == c) continue;
			foreach (k; j+1..n)
			{
				if (s[k] != c) continue;
				auto d = k - j;
				ans[i] ~= [j, k];
				foreach (l; j..j+(d+1)/2)
				{
					auto r = k-(l-j);
					swap(s[l], s[r]);
				}
				break;
			}
		}
	}

	foreach (e; ans)
	{
		writeln(e.length);
		foreach (ee; e)
			writeln(ee[0]+1, " ", ee[1]+1);
	}

	stdout.flush();
	debug readln();
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.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();
        const K = readInt();
        const S = readToken();

        string t;
        foreach (_; 0 .. N / 2 - (K - 1)) t ~= '(';
        foreach (_; 0 .. N / 2 - (K - 1)) t ~= ')';
        foreach (_; 0 .. K - 1) t ~= "()";
        debug {
          writeln("t = ", t);
        }

        auto s = S.dup;
        writeln(N);
        foreach (i; 0 .. N) {
          foreach (j; i .. N) {
            if (s[j] == t[i]) {
              s[i .. j + 1].reverse;
              writeln(i + 1, " ", j + 1);
              goto found;
            }
          }
          assert(false);
         found:
        }
        assert(s == t);
      }
    }
  } 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.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; }

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

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

void main()
{
	auto t = RD!int;
	auto ans = new size_t[2][][](t);
	foreach (i; 0..t)
	{
		auto n = RD!int;
		auto K = RD!int;
		auto s = RD!(char[]);
		int cnt = n/2 - K;
		foreach (j; 0..cnt+1)
		{
			if (s[j] == '(') continue;
			foreach (k; j+1..n)
			{
				if (s[k] == ')') continue;
				auto d = k - j;
				foreach (l; j..j+(d+1)/2)
				{
					auto r = k-(l-j);
					swap(s[l], s[r]);
					ans[i] ~= [l, r];
				}
			}
		}
		foreach (j; cnt+1..(cnt+1)*2)
		{
			if (s[j] == ')') continue;
			foreach (k; j+1..n)
			{
				if (s[k] == '(') continue;
				auto d = k - j;
				foreach (l; j..j+(d+1)/2)
				{
					auto r = k-(l-j);
					swap(s[l], s[r]);
					ans[i] ~= [l, r];
				}
			}
		}
		foreach (j; (cnt+1)*2..n)
		{
			auto c = j % 2 == 0 ? '(' : ')';
			if (s[j] == c) continue;
			foreach (k; j+1..n)
			{
				if (s[k] != c) continue;
				auto d = k - j;
				foreach (l; j..j+(d+1)/2)
				{
					auto r = k-(l-j);
					swap(s[l], s[r]);
					ans[i] ~= [l, r];
				}
			}
		}
	}

	foreach (e; ans)
	{
		writeln(e.length);
		foreach (ee; e)
			writeln(ee[0]+1, " ", ee[1]+1);
	}

	stdout.flush();
	debug readln();
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.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; }

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

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

void main()
{
	auto t = RD!int;
	auto ans = new size_t[2][][](t);
	foreach (i; 0..t)
	{
		auto n = RD!int;
		auto K = RD!int;
		auto s = RD!(char[]);
		int cnt = n/2 - K;
		foreach (j; 0..cnt+1)
		{
			if (s[j] == '(') continue;
			foreach (k; j+1..n)
			{
				if (s[k] == ')') continue;
				auto d = k - j;
				ans[i] ~= [j, k];
				foreach (l; j..j+(d+1)/2)
				{
					auto r = k-(l-j);
					swap(s[l], s[r]);
				}
			}
		}
		foreach (j; cnt+1..(cnt+1)*2)
		{
			if (s[j] == ')') continue;
			foreach (k; j+1..n)
			{
				if (s[k] == '(') continue;
				auto d = k - j;
				ans[i] ~= [j, k];
				foreach (l; j..j+(d+1)/2)
				{
					auto r = k-(l-j);
					swap(s[l], s[r]);
				}
			}
		}
		foreach (j; (cnt+1)*2..n)
		{
			auto c = j % 2 == 0 ? '(' : ')';
			if (s[j] == c) continue;
			foreach (k; j+1..n)
			{
				if (s[k] != c) continue;
				auto d = k - j;
				ans[i] ~= [j, k];
				foreach (l; j..j+(d+1)/2)
				{
					auto r = k-(l-j);
					swap(s[l], s[r]);
				}
			}
		}
	}

	foreach (e; ans)
	{
		writeln(e.length);
		foreach (ee; e)
			writeln(ee[0]+1, " ", ee[1]+1);
	}

	stdout.flush();
	debug readln();
}


import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.math;
void main()
{
    auto st = readln()[].chomp;
    int n = to!int(st);

    foreach(int _; 0..n)
    {
        auto a = readln()[].chomp;
        auto b = readln()[].chomp;

        auto m = min(a.length, b.length);
        int res = a.length+b.length;
        bool match=true;

        for(int i = 0; i < a.length; i++)
        {
            for(int j = i; j < a.length; j++)
            {
                if (b.canFind(a[i..j+1]))
                {
                    res = min(res, abs(a.length-(j-i+1))+abs(b.length-(j-i+1)));
                }
            }
        }

        writeln(res);
    }
}

// Vicfred
// https://codeforces.com/contest/1506/problem/C
// brute force
import std.algorithm;
import std.stdio;

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

while(t--) {
    string a, b;
    readf("%s\n", &a);
    readf("%s\n", &b);

    int n = cast(int)a.length;
    int m = cast(int)b.length;

    int minima = min(n, m);

    int maxima = 0;
    for(int z = 1; z <= minima; z++) {
        for(int i = 0; i + z <= n; i++) {
            for(int j = 0; j + z <= m; j++) {
                if(a[i..i+z] == b[j..j+z])
                    maxima = max(maxima, z);
            }
        }
    }

    writefln("%s", n - maxima + m - maxima);
}
}

import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.functional;
void main()
{
    auto st = readln()[].chomp;
    int n = to!int(st);

    foreach(int _; 0..n)
    {
        auto a = readln()[].chomp;
        auto b = readln()[].chomp;

        auto m = min(a.length, b.length);
        int res = a.length+b.length;
        bool match=true;

        for(int i = 0; i < a.length; i++)
        {
            for(int j = i+1; j <= a.length; j++)
            {
                for(int k = 0; k < b.length; k++)
                {
                    if(k+(j-i) > b.length)
                        break;
                    int l = k+(j-i);
                    if(a[i..j].equal(b[k..l]))
                    {
                        int c = a.length - (j-i);
                        int d = b.length-(l-k);
                        res = min(res, c+d);
                    }
                }
            }
        }

        writeln(res);
    }
}

import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.functional;
void main()
{
    auto st = readln()[].chomp;
    int n = to!int(st);

    foreach(int _; 0..n)
    {
        auto a = readln()[].chomp;
        auto b = readln()[].chomp;

        auto m = min(a.length, b.length);
        int res = a.length+b.length;
        bool match=true;

        for(int i = 0; i < a.length; i++)
        {
            for(int j = i+1; j <= a.length; j++)
            {
                for(int k = 0; k < b.length; k++)
                {
                    for(int l = k+1; l <= b.length; l++)
                    {
                        if(a[i..j].equal(b[k..l]))
                        {
                            int c = a.length - (j-i);
                            int d = b.length-(l-k);
                            res = min(res, c+d);
                            break;
                        }
                    }

                }
            }
        }

        writeln(res);
    }
}

// Vicfred
// https://codeforces.com/contest/1506/problem/C
// brute force
import std.algorithm;
import std.stdio;

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

while(t--) {
    string a, b;
    readf("%s\n", &a);
    readf("%s\n", &b);

    int n = cast(int)a.length;
    int m = cast(int)b.length;

    int minima = min(n, m);

    int maxima = -1;
    for(int z = 1; z <= minima; ++z) {
        for(int i = 0; i + z <= n; ++i) {
            for(int j = 0; j + z <= m; ++j) {
                if(a[i..i+z] == b[j..j+z])
                    maxima = max(maxima, z);
            }
        }
    }

    writefln("%s", n - maxima + m - maxima);
}
}


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

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

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

    auto p = n - arr.find(m).length;

    debug { p.writeln; }

    int [bool][int] cnt;
    auto cur = 0, oddlen = false;
    long ans = 1L;
    foreach_reverse (i; 0 .. p) {
        oddlen ^= 1;
        cur = cur + (arr[i] > m ? 1 : -1);

        if (cur == 0 || (cur == 1 && oddlen)) ++ans;

        cnt[cur][oddlen] += 1;
    }

    cur = 0, oddlen = false;
    foreach (i; p+1 .. n) {
        oddlen ^= 1;
        cur = cur + (arr[i] > m ? 1 : -1);

        if (cur == 0 || (cur == 1 && oddlen)) ++ans;

        if (-cur in cnt) {
            ans += cnt[-cur].get(false, 0) + cnt[-cur].get(true, 0);
        }
        if ((-cur+1) in cnt) {
            ans += cnt[-cur+1].get(!oddlen, 0);
        }
    }

    ans.writeln;
}

import std.algorithm;
import std.container;
import std.conv;
import std.exception;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
    int n,m;
    readf!" %s %s "(n,m);
    auto p = readln.strip.split.map!(a => to!long(a)).array;

    int mi;
    foreach (i,v; p) {
        if (v == m) mi = to!int(i);
    }

    long[int] cnt1, cnt2;

    int x = 0, y = 0;
    for (int i = mi - 1; i >= 0; i--) {
        if (p[i] > m) x++;
        else y++;

        cnt1[x - y]++;
    }
    cnt1[0]++;

    x = 0, y = 0;
    for (int i = mi+1; i < n; i++) {
        if (p[i] > m) x++;
        else y++;

        cnt2[x - y]++;
    }

    long ans = 0;
    foreach (v,c; cnt1) {
        if (-v in cnt2)
            ans += c * cnt2[-v];
        if (-v+1 in cnt2)
            ans += c * cnt2[-v+1];
    }
    if (0 in cnt1)
        ans += cnt1[0];
    if (1 in cnt1)
        ans += cnt1[1];

    writeln(ans);
}

import std.algorithm;
import std.container;
import std.conv;
import std.exception;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
    int n,m;
    readf!" %s %s "(n,m);
    auto p = readln.strip.split.map!(a => to!long(a)).array;

    int mi;
    foreach (i,v; p) {
        if (v == m) mi = to!int(i);
    }

    int[long] cnt1, cnt2;

    long x = 0, y = 0;
    for (int i = mi - 1; i >= 0; i--) {
        if (p[i] > m) x++;
        else y++;

        cnt1[x - y]++;
    }
    cnt1[0]++;

    x = 0, y = 0;
    for (int i = mi+1; i < n; i++) {
        if (p[i] > m) x++;
        else y++;

        cnt2[x - y]++;
    }

    long ans = 0;
    foreach (v,c; cnt1) {
        if (-v in cnt2)
            ans += c * cnt2[-v];
        if (-v+1 in cnt2)
            ans += c * cnt2[-v+1];
    }
    if (0 in cnt1)
        ans += cnt1[0];
    if (1 in cnt1)
        ans += cnt1[1];

    writeln(ans);
}

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

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

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

    auto p = n - arr.find(m).length;

    debug { p.writeln; }

    int [bool][int] cnt;
    auto cur = 0, oddlen = false;
    auto ans = 1;
    foreach_reverse (i; 0 .. p) {
        oddlen ^= 1;
        cur = cur + (arr[i] > m ? 1 : -1);

        if (cur == 0 || (cur == 1 && oddlen)) ++ans;

        cnt[cur][oddlen] += 1;
    }

    cur = 0, oddlen = false;
    foreach (i; p+1 .. n) {
        oddlen ^= 1;
        cur = cur + (arr[i] > m ? 1 : -1);

        if (cur == 0 || (cur == 1 && oddlen)) ++ans;

        if (-cur in cnt) {
            ans += cnt[-cur].get(false, 0) + cnt[-cur].get(true, 0);
        }
        if ((-cur+1) in cnt) {
            ans += cnt[-cur+1].get(!oddlen, 0);
        }
    }

    ans.writeln;
}


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

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

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

    auto d = arr.map!(x => x % k).fold!(gcd)(k);

    if (d == 0) d = k;

    debug { d.writeln; }

    auto ans = iota(0, k, d);

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

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

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		a[] %= k;
		auto d = a.fold !(gcd) (k);
		d += !d * k;
		auto r = iota (0, k, d);
		writefln ("%s\n%(%s %)", r.walkLength, r);
	}
}

import std.algorithm, std.conv, std.numeric, std.range, std.stdio;
void main () {
	int n, k;
	readf (" %s %s ", &n, &k);
	int d = readln.split.map !(to!int).fold!gcd (k);
	d += !d * k;
	writefln ("%s\n%(%s %)", k / d, iota (0, k, d));
}

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

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto A = readln.split.map!(to!int).array;
    A = A.map!(a => a % K).array.sort().uniq().array;

    if (A.length == 1 && A[0] == 0) {
        writeln(1);
        writeln(0);
        return;
    }

    if (A[0] == 0) A.popFront;
    auto G = A.length > 1 ? A.reduce!gcd : A[0];
    G = gcd(G, K);

    int[] ans = [G];
    while (ans.front != (ans.back + G) % K) {
        ans ~= (ans.back + G) % K;
    }

    ans.sort();
    ans.length.writeln;
    foreach (a; ans) write(a, " ");
    writeln;
}

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

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		a[] %= k;
		auto d = a.reduce !(gcd);
		d += !d * k;
		auto r = iota (0, k, d);
		writefln ("%s\n%(%s %)", r.walkLength, r);
	}
}


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

void solve() {
    long N, K; readf("%d %d\n", &N, &K);
    auto A = readln.chomp.split(" ").map!(to!long).array;
    if (K >= N) {
        writeln(A.reduce!"a+b" + (K - N) * N + N * (N-1) / 2);
    } else {
        int k = cast(int)(K);
        long x = A[0 .. k].reduce!"a+b";
        long mx = x;
        for (int l = 0; l + k < N; l++) {
            int r = l + k;
            x = x - A[l] + A[r];
            mx = max(mx, x);
        }
        writeln(mx + K * (K-1) / 2);
    }
}

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

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto s = [0L];
		foreach (ref c; a)
		{
			s ~= s.back + c;
		}
		long res = 0;
		if (k >= n)
		{
			res = a.sum (0L);
			foreach (i; 0..n)
			{
				res += k - i - 1;
			}
		}
		else
		{
			res += zip (s, s.drop (k)).map !(q{a[1] - a[0]})
			    .maxElement;
			foreach (i; 0..k)
			{
				res += i;
			}
		}
		writeln (res);
	}
}

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;
        const K = readLong;
        auto A = new long[N];
        foreach (i; 0 .. N) {
          A[i] = readLong;
        }

        auto ASum = new long[N + 1];
        foreach (i; 0 .. N) {
          ASum[i + 1] = ASum[i] + A[i];
        }

        const k = min(K, N);
        long ans;
        foreach (i; 0 .. N - k + 1) {
          chmax(ans, ASum[cast(int)(i + k)] - ASum[cast(int)(i)]);
        }
        foreach (j; 0 .. k) {
          ans += (K - 1 - j);
        }
        writeln(ans);
      }
    }
  } 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 = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto n = RD!int;
	auto k = RD!int;
	auto p = RDA!int;

	long ans0;
	int[] pos;
	foreach (i; 0..n)
	{
		if (p[i] > n-k)
		{
			pos ~= i;
			ans0 += p[i];
		}
	}

	long ans = 1;
	foreach (i; 1..pos.length)
	{
		auto d = pos[i] - pos[i-1];
		ans.modm(d);
	}

	writeln(ans0, " ", ans);
	stdout.flush;
	debug readln;
}

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

immutable int mod = 998_244_353;

void main ()
{
	int n, k;
	while (readf !(" %s %s") (n, k) > 0)
	{
		readln;
		auto p = readln.splitter.map !(to !(int)).array;
		p[] -= 1;

		long best = k;
		int res = 1;
		int prev = -1;
		foreach (i, ref c; p)
		{
			if (c + k >= n)
			{
				best += c;
				if (prev >= 0)
				{
					res = (res * 1L * (i - prev)) % mod;
				}
				prev = i;
			}
		}

		writeln (best, " ", res);
	}
}

// Code By H~$~C

module main;

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

struct modular_int(uint M_) {
  alias M = M_;
  uint x;
  modular_int inv() const {
    uint a = M, b = x;
    long u = 0, v = 1;
    while (b) {
      uint t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    if (u < 0) u += M;
    return modular_int(u);
  }
  this(modular_int a) { x = a.x; }
  this(long a) { a %= M; if (a < 0) a += M; x = cast(int)a; }
  ref modular_int opAssign(long a) { return (this = modular_int(a)); }
  ref modular_int opOpAssign(string op)(modular_int a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x & (1U << 31)) x += M; }
    else static if (op == "*") { x = cast(uint)((cast(long)(x) * a.x) % M); }
    else static if (op == "/") { this *= a.inv(); }
    else static assert(false);
    return this;
  }
  ref modular_int opOpAssign(string op)(long a) {
    static if (op == "^^") {
      modular_int t2 = this, te = modular_int(1);
      if (a < 0) a = -a, t2 = t2.inv();
      for (long e = a; e; e >>= 1) {
        if (e & 1) te *= t2;
        t2 *= t2;
      }
      x = te.x;
      return this;
    }
    else return mixin("this " ~ op ~ "= modular_int(a)");
  }
  modular_int opUnary(string op)() const if (op == "-") {
    return modular_int(M - x);
  }
  modular_int opBinary(string op, T)(T a) const {
    return mixin("modular_int(this) " ~ op ~ "= a");
  }
  modular_int opBinaryRight(string op)(long a) const {
    return mixin("modular_int(a) " ~ op ~ "= this");
  }
  T to(T)() const {
    return x.to!T;
  }
}
alias modint = modular_int!998244353;

immutable Maxn = 200005;

int n, k;
int[Maxn] a;
long[Maxn] b;

// FIXME
void solve(in int testcase) {
  n.read, k.read;
  a[1 .. n + 1] = readarray!int.array;
  b[1 .. n + 1] = a[1 .. n + 1].map!(to!long).array.sort.array;
  b[n - k + 1 .. n + 1].sum.writef!"%s ";
  int q = cast(int)(b[n - k + 1]);
  int[] vec;
  foreach(i; 1 .. n + 1)
    if (a[i] >= q)
      vec ~= i;
  modint ans = 1;
  foreach(i; 0 .. vec.length - 1) {
    ans *= cast(long)(vec[i + 1] - vec[i]);
  }
  ans.to!int.writeln;
}

// ************************************************************

T reader(T)() { return readToken().to!T; }
void read(T)(ref T t) { t = reader!T; }
T[] readarray(T)() { return readln.splitter.map!(to!T).array; }
void chmax(T)(ref T a, T b) { a = max(a, b); }
void chmin(T)(ref T a, T b) { a = min(a, b); }
alias less = (a, b) => a < b;
alias greater = (a, b) => a > b;
T min_element(T)(in T[] a) { return a.element!less; }
T max_element(T)(in T[] a) { return a.element!greater; }
alias unique = uniq;
alias set = RedBlackTree;
alias Set = redBlackTree;

// constant or some variables
immutable int inf = 0x3f3f3f3f;
immutable long lnf = 0x3f3f3f3f3f3f3f3f;
immutable typeof(null) NULL = null;
string[] _tokens;

// functions
T element(alias pred, T)(in T[] a) {
  int pos = 0;
  for (int i = 1; i < cast(int)(a.length); ++i)
    if (binaryFun!pred(a[i], a[pos])) pos = i;
  return a[pos];
}
string readToken() {
  for (; _tokens.empty; ) {
    if (stdin.eof) return "";
    _tokens = readln.split;
  }
  auto token = _tokens.front;
  _tokens.popFront;
  return token;
}
int binary_bearch(alias pred, T)(in T[] as) {
  int l = -1, h = cast(int)(as.length), mid;
  for (; l + 1 < h; ) {
    mid = (l + h) >> 1;
    (unaryFun!pred(as[mid]) ? h : l) = mid;
  }
  return h;
}
int lower_bound(alias pred = less, T)(in T[] as, T val) {
  return as.binary_bearch!(a => a == val || pred(val, a));
}
int upper_bound(alias pred = less, T)(in T[] as, T val) {
  return as.binary_bearch!(a => pred(val, a));
}

void main(string[] args) {
  int tests = 1;
//  tests.read();
  foreach(test; 1 .. tests + 1) solve(test);
}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
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)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
    int n = scan!int, k = scan!int;
    int[] ps = scan!int(n);

    long[] us;
    long sum;
    foreach(i, p; ps){
        if(p >= n - k + 1) sum += p, us ~= i.to!long;
    }

    Finite.mod = 998_244_353;
    Finite ans = Finite(1);
    foreach(i; 0 .. us.length - 1){
        ans *= us[i + 1] - us[i];
    }
    print(sum, ans);

}

struct Finite{
	long value; static long mod = 1_000_000_007;
	this(long v){ value = val(v); }
	static long val(long v){ return (v + mod  - (v / mod) * mod) % mod; }
	bool opCast(T: bool)(){ return value != 0; }
	bool opEquals(Finite b){ return(value == b.value); }
	string toString(){ return value.to!string; }

	Finite opUnary(string s){ long v;
		if(s == "+") v = value;
		else if(s == "-") v = mod - value;
		else if(s == "++") v = value + 1;
		else if(s == "--") v = value + mod - 1;
		else assert(0, "Operator unary " ~ s ~ " not implemented");
		return Finite(v);
	}

	Finite opBinary(string s)(Finite b){ return opBinary!s(b.value); }
	Finite opBinary(string s)(long u){ long v;
		if(s == "+") v = value + u;
		else if(s == "-") v = value + mod - u;
		else if(s == "*") v = value * u;
		else if(s == "/") v = value * inv(u);
		else assert(0, "Operator " ~ s ~ " not implemented");
		return Finite(v);
	}
	Finite opBinaryRight(string s)(long u){ long v;
		if(s == "+") v = u + value;
		else if(s == "-") v = u + mod - value;
		else if(s == "*") v = u * value;
		else if(s == "/") v = u * invvalue;
		else assert(0, "Operator " ~ s ~ " not implemented");
		return Finite(v);
	}
	Finite opAssign(long v){ value = v; return this; }

	Finite opOpAssign(string s)(Finite b){ return opOpAssign!s(b.value); }
	Finite opOpAssign(string s)(long v){
		if(s == "+") value = (value + v) % mod;
		else if(s == "-") value = (value + mod - v) % mod;
		else if(s == "*") value = (value * v) % mod;
		else if(s == "/") value = (value * inv(v)) % mod;
		else assert(0, "Operator " ~ s ~ "= not implemented");
		return this;
	}

	private static long[] _inv = [0, 1];
	long invvalue(){ return inv(value); }
	long inv(long v){ int i = val(v).to!int;
		while(i >= _inv.length){
			_inv ~= _inv[(mod % $).to!int] * (mod - mod / _inv.length) % mod;
		}
		return _inv[i];
	}

}

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

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

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

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

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

enum MO = 998244353;
alias Mint = ModInt!MO;

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

      long ans0;
      foreach (k; 0 .. K) {
        ans0 += (N - k);
      }

      int[] xs;
      foreach (i; 0 .. N) {
        if (P[i] > N - K) {
          xs ~= i;
        }
      }
      Mint ans1 = 1;
      foreach (k; 0 .. K - 1) {
        ans1 *= (xs[k + 1] - xs[k]);
      }

      writeln(ans0, " ", ans1);
    }
  } catch (EOFException e) {
  }
}

// Code By H~$~C

module main;

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

struct modular_int(uint M_) {
  alias M = M_;
  uint x;
  modular_int inv() const {
    uint a = M, b = x;
    long u = 0, v = 1;
    while (b) {
      uint t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    if (u < 0) u += M;
    return modular_int(u);
  }
  this(modular_int a) { x = a.x; }
  this(long a) { a %= M; if (a < 0) a += M; x = cast(int)a; }
  ref modular_int opAssign(long a) { return (this = modular_int(a)); }
  ref modular_int opOpAssign(string op)(modular_int a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x & (1U << 31)) x += M; }
    else static if (op == "*") { x = cast(uint)((cast(long)(x) * a.x) % M); }
    else static if (op == "/") { this *= a.inv(); }
    else static assert(false);
    return this;
  }
  ref modular_int opOpAssign(string op)(long a) {
    static if (op == "^^") {
      modular_int t2 = this, te = modular_int(1);
      if (a < 0) a = -a, t2 = t2.inv();
      for (long e = a; e; e >>= 1) {
        if (e & 1) te *= t2;
        t2 *= t2;
      }
      x = te.x;
      return this;
    }
    else return mixin("this " ~ op ~ "= modular_int(a)");
  }
  modular_int opUnary(string op)() const if (op == "-") {
    return modular_int(M - x);
  }
  modular_int opBinary(string op, T)(T a) const {
    return mixin("modular_int(this) " ~ op ~ "= a");
  }
  modular_int opBinaryRight(string op)(long a) const {
    return mixin("modular_int(a) " ~ op ~ "= this");
  }
  T to(T)() const {
    return x.to!T;
  }
}
alias modint = modular_int!998244353;

immutable Maxn = 200005;

int n, k;
int[Maxn] a, b;

// FIXME
void solve(in int testcase) {
  n.read, k.read;
  a[1 .. n + 1] = readarray!int.array;
  b[1 .. n + 1] = a[1 .. n + 1].dup.sort.array;
  b[n - k + 1 .. n + 1].sum.writef!"%s ";
  int q = b[n - k + 1];
  int[] vec;
  foreach(i; 1 .. n + 1)
    if (a[i] >= q)
      vec ~= i;
  modint ans = 1;
  foreach(i; 0 .. vec.length - 1) {
    ans *= cast(long)(vec[i + 1] - vec[i]);
  }
  ans.to!int.writeln;
}

// ************************************************************

T reader(T)() { return readToken().to!T; }
void read(T)(ref T t) { t = reader!T; }
T[] readarray(T)() { return readln.splitter.map!(to!T).array; }
void chmax(T)(ref T a, T b) { a = max(a, b); }
void chmin(T)(ref T a, T b) { a = min(a, b); }
alias less = (a, b) => a < b;
alias greater = (a, b) => a > b;
T min_element(T)(in T[] a) { return a.element!less; }
T max_element(T)(in T[] a) { return a.element!greater; }
alias unique = uniq;
alias set = RedBlackTree;
alias Set = redBlackTree;

// constant or some variables
immutable int inf = 0x3f3f3f3f;
immutable long lnf = 0x3f3f3f3f3f3f3f3f;
immutable typeof(null) NULL = null;
string[] _tokens;

// functions
T element(alias pred, T)(in T[] a) {
  int pos = 0;
  for (int i = 1; i < cast(int)(a.length); ++i)
    if (binaryFun!pred(a[i], a[pos])) pos = i;
  return a[pos];
}
string readToken() {
  for (; _tokens.empty; ) {
    if (stdin.eof) return "";
    _tokens = readln.split;
  }
  auto token = _tokens.front;
  _tokens.popFront;
  return token;
}
int binary_bearch(alias pred, T)(in T[] as) {
  int l = -1, h = cast(int)(as.length), mid;
  for (; l + 1 < h; ) {
    mid = (l + h) >> 1;
    (unaryFun!pred(as[mid]) ? h : l) = mid;
  }
  return h;
}
int lower_bound(alias pred = less, T)(in T[] as, T val) {
  return as.binary_bearch!(a => a == val || pred(val, a));
}
int upper_bound(alias pred = less, T)(in T[] as, T val) {
  return as.binary_bearch!(a => pred(val, a));
}

void main(string[] args) {
  int tests = 1;
//  tests.read();
  foreach(test; 1 .. tests + 1) solve(test);
}