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

void main(string[] args)
{
  auto n = next!int;
  auto b = next!long(n);
  auto pows = b.map!log2.array;
  auto mostCommonPow = pows.mode!(int[], 65);
  printArr(iota(0, n).filter!(i => pows[i] != mostCommonPow).map!(i => b[i]).array);
}

void printArr(Arr)(Arr arr)
{
  println(arr.length, arr);
}

int log2(long x)
{
  int cnt = 0;
  while((x & 1) == 0) {cnt++; x >>= 1;}
  return cnt;
}

auto mode(Arr, size_t n = 0)(Arr arr)
{
  alias Elem = typeof(arr.front);
  static if (n == 0)
    {
      size_t[Elem] cnt;
      Elem res;
      cnt[res] = 0;
      foreach(elem; arr)
	{
	  cnt.require(elem, 0)++;
	  if (cnt[elem] > cnt[res])
	    res = elem;
	}
      return res;
    }
  else
    {
      size_t[n] cnt;
      Elem res = 0;
      foreach(elem; arr)
	{
	  cnt[elem]++;
	  if (cnt[elem] > cnt[res])
	    res = elem;
	}
      return res;
    }
}

static this()
{
  popChar;
}

struct Any(T)
{
  static auto read()
  {
    static if (is(T == char))
      {
	auto res = frontChar;
	popChar;
	return res;
      }
  }
}

struct Unsigned(T)
{
  auto read()
  {
    auto res = T(0);
    while(!frontChar.isDigit) popChar;
    do
      {
	res = res * T(10) + T(frontChar - '0');
	popChar;
      }
    while(frontChar.isDigit);
    return res;
  }
}

struct Matrix(T, alias rows, alias cols)
{
  T[][] _cell;
  alias _cell this;
  // Ring constructor
  this(int n)
  {
    final switch(n)
      {
      case 0:
	_cell = new T[][](rows, cols);
	break;
      case 1:
	debug assert(rows == cols);
	_cell = new T[][](rows, cols);
	foreach(i; 0 .. rows)
	  _cell[i][i] = T(1);
	break;
      }
  }
  // Copy constructor
  this(Matrix!(T, rows, cols) other)
  {
    _cell = new T[][](rows, cols);
    foreach(i; 0 .. rows)
      _cell[i][] = other[i][];
  }
  auto opBinary(string op)(Matrix!(T, rows, cols) other)
       if (op == "+" || op == "-")
	 {
	   auto res = Matrix!(T, rows, cols)(0);
	   foreach(i; 0 .. rows)
	     foreach(j; 0 .. cols)
	       res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});
	   return res;
	 }
  auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)
       if (op == "*")
	 {
	   debug assert(cols == otherRows);
	   auto res = Matrix!(T, rows, otherCols)(0);
	   foreach(i; 0 .. rows)
	     foreach(k; 0 .. cols)
	       foreach(j; 0 .. otherCols)
		 res[i][j] += this[i][k] * other[k][j];
	   return res;
	 }
  ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)
  {
    static if (op == "*")
      {
	debug assert(rows == cols);
	alias n = rows;
	auto res = Matrix!(T, n, n)(0);
	T factor;
	foreach(i; 0 .. n)
	  foreach(k; 0 .. n)
	    foreach(j; 0 .. n)
	      res[i][j] += this[i][k] * other[k][j];
	foreach(i; 0 .. n)
	  this[i][] = res[i][];
      }
    else
      {
	foreach(i; 0 .. rows)
	  foreach(j; 0 .. cols)
	    mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});
      }
    return this;
  }
  mixin powMethod;
}

struct Mod(T, alias mod)
{
  alias This = Mod!(T, mod);
  T _rep;
  this(T t)
  {
    _rep = t % mod;
    if (_rep < 0) _rep += mod;
  }
  static auto plain(T t)
  {
    auto res = Mod!(T, mod)();
    res._rep = t;
    return res;
  }
  static auto fromPositive(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod);
  }
  static auto fromNegative(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod + mod);
  }
  string toString()
  {
    return to!string(_rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plain(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plain(resrep);
      }
    else static if (op == "*")
      {
	return This.fromPositive(_rep * b._rep);
      }
  }
  auto opOpAssign(string op)(This b)
  {
    mixin(q{_rep }, text(op, "="), q{b._rep;});
    static if (op == "+")
      {
	if (_rep >= mod) _rep -= mod;
      }
    else static if (op == "-")
      {
	if (_rep < 0) _rep += mod;
      }
    else static if (op == "*")
      {
	_rep %= mod;
      }
    return this;
  }

  auto opBinary(string op)(long exp)
       if (op == "^^")
	 {
	   return pow(exp);
	 }
  mixin powMethod;
}

mixin template powMethod()
{
  auto pow(this ThisType)(long exp)
    {
      auto res = ThisType(1);
      auto pow = ThisType(this);
      while(exp)
	{
	  if (exp & 1) res *= pow;
	  pow *= pow;
	  exp >>= 1;
	}
      return res;
    }
}
// INPUT
char frontChar;
void popChar()
{
  import core.stdc.stdio;
  frontChar = cast(char) getchar;
  if (feof(stdin)) frontChar = ' ';
}
auto makeArray(T, S...)(S s)
{
  enum brackets = () {
    string res;
    foreach(i; 0 .. s.length)
      res ~= "[]";
    return res;
  } ();
  mixin(q{alias Type = T}, brackets, q{;});
  return new Type(s);
}
template isNumberLike(T)
{
  enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));
}
void popWhite()
{
  import std.ascii;
  while (frontChar.isWhite) popChar;
}
void print(T...)(T t)
{
  static foreach(ti; t)
    {
      static if (is(typeof(ti) == string))
	{
	  write(ti, " ");
	}
      else static if (is(typeof((){foreach(e; ti) print(e);}())))
	{
	  foreach(e; ti) print(e);
	}
      else static if (isTuple!(typeof(ti)))
	{
	  static foreach(i; ti.length) writesp(ti[i]);
	}
      else
	{
	  write(ti, " ");
	}
    }
}
void println(T...)(T t)
{
  static if (t.length == 0)
    writeln;
  static foreach(ti; t)
    {
      print(ti);
      writeln;
    }
}
auto next(alias T, S...)(S s)
{
  pragma(inline, true);
  static if (s.length > 0)
    {
      auto res = makeArray!(typeof(next!T()))(s);
      S t;
      enum loops = () {
	string res;
	foreach(i; 0 .. s.length)
	  {
	    auto ti = text(q{t[}, i, q{]});
	    res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});
	  }
	return res;
      } ();
      enum indexing = () {
	string res = "res";
	foreach(i; 0 .. s.length)
	  res ~= text(q{[t[}, i, q{]]});
	return res;
      } ();
      mixin(loops, indexing, q{ = next!T;});
      return res;
    }
  else
    {
      static if (isNumberLike!T)
	{
	  import std.ascii: isDigit;
	  T res;
	  while(frontChar.isWhite) popChar;
	  T multiplier = T(1);
	  if (frontChar == '-')
	    {
	      multiplier = T(-1);
	      popChar;
	    }
	  else if (frontChar == '+')
	    {
	      popChar;
	    }
	  debug assert(frontChar.isDigit);
	  do
	    {
	      res = res * T(10) + T(frontChar - '0');
	      popChar;
	    }
	  while(frontChar.isDigit);
	  return multiplier * res;
	}
      else static if (is(T == string))
	{
	  import std.ascii: isWhite;
	  string res;
	  while(frontChar.isWhite)
	    popChar;
	  while(!frontChar.isWhite)
	    {
	      res ~= frontChar;
	      popChar;
	    }
	  return res;
	}
      else static if (is(T == char))
	{
	  while(frontChar.isWhite) popChar;
	  auto res = frontChar;
	  popChar;
	  return res;
	}
      else
	{
	  return T.read;
	}
    }
}

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

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

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

    long pw = 1;
    int bestcnt = 0; long bestpw = -1;
    foreach (_; 0 .. 60) {
        int cur = 0;
        foreach (e; arr) {
            if (e % pw == 0 && e % (2*pw) != 0) {
                ++cur;
            }
        }

        debug { writeln(pw, ' ', cur); }
        if (cur > bestcnt) {
            bestcnt = cur;
            bestpw = pw;
        }

        pw *= 2;
    }

    debug { bestpw.writeln; }

    long[] ans;
    foreach (e; arr) {
        if (e % bestpw == 0 && e % (bestpw * 2) != 0) { continue; }

        ans ~= e;
    }

    ans.length.writeln;
    ans.map!(to!string).join(" ").writeln;
}

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

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

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

    long pw = 1;
    int bestcnt = 0; long bestpw = -1;
    foreach (_; 0 .. 60) {
        int cur = 0;
        foreach (e; arr) {
            if (e % pw == 0 && e % (2*pw) != 0) {
                ++cur;
            }
        }

        debug { writeln(pw, ' ', cur); }
        if (cur > bestcnt) {
            bestcnt = cur;
            bestpw = pw;
        }

        pw *= 2;
    }

    debug { bestpw.writeln; }

    long[] ans;
    foreach (e; arr) {
        if (e % bestpw == 0 && e % (bestpw * 2) != 0) { continue; }

        ans ~= e;
    }

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

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

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

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

    bool isExactlyDivisible(long x, long pw2) {
        return x % pw2 == 0 && x % (pw2 * 2) != 0;
    }

    long pw = 1;
    int bestcnt = 0; long bestpw = -1;
    foreach (_; 0 .. 60) {
        int cur = 0;
        foreach (e; arr) {
            if (isExactlyDivisible(e, pw)) {
                ++cur;
            }
        }

        debug { writeln(pw, ' ', cur); }
        if (cur > bestcnt) {
            bestcnt = cur;
            bestpw = pw;
        }

        pw *= 2;
    }

    debug { bestpw.writeln; }

    long[] ans;
    foreach (e; arr) {
        if (isExactlyDivisible(e, bestpw)) { continue; }

        ans ~= e;
    }

    ans.length.writeln;
    ans.map!(to!string).join(" ").writeln;
}

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

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

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

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

int N;
long[] B;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      B = new long[N];
      foreach (i; 0 .. N) {
        B[i] = readLong();
      }

      auto cnt = new int[64];
      foreach (i; 0 .. N) {
        ++cnt[bsf(B[i])];
      }
      const em = cnt.maxIndex;

      writeln(N - cnt[em]);
      int ou;
      foreach (i; 0 .. N) {
        if (em != bsf(B[i])) {
          if (ou++) write(" ");
          write(B[i]);
        }
      }
      writeln();
    }
  } catch (EOFException e) {
  }
}

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

void main(string[] args)
{
  auto n = next!int;
  auto b = next!long(n);
  auto pows = b.map!log2.array;
  auto mostCommonPow = pows.mode!(int[], 65);
  auto indicesToRemove = iota(0, n).filter!(i => pows[i] != mostCommonPow).array;
  println(indicesToRemove.length, indicesToRemove.map!(i => b[i]));
}

int log2(long x)
{
  int cnt = 0;
  while((x & 1) == 0) {cnt++; x >>= 1;}
  return cnt;
}

auto mode(Arr, size_t n = 0)(Arr arr)
{
  alias Elem = typeof(arr.front);
  static if (n == 0)
    {
      size_t[Elem] cnt;
      Elem res;
      cnt[res] = 0;
      foreach(elem; arr)
	{
	  cnt.require(elem, 0)++;
	  if (cnt[elem] > cnt[res])
	    res = elem;
	}
      return res;
    }
  else
    {
      size_t[n] cnt;
      Elem res = 0;
      foreach(elem; arr)
	{
	  cnt[elem]++;
	  if (cnt[elem] > cnt[res])
	    res = elem;
	}
      return res;
    }
}

static this()
{
  popChar;
}

struct Any(T)
{
  static auto read()
  {
    static if (is(T == char))
      {
	auto res = frontChar;
	popChar;
	return res;
      }
  }
}

struct Unsigned(T)
{
  auto read()
  {
    auto res = T(0);
    while(!frontChar.isDigit) popChar;
    do
      {
	res = res * T(10) + T(frontChar - '0');
	popChar;
      }
    while(frontChar.isDigit);
    return res;
  }
}

struct Matrix(T, alias rows, alias cols)
{
  T[][] _cell;
  alias _cell this;
  // Ring constructor
  this(int n)
  {
    final switch(n)
      {
      case 0:
	_cell = new T[][](rows, cols);
	break;
      case 1:
	debug assert(rows == cols);
	_cell = new T[][](rows, cols);
	foreach(i; 0 .. rows)
	  _cell[i][i] = T(1);
	break;
      }
  }
  // Copy constructor
  this(Matrix!(T, rows, cols) other)
  {
    _cell = new T[][](rows, cols);
    foreach(i; 0 .. rows)
      _cell[i][] = other[i][];
  }
  auto opBinary(string op)(Matrix!(T, rows, cols) other)
       if (op == "+" || op == "-")
	 {
	   auto res = Matrix!(T, rows, cols)(0);
	   foreach(i; 0 .. rows)
	     foreach(j; 0 .. cols)
	       res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});
	   return res;
	 }
  auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)
       if (op == "*")
	 {
	   debug assert(cols == otherRows);
	   auto res = Matrix!(T, rows, otherCols)(0);
	   foreach(i; 0 .. rows)
	     foreach(k; 0 .. cols)
	       foreach(j; 0 .. otherCols)
		 res[i][j] += this[i][k] * other[k][j];
	   return res;
	 }
  ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)
  {
    static if (op == "*")
      {
	debug assert(rows == cols);
	alias n = rows;
	auto res = Matrix!(T, n, n)(0);
	T factor;
	foreach(i; 0 .. n)
	  foreach(k; 0 .. n)
	    foreach(j; 0 .. n)
	      res[i][j] += this[i][k] * other[k][j];
	foreach(i; 0 .. n)
	  this[i][] = res[i][];
      }
    else
      {
	foreach(i; 0 .. rows)
	  foreach(j; 0 .. cols)
	    mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});
      }
    return this;
  }
  mixin powMethod;
}

struct Mod(T, alias mod)
{
  alias This = Mod!(T, mod);
  T _rep;
  this(T t)
  {
    _rep = t % mod;
    if (_rep < 0) _rep += mod;
  }
  static auto plain(T t)
  {
    auto res = Mod!(T, mod)();
    res._rep = t;
    return res;
  }
  static auto fromPositive(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod);
  }
  static auto fromNegative(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod + mod);
  }
  string toString()
  {
    return to!string(_rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plain(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plain(resrep);
      }
    else static if (op == "*")
      {
	return This.fromPositive(_rep * b._rep);
      }
  }
  auto opOpAssign(string op)(This b)
  {
    mixin(q{_rep }, text(op, "="), q{b._rep;});
    static if (op == "+")
      {
	if (_rep >= mod) _rep -= mod;
      }
    else static if (op == "-")
      {
	if (_rep < 0) _rep += mod;
      }
    else static if (op == "*")
      {
	_rep %= mod;
      }
    return this;
  }

  auto opBinary(string op)(long exp)
       if (op == "^^")
	 {
	   return pow(exp);
	 }
  mixin powMethod;
}

mixin template powMethod()
{
  auto pow(this ThisType)(long exp)
    {
      auto res = ThisType(1);
      auto pow = ThisType(this);
      while(exp)
	{
	  if (exp & 1) res *= pow;
	  pow *= pow;
	  exp >>= 1;
	}
      return res;
    }
}
// INPUT
char frontChar;
void popChar()
{
  import core.stdc.stdio;
  frontChar = cast(char) getchar;
  if (feof(stdin)) frontChar = ' ';
}
auto makeArray(T, S...)(S s)
{
  enum brackets = () {
    string res;
    foreach(i; 0 .. s.length)
      res ~= "[]";
    return res;
  } ();
  mixin(q{alias Type = T}, brackets, q{;});
  return new Type(s);
}
template isNumberLike(T)
{
  enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));
}
void popWhite()
{
  import std.ascii;
  while (frontChar.isWhite) popChar;
}
void print(T...)(T t)
{
  static foreach(ti; t)
    {
      static if (is(typeof(ti) == string))
	{
	  write(ti, " ");
	}
      else static if (is(typeof((){foreach(e; ti) print(e);}())))
	{
	  foreach(e; ti) print(e);
	}
      else static if (isTuple!(typeof(ti)))
	{
	  static foreach(i; ti.length) writesp(ti[i]);
	}
      else
	{
	  write(ti, " ");
	}
    }
}
void println(T...)(T t)
{
  static if (t.length == 0)
    writeln;
  static foreach(ti; t)
    {
      print(ti);
      writeln;
    }
}
auto next(alias T, S...)(S s)
{
  pragma(inline, true);
  static if (s.length > 0)
    {
      auto res = makeArray!(typeof(next!T()))(s);
      S t;
      enum loops = () {
	string res;
	foreach(i; 0 .. s.length)
	  {
	    auto ti = text(q{t[}, i, q{]});
	    res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});
	  }
	return res;
      } ();
      enum indexing = () {
	string res = "res";
	foreach(i; 0 .. s.length)
	  res ~= text(q{[t[}, i, q{]]});
	return res;
      } ();
      mixin(loops, indexing, q{ = next!T;});
      return res;
    }
  else
    {
      static if (isNumberLike!T)
	{
	  import std.ascii: isDigit;
	  T res;
	  while(frontChar.isWhite) popChar;
	  T multiplier = T(1);
	  if (frontChar == '-')
	    {
	      multiplier = T(-1);
	      popChar;
	    }
	  else if (frontChar == '+')
	    {
	      popChar;
	    }
	  debug assert(frontChar.isDigit);
	  do
	    {
	      res = res * T(10) + T(frontChar - '0');
	      popChar;
	    }
	  while(frontChar.isDigit);
	  return multiplier * res;
	}
      else static if (is(T == string))
	{
	  import std.ascii: isWhite;
	  string res;
	  while(frontChar.isWhite)
	    popChar;
	  while(!frontChar.isWhite)
	    {
	      res ~= frontChar;
	      popChar;
	    }
	  return res;
	}
      else static if (is(T == char))
	{
	  while(frontChar.isWhite) popChar;
	  auto res = frontChar;
	  popChar;
	  return res;
	}
      else
	{
	  return T.read;
	}
    }
}

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

void main(string[] args)
{
  auto n = next!int;
  auto b = next!long(n);
  int[65] powcnt;
  int maxpow = 0;
  foreach(bi; b)
    {
      auto p = log2(bi);
      powcnt[p]++;
      if (powcnt[p] > powcnt[maxpow])
	maxpow = p;
    }
  writeln(n - powcnt[maxpow]);
  foreach(bi; b)
    {
      auto p = log2(bi);
      if (p != maxpow) write(bi, " ");
    }
  writeln;
}

int log2(long x)
{
  int cnt = 0;
  while((x & 1) == 0) {cnt++; x >>= 1;}
  return cnt;
}

static this()
{
  popChar;
}

struct Any(T)
{
  static auto read()
  {
    static if (is(T == char))
      {
	auto res = frontChar;
	popChar;
	return res;
      }
  }
}

struct Unsigned(T)
{
  auto read()
  {
    auto res = T(0);
    while(!frontChar.isDigit) popChar;
    do
      {
	res = res * T(10) + T(frontChar - '0');
	popChar;
      }
    while(frontChar.isDigit);
    return res;
  }
}

struct Matrix(T, alias rows, alias cols)
{
  T[][] _cell;
  alias _cell this;
  // Ring constructor
  this(int n)
  {
    final switch(n)
      {
      case 0:
	_cell = new T[][](rows, cols);
	break;
      case 1:
	debug assert(rows == cols);
	_cell = new T[][](rows, cols);
	foreach(i; 0 .. rows)
	  _cell[i][i] = T(1);
	break;
      }
  }
  // Copy constructor
  this(Matrix!(T, rows, cols) other)
  {
    _cell = new T[][](rows, cols);
    foreach(i; 0 .. rows)
      _cell[i][] = other[i][];
  }
  auto opBinary(string op)(Matrix!(T, rows, cols) other)
       if (op == "+" || op == "-")
	 {
	   auto res = Matrix!(T, rows, cols)(0);
	   foreach(i; 0 .. rows)
	     foreach(j; 0 .. cols)
	       res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});
	   return res;
	 }
  auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)
       if (op == "*")
	 {
	   debug assert(cols == otherRows);
	   auto res = Matrix!(T, rows, otherCols)(0);
	   foreach(i; 0 .. rows)
	     foreach(k; 0 .. cols)
	       foreach(j; 0 .. otherCols)
		 res[i][j] += this[i][k] * other[k][j];
	   return res;
	 }
  ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)
  {
    static if (op == "*")
      {
	debug assert(rows == cols);
	alias n = rows;
	auto res = Matrix!(T, n, n)(0);
	T factor;
	foreach(i; 0 .. n)
	  foreach(k; 0 .. n)
	    foreach(j; 0 .. n)
	      res[i][j] += this[i][k] * other[k][j];
	foreach(i; 0 .. n)
	  this[i][] = res[i][];
      }
    else
      {
	foreach(i; 0 .. rows)
	  foreach(j; 0 .. cols)
	    mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});
      }
    return this;
  }
  mixin powMethod;
}

struct Mod(T, alias mod)
{
  alias This = Mod!(T, mod);
  T _rep;
  this(T t)
  {
    _rep = t % mod;
    if (_rep < 0) _rep += mod;
  }
  static auto plain(T t)
  {
    auto res = Mod!(T, mod)();
    res._rep = t;
    return res;
  }
  static auto fromPositive(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod);
  }
  static auto fromNegative(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod + mod);
  }
  string toString()
  {
    return to!string(_rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plain(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plain(resrep);
      }
    else static if (op == "*")
      {
	return This.fromPositive(_rep * b._rep);
      }
  }
  auto opOpAssign(string op)(This b)
  {
    mixin(q{_rep }, text(op, "="), q{b._rep;});
    static if (op == "+")
      {
	if (_rep >= mod) _rep -= mod;
      }
    else static if (op == "-")
      {
	if (_rep < 0) _rep += mod;
      }
    else static if (op == "*")
      {
	_rep %= mod;
      }
    return this;
  }

  auto opBinary(string op)(long exp)
       if (op == "^^")
	 {
	   return pow(exp);
	 }
  mixin powMethod;
}

mixin template powMethod()
{
  auto pow(this ThisType)(long exp)
    {
      auto res = ThisType(1);
      auto pow = ThisType(this);
      while(exp)
	{
	  if (exp & 1) res *= pow;
	  pow *= pow;
	  exp >>= 1;
	}
      return res;
    }
}
// INPUT
char frontChar;
void popChar()
{
  import core.stdc.stdio;
  frontChar = cast(char) getchar;
  if (feof(stdin)) frontChar = ' ';
}
auto makeArray(T, S...)(S s)
{
  enum brackets = () {
    string res;
    foreach(i; 0 .. s.length)
      res ~= "[]";
    return res;
  } ();
  mixin(q{alias Type = T}, brackets, q{;});
  return new Type(s);
}
template isNumberLike(T)
{
  enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));
}
void popWhite()
{
  import std.ascii;
  while (frontChar.isWhite) popChar;
}
void print(T...)(T t)
{
  static foreach(ti; t)
    {
      static if (is(typeof(ti) == string))
	{
	  write(ti, " ");
	}
      else static if (isArray!(typeof(ti)))
	{
	  foreach(e; ti) print(e);
	}
      else static if (isTuple!(typeof(ti)))
	{
	  static foreach(i; ti.length) writesp(ti[i]);
	}
      else
	{
	  write(ti, " ");
	}
    }
}
void println(T...)(T t)
{
  static if (t.length == 0)
    writeln;
  static foreach(ti; t)
    {
      print(ti);
      writeln;
    }
}
auto next(alias T, S...)(S s)
{
  pragma(inline, true);
  static if (s.length > 0)
    {
      auto res = makeArray!(typeof(next!T()))(s);
      S t;
      enum loops = () {
	string res;
	foreach(i; 0 .. s.length)
	  {
	    auto ti = text(q{t[}, i, q{]});
	    res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});
	  }
	return res;
      } ();
      enum indexing = () {
	string res = "res";
	foreach(i; 0 .. s.length)
	  res ~= text(q{[t[}, i, q{]]});
	return res;
      } ();
      mixin(loops, indexing, q{ = next!T;});
      return res;
    }
  else
    {
      static if (isNumberLike!T)
	{
	  import std.ascii: isDigit;
	  T res;
	  while(frontChar.isWhite) popChar;
	  T multiplier = T(1);
	  if (frontChar == '-')
	    {
	      multiplier = T(-1);
	      popChar;
	    }
	  else if (frontChar == '+')
	    {
	      popChar;
	    }
	  debug assert(frontChar.isDigit);
	  do
	    {
	      res = res * T(10) + T(frontChar - '0');
	      popChar;
	    }
	  while(frontChar.isDigit);
	  return multiplier * res;
	}
      else static if (is(T == string))
	{
	  import std.ascii: isWhite;
	  string res;
	  while(frontChar.isWhite)
	    popChar;
	  while(!frontChar.isWhite)
	    {
	      res ~= frontChar;
	      popChar;
	    }
	  return res;
	}
      else static if (is(T == char))
	{
	  while(frontChar.isWhite) popChar;
	  auto res = frontChar;
	  popChar;
	  return res;
	}
      else
	{
	  return T.read;
	}
    }
}

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

void main(string[] args)
{
  auto n = next!int;
  auto b = next!long(n);
  auto pows = b.map!log2;
  auto mostCommonPow = pows.mode;
  auto indicesToRemove = iota(0, n).filter!(i => pows[i] != mostCommonPow).array;
  println(indicesToRemove.length, indicesToRemove.map!(i => b[i]));
}

int log2(long x)
{
  int cnt = 0;
  while((x & 1) == 0) {cnt++; x >>= 1;}
  return cnt;
}

auto mode(Arr)(Arr arr)
{
  alias Elem = typeof(arr.front);
  size_t[Elem] cnt;
  Elem res;
  cnt[res] = 0;
  foreach(elem; arr)
    {
      cnt.require(elem, 0)++;
      if (cnt[elem] > cnt[res])
	res = elem;
    }
  return res;
}

static this()
{
  popChar;
}

struct Any(T)
{
  static auto read()
  {
    static if (is(T == char))
      {
	auto res = frontChar;
	popChar;
	return res;
      }
  }
}

struct Unsigned(T)
{
  auto read()
  {
    auto res = T(0);
    while(!frontChar.isDigit) popChar;
    do
      {
	res = res * T(10) + T(frontChar - '0');
	popChar;
      }
    while(frontChar.isDigit);
    return res;
  }
}

struct Matrix(T, alias rows, alias cols)
{
  T[][] _cell;
  alias _cell this;
  // Ring constructor
  this(int n)
  {
    final switch(n)
      {
      case 0:
	_cell = new T[][](rows, cols);
	break;
      case 1:
	debug assert(rows == cols);
	_cell = new T[][](rows, cols);
	foreach(i; 0 .. rows)
	  _cell[i][i] = T(1);
	break;
      }
  }
  // Copy constructor
  this(Matrix!(T, rows, cols) other)
  {
    _cell = new T[][](rows, cols);
    foreach(i; 0 .. rows)
      _cell[i][] = other[i][];
  }
  auto opBinary(string op)(Matrix!(T, rows, cols) other)
       if (op == "+" || op == "-")
	 {
	   auto res = Matrix!(T, rows, cols)(0);
	   foreach(i; 0 .. rows)
	     foreach(j; 0 .. cols)
	       res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});
	   return res;
	 }
  auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)
       if (op == "*")
	 {
	   debug assert(cols == otherRows);
	   auto res = Matrix!(T, rows, otherCols)(0);
	   foreach(i; 0 .. rows)
	     foreach(k; 0 .. cols)
	       foreach(j; 0 .. otherCols)
		 res[i][j] += this[i][k] * other[k][j];
	   return res;
	 }
  ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)
  {
    static if (op == "*")
      {
	debug assert(rows == cols);
	alias n = rows;
	auto res = Matrix!(T, n, n)(0);
	T factor;
	foreach(i; 0 .. n)
	  foreach(k; 0 .. n)
	    foreach(j; 0 .. n)
	      res[i][j] += this[i][k] * other[k][j];
	foreach(i; 0 .. n)
	  this[i][] = res[i][];
      }
    else
      {
	foreach(i; 0 .. rows)
	  foreach(j; 0 .. cols)
	    mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});
      }
    return this;
  }
  mixin powMethod;
}

struct Mod(T, alias mod)
{
  alias This = Mod!(T, mod);
  T _rep;
  this(T t)
  {
    _rep = t % mod;
    if (_rep < 0) _rep += mod;
  }
  static auto plain(T t)
  {
    auto res = Mod!(T, mod)();
    res._rep = t;
    return res;
  }
  static auto fromPositive(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod);
  }
  static auto fromNegative(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod + mod);
  }
  string toString()
  {
    return to!string(_rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plain(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plain(resrep);
      }
    else static if (op == "*")
      {
	return This.fromPositive(_rep * b._rep);
      }
  }
  auto opOpAssign(string op)(This b)
  {
    mixin(q{_rep }, text(op, "="), q{b._rep;});
    static if (op == "+")
      {
	if (_rep >= mod) _rep -= mod;
      }
    else static if (op == "-")
      {
	if (_rep < 0) _rep += mod;
      }
    else static if (op == "*")
      {
	_rep %= mod;
      }
    return this;
  }

  auto opBinary(string op)(long exp)
       if (op == "^^")
	 {
	   return pow(exp);
	 }
  mixin powMethod;
}

mixin template powMethod()
{
  auto pow(this ThisType)(long exp)
    {
      auto res = ThisType(1);
      auto pow = ThisType(this);
      while(exp)
	{
	  if (exp & 1) res *= pow;
	  pow *= pow;
	  exp >>= 1;
	}
      return res;
    }
}
// INPUT
char frontChar;
void popChar()
{
  import core.stdc.stdio;
  frontChar = cast(char) getchar;
  if (feof(stdin)) frontChar = ' ';
}
auto makeArray(T, S...)(S s)
{
  enum brackets = () {
    string res;
    foreach(i; 0 .. s.length)
      res ~= "[]";
    return res;
  } ();
  mixin(q{alias Type = T}, brackets, q{;});
  return new Type(s);
}
template isNumberLike(T)
{
  enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));
}
void popWhite()
{
  import std.ascii;
  while (frontChar.isWhite) popChar;
}
void print(T...)(T t)
{
  static foreach(ti; t)
    {
      static if (is(typeof(ti) == string))
	{
	  write(ti, " ");
	}
      else static if (is(typeof((){foreach(e; ti) print(e);}())))
	{
	  foreach(e; ti) print(e);
	}
      else static if (isTuple!(typeof(ti)))
	{
	  static foreach(i; ti.length) writesp(ti[i]);
	}
      else
	{
	  write(ti, " ");
	}
    }
}
void println(T...)(T t)
{
  static if (t.length == 0)
    writeln;
  static foreach(ti; t)
    {
      print(ti);
      writeln;
    }
}
auto next(alias T, S...)(S s)
{
  pragma(inline, true);
  static if (s.length > 0)
    {
      auto res = makeArray!(typeof(next!T()))(s);
      S t;
      enum loops = () {
	string res;
	foreach(i; 0 .. s.length)
	  {
	    auto ti = text(q{t[}, i, q{]});
	    res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});
	  }
	return res;
      } ();
      enum indexing = () {
	string res = "res";
	foreach(i; 0 .. s.length)
	  res ~= text(q{[t[}, i, q{]]});
	return res;
      } ();
      mixin(loops, indexing, q{ = next!T;});
      return res;
    }
  else
    {
      static if (isNumberLike!T)
	{
	  import std.ascii: isDigit;
	  T res;
	  while(frontChar.isWhite) popChar;
	  T multiplier = T(1);
	  if (frontChar == '-')
	    {
	      multiplier = T(-1);
	      popChar;
	    }
	  else if (frontChar == '+')
	    {
	      popChar;
	    }
	  debug assert(frontChar.isDigit);
	  do
	    {
	      res = res * T(10) + T(frontChar - '0');
	      popChar;
	    }
	  while(frontChar.isDigit);
	  return multiplier * res;
	}
      else static if (is(T == string))
	{
	  import std.ascii: isWhite;
	  string res;
	  while(frontChar.isWhite)
	    popChar;
	  while(!frontChar.isWhite)
	    {
	      res ~= frontChar;
	      popChar;
	    }
	  return res;
	}
      else static if (is(T == char))
	{
	  while(frontChar.isWhite) popChar;
	  auto res = frontChar;
	  popChar;
	  return res;
	}
      else
	{
	  return T.read;
	}
    }
}


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

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long a, b, c, n;
    readf!" %d %d %d "(a, b, c);
    n = 2 * (max(a, b) - min(a, b));
    if (max(a, b, c) > n)
      writeln(-1);
    else
      writeln(((c - 1) + n / 2) % n + 1);
  }
}

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

void theCode(){
    ll a = scan;
    ll b = scan;
    ll c = scan;
    ll hf = abs(a - b);
    ll n = 2 * hf;
    if(n < max(a, b, c)){
        writeln(-1);
    }else{
    ll rem = (c + hf) % n;
        if(rem == 0){
            writeln(n);
        }else{
            writeln(rem);
        }
    }
}

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

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


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

void main() {
    int n, x;
    readf("%d %d\n", &n, &x);
    int[] hands = readln.chomp.split.map!(to!int).array;
    int rest = hands.sum.abs;
    ceil(cast(double)rest / x).writeln;
}

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

void main() {
    int n, x;
    readf("%d %d\n", &n, &x);
    long sum = readln.chomp.split(" ").map!(to!int).reduce!"a + b".abs;
    writeln(sum / x + (sum % x != 0));
}

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

void main() {
    int n, x;
    readf("%d %d\n", &n, &x);
    int[] hands = readln.chomp.split.map!(to!int).array;
    int[] cards = new int[x + 1];
    foreach (e; hands) {
        if (e > 0) {
            cards[e]++;
        } else if (e < 0) {
            cards[-e]--;
        }
    }

    cards.map!"abs(a)".sum.writeln;
}

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

void main() {
    int n, x;
    readf("%d %d\n", &n, &x);
    int[] hands = readln.chomp.split.map!(to!int).array;
    int rest = hands.sum;
    ceil(cast(double)rest / x).writeln;
}


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int x, y;
		readf !(" %s %s") (x, y);
		if (x > y)
		{
			writeln (x + y);
		}
		else if (x == y)
		{
			writeln (x);
		}
		else if (x < y)
		{
			int rem = y % x;
			int eps = rem / 2;
			writeln (y - eps);
		}
		else
		{
			assert (false);
		}
	}
}

immutable multi = true;

void solve(int tc)
{
	auto x = readInt!long;
	auto y = readInt!long;
	if (x == y) return writeln(x);
	if (x > y) return writeln(x + y);
	auto alpha = (y - 1) % x;
	assert (alpha % 2 == 1);
	writeln(y - 1 - (alpha - 1)/2);
}

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

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

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

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

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

import std.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)); }

long solve(long X, long Y) {
  const c = Y / X, d = Y % X;
  long a, b, r;
  if (c == 0) {
    a = 1;
    b = 0;
    r = d;
  } else {
    a = c;
    b = 1;
    r = d / 2;
  }
  const n = X * a + r;
  debug {
    // writeln(X, " ", Y, ": ", n);
  }
  assert(1 <= n); assert(n <= 2 * max(X, Y)^^2);
  assert(n % X == Y % n);
  return n;
}

void main() {
  debug {{
    enum lim = 100;
    for (long x = 2; x <= lim; x += 2) for (long y = 2; y <= lim; y += 2) {
      solve(x, y);
    }
  }}

  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (_; 0 .. numCases) {
        const X = readLong();
        const Y = readLong();

        const ans = solve(X, Y);
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}


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

  int n; rd(n);
  auto y=readln.split.to!(long[]);

  alias pt=Tuple!(long, "x", long ,"y");
  pt[] f(long dy, long dx){
    pt[] rt;
    foreach(x; 1..n){
      long dy_=y[x]-y[0];
      if(dy*x!=dy_*dx) rt~=pt(x, y[x]);
    }
    return rt;
  }

  bool g(long _dy, long _dx, pt[] ys){
    if(ys.length==0) return false;
    if(ys.length==1) return true;
    long dy=ys[1].y-ys[0].y;
    long dx=ys[1].x-ys[0].x;
    if(_dy*dx!=dy*_dx) return false;
    foreach(i; 1..ys.length){
      long dy_=ys[i].y-ys[0].y;
      long dx_=ys[i].x-ys[0].x;
      if(dy*dx_!=dy_*dx) return false;
    }
    return true;
  }

  foreach(x; 1..n){
    long dy=y[x]-y[0];
    // int dx=x;
    auto rs=f(dy, x);
    // writeln(x, " ", rs);

    if(g(dy, x, rs)){
      writeln("Yes");
      return;
    }
  }

  // l1={1}, l2={2, 3, ..., n};
  long dydy=y[2]-y[1];
  // int dxdx=2-1;
  pt[] rsrs;
  foreach(x; 2..y.length){
    long dy_dy=y[x]-y[1];
    if(dydy*(x-1)!=dy_dy*1) rsrs~=pt(x, y[x]);
  }
  if(rsrs.length==0){
    if(y[1]-y[0]!=dydy){
      writeln("Yes"); return;
    }
  }

  writeln("No");
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      auto Y = new long[N];
      foreach (x; 0 .. N) {
        Y[x] = readLong();
      }

      bool ans;
      foreach (i; 0 .. 2) {
        foreach (j; 0 .. N) {
          if (i != j) {
            // (i, Y[i]), (j, Y[j])
            int[] xs;
            foreach (x; 0 .. N) {
              if ((j - i) * (Y[x] - Y[i]) != (Y[j] - Y[i]) * (x - i)) {
                xs ~= x;
              }
            }
            if (!xs.empty) {
              bool ok = true;
              foreach (x; xs) {
                if ((j - i) * (Y[x] - Y[xs[0]]) != (Y[j] - Y[i]) * (x - xs[0])) {
                  ok = false;
                }
              }
              if (ok) {
                ans = true;
              }
            }
          }
        }
      }
      writeln(ans ? "Yes" : "No");
    }
  } 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, core.stdc.string;

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto G = new Tuple!(int, int, int)[][](N);
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        G[s[0]-1] ~= tuple(s[1]-1, i, 0);
        G[s[1]-1] ~= tuple(s[0]-1, i, 1);
    }

    auto C = new int[](N);
    C[] = -1;

    bool dfs(int n, int c) {
        if (C[n] != -1) {
            return C[n] == c;
        }
        C[n] = c;
        foreach (m; G[n]) {
            if (!dfs(m[0], c^1)) {
                return false;
            }
        }
        return true;
    }

    if (!dfs(0, 0)) {
        writeln("NO");
        return;
    }

    auto ans = new int[](M);
    foreach (i; 0..N) {
        foreach (e; G[i]) {
            if (C[i] != e[2]) {
                ans[e[1]] = 1;
            }
        }
    }

    writeln("YES");
    ans.map!(to!string).join("").writeln;
}

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

immutable int INF = 10L ^^ 9 + 23;

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

    Tuple!(int, int)[] edges;
    auto g = new int[][] (n);
    foreach (_; 0 .. m) {
        int u, v;
        readf("%s %s", &u, &v);
        readln;

        --u, --v;
        g[u] ~= v;
        g[v] ~= u;
        edges ~= tuple(u, v);
    }

    auto clr = new int[] (n);
    bool dfs(int v, int clrnow) {
        auto ok = true;
        clr[v] = clrnow;
        foreach (u; g[v]) {
            if (clr[u] == 0) { ok &= dfs(u, 3 - clrnow); }
            else if (clr[u] == clrnow) { return false; }
        }

        return ok;
    }

    auto ok = dfs(1, 1);

    if (!ok) {
        writeln("NO");
        return;
    }

    int[] ans;
    foreach (e; edges) {
        ans ~= clr[e[0]] - 1;
    }

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


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

  int n, k; rd(n, k);
  auto a=readln.split.to!(int[]);

  int num=0, c=1;
  sort(a);
  // writeln(a);
  foreach(i; 1..n){
    if(a[i-1]==a[i]){
      c++;
    }else{
      if(a[i-1]+k<a[i]) num+=c;
      c=1;
    }
  }
  // writeln(num);
  // writeln(c);
  writeln(num+c);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}

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

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

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

    a.sort();

    debug { a.writeln; }

    SList!int res;
    foreach (e; a) {
        while (!res.empty && res.front < e && e <= res.front + k) res.removeFront();
        res.insertFront(e);
    }

    res.array.length.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 K = s[1];
    auto A = readln.split.map!(to!int).array;
    A.sort();
    int ans = 0;
    int tmp = 1;
    int prev = -1;

    foreach (i; 0..N-1) {
        if (A[i+1] == A[i]) {
            ++tmp;
        }
        else {
            if (A[i+1] <= A[i] + K)
                ans += tmp;
            tmp = 1;
        }
    }

    ans = N - ans;
    ans.writeln;
}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///int length
		int sz(T)(ref const T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int n, k;
	read(n, k);
	auto a = arread!int;
	sort(a);
	debug writeln(a);
	int p;
	int c = 1;
	foreach (i; 1 .. n)
	{
		if (a[i] > a[i - 1] && a[i] <= a[i - 1] + k)
		{
			p += c;
			c = 1;
		}
		else if (a[i] == a[i - 1])
			c++;
		else
			c = 1;
	}
	writeln(n - p);
}


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		bool [int] used;
		int [] p;
		foreach (ref c; a)
		{
			if (c !in used)
			{
				p ~= c;
				used[c] = true;
			}
		}
		writefln !("%(%s %)") (p);
	}
}

import std.stdio;
import std.string : split, strip;
import std.algorithm : map, joiner;
import std.conv : to, text;

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

  foreach (i; 0..t) {
    int n;
    readf!"%d\n"(n);

    auto a = readln.strip.split.map!(to!int);
    bool[] s = new bool[n];
    int[] o = new int[n];

    int p = 0;

    foreach (j; a) {
      if (s[j-1]) continue;
      s[j-1] = true;

      o[p++] = j;
    }

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


// Vicfred
// https://codeforces.com/contest/1497/problem/A
// sorting, greedy
import std.algorithm;
import std.array;
import std.conv;
import std.container;
import std.stdio;
import std.string;

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

while(t--) {
    int n = readln.chomp.to!int;
    int[] a = readln.split.map!(to!int).array;

    auto unique = redBlackTree(a);
    auto dups = redBlackTree!true(a);

    foreach(number; unique) {
        writef("%s ", number);
        dups.removeKey(number);
    }
    foreach(number; dups) {
        writef("%s ", number);
    }
    "".writeln;
}
}

import std.stdio, std.string, std.algorithm, std.conv, std.range;
void main()
{
    int q;
    readf!"%d\n"(q);
    foreach (_; 0 .. q)
    {
        int n;
        readf!"%d\n"(n);
        int[] a = readln.split.map!(to!int).array, res;
        a.sort();
        foreach (i; 0 .. n)
            if (!i || a[i] != a[i - 1])
                res ~= [a[i]];
        foreach (i; 0 .. n)
            if (i && a[i] == a[i - 1])
                res ~= [a[i]];
        res.map!(to!string).join(" ").writeln;
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

		auto cnt = new long[](101);
		foreach (e; a)
			++cnt[e];

		int[] rem;
		foreach (i; 0..cnt.length)
		{
			if (cnt[i] == 0) continue;
			ans[ti] ~= cast(int)i;
			foreach (j; 1..cnt[i])
				rem ~= cast(int)i;
		}
		ans[ti] ~= rem;
	}

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

// Vicfred
// https://codeforces.com/contest/1497/problem/A
// sorting, greedy
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

long mex(long[] numbers) {
    long[long] missing;
    foreach(number; numbers) {
        missing[number] = 1L;
    }

    long mex = 0L;
    for(long i = 0L; i <= 100L; ++i) {
        auto p = (i in missing);
        if(p is null) {
            mex = i;
            return mex;
        }
    }
    return mex;
}

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

while(t--) {
    long n = readln.chomp.to!long;
    long[] a = readln.split.map!(to!long).array;
    a.sort;

    foreach(number; a) {
        writef("%s ", number);
    } "".writeln;
}
}


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

immutable long infinity = long.max / 8;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, m;
		readf !(" %s %s") (n, m);

		alias Rain = Tuple !(long, q{x}, long, q{p});
		auto r = new Rain [n];
		foreach (ref c; r)
		{
			readf !(" %s %s") (c.x, c.p);
		}

		alias Event = Tuple !(long, q{x}, long, q{delta});
		Event [] e;
		e.reserve (n * 3);
		foreach (ref c; r)
		{
			e ~= Event (c.x - c.p, +1);
			e ~= Event (c.x, -2);
			e ~= Event (c.x + c.p, +1);
		}
		sort (e);

		auto x = new long [n * 3];
		auto y = new long [n * 3];
		long cur = e[0].delta;
		x[0] = e[0].x;
		foreach (i; 1..n * 3)
		{
			x[i] = e[i].x;
			y[i] = y[i - 1] + cur * (x[i] - x[i - 1]);
			cur += e[i].delta;
		}

		auto lo = new long [n * 3];
		lo[0] = -infinity;
		foreach (i; 1..n * 3)
		{
			lo[i] = lo[i - 1];
			if (y[i] > m)
			{
				lo[i] = max (lo[i], y[i] - x[i]);
			}
		}

		auto hi = new long [n * 3];
		hi[$ - 1] = -infinity;
		foreach_reverse (i; 0..n * 3 - 1)
		{
			hi[i] = hi[i + 1];
			if (y[i] > m)
			{
				hi[i] = max (hi[i], y[i] + x[i]);
			}
		}

		auto xs = x.assumeSorted ();

		auto answer = new bool [n];
		foreach (i; 0..n)
		{
			answer[i] = true;
			auto pos = xs.lowerBound (r[i].x).length;
			answer[i] &= (lo[pos] + x[pos] - r[i].p <= m);
			answer[i] &= (hi[pos] - x[pos] - r[i].p <= m);
		}

		writefln !("%(%d%)") (answer);
	}
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const numCases = readInt;
      foreach (caseId; 0 .. numCases) {
        const N = readInt;
        const M = readLong;
        auto X = new long[N];
        auto P = new long[N];
        foreach (i; 0 .. N) {
          X[i] = readLong;
          P[i] = readLong;
        }

        alias Entry = Tuple!(long, "x", long, "a", long, "b");
        auto es = new Entry[3 * N];
        foreach (i; 0 .. N) {
          es[i * 3 + 0] = Entry(X[i] - P[i], +1, -(X[i] - P[i]));
          es[i * 3 + 1] = Entry(X[i]       , -2, +2 * X[i]);
          es[i * 3 + 2] = Entry(X[i] + P[i], +1, -(X[i] + P[i]));
        }
        es.sort;

        long maxS = long.min;
        long maxT = long.min;
        {
          long a, b;
          foreach (ref e; es) {
            const x = e.x;
            const y = (a * x + b) - M;
            debug {
              writeln(x, " ", y);
            }
            if (y > 0) {
              chmax(maxS, y + x);
              chmax(maxT, y - x);
            }
            a += e.a;
            b += e.b;
          }
        }

        auto ans = new char[N];
        foreach (i; 0 .. N) {
          const s = P[i] + X[i];
          const t = P[i] - X[i];
          ans[i] = (s >= maxS && t >= maxT) ? '1' : '0';
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}


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

string FMT_F = "%.10f";

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

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

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

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

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

		foreach (i; 0..n/2)
		{
			ans[ti] ~= [1, i+1, n-i];
			ans[ti] ~= [1, i+1, n-i];
			ans[ti] ~= [2, i+1, n-i];
			ans[ti] ~= [1, i+1, n-i];
			ans[ti] ~= [1, i+1, n-i];
			ans[ti] ~= [2, i+1, n-i];
		}
	}

	foreach (e; ans)
	{
		writeln(e.length);
		foreach (ee; e)
			writeln(ee[0], " ", ee[1], " ", ee[2]);
	}
	stdout.flush;
	debug readln;
}

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

void swaptwo(int i, int j)
{
  int opcount = 6;
  int oplist = 0x9;
  while (opcount-- > 0) {
    if (oplist & 1)
      printf("1 %d %d\n", i, j);
    else
      printf("2 %d %d\n", i, j);
    oplist >>= 1;
  }
}

void main()
{
  int t, n;
  readf!" %d"(t);
  while (t--) {
    readf!" %d"(n);
    readln;
    auto a = readln.chomp.split.map!(to!int).array;

    writeln(n / 2 * 6);
    int idx = 1;
    while (idx <= a.length) {
      swaptwo(idx, idx + 1);
      idx += 2;
    }
  }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		writeln (n * 3);
		for (int i = 1; i <= n; i += 2)
		{
			writeln (1, " ", i, " ", i + 1);
			writeln (2, " ", i, " ", i + 1);
			writeln (1, " ", i, " ", i + 1);

			writeln (1, " ", i, " ", i + 1);
			writeln (2, " ", i, " ", i + 1);
			writeln (1, " ", i, " ", i + 1);
		}
	}
}

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

void swaptwo(int i, int j)
{
  int opcount = 6;
  int oplist = 0x9;
  while (opcount-- > 0) {
    if (oplist & 1)
      printf("1 %d %d\n", i, j);
    else
      printf("2 %d %d\n", i, j);
    oplist >>= 1;
  }
}

void main()
{
  int t, n;
  readf!" %d"(t);
  while (t--) {
    readf!" %d"(n);
    readln;
    auto a = readln.chomp.split.map!(to!int).array;

    writeln(n / 2 * 6);
    int idx = 0;
    while (idx < a.length) {
      swaptwo(idx, idx + 1);
      idx += 2;
    }
  }
}


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 solve(const(int) N, const(int[]) P) {
  auto ans = new int[][](N + 2, N + 2);
  foreach (i; 1 .. N + 1) {
    int x = i, y = i;
    ans[x][y] = P[i];
    foreach (_; 1 .. P[i]) {
      if (y - 1 >= 1 && !ans[x][y - 1]) {
        ans[x][y - 1] = P[i];
        --y;
      } else if (x + 1 <= N && !ans[x + 1][y]) {
        ans[x + 1][y] = P[i];
        ++x;
      } else {
        assert(false);
      }
    }
  }
  foreach (i; 1 .. N + 1) {
    foreach (j; 1 .. i + 1) {
      if (j > 1) write(" ");
      write(ans[i][j]);
    }
    writeln;
  }
}

void main() {
  debug {
    foreach (n; 1 .. 8 + 1) {
      auto perm = iota(n + 1).array;
      do {
        writeln(perm);
        solve(n, perm);
      } while (perm[1 .. n + 1].nextPermutation);
    }
  }

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

      solve(N, P);
    }
  } catch (EOFException e) {
  }
}

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

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto p = readln.splitter.map !(to !(int)).array;
		int [] [] answer;
		foreach (i; 0..n)
		{
			answer ~= new int [i + 1];
		}
		foreach (i; 0..n)
		{
			answer[i][i] = p[i];
		}
		foreach (d; 0..n - 1)
		{
			bool shift = false;
			foreach (i; d..n)
			{
				auto value = answer[i][i - d];
				if (value == d + 1)
				{
					shift = true;
				}
				else
				{
					if (shift)
					{
						answer[i][i - d - 1] = value;
					}
					else
					{
						answer[i + 1][i - d] = value;
					}
				}
			}
		}
		writefln !("%(%(%s %)\n%)") (answer);
	}
}


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

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto S = readln.chomp;
    auto A = readln.split.map!(a => a.front.to!dchar).array;

    auto B = new bool[](26);
    foreach (a; A) B[a-'a'] = true;

    long tmp = 0;
    long ans = 0;

    foreach (i; 0..N) {
        if (!B[S[i]-'a']) {
            ans += tmp * (tmp + 1) / 2;
            tmp = 0;
        } else {
            tmp += 1;
        }
    }

    ans += tmp * (tmp + 1) / 2;
    ans.writeln;
}

import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
struct Input
{
  T next(T)()
  {
    import std.conv;
    return to!T(nextWord);
  }
  string nextWord()
  {
    if (_nextWords.empty)
	_nextWords.insertFront(readln().split);
    string word = _nextWords.front; _nextWords.removeFront;
    return word;
  }
  import std.container;
  DList!string _nextWords;
}
Input input;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      static foreach(n; 0 .. T[i].Types.length)
	read(args[i][n]);
    else
      args[i] = input.next!(typeof(args[i]))();
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t; get(t);
      F(t);
    }
}
alias get = read;
void wone(T)(T t, char end)
{
  static if(isArray!T && !is(T == string))
    {
      foreach(i; 0 .. t.length - 1)
	  write(t[i], ' ');
      write(t[$ - 1], end);
    }
  else
      write(t, end);
}
void wr(T...)(T t)
{
  static foreach(i; 0 .. T.length)
    static if(i + 1 < T.length)
      wone(t[i], ' ');
    else
      wone(t[i], '\n');
}
void ans(T...)(T t)
{
  import core.stdc.stdlib;
  wr(t);
  exit(0);
}
void main()
{
  int n, k; get(n, k);
  string str; get(str);
  bool[26] ap = false;
  foreach(i; 0 .. k)
    {
      string r; get(r);
      ap[r[0] - 'a'] = true;
    }
  int i = 0;
  long res = 0;
  for(; i < str.length;)
    {
      long count = 0;
      while(i < str.length && ap[str[i] - 'a'])
	{
	  count++;
	  i++;
	}
      res += count * (count + 1) / 2;
      if(!count)
	i++;
    }
  ans(res);
}

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

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

void solve(){
	int n = rint, k = rint;
	string s = rstring;
	char[] cs = readln.chomp.split.join.to!(char[]);

	bool[char] cset;
	foreach(c; cs) cset[c] = 1;

	long ans;
	long t;
	foreach(c; s){
		if(c !in cset){
			ans += t * (t + 1) / 2;
			t = 0;
		}
		else{
			t += 1;
		}
	}
	ans += t * (t + 1) / 2;

	ans.writeln;
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto n = RD!int;
	auto k = RD!int;
	auto s = RD!string;
	bool[char] set;
	foreach (i; 0..k)
	{
		auto c = RD!string;
		set[c[0]] = true;
	}

	long ans;
	long cnt;
	foreach (c; s)
	{
		if (set.get(c, false))
			++cnt;
		else
		{
			ans += cnt * (cnt+1) / 2;
			cnt = 0;
		}
	}
	ans += cnt * (cnt+1) / 2;
	cnt = 0;

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

import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
struct Input
{
  T next(T)()
  {
    import std.conv;
    return to!T(nextWord);
  }
  string nextWord()
  {
    if (_nextWords.empty)
	_nextWords.insertFront(readln().split);
    string word = _nextWords.front; _nextWords.removeFront;
    return word;
  }
  import std.container;
  DList!string _nextWords;
}
Input input;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      static foreach(n; 0 .. T[i].Types.length)
	read(args[i][n]);
    else
      args[i] = input.next!(typeof(args[i]))();
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t; get(t);
      F(t);
    }
}
alias get = read;
void wone(T)(T t, char end)
{
  static if(isArray!T && !is(T == string))
    {
      foreach(i; 0 .. t.length - 1)
	  write(t[i], ' ');
      write(t[$ - 1], end);
    }
  else
      write(t, end);
}
void wr(T...)(T t)
{
  static foreach(i; 0 .. T.length)
    static if(i + 1 < T.length)
      wone(t[i], ' ');
    else
      wone(t[i], '\n');
}
void ans(T...)(T t)
{
  import core.stdc.stdlib;
  wr(t);
  exit(0);
}
void main()
{
  int n, k; get(n, k);
  string str; get(str);
  bool[26] ap = false;
  foreach(i; 0 .. k)
    {
      string r; get(r);
      ap[r[0] - 'a'] = true;
    }

  int i = 0;
  long res = 0;
  for(; i < str.length; i++)
    {
      int count = 0;
      while(i < str.length && ap[str[i] - 'a'])
	{
	  count++;
	  i++;
	}
      res += count * (count + 1) / 2;
    }
  ans(res);
}

import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
struct Input
{
  T next(T)()
  {
    import std.conv;
    return to!T(nextWord);
  }
  string nextWord()
  {
    if (_nextWords.empty)
	_nextWords.insertFront(readln().split);
    string word = _nextWords.front; _nextWords.removeFront;
    return word;
  }
  import std.container;
  DList!string _nextWords;
}
Input input;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      static foreach(n; 0 .. T[i].Types.length)
	read(args[i][n]);
    else
      args[i] = input.next!(typeof(args[i]))();
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t; get(t);
      F(t);
    }
}
alias get = read;
void wone(T)(T t, char end)
{
  static if(isArray!T && !is(T == string))
    {
      foreach(i; 0 .. t.length - 1)
	  write(t[i], ' ');
      write(t[$ - 1], end);
    }
  else
      write(t, end);
}
void wr(T...)(T t)
{
  static foreach(i; 0 .. T.length)
    static if(i + 1 < T.length)
      wone(t[i], ' ');
    else
      wone(t[i], '\n');
}
void ans(T...)(T t)
{
  import core.stdc.stdlib;
  wr(t);
  exit(0);
}
void main()
{
  int n, k; get(n, k);
  string str; get(str);
  bool[26] ap = false;
  foreach(i; 0 .. k)
    {
      string r; get(r);
      ap[r[0] - 'a'] = true;
    }
  int i = 0;
  long res = 0;
  for(; i < str.length;)
    {
      int count = 0;
      while(i < str.length && ap[str[i] - 'a'])
	{
	  count++;
	  i++;
	}
      res += count * (count + 1) / 2;
      if(!count)
	i++;
    }
  ans(res);
}


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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto p = readln.splitter.map !(to !(int)).array;
		p[] -= 1;
		auto board = new char [] [] (n, n);
		foreach (ref line; board)
		{
			line[] = '.';
		}

		auto b = new bool [n];
		int k = 1;
		int res = 0;
		int prev = -1;
		foreach (i; 0..n)
		{
			if (i == p[i])
			{
				res += 1;
			}
			if (i != p[i] && !b[i])
			{
				int m = k;
				b[i] = true;
				int j = i;
				int last = -1;
				do
				{
					res += 1;
					debug {writeln ("?", k, " ", j);}
					if (j < p[j])
					{
						board[k][j] = '/';
						board[k][p[j]] = '/';
					}
					else
					{
						board[k][j] = '\\';
						board[k][p[j]] = '\\';
					}
					k += 1;
					last = j;
					j = p[j];
					b[j] = true;
				}
				while (p[j] != i);

				if (prev != -1)
				{
					res += 1;
					board[k][j] = '\\';
					board[k][prev] = '\\';
					board[0][prev] = '/';
					board[0][i] = '/';
					k += 1;
				}
				prev = i;

				debug {writeln (m, " ", k, "!");}
				bringToFront (board[1..m], board[m..k]);
			}
		}

		writeln (res);
		writefln ("%-(%s\n%)", board);
	}
}

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

void main ()
{
	auto n = readln.strip.to !(int);
	auto p = readln.splitter.map !(to !(int)).array;
	p[] -= 1;
	auto board = new char [] [] (n, n);
	foreach (ref line; board)
		line[] = '.';

	auto b = new bool [n];
	int k = 1, res = 0, prev = -1;
	foreach (i; 0..n)
	{
		res += (i == p[i]);
		if (i != p[i] && !b[i])
		{
			int m = k, j = i;
			b[i] = true;
			do
			{
				res += 1;
				auto dir = "\\/"[j < p[j]];
				board[k][j] = dir;
				board[k][p[j]] = dir;
				k += 1;
				j = p[j];
				b[j] = true;
			}
			while (p[j] != i);

			if (prev != -1)
			{
				res += 1;
				board[k][j] = '\\';
				board[k][prev] = '\\';
				board[0][prev] = '/';
				board[0][i] = '/';
				k += 1;
			}
			prev = i;

			bringToFront (board[1..m], board[m..k]);
		}
	}

	writeln (res);
	writefln ("%-(%s\n%)", board);
}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto p = readln.splitter.map !(to !(int)).array;
		p[] -= 1;
		auto board = new char [] [] (n, n);
		foreach (ref line; board)
		{
			line[] = '.';
		}

		auto b = new bool [n];
		int k = 0;
		int res = 0;
		foreach (i; 0..n)
		{
			if (i == p[i])
			{
				res += 1;
			}
			if (i != p[i] && !b[i])
			{
				b[i] = true;
				int j = p[i];
				do
				{
					b[j] = true;
					res += 1;
					if (j < p[j])
					{
						board[k][j] = '/';
						board[k][p[j]] = '/';
					}
					else
					{
						board[k][j] = '\\';
						board[k][p[j]] = '\\';
					}
					k += 1;
					j = p[j];
				}
				while (j != i);
			}
		}

		writeln (res);
		writefln ("%-(%s\n%)", board);
	}
}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto p = readln.splitter.map !(to !(int)).array;
		p[] -= 1;
		auto board = new char [] [] (n, n);
		foreach (ref line; board)
		{
			line[] = '.';
		}

		auto b = new bool [n];
		int k = 0;
		foreach (i; 0..n)
		{
			if (i != p[i] && !b[i])
			{
				b[i] = true;
				int j = p[i];
				do
				{
					b[j] = true;
					if (j < p[j])
					{
						board[k][j] = '/';
						board[k][p[j]] = '/';
					}
					else
					{
						board[k][j] = '\\';
						board[k][p[j]] = '\\';
					}
					k += 1;
					j = p[j];
				}
				while (j != i);
			}
		}
		writefln ("%-(%s\n%)", board);
	}
}


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()
{
    immutable int mxcost = 101;

    int n, m, q;
    readf("%s %s %s", &n, &m, &q);
    readln;

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

    auto cnt = new int[] (1 << n);
    foreach (_; 0 .. m) {
        auto x = readln.chomp.to!(int)(2);
        ++cnt[x];
    }

    auto v = new int[][] (1 << n, mxcost+1);
    foreach (e; 0 .. 1 << n) {
        foreach (o; e .. 1 << n) {
            auto xr = e ^ o;
            auto cost = 0;
            foreach (b; 0 .. n) {
                if ((xr & (1 << b)) == 0) cost += w[b];
            }
            cost = min(cost, mxcost);

            v[e][cost] += cnt[o];
            if (e != o) v[o][cost] += cnt[e];
        }
    }

    foreach (e; 0 .. 1 << n) {
        foreach (i; 0 .. mxcost) v[e][i+1] += v[e][i];

    }

    debug { v.each!(arr => arr.take(20).writeln); }

    while (q--) {
        auto line = readln.splitter;
        auto x = line.front.to !(int) (2);
        line.popFront ();
        auto k = line.front.to !(int);
        /*
        string t; int k;
        readf("%s %s", &t, &k);
        readln;
        auto x = t.to!(int)(2);
        */
        v[x][k].writeln;
    }

}

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

void main()
{
    immutable int mxcost = 101;

    int n, m, q;
    readf("%s %s %s", &n, &m, &q);
    readln;

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

    auto cnt = new int[] (1 << n);
    foreach (_; 0 .. m) {
        auto x = readln.chomp.to!(int)(2);
        ++cnt[x];
    }

    auto v = new int[][] (1 << n, mxcost+1);
    foreach (e; 0 .. 1 << n) {
        foreach (o; e .. 1 << n) {
            auto xr = e ^ o;
            auto cost = 0;
            foreach (b; 0 .. n) {
                if ((xr & (1 << b)) == 0) cost += w[b];
            }
            cost = min(cost, mxcost);

            v[e][cost] += cnt[o];
            if (e != o) v[o][cost] += cnt[e];
        }
    }

    foreach (ref rw; v) {
        rw = rw.cumulativeFold!((a, b) => a + b).array;
    }

    debug { v.each!(arr => arr.take(20).writeln); }

    while (q--) {
        string t; int k;
        readf("%s %s", &t, &k);
        readln;
        auto x = t.to!(int)(2);
        v[x][k].writeln;
    }

}

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

void main()
{
    immutable int mxcost = 101;

    int n, m, q;
    readf("%s %s %s", &n, &m, &q);
    readln;

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

    auto cnt = new int[] (1 << n);
    foreach (_; 0 .. m) {
        auto x = readln.chomp.to!(int)(2);
        ++cnt[x];
    }

    auto v = new int[][] (1 << n, mxcost+1);
    foreach (e; 0 .. 1 << n) {
        foreach (o; e .. 1 << n) {
            auto xr = e ^ o;
            auto cost = 0;
            foreach (b; 0 .. n) {
                if ((xr & (1 << b)) == 0) cost += w[b];
            }
            cost = min(cost, mxcost);

            v[e][cost] += cnt[o];
            if (e != o) v[o][cost] += cnt[e];
        }
    }

    foreach (ref rw; v) {
        rw = rw.cumulativeFold!((a, b) => a + b).array;
    }

    debug { v.each!(arr => arr.take(20).writeln); }

    while (q--) {
        auto line = readln.splitter;
        auto x = line.front.to !(int) (2);
        line.popFront ();
        auto k = line.front.to !(int);
        /*
        string t; int k;
        readf("%s %s", &t, &k);
        readln;
        auto x = t.to!(int)(2);
        */
        v[x][k].writeln;
    }

}

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

immutable int limit = 102;

void main ()
{
	int n, m, q;
	while (readf (" %s %s %s", &n, &m, &q) > 0)
	{
		readln;
		auto w = readln.splitter.map !(to !(int)).array;
		reverse (w);
		auto num = new int [1 << n];
		foreach (i; 0..m)
		{
			auto b = readln.strip.to !(int) (2);
			num[b] += 1;
		}
		debug {writeln (num);}

		auto numAtCost = new int [] [] (1 << n, limit + 1);
		foreach (s; 0..1 << n)
		{
			foreach (t; s..1 << n)
			{
				int cost = 0;
				auto r = s ^ t;
				foreach (k; 0..n)
				{
					if (!((r >> k) & 1))
					{
						cost += w[k];
					}
				}
				cost = min (cost, limit);
				numAtCost[s][cost] += num[t];
				if (s < t)
				{
					numAtCost[t][cost] += num[s];
				}
			}
		}

		foreach (s; 0..1 << n)
		{
			foreach (cost; 0..limit)
			{
				numAtCost[s][cost + 1] += numAtCost[s][cost];
			}
			debug {writeln (s, ": ", numAtCost[s]);}
		}

		foreach (j; 0..q)
		{
			auto v = readln.splitter;
			auto b = v.front.to !(int) (2);
			v.popFront ();
			auto k = v.front.to !(int);
			debug {writeln (b, ", ", k, ": ");}
			writeln (numAtCost[b][k]);
		}
	}
}

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 LIM = 105;

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

      int readIt() {
        const str = readToken();
        int ret;
        foreach (i; 0 .. N) {
          ret |= (str[i] - '0') << i;
        }
        return ret;
      }

      auto S = new int[M];
      foreach (j; 0 .. M) {
        S[j] = readIt();
      }
      auto T = new int[Q];
      auto K = new int[Q];
      foreach (q; 0 .. Q) {
        T[q] = readIt();
        K[q] = readInt();
      }

      auto WSum = new int[1 << N];
      foreach (i; 0 .. N) {
        foreach (h; 0 .. 1 << i) {
          WSum[h | 1 << i] = WSum[h] + W[i];
        }
      }

      auto cnt = new int[1 << N];
      foreach (j; 0 .. M) {
        ++cnt[S[j]];
      }
      auto anss = new int[][](1 << N, LIM);
      foreach (t; 0 .. 1 << N) {
        foreach (s; 0 .. 1 << N) {
          const w = WSum[((1 << N) - 1) ^ s ^ t];
          if (w < LIM) {
            anss[t][w] += cnt[s];
          }
        }
        foreach (k; 1 .. LIM) {
          anss[t][k] += anss[t][k - 1];
        }
      }

      foreach (q; 0 .. Q) {
        writeln(anss[T[q]][K[q]]);
      }
    }
  } 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()
{
    immutable int mxcost = 100;

    int n, m, q;
    readf("%s %s %s", &n, &m, &q);
    readln;

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

    auto cnt = new int[] (1 << n);
    foreach (_; 0 .. m) {
        auto x = readln.chomp.to!(int)(2);
        ++cnt[x];
    }

    auto v = new int[][] (1 << n, mxcost+1);
    foreach (e; 0 .. 1 << n) {
        foreach (o; e .. 1 << n) {
            auto xr = e ^ o;
            auto cost = 0;
            foreach (b; 0 .. n) {
                if ((xr & (1 << b)) != 0) cost += w[b];
            }
            cost = min(cost, mxcost);

            v[e][cost] += cnt[o];
            if (e != o) v[o][cost] += cnt[e];
        }
    }

    foreach (e; 0 .. 1 << n) {
        foreach (i; 0 .. mxcost) v[e][i+1] += v[e][i];

    }

    debug { v.each!(arr => arr.take(20).writeln); }

    while (q--) {
        auto line = readln.splitter;
        auto x = line.front.to !(int) (2);
        line.popFront ();
        auto k = line.front.to !(int);
        /*
        string t; int k;
        readf("%s %s", &t, &k);
        readln;
        auto x = t.to!(int)(2);
        */
        v[x][k].writeln;
    }

}

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

void main()
{
    immutable int mxcost = 100;

    int n, m, q;
    readf("%s %s %s", &n, &m, &q);
    readln;

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

    auto cnt = new int[] (1 << n);
    foreach (_; 0 .. m) {
        auto x = readln.chomp.to!(int)(2);
        ++cnt[x];
    }

    auto v = new int[][] (1 << n, mxcost+1);
    foreach (e; 0 .. 1 << n) {
        foreach (o; e .. 1 << n) {
            auto xr = e ^ o;
            auto cost = 0;
            foreach (b; 0 .. n) {
                if ((xr & (1 << b)) == 0) cost += w[b];
            }
            cost = min(cost, mxcost);

            v[e][cost] += cnt[o];
            if (e != o) v[o][cost] += cnt[e];
        }
    }

    foreach (e; 0 .. 1 << n) {
        foreach (i; 0 .. mxcost) v[e][i+1] += v[e][i];

    }

    debug { v.each!(arr => arr.take(20).writeln); }

    while (q--) {
        auto line = readln.splitter;
        auto x = line.front.to !(int) (2);
        line.popFront ();
        auto k = line.front.to !(int);
        /*
        string t; int k;
        readf("%s %s", &t, &k);
        readln;
        auto x = t.to!(int)(2);
        */
        v[x][k].writeln;
    }

}