Timur's grandfather gifted him a chessboard to practice his chess skills. This chessboard is a grid $$$a$$$ with $$$n$$$ rows and $$$m$$$ columns with each cell having a non-negative integer written on it. Timur's challenge is to place a bishop on the board such that the sum of all cells attacked by the bishop is maximal. The bishop attacks in all directions diagonally, and there is no limit to the distance which the bishop can attack. Note that the cell on which the bishop is placed is also considered attacked. Help him find the maximal sum he can get.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains the integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 200$$$, $$$1 \leq m \leq 200$$$). The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element of the $$$i$$$-th line $$$a_{ij}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row $$$(0\leq a_{ij} \leq 10^6)$$$ It is guaranteed that the sum of $$$n\cdot m$$$ over all test cases does not exceed $$$4\cdot10^4$$$.

For each test case output a single integer, the maximum sum over all possible placements of the bishop.

NoteFor the first test case here the best sum is achieved by the bishop being in this position:

module x_sum;

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

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

int SD(int[][] matrix, int n, int m) {
    int sum = matrix[n][m];
    for ( {int i = n-1; int j = m-1; } i >= 0 && j >= 0; i--, j--)
        sum += matrix[i][j];
    for ( {int i = n+1; int j = m+1; } i < matrix.length && j < matrix[0].length; i++, j++)
        sum += matrix[i][j];
    for ( {int i = n-1; int j = m+1; } i >= 0 && j < matrix[0].length; i--, j++)
        sum += matrix[i][j];
    for ( {int i = n+1; int j = m-1; } i < matrix.length && j >= 0; i++, j--)
        sum += matrix[i][j];
    return sum;
}

void main() {
    int t, n, m;
    readf("%d\n", t);
    while(t--) {
        int sum = 0;
        readf("%d %d\n", n, m);
        int[][] matrix;
        int temp = n;
        while (temp--)
            matrix ~= rtln!int;
        if (m == 1)
            foreach (ln; matrix)
                sum = max(sum, ln[0]);
        else
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    sum = max(sum, SD(matrix, i, j));
        writeln(sum);
    }
}

void main() { runSolver(); }

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

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto M = scan!int;
      auto A = scan!long(N * M).chunks(M).array;

      auto lsum = new long[](N + M - 1);
      foreach(y; -M+1..N) {
        int tx = max(-y, 0);
        int ty = max(0, y);
        while(tx < M && ty < N) {
          lsum[y + M - 1] += A[ty++][tx++];
        }
      }

      auto rsum = new long[](N + M - 1);
      foreach(y; -M+1..N) {
        int tx = min(M - 1 + y , M - 1);
        int ty = max(0, y);
        while(tx >= 0 && ty < N) {
          rsum[y + M - 1] += A[ty++][tx--];
        }
      }

      // lsum.deb;
      // rsum.deb;
      long ans = 0;
      foreach(y; 0..N) foreach(x; 0..M) {
        long tans;
        tans += lsum[M - x + y - 1];
        tans += rsum[x + y];
        tans -= A[y][x];
        ans = max(ans, tans);
      }

      return ans;
    }

    foreach(i; 0..QN) {
      subSolve().writeln;
    }
  }

  outputForAtCoder(&solve);
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

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

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, m;
		readf !(" %s %s") (n, m);
		readln;
		int [] [] a;
		foreach (row; 0..n)
		{
			a ~= readln.splitter.map !(to !(int)).array;
		}

		auto c = new int [n + m - 1];
		auto d = new int [n + m - 1];
		foreach (row; 0..n)
		{
			foreach (col; 0..m)
			{
				c[row + col] += a[row][col];
				d[row + m - col - 1] += a[row][col];
			}
		}

		int res = 0;
		foreach (row; 0..n)
		{
			foreach (col; 0..m)
			{
				res = max (res, c[row + col] +
				    d[row + m - col - 1] - a[row][col]);
			}
		}
		writeln (res);
	}
}

module x_sum;

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

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

int SD(int[][] matrix, int n, int m) {
    int sum = matrix[n][m];
    for ( {int i = n-1; int j = m-1; } i >= 0 && j >= 0; i--, j--)
        sum += matrix[i][j];
    for ( {int i = n+1; int j = m+1; } i < matrix.length && j < matrix[0].length; i++, j++)
        sum += matrix[i][j];
    for ( {int i = n-1; int j = m+1; } i >= 0 && j < matrix[0].length; i--, j++)
        sum += matrix[i][j];
    for ( {int i = n+1; int j = m-1; } i < matrix.length && j >= 0; i++, j--)
        sum += matrix[i][j];
    return sum;
}

void main() {
    int t, n, m;
    readf("%d\n", t);
    while(t--) {
        int sum = 0;
        readf("%d %d\n", n, m);
        int[][] matrix;
        int temp = n;
        while (temp--)
            matrix ~= rtln!int;
        if (m == 1)
            foreach (ln; matrix)
                sum = max(sum, ln[0]);
        else
            for (int i = 0; i < n; i++)
                for (int j = 1; j < m; j++)
                    sum = max(sum, SD(matrix, i, j));
        writeln(sum);
    }
}

module x_sum;

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

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

int SD(int[][] matrix, int n, int m) {
    int sum = -(2 * matrix[n][m]);
    for ( {int i = 0; int j = 0; } i < n && j < m; i++, j++)
        sum += matrix[i][j];
    for ( {int i = n; int j = m; } i < matrix.length && j < matrix[0].length; i++, j++)
        sum += matrix[i][j];
    for ( {int i = n; int j = m; } i >= 0 && j < matrix[0].length; i--, j++)
        sum += matrix[i][j];
    for ( {int i = n; int j = m; } i < matrix.length && j >= 0; i++, j--)
        sum += matrix[i][j];
    return sum;
}

void main() {
    int t, n, m;
    readf("%d\n", t);
    while(t--) {
        int sum;
        readf("%d %d\n", n, m);
        int[][] matrix;
        int temp = n;
        while (temp--)
            matrix ~= rtln!int;
        if (m == 1)
            foreach (ln; matrix)
                sum = max(sum, ln[0]);
        else
            for (int i = 0; i < n; i++)
                for (int j = 1; j < m; j++)
                    sum = max(sum, SD(matrix, i, j));
        writeln(sum);
    }
}

module x_sum;

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

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

int SD(int[][] matrix, int n, int m) {
    int sum = -(2 * matrix[n][m]);
    for ( {int i = 0; int j = 0; } i < n && j < m; i++, j++)
        sum += matrix[i][j];
    for ( {int i = n; int j = m; } i < matrix.length && j < matrix[0].length; i++, j++)
        sum += matrix[i][j];
    for ( {int i = n; int j = m; } i >= 0 && j < matrix[0].length; i--, j++)
        sum += matrix[i][j];
    for ( {int i = n; int j = m; } i < matrix.length && j >= 0; i++, j--)
        sum += matrix[i][j];
    return sum;
}

void main() {
    int t, n, m;
    readf("%d\n", t);
    while(t--) {
        int sum;
        readf("%d %d\n", n, m);
        int[][] matrix;
        int temp = n;
        while (temp--)
            matrix ~= rtln!int;
        for (int i = 0; i < n; i++)
            for (int j = 1; j < m; j++)
                sum = max(sum, SD(matrix, i, j));
        writeln(sum);
    }
}

module x_sum;

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

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

int SD(int[][] matrix, int n, int m) {
    int sum = -(2 * matrix[n][m]);
    for ( {int i = 0; int j = 0; } i < n && j < m; i++, j++)
        sum += matrix[i][j];
    for ( {int i = n; int j = m; } i < matrix.length && j < matrix[0].length; i++, j++)
        sum += matrix[i][j];
    for ( {int i = n; int j = m; } i >= 0 && j < matrix[0].length; i--, j++)
        sum += matrix[i][j];
    for ( {int i = n; int j = m; } i < matrix.length && j >= 0; i++, j--)
        sum += matrix[i][j];
    return sum;
}

void main() {
    int t, n, m;
    readf("%d\n", t);
    while(t--) {
        int sum;
        readf("%d %d\n", n, m);
        int[][] matrix;
        int temp = n;
        while (temp--)
            matrix ~= rtln!int;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                sum = max(sum, SD(matrix, i, j));
        writeln(sum);
    }
}

module x_sum;

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

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

int SD(int[][] matrix, int n, int m) {
    int sum = -(2 * matrix[n][m]);
    for ( {int i = 0; int j = 0; } i < n && j < m; i++, j++)
        sum += matrix[i][j];
    for ( {int i = n; int j = m; } i < matrix.length && j < matrix[0].length; i++, j++)
        sum += matrix[i][j];
    for ( {int i = n; int j = m; } i >= 0 && j < matrix[0].length; i--, j++)
        sum += matrix[i][j];
    for ( {int i = n; int j = m; } i < matrix.length && j >= 0; i++, j--)
        sum += matrix[i][j];
    return sum;
}

void main() {
    int t, n, m, sum;
    readf("%d\n", t);
    while(t--) {
        readf("%d %d\n", n, m);
        int[][] matrix;
        int temp = n;
        while (temp--)
            matrix ~= rtln!int;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                sum = max(sum, SD(matrix, i, j));
        writeln(sum);
    }
}


Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the і-th row and j-th column that describes the result of the collision of the і-th and the j-th car:    - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix.  0: if no car turned over during the collision.  1: if only the i-th car turned over during the collision.  2: if only the j-th car turned over during the collision.  3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?

The first line contains integer n (1 ≤ n ≤ 100) — the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A.  It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.

Print the number of good cars and in the next line print their space-separated indices in the increasing order.

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

void main() {

	int sum; int[] ans;
	foreach (i; 1 .. readln.strip.to!int + 1) {
		if (readln.split.map!(to!int).all!"a != 1 && a != 3") {
			++sum;
			ans ~= i;
		}
	}

	writeln(sum);

	if (sum > 0) {
		writefln("%(%s %)", ans);
	}
}

import std.math,
       std.conv,
       std.stdio,
       std.ascii,
       std.range,
       std.array,
       std.regex,
       std.format,
       std.bigint,
       std.traits,
       std.string,
       std.numeric,
       std.variant,
       std.typecons,
       std.algorithm,
       std.typetuple,
       std.exception;

void main() {

	int n = readln.strip.to!int;

	int[101][101] a; bool[int] hash;
	foreach (i; 1 .. n + 1) {
		foreach (j; 1 .. n + 1) {
			scanf("%d", &a[i][j]);
			if (a[i][j] != 0 && a[i][j] != -1) {
				if (a[i][j] == 1) {
					hash[i] = false;
				}
				if (a[i][j] == 2) {
					hash[j] = false;
				}
				if (a[i][j] == 3) {
					hash[i] = hash[j] = false;
				}
			}
		}
	}

	int[] ans; int sum;
	foreach (i; 1 .. n + 1) {
		if (i !in hash) {
			++sum;
			ans ~= i;
		}
	}

	writeln(sum);
	if (sum > 0) {
		writefln("%(%s %)", ans);
	}
}

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

void main() {

	int n = readln.strip.to!int;

	auto t = stdin.byLine.take(n).
		map!(a => a.split.map!(to!int).any!"a == 1 || a == 3").array;

	int[] idx;
	foreach (i, el; t) {
		if (!el) {
			idx ~= i + 1;
		}
	}

	writeln(idx.length);
	writefln("%(%s %)", idx);
}

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

void main() {
    int n = readln.chomp.to!int;
    int[] ans;
    foreach (i; 0..n) {
        auto row = readln.chomp.split.map!(to!int);
        if (row.any!"a == 1 || a == 3") {
            continue;
        }

        ans ~= i + 1;
    }

    ans.length.writeln;
    if (ans.length > 0) {
        ans.map!(to!string).join(" ").writeln;
    }
}

import std.math,
       std.conv,
       std.stdio,
       std.ascii,
       std.range,
       std.array,
       std.regex,
       std.format,
       std.bigint,
       std.traits,
       std.string,
       std.numeric,
       std.variant,
       std.typecons,
       std.algorithm,
       std.typetuple,
       std.exception;

void main() {

	int n = readln.strip.to!int;

	int[101][101] a;
	foreach (i; 1 .. n + 1) {
		foreach (j; 1 .. n + 1) {
			scanf("%d", &a[i][j]);
		}
	}

	bool[int] hash;
	foreach (i; 1 .. n) {
		if (a[i][i + 1] != 0) {
			if (a[i][i + 1] == 1) {
				hash[i] = false;
			}
			if (a[i][i + 1] == 2) {
				hash[i + 1] = false;
			}
			if (a[i][i + 1] == 3) {
				hash[i] = hash[i + 1] = false;
			}
		}
		if (a[i + 1][i] != 0) {
			if (a[i + 1][i] == 1) {
				hash[i + 1] = false;
			}
			if (a[i + 1][i] == 2) {
				hash[i] = false;
			}
			if (a[i + 1][i] == 3) {
				hash[i] = hash[i + 1] = false;
			}
		}
	}

	if (a[1][n] != 0) {
		hash[n] = false;
	}

	if (a[n][1] != 0) {
		if (a[n][1] == 1) {
			hash[n] = false;
		}
		if (a[n][1] == 2) {
			hash[1] = false;
		}
		if (a[n][1] == 3) {
			hash[1] = hash[n] = false;
		}
	}

	int[] ans; int sum;
	foreach (i; 1 .. n + 1) {
		if (i !in hash) {
			++sum;
			ans ~= i;
		}
	}

	writeln(sum);
	if (sum > 0) {
		writefln("%(%s %)", ans);
	}
}

import std.math,
       std.conv,
       std.stdio,
       std.ascii,
       std.range,
       std.array,
       std.regex,
       std.format,
       std.bigint,
       std.traits,
       std.string,
       std.numeric,
       std.variant,
       std.typecons,
       std.algorithm,
       std.typetuple,
       std.exception;

void main() {

	int n = readln.strip.to!int;

	int[101][101] a;
	foreach (i; 1 .. n + 1) {
		foreach (j; 1 .. n + 1) {
			scanf("%d", &a[i][j]);
		}
	}

	bool[int] hash;
	foreach (i; 1 .. n) {
		if (a[i][i + 1] != 0) {
			if (a[i][i + 1] == 1) {
				hash[i] = false;
			}
			if (a[i][i + 1] == 2) {
				hash[i + 1] = false;
			}
			if (a[i][i + 1] == 3) {
				hash[i] = hash[i + 1] = false;
			}
		}
		if (a[i + 1][i] != 0) {
			if (a[i + 1][i] == 1) {
				hash[i + 1] = false;
			}
			if (a[i + 1][i] == 2) {
				hash[i] = false;
			}
			if (a[i + 1][i] == 3) {
				hash[i] = hash[i + 1] = false;
			}
		}
	}

	if (a[1][n] != 0) {
		if (a[1][n] == 1) {
			hash[1] = false;
		}
		if (a[1][n] == 2) {
			hash[n] = false;
		}
		if (a[1][n] == 3) {
			hash[1] = hash[n] = false;
		}
	}

	if (a[n][1] != 0) {
		if (a[n][1] == 1) {
			hash[n] = false;
		}
		if (a[n][1] == 2) {
			hash[1] = false;
		}
		if (a[n][1] == 3) {
			hash[1] = hash[n] = false;
		}
	}

	int[] ans; int sum;
	foreach (i; 1 .. n + 1) {
		if (i !in hash) {
			++sum;
			ans ~= i;
		}
	}

	writeln(sum);
	if (sum > 0) {
		writefln("%(%s %)", ans);
	}
}


You have a permutation: an array $$$a = [a_1, a_2, \ldots, a_n]$$$ of distinct integers from $$$1$$$ to $$$n$$$. The length of the permutation $$$n$$$ is odd.You need to sort the permutation in increasing order.In one step, you can choose any prefix of the permutation with an odd length and reverse it. Formally, if $$$a = [a_1, a_2, \ldots, a_n]$$$, you can choose any odd integer $$$p$$$ between $$$1$$$ and $$$n$$$, inclusive, and set $$$a$$$ to $$$[a_p, a_{p-1}, \ldots, a_1, a_{p+1}, a_{p+2}, \ldots, a_n]$$$.Find a way to sort $$$a$$$ using no more than $$$\frac{5n}{2}$$$ reversals of the above kind, or determine that such a way doesn't exist. The number of reversals doesn't have to be minimized.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 2021$$$; $$$n$$$ is odd) — the length of the permutation. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$) — the permutation itself.  It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2021$$$.

For each test case, if it's impossible to sort the given permutation in at most $$$\frac{5n}{2}$$$ reversals, print a single integer $$$-1$$$. Otherwise, print an integer $$$m$$$ ($$$0 \le m \le \frac{5n}{2}$$$), denoting the number of reversals in your sequence of steps, followed by $$$m$$$ integers $$$p_i$$$ ($$$1 \le p_i \le n$$$; $$$p_i$$$ is odd), denoting the lengths of the prefixes of $$$a$$$ to be reversed, in chronological order. Note that $$$m$$$ doesn't have to be minimized. If there are multiple answers, print any.

NoteIn the first test case, the permutation is already sorted. Any even number of reversals of the length $$$3$$$ prefix doesn't change that fact.In the second test case, after reversing the prefix of length $$$3$$$ the permutation will change to $$$[5, 4, 3, 2, 1]$$$, and then after reversing the prefix of length $$$5$$$ the permutation will change to $$$[1, 2, 3, 4, 5]$$$.In the third test case, it's impossible to sort the permutation.

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		if (a.stride (2).canFind !(q{a % 2 == 0}))
		{
			writeln (-1);
			continue;
		}

		int [] answer;

		void go (int pos)
		{
			answer ~= pos;
			reverse (a[0..pos]);
		}

		for ( ; n > 1; n -= 2)
		{
			go (a.countUntil (n).to !(int) + 1);
			go (a.countUntil (n - 1).to !(int) + 0);
			go (a.countUntil (n - 1).to !(int) + 2);
			go (3);
			go (n);
			debug {writeln (a);}
		}

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

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

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

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

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

void main() {
  debug {
    for (int n = 3; n <= 7; n += 2) {
      writeln("n = ", n);
      int[string] vis;
      auto as = iota(n).array;
      void dfs(int last) {
        const key = as.to!string;
        if (key !in vis) {
          vis[key] = last;
          for (int m = 3; m <= n; m += 2) {
            as[0 .. m].reverse;
            dfs(m);
            as[0 .. m].reverse;
          }
        }
      }
      dfs(-1);
      foreach (key, val; vis) {
        writeln(key, " ", val);
      }
      writeln("|vis| = ", vis.length);
    }
  }

  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const N = readInt();
        auto A = new int[N];
        foreach (i; 0 .. N) {
          A[i] = readInt() - 1;
        }

        bool ok = true;
        foreach (i; 0 .. N) {
          ok = ok && ((A[i] - i) % 2 == 0);
        }
        if (ok) {
          auto as = A.dup;
          int[] ans;
          for (int n = N; n > 1; n -= 2) {
            int p = -1, q = -1;
            foreach (i; 0 .. n) {
              if (as[i] == n - 2) p = i;
              if (as[i] == n - 1) q = i;
            }

            void oper(int m) {
              assert(m % 2 != 0);
              ans ~= m;
              as[0 .. m].reverse;
              if (p < m) p = m - 1 - p;
              if (q < m) q = m - 1 - q;
            }
            oper(q + 1);
            oper(p);
            oper(n);
            oper(q + 1);
            oper(n);
            assert(p == n - 2);
            assert(q == n - 1);
          }

          const ansLen = cast(int)(ans.length);
          writeln(ansLen);
          foreach (i; 0 .. ansLen) {
            if (i > 0) write(" ");
            write(ans[i]);
          }
          writeln;
          assert(2 * ansLen <= 5 * N);
        } else {
          writeln(-1);
        }
      }
    }
  } catch (EOFException e) {
  }
}


Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false. Implication is written by using character '', and the arguments and the result of the implication are written as '0' (false) and '1' (true). According to the definition of the implication:   When a logical expression contains multiple implications, then when there are no brackets, it will be calculated from left to fight. For example,. When there are brackets, we first calculate the expression in brackets. For example,.For the given logical expression  determine if it is possible to place there brackets so that the value of a logical expression is false. If it is possible, your task is to find such an arrangement of brackets.

The first line contains integer n (1 ≤ n ≤ 100 000) — the number of arguments in a logical expression. The second line contains n numbers a1, a2, ..., an (), which means the values of arguments in the expression in the order they occur.

Print "NO" (without the quotes), if it is impossible to place brackets in the expression so that its value was equal to 0. Otherwise, print "YES" in the first line and the logical expression with the required arrangement of brackets in the second line. The expression should only contain characters '0', '1', '-' (character with ASCII code 45), '>' (character with ASCII code 62), '(' and ')'. Characters '-' and '>' can occur in an expression only paired like that: ("->") and represent implication. The total number of logical arguments (i.e. digits '0' and '1') in the expression must be equal to n. The order in which the digits follow in the expression from left to right must coincide with a1, a2, ..., an. The expression should be correct. More formally, a correct expression is determined as follows:   Expressions "0", "1" (without the quotes) are correct.  If v1, v2 are correct, then v1->v2 is a correct expression.  If v is a correct expression, then (v) is a correct expression.  The total number of characters in the resulting expression mustn't exceed 106. If there are multiple possible answers, you are allowed to print any of them.

import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.range;
import std.container.dlist;

int impl(int x, int y) {
  return (1 - x) | y;
}

string solve(int[] a) {
  auto n = a.length;
  if (a.back() != 0) {
    return "";
  }
  if (n == 1) {
    return "0";
  }
  int val = a[n - 2];
  foreach_reverse (i; 0..n-2) {
    val = impl(a[i], val);
  }
  if (val != 1) {
    return "";
  }
  char[] buf;
  foreach (i; 0..n-2) {
    buf ~= "(" ~ to!string(a[i]) ~ "->";
  }
  buf ~= "(" ~ to!string(a[a.length-2]);
  buf ~= ')'.repeat().take(a.length - 1).array;
  buf ~= "->0";
  return buf.dup;
}

void main() {
  int n = readln().strip().to!int;
  auto a = readln().split().map!(to!int).array;
  string ans = solve(a);
  if (!ans.empty()) {
    writeln("YES");
    writeln(ans);
  } else {
    writeln("NO");
  }

}

import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.container.dlist;

bool dcare(int[] s, int p, ref DList!string ans) {
  if (p >= s.length) {
    return true;
  } else if (s[p] == 0){
    ans.insertFront("(0->");
    ans.insertBack(")");
    dcare(s, p + 1, ans);
    return true;
  } else {
    ans.insertFront("(1->");
    ans.insertBack(")");
    dcare(s, p + 1, ans);
    return true;
  }
}

bool exact_zero(int[] s, int p, ref DList!string ans) {
  if (p >= s.length) {
    return false;
  } else if (s[p] == 1) {
    ans.insertFront("(1->");
    ans.insertBack(")");
    return exact_zero(s, p + 1, ans);
  } else {
    ans.insertFront("(0->");
    ans.insertBack(")");
    dcare(s, p + 1, ans);
    return true;
  }
}

bool one(int[] s, int p, ref DList!string ans) {
  if (p >= s.length) {
    return true;
  } else if (s[p] == 0) {
    ans.insertBack("(0)");
    if (!exact_zero(s, p + 1, ans)) {
      return false;
    }
    return true;
  } else {
    ans.insertBack("(1)");
    dcare(s, p + 1, ans);
    return true;
  }
}

bool zero(int[] s, int p, ref DList!string ans) {
  if (p >= s.length) {
    return false;
  } else if (s[p] == 1) {
    return false;
  } else {
    if (!one(s, p + 1, ans)) {
      return false;
    }
    if (p == s.length - 1) {
      ans.insertBack("(0)");
    } else {
      ans.insertFront("(");
      ans.insertBack("->0)");
    }
    return true;
  }
}

void main() {
  int n = readln().strip().to!int;
  auto a = readln().split().map!(to!int).array;
  a.reverse();
  DList!string ans;
  if (zero(a, 0, ans)) {
    writeln("YES");
    writeln(ans.array.join(""));
  } else {
    writeln("NO");
  }

}

import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.container.dlist;

bool dcare(int[] s, int p, ref DList!string ans) {
  if (p >= s.length) {
    return true;
  } else if (s[p] == 0){
    ans.insertFront("(0->");
    ans.insertBack(")");
    dcare(s, p + 1, ans);
    return true;
  } else {
    ans.insertFront("(1->");
    ans.insertBack(")");
    dcare(s, p + 1, ans);
    return true;
  }
}

bool one(int[] s, int p, ref DList!string ans) {
  if (p >= s.length) {
    return true;
  } else if (s[p] == 0) {
    if (!zero(s, p + 1, ans)) {
      return false;
    }
    ans.insertFront("(");
    ans.insertBack("->0)");
    return true;
  } else {
    ans.insertBack("(1)");
    dcare(s, p + 1, ans);
    return true;
  }
}

bool zero(int[] s, int p, ref DList!string ans) {
  if (p >= s.length) {
    return false;
  } else if (s[p] == 1) {
    return false;
  } else {
    if (!one(s, p + 1, ans)) {
      return false;
    }
    if (p == s.length - 1) {
      ans.insertBack("(0)");
    } else {
      ans.insertFront("(");
      ans.insertBack("->0)");
    }
    return true;
  }
}

void main() {
  int n = readln().strip().to!int;
  auto a = readln().split().map!(to!int).array;
  a.reverse();
  DList!string ans;
  if (zero(a, 0, ans)) {
    writeln("YES");
    writeln(ans.array.join(""));
  } else {
    writeln("NO");
  }

}

import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.container.dlist;

bool dcare(int[] s, int p, ref DList!string ans) {
  if (p >= s.length) {
    return true;
  } else if (s[p] == 0){
    ans.insertFront("(0->");
    ans.insertBack(")");
    dcare(s, p + 1, ans);
    return true;
  } else {
    ans.insertFront("(1->");
    ans.insertBack(")");
    dcare(s, p + 1, ans);
    return true;
  }
}

bool exact_zero(int[] s, int p, ref DList!string ans) {
  if (p >= s.length) {
    return false;
  } else if (s[p] == 1) {
    return false;
  } else {
    ans.insertBack("(0)");
    return true;
  }
}

bool one(int[] s, int p, ref DList!string ans) {
  if (p >= s.length) {
    return true;
  } else if (s[p] == 0) {
    if (!exact_zero(s, p + 1, ans)) {
      return false;
    }
    ans.insertFront("(");
    ans.insertBack("->0)");
    dcare(s, p + 2, ans);
    return true;
  } else {
    ans.insertBack("(1)");
    dcare(s, p + 1, ans);
    return true;
  }
}

bool zero(int[] s, int p, ref DList!string ans) {
  if (p >= s.length) {
    return false;
  } else if (s[p] == 1) {
    return false;
  } else {
    if (!one(s, p + 1, ans)) {
      return false;
    }
    if (p == s.length - 1) {
      ans.insertBack("(0)");
    } else {
      ans.insertFront("(");
      ans.insertBack("->0)");
    }
    return true;
  }
}

void main() {
  int n = readln().strip().to!int;
  auto a = readln().split().map!(to!int).array;
  a.reverse();
  DList!string ans;
  if (zero(a, 0, ans)) {
    writeln("YES");
    writeln(ans.array.join(""));
  } else {
    writeln("NO");
  }

}