import std.stdio;
import std.algorithm.comparison;
import std.algorithm.sorting;
import std.algorithm.searching;
import std.algorithm.mutation;
import std.string;
import std.range;
import std.range.primitives;
import std.conv;

int main() {
    debug stdin = File("in.txt", "r");

    int[100_000] arr, ht;
    int n;
    int curht = 0, maxht = 0;
    readf(" %s\n", &n);
    foreach ( i ; 0 .. n ) {
        readf(" %s", &arr[i]);
        if (arr[i] > curht) ++curht;
        else curht = arr[i];
        ht[i] = curht;
    }
    curht = 0;
    foreach_reverse ( i ; 0 .. n ) {
        if (arr[i] > curht) ++curht;
        else curht = arr[i];
        int joinht = min(curht, ht[i]);
        if (joinht > maxht) maxht = joinht;
    }
    writeln(maxht);

    return 0;
}

import std.stdio;
import std.algorithm.comparison;
import std.algorithm.sorting;
import std.algorithm.searching;
import std.algorithm.mutation;
import std.string;
import std.range;
import std.range.primitives;
import std.conv;

int main() {
    debug stdin = File("in.txt", "r");

    int[100_000] arr, ht;
    int n;
    int curht = 0, maxht = 0;
    readf(" %s\n", &n);
    foreach ( i ; 0 .. n ) {
        readf(" %s", &arr[i]);
        if (arr[i] > curht) {
            ++curht;
            if (curht > maxht) maxht = curht;
        }
        else curht = arr[i];
        ht[i] = curht;
    }
    curht = 0;
    foreach_reverse ( i ; 0 .. n ) {
        if (arr[i] > curht) {
            ++curht;
            if (curht > maxht) maxht = curht;
        }
        else curht = arr[i];
        int joinht = min(curht, ht[i]) * 2;
        if (joinht > maxht) maxht = joinht;
    }
    ++maxht;
    maxht /= 2;
    writeln(maxht);

    return 0;
}

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

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

    auto d = new int[](n);
    d.fill(INF);

    void go(int[] h, int[] d) {
        int cur = 1;
        foreach (i, e; h) {
            cur = min(cur, e);
            d[i] = min(cur, d[i]);
            cur += 1;
        }
    }

    go(h, d);

    h.reverse();
    d.reverse();
    go(h, d);

    int ans = d.maxElement;
    ans.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 long INF = 10L ^^ 18 + 23;

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

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

    auto d = new int[](n);
    int cur = 1;
    foreach (i, e; h) {
        cur = min(cur, e);
        d[i] = cur;
        cur += 1;
    }

    cur = 1;
    foreach_reverse (i, e; h) {
        cur = min(cur, e);
        d[i] = min(d[i], cur);
        cur += 1;
    }

    int ans = d.maxElement;
    ans.writeln;
}

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

void main ()
{
	int n;
	while (readf (" %s ", &n) > 0)
	{
		auto a = readln.split.map !(to !(int)).array;
		auto lo = new int [n];
		lo.front = 1;
		foreach (i; 1..n)
		{
			lo[i] = min (lo[i - 1] + 1, a[i]);
		}

		auto hi = new int [n];
		hi.back = 1;
		foreach_reverse (i; 0..n - 1)
		{
			hi[i] = min (hi[i + 1] + 1, a[i]);
		}

		int res = 0;
		foreach (i; 0..n)
		{
			res = max (res, min (lo[i], hi[i]));
		}

		writeln (res);
	}
}


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

  int n;
  rd(n);
  struct P {
    int y, x;
  }

  auto xs = new int[](n), ys = new int[](n);
  bool[P] seen;
  foreach (i; 0 .. n) {
    rd(xs[i], ys[i]);
    if (i > 0) {
      seen[P(xs[i], ys[i])] = true;
    }
  }
  auto vy = new int[](n), vx = new int[](n);
  foreach (i; 0 .. n) {
    rd(vx[i], vy[i]);
  }
  foreach (i; 0 .. n) {
    auto tx = xs[0] + vx[i], ty = ys[0] + vy[i];
    foreach (j; 0 .. n) {
      if (i != j) {
        auto p = P(tx - vx[j], ty - vy[j]);
        if ((p in seen) == null || !seen[p]) {
          goto hell;
        }
        seen[p] = false;
      }
    }
    writeln(tx, " ", ty);
    return;
  hell:
    // revert
    foreach (j; 1 .. n) {
      seen[P(xs[j], ys[j])] = true;
    }
  }
  import std.exception : enforce;

  enforce(false);
}

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

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

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

alias Point = Tuple!(int, "x", int, "y");

void main() {
    int n;
    scan(n);

    auto xys = new Point[](n);
    auto abs = new Point[](n);

    foreach (i ; 0 .. n) {
        int x, y;
        scan(x, y);
        xys[i] = Point(x, y);
    }

    foreach (i ; 0 .. n) {
        int a, b;
        scan(a, b);
        abs[i] = Point(a, b);
    }

    int[Point] cnt;

    foreach (i ; 0 .. n) {
        foreach (j ; 0 .. n) {
            int xx = xys[i].x + abs[j].x;
            int yy = xys[i].y + abs[j].y;

            cnt[Point(xx, yy)]++;

            if (cnt[Point(xx, yy)] == n) {
                writefln("%d %d", xx, yy);
                return;
            }
        }
    }

}

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

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

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

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

void main() {
    auto N = readln.chomp.to!int;
    auto X = new long[](N);
    auto Y = new long[](N);
    auto A = new long[](N);
    auto B = new long[](N);
    foreach (i; 0..N) {
        auto s = readln.split.map!(to!long);
        X[i] = s[0];
        Y[i] = s[1];
    }
    foreach (i; 0..N) {
        auto s = readln.split.map!(to!long);
        A[i] = s[0];
        B[i] = s[1];
    }

    long[long][long] mp;
    foreach (i; 0..N) {
        foreach (j; 0..N) {
            long x = X[i] + A[j];
            long y = Y[i] + B[j];
            mp[x][y] += 1;
        }
    }

    foreach (x; mp.keys) {
        foreach (y; mp[x].keys) {
            if (mp[x][y] == N) {
                writeln(x, " ", y);
                return;
            }
        }
    }
}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		long x = 0;
		long y = 0;
		foreach (i; 0..n * 2)
		{
			int u, v;
			readf (" %s %s", &u, &v);
			x += u;
			y += v;
		}
		writeln (x / n, " ", y / n);
	}
}


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 k = next!long;
  auto d = next!int;
  // k ^ d >= n
  long pot = 1;
  bool possible = false;
  foreach(p; 0 .. d + 1)
    {
      if (pot >= n) {possible = true; break;}
      pot *= k;
    }
  if (!possible) return writeln(-1);
  auto res = new long[][](d, n);
  foreach(i; 0 .. d) res[i][0] = 0;
  foreach(j; 1 .. n)
    {
      long carry = 1;
      foreach(i; 0 .. d)
	{
	  if (carry)
	    {
	      res[i][j] = res[i][j - 1] + carry;
	      if (res[i][j] == k)
		{
		  res[i][j] = 0;
		  carry = 1;
		}
	      else
		{
		  carry = 0;
		}
	    }
	  else
	    {
	      res[i][j] = res[i][j - 1];
	    }
	}
      assert(carry == 0);
    }
  foreach(row; res)
    {
      foreach(elem; row)
	{
	  write(elem + 1, " ");
	}
      writeln;
    }
}

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.string;
import std.bigint;
import std.array;
import std.ascii;
import std.math;
import std.numeric;
import std.algorithm;
import std.container;
import std.conv;
import core.bitop;

alias Int = int;
immutable Int N_MAX = pow(10, 3) + 11;
immutable Int D_MAX = pow(10, 3) + 11;
immutable Int K_MAX = pow(10, 9) + 11;

Int T[D_MAX][N_MAX];

mixin template Inputter() {
  Int N;
  Int K;
  Int D;

  bool input(T)(T s) {
    if ( readf(" %s %s %s", &N, &K, &D) ) {
      debug writefln("N = %s, K = %s, D = %s", N, K, D);
      return true;
    }
    return false;
  }
}

mixin template Outputter() {
  bool ok;

  void output() {
    if ( ok ) {
      foreach ( i; 0 .. D ) {
        foreach ( j; 0 .. N ) {
          writef("%s ", T[i][j]);
        }
        writeln("");
      }
    } else {
      writefln("-1");
    }
  }
}

mixin template Solver() {
  void init() {
  }

  void solve() {
    foreach ( i; 0 .. D ) {
      T[i][0] = 1;
    }
    ok = find(1);
  }

  bool find( int c ) {
    debug writefln("@find: c = %s", c);
    if ( c >= N ) return true;
    foreach ( i; 0 .. D ) {
      T[i][c] = T[i][c - 1];
    }
    if ( ! add(c, 0) ) return false;
    return find(c + 1);
  }

  bool add( int c, int r ) {
    if ( r >= D ) return false;
    debug writefln("@add: c = %s, r = %s", c, r);
    if ( T[r][c] + 1 > K ) {
      T[r][c] = 1;
      return add(c, r + 1);
    }
    T[r][c] ++;
    return true;
  }
}

// Runner {{{
mixin template Runner() {
  void run() {
    while ( input(stdin) ) {
      init();
      solve();
      output();
    }
  }
}
// }}}

// Solution {{{
struct Solution {
  mixin Solver;
  mixin Inputter;
  mixin Outputter;
  mixin Runner;
}
// }}}

// main() {{{
Solution s;
void main() {
  s.run();
}
// }}}


import std.algorithm, std.range, std.stdio, std.string;
void main () {
	readln;
	int n, k;
	while (readf !(" %s %s") (n, k) > 0) {
		writeln (!!(k % n) * 2);
		writefln !("%(%(%d%)\n%)") (n.iota.map !(r =>
		    n.iota.map !(c => ((r + c) % n * n + r < k))));
	}
}

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

DList!string _words;
void read(T)(out T t)
{
  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;
  t = to!T(word);
}

void main()
{
  int t;
  read(t);
  while(t--)
    {
      int n, k;
      read(n), read(k);
      auto qperrow = new int[cast(size_t)n];
      foreach(i; 0 .. k % n)
        qperrow[i] = k / n + 1;
      foreach(i; k % n .. n)
        qperrow[i] = k / n;
      auto res = new int[][cast(size_t)n];
      foreach(ref row; res)
        {
          row = new int[cast(size_t)n];
          row[] = 0;
        }
      int cnt = 0;
      int rcnt = 0;
      int i = 0;
      int j = 0;
      while(cnt < k)
        {
          if (rcnt == qperrow[i])
            {
              i++;
              rcnt = 0;
            }
          res[cast(size_t)i][cast(size_t)j] = 1;
          j++; j %= n;
          rcnt++;
          cnt++;
        }
      if (k % n == 0)
        {
          writeln(0);
        }
      else
        {
          writeln(2);
        }
      foreach(row; res)
        {
          foreach(cell; row)
            write(cell);
          writeln;
        }
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		a[ti] = new char[][](n, n);
		ans[ti] = k % n == 0 ? 0 : 2;

		foreach (i; 0..n)
		{
			foreach (j; 0..n)
				a[ti][i][j] = '0';
		}

		(){
		foreach (i; 0..n)
		{
			foreach (j; 0..n)
			{
				if (k == 0) return;
				a[ti][j][(i+j)%n] = '1';
				--k;
			}
		}}();
	}

	foreach (ti, e; ans)
	{
		writeln(e);
		foreach (ee; a[ti])
			writeln(ee);
	}

	stdout.flush;
	debug readln;
}

import std.algorithm, std.range, std.stdio;
void main() {
	readln;
	int n, k;
	while (readf!" %s %s"(n, k) > 0)
		writefln!"%s\n%(%(%d%)\n%)"(!!(k % n) * 2,
			n.iota.map!(r => n.iota.map!(c => ((r + c) % n * n + r < k))));
}

import std.algorithm, std.range, std.stdio;
void main () {
	readln;
	int n, k;
	while (readf !(" %s %s") (n, k) > 0)
		writefln !("%s\n%(%(%d%)\n%)") (!!(k % n) * 2,
			n.iota.map !(r => n.iota.map !(c => ((r + c) % n * n + r < k))));
}

import std.algorithm, std.range, std.stdio, std.string;
void main () {
	readln;
	int n, k;
	while (readf !(" %s %s") (n, k) > 0) {
		writefln !("%(%(%d%)\n%)") (n.iota.map !(r =>
		    n.iota.map !(c => ((r + c) % n * n + r < k))));
	}
}


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

void solve()
{
    auto n = readln.chomp.to!int;
    auto S = readln.chomp.to!(char[]);
    int r, s;
    foreach (c; S) {
        if (c == '<') r = 0;
        else ++r;
    }
    foreach_reverse (c; S) {
        if (c == '>') s = 0;
        else ++s;
    }
    writeln(min(r, s));
}

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

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 solve() {
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;
    int ans = 1 << 29;
    foreach (i; 0..N) {
        if (S[i] == '>' || S[N - i - 1] == '<') {
            ans = i;
            break;
        }
    }
    ans.writeln;
}

void main() {
    auto T = readln.chomp.to!int;
    while (T--) solve;
}

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

void solve()
{
    auto n = readln.chomp.to!int;
    auto S = readln.chomp.to!(char[]);
    foreach (i, c; S) {
        if (c == '>') {
            writeln(min(i, n-i));
            return;
        }
    }
    writeln("0");
    return;
}

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


import std.stdio;
import std.math;

/// Template for power function. Returns a^n.
pure T pow(T)(const T a, uint n) {
	T res = 1;
	T x = a;
	while (0 != n) {
		if (1 == n % 2) {
			res *= x;
		}
		x *= x;
		n /= 2;
	}
	return res;
}

bool eq(const double a, const double b,  const double EPS = 1E-7) {
	return abs(a - b) <= EPS;
}

unittest {
	assert(243 == pow!int(3, 5));
	assert(1 == pow!uint(234, 0));
	assert(4 == pow!ulong(2, 2));
	assert(256 == pow!long(2, 8));
	assert(161051 == pow!ulong(11, 5));
}

pure double solve(const uint m, const uint n) {
	double res = 0.0;
	foreach(i; 0 .. m) {
		res += (i + 1) * (pow!double(cast(double)(i + 1) / m, n) - pow!double(cast(double)i / m, n));
	}
	return res;
}

unittest {
	assert(eq(3.5, solve(6, 1)));
	assert(eq(4.958333333333, solve(6, 3)));
	assert(eq(1.75, solve(2, 2)));
}

int main(string[] argv) {
	uint m = 0;
	uint n = 0;
	readf(" %s %s", &m, &n);
	writefln("%.7f", solve(m, n));
    return 0;
}

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 m;
	int n;
	while (readf (" %s %s", &m, &n) > 0)
	{
		real res = 0.0;
		real p = 1.0;
		for (int i = m; i >= 1; i--)
		{
			real temp = (i - 1.0L) / i;
			temp = 1.0L - pow (temp, n);
			res += temp * p * i;
			p *= 1.0L - temp;
		}
		writefln ("%.20f", res);
	}
}

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

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

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

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

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

int M, N;

void main(string[] args) {
	try {
	for (; ; ) {
		M = readInt;
		N = readInt;
		real ans = 0.0;
		foreach (x; 0 .. M) {
			ans += 1.0 - (x / cast(real)(M)) ^^ N;
		}
		writefln("%.10f", ans);
	}
	} catch (EOFException) {}
}


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

int N;
int[] A, B;

int[][] G;
int[] sz;

void dfsSz(int u, int p) {
  sz[u] = 1;
  foreach (i; G[u]) {
    const v = A[i] ^ B[i] ^ u;
    if (v != p) {
      dfsSz(v, u);
      sz[u] += sz[v];
    }
  }
}

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

      G = new int[][N];
      foreach (i; 0 .. N - 1) {
        G[A[i]] ~= i;
        G[B[i]] ~= i;
      }
      sz = new int[N];
      dfsSz(0, -1);

      int[] rs;
      for (int u = 0; ; ) {
        int vm = -1;
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (vm == -1 || sz[vm] < sz[v]) {
            vm = v;
          }
        }
        if (vm == -1 || sz[u] >= 2 * sz[vm]) {
          rs ~= u;
          if (sz[u] == 2 * sz[vm]) {
            rs ~= vm;
          }
          break;
        } else {
          sz[u] -= sz[vm];
          sz[vm] += sz[u];
          u = vm;
        }
      }
      debug {
        writeln("rs = ", rs);
      }

      int[][] ans;
      auto par = new int[N];
      foreach (r; rs) {
        foreach (j; G[r]) {
          const s = A[j] ^ B[j] ^ r;
          if (rs.count(s) == 0) {
            int[] us;
            void dfs(int u, int p) {
              us ~= u;
              par[u] = p;
              foreach (i; G[u]) {
                const v = A[i] ^ B[i] ^ u;
                if (v != p) {
                  dfs(v, u);
                }
              }
            }
            dfs(s, r);
            debug {
              writeln(r, " ", s, " ", us);
            }
            int now = s;
            foreach (u; us) {
              if (par[u] != r) {
                ans ~= [r, now, u];
                now = u;
                ans ~= [u, par[u], s];
              }
            }
            ans ~= [r, now, s];
          }
        }
      }

      ans = ans.filter!(row => (row[1] != row[2])).array;

      writeln(ans.length);
      foreach (row; ans) {
        writeln(row[0] + 1, " ", row[1] + 1, " ", row[2] + 1);
      }
    }
  } catch (EOFException e) {
  }
}

/+ dub.sdl:
    name "C"
    dependency "dcomp" version=">=0.6.0"
+/

import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;

int main() {
    auto sc = new Scanner(stdin);
    int n;
    sc.read(n);
    int[][] g = new int[][](n);
    foreach (i; 0..n-1) {
        int a, b;
        sc.read(a, b); a--; b--;
        g[a] ~= b;
        g[b] ~= a;
    }
    bool[] isCent = new bool[n];
    int[] sz = new int[n];
    void dfs(int p, int b) {
        sz[p] = 1; isCent[p] = true;
        foreach (d; g[p]) {
            if (d == b) continue;
            dfs(d, p);
            sz[p] += sz[d];
            if (sz[d] > n/2) isCent[p] = false;
        }
        if (n - sz[p] > n/2) isCent[p] = false;
    }
    dfs(0, -1);

//    writeln(isCent);

    Appender!(int[]) ap;
    int[] par = new int[n];
    void sea(int p, int b) {
        par[p] = b;
        ap ~= p;
        foreach (d; g[p]) {
            if (d == b) continue;
            sea(d, p);
        }
    }
    int[3][] res;
    foreach (i; 0..n) {
        if (!isCent[i]) continue;
        foreach (j; g[i]) {
            if (isCent[j]) continue;
//            writeln(i, " -> ", j);
            ap.clear();
            sea(j, i);
            int p = j;
            foreach (d; ap.data) {
                if (d == j) continue;
                res ~= [i, p, d]; p = d;
                res ~= [d, par[d], j];
            }
            res ~= [i, p, j];
        }
    }

    writeln(res.length);
    foreach (v; res) {
        writeln(v[].map!(x => (x+1).to!string).join(" "));
    }
    return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;

static if (__VERSION__ <= 2070) {
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            import std.algorithm : reduce;
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                import std.typecons : tuple;
                return reduce!fun(tuple(seed), r);
            }
        }
    }

}
version (X86) static if (__VERSION__ < 2071) {
    import core.bitop : bsf, bsr, popcnt;
    int bsf(ulong v) {
        foreach (i; 0..64) {
            if (v & (1UL << i)) return i;
        }
        return -1;
    }
    int bsr(ulong v) {
        foreach_reverse (i; 0..64) {
            if (v & (1UL << i)) return i;
        }
        return -1;
    }
    int popcnt(ulong v) {
        int c = 0;
        foreach (i; 0..64) {
            if (v & (1UL << i)) c++;
        }
        return c;
    }
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray;
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            if (f.eof) return false;
            line = lineBuf[];
            f.readln(line);
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {

                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else {
                auto buf = line.split.map!(to!E).array;
                static if (isStaticArray!T) {

                    assert(buf.length == T.length);
                }
                x = buf;
                line.length = 0;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

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

int N;
int[] A, B;

int[][] G;
int[][] ans;

void solveCentroidDecomp() {
  auto sz = new int[N];
  auto del = new bool[N];
  void dfsSz(int u, int p) {
    sz[u] = 1;
    foreach (i; G[u]) {
      const v = A[i] ^ B[i] ^ u;
      if (v != p) {
        dfsSz(v, u);
        sz[u] += sz[v];
      }
    }
  }
  dfsSz(0, -1);

  // r: centroid
  void solveSubtree(int r) {
    debug {
      string dfsDebug(int u, int p) {
        string ret = u.to!string;
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v] && v != p) {
            ret ~= "(" ~ dfsDebug(v, u) ~ ")";
          }
        }
        return ret;
      }
      writeln("solveSubtree ", dfsDebug(r, -1));
    }
    //
    void dfs(int u, int p, int d) {
      //
      foreach (i; G[u]) {
        const v = A[i] ^ B[i] ^ u;
        if (!del[v] && v != p) {
          dfs(v, u, d + 1);
        }
      }
    }
    foreach (i; G[r]) {
      const v = A[i] ^ B[i] ^ r;
      if (!del[v]) {
        dfs(v, r, 1);
        //
      }
    }
    //
  }

  long calc(int u) {
    long ret;
    void dfs(int u, int p, long d) {
      ret += d;
      foreach (i; G[u]) {
        const v = A[i] ^ B[i] ^ u;
        if (!del[v] && v != p) {
          dfs(v, u, d + 1);
        }
      }
    }
    dfs(u, -1, 0);
    debug {
      writeln("calc ", u, " = ", ret);
    }
    return ret;
  }

  // void solveRec(int u) {
  int solveRec(int u) {
    for (; ; ) {
      int vm = -1;
      foreach (i; G[u]) {
        const v = A[i] ^ B[i] ^ u;
        if (!del[v]) {
          if (vm == -1 || sz[vm] < sz[v]) {
            vm = v;
          }
        }
      }
      if (vm == -1 || sz[u] >= 2 * sz[vm]) {
        solveSubtree(u);
        /*
        del[u] = true;
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v]) {
            solveRec(v);
          }
        }
        */
        ////
        int same = -1;
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v]) {
            if (sz[u] - sz[v] == sz[v]) {
              same = v;
            }
          }
        }
        debug {
          writefln("u = %s, same = %s", u, same);
        }
        del[u] = true;
        int ret = u;
        if (same != -1) {
          del[same] = true;
          const resU = calc(u);
          const resSame = calc(same);
          if (resU < resSame) {
            ret = same;
          }
        }
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v]) {
            if (v != same) {
              const res = solveRec(v);
              if (v != res) {
                ans ~= [u, v, res];
              }
            }
          }
        }
        if (same != -1) {
          foreach (i; G[same]) {
            const v = A[i] ^ B[i] ^ same;
            if (!del[v]) {
              const res = solveRec(v);
              if (v != res) {
                ans ~= [same, v, res];
              }
            }
          }
        }
        return ret;
        ////
        break;
      } else {
        sz[u] -= sz[vm];
        sz[vm] += sz[u];
        u = vm;
      }
    }
  }
  solveRec(0);
}

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

      G = new int[][N];
      foreach (i; 0 .. N - 1) {
        G[A[i]] ~= i;
        G[B[i]] ~= i;
      }
      ans = [];
      solveCentroidDecomp;
      writeln(ans.length);
      foreach_reverse (op; ans) {
        writeln(op[0] + 1, " ", op[1] + 1, " ", op[2] + 1);
      }
    }
  } catch (EOFException 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)); }

int N;
int[] A, B;

int[][] G;
int[][] ans;

void solveCentroidDecomp() {
  auto sz = new int[N];
  auto del = new bool[N];
  void dfsSz(int u, int p) {
    sz[u] = 1;
    foreach (i; G[u]) {
      const v = A[i] ^ B[i] ^ u;
      if (v != p) {
        dfsSz(v, u);
        sz[u] += sz[v];
      }
    }
  }
  dfsSz(0, -1);

  // r: centroid
  void solveSubtree(int r) {
    debug {
      string dfsDebug(int u, int p) {
        string ret = u.to!string;
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v] && v != p) {
            ret ~= "(" ~ dfsDebug(v, u) ~ ")";
          }
        }
        return ret;
      }
      writeln("solveSubtree ", dfsDebug(r, -1));
    }
    //
    void dfs(int u, int p, int d) {
      //
      foreach (i; G[u]) {
        const v = A[i] ^ B[i] ^ u;
        if (!del[v] && v != p) {
          dfs(v, u, d + 1);
        }
      }
    }
    foreach (i; G[r]) {
      const v = A[i] ^ B[i] ^ r;
      if (!del[v]) {
        dfs(v, r, 1);
        //
      }
    }
    //
  }

  long calc(int u) {
    long ret;
    void dfs(int u, int p, long d) {
      ret += d;
      foreach (i; G[u]) {
        const v = A[i] ^ B[i] ^ u;
        if (!del[v] && v != p) {
          dfs(v, u, d + 1);
        }
      }
    }
    dfs(u, -1, 0);
    debug {
      writeln("calc ", u, " = ", ret);
    }
    return ret;
  }

  // void solveRec(int u) {
  int solveRec(int u) {
    for (; ; ) {
      int vm = -1;
      foreach (i; G[u]) {
        const v = A[i] ^ B[i] ^ u;
        if (!del[v]) {
          if (vm == -1 || sz[vm] < sz[v]) {
            vm = v;
          }
        }
      }
      if (vm == -1 || sz[u] >= 2 * sz[vm]) {
        solveSubtree(u);
        /*
        del[u] = true;
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v]) {
            solveRec(v);
          }
        }
        */
        ////
        int same = -1;
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v]) {
            if (sz[u] - sz[v] == sz[v]) {
              same = v;
            }
          }
        }
        debug {
          writefln("u = %s, same = %s", u, same);
        }
        del[u] = true;
        int ret = u;
        if (same != -1) {
          del[same] = true;
          const resU = calc(u);
          const resSame = calc(same);
          if (resU < resSame) {
            ret = same;
          }
        }
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v]) {
            if (v != same) {
              const res = solveRec(v);
              if (v != res) {
                ans ~= [u, v, res];
              }
            }
          }
        }
        if (same != -1) {
          foreach (i; G[same]) {
            const v = A[i] ^ B[i] ^ same;
            if (!del[v]) {
              const res = solveRec(v);
              if (v != res) {
                ans ~= [same, v, res];
              }
            }
          }
        }
        return ret;
        ////
        break;
      } else {
        sz[u] -= sz[vm];
        sz[vm] += sz[u];
        u = vm;
      }
    }
  }
  solveRec(0);
}

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

      G = new int[][N];
      foreach (i; 0 .. N - 1) {
        G[A[i]] ~= i;
        G[B[i]] ~= i;
      }
      ans = [];
      solveCentroidDecomp;
      writeln(ans.length);
      foreach (op; ans) {
        writeln(op[0] + 1, " ", op[1] + 1, " ", op[2] + 1);
      }
    }
  } catch (EOFException 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)); }

int N;
int[] A, B;

int[][] G;
int[][] ans;

void solveCentroidDecomp() {
  auto sz = new int[N];
  auto del = new bool[N];
  void dfsSz(int u, int p) {
    sz[u] = 1;
    foreach (i; G[u]) {
      const v = A[i] ^ B[i] ^ u;
      if (v != p) {
        dfsSz(v, u);
        sz[u] += sz[v];
      }
    }
  }
  dfsSz(0, -1);

  // r: centroid
  void solveSubtree(int r) {
    debug {
      string dfsDebug(int u, int p) {
        string ret = u.to!string;
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v] && v != p) {
            ret ~= "(" ~ dfsDebug(v, u) ~ ")";
          }
        }
        return ret;
      }
      writeln("solveSubtree ", dfsDebug(r, -1));
    }
    //
    void dfs(int u, int p, int d) {
      //
      foreach (i; G[u]) {
        const v = A[i] ^ B[i] ^ u;
        if (!del[v] && v != p) {
          dfs(v, u, d + 1);
        }
      }
    }
    foreach (i; G[r]) {
      const v = A[i] ^ B[i] ^ r;
      if (!del[v]) {
        dfs(v, r, 1);
        //
      }
    }
    //
  }

  // void solveRec(int u) {
  int solveRec(int u) {
    for (; ; ) {
      int vm = -1;
      foreach (i; G[u]) {
        const v = A[i] ^ B[i] ^ u;
        if (!del[v]) {
          if (vm == -1 || sz[vm] < sz[v]) {
            vm = v;
          }
        }
      }
      if (vm == -1 || sz[u] >= 2 * sz[vm]) {
        solveSubtree(u);
        del[u] = true;
        /*
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v]) {
            solveRec(v);
          }
        }
        */
        ////
        int same = -1;
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v]) {
            if (sz[u] - sz[v] == sz[v]) {
              same = v;
            }
          }
        }
        debug {
          writefln("u = %s, same = %s", u, same);
        }
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v]) {
            if (v != same) {
              const res = solveRec(v);
              if (v != res) {
                ans ~= [u, v, res];
              }
            }
          }
        }
        if (same != -1) {
          del[same] = true;
          foreach (i; G[same]) {
            const v = A[i] ^ B[i] ^ same;
            if (!del[v]) {
              const res = solveRec(v);
              if (v != res) {
                ans ~= [same, v, res];
              }
            }
          }
        }
        return u;
        ////
        break;
      } else {
        sz[u] -= sz[vm];
        sz[vm] += sz[u];
        u = vm;
      }
    }
  }
  solveRec(0);
}

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

      G = new int[][N];
      foreach (i; 0 .. N - 1) {
        G[A[i]] ~= i;
        G[B[i]] ~= i;
      }
      ans = [];
      solveCentroidDecomp;
      writeln(ans.length);
      foreach (op; ans) {
        writeln(op[0] + 1, " ", op[1] + 1, " ", op[2] + 1);
      }
    }
  } catch (EOFException 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)); }

int N;
int[] A, B;

int[][] G;
int[][] ans;

void solveCentroidDecomp() {
  auto sz = new int[N];
  auto del = new bool[N];
  void dfsSz(int u, int p) {
    sz[u] = 1;
    foreach (i; G[u]) {
      const v = A[i] ^ B[i] ^ u;
      if (v != p) {
        dfsSz(v, u);
        sz[u] += sz[v];
      }
    }
  }
  dfsSz(0, -1);

  // r: centroid
  void solveSubtree(int r) {
    debug {
      string dfsDebug(int u, int p) {
        string ret = u.to!string;
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v] && v != p) {
            ret ~= "(" ~ dfsDebug(v, u) ~ ")";
          }
        }
        return ret;
      }
      writeln("solveSubtree ", dfsDebug(r, -1));
    }
    //
    void dfs(int u, int p, int d) {
      //
      foreach (i; G[u]) {
        const v = A[i] ^ B[i] ^ u;
        if (!del[v] && v != p) {
          dfs(v, u, d + 1);
        }
      }
    }
    foreach (i; G[r]) {
      const v = A[i] ^ B[i] ^ r;
      if (!del[v]) {
        dfs(v, r, 1);
        //
      }
    }
    //
  }

  // void solveRec(int u) {
  int solveRec(int u) {
    for (; ; ) {
      int vm = -1;
      foreach (i; G[u]) {
        const v = A[i] ^ B[i] ^ u;
        if (!del[v]) {
          if (vm == -1 || sz[vm] < sz[v]) {
            vm = v;
          }
        }
      }
      if (vm == -1 || sz[u] >= 2 * sz[vm]) {
        solveSubtree(u);
        del[u] = true;
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v]) {
            // solveRec(v);
            const res = solveRec(v);
            if (sz[u] - sz[v] > sz[v] && v != res) {
              ans ~= [u, v, res];
            }
          }
        }
        // break;
        return u;
      } else {
        sz[u] -= sz[vm];
        sz[vm] += sz[u];
        u = vm;
      }
    }
  }
  solveRec(0);
}

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

      G = new int[][N];
      foreach (i; 0 .. N - 1) {
        G[A[i]] ~= i;
        G[B[i]] ~= i;
      }
      ans = [];
      solveCentroidDecomp;
      writeln(ans.length);
      foreach (op; ans) {
        writeln(op[0] + 1, " ", op[1] + 1, " ", op[2] + 1);
      }
    }
  } catch (EOFException 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)); }

int N;
int[] A, B;

int[][] G;
int[][] ans;

void solveCentroidDecomp() {
  auto sz = new int[N];
  auto del = new bool[N];
  void dfsSz(int u, int p) {
    sz[u] = 1;
    foreach (i; G[u]) {
      const v = A[i] ^ B[i] ^ u;
      if (v != p) {
        dfsSz(v, u);
        sz[u] += sz[v];
      }
    }
  }
  dfsSz(0, -1);

  // r: centroid
  void solveSubtree(int r) {
    debug {
      string dfsDebug(int u, int p) {
        string ret = u.to!string;
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v] && v != p) {
            ret ~= "(" ~ dfsDebug(v, u) ~ ")";
          }
        }
        return ret;
      }
      writeln("solveSubtree ", dfsDebug(r, -1));
    }
    //
    void dfs(int u, int p, int d) {
      //
      foreach (i; G[u]) {
        const v = A[i] ^ B[i] ^ u;
        if (!del[v] && v != p) {
          dfs(v, u, d + 1);
        }
      }
    }
    foreach (i; G[r]) {
      const v = A[i] ^ B[i] ^ r;
      if (!del[v]) {
        dfs(v, r, 1);
        //
      }
    }
    //
  }

  // void solveRec(int u) {
  int solveRec(int u) {
    for (; ; ) {
      int vm = -1;
      foreach (i; G[u]) {
        const v = A[i] ^ B[i] ^ u;
        if (!del[v]) {
          if (vm == -1 || sz[vm] < sz[v]) {
            vm = v;
          }
        }
      }
      if (vm == -1 || sz[u] >= 2 * sz[vm]) {
        solveSubtree(u);
        del[u] = true;
        /*
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v]) {
            solveRec(v);
          }
        }
        */
        ////
        int same = -1;
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v]) {
            if (sz[u] - sz[v] == sz[v]) {
              same = v;
            }
          }
        }
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!del[v]) {
            if (v != same) {
              const res = solveRec(v);
              if (v != res) {
                ans ~= [u, v, res];
              }
            }
          }
        }
        if (same != -1) {
          foreach (i; G[same]) {
            const v = A[i] ^ B[i] ^ same;
            if (!del[v]) {
              const res = solveRec(v);
              if (v != res) {
                ans ~= [same, v, res];
              }
            }
          }
        }
        return u;
        ////
        break;
      } else {
        sz[u] -= sz[vm];
        sz[vm] += sz[u];
        u = vm;
      }
    }
  }
  solveRec(0);
}

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

      G = new int[][N];
      foreach (i; 0 .. N - 1) {
        G[A[i]] ~= i;
        G[B[i]] ~= i;
      }
      ans = [];
      solveCentroidDecomp;
      writeln(ans.length);
      foreach (op; ans) {
        writeln(op[0] + 1, " ", op[1] + 1, " ", op[2] + 1);
      }
    }
  } catch (EOFException e) {
  }
}


module cf_43A;

import std.stdio;

void main() {
    int n, maxGoals = 0;
    int[string] teamGoals;
    string teamName, winTeam;

    readf("%d", &n);
    for (int i = 0; i < n; ++i) {
        readf(" %s\n", &teamName);

        if (++teamGoals[teamName] > maxGoals) {
            winTeam = teamName;
            maxGoals = teamGoals[teamName];
        }
    }

    writeln(winTeam);
}

import std.stdio;

void main() {
    int i;
    readf("%d\n", &i);
    string winner = "";
    int most = 0;
    int[string] m;
   // writeln("Entering loop");
    for (int j = 0; j < i; ++j) {
        //writeln("Reading");
        string t = readln();
        m[t] = m.get(t, 0) + 1;
        //writef("%s has %d\n", t, m[t]);
        if (m[t] > most) {
            most = m[t];
            winner = t;
        }
    }
    write(winner);
}

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

void main(){
    int n=readln.strip.to!int;
    string s,w;
    int[string] aa;
    int ans=0;
    while(n--){
        s=readln.strip;
        aa[s]++;
        if(aa[s]>ans){
            w=s;
            ans=aa[s];
        }
    }
    writeln(w);
}


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 s = readln.strip;
		int res = s.length.to !(int);
		int a = 0, b = 0;
		foreach (c; s)
		{
			if (c == 'A')
			{
				a += 1;
			}
			else
			{
				b += 1;
				if (a > 0 && b > 0)
				{
					a -= 1;
					b -= 1;
					res -= 2;
				}
				else if (b >= 2)
				{
					b -= 2;
					res -= 2;
				}
			}
		}
		writeln (res);
	}
}

import std.stdio;
import std.string;
import std.array;

void main() {
	int t;
	readf("%d\n", &t);
	while(t--) {
		auto str = readln.strip;
		char[] stack;
		stack.reserve(str.length);
		foreach(c; str) {
			stack ~= c;
			if(stack.length >= 2) {
				if((stack[$-2] == 'A' || stack[$-2] == 'B') && stack[$-1] == 'B') {
					stack.popBack();
					stack.popBack();
				}
			}
		}

		writeln(stack.length);
	}
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		int cnt, cnt_b;
		foreach_reverse (i; 0..s.length)
		{
			if (s[i] == 'B')
				++cnt_b;
			else if (cnt_b >= 1)
			{
				--cnt_b;
				cnt += 2;
			}
		}
		cnt += cnt_b - (cnt_b % 2);
		ans[ti] = cast(int)s.length - cnt;
	}

	foreach (e; ans)
		writeln(e);

	stdout.flush;
	debug readln;
}


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

void main()
{
	auto x = readln.split.map!(to!int);
	auto t = x[1] - 1;
	auto tp = readln.split.map!(to!int);
	int i;
	while (i < tp.length) {
		if (i == t) break;
		i += tp[i];
	}

	if (i == t) writeln("YES");
	else writeln("NO");
}

import std.stdio;
import std.ascii;
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;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

void main() {
    int N, T; scanf("%d %d\n", &N, &T);
    auto as = readln.chomp.split(" ").map!(to!int).array;

    auto bs = new int[N];
    foreach (int i, a; as) {
        bs[i] = i + a;
    }

    bool dfs(int index) {
        if (index == T - 1) return true;
        if (bs[index] == 0) return false;
        return dfs(bs[index]);
    }

    writeln(dfs(0) ? "YES" : "NO");
}

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

void main(string[] args){
	int n, t;
	readf(" %s %s\n", &n, &t);
	--t;
	int[] line = to!(int[])(readln.strip.split) ~ 0;
	int point = 0;
	while(point < t)
		point += line[point];

	writeln(point == t ? "YES" : "NO");
}

import std.stdio;

int[] a;

void main() {

	int n, t;

	scanf("%d%d", &n, &t);
	--t;

	int c;
	foreach (i; 0 .. n - 1) {
		scanf("%d", &c);
		a ~= c;
	}

	int x = 0;
	while (x < t)
		x += a[x];

	puts((x == t) ? "YES" : "NO");
}

import std.stdio: writeln, stdin;
import std.regex: split, regex;
import std.string: strip;
import std.conv: to;
import std.algorithm.iteration: map;

void main()
{
  auto nt = stdin.readln.strip.split(regex(` +`)).map!(to!int);
  auto as = stdin.readln.strip.split(regex(` +`)).map!(to!int);
  auto n = nt[0], t = nt[1]-1;
  int i=0;
  while(i<t) i+=as[i];
  writeln(i==t ? "YES" : "NO");
}

import std.stdio;
import std.uni;
import std.string;
import core.stdc.stdio;
import std.array;
import std.algorithm;
import std.string;
import std.math;

int main(string[] argv)
{
	int n, k;
	scanf("%d %d", &n, &k);
	int ts = 0;
	foreach (int i; 0..(n-1))
	{
		if (ts == (k-1))
		{
			write("YES");
			return 0;
		}
		int l;
		scanf("%d", &l);
		if (ts == i)
		{
			ts += l;
		}
	}
	if (ts == (k-1))
	{
		write("YES");
		return 0;
	}
	write("NO");
	return 0;
}

import std.stdio;

int[] a;

void main() {

	int n, t;

	scanf("%s %s", &n, &t);
	--t;

	int c;
	foreach (i; 0 .. n - 1) {
		readf(" %s", &c);
		a ~= c;
	}

	int x = 0;
	while (x < t)
		x += a[x];

	puts(x == t ? "YES" : "NO");
}

import std.stdio;
import std.uni;
import std.string;
import core.stdc.stdio;
import std.array;
import std.algorithm;
import std.string;
import std.math;

int main(string[] argv)
{
	int n, k;
	scanf("%d %d", &n, &k);
	int ts = 0;
	foreach (int i; 0..(n-1))
	{
		if (ts == (k-1))
		{
			write("YES");
			return 0;
		}
		int l;
		scanf("%d", &l);
		if (ts == i)
		{
			ts += l;
		}
	}
	write("NO");
	return 0;
}

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

void main()
{
	auto x = readln.split.map!(to!int);
	auto t = x[1] - 1;
	auto tp = readln.split.map!(to!int);
	int i;
	while (i < tp.length) {
		writeln(i+1);
		if (i == t) {
			break;
		}
		i += tp[i];
	}

	if (i == t) {
		writeln("YES");
	} else {
		writeln("NO");
	}
}


/+ dub.sdl:
    name "C"
    dependency "dcomp" version=">=0.7.3"
+/

import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;
// import dcomp.twosat;

int main() {
    Scanner sc = new Scanner(stdin);
    int n, m;
    sc.read(n, m);
    auto sat = TwoSat(m);
    int[][] g = new int[][n];
    foreach (i; 0..n) {
        int k;
        sc.read(k);
        g[i] = new int[k];
        foreach (j; 0..k) {
            sc.read(g[i][j]);
        }
        g[i][] -= 1;
    }

    foreach (i; 0..n-1) {
        //g[i], g[i+1]
        int mi = min(g[i].length, g[i+1].length).to!int;
        bool dif = false;
        foreach (j; 0..mi) {
            int x = g[i][j];
            int y = g[i+1][j];
            if (x != y) {
                dif = true;
                if (x > y) {
                    //only true, false
                    sat.addCond(x, true, y, false);
                    sat.addCond(x, false, y, false);
                    sat.addCond(x, true, y, true);
                } else {
                    //only ~(false, true)
                    sat.addCond(x, true, y, false);
                }
                break;
            }
        }
        if (!dif) {
            if (g[i].length > g[i+1].length) {
                writeln("No");
                return 0;
            }
        }
    }
    if (!sat.exec()) {
        writeln("No");
        return 0;
    }
    auto res = sat.res.enumerate.filter!"a[1]==true".array;
    writeln("Yes");
    writeln(res.length);
    writeln(res.map!"a[0]+1".map!(to!string).join(" "));
    return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/twosat.d */

// module dcomp.twosat;

// import dcomp.graph.scc;
// import dcomp.array;

struct TwoSat {

    bool[] res;

    struct Edge {int to;}
    FastAppender!(Edge[])[] g;

    void addCond(int a, bool aExp, int b, bool bExp) {
        g[2*a+(aExp?0:1)] ~= Edge(2*b+(bExp?1:0));
        g[2*b+(bExp?0:1)] ~= Edge(2*a+(aExp?1:0));
    }

    bool exec() {
        import std.array : array;
        import std.algorithm : map;
        import std.conv : to;
        int n = res.length.to!int;
        auto sccInfo = scc(g.map!(v => v.data).array);
        for (int i = 0; i < n; i++) {
            if (sccInfo.id[2*i] == sccInfo.id[2*i+1]) return false;
            res[i] = sccInfo.id[2*i] < sccInfo.id[2*i+1];
        }
        return true;
    }

    this(int n) {
        res = new bool[n];
        g = new FastAppender!(Edge[])[](2*n);
    }
}

/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/graph/scc.d */
// module dcomp.graph.scc;

// import dcomp.array;
// import dcomp.graph.primitive;
// import dcomp.container.deque;

struct SCCInfo {
    int[] id;
    int[][] groups;

    int[] group(int i) {
        return groups[id[i]];
    }
    this(int n) {
        id = new int[n];
    }
}

SCCInfo scc(T)(T g) {
    import std.range;
    import std.algorithm : each, map, min, reverse;
    import std.conv : to;
    int n = g.length.to!int;
    auto sccInfo = SCCInfo(n);
    with (sccInfo) {
        bool[] inS = new bool[n];
        int[] low = new int[n], ord = new int[n]; ord[] = -1;
        int time = 0;
        Deque!int st;
        int bufC = 0;
        FastAppender!(int[]) buf; buf.reserve(n);
        FastAppender!(int[][]) gBuf;
        void dfs(int v) {
            low[v] = ord[v] = time++;
            st.insertBack(v);
            inS[v] = true;
            foreach (e; g[v]) {
                if (ord[e.to] == -1) {
                    dfs(e.to);
                    low[v] = min(low[v], low[e.to]);
                } else if (inS[e.to]) {
                    low[v] = min(low[v], ord[e.to]);
                }
            }
            if (low[v] == ord[v]) {
                while (true) {
                    int u = st.back; st.removeBack;
                    buf ~= u;
                    if (u == v) break;
                }
                auto gr = buf.data[bufC..$];
                bufC = buf.length.to!int;
                gr.each!(x => inS[x] = false);
                gBuf ~= gr;
            }
        }
        foreach (i; 0..n) {
            if (ord[i] == -1) dfs(i);
        }
        groups = gBuf.data;
        reverse(groups);
        groups.each!((i, v) => v.each!(x => id[x] = i.to!int));
    }
    return sccInfo;
}

/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/container/deque.d */
// module dcomp.container.deque;

struct DequePayload(T) {
    import core.exception : RangeError;
    import core.memory : GC;
    import std.range : ElementType, isInputRange;
    import std.traits : isImplicitlyConvertible;
    T *d;
    size_t st, length, cap;
    @property bool empty() const { return length == 0; }
    alias opDollar = length;
    ref inout(T) opIndex(size_t i) inout {
        version(assert) if (length <= i) throw new RangeError();
        return d[(st+i >= cap) ? (st+i-cap) : st+i];
    }
    private void expand() {
        import std.algorithm : max;
        assert(length == cap);
        auto nc = max(size_t(4), 2*cap);
        T* nd = cast(T*)GC.malloc(nc * T.sizeof);
        foreach (i; 0..length) {
            nd[i] = this[i];
        }
        d = nd; st = 0; cap = nc;
    }
    void clear() {
        st = length = 0;
    }
    void insertFront(T v) {
        if (length == cap) expand();
        if (st == 0) st += cap;
        st--; length++;
        this[0] = v;
    }
    void insertBack(T v) {
        if (length == cap) expand();
        length++;
        this[length-1] = v;
    }
    void removeFront() {
        assert(!empty, "Deque.removeFront: Deque is empty");
        st++; length--;
        if (st == cap) st = 0;
    }
    void removeBack() {
        assert(!empty, "Deque.removeBack: Deque is empty");
        length--;
    }

    ref inout(T) front() inout { return this[0]; }
    ref inout(T) back() inout { return this[$-1]; }
    Range opSlice() {return Range(&this, 0, length); }

    alias Range = RangeT!(DequePayload!T);
    alias ConstRange = RangeT!(const DequePayload!T);
    alias ImmutableRange = RangeT!(immutable DequePayload!T);

    static struct RangeT(A) {
        import std.traits : CopyTypeQualifiers;
        alias E = CopyTypeQualifiers!(A, T);
        A *p;
        size_t a, b;
        @property bool empty() const { return b <= a; }
        @property size_t length() const { return b-a; }
        @property RangeT save() { return RangeT(p, a, b); }
        @property RangeT!(const A) save() const {
            return typeof(return)(p, a, b);
        }
        alias opDollar = length;
        @property ref inout(E) front() inout { return (*p)[a]; }
        @property ref inout(E) back() inout { return (*p)[b-1]; }
        void popFront() {
            version(assert) if (empty) throw new RangeError();
            a++;
        }
        void popBack() {
            version(assert) if (empty) throw new RangeError();
            b--;
        }
        ref inout(E) opIndex(size_t i) inout { return (*p)[i]; }
        RangeT opSlice() { return this.save; }
        RangeT opSlice(size_t i, size_t j) {
            version(assert) if (i > j || a + j > b) throw new RangeError();
            return typeof(return)(p, a+i, a+j);
        }
        RangeT!(const A) opSlice() const { return this.save; }
        RangeT!(const A) opSlice(size_t i, size_t j) const {
            version(assert) if (i > j || a + j > b) throw new RangeError();
            return typeof(return)(p, a+i, a+j);
        }
    }
}

struct Deque(T, bool mayNull = true) {
    import core.exception : RangeError;
    import core.memory : GC;
    import std.range : ElementType, isInputRange;
    import std.traits : isImplicitlyConvertible;

    alias Payload = DequePayload!T;
    alias Range = Payload.Range;
    alias ConstRange = Payload.ConstRange;
    alias ImmutableRange = Payload.ImmutableRange;

    Payload* p;
    private void I() { if (mayNull && !p) p = new Payload(); }
    private void C() const {
        version(assert) if (mayNull && !p) throw new RangeError();
    }
    static if (!mayNull) {
        @disable this();
    }

    private this(Payload* p) {
        this.p = p;
    }
    this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) {
        p = new Payload();
        foreach (v; values) {
            insertBack(v);
        }
    }

    this(Range)(Range r)
    if (isInputRange!Range &&
    isImplicitlyConvertible!(ElementType!Range, T) &&
    !is(Range == T[])) {
        p = new Payload();
        foreach (v; r) {
            insertBack(v);
        }
    }
    static Deque make() { return Deque(new Payload()); }
    @property bool havePayload() const { return (!mayNull || p); }

    @property bool empty() const { return (!havePayload || p.empty); }

    @property size_t length() const { return (havePayload ? p.length : 0); }

    alias opDollar = length;
    ref inout(T) opIndex(size_t i) inout {C; return (*p)[i]; }

    ref inout(T) front() inout {C; return (*p)[0]; }

    ref inout(T) back() inout {C; return (*p)[$-1]; }
    void clear() { if (p) p.clear(); }

    void insertFront(T v) {I; p.insertFront(v); }

    void insertBack(T v) {I; p.insertBack(v); }

    alias stableInsertBack = insertBack;

    void removeFront() {C; p.removeFront(); }

    void removeBack() {C; p.removeBack(); }

    Range opSlice() {I; return Range(p, 0, length); }
}

/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

// import dcomp.array;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray;
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succW() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (!line.empty && line.front.isWhite) {
            line.popFront;
        }
        return !line.empty;
    }
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            line = lineBuf[];
            f.readln(line);
            if (!line.length) return false;
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {

                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else static if (isStaticArray!T) {
                foreach (i; 0..T.length) {
                    bool f = succW();
                    assert(f);
                    x[i] = line.parse!E;
                }
            } else {
                FastAppender!(E[]) buf;
                while (succW()) {
                    buf ~= line.parse!E;
                }
                x = buf.data;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/graph/primitive.d */
// module dcomp.graph.primitive;

import std.range : ElementType;
alias EdgeType(R) = ElementType!(ElementType!R);
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;

static if (__VERSION__ <= 2070) {
    /*
    Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
    Copyright: Andrei Alexandrescu 2008-.
    License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
    */
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            import std.algorithm : reduce;
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                import std.typecons : tuple;
                return reduce!fun(tuple(seed), r);
            }
        }
    }

}
version (X86) static if (__VERSION__ < 2071) {
    import core.bitop : bsf, bsr, popcnt;
    int bsf(ulong v) {
        foreach (i; 0..64) {
            if (v & (1UL << i)) return i;
        }
        return -1;
    }
    int bsr(ulong v) {
        foreach_reverse (i; 0..64) {
            if (v & (1UL << i)) return i;
        }
        return -1;
    }
    int popcnt(ulong v) {
        int c = 0;
        foreach (i; 0..64) {
            if (v & (1UL << i)) c++;
        }
        return c;
    }
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/array.d */
// module dcomp.array;

T[N] fixed(T, size_t N)(T[N] a) {return a;}

struct FastAppender(A, size_t MIN = 4) {
    import std.algorithm : max;
    import std.conv;
    import std.range.primitives : ElementEncodingType;
    import core.stdc.string : memcpy;

    private alias T = ElementEncodingType!A;
    private T* _data;
    private uint len, cap;

    @property size_t length() const {return len;}
    bool empty() const { return len == 0; }

    void reserve(size_t nlen) {
        import core.memory : GC;
        if (nlen <= cap) return;

        void* nx = GC.malloc(nlen * T.sizeof);

        cap = nlen.to!uint;
        if (len) memcpy(nx, _data, len * T.sizeof);
        _data = cast(T*)(nx);
    }
    void free() {
        import core.memory : GC;
        GC.free(_data);
    }

    void opOpAssign(string op : "~")(T item) {
        if (len == cap) {
            reserve(max(MIN, cap*2));
        }
        _data[len++] = item;
    }

    void insertBack(T item) {
        this ~= item;
    }

    void removeBack() {
        len--;
    }

    void clear() {
        len = 0;
    }
    ref inout(T) back() inout { assert(len); return _data[len-1]; }
    ref inout(T) opIndex(size_t i) inout { return _data[i]; }

    T[] data() {
        return (_data) ? _data[0..len] : null;
    }
}

/*
This source code generated by dcomp and include dcomp's source code.
dcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)
dcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt)
*/

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

Tuple!(int, int[]) scc(in int[][][] graph) {
  const n = cast(int)(graph[0].length);
  int compN;
  auto compIds = new int[n];
  int[] us;
  void dfs(int s, int u, int a, int b) {
    if (compIds[u] == a) {
      compIds[u] = b;
      foreach (v; graph[s][u]) {
        dfs(s, v, a, b);
      }
      if (s == 0) {
        us ~= u;
      }
    }
  }
  foreach (u; 0 .. n) {
    dfs(0, u, 0, -1);
  }
  foreach_reverse (u; us) {
    if (compIds[u] == -1) {
      dfs(1, u, -1, compN);
      ++compN;
    }
  }
  return tuple(compN, compIds);
}

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

      bool ans = true;
      auto graph = new int[][][](2, M << 1);
      void addEdge(int x, int y) {
        graph[0][x] ~= y;
        graph[1][y] ~= x;
      }

      foreach (i; 0 .. N - 1) {
        for (int j = 0; ; ++j) {
          if (j == L[i]) {
            break;
          } else if (j == L[i + 1]) {
            ans = false;
            break;
          } else {
            const u = S[i][j], v = S[i + 1][j];
            if (u < v) {
              // CAP(u) || NOCAP(v)
              addEdge(u << 1 | 0, v << 1 | 0);
              addEdge(v << 1 | 1, u << 1 | 1);
              break;
            } else if (u > v) {
              // CAP(u) && NOCAP(v)
              addEdge(u << 1 | 0, u << 1 | 1);
              addEdge(v << 1 | 1, v << 1 | 0);
              break;
            }
          }
        }
      }
      auto res = scc(graph);
      foreach (u; 0 .. M) {
        ans = ans && (res[1][u << 1 | 0] != res[1][u << 1 | 1]);
      }
      if (ans) {
        int[] us;
        foreach (u; 0 .. M) {
          if (res[1][u << 1 | 0] < res[1][u << 1 | 1]) {
            us ~= u;
          }
        }
        writeln("Yes");
        writeln(us.length);
        foreach (index, u; us) {
          if (index > 0) write(" ");
          write(u + 1);
        }
        writeln;
      } else {
        writeln("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;

void main() {
    auto N = readln.chomp.to!int;
    auto X = new int[][](10, 2);
    foreach (i; 0..10) X[i][0] = 0;
    foreach (i; 0..10) X[i][1] = 1;

    foreach (i; 0..N) {
        auto s = readln.split;
        auto op = s[0];
        auto n = s[1].to!int;
        foreach (j; 0..10) {
            bool b = (n & (1 << j)) != 0;
            if (op[0] == '|') {
                X[j][0] |= b;
                X[j][1] |= b;
            } else if (op[0] == '&') {
                X[j][0] &= b;
                X[j][1] &= b;
            } else {
                X[j][0] ^= b;
                X[j][1] ^= b;
            }
        }
    }

    int opor = 0;
    int opand = 0;
    int opxor = 0;

    foreach (i; 0..10) {
        if (X[i][0] == 0 && X[i][1] == 0) {

        } else if (X[i][0] == 0 && X[i][1] == 1) {
            opand |= (1 << i);
        } else if (X[i][0] == 1 && X[i][1] == 0) {
            opand |= (1 << i);
            opxor |= (1 << i);
        } else {
            opor |= (1 << i);
            opand |= (1 << i);
        }
    }

    writeln(3);
    writeln("| ", opor);
    writeln("& ", opand);
    writeln("^ ", opxor);
}

import core.bitop;
import core.checkedint;
//import core.stdc.stdio;
import core.stdc.stdlib: alloca, malloc, calloc, realloc, _Exit;
import core.stdc.string;
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.bitmanip;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.regex;
import std.stdio;
import std.string;
import std.typecons;

__gshared:

alias BitSet(size_t n) = size_t[(n + size_t.sizeof * 8 - 1) / (size_t.sizeof * 8)];

auto getAddrTuple() {
    return tuple();
}

auto getAddrTuple(T, U...)(ref T head, ref U tail) {
    return tuple(&head, getAddrTuple(tail).expand);
}

bool read(T...)(ref T vars) if (vars.length > 0) {
    return readf(' ' ~ replicate("%s ", vars.length), getAddrTuple(vars).expand) == vars.length;
}

T[ ] allocate(T)(size_t n) {
    return (cast(T*)malloc(n * T.sizeof))[0 .. n];
}

void memSet(T, size_t n)(ref T[n] a, ubyte value) {
    memset(a.ptr, value, a.sizeof);
}

void memSet(T)(T[ ] a, ubyte value) {
    memset(a.ptr, value, a.length * T.sizeof);
}

auto pairwise(R)(R range) if (isForwardRange!R) {
    return lockstep(range, dropOne(range));
}

enum Action { none, flip, set, unset }

void main() {
    int n;
    while (read(n)) {
        Action[10] bits;
        while (n--) {
            char c;
            int x;
            read(c, x);
            final switch (c) {
                case '&': {
                    foreach (i; 0 .. 10) {
                        if (!(x & 0x1))
                            bits[i] = Action.unset;
                        x >>= 1;
                    }
                    break;
                }
                case '|': {
                    foreach (i; 0 .. 10) {
                        if (x & 0x1)
                            bits[i] = Action.set;
                        x >>= 1;
                    }
                    break;
                }
                case '^': {
                    foreach (i; 0 .. 10) {
                        if (x & 0x1)
                            bits[i] ^= 0x1;
                        x >>= 1;
                    }
                    break;
                }
            }
        }

        auto accumulate(Action action)() {
            return iota(10).filter!(i => bits[i] == action).fold!`a | 1 << b`(0x0);
        }

        write("3\n& ", accumulate!(Action.unset) ^ 0x3FF);
        write("\n| ", accumulate!(Action.set));
        writeln("\n^ ", accumulate!(Action.flip));
        debug writeln();
    }

    stdout.flush();
    _Exit(0);
}

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 E = 10;

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

      int[] ans = [(1 << E) - 1, 0, 0];
      foreach (e; 0 .. E) {
        auto ts = new int[2];
        foreach (s; 0 .. 2) {
          int z = s << e;
          foreach (i; 0 .. N) {
            switch (A[i]) {
              case "&": z &= X[i]; break;
              case "|": z |= X[i]; break;
              case "^": z ^= X[i]; break;
              default: assert(false);
            }
          }
          ts[s] = (z >> e) & 1;
        }
        debug {
          writeln(e, ": ", ts);
        }
        switch (ts[0] << 0 | ts[1] << 1) {
          case 0: ans[0] ^= 1 << e; break;
          case 1: ans[2] ^= 1 << e; break;
          case 2: break;
          case 3: ans[1] ^= 1 << e; break;
          default: assert(false);
        }
      }
      writeln(3);
      writefln("& %s", ans[0]);
      writefln("| %s", ans[1]);
      writefln("^ %s", ans[2]);

      debug {
        foreach (z; 0 .. 1 << E) {
          int expected = z;
          foreach (i; 0 .. N) {
            switch (A[i]) {
              case "&": expected &= X[i]; break;
              case "|": expected |= X[i]; break;
              case "^": expected ^= X[i]; break;
              default: assert(false);
            }
          }
          int actual = z;
          actual &= ans[0];
          actual |= ans[1];
          actual ^= ans[2];
          assert(expected == actual);
        }
      }
    }
  } catch (EOFException e) {
  }
}


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

string FMT_F = "%.10f";

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

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

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

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(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 n = RD!int;
	auto q = RD!int;
	auto a = RDA;

	long cnt = a.sum;
	long[] ans;
	foreach (i; 0..q)
	{
		auto t = RD!int;
		if (t == 1)
		{
			auto x = RD!int-1;
			if(a[x] == 1)
			{
				--cnt;
				a[x] = 0;
			}
			else
			{
				++cnt;
				a[x] = 1;
			}
		}
		else
		{
			auto k = RD!int;
			if (k <= cnt)
				ans ~= 1;
			else
				ans ~= 0;
		}
	}

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

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

void main ()
{
	int n, q;
	while (readf !(" %s %s") (n, q) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto s = sum (a);
		foreach (r; 0..q)
		{
			int t, z;
			readf !(" %s %s") (t, z);
			if (t == 1)
			{
				auto x = z - 1;
				s -= (a[x] == 1);
				a[x] ^= 1;
				s += (a[x] == 1);
			}
			else
			{
				auto k = z;
				writeln (to !(int) (k <= s));
			}
		}
	}
}

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

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

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

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

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

      auto as = A.dup;
      int now = cast(int)(as.count(1));

      foreach (q; 0 .. Q) {
        const typ = readInt();
        if (typ == 1) {
          const x = readInt() - 1;
          if (as[x] == 1) --now;
          as[x] = 1 - as[x];
          if (as[x] == 1) ++now;
        } else {
          const k = readInt();
          writeln((now >= k) ? 1 : 0);
        }
      }
    }
  } catch (EOFException e) {
  }
}


import std.stdio;
int or(int a, int b)
{
	if (a==1 || b==1)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
int main()
{
	int a=0;
	int b=0;
	readf(" %d", &a);
	readf(" %d", &b);
	int count=0;
	int[] n = new int[2*b];
	int[] m = new int[b];
	for (int i=0; i<a; i++)
	{
		for (int j=0; j<2*b; j++)
		{
			readf(" %d", &n[j]);
		}
		for (int j=0; j<b; j++)
		{
			m[j]=or(n[2*j],n[2*j+1]);
		}
		for (int j=0; j<b; j++)
		{
			if (m[j]==1)
			{
				count=count+1;
			}
		}
	}
	writeln(count);
	return 0;
}

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

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

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

        double read_double() {
                return read_string.to!double;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // int t = cin.read_int;
        while (t--) {
                int n = cin.read_int;
                int m = cin.read_int;
                int count = 0;
                for (int i = 0; i < n; i++) {
                        for (int j = 0; j < m; j++) {
                                int a = cin.read_int;
                                int b = cin.read_int;
                                if (a || b) count++;
                        }
                }
                writeln(count);
        }
}

import std.stdio;

void main() {

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

    int last, next, ans;
    foreach (i; 0 .. n)
        foreach (j; 0 .. 2*m) {
            readf(" %s ", &next);

            if (next && !(last && j & 1))
                ++ans;
            last = next;
        }

    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;
		auto res = [0, 0, 0]; // pow, lo, hi
		auto startVal = [0, 0];
		auto startPos = [0, int.max];
		int isNeg = 0;
		int val = 0;
		foreach (int pos, c; a)
		{
			if (c == 0)
			{
				startVal = [0, 0];
				startPos = [pos + 1, int.max];
				isNeg = 0;
				val = 0;
				continue;
			}
			if (c < 0)
			{
				isNeg ^= 1;
				c *= -1;
			}
			c -= 1;
			val += c;
			if (startPos[isNeg] == int.max)
			{
				startVal[isNeg] = val;
				startPos[isNeg] = pos + 1;
			}
			res = max (res,
			    [val - startVal[isNeg], startPos[isNeg], pos + 1]);
		}
		writeln (res[1], " ", n - res[2]);
	}
}

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

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

void solve() {
    int N = read!int;
    auto A = readarray!int;

    int[] zs = [-1];
    foreach (i, a; A) {
        if (a == 0) zs ~= i;
    }
    zs ~= N;

    int max_nt = 0;
    int[] ans = [0, 0];
    for (int k = 0; k + 1 < zs.length; k++) {
        int l = zs[k], r = zs[k + 1];
        l++; // exclude leftmost zero
        int nm = 0;
        int nt = 0;
        for (int i = l; i < r; i++) {
            assert(A[i] != 0);
            if (A[i] < 0) nm++;
            if (abs(A[i]) == 2) nt++;
        }
        if (nm % 2 == 0) {
            if (max_nt < nt) {
                max_nt = nt;
                ans = [l, r];
            }
        } else {
            // remove left or right
            int lrt = 0, rrt = 0; // left removed t
            int li = -1, ri = -1;
            for (int i = l; i < r; i++) {
                if (abs(A[i]) == 2) lrt++;
                if (A[i] < 0) {
                    li = i + 1;
                    break;
                }
            }
            for (int i = r-1; i >= l; i--) {
                if (abs(A[i]) == 2) rrt++;
                if (A[i] < 0) {
                    ri = i;
                    break;
                }
            }
            if (lrt > rrt) {
                // remove right
                int tnt = nt - rrt;
                if (max_nt < tnt) {
                    max_nt = tnt;
                    ans = [l, ri];
                }
            } else {
                // remove left
                int tnt = nt - lrt;
                if (max_nt < tnt) {
                    max_nt = tnt;
                    ans = [li, r];
                }
            }
        }
    }
    auto removed = [ ans[0], N - ans[1] ];
    writefln("%(%s %)", removed);
}

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