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 L = readInt;
        const M = readInt;
        auto A = new long[L];
        foreach (l; 0 .. L) {
          A[l] = readLong;
        }
        auto X = new long[M];
        auto Y = new long[M];
        foreach (i; 0 .. M) {
          X[i] = readLong;
          Y[i] = readLong;
        }

        auto as = A.dup;
        as = as.sort.uniq.array;
        const V = cast(int)(as.length);

        auto cnt = new int[V];
        foreach (l; 0 .. L) {
          ++cnt[as.lowerBound(A[l])];
        }
        auto uss = new int[][L + 1];
        foreach (u; 0 .. V) {
          uss[cnt[u]] ~= u;
        }
        foreach (k; 1 .. L + 1) if (!uss[k].empty) {
          uss[k].sort!((u, v) => (as[u] > as[v]));
        }

        auto graph = new int[][V];
        foreach (i; 0 .. M) {
          const u = as.lowerBound(X[i]);
          const v = as.lowerBound(Y[i]);
          graph[u] ~= v;
          graph[v] ~= u;
        }

        auto bad = new int[V];
        bad[] = -1;
        long ans;
        foreach (u; 0 .. V) {
          bad[u] = u;
          foreach (v; graph[u]) {
            bad[v] = u;
          }
          foreach (k; 1 .. cnt[u] + 1) {
            foreach (v; uss[k]) {
              if (bad[v] != u) {
                chmax(ans, 1L * (cnt[u] + cnt[v]) * (as[u] + as[v]));
                break;
              }
            }
          }
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}

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

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;

		alias Pair = Tuple !(int, q{x}, int, q{y});
		bool [Pair] bad;
		foreach (j; 0..m)
		{
			Pair p;
			readf !(" %s %s") (p.x, p.y);
			bad[p] = true;
			swap (p.x, p.y);
			bad[p] = true;
		}

		int [int] cnt;
		foreach (ref c; a)
		{
			cnt[c] += 1;
		}

		int [] [int] byCnt;
		foreach (k, v; cnt)
		{
			byCnt[v] ~= k;
		}

		foreach (line; byCnt)
		{
			sort (line);
		}

		long res = 0;
		foreach (k, _; cnt)
		{
			auto cntK = cnt[k];
			foreach (cnt2; 1..cntK + 1)
			{
				if (cnt2 !in byCnt)
				{
					continue;
				}
				foreach_reverse (elem; byCnt[cnt2])
				{
					if (k != elem &&
					   Pair (k, elem) !in bad)
					{
						res = max (res, (k + elem) *
						    1L * (cntK + cnt2));
						break;
					}
				}
			}
		}
		writeln (res);
	}
}

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

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;

		alias Pair = Tuple !(int, q{x}, int, q{y});
		bool [Pair] bad;
		foreach (j; 0..m)
		{
			Pair p;
			readf !(" %s %s") (p.x, p.y);
			bad[p] = true;
			swap (p.x, p.y);
			bad[p] = true;
		}

		int [int] cnt;
		foreach (ref c; a)
		{
			cnt[c] += 1;
		}

		int [] [int] byCnt;
		foreach (k, v; cnt)
		{
			byCnt[v] ~= k;
		}

		foreach (line; byCnt)
		{
			sort (line);
		}

		long res = 0;
		foreach (k, _; cnt)
		{
			auto cntK = cnt[k];
			foreach (curCnt, line; byCnt)
			{
				foreach_reverse (elem; line)
				{
					if (k != elem &&
					   Pair (k, elem) !in bad)
					{
						res = max (res, (k + elem) *
						    1L * (cntK + curCnt));
						break;
					}
				}
			}
		}
		writeln (res);
	}
}

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

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;

		alias Pair = Tuple !(int, q{x}, int, q{y});
		bool [Pair] bad;
		foreach (j; 0..m)
		{
			Pair p;
			readf !(" %s %s") (p.x, p.y);
			bad[p] = true;
			swap (p.x, p.y);
			bad[p] = true;
		}

		int [int] cnt;
		foreach (ref c; a)
		{
			cnt[c] += 1;
		}

		int [] [int] byCnt;
		foreach (k, v; cnt)
		{
			byCnt[v] ~= k;
		}

		foreach (line; byCnt)
		{
			sort (line);
		}

		long res = 0;
		foreach (k, _; cnt)
		{
			auto cntK = cnt[k];
			foreach (cnt2; 1..cntK + 1)
			{
				if (cnt2 !in cnt)
				{
					continue;
				}
				foreach_reverse (elem; byCnt[cnt2])
				{
					if (k != elem &&
					   Pair (k, elem) !in bad)
					{
						res = max (res, (k + elem) *
						    1L * (cntK + cnt2));
						break;
					}
				}
			}
		}
		writeln (res);
	}
}


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;
import core.bitop;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		alias Tuple !(int, "v", int, "d") pair;
		auto x = new pair [n];
		foreach (i; 0..n)
		{
			readf (" %s", &x[i].v);
			x[i].d = i + 1;
		}
		int k;
		readf (" %s", &k);
		x.sort !("a < b", SwapStrategy.stable);
		x ~= x[$ - 1];

		long s = 0;
		long cur = 0;
		foreach (i; 0..k)
		{
			s += x[i].v;
			cur += x[i].v * cast (long) (i + 1) - s;
		}

		long res = long.max;
		int st = int.min;
		foreach (i; k..n + 1)
		{
			debug {writefln ("i = %s, cur = %s, res = %s, s = %s",
			                 i, cur, res, s);}
			if (res > cur)
			{
				res = cur;
				st = i - k;
			}
			cur -= s - x[i - k].v * cast (long) k;
			s += x[i].v - x[i - k].v;
			cur += x[i].v * cast (long) k - s;
		}
		debug {writeln (res);}
		writefln ("%(%s %)", k.iota.map !(a => x[a + st].d).array);
	}
}

import std.algorithm;
import std.array;
import std.range;
import std.stdio;
import std.typecons;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		alias Tuple !(int, "v", int, "d") pair;
		auto x = new pair [n];
		foreach (i; 0..n)
		{
			readf (" %s", &x[i].v);
			x[i].d = i + 1;
		}
		int k;
		readf (" %s", &k);
		x.sort !("a < b", SwapStrategy.stable);
		x ~= x[$ - 1];

		long s = 0;
		long cur = 0;
		foreach (i; 0..k)
		{
			s += x[i].v;
			cur += x[i].v * cast (long) (i + 1) - s;
		}

		long res = long.max;
		int st = int.min;
		foreach (i; k..n + 1)
		{
			if (res > cur)
			{
				res = cur;
				st = i - k;
			}
			cur -= s - x[i - k].v * cast (long) k;
			s += x[i].v - x[i - k].v;
			cur += x[i].v * cast (long) k - s;
		}
		writefln ("%(%s %)", k.iota.map !(a => x[a + st].d).array);
	}
}

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;
import core.bitop;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto x = new int [n];
		foreach (i; 0..n)
		{
			readf (" %s", &x[i]);
		}
		int k;
		readf (" %s", &k);
		x.sort !("a < b", SwapStrategy.stable);
		x ~= x[$ - 1];

		long s = 0;
		long cur = 0;
		foreach (i; 0..k)
		{
			s += x[i];
			cur += x[i] * (i + 1) - s;
		}

		long res = long.max;
		int st = int.min;
		foreach (i; k..n + 1)
		{
			debug {writefln ("i = %s, cur = %s, res = %s, s = %s",
			                 i, cur, res, s);}
			if (res > cur)
			{
				res = cur;
				st = i - k + 1;
			}
			cur -= s - x[i - k] * k;
			s += x[i] - x[i - k];
			cur += x[i] * k - s;
		}
		debug {writeln (res);}
		writefln ("%(%s %)", k.iota.map !(a => a + st).array);
	}
}

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;
import core.bitop;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto x = new int [n];
		foreach (i; 0..n)
		{
			readf (" %s", &x[i]);
		}
		int k;
		readf (" %s", &k);
		x.sort !("a < b", SwapStrategy.stable);
		x ~= x[$ - 1];

		long s = 0;
		long cur = 0;
		foreach (i; 0..k)
		{
			s += x[i];
			cur += x[i] * (i + 1) - s;
		}

		long res = long.max;
		foreach (i; k..n + 1)
		{
			debug {writefln ("i = %s, cur = %s, res = %s, s = %s",
			                 i, cur, res, s);}
			res = min (res, cur);
			cur -= s - x[i - k] * k;
			s += x[i] - x[i - k];
			cur += x[i] * k - s;
		}
		writeln (res);
	}
}


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

string FMT_F = "%.10f";

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

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

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

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(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); }

T binarySearch(alias pred, T)(T ok, T ng)
{
	while (abs(ok-ng) > 1)
	{
		auto mid = (ok+ng)/2;
		if (unaryFun!pred(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

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

	bool f(int x)
	{
		{
			auto dp = new int[](n+2);
			auto begin = k % 2 ? 1 : 0;
			auto end   = n-1;
			foreach (i; begin..end)
			{
				if (a[i] <= x)
				{
					if (dp[i]+1 == k/2) return true;
					dp[i+2].chmax(dp[i]+1);
				}
				dp[i+1].chmax(dp[i]);
			}
		}
		{
			auto dp = new int[](n+2);
			auto begin = k % 2 ? 0 : 1;
			auto end   = n;
			foreach (i; begin..end)
			{
				if (a[i] <= x)
				{
					if (dp[i]+1 == (k+1)/2) return true;
					dp[i+2].chmax(dp[i]+1);
				}
				dp[i+1].chmax(dp[i]);
			}
		}
		return false;
	}

	auto ans = binarySearch!(f)(10^^9, 0);

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

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

alias A = Tuple!(int, "i", int, "a");

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    auto K = nk[1];

    int o_i, o_j, e_i, e_j;
    if (K%2 == 0) {
        o_i = 0;
        o_j = N-2;
        e_i = 1;
        e_j = N-1;
    } else {
        o_i = 0;
        o_j = N-1;
        e_i = 1;
        e_j = N-2;
    }

    int[] aa, bb;
    foreach (a; readln.split.to!(int[])) {
        aa ~= a;
        bb ~= a;
    }
    sort(bb);
    bb.uniq();
    int l = -1, r = N-1;
    while (l+1 < r) {
        auto m = (l+r)/2;
        auto a = bb[m];
        // odd
        {
            int i = o_i;
            int o;
            while (i <= o_j) {
                if (aa[i] <= a) {
                    ++o;
                    ++i;
                }
                ++i;
            }

            if (o >= (K+1)/2) {
                r = m;
                continue;
            }
        }
        // even
        {
            auto i = e_i;
            int e;
            while (i <= e_j) {
                if (aa[i] <= a) {
                    ++e;
                    ++i;
                }
                ++i;
            }

            if (e >= K/2) {
                r = m;
                continue;
            }
        }

        l = m;
    }
    writeln(bb[r]);
}

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

bool ok (int [] a, int me, int k)
{
	int pos = 0;
	foreach (ref c; a)
	{
		if ((pos & 1) || (c <= me))
		{
			pos += 1;
		}
	}
	return pos >= k;
}

int solveOdd (int [] a, int k)
{
	int lo = 0;
	int hi = 10 ^^ 9 + 1;
	while (lo < hi)
	{
		int me = (lo + hi) >> 1;
		if (ok (a, me, k))
		{
			hi = me;
		}
		else
		{
			lo = me + 1;
		}
	}
	return lo;
}

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

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

long x10(long mul, long exp)
{
  long res = 1;
  foreach(i; 0 .. exp)
    res *= 10;
  res *= mul;
  return res;
}

int maxPlace(int[] arr, int ub)
{
  int res = 0;
  for(int i = 0; i < arr.length; i++)
    {
      if (arr[i] <= ub)
        {
          res++;
          i++;
        }
    }
  return res;
}

int[2.x10(5)] A;

void main()
{
  static assert(int.max >= 2.x10(5));
  int n, k; read(n, k);
  auto a = A[0 .. n];
  read(a);
  bool function(int, int, int[]) can;
  if (k % 2 == 0)
    {
      can = (int ub, int k, int[] a)
        {
          return maxPlace(a[0 .. $ - 1], ub) >= k / 2 ||
          maxPlace(a[1 .. $], ub) >= k / 2;
        };
    }
  else
    {
      can = (int ub, int k, int[] a)
        {
          return maxPlace(a[0 .. $], ub) >= (k / 2 + 1) ||
          maxPlace(a[1 .. $ - 1], ub) >= k / 2;
        };
    }
  auto minres = cast(int) 1.x10(9);
  int hi = minres;
  int lo = 1;
  while(lo <= hi)
    {
      int mid = (lo + hi) / 2;
      if (can(mid, k, a))
        {
          minres = min(minres, mid);
          hi = mid - 1;
        }
      else
        {
          lo = mid + 1;
        }
    }
  minres.writeln;
}

alias seq = (x, y) => iota(x, y + 1);
alias writesp = (x) => write(x, " ");

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

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

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

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

long x10(long mul, long exp)
{
  long res = 1;
  foreach(i; 0 .. exp)
    res *= 10;
  res *= mul;
  return res;
}

int[2.x10(5)] A;

void main()
{
  static assert(int.max >= 2.x10(5));
  int n, k; read(n, k);
  auto a = A[0 .. n];
  read(a);
  int maxPlace(int[] arr, int ub)
  {
    int res = 0;
    for(int i = 0; i < arr.length; i++)
      {
        if (arr[i] <= ub)
          {
            res++;
            i++;
          }
      }
    return res;
  }
  bool delegate(int) can;
  if (k % 2 == 0)
    {
      can = (int ub)
        {
          return maxPlace(a[0 .. $ - 1], ub) >= k / 2 ||
          maxPlace(a[1 .. $], ub) >= k / 2;
        };
    }
  else
    {
      can = (int ub)
        {
          return maxPlace(a[0 .. $], ub) >= (k / 2 + 1) ||
          maxPlace(a[1 .. $ - 1], ub) >= k / 2;
        };
    }
  auto minres = cast(int) 1.x10(9);
  int hi = minres;
  int lo = 1;
  while(lo <= hi)
    {
      int mid = (lo + hi) / 2;
      if (can(mid))
        {
          minres = min(minres, mid);
          hi = mid - 1;
        }
      else
        {
          lo = mid + 1;
        }
    }
  minres.writeln;
}

alias seq = (x, y) => iota(x, y + 1);
alias writesp = (x) => write(x, " ");

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

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

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

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

alias A = Tuple!(int, "i", int, "a");

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    auto K = nk[1];

    int o_i, o_j, e_i, e_j;
    if (K%2 == 0) {
        o_i = 0;
        o_j = N-2;
        e_i = 1;
        e_j = N-1;
    } else {
        o_i = 0;
        o_j = N-1;
        e_i = 1;
        e_j = N-2;
    }

    int[] aa;
    auto AA = [A(-1, -1)];
    foreach (i, a; readln.split.to!(int[])) {
        aa ~= a;
        AA ~= A(i.to!int, a);
    }
    sort!"a.a < b.a"(AA);
    int l, r = N;
    while (l+1 < r) {
        auto m = (l+r)/2;
        auto k = AA[m].i;
        auto a = AA[m].a;

        auto i = k;
        auto j = k;
        // odd
        if (o_i <= k && k <= o_j) {
            int o = 1;
            while (i-1 >= o_i) {
                --i;
                if (aa[i] <= a) {
                    ++o;
                    --i;
                }
            }
            while (j+1 <= o_j) {
                ++j;
                if (aa[j] <= a) {
                    ++o;
                    ++j;
                }
            }

            if (o >= (K+1)/2) {
                r = m;
                continue;
            }
        }

        i = k;
        j = k;
        // even
        if (e_i <= k && k <= e_j) {
            int e = 1;
            while (i-1 >= e_i) {
                --i;
                if (aa[i] <= a) {
                    ++e;
                    --i;
                }
            }
            while (j+1 <= e_j) {
                ++j;
                if (aa[j] <= a) {
                    ++e;
                    ++j;
                }
            }

            if (e >= K/2) {
                r = m;
                continue;
            }
        }

        l = m;
    }

    writeln(AA[r].a);
}

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

T binarySearch(alias pred, T)(T ok, T ng)
{
	while (abs(ok-ng) > 1)
	{
		auto mid = (ok+ng)/2;
		if (unaryFun!pred(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

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

	bool f(int x)
	{
		auto dp = new int[](n+2);
		auto begin = k % 2 ? 1 : 0;
		foreach (i; begin..n)
		{
			if (a[i] <= x)
			{
				if (dp[i]+1 == k/2) return true;
				dp[i+2].chmax(dp[i]+1);
			}
			dp[i+1].chmax(dp[i]);
		}
		return false;
	}

	auto ans = binarySearch!(f)(10^^9, 0);

	writeln(ans);
	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, std.bitmanip;

immutable int INF = 1 << 29;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    long m = 0;

    foreach (i; 0..N) {
        if (A[i] > m) {
            writeln(i + 1);
            return;
        }
        if (A[i] == m) {
            m += 1;
        }
    }

    writeln(-1);
}

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

int solve (int [] a)
{
	int next = 0;
	foreach (pos, ref cur; a)
	{
		if (cur > next)
		{
			return pos + 1;
		}
		next = max (next, cur + 1);
	}
	return -1;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		writeln (solve (a));
	}
}

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

int solve (int [] a)
{
	int next = 0;
	foreach (pos, ref cur; a)
	{
		if (cur > next)
		{
			return pos;
		}
		next = max (next, cur + 1);
	}
	return -1;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		writeln (solve (a));
	}
}


import
		std.math,
		std.conv,
		std.file,
		std.range,
		std.array,
		std.stdio,
		std.string,
		std.bitmanip,
		std.typecons,
		std.algorithm;

void main()
{
	uint hh, mm, h, d, c, n;

	readf!`%d %d %d %d %d %d`(hh, mm, h, d, c, n);

	auto e = ceil(float(h) / n) * c;

	if(hh >= 20)
	{
		writeln(e * 0.8);
	}
	else
	{
		auto v = ceil(float((20 * 60 - hh * 60 - mm) * d + h) / n) * c * 0.8;

		min(e, v).writeln;
	}
}

import core.stdc.stdio;
import core.stdc.stdlib;
import std.algorithm;
void main()
{
	int n,m,a,b,c,d;
	scanf("%d%d",&n,&m);
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if (n>=20)
	{
		printf("%.5lf\n",((a-1)/d+1)*c*0.8);
		exit(0);
	}
	int dis=a+((60-m)+(19-n)*60)*b;
	printf("%.5lf\n",min(((dis-1)/d+1)*c*0.8,((a-1)/d+1)*c*1.0));
}

import
		std.math,
		std.conv,
		std.file,
		std.range,
		std.array,
		std.stdio,
		std.string,
		std.bitmanip,
		std.typecons,
		std.algorithm;

void main()
{
	uint hh, mm, h, d, c, n;

	readf!`%d %d %d %d %d %d`(hh, mm, h, d, c, n);

	auto e = ceil(double(h) / n) * c;

	if(hh >= 20)
	{
		writeln(e * 0.8);
	}
	else
	{
		auto v = ceil(double((20 * 60 - hh * 60 - mm) * d + h) / n * c * 0.8);

		min(e, v).writeln;
	}
}

import
		std.math,
		std.conv,
		std.file,
		std.range,
		std.array,
		std.stdio,
		std.string,
		std.bitmanip,
		std.typecons,
		std.algorithm;

void main()
{
	uint hh, mm, h, d, c, n;

	readf!`%d %d %d %d %d %d`(hh, mm, h, d, c, n);

	auto e = ceil(float(h) / n) * c;

	if(hh >= 20)
	{
		writeln(e * 0.8);
	}
	else
	{
		auto v = ceil(float((20 * 60 - hh * 60 - mm) * d + h) / n * c * 0.8);

		min(e, v).writeln;
	}
}


import std.algorithm;
import std.conv;
import std.stdio;

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		auto v = new int [] [m];
		foreach (i; 0..n)
		{
			int p, c;
			readf (" %s %s", &p, &c);
			p -= 1;
			v[p] ~= c;
		}

		foreach (j; 0..m)
		{
			sort !(q{a > b}) (v[j]);
		}

		long res = long.max;
		auto w = new int [n];
		for (int limit = 0; limit <= n; limit++)
		{
			long cur = 0;
			int votes = v[0].length.to !(int);
			int t = 0;
			foreach (j; 1..m)
			{
				foreach (k, c; v[j])
				{
					if (k < limit)
					{
						w[t] = c;
						t += 1;
					}
					else
					{
						cur += c;
						votes += 1;
					}
				}
			}

			sort (w[0..t]);
			int p = 0;
			while (votes <= limit && p < t)
			{
				cur += w[p];
				p += 1;
				votes += 1;
			}

			debug {writeln (limit, " ", votes, " ", cur);}
			if (votes > limit)
			{
				res = min (res, cur);
			}
		}

		writeln (res);
	}
}

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, m;
    readf("%s %s", &n, &m);
    readln;

    int partyvotes = 0;
    int[][int] votes;
    foreach (_; 0 .. n) {
        int p, c;
        readf("%s %s", &p, &c);
        readln;

        if (p == 1) partyvotes += 1;
        else votes[p] ~= c;
    }

    foreach (k, ref v; votes) sort(v);

    debug { votes.writeln; }

    auto ans = 3000L * 10 ^^ 9;
    foreach (x; partyvotes .. n+1) {
        auto curvotes = partyvotes;
        auto cursum = 0L;
        int[] cheap;
        foreach (k, v; votes) {
            auto need = max(0, cast(int)v.length - x + 1);

            debug { writeln(k, ' ', v, ' ', v.length, ' ', need); }

            curvotes += need;
            cursum += v.take(need).sum(0L);
            cheap ~= v.drop(need);
        }
        auto need = max(0, x - curvotes);
        curvotes = x;
        sort(cheap);
        cursum += cheap.take(need).sum(0L);

        debug { writeln(x, ' ', cursum); }

        ans = min(ans, cursum);
    }

    ans.writeln;
}

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

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto A = new Tuple!(int, long)[][](M);
    Tuple!(int, long)[] B;
    int cnt = 0;

    foreach (i; 0..N) {
        s = readln.split.map!(to!int);
        auto m = s[0];
        auto c = s[1].to!long;
        if (m == 1) {
            cnt += 1;
        } else {
            A[m-1] ~= tuple(i, c);
            B ~= tuple(i, c);
        }
    }

    foreach (i; 0..M) {
        A[i].sort!"a[1] < b[1]"();
    }
    B.sort!"a[1] < b[1]"();

    auto used = new bool[](N);
    long ans = 1L << 59;

    foreach (x; 0..N-cnt+1) {
        used.fill(false);
        int v = cnt + x;
        if (v == 0) continue;
        long tmp = 0;
        int tmpcnt = cnt;
        foreach (i; 0..M) {
            for (int j = 0; A[i].length.to!int - j >= v; ++j) {
                tmp += A[i][j][1];
                used[A[i][j][0]] = true;
                tmpcnt += 1;
            }
        }
        for (int i = 0; i < B.length.to!int && tmpcnt < v; ++i) {
            if (used[B[i][0]]) continue;
            tmp += B[i][1];
            tmpcnt += 1;
        }
        if (tmpcnt >= v)
            ans = min(ans, tmp);
    }

    ans.writeln;
}

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

enum INF = 10L^^18;

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

      auto css = new long[][M];
      foreach (i; 0 .. N) {
        css[P[i]] ~= C[i];
      }
      foreach (j; 0 .. M) {
        css[j].sort;
      }

      long ans = INF;
      foreach (k; 1 .. N + 1) {
        long cost;
        long[] cs;
        foreach (j; 1 .. M) {
          const len = cast(int)(css[j].length);
          const bribe = max(len - (k - 1), 0);
          foreach (x; 0 .. bribe) {
            cost += css[j][x];
          }
          foreach (x; bribe .. len) {
            cs ~= css[j][x];
          }
        }
        cs.sort;
        {
          const len = cast(int)(cs.length);
          const bribe = max(len - (N - k), 0);
          debug {
            writeln("  ", k, ": ", cs, " ", bribe);
          }
          foreach (x; 0 .. bribe) {
            cost += cs[x];
          }
        }
        debug {
          writeln(k, ": ", cost);
        }
        chmin(ans, cost);
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

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

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto A = new Tuple!(int, long)[][](M);
    auto B = new Tuple!(int, long)[](N);
    int cnt = 0;

    foreach (i; 0..N) {
        s = readln.split.map!(to!int);
        auto m = s[0];
        auto c = s[1].to!long;
        if (m == 1) {
            cnt += 1;
        } else {
            A[m-1] ~= tuple(i, c);
            B[i] = tuple(i, c);
        }
    }

    foreach (i; 0..M) {
        A[i].sort!"a[1] < b[1]"();
    }
    B.sort!"a[1] < b[1]"();
    auto used = new bool[](N);
    long ans = 1L << 59;

    foreach (x; 0..N-cnt+1) {
        int v = cnt + x;
        if (v == 0) continue;
        long tmp = 0;
        int tmpcnt = cnt;
        foreach (i; 0..M) {
            for (int j = 0; A[i].length.to!int - j >= v; ++j) {
                tmp += A[i][j][1];
                used[A[i][j][0]] = true;
                tmpcnt += 1;
            }
        }
        for (int i = 0; i < B.length.to!int && tmpcnt < v; ++i) {
            if (used[B[i][0]]) continue;
            tmp += B[i][1];
            tmpcnt += 1;
        }
        ans = min(ans, tmp);
        used.fill(false);
    }

    ans.writeln;
}

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

enum INF = 10L^^18;

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

      auto css = new long[][M];
      foreach (i; 0 .. N) {
        css[P[i]] ~= C[i];
      }
      foreach (j; 0 .. M) {
        css[j].sort;
      }

      long ans = INF;
      foreach (k; 1 .. N + 1) {
        long cost;
        long[] cs;
        foreach (j; 1 .. M) {
          const len = cast(int)(css[j].length);
          const bribe = max(len - (k - 1), 0);
          foreach (x; 0 .. bribe) {
            cost += css[j][x];
          }
          foreach (x; bribe .. len) {
            cs ~= css[j][x];
          }
        }
        {
          const len = cast(int)(cs.length);
          const bribe = max(len - (N - k), 0);
          foreach (x; 0 .. bribe) {
            cost += cs[x];
          }
        }
        debug {
          writeln(k, ": ", cost);
        }
        chmin(ans, cost);
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

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, m;
    readf("%s %s", &n, &m);
    readln;

    int partyvotes = 0;
    int[][int] votes;
    foreach (_; 0 .. n) {
        int p, c;
        readf("%s %s", &p, &c);
        readln;

        if (p == 1) partyvotes += 1;
        else votes[p] ~= c;
    }

    foreach (k, ref v; votes) sort(v);

    debug { votes.writeln; }

    auto ans = 3000L * 10 ^^ 9;
    foreach (x; partyvotes .. n+1) {
        auto curvotes = partyvotes;
        auto cursum = 0;
        int[] cheap;
        foreach (k, v; votes) {
            auto need = max(0, cast(int)v.length - x + 1);

            debug { writeln(k, ' ', v, ' ', v.length, ' ', need); }

            curvotes += need;
            cursum += v.take(need).sum(0L);
            cheap ~= v.drop(need);
        }
        auto need = max(0, x - curvotes);
        curvotes = x;
        sort(cheap);
        cursum += cheap.take(need).sum(0L);

        debug { writeln(x, ' ', cursum); }

        ans = min(ans, cursum);
    }

    ans.writeln;
}


// Vicfred
// https://codeforces.com/contest/1519/problem/B
// math
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

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

while(t--) {
    int n, m, k;
    readf("%s %s %s\n", &n, &m, &k);
    if(k == n * m - 1)
        "YES".writeln;
    else
        "NO".writeln;
}
}

import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.math;
import std.container.rbtree;
import std.range;

void main()
{
    auto l= to!long(readln().chomp);
    foreach(_; 0..l)
    {
        auto params = readln().chomp.splitter(" ").map!(to!long).array;
        long m = params[0];
        long n = params[1];
        long k = params[2];

        writeln(m*n-1 == k ? "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)); }
double[] rotate(double[] vec, double rad) { return [cos(rad) * vec[0] - sin(rad) * vec[1], sin(rad) * vec[0] + cos(rad) * vec[1]]; }

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

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

		long cnt = n-1;
		cnt += n * (m-1);
		ans[ti] = cnt == k;
	}

	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 n = RD!int;
	auto a = RDA;
	a.sort();

	auto ans = new long[](n);
	foreach (i; 0..n/2)
	{
		ans[i*2+1] = a.front; a.popFront;
	}
	foreach (i; n/2..n)
	{
		ans[(i-n/2)*2] = a.front; a.popFront;
	}

	long cnt;
	foreach (i; 1..n-1)
	{
		if (ans[i] < ans[i-1] && ans[i] < ans[i+1])
			++cnt;
	}

	writeln(cnt);
	ans.map!(to!string).join(" ").writeln;
	stdout.flush;
	debug readln;
}

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

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

void solve(){
    int n;
    n = rd!int;
    ll[] arr = rdarr;
    arr.sort();
    ll[] res = new ll[](n);
    foreach(i; 0..n/2){
        res[2*i + 1] = arr[i];
    }
    foreach(i;(n/2)..n){
        res[2*(i - n/2)] = arr[i];
    }
    ll num = 0;
    foreach(i; 1..n-1){
        if(res[i] < res[i-1] && res[i] < res[i+1]){
            ++num;
        }
    }
    writeln(num);
    foreach(el; res){
        write(el, " ");
    }
    writeln;
}

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

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

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(int[]);
    sort!"a > b"(AS);

    auto BS = new int[](N);
    int i, j;
    while (j < N) {
        BS[j] = AS[i];
        ++i;
        j += 2;
    }
    foreach (k; 0..N) if (BS[k] == 0) BS[k] = AS[i++];
    if (N%2 == 0) {
        int k = 1;
        while (k < N-1) {
            if (BS[k-1] > BS[k] && BS[k+1] > BS[k]) {
                k += 2;
                continue;
            }
            BS[$-1] = BS[k];
            BS[k] = AS[i-1];
            goto end;
        }
    }
    end:

    int r;
    foreach (k; 1..N-1) if (BS[k-1] > BS[k] && BS[k+1] > BS[k]) ++r;
    writeln(r);
    writeln(BS.to!(string[]).join(" "));
}


import std.stdio;
import std.math;
import std.algorithm;
/*
int myabs(int a) {
  if (a < 0) return -a;
  return a;
}
*/
void main() {
  int n;
  scanf("%d",&n);
  int[] a = new int[n];
  for (int i = 0 ; i < n ; ++i)
    scanf("%d",&a[i]);
  sort(a);
  ulong ans = 0;
  foreach (int idx, ele ; a) {
    ans += abs(idx-ele+1);
  }
  writef("%d\n", ans);
}

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

void main ()
{
	int n;
	while (scanf (" %d", &n) > 0)
	{
		auto a = new int [n];
		foreach (i; 0..n)
		{
			scanf (" %d", &a[i]);
		}
		sort (a);
		long res = 0;
		foreach (i; 0..n)
		{
			res += abs (i + 1 - a[i]);
		}
		writeln (res);
	}
}

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

void main ()
{
	int n;
	while (scanf (" %d", &n) > 0)
	{
		auto a = new int [n];
		foreach (i; 0..n)
		{
			scanf (" %d", &a[i]);
		}
		sort (a);
		long res = 0;
		foreach (i; 0..n)
		{
			res += abs (i + 1 - a[i]);
		}
		writeln (res);
	}
}

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

immutable int mod = 10^^9 + 7;

void main()
{
    auto n = readln.chomp.to!int;
    auto a = readln.split.to!(long[]);

    long ans;

    sort(a);

    foreach (i ; 0 .. n) {
        ans += abs(i + 1 - a[i]);
    }

    writeln(ans);
}

void readVars(T...)(auto ref T args)
{
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        writeln(line);
        throw new Exception("args num < input num");
    }
}

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

immutable int mod = 10^^9 + 7;

void main()
{
    auto n = readln.chomp.to!int;
    auto a = readln.split.to!(int[]);

    long ans;

    sort(a);

    foreach (i ; 0 .. n) {
        ans += abs(i + 1 - a[i]);
    }

    writeln(ans);
}

void readVars(T...)(auto ref T args)
{
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        writeln(line);
        throw new Exception("args num < input num");
    }
}

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

immutable int mod = 10^^9 + 7;

void main()
{
    auto n = readln.chomp.to!int;
    auto a = readln.split.to!(int[]);

    long ans;

    sort(a);

    foreach (i ; 0 .. n) {
        if(i + 1 > a[i]) {
            ans += i + 1 - a[i];
        }
        else {
            ans += a[i] - i - 1;
        }
    }

    writeln(ans);
}

void readVars(T...)(auto ref T args)
{
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        writeln(line);
        throw new Exception("args num < input num");
    }
}

module sigod.codeforces.p285C;

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

void main()
{
	int n;
	stdin.readf("%s", &n);

	stdin.readln();
	long[] a = read_array!(long)();

	sort(a);

	long result = 0;

	foreach (i, ai; a) {
		result += abs(ai - (i + 1));
	}

	stdout.writeln(result);
}

private
T[] read_array(T)()
{
	auto input = stdin.readln().strip().split();

	T[] result = new T[input.length];

	foreach (index, ref element; input) {
		result[index] = element.to!T();
	}

	return result;
}

import std.stdio;
import std.math;
import std.algorithm;
/*
int myabs(int a) {
  if (a < 0) return -a;
  return a;
}
*/
void main() {
  int n;
  scanf("%d",&n);
  int[] a = new int[n];
  for (int i = 0 ; i < n ; ++i)
    scanf("%d",&a[i]);
  sort(a);
  int ans = 0;
  foreach (int idx, ele ; a) {
    ans += abs(idx-ele+1);
  }
  writef("%d\n", ans);
}

import std.stdio;
import std.math;
import std.algorithm;
/*
int myabs(int a) {
  if (a < 0) return -a;
  return a;
}
*/
void main() {
  int n;
  scanf("%d",&n);
  int[] a = new int[n];
  for (int i = 0 ; i < n ; ++i)
    scanf("%d",&a[i]);
  sort(a);
  int ans = 0;
  foreach (int idx, ele ; a) {
    ans += abs(idx-ele+1);
  }
  printf("%d\n", ans);
}


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

// Main Logic Here
void play(){
    dchar[] word = rd!(dchar[]);
    ll bal0 = 0, bal1 = 0;
    ll pair0 = 0, pair1 = 0;
    foreach(cr; word){
        show(cr, pair0, pair1);
        if(cr == '('){
            ++bal0;
        }else if(cr == '['){
            ++bal1;
        }else if(cr == ')'){
            if(bal0 > 0) ++pair0;
            --bal0;
        }else if(cr==']'){
            if(bal1 > 0) ++pair1;
            --bal1;
        }
        bal0 = max(bal0, 0);
        bal1 = max(bal1, 0);
    }
    writeln(pair1 + pair0);
}

int main(){
    long t = 1;
    t = rd;        // Toggle for testcases!
    while(t--) play();  // Let's play!
    return 0;
}

/**********That's All Folks!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
static string[] inp;    // Read input
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }
alias ll = long;
alias tup = Tuple!(long, "x",  long, "y");
void show(A...)(A a) { debug{ foreach(t; a){ stderr.write(t, "| "); } stderr.writeln; } } // Debug
/* Add if TLE, T max(T = long)(T a, T b){ return (a > b) ? a : b; } */

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

auto go (string s, string c)
{
	char [] stack = "**".dup;
	foreach (ref e; s.filter !(e => c.canFind (e)))
	{
		stack.assumeSafeAppend ();
		stack ~= e;
		if (stack[$ - 2..$] == c)
		{
			stack.popBackN (2);
		}
	}
	return stack.length.to !(int) - 2;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip;
		writeln ((s.length - s.go ("()") - s.go ("[]")) / 2);
	}
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		long cnt1, cnt2;
		foreach (c; s)
		{
			if (c == ')')
			{
				if (cnt1 > 0)
				{
					--cnt1;
					++ans[ti];
				}
			}
			else if (c == '(')
			{
				++cnt1;
			}
			else if (c == ']')
			{
				if (cnt2 > 0)
				{
					--cnt2;
					++ans[ti];
				}
			}
			else
			{
				++cnt2;
			}
		}
	}

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

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

// Main Logic Here
void play(){
    dchar[] word = rd!(dchar[]);
    ll bal0 = 0, bal1 = 0;
    ll pair0 = 0, pair1 = 0;
    foreach(cr; word){
        show(cr, pair0, pair1);
        if(cr == '('){
            ++bal0;
        }else if(cr == '['){
            ++bal1;
        }else if(cr == ')'){
            if(bal0 > 0) ++pair0;
            --bal0;
        }else if(cr==']'){
            if(bal1 > 0) ++pair1;
            --bal1;
        }
    }
    writeln(pair1 + pair0);
}

int main(){
    long t = 1;
    t = rd;        // Toggle for testcases!
    while(t--) play();  // Let's play!
    return 0;
}

/**********That's All Folks!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
static string[] inp;    // Read input
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }
alias ll = long;
alias tup = Tuple!(long, "x",  long, "y");
void show(A...)(A a) { debug{ foreach(t; a){ stderr.write(t, "| "); } stderr.writeln; } } // Debug
/* Add if TLE, T max(T = long)(T a, T b){ return (a > b) ? a : b; } */


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

immutable int infinity = int.max / 4;
immutable int totalLevels = 9;
immutable int NA = -1;

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

		alias State = int [4];
		State [] states;
		int [State] stateNum;
		foreach (a; NA..totalLevels)
		{
			foreach (b; a..totalLevels)
			{
				foreach (c; b..totalLevels)
				{
					foreach (d; c..totalLevels)
					{
						State state = [a, b, c, d];
						do
						{
							stateNum[state] =
							    states.length
							    .to !(int);
						}
						while (nextPermutation
						    (state[]));
						states ~= state;
					}
				}
			}
		}
		immutable int totalStates = 715;
		assert (totalStates == states.length);

		auto f = new int [totalLevels] [] [] (n + 1, totalStates);
		foreach (i; 0..n + 1)
		{
			foreach (stateIndex; 0..totalStates)
			{
				f[i][stateIndex][] = infinity;
			}
		}
		f[0][0][0] = 0;

		int res = infinity;
		foreach (i; 0..n + 1)
		{
			foreach_reverse (stateIndex; 0..totalStates)
			{
				auto curState = states[stateIndex];
				foreach (level; 0..totalLevels)
				{
					auto cur = f[i][stateIndex][level];
					if (cur >= infinity)
					{
						continue;
					}
					foreach (j, v; curState)
					{
						if (v == NA)
						{
							continue;
						}
						auto nextValue = cur + abs
						    (level - v) + 1;
						auto nextState = curState;
						nextState[j] = NA;
						auto nextIndex =
						    stateNum[nextState];
						f[i][nextIndex][v] =
						    min (f[i][nextIndex][v],
						    nextValue);
					}

					if (i < n && curState[0] == NA)
					{
						auto u = src[i];
						auto nextValue = cur + abs
						    (level - u) + 1;
						auto nextState = curState;
						nextState[0] = dst[i];
						auto nextIndex =
						    stateNum[nextState];
						f[i + 1][nextIndex][u] =
						    min (f[i + 1][nextIndex]
						    [u], nextValue);
					}
				}
			}
		}

		writeln (minElement (f[n][0][]));
	}
}

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() {
    immutable int INF = 1 << 29;

    int[] unfold(int n) {
        return [n / 1000 % 10, n / 100 % 10, n / 10 % 10, n % 10];
    }

    int fold(int[] a) {
        int[] b = a.dup;
        b.sort!"a > b";
        return b[0] + b[1] * 10 + b[2] * 100 + b[3] * 1000;
    }

    auto N = readln.chomp.to!int;
    auto src = new int[](N);
    auto dst = new int[](N);
    foreach (i; 0..N) {
        auto s = readln.split.map!(to!int);
        src[i] = s[0];
        dst[i] = s[1];
    }

    auto dp = new int[][](N+1, 10000);
    foreach (i; 0..N+1) dp[i].fill(INF);
    dp[0][0] = 0;

    foreach (i; 0..N) {
        int cur = i == 0 ? 1 : src[i-1];
        int tar = src[i];
        foreach (a; 0..10) {
            foreach (b; a..10) {
                foreach (c; b..10) {
                    foreach (d; c..10) {
                        foreach (k; 1..10) {
                            if (dp[i][d + c*10 + b*100 + a*1000] >= INF) continue;
                            int hi = max(cur, tar, k);
                            int lo = min(cur, tar, k);
                            int[] v = [a, b, c, d];
                            int cost = 1;
                            foreach (j; 0..4) if (lo <= v[j] && v[j] <= hi) v[j] = 0, cost += 1;
                            int z = -1;
                            foreach (j; 0..4) if (v[j] == 0) z = j;
                            if (z == -1) continue;
                            v[z] = dst[i];
                            int dist = abs(cur - k) + abs(k - tar);
                            int fv = fold(v);
                            dp[i+1][fv] = min(dp[i+1][fv], dp[i][d + c*10 + b*100 + a*1000] + dist + cost);
                        }
                    }
                }
            }
        }
    }

    int ans = INF;

    foreach (a; 0..10) {
        foreach (b; a..10) {
            foreach (c; b..10) {
                foreach (d; c..10) {
                    int[] v = [a, b, c, d];
                    if (v.all!"a == 0") {
                        ans = min(ans, dp[N][0]);
                        continue;
                    }
                    int hi = (src.back, v.filter!"a != 0".reduce!max);
                    int lo = (src.back, v.filter!"a != 0".reduce!min);
                    int cost = (a != 0) + (b != 0) + (c != 0) + (d != 0);
                    int dist = min(abs(src.back - hi) + abs(hi - lo), abs(src.back - lo) + abs(lo - hi));
                    ans = min(ans, dp[N][fold([a, b, c, d])] + dist + cost);
                }
            }
        }
    }

    ans.writeln;
}

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() {
    immutable int INF = 1 << 29;

    int[] unfold(int n) {
        return [n / 1000 % 10, n / 100 % 10, n / 10 % 10, n % 10];
    }

    int fold(int[] a) {
        int[] b = a.dup;
        b.sort!"a > b";
        return b[0] + b[1] * 10 + b[2] * 100 + b[3] * 1000;
    }

    auto N = readln.chomp.to!int;
    auto src = new int[](N);
    auto dst = new int[](N);
    foreach (i; 0..N) {
        auto s = readln.split.map!(to!int);
        src[i] = s[0];
        dst[i] = s[1];
    }

    auto dp = new int[][](N+1, 10000);
    foreach (i; 0..N+1) dp[i].fill(INF);
    dp[0][0] = 0;

    foreach (i; 0..N) {
        int cur = i == 0 ? 1 : src[i-1];
        int tar = src[i];
        foreach (a; 0..10) {
            foreach (b; a..10) {
                foreach (c; b..10) {
                    foreach (d; c..10) {
                        foreach (k; 1..10) {
                            int[] v = [a, b, c, d];
                            int fv = fold(v);
                            if (dp[i][fv] >= INF) continue;
                            int hi = max(cur, tar, k);
                            int lo = min(cur, tar, k);
                            int cost = 1;
                            foreach (j; 0..4) if (lo <= v[j] && v[j] <= hi) v[j] = 0, cost += 1;
                            int z = -1;
                            foreach (j; 0..4) if (v[j] == 0) z = j;
                            if (z == -1) continue;
                            v[z] = dst[i];
                            int dist = abs(cur - k) + abs(k - tar);
                            dp[i+1][fv] = min(dp[i+1][fv], dp[i][d + c*10 + b*100 + a*1000] + dist + cost);
                        }
                    }
                }
            }
        }
    }

    int ans = INF;

    foreach (a; 0..10) {
        foreach (b; a..10) {
            foreach (c; b..10) {
                foreach (d; c..10) {
                    int[] v = [a, b, c, d];
                    if (v.all!"a == 0") {
                        ans = min(ans, dp[N][0]);
                        continue;
                    }
                    int hi = (src.back, v.filter!"a != 0".reduce!max);
                    int lo = (src.back, v.filter!"a != 0".reduce!min);
                    int cost = (a != 0) + (b != 0) + (c != 0) + (d != 0);
                    int dist = min(abs(src.back - hi) + abs(hi - lo), abs(src.back - lo) + abs(lo - hi));
                    ans = min(ans, dp[N][fold([a, b, c, d])] + dist + cost);
                }
            }
        }
    }

    ans.writeln;
}


import std.stdio;
import std.container;
import std.typecons;
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;
	int m = readInt!int;
	int x = readInt!int;
	auto h = new int[](n); foreach(ref hi; h) hi = readInt!int;
	auto queue = redBlackTree!(Tuple!(int, size_t))();
	auto cnt = new int[](m);
	auto bucket = new size_t[](n);
	bucket[] = -1;
	foreach(i, cnti; cnt) queue.insert(tuple(cnti, i));
	foreach(i, ref hi; h)
	{
		auto nextPlaceT = queue.front; queue.removeFront;
		auto nextBucket = nextPlaceT[1];
		bucket[i] = nextBucket + 1;
		cnt[nextPlaceT[1]] += hi;
		queue.insert(tuple(cnt[nextPlaceT[1]], nextPlaceT[1]));
	}
	"YES".writeln;
	foreach(bi; bucket) bi.write(" ");
	writeln;
}

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

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

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

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

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

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

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

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

import std.stdio, std.algorithm, std.typecons, std.container, std.range;

void main() {
  int t;
  readf!" %d"(t);

  while (t--) {
    writeln("YES");
    int n, m, x;
    readf!" %d %d %d\n"(n, m, x);

    auto heap = iota(m).map!"tuple(0L, a + 1)".array.heapify!"a > b";

    foreach (h; readln.split.map!"a.to!int") {
      auto tower = heap.front;
      tower[0] += h;
      write(tower[1], ' ');
      heap.replaceFront(tower);
    }
  }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, m, x;
		readf !(" %s %s %s") (n, m, x);
		readln;
		auto h = readln.splitter.map !(to !(int)).array;
		auto y = new int [m];
		auto t = redBlackTree !((i, j) => y[i] < y[j], true)
		    (m.iota.array);
		auto answer = new int [n];
		foreach (i, ref c; h)
		{
			auto p = t.front;
			t.removeFront ();
			y[p] += c;
			answer[i] = p + 1;
			t.insert (p);
		}
		writeln ("YES");
		writefln !("%(%s %)") (answer);
	}
}

import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.math;
import std.container.rbtree;
import std.range;
import std.container.binaryheap;
import std.typecons;

void main()
{
    auto t = to!long(readln().chomp);
    OUTER: foreach(_; 0..t)
    {
        auto params = readln().chomp.splitter(" ").map!(to!int).array;
        int n = params[0];
        int m = params[1];
        int x = params[2];

        auto arr = readln().chomp.splitter(" ").map!(to!long).array;

        int cur = 0;
        auto h = heapify!"a[0] > b[0]"([[0L, 1L]]);

        foreach(i; 2..m+1)
        {
            h.insert([0L, to!long(i)]);
        }

        foreach (int i; 0..n)
        {
            auto ar = h.front;
            h.removeFront();
            h.insert([arr[i]+ar[0], ar[1]]);
            arr[i] = ar[1];
        }

        writeln("YES");
        writeln(arr.map!(to!string).joiner(" "));
    }
}


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;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto TB = N.iota.map!(_ => readln.split.map!(to!long).array).array;
    TB.sort!"a[1] > b[1]";

    auto pq = new BinaryHeap!(Array!long, "a > b");
    long tmp = 0;
    long ans = 0;

    for (int i = 0; i < N; ) {
        long b = TB[i][1];
        while (i < N && TB[i][1] == b) {
            pq.insert(TB[i][0]);
            tmp += TB[i][0];
            if (pq.length > K) {
                tmp -= pq.front;
                pq.removeFront;
            }
            ++i;
        }
        ans = max(ans, tmp * b);
    }

    ans.writeln;
}

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

alias S = Tuple!(long, "t", long, "b");

S[10^^5*3] SS;

long[10^^5*3] MIN_P;

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    auto K = nk[1];

    foreach (i; 0..N) {
        auto tb = readln.split.to!(long[]);
        SS[i] = S(tb[0], tb[1]);
    }

    sort!"a.b > b.b"(SS[0..N]);

    long t, p, r;
    auto tree = redBlackTree!true(0L);
    foreach (i; 0..N) {
        if (!tree.front) tree.removeFront();
        t += SS[i].t;
        tree.insert(SS[i].t);
        if (tree.length > K) {
            t -= tree.front;
            tree.removeFront();
        }
        r = max(r, t * SS[i].b);
    }

    writeln(r);
}

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

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

void main() {
  auto r = new InputReader;
  immutable n = r.next!uint;
  immutable k = r.next!uint;
  auto a = uninitializedArray!(Tuple!(uint, uint)[]) (n);
  auto c = uninitializedArray!(uint[]) (n);
  foreach (i, ref p; a) {
    auto l = r.next!uint;
    auto b = r.next!uint;
    p = tuple (b, l);
    c[i] = l;
  }
  c.sort ();
  auto t1 = new RedBlackTree!(int, "a < b", true) ();
  auto t2 = new RedBlackTree!(int, "a < b", true) ();
  long s;
  foreach (i; 0 .. k) {
    t2.insert (c[n-1-i]);
    s += c[n-1-i];
  }
  foreach (i; k .. n) {
    t1.insert (c[n-1-i]);
  }
  a.sort ();
  debug stderr.writeln (a);
  debug stderr.writeln (c);

  long res = long.min;
  foreach (i; 0 .. n) {
    int x = a[i][0];
    res = max (res, x * s);
    //remove p[i][1]
    int w = a[i][1];
    auto e = t1.equalRange (w);
    if (e.empty) {
      s -= w;
      t2.removeKey (w);
      if (t1.empty) {
      } else {
        int v = t1.back;
        t1.removeBack ();
        t2.insert (v);
        s += v;
      }
    } else {
      t1.removeKey (w);
    }
  }
  writeln (res);
}

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;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto TB = N.iota.map!(_ => readln.split.map!(to!long).array).array;
    TB.sort!"a[1] > b[1]";

    auto pq = new BinaryHeap!(Array!long, "a < b");
    long tmp = 0;
    long ans = 0;

    for (int i = 0; i < N; ) {
        long b = TB[i][1];
        while (i < N && TB[i][1] == b) {
            pq.insert(TB[i][0]);
            tmp += TB[i][0];
            if (pq.length > K) {
                tmp -= pq.front;
                pq.removeFront;
            }
            ++i;
        }
        ans = max(ans, tmp * b);
    }

    ans.writeln;
}


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		alias Segment = Tuple !(int, q{len}, int, q{start});
		auto t = redBlackTree !(Segment);
		t.insert (Segment (-(n - 1), 0));
		auto a = new int [n];
		foreach (i; 0..n)
		{
			auto lo = t.front.start;
			auto hi = t.front.start - t.front.len;
			t.removeFront ();
			auto me = (lo + hi) / 2;
			a[me] = i + 1;
			t.insert (Segment (-(me - lo - 1), lo));
			t.insert (Segment (-(hi - me - 1), me + 1));
		}
		writefln !("%(%s %)") (a);
	}
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		BinaryHeap!(Array!(int[]), "a[1]-a[0] == b[1]-b[0] ? a[0] > b[0] : a[1]-a[0] < b[1]-b[0]") heap;
		heap.insert([0, n]);
		int i = 1;
		while (!heap.empty)
		{
			auto nd = heap.front; heap.popFront;
			auto l = nd[0];
			auto r = nd[1];
			auto m = (l+r-1)/2;
			ans[ti][m] = i;
			++i;
			if (r-l == 1) continue;
			else if (r-l == 2)
			{
				heap.insert([m+1, r]);
			}
			else
			{
				heap.insert([l, m]);
				heap.insert([m+1, r]);
			}
		}
	}

	foreach (e; ans)
		e.map!(to!string).join(" ").writeln;
	stdout.flush;
	debug readln;
}


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

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

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

    bool C(int k) {
        auto X = A.dup;
        sort!"a>b"(X);
        int i = 0, j = N;
        for (int t = k; t >= 1; t--) {
            while (i < j && X[i] > t) {
                i++;
            }
            if (i >= j) return false;
            i++;
            // turn of B
            j--;
        }
        return true;
    }

    for (int k = 1; ; k++) {
        if (! C(k)) {
            writeln(k - 1);
            return;
        }
    }

}

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

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

		bool ok (int k)
		{
			int cur = k;
			int pos = 0;
			for (int i = n - 1; i >= pos; i--)
			{
				if (i < pos)
				{
					break;
				}
				if (a[i] <= cur)
				{
					cur -= 1;
					pos += 1;
				}
			}
			return cur == 0;
		}

		int lo = 0;
		int hi = n + 1;
		while (hi - lo > 1)
		{
			int me = (lo + hi) / 2;
			if (ok (me))
			{
				lo = me;
			}
			else
			{
				hi = me;
			}
		}
		writeln (lo);
	}
}

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

// returns true if Alice wins
bool solve(int[] a, int k)
{
  foreach_reverse (i ; 1 .. k + 1) {
    // Alice turn
    while (a.length > 0 && a.back > i)
      a = a[0 .. $ - 1];
    if (a.empty)
      return false;
    a = a[0 .. $ - 1];
    if (a.length > 0)
      a = a[1 .. $];
  }
  return true;
}

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto n = readln.strip.to!int;
    auto a = readln.splitter.map!(to!int).array.sort.array;
    writeln(iota(0, n + 105).map!(k => !solve(a, k)).assumeSorted.lowerBound(true).length - 1);
  }
}

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

// returns tru if Alice wins
bool solve(int[] a, int k)
{
  foreach_reverse (i ; 1 .. k + 1) {
    // Alice turn
    while (a.length > 0 && a.back > k)
      a = a[0 .. $ - 1];
    if (a.empty)
      return false;
    a = a[0 .. $ - 1];
    // Bob turn
    if (a.length > 0)
      a = a[1 .. $];
  }
  return true;
}

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto n = readln.strip.to!int;
    auto a = readln.splitter.map!(to!int).array.sort.array;
    int k = 0;
    while (solve(a, k)) {
      k++;
    }
    writeln(k - 1);
  }
}

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

// returns tru if Alice wins
bool solve(int[] a, int k)
{
  foreach_reverse (i ; 1 .. k + 1) {
    // Alice turn
    while (a.length > 0 && a.back > k)
      a = a[0 .. $ - 1];
    if (a.empty)
      return false;
    a = a[0 .. $ - 1];
    if (a.length > 0)
      a = a[1 .. $];
  }
  return true;
}

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto n = readln.strip.to!int;
    auto a = readln.splitter.map!(to!int).array.sort.array;
    writeln(iota(0, n + 105).map!(k => !solve(a, k)).assumeSorted.lowerBound(true).length - 1);
  }
}

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

// returns tru if Alice wins
bool solve(int[] a, int k)
{
  foreach_reverse (i ; 1 .. k + 1) {
    while (a.length > 0 && a.back > k)
      a = a[0 .. $ - 1];
    if (a.empty)
      return false;
    a = a[0 .. $ - 1];
    if (a.length > 0)
      a = a[1 .. $];
  }
  return true;
}

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto n = readln.strip.to!int;
    auto a = readln.splitter.map!(to!int).array.sort.array;
    writeln(iota(1, n + 5).map!(k => !solve(a, k)).assumeSorted.lowerBound(true).length);
  }
}


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

struct IO {
        string[] tk;
        string readString() {
                while (tk.empty)
                        tk = readln.split;
                auto tkt = tk.front;
                tk.popFront;
                return tkt;
        }
        int readInt() {
                return readString.to!int;
        }
        double readDouble() {
                return readString.to!double;
        }
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.readInt;
        while (t--) {
                double l = cin.readDouble;
                double p = cin.readDouble;
                double q = cin.readDouble;
                writeln(p * (l / (p + q)));

        }
}

import std.stdio;
import std.string;
void main()
{
	double a,b,c;
	readf("%f\n%f\n%f\n",&a,&b,&c);
	writeln(a*b/(b+c));
}

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;
import core.bitop;

void main ()
{
    int l, p, q;
    while (readf (" %s %s %s", &l, &p, &q) > 0)
    {
        writeln (l * p * 1.0 / (p + q));
    }
}


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

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

void main() {
    int N = read!int;
    auto s = read!string;

    //auto rmlz() {
    {
        int k = 0;
        while (s[k] == '0' && k < N - 1) k++;
        s = s[k .. $];
    }
    N = cast(int)(s.length);

    int lo = 0;
    for (int i = 0; i < N; i++) {
        if (s[i] == '1') {
            lo++;
        } else {
            break;
        }
    }

    string f(string b) {
        char z(char x, char y) {
            if (x == '1' || y == '1') return '1';
            else return '0';
        }
        int m = cast(int)(b.length);
        auto r = new char[N];
        for (int i = 0; i < N; i++) {
            if (i < N - m) {
                r[i] = s[i] ;
            } else {
                r[i] = z(s[i], b[i - N + m]);
            }
        }
        return r.idup;
    }

    string ans = s;
    for (int k = 1; k <= lo; k++) {
        auto s2 = s[0 .. $ - k];
        auto cand = f(s2);
        ans = max(ans, cand);
    }

    writeln(ans);
}

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

int[] solve(int[] a, int[] n2)
{
  int[] offs;
  foreach (i ; 0 .. cast(int)n2.length)
    if (n2[i])
      offs ~= i;
  int best_i = -1, best_score = -1;
  foreach (i ; 0 .. cast(int)(a.length - n2.length + 1)) {
    int score = 0;
    foreach (j ; offs) {
      if (a[i + j] == 1)
        score++;
      else
        break;
    }
    if (score > best_score) {
      best_i = i;
      best_score = score;
    } else if (score == best_score) {
      bool better = false;
      foreach (j ; offs[score .. $]) {
        if (a[i + j] == a[best_i + j])
          continue;
        if (a[i + j] == 1)
          better = true;
        break;
      }
      if (better) {
        best_i = i;
        best_score = score;
      }
    }
  }
  return a[best_i .. best_i + n2.length];
}

void main()
{
  long n;
  readf!" %d "(n);
  auto a = readln.strip.splitter("").map!(to!int).array;
  auto n1 = a.find(1).array;
  auto n2 = n1.map!(x => x ^ 1).find(1).array;

  if (n1.empty) {
    writeln(0);
    return;
  }

  while (true) {
    if (n2.empty)
      break;
    auto tmp = solve(a, n2);
    if (tmp[0] == 0) {
      n2 = n2[1 .. $];
      while (!n2.empty && n2[0] == 0)
        n2 = n2[1 .. $];
    } else {
      foreach (i ; 0 .. tmp.length) {
        n1[$ - i - 1] |= tmp[$ - i - 1];
      }
      break;
    }
  }

  writeln(n1.map!text.joiner(""));
}

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

int[] solve(int[] a, int[] n2)
{
  int[] offs;
  foreach (i ; 0 .. cast(int)n2.length)
    if (n2[i])
      offs ~= i;
  int best_i = -1, best_score = -1;
  foreach (i ; 0 .. cast(int)(a.length - n2.length + 1)) {
    int score = 0;
    foreach (j ; offs) {
      if (a[i + j] == 1)
        score++;
      else
        break;
    }
    if (score > best_score) {
      best_i = i;
      best_score = score;
    }
  }
  return a[best_i .. best_i + n2.length];
}

void main()
{
  long n;
  readf!" %d "(n);
  auto a = readln.strip.splitter("").map!(to!int).array;
  auto n1 = a.find(1).array;
  auto n2 = n1.map!(x => x ^ 1).find(1).array;

  if (n1.empty) {
    writeln(0);
    return;
  }

  while (true) {
    if (n2.empty)
      break;
    auto tmp = solve(a, n2);
    if (tmp[0] == 0) {
      n2 = n2[1 .. $];
      while (!n2.empty && n2[0] == 0)
        n2 = n2[1 .. $];
    } else {
      foreach (i ; 0 .. tmp.length) {
        n1[$ - i - 1] |= tmp[$ - i - 1];
      }
      break;
    }
  }

  writeln(n1.map!text.joiner(""));
}

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

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

void main() {
    int N = read!int;
    auto s = read!string;

    int lo = 0;
    for (int i = 0; i < N; i++) {
        if (s[i] == '1') {
            lo++;
        } else {
            break;
        }
    }

    string f(string b) {
        char z(char x, char y) {
            if (x == '1' || y == '1') return '1';
            else return '0';
        }
        int m = cast(int)(b.length);
        auto r = new char[N];
        for (int i = 0; i < N; i++) {
            if (i < N - m) {
                r[i] = s[i] ;
            } else {
                r[i] = z(s[i], b[i - N + m]);
            }
        }
        return r.idup;
    }

    string ans = s;
    for (int k = 1; k <= lo; k++) {
        auto s2 = s[0 .. $ - k];
        auto cand = f(s2);
        ans = max(ans, cand);
    }
    writeln(ans);
}


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		long res = 0;
		foreach (i; 0..n)
		{
			auto lo = 0;
			if (i > 0)
			{
				lo = max (lo, a[i - 1]);
			}
			if (i + 1 < n)
			{
				lo = max (lo, a[i + 1]);
			}
			int delta = max (0, a[i] - lo);
			a[i] -= delta;
			res += delta;
		}
		debug {writeln (a, " ", res);}
		res += a[0];
		res += a[n - 1];
		foreach (i; 1..n)
		{
			res += abs (a[i] - a[i - 1]);
		}
		writeln (res);
	}
}

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

void main()
{
  int t;
  readf!" %d "(t);
  while (t--) {
    int n;
    readf!" %d "(n);
    auto a = readln.chomp.split.map!(to!int).array;
    int[] b = [0] ~ a ~ [0];
    long result = 0;
    foreach (i ; 1 .. b.length - 1) {
      int diff_l = b[i] - b[i - 1];
      int diff_r = b[i] - b[i + 1];
      if (diff_l > 0 && diff_r > 0) {
        b[i] -= min(diff_l, diff_r);
        result += min(diff_l, diff_r);
      }
    }
    foreach (i ; 1 .. b.length) {
      result += abs(b[i] - b[i - 1]);
    }
    writeln(result);
  }
}

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

void main()
{
	int t = readInt!int;
	while (t--) solve;
}
void solve()
{
	int n = readInt!int;
	auto a = new int[](n);
	foreach(ref ai; a) ai = readInt!int;
	a = 0 ~ a ~ 0;
	long ops = 0;
	long border = 0;
	foreach(i; 1 .. n + 1)
	{
		if (a[i] > a[i - 1] && a[i] > a[i + 1])
		{
			debug writeln("reducing ", i, " ", a[i]);
			int s = max(a[i - 1], a[i + 1]);
			ops += a[i] - s;
			a[i] = cast(int)s;
		}
		border += abs(a[i - 1] - a[i]);
	}
	border += a[n];
	(border + ops).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);
	}
}

// code by cutx64

module main;

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

void main() {

  int tests; readf!"%s\n"(tests);
multitest_end:
  while(tests--) {
    int n; readf!"%s\n"(n);
    int[] a = readln.splitter.map!(to!int).array;
    long res = 0;
    foreach(i; 0 .. n) {
      int low = 0;
      if(i > 0) {
        low = max(low, a[i - 1]);
      }
      if(i + 1 < n) {
        low = max(low, a[i + 1]);
      }
      int delta = max(0, a[i] - low);
      a[i] -= delta;
      res += delta;
    }
    res += a[0];
    res += a[n - 1];
    foreach(i; 1 .. n) {
      res += abs(a[i] - a[i - 1]);
    }
    res.writeln;
  }

} // main


import std.stdio;
import std.math;

void main() {
    int n, k; scanf("%u %u", &n, &k);
    double t = 0;
    double x, y, px, py;
    scanf("%lf %lf", &px, &py);
    foreach (i; 1 .. n) {
        scanf("%lf %lf", &x, &y);
        double dx = abs(x - px);
        double dy = abs(y - py);
        t += sqrt(dx * dx + dy * dy);
        px = x; py = y;
    }
    printf("%.9f\n", t / 50 * k);
}

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

struct IO {
        string[] tk;
        string readString() {
                while (tk.empty)
                        tk = readln.split;
                auto tkt = tk.front;
                tk.popFront;
                return tkt;
        }
        int readInt() {
                return readString.to!int;
        }
        double readDouble() {
                return readString.to!double;
        }
}

double dist(int x1, int y1, int x2, int y2) {
        double dist = sqrt((x1.to!double - x2.to!double) ^^ 2 + (y1.to!double - y2.to!double) ^^ 2).to!double;
        return dist;
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.readInt;
        while (t--) {
                int n = cin.readInt();
                int k = cin.readInt();
                int[][] points = new int[][](n, 2);
                for (int i = 0; i < n; i++) {
                        int a = cin.readInt;
                        int b = cin.readInt;
                        points[i][0] = a;
                        points[i][1] = b;
                }
                double totalDistance = 0;
                for (int i = 1; i < n; i++) {
                        totalDistance += dist(points[i][0], points[i][1], points[i - 1][0], points[i - 1][1]);
                }
                double time = k * cast(double)(totalDistance / 50.0);
                writefln("%.9f", time);
        }
}