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

void main ()
{
	int rows, cols;
	while (readf (" %s %s", &rows, &cols) > 0)
	{
		readln;
		auto a = new bool [] [] (rows + 2, cols + 2);
		foreach (row; 1..rows + 1)
		{
			auto s = readln.strip;
			foreach (col; 1..cols + 1)
			{
				a[row][col] = (s[col - 1] == '*');
			}
		}
		rows += 2;
		cols += 2;

		auto dr = new int [] [] (rows, cols);
		foreach (row; 0..rows)
		{
			int val = -1;
			foreach (col; 0..cols)
			{
				if (a[row][col])
				{
					val += 1;
				}
				else
				{
					val = -1;
				}
				dr[row][col] = val;
			}
		}

		auto dl = new int [] [] (rows, cols);
		foreach (row; 0..rows)
		{
			int val = -1;
			foreach_reverse (col; 0..cols)
			{
				if (a[row][col])
				{
					val += 1;
				}
				else
				{
					val = -1;
				}
				dl[row][col] = val;
			}
		}

		auto dd = new int [] [] (rows, cols);
		foreach (col; 0..cols)
		{
			int val = -1;
			foreach (row; 0..rows)
			{
				if (a[row][col])
				{
					val += 1;
				}
				else
				{
					val = -1;
				}
				dd[row][col] = val;
			}
		}

		auto du = new int [] [] (rows, cols);
		foreach (col; 0..cols)
		{
			int val = -1;
			foreach_reverse (row; 0..rows)
			{
				if (a[row][col])
				{
					val += 1;
				}
				else
				{
					val = -1;
				}
				du[row][col] = val;
			}
		}

		int res = 0;
		auto mr = new int [] [] (rows, cols);
		auto ml = new int [] [] (rows, cols);
		auto md = new int [] [] (rows, cols);
		auto mu = new int [] [] (rows, cols);
		foreach (row; 0..rows)
		{
			foreach (col; 0..cols)
			{
				auto d = min (dr[row][col], dl[row][col],
				    dd[row][col], du[row][col]);
				if (d <= 0)
				{
					continue;
				}
				int r = d * 2 + 1;
				res += 1;
				mr[row][col - d] = max (mr[row][col - d], r);
				ml[row][col + d] = max (ml[row][col + d], r);
				md[row - d][col] = max (md[row - d][col], r);
				mu[row + d][col] = max (mu[row + d][col], r);
			}
		}

		foreach (row; 0..rows)
		{
			int val = 0;
			foreach (col; 0..cols)
			{
				val = max (val, mr[row][col]);
				if (val > 0)
				{
					a[row][col] = false;
					val -= 1;
				}
			}
		}

		foreach (row; 0..rows)
		{
			int val = 0;
			foreach_reverse (col; 0..cols)
			{
				val = max (val, ml[row][col]);
				if (val > 0)
				{
					a[row][col] = false;
					val -= 1;
				}
			}
		}

		foreach (col; 0..cols)
		{
			int val = 0;
			foreach (row; 0..rows)
			{
				val = max (val, md[row][col]);
				if (val > 0)
				{
					a[row][col] = false;
					val -= 1;
				}
			}
		}

		foreach (col; 0..cols)
		{
			int val = 0;
			foreach_reverse (row; 0..rows)
			{
				val = max (val, mu[row][col]);
				if (val > 0)
				{
					a[row][col] = false;
					val -= 1;
				}
			}
		}

		debug {writefln ("%(%(%d %)\n%)", a);}
		if (a.any !(any))
		{
			writeln (-1);
			continue;
		}

		writeln (res);
		foreach (row; 0..rows)
		{
			foreach (col; 0..cols)
			{
				auto d = min (dr[row][col], dl[row][col],
				    dd[row][col], du[row][col]);
				if (d <= 0)
				{
					continue;
				}
				writeln (row, " ", col, " ", d);
			}
		}
	}
}

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

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

    dchar[][] arr;
    arr ~= (cast(dchar)'.').repeat(m).array;
    foreach (_; 0 .. n) arr ~= readln.chomp.to!(dchar[]);
    arr ~= (cast(dchar)'.').repeat(m).array;

    foreach (ref rw; arr) rw = cast(dchar)'.' ~ rw ~ cast(dchar)'.';

    debug { arr.writeln; }

    auto covered = new bool[][] (n+1, m+1);
    Tuple!(int, int, int)[] ans;
    foreach (i, rw; arr) {
        foreach (j, el; rw) {
            if (el != '*') continue;

            int range = 0;
            while (arr[i-range-1][j] == '*' && arr[i+range+1][j] == '*'
                  && arr[i][j-range-1] == '*' && arr[i][j+range+1] == '*') {
                covered[i-range-1][j] = true;
                covered[i+range+1][j] = true;
                covered[i][j-range-1] = true;
                covered[i][j+range+1] = true;
                ++range;
            }

            if (range > 0) {
                covered[i][j] = true;
                ans ~= tuple(cast(int)i, cast(int)j, range);
            }
        }
    }

    foreach (i, rw; covered) {
        foreach (j, e; rw) {
            if (arr[i][j] == '*' && !covered[i][j]) {
                writeln(-1);
                return;
            }
        }
    }

    ans.length.writeln;
    ans.each!(t => writeln(t[0], ' ', t[1], ' ', t[2]));
}

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

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

    dchar[][] arr;
    arr ~= (cast(dchar)'.').repeat(m).array;
    foreach (_; 0 .. n) arr ~= readln.chomp.to!(dchar[]);
    arr ~= (cast(dchar)'.').repeat(m).array;

    foreach (ref rw; arr) rw = cast(dchar)'.' ~ rw ~ cast(dchar)'.';

    debug { arr.writeln; }

    auto reach = new int[][][] (n+2, m+2, 4);
    foreach (i, rw; arr) {
        foreach (j, e; rw) {
            if (e == '.') reach[i][j][0] = reach[i][j][1] = 0;
            else {
                reach[i][j][0] = 1 + reach[i-1][j][0];
                reach[i][j][1] = 1 + reach[i][j-1][1];
            }
        }
    }
    foreach_reverse (i, rw; arr) {
        foreach_reverse (j, e; rw) {
            if (e == '.') reach[i][j][2] = reach[i][j][3] = 0;
            else {
                reach[i][j][2] = 1 + reach[i+1][j][2];
                reach[i][j][3] = 1 + reach[i][j+1][3];
            }

        }
    }

    auto cnt = new int[][][] (2, n+2, m+2);
    Tuple!(int, int, int)[] ans;
    foreach (i, rw; arr) {
        foreach (j, el; rw) {
            if (el != '*') continue;

            int range = reach[i][j].minElement - 1;

            if (range > 0) {
                cnt[0][i][j-range] += 1;
                cnt[0][i][j+range+1] -= 1;
                cnt[1][i-range][j] += 1;
                cnt[1][i+range+1][j] -= 1;
                ans ~= tuple(cast(int)i, cast(int)j, range);
            }
        }
    }

    foreach (ref rw; cnt[0]) {
        rw = rw.cumulativeFold!((a, b) => a + b).array;
    }
    foreach (i, rw; cnt[1]) {
        foreach (j, ref e; rw) {
            if (i > 0) e += cnt[1][i-1][j];
        }
    }

    foreach (i, rw; arr) {
        foreach (j, e; rw) {
            if (e == '.') continue;
            if (!cnt[0][i][j] && !cnt[1][i][j]) {
                writeln(-1);
                return;
            }
        }
    }

    ans.length.writeln;
    ans.each!(t => writeln(t[0], ' ', t[1], ' ', t[2]));
}


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

int N;
int[] A;
void main() {
    scanf("%d\n", &N);
    A = readln.chomp.split(" ").map!(to!int).array;
    int[] L1 = new int[N];
    int[] L2 = new int[N];

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

    L2[N - 1] = 1;
    for (int i = N - 1; i > 0; i--) {
        if (A[i - 1] + 1 <= A[i]) {
            L2[i - 1] = L2[i] + 1;
        } else {
            L2[i - 1] = 1;
        }
    }
    //writeln(L1);
    //writeln(L2);

    int Ans = L1.reduce!max;
    if (N > 1 && L2[0] == 1) Ans = max(Ans, L2[1] + 1);
    if (N > 1 && L1[$ - 1] == 1) Ans = max(Ans, L1[$ - 2] + 1);
    foreach (i; 0 .. N - 2) {
        if (A[i] >= A[i + 1]) {
            Ans = max(Ans, L1[i] + 1, L2[i + 1] + 1);
        }
        if (A[i] + 2 <= A[i + 2]) {
            Ans = max(Ans, L1[i] + L2[i + 2] + 1);
        }
    }
    writeln(Ans);
}

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.stdio, std.bitmanip;

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

    auto dp = new int[][](2, N);
    dp[0][0] = dp[1][N-1] = 1;

    foreach (i; 1..N) {
        dp[0][i] = (A[i] > A[i-1]) ? dp[0][i-1] + 1 : 1;
        dp[1][N-i-1] = (A[N-i] > A[N-i-1]) ? dp[1][N-i] + 1 : 1;
    }

    int ans = 0;

    foreach (i; 0..N) ans = max(max(ans, dp[0][i]+1), dp[1][i]+1);
    foreach (i; 0..N-2) if (A[i+2] - A[i] >= 2) ans = max(ans, dp[0][i]+dp[1][i+2]+1);

    writeln(min(ans, N));
}

import std.stdio, std.string;

void update(ref int tar, int val)
{
    if (val > tar)
    {
        tar = val;
    }
}

void solve(int[] a)
{
    auto pre = new int[a.length];
    auto len = new int[a.length];
    pre[0] = 0;
    len[0] = 1;
    foreach (i; 1 .. a.length)
    {
        if (a[i] > a[i - 1])
        {
            pre[i] = pre[i - 1];
        }
        else
        {
            pre[i] = i;
        }
        len[i] = i - pre[i] + 1;
    }
    int ans = 0;
    foreach (i; 0 .. a.length)
    {
        update(ans, len[i]);
        int idx = pre[i];
        if (idx > 0)
        {
            update(ans, len[i] + 1);
            if (len[i] == 1)
            {
                update(ans, len[idx - 1] + 1);
            }
        }
        if (idx > 1)
        {
            if (a[idx] - a[idx - 2] > 1)
            {
                update(ans, len[i] + 1 + len[idx - 2]);
            }
            if (len[i] > 1)
            {
                if (a[idx + 1] - a[idx - 1] > 1)
                {
                    update(ans, len[i] + len[idx - 1]);
                }
            }
        }
    }
    writefln("%d", ans);
}

void main(string[] args)
{
    int n;
    while (scanf("%d", &n) == 1)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            scanf("%d", &a[i]);
        }
        solve(a);
    }
}

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

//	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 N;
int[] A;

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

		int[] ls = new int[N];
		int[] rs = new int[N];
		ls[0] = 0;
		foreach (i; 1 .. N) {
			ls[i] = (A[i - 1] < A[i]) ? ls[i - 1] : i;
		}
		rs[N - 1] = N - 1;
		foreach_reverse (i; 0 .. N - 1) {
			rs[i] = (A[i] < A[i + 1]) ? rs[i + 1] : i;
		}

		int ans;

		//	no change
		foreach (i; 0 .. N) {
			chmax(ans, rs[i] - i + 1);
		}

		//	one change, one side
		foreach (i; 0 .. N) {
			if (i - 1 >= 0) {
				chmax(ans, i - ls[i - 1] + 1);
			}
			if (i + 1 < N) {
				chmax(ans, rs[i + 1] - i + 1);
			}
		}

		//	one change, two sides
		foreach (i; 1 .. N - 1) {
			if (A[i + 1] - A[i - 1] >= 2) {
				chmax(ans, rs[i + 1] - ls[i - 1] + 1);
			}
		}

		writeln(ans);

	}
	} catch (EOFException) {}
}

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

int N;
int[] A;
void main() {
    scanf("%d\n", &N);
    A = readln.chomp.split(" ").map!(to!int).array;
    int[] L1 = new int[N];
    int[] L2 = new int[N];

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

    L2[N - 1] = 1;
    for (int i = N - 1; i > 0; i--) {
        if (A[i - 1] + 1 <= A[i]) {
            L2[i - 1] = L2[i] + 1;
        } else {
            L2[i - 1] = 1;
        }
    }

    int Ans = L1.reduce!max;
    if (N > 1 && L1[$ - 1] == 1) Ans = max(Ans, L1[$ - 2] + 1);
    foreach (i; 0 .. N - 2) {
        if (A[i] >= A[i + 1]) Ans = max(Ans, L1[i] + 1);
        if (A[i] + 2 <= A[i + 2]) {
            Ans = max(Ans, L1[i] + L2[i + 2] + 1);
        }
    }
    writeln(Ans);
}

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

int N;
int[] A;
void main() {
    scanf("%d\n", &N);
    A = readln.chomp.split(" ").map!(to!int).array;
    int[] L1 = new int[N];
    int[] L2 = new int[N];

    if (N == 2) {
        writeln(2);
        return;
    }

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

    L2[N - 1] = 1;
    for (int i = N - 1; i > 0; i--) {
        if (A[i - 1] + 1 <= A[i]) {
            L2[i - 1] = L2[i] + 1;
        } else {
            L2[i - 1] = 1;
        }
    }

    int Ans = L1.reduce!max;
    foreach (i; 0 .. N - 2) {
        if (A[i] >= A[i + 1]) Ans = max(Ans, L1[i] + 1);
        if (A[i] + 2 <= A[i + 2]) {
            Ans = max(Ans, L1[i] + L2[i + 2] + 1);
        }
    }
    writeln(Ans);
}

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

int N;
int[] A;
void main() {
    scanf("%d\n", &N);
    A = readln.chomp.split(" ").map!(to!int).array;
    int[] L1 = new int[N];
    int[] L2 = new int[N];

    if (N == 2) {
        writeln(2);
        return;
    }

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

    L2[N - 1] = 1;
    for (int i = N - 1; i > 0; i--) {
        if (A[i - 1] + 1 <= A[i]) {
            L2[i - 1] = L2[i] + 1;
        } else {
            L2[i - 1] = 1;
        }
    }

    int Ans = L1.reduce!max;
    if (L1[$ - 1] == 1) Ans = max(Ans, L1[$ - 2] + 1);
    foreach (i; 0 .. N - 2) {
        if (A[i] >= A[i + 1]) Ans = max(Ans, L1[i] + 1);
        if (A[i] + 2 <= A[i + 2]) {
            Ans = max(Ans, L1[i] + L2[i + 2] + 1);
        }
    }
    writeln(Ans);
}

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

int N;
int[] A;
void main() {
    scanf("%d\n", &N);
    A = readln.chomp.split(" ").map!(to!int).array;
    int[] L1 = new int[N];
    int[] L2 = new int[N];

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

    L2[N - 1] = 1;
    for (int i = N - 1; i > 0; i--) {
        if (A[i - 1] + 1 <= A[i]) {
            L2[i - 1] = L2[i] + 1;
        } else {
            L2[i - 1] = 1;
        }
    }
    //writeln(L1);
    //writeln(L2);

    int Ans = L1.reduce!max;
    if (N > 1 && L2[0] == 1) Ans = max(Ans, L2[1] + 1);
    if (N > 1 && L1[$ - 1] == 1) Ans = max(Ans, L1[$ - 2] + 1);
    foreach (i; 0 .. N - 2) {
        if (A[i] >= A[i + 1]) Ans = max(Ans, L1[i] + 1);
        if (A[i] + 2 <= A[i + 2]) {
            Ans = max(Ans, L1[i] + L2[i + 2] + 1);
        }
    }
    writeln(Ans);
}

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.stdio, std.bitmanip;

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

    auto dp = new int[][](N, 3);
    dp[0][0] = 1;

    foreach (i; 1..N) {
        if (A[i] > A[i-1]) {
            dp[i][0] = dp[i-1][0] + 1;
            if (i > 1 && A[i] > A[i-2] + 1)
                dp[i][2] = dp[i-1][1] + 1;
            dp[i][2] = max(dp[i][2], dp[i-1][2]+1);
        }
        else {
            dp[i][0] = 1;
            dp[i][1] = dp[i-1][0]+1;
            dp[i][2] = 1;
        }
    }

    int ans = 0;
    foreach (i; 0..N) foreach (j; 0..2) ans = max(ans, dp[i][j]);
    writeln(ans);
}

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.stdio, std.bitmanip;

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

    auto dp = new int[][](N, 3);
    dp[0][0] = 1;

    foreach (i; 1..N) {
        if (A[i] > A[i-1]) {
            dp[i][0] = dp[i-1][0] + 1;
            if (i > 1 && A[i] > A[i-2] + 1)
                dp[i][2] = dp[i-1][1] + 1;
            dp[i][2] = max(dp[i][2], dp[i-1][2]+1);
        }
        else {
            dp[i][0] = 1;
            dp[i][1] = dp[i-1][0]+1;
            dp[i][2] = 1;
        }
    }

    int ans = 0;
    foreach (i; 0..N) foreach (j; 0..3) ans = max(ans, dp[i][j]);
    writeln(ans);
}

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.stdio, std.bitmanip;

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

    auto dp = new int[](N);
    dp[0] = 1;

    foreach (i; 1..N)
        dp[i] = (A[i] > A[i-1]) ? dp[i-1] + 1 : 1;

    int ans = 0;

    foreach (i; 0..N) ans = max(ans, dp[i]+1);
    foreach (i; 0..N-2) if (dp[i+2] - dp[i] >= 2) ans = max(ans, dp[i]+dp[i+2]+1);

    writeln(min(ans, N));
}

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.stdio, std.bitmanip;

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

    auto dp = new int[][](N, 2);
    dp[0][0] = dp[0][1] = 1;

    foreach (i; 1..N) {
        if (A[i] > A[i-1]) {
            dp[i][0] = dp[i-1][0] + 1;
            dp[i][1] = dp[i-1][1] + 1;
        }
        else {
            dp[i][0] = 1;
            dp[i][1] = max(dp[i-1][1], dp[i-1][0]+1);
        }
    }

    int ans = 0;
    foreach (i; 0..N) foreach (j; 0..2) ans = max(ans, dp[i][j]);
    writeln(ans);
}


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

void main()
{
	int t = readInt!int;
	while (t--) solve;
}
void solve()
{
	int m = readInt!int;
	auto a = new long[][](2, m);
	auto score = new long[](m);
	foreach(ref row; a) foreach(ref cell; row) cell = readInt!long;
	auto pf1 = a[0].cumulativeFold!((a, b) => a + b).array;
	auto pf2 = a[1].cumulativeFold!((a, b) => a + b).array;
	alias sum1 = (i, j) => (i > 0? pf1[j] - pf1[i - 1] : pf1[j]);
	alias sum2 = (i, j) => (i > 0? pf2[j] - pf2[i - 1] : pf2[j]);
	foreach(i; 0 .. m)
	{
		score[i] = sum1(0, i) + sum2(i, m - 1);
	}
	auto mxp = score.cumulativeFold!max.array; mxp[] -= a[0][0];
	auto mxs = score.reverse.cumulativeFold!max.array.reverse.array; mxs[] -= a[1][m-1];
	long minAns = long.max;
	foreach(i; 0 .. m)
	{
		auto p1 = i > 0? sum2(0, i - 1) : 0;
		auto p2 = i + 1 < m? sum1(i + 1, m - 1) : 0;
		minAns = min(minAns, max(p1, p2));
	}
	minAns.writeln;
}

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

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

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

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

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

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

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

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

import std.algorithm;
import std.random;

struct SegmentTreeLazy(V, U, alias f, alias fou, alias uou, string fName = null, string uName = null)
{
	alias This = typeof(this);
	size_t length;
	size_t realLength = 0;
	V[] _nodeFValue;
	U[] _nodeUpdate;
	bool[] _nodeHasUpdate;
	size_t[] _nodeRangeEnd;
	size_t[] _nodeRangeStart;
	string toString()
	{
		import std.conv;
		string str;
		foreach(i; 0 .. realLength)
			if (_nodeHasUpdate[i])
			{
				str ~= text(_nodeFValue[i], "(", _nodeUpdate[i], "), ");
			}
			else
			{
				str ~= text(_nodeFValue[i], ", ");
			}
		return str;
	}
	this(size_t length, V initialValue)
	{
		this.length = length;
		size_t noNodes = 4 * length;
		_nodeFValue = new V[](noNodes);
		_nodeUpdate = new U[](noNodes);
		_nodeHasUpdate = new bool[](noNodes);
		_nodeRangeEnd = new size_t[](noNodes);
		_nodeRangeStart = new size_t[](noNodes);
		void fill(size_t i, size_t rangeStart, size_t rangeEnd)
		{
			realLength = max(realLength, i + 1);
			_nodeRangeStart[i] = rangeStart;
			_nodeRangeEnd[i] = rangeEnd;
			if (_isLeaf(i)) { _nodeFValue[i] = initialValue; return; }
			size_t l = i<<1;
			size_t r = l+1;
			size_t m = (rangeStart + rangeEnd) / 2;
			fill(l, rangeStart, m), fill(r, m + 1, rangeEnd);
			_nodeFValue[i] = f(_nodeFValue[l], _nodeFValue[r]);
		}
		fill(1, 0, length - 1);
	}
	V rangeF(size_t start, size_t end)
	{
		bool set = false;
		V result;
		void visit(size_t i) in(_hasFragments(i, start, end))
		{
			if (_isFragment(i, start, end))
			{
				if (!set) { result = _cookedF(i); set = true; }
				else { result = f(result, _cookedF(i)); }
				return;
			}
			_clearUpdate(i);
			size_t l = i<<1, r = (i<<1)+1;
			if (_hasFragments(l, start, end)) visit(l);
			if (_hasFragments(r, start, end)) visit(r);
		}
		visit(1);
		return result;
	}
	void rangeU(size_t start, size_t end, U u)
	{
		void visit(size_t i) in(_hasFragments(i, start, end))
		{
			if (_isFragment(i, start, end))
			{
				_addUpdate(i, u);
				return;
			}
			_clearUpdate(i);
			size_t l = i<<1, r = (i<<1)+1;
			if (_hasFragments(l, start, end)) visit(l);
			if (_hasFragments(r, start, end)) visit(r);
			_nodeFValue[i] = f(_cookedF(l), _cookedF(r));
		}
		visit(1);
	}
	V _cookedF(size_t i)
	{
		if (_nodeHasUpdate[i]) { return fou(_nodeFValue[i],
						    _nodeUpdate[i],
						    _nodeRangeStart[i],
						    _nodeRangeEnd[i]); }
		return _nodeFValue[i];
	}
	void _clearUpdate(size_t i)
	{
		if (!_nodeHasUpdate[i]) return;
		if (_isLeaf(i)) { _nodeFValue[i] = _cookedF(i); _nodeHasUpdate[i] = false; return;}
		size_t l = i<<1, r = (i<<1)+1;
		_addUpdate(l, _nodeUpdate[i]), _addUpdate(r, _nodeUpdate[i]);
		_nodeFValue[i] = f(_cookedF(l), _cookedF(r));
		_nodeHasUpdate[i] = false;
	}
	void _addUpdate(size_t i, U u)
	{
		if (!_nodeHasUpdate[i]) { _nodeHasUpdate[i] = true; _nodeUpdate[i] = u; return; }
		_nodeUpdate[i] = uou(_nodeUpdate[i], u);
	}
	bool _isLeaf(size_t i)
	{
		return _nodeRangeStart[i] == _nodeRangeEnd[i];
	}
	bool _isFragment(size_t i, size_t rangeStart, size_t rangeEnd)
	{
		return rangeStart <= _nodeRangeStart[i] && _nodeRangeEnd[i] <= rangeEnd;
	}
	bool _hasFragments(size_t i, size_t rangeStart, size_t rangeEnd)
	{
		return _nodeRangeStart[i] <= rangeEnd && rangeStart <= _nodeRangeEnd[i];
	}
	// prettifiers
	struct Handle
	{
		import std.ascii;
		size_t _start, _end;
		This* _parent;
		auto f()
		{
			return _parent.rangeF(_start, _end);
		}
		auto u(U v)
		{
			_parent.rangeU(_start, _end, v);
		}
		static if (fName !is null)
		{
			mixin(q{alias }, fName, q{ = f;});
		}
		static if (uName !is null)
		{
			static if (uName[0].isAlphaNum)
			{
				mixin(q{alias }, uName, q{ = u;});
			}
			else static if (uName[0] != ' ')
			{
				ref Handle opOpAssign(string operator)(U v)
				if (operator == uName)
				{
					u(v);
					return this;
				}
			}
			else
			{
				ref Handle opAssign(U v)
				{
					u(v);
					return this;
				}
			}
		}
	}
	size_t[2] opSlice(size_t i)(size_t s, size_t e) if (i == 0)
	{
		return [s, e-1];
	}
	auto opIndex(size_t[2] slice)
	{
		return Handle(slice[0], slice[1], &this);
	}
}

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

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    int m;
    readf!" %d "(m);
    auto a = readln.strip.split.map!(to!long).array;
    auto b = readln.strip.split.map!(to!long).array;

    long[] sfa = [0L];
    long sum;
    foreach_reverse (x ; a) {
      sum += x;
      sfa ~= sum;
    }
    long[] pfb = [0L];
    sum = 0;
    foreach (x ; b) {
      sum += x;
      pfb ~= sum;
    }

    long min_bobscore = long.max;
    foreach (i ; 0 .. m) {
      long bobscore1 = pfb[i];
      long bobscore2 = sfa[$ - i - 2];
      long bobscore = max(bobscore1, bobscore2);
      if (bobscore < min_bobscore)
        min_bobscore = bobscore;
    }
    writeln(min_bobscore);
  }
}

import std;

T read (T, string ending = "", string beginning = "") () @trusted {
    scope T x;
    readf!(beginning ~ "%s" ~ ending)(x);
    return x;
}

void main () {
    immutable tests = read!(uint, "\n");
    TEST_LOOP: foreach (test_index; 0 .. tests) {
        immutable m = readln.chomp.to!uint;

        auto mat = (){
            auto result = appender!(uint[]);
            result.reserve(2 * m);

            foreach (line; stdin.byLine.take(2))
                result.put(line.splitter(' ').map!(to!uint));

            return chunks(result[].assumeUnique, m);
        }();

        immutable sum = mat[0].sum;

        StoppingPolicy.requireSameLength.zip(
            cumulativeFold!"a - b"(mat[0], sum),
            cumulativeFold!"a + b"(chain([0], mat[1].dropBackOne))
        ).map!"max(a.expand)".minElement.writeln;
    }
}

// "" `` '' () {} []

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

void main()
{
	int t = readInt!int;
	while (t--) solve;
}
void solve()
{
	int m = readInt!int;
	auto a = new long[][](2, m);
	auto score = new long[](m);
	foreach(ref row; a) foreach(ref cell; row) cell = readInt!long;
	auto pf1 = a[0].cumulativeFold!((a, b) => a + b).array;
	auto pf2 = a[1].cumulativeFold!((a, b) => a + b).array;
	alias sum1 = (i, j) => (i > 0? pf1[j] - pf1[i - 1] : pf1[j]);
	alias sum2 = (i, j) => (i > 0? pf2[j] - pf2[i - 1] : pf2[j]);
	foreach(i; 0 .. m)
	{
		score[i] = sum1(0, i) + sum2(i, m - 1);
	}
	auto mxp = score.cumulativeFold!max.array; mxp[] -= a[0][0];
	auto mxs = score.reverse.cumulativeFold!max.array.reverse.array; mxs[] -= a[1][m-1];
	long minAns = long.max;
	foreach(i; 0 .. m)
	{
		auto p1 = i > 0? mxp[i - 1] - sum2(i, m - 1) : 0;
		auto p2 = i + 1 < m? mxs[i + 1] - sum1(0, i) : 0;
		minAns = min(minAns, max(p1, p2));
	}
	minAns.writeln;
}

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

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

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

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

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

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

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

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

import std.algorithm;
import std.random;

struct SegmentTreeLazy(V, U, alias f, alias fou, alias uou, string fName = null, string uName = null)
{
	alias This = typeof(this);
	size_t length;
	size_t realLength = 0;
	V[] _nodeFValue;
	U[] _nodeUpdate;
	bool[] _nodeHasUpdate;
	size_t[] _nodeRangeEnd;
	size_t[] _nodeRangeStart;
	string toString()
	{
		import std.conv;
		string str;
		foreach(i; 0 .. realLength)
			if (_nodeHasUpdate[i])
			{
				str ~= text(_nodeFValue[i], "(", _nodeUpdate[i], "), ");
			}
			else
			{
				str ~= text(_nodeFValue[i], ", ");
			}
		return str;
	}
	this(size_t length, V initialValue)
	{
		this.length = length;
		size_t noNodes = 4 * length;
		_nodeFValue = new V[](noNodes);
		_nodeUpdate = new U[](noNodes);
		_nodeHasUpdate = new bool[](noNodes);
		_nodeRangeEnd = new size_t[](noNodes);
		_nodeRangeStart = new size_t[](noNodes);
		void fill(size_t i, size_t rangeStart, size_t rangeEnd)
		{
			realLength = max(realLength, i + 1);
			_nodeRangeStart[i] = rangeStart;
			_nodeRangeEnd[i] = rangeEnd;
			if (_isLeaf(i)) { _nodeFValue[i] = initialValue; return; }
			size_t l = i<<1;
			size_t r = l+1;
			size_t m = (rangeStart + rangeEnd) / 2;
			fill(l, rangeStart, m), fill(r, m + 1, rangeEnd);
			_nodeFValue[i] = f(_nodeFValue[l], _nodeFValue[r]);
		}
		fill(1, 0, length - 1);
	}
	V rangeF(size_t start, size_t end)
	{
		bool set = false;
		V result;
		void visit(size_t i) in(_hasFragments(i, start, end))
		{
			if (_isFragment(i, start, end))
			{
				if (!set) { result = _cookedF(i); set = true; }
				else { result = f(result, _cookedF(i)); }
				return;
			}
			_clearUpdate(i);
			size_t l = i<<1, r = (i<<1)+1;
			if (_hasFragments(l, start, end)) visit(l);
			if (_hasFragments(r, start, end)) visit(r);
		}
		visit(1);
		return result;
	}
	void rangeU(size_t start, size_t end, U u)
	{
		void visit(size_t i) in(_hasFragments(i, start, end))
		{
			if (_isFragment(i, start, end))
			{
				_addUpdate(i, u);
				return;
			}
			_clearUpdate(i);
			size_t l = i<<1, r = (i<<1)+1;
			if (_hasFragments(l, start, end)) visit(l);
			if (_hasFragments(r, start, end)) visit(r);
			_nodeFValue[i] = f(_cookedF(l), _cookedF(r));
		}
		visit(1);
	}
	V _cookedF(size_t i)
	{
		if (_nodeHasUpdate[i]) { return fou(_nodeFValue[i],
						    _nodeUpdate[i],
						    _nodeRangeStart[i],
						    _nodeRangeEnd[i]); }
		return _nodeFValue[i];
	}
	void _clearUpdate(size_t i)
	{
		if (!_nodeHasUpdate[i]) return;
		if (_isLeaf(i)) { _nodeFValue[i] = _cookedF(i); _nodeHasUpdate[i] = false; return;}
		size_t l = i<<1, r = (i<<1)+1;
		_addUpdate(l, _nodeUpdate[i]), _addUpdate(r, _nodeUpdate[i]);
		_nodeFValue[i] = f(_cookedF(l), _cookedF(r));
		_nodeHasUpdate[i] = false;
	}
	void _addUpdate(size_t i, U u)
	{
		if (!_nodeHasUpdate[i]) { _nodeHasUpdate[i] = true; _nodeUpdate[i] = u; return; }
		_nodeUpdate[i] = uou(_nodeUpdate[i], u);
	}
	bool _isLeaf(size_t i)
	{
		return _nodeRangeStart[i] == _nodeRangeEnd[i];
	}
	bool _isFragment(size_t i, size_t rangeStart, size_t rangeEnd)
	{
		return rangeStart <= _nodeRangeStart[i] && _nodeRangeEnd[i] <= rangeEnd;
	}
	bool _hasFragments(size_t i, size_t rangeStart, size_t rangeEnd)
	{
		return _nodeRangeStart[i] <= rangeEnd && rangeStart <= _nodeRangeEnd[i];
	}
	// prettifiers
	struct Handle
	{
		import std.ascii;
		size_t _start, _end;
		This* _parent;
		auto f()
		{
			return _parent.rangeF(_start, _end);
		}
		auto u(U v)
		{
			_parent.rangeU(_start, _end, v);
		}
		static if (fName !is null)
		{
			mixin(q{alias }, fName, q{ = f;});
		}
		static if (uName !is null)
		{
			static if (uName[0].isAlphaNum)
			{
				mixin(q{alias }, uName, q{ = u;});
			}
			else static if (uName[0] != ' ')
			{
				ref Handle opOpAssign(string operator)(U v)
				if (operator == uName)
				{
					u(v);
					return this;
				}
			}
			else
			{
				ref Handle opAssign(U v)
				{
					u(v);
					return this;
				}
			}
		}
	}
	size_t[2] opSlice(size_t i)(size_t s, size_t e) if (i == 0)
	{
		return [s, e-1];
	}
	auto opIndex(size_t[2] slice)
	{
		return Handle(slice[0], slice[1], &this);
	}
}

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

void main()
{
	int t = readInt!int;
	while (t--) solve;
}
void solve()
{
	int m = readInt!int;
	auto a = new long[][](2, m);
	auto score = SegmentTreeLazy!(long, long,
			(a, b) => max(a, b),
			(mx, u, rs, re) => u,
			(u1, u2) => u2,
			"max",
			" ")(m, 0);
	foreach(ref row; a) foreach(ref cell; row) cell = readInt!int;
	auto pf1 = a[0].cumulativeFold!((a, b) => a + b).array;
	auto pf2 = a[1].cumulativeFold!((a, b) => a + b).array;
	alias sum1 = (i, j) => (i > 0? pf1[j] - pf1[i - 1] : pf1[j]);
	alias sum2 = (i, j) => (i > 0? pf2[j] - pf2[i - 1] : pf2[j]);
	foreach(i; 0 .. m)
		score[i .. i + 1] = sum1(0, i) + sum2(i, m - 1);
	debug
	{
		foreach(i; 0 .. m) score[i .. i + 1].max.write(" ");
		writeln;
	}
	long minAns = long.max;
	foreach(i; 0 .. m)
	{
		auto p1 = i > 0? score[0 .. i].max - sum2(i, m - 1) - a[0][0] : 0;
		auto p2 = i + 1 < m? score[i + 1 .. m].max - sum1(0, i) - a[1][m-1] : 0;
		debug writeln("p1 = ", p1, " p2 = ", p2);
		minAns = min(minAns, max(p1, p2));
	}
	minAns.writeln;
}

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

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

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

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

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

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

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

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

import std.algorithm;
import std.random;

struct SegmentTreeLazy(V, U, alias f, alias fou, alias uou, string fName = null, string uName = null)
{
	alias This = typeof(this);
	size_t length;
	size_t realLength = 0;
	V[] _nodeFValue;
	U[] _nodeUpdate;
	bool[] _nodeHasUpdate;
	size_t[] _nodeRangeEnd;
	size_t[] _nodeRangeStart;
	string toString()
	{
		import std.conv;
		string str;
		foreach(i; 0 .. realLength)
			if (_nodeHasUpdate[i])
			{
				str ~= text(_nodeFValue[i], "(", _nodeUpdate[i], "), ");
			}
			else
			{
				str ~= text(_nodeFValue[i], ", ");
			}
		return str;
	}
	this(size_t length, V initialValue)
	{
		this.length = length;
		size_t noNodes = 4 * length;
		_nodeFValue = new V[](noNodes);
		_nodeUpdate = new U[](noNodes);
		_nodeHasUpdate = new bool[](noNodes);
		_nodeRangeEnd = new size_t[](noNodes);
		_nodeRangeStart = new size_t[](noNodes);
		void fill(size_t i, size_t rangeStart, size_t rangeEnd)
		{
			realLength = max(realLength, i + 1);
			_nodeRangeStart[i] = rangeStart;
			_nodeRangeEnd[i] = rangeEnd;
			if (_isLeaf(i)) { _nodeFValue[i] = initialValue; return; }
			size_t l = i<<1;
			size_t r = l+1;
			size_t m = (rangeStart + rangeEnd) / 2;
			fill(l, rangeStart, m), fill(r, m + 1, rangeEnd);
			_nodeFValue[i] = f(_nodeFValue[l], _nodeFValue[r]);
		}
		fill(1, 0, length - 1);
	}
	V rangeF(size_t start, size_t end)
	{
		bool set = false;
		V result;
		void visit(size_t i) in(_hasFragments(i, start, end))
		{
			if (_isFragment(i, start, end))
			{
				if (!set) { result = _cookedF(i); set = true; }
				else { result = f(result, _cookedF(i)); }
				return;
			}
			_clearUpdate(i);
			size_t l = i<<1, r = (i<<1)+1;
			if (_hasFragments(l, start, end)) visit(l);
			if (_hasFragments(r, start, end)) visit(r);
		}
		visit(1);
		return result;
	}
	void rangeU(size_t start, size_t end, U u)
	{
		void visit(size_t i) in(_hasFragments(i, start, end))
		{
			if (_isFragment(i, start, end))
			{
				_addUpdate(i, u);
				return;
			}
			_clearUpdate(i);
			size_t l = i<<1, r = (i<<1)+1;
			if (_hasFragments(l, start, end)) visit(l);
			if (_hasFragments(r, start, end)) visit(r);
			_nodeFValue[i] = f(_cookedF(l), _cookedF(r));
		}
		visit(1);
	}
	V _cookedF(size_t i)
	{
		if (_nodeHasUpdate[i]) { return fou(_nodeFValue[i],
						    _nodeUpdate[i],
						    _nodeRangeStart[i],
						    _nodeRangeEnd[i]); }
		return _nodeFValue[i];
	}
	void _clearUpdate(size_t i)
	{
		if (!_nodeHasUpdate[i]) return;
		if (_isLeaf(i)) { _nodeFValue[i] = _cookedF(i); _nodeHasUpdate[i] = false; return;}
		size_t l = i<<1, r = (i<<1)+1;
		_addUpdate(l, _nodeUpdate[i]), _addUpdate(r, _nodeUpdate[i]);
		_nodeFValue[i] = f(_cookedF(l), _cookedF(r));
		_nodeHasUpdate[i] = false;
	}
	void _addUpdate(size_t i, U u)
	{
		if (!_nodeHasUpdate[i]) { _nodeHasUpdate[i] = true; _nodeUpdate[i] = u; return; }
		_nodeUpdate[i] = uou(_nodeUpdate[i], u);
	}
	bool _isLeaf(size_t i)
	{
		return _nodeRangeStart[i] == _nodeRangeEnd[i];
	}
	bool _isFragment(size_t i, size_t rangeStart, size_t rangeEnd)
	{
		return rangeStart <= _nodeRangeStart[i] && _nodeRangeEnd[i] <= rangeEnd;
	}
	bool _hasFragments(size_t i, size_t rangeStart, size_t rangeEnd)
	{
		return _nodeRangeStart[i] <= rangeEnd && rangeStart <= _nodeRangeEnd[i];
	}
	// prettifiers
	struct Handle
	{
		import std.ascii;
		size_t _start, _end;
		This* _parent;
		auto f()
		{
			return _parent.rangeF(_start, _end);
		}
		auto u(U v)
		{
			_parent.rangeU(_start, _end, v);
		}
		static if (fName !is null)
		{
			mixin(q{alias }, fName, q{ = f;});
		}
		static if (uName !is null)
		{
			static if (uName[0].isAlphaNum)
			{
				mixin(q{alias }, uName, q{ = u;});
			}
			else static if (uName[0] != ' ')
			{
				ref Handle opOpAssign(string operator)(U v)
				if (operator == uName)
				{
					u(v);
					return this;
				}
			}
			else
			{
				ref Handle opAssign(U v)
				{
					u(v);
					return this;
				}
			}
		}
	}
	size_t[2] opSlice(size_t i)(size_t s, size_t e) if (i == 0)
	{
		return [s, e-1];
	}
	auto opIndex(size_t[2] slice)
	{
		return Handle(slice[0], slice[1], &this);
	}
}


import std.stdio, std.algorithm;
long solve(long[] a)
{
    int n = cast(int) a.length;
    a.sort();
    return a[n / 2] - a[(n - 1) / 2] + 1;
}
void main()
{
    int q;
    readf!"%d\n"(q);
    foreach (_; 0 .. q)
    {
        int n;
        readf!"%d\n"(n);
        long[] a = new long[n], b = new long[n];
        foreach (i; 0 .. n)
            readf!"%d %d\n"(a[i], b[i]);
        writeln(solve(a) * solve(b));
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto x = new long[](n);
		auto y = new long[](n);
		foreach (i; 0..n)
		{
			x[i] = RD;
			y[i] = RD;
		}
		x.sort;
		y.sort;

		long a, b;
		if (n % 2)
		{
			a = 1;
			b = 1;
		}
		else
		{
			a = x[n/2] - x[n/2-1] + 1;
			b = y[n/2] - y[n/2-1] + 1;
		}
		ans[ti] = a * b;
	}

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

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

void get(Args...)(ref Args args)
{
    import std.traits, std.meta, std.typecons;

    static if (Args.length == 1) {
        alias Arg = Args[0];

        static if (isArray!Arg) {
          static if (isSomeChar!(ElementType!Arg)) {
            args[0] = readln.chomp.to!Arg;
          } else {
            args[0] = readln.split.to!Arg;
          }
        } else static if (isTuple!Arg) {
            auto input = readln.split;
            static foreach (i; 0..Fields!Arg.length) {
                args[0][i] = input[i].to!(Fields!Arg[i]);
            }
        } else {
            args[0] = readln.chomp.to!Arg;
        }
    } else {
        auto input = readln.split;
        assert(input.length == Args.length);

        static foreach (i; 0..Args.length) {
            args[i] = input[i].to!(Args[i]);
        }
    }
}

void get_lines(Args...)(size_t N, ref Args args)
{
    import std.traits, std.range;

    static foreach (i; 0..Args.length) {
        static assert(isArray!(Args[i]));
        args[i].length = N;
    }

    foreach (i; 0..N) {
        static if (Args.length == 1) {
            get(args[0][i]);
        } else {
            auto input = readln.split;
            static foreach (j; 0..Args.length) {
                args[j][i] = input[j].to!(ElementType!(Args[j]));
            }
        }
    }
}

void main()
{
    int T; get(T); while (T--) {
        int N; get(N);
        long[] xs, ys; get_lines(N, xs, ys);
        if (N % 2 == 1) {
            writeln(1);
            continue;
        }
        sort(xs);
        auto x = xs[N / 2] - xs[N / 2 - 1] + 1;
        sort(ys);
        auto y = ys[N / 2] - ys[N / 2 - 1] + 1;
        writeln(x * y);
    }
}


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 = 61;

void main() {
  try {
    for (; ; ) {
      const Q = readInt();
      auto T = new int[Q];
      auto X = new long[Q];
      auto K = new long[Q];
      foreach (q; 0 .. Q) {
        T[q] = readInt();
        X[q] = readLong();
        if (T[q] == 1 || T[q] == 2) {
          K[q] = readLong();
        }
      }

      // e: [2^e, 2^(e+1))
      auto xs = new long[E];
      auto ys = new long[E];
      auto zs = new long[E];
      foreach (q; 0 .. Q) {
        int e = bsr(X[q]);
        switch (T[q]) {
          case 1: {
            (xs[e] += K[q]) &= ((1L << e) - 1);
          } break;
          case 2: {
            (ys[e] += K[q]) &= ((1L << e) - 1);
            long k = K[q] & ((1L << e) - 1);
            foreach (f; e .. E) {
              (zs[f] += k) &= ((1L << f) - 1);
              k <<= 1;
            }
          } break;
          case 3: {
            debug {
              writeln("query ", X[q]);
              writeln("  xs = ", xs);
              writeln("  ys = ", ys);
              writeln("  zs = ", zs);
            }
            long[] ans;
            long u = X[q];
            // u = (1L << e) + ((u - (1L << e) - zs[e]) & ((1L << e) - 1));
            u = (1L << e) + ((u - (1L << e) + xs[e]) & ((1L << e) - 1));
            for (; ; ) {
              const val = (1L << e) + ((u - (1L << e) - xs[e]) & ((1L << e) - 1));
              ans ~= val;
              if (e == 0) {
                break;
              }
              u = (1L << e) + ((u - (1L << e) + ys[e]) & ((1L << e) - 1));
              u >>= 1;
              --e;
            }
            foreach (idx, val; ans) {
              if (idx > 0) write(" ");
              write(val);
            }
            writeln();
          } break;
          default: assert(false);
        }
      }
    }
  } catch (EOFException e) {
  }
}

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

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void pickV(R,T...)(ref R r,ref T t){foreach(ref v;t)pick(r,v);}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int q; readV(q);

  auto v = new long[](64), n = new long[](64);

  foreach (_; 0..q) {
    auto rd = rdsp;
    int t; long x; pickV(rd, t, x);
    auto r = x.bsr, r2 = (1L<<r);
    switch (t) {
    case 1:
      long k; pick(rd, k);
      (v[r] += k%r2 + r2) %= r2;
      break;
    case 2:
      long k; pick(rd, k);
      (n[r] += k%r2 + r2) %= r2;
      break;
    case 3:
      auto s = new long[](r+1);
      foreach (i; 1..r+1) s[i] = (s[i-1]*2+n[i])%(1L<<i);

      auto ri = x.bitReset(r)+v[r]+s[r];
      foreach_reverse (i; 0..r+1) {
        auto si = (v[i]+s[i])%(1L<<i);
        auto y = (((1L<<i)-si+ri)%(1L<<i)).bitSet(i);
        write(y);
        if (i > 0) write(" ");
        ri >>= 1;
      }
      writeln;
      break;
    default:
      assert(0);
    }
  }
}

pragma(inline) {
  pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; }
  pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); }
  pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); }
  pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); }

  pure T bitSet(T)(T n, size_t s, size_t e) { return n | ((T(1) << e) - 1) & ~((T(1) << s) - 1); }
  pure T bitReset(T)(T n, size_t s, size_t e) { return n & (~((T(1) << e) - 1) | ((T(1) << s) - 1)); }
  pure T bitComp(T)(T n, size_t s, size_t e) { return n ^ ((T(1) << e) - 1) & ~((T(1) << s) - 1); }

  import core.bitop;
  pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); }
  pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); }
  pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); }
}

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 = 61;

void main() {
  try {
    for (; ; ) {
      const Q = readInt();
      auto T = new int[Q];
      auto X = new long[Q];
      auto K = new long[Q];
      foreach (q; 0 .. Q) {
        T[q] = readInt();
        X[q] = readLong();
        if (T[q] == 1 || T[q] == 2) {
          K[q] = readLong();
        }
      }

      // e: [2^e, 2^(e+1))
      auto xs = new long[E];
      auto ys = new long[E];
      foreach (q; 0 .. Q) {
        int e = bsr(X[q]);
        switch (T[q]) {
          case 1: {
            (xs[e] += K[q]) &= ((1L << e) - 1);
          } break;
          case 2: {
            (ys[e] += K[q]) &= ((1L << e) - 1);
          } break;
          case 3: {
            debug {
              writeln("query ", X[q]);
              writeln("  xs = ", xs);
              writeln("  ys = ", ys);
            }
            long[] ans;
            long u = X[q];
            for (; ; ) {
              const val = (1L << e) + ((u - (1L << e) - xs[e]) & ((1L << e) - 1));
              ans ~= val;
              if (e == 0) {
                break;
              }
              u = (1L << e) + ((u - (1L << e) + ys[e]) & ((1L << e) - 1));
              u >>= 1;
              --e;
            }
            foreach (idx, val; ans) {
              if (idx > 0) write(" ");
              write(val);
            }
            writeln();
          } break;
          default: assert(false);
        }
      }
    }
  } 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)); }

enum E = 61;

void main() {
  try {
    for (; ; ) {
      const Q = readInt();
      auto T = new int[Q];
      auto X = new long[Q];
      auto K = new long[Q];
      foreach (q; 0 .. Q) {
        T[q] = readInt();
        X[q] = readLong();
        if (T[q] == 1 || T[q] == 2) {
          K[q] = readLong();
        }
      }

      // e: [2^e, 2^(e+1))
      auto xs = new long[E];
      auto ys = new long[E];
      auto zs = new long[E];
      foreach (q; 0 .. Q) {
        int e = bsr(X[q]);
        switch (T[q]) {
          case 1: {
            (xs[e] += K[q]) &= ((1L << e) - 1);
          } break;
          case 2: {
            (ys[e] += K[q]) &= ((1L << e) - 1);
            long k = K[q] & ((1L << e) - 1);
            foreach (f; e .. E) {
              (zs[f] += k) &= ((1L << f) - 1);
              k <<= 1;
            }
          } break;
          case 3: {
            debug {
              writeln("query ", X[q]);
              writeln("  xs = ", xs);
              writeln("  ys = ", ys);
            }
            long[] ans;
            long u = X[q];
            u = (1L << e) + ((u - (1L << e) - zs[e]) & ((1L << e) - 1));
            for (; ; ) {
              const val = (1L << e) + ((u - (1L << e) - xs[e]) & ((1L << e) - 1));
              ans ~= val;
              if (e == 0) {
                break;
              }
              u = (1L << e) + ((u - (1L << e) + ys[e]) & ((1L << e) - 1));
              u >>= 1;
              --e;
            }
            foreach (idx, val; ans) {
              if (idx > 0) write(" ");
              write(val);
            }
            writeln();
          } break;
          default: assert(false);
        }
      }
    }
  } catch (EOFException e) {
  }
}


import std;

int t;

void main() {
    scanf("%d\n", &t);
    foreach(_;0..t) {
        bool flag = false;
        foreach(k; 0..8){
            string row_s = readln.strip;
            char[] row = row_s.dup;
            if ((uniq(row).array.length == 1) && (row[0] == 'R')) {
                flag = true;
            }
        }
        readln;
        if (flag)
            writeln("R");
        else
            writeln("B");
    }
}

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

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    readln;
    string[] grid;
    foreach (i ; 0 .. 8)
      grid ~= readln.strip;

    char ans = '?';

    foreach (i ; 0 .. 8) {
      char first = grid[i][0];
      bool match = (first == 'R');
      foreach (j ; 1 .. 8) {
        if (grid[i][j] != first) {
          match = false;
          break;
        }
      }
      if (match)
        ans = first;
    }

    foreach (i ; 0 .. 8) {
      char first = grid[0][i];
      bool match = (first == 'B');
      foreach (j ; 1 .. 8) {
        if (grid[j][i] != first) {
          match = false;
          break;
        }
      }
      if (match)
        ans = first;
    }

    writeln(ans);
  }
}

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() {
    readln;
    int N = 8;
    auto F = new string[N];
    foreach (i; 0 .. N) F[i] = readln.chomp;

    char f() {
        bool allY(int y) {
            return F[y].all!(c => c == 'R');
        }
        bool allX(int x) {
            return iota(N).all!(y => F[y][x] == 'B');
        }
        for (int y = 0; y < N; y++) {
            if (allY(y)) return 'R';
        }
        for (int x = 0; x < N; x++) {
            if (allX(x)) return 'B';
        }
        assert(false);
    }
    writeln(f());
}

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

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

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    readln;
    string[] grid;
    foreach (i ; 0 .. 8)
      grid ~= readln.strip;
    char ans = '?';
    foreach (i ; 0 .. 8) {
      char first = grid[i][0];
      bool match = (first != '.');
      foreach (j ; 1 .. 8) {
        if (grid[i][j] != first) {
          match = false;
          break;
        }
      }
      if (match)
        ans = first;
    }
    foreach (i ; 0 .. 8) {
      char first = grid[0][i];
      bool match = (first != '.');
      foreach (j ; 1 .. 8) {
        if (grid[j][i] != first) {
          match = false;
          break;
        }
      }
      if (match)
        ans = first;
    }
    writeln(ans);
  }
}

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() {
    readln;
    int N = 8;
    auto F = new string[N];
    foreach (i; 0 .. N) F[i] = readln.chomp;

    char f() {
        bool allY(int y) {
            return F[y].all!(c => c == 'R') || F[y].all!(c => c == 'B');
        }
        bool allX(int x) {
            return iota(N).all!(y => F[y][x] == 'R')
                || iota(N).all!(y => F[y][x] == 'B');
        }
        for (int y = 0; y < N; y++) {
            if (allY(y)) return F[y][0];
        }
        for (int x = 0; x < N; x++) {
            if (allX(x)) return F[0][x];
        }
        assert(false);
    }
    writeln(f());
}

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

import std;

int t;

void main() {
    scanf("%d\n", &t);
    outer: foreach(_;0..t) {
        foreach(k; 0..9){
            string row_s = readln.strip;
            char[] row = row_s.dup;
            if ((uniq(row).array.length == 1) && (row[0] == 'R')) {
                writeln("R");
                continue outer;
            }
        }
        writeln("B");
    }
}


void main() { runSolver(); }

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

  auto solve() {
    auto subSolve() {
      auto S = scan;
      int n = cast(int)S.length;

      auto a = new int[](n + 2);
      auto b = new int[](n + 2);
      auto c = new int[](n + 2);
      foreach(i; 1..n + 1) a[i] = (S[i - 1] - '0') ^ 1;
      foreach(i; 1..n + 1) b[i] = b[i - 1] + a[i];
      foreach(i; iota(n, 0, -1)) c[i] = c[i + 1] + a[i];

      long ans = b[n];
      foreach(i; 0.. b[n] + 1) ans = min(ans, b[n] - (b[i] + c[n - b[n] + i + 1]));
      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, core.stdc.stdlib, 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"];

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

struct SegTree(alias pred = "a + b", T = long) {
  alias predFun = binaryFun!pred;
  int size;
  T[] data;
  T monoid;

  this(T[] src, T monoid = T.init) {
    this.monoid = monoid;

    for(int i = 2; i < 2L^^32; i *= 2) {
      if (src.length <= i) {
        size = i;
        break;
      }
    }

    data = new T[](size * 2);
    foreach(i, s; src) data[i + size] = s;
    foreach_reverse(b; 1..size) {
      data[b] = predFun(data[b * 2], data[b * 2 + 1]);
    }
  }

  void update(int index, T value) {
    int i = index + size;
    data[i] = value;
    while(i > 0) {
      i /= 2;
      data[i] = predFun(data[i * 2], data[i * 2 + 1]);
    }
  }

  T get(int index) {
    return data[index + size];
  }

  T sum(int a, int b, int k = 1, int l = 0, int r = -1) {
    if (r < 0) r = size;

    if (r <= a || b <= l) return monoid;
    if (a <= l && r <= b) return data[k];

    T leftValue = sum(a, b, 2*k, l, (l + r) / 2);
    T rightValue = sum(a, b, 2*k + 1, (l + r) / 2, r);
    return predFun(leftValue, rightValue);
  }
}

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

auto go (T) (T c)
{
	int [] s = [0];
	foreach (ref x; c)
	{
		s ~= s.back + (x ? +1 : -1);
	}
	return s;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto a = readln.strip.map !(q{a - '0'}).array;
		auto n = a.length.to !(int);
		auto s0 = [0];
		foreach (ref c; a)
		{
			s0 ~= s0.back + !c;
		}
		auto s1 = [0];
		foreach (ref c; a)
		{
			s1 ~= s1.back + c;
		}

		bool go (int limit)
		{
			int j = 0;
			int cur0 = 0;
			foreach (i; 0..n)
			{
				j = max (j, i);
				while (j < n && s0[j + 1] - s0[i] <= limit)
				{
					j += 1;
				}
				if (s1[i] - s1[0] + s1[n] - s1[j] <= limit)
				{
					return true;
                                }
			}
			return false;
		}

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

void main() { runSolver(); }

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

  auto solve() {
    auto subSolve() {
      auto S = scan;
      int n = cast(int)S.length;

      auto pre = new int[](n + 1);
      auto suf = new int[](n + 1);
      foreach(i; 1..n + 1) {
        pre[i] = pre[i - 1] + (S[i - 1] == '0');
        suf[i] = suf[i - 1] + (S[n - i] == '0');
      }
      // pre.deb;
      // suf.deb;

      int a, ans;
      a = ans = pre[n];
      foreach(i; 0..a + 1) {
        ans = min(ans, a - pre[i] - suf[a - i]);
      }

      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, core.stdc.stdlib, 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"];

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

struct SegTree(alias pred = "a + b", T = long) {
  alias predFun = binaryFun!pred;
  int size;
  T[] data;
  T monoid;

  this(T[] src, T monoid = T.init) {
    this.monoid = monoid;

    for(int i = 2; i < 2L^^32; i *= 2) {
      if (src.length <= i) {
        size = i;
        break;
      }
    }

    data = new T[](size * 2);
    foreach(i, s; src) data[i + size] = s;
    foreach_reverse(b; 1..size) {
      data[b] = predFun(data[b * 2], data[b * 2 + 1]);
    }
  }

  void update(int index, T value) {
    int i = index + size;
    data[i] = value;
    while(i > 0) {
      i /= 2;
      data[i] = predFun(data[i * 2], data[i * 2 + 1]);
    }
  }

  T get(int index) {
    return data[index + size];
  }

  T sum(int a, int b, int k = 1, int l = 0, int r = -1) {
    if (r < 0) r = size;

    if (r <= a || b <= l) return monoid;
    if (a <= l && r <= b) return data[k];

    T leftValue = sum(a, b, 2*k, l, (l + r) / 2);
    T rightValue = sum(a, b, 2*k + 1, (l + r) / 2, r);
    return predFun(leftValue, rightValue);
  }
}


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

void main() {
  int n = readln.strip.to!int;
  auto v = readln.splitter.map!(to!long).array;
  v.reverse;
  long md = 5000;
  writeln(n+1);
  //make v[i] = -i mod md.
  foreach(i,x;v) {
    //x + i + delta = k*md
    long target = (x+i+md)/md*md;
    long d = target - (x+i+1);
    v[i..$] += d;
    writefln!"1 %d %d" (n-i, d);
    debug {writeln(v);}
  }
  v.reverse;
  v[] %= md;
  debug {writeln(v);}
  writefln!"2 %d %d" (n, md);
}

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

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

    auto ans = new long[](N);
    long a = 0;

    foreach_reverse (i; 0..N) {
        long m = (A[i] + a) % N;
        long b = ((i - m) % N + N) % N;
        ans[i] = b;
        a += b;
    }

    writeln(N+1);
    foreach (i; 0..N) {
        writeln(1, " ", N-i, " ", ans[N-i-1]);
    }
    writeln(2, " ", N, " ", N);
}

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

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

    auto ans = new long[](N);
    long a = 0;

    foreach_reverse (i; 0..N) {
        long m = (A[i] + a) % N;
        long b = ((i - m) % N + N) % N;
        ans[i] = b;
        a += b;
    }

    writeln(N+1);
    foreach (i; 0..N) {
        writeln(1, " ", N-i, " ", ans[N-i-1]);
    }
    writeln(2, " ", 1, " ", N);
}


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

immutable int dirs = 4;
immutable int [dirs] dRow = [-1,  0, +1,  0];
immutable int [dirs] dCol = [ 0, -1,  0, +1];

void main ()
{
	int rows, cols;
	while (readf (" %s %s", &rows, &cols) > 0)
	{
		readln;
		string [] a;
		foreach (row; 0..rows)
		{
			a ~= readln.strip;
		}
		int rowS, colS, rowF, colF;
		foreach (row; 0..rows)
		{
			foreach (col; 0..cols)
			{
				if (a[row][col] == 'S')
				{
					rowS = row;
					colS = col;
				}
				if (a[row][col] == 'E')
				{
					rowF = row;
					colF = col;
				}
			}
		}
		auto commands = readln.strip.map !(x => x - '0').array;

		int res = 0;
		auto p = dirs.iota.array;
		do
		{
			int row = rowS;
			int col = colS;
			foreach (dir; commands)
			{
				row += dRow[p[dir]];
				col += dCol[p[dir]];
				if (row < 0 || rows <= row ||
				    col < 0 || cols <= col)
				{
					break;
				}
				if (a[row][col] == '#')
				{
					break;
				}
				if (tuple (row, col) == tuple (rowF, colF))
				{
					break;
				}
			}
			res += (tuple (row, col) == tuple (rowF, colF));
		}
		while (nextPermutation (p));
		writeln (res);
	}
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const M = readInt();
      const N = readInt();
      auto A = new string[M];
      foreach (x; 0 .. M) {
        A[x] = readToken();
      }
      const S = readToken();

      int sx, sy;
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        if (A[x][y] == 'S') {
          sx = x;
          sy = y;
        }
      }

      int ans;
      auto perm = iota(4).array;
      do {
        bool ok;
        int x = sx, y = sy;
        foreach (s; S) {
          const dir = perm[s - '0'];
          const xx = x + [+1, 0, -1, 0][dir];
          const yy = y + [0, -1, 0, +1][dir];
          if (0 <= xx && xx < M && 0 <= yy && yy < N && A[xx][yy] != '#') {
            x = xx;
            y = yy;
            if (A[x][y] == 'E') {
              ok = true;
              break;
            }
          } else {
            break;
          }
        }
        if (ok) {
          ++ans;
        }
      } while (perm.nextPermutation);
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

/+ dub.sdl:
    name "B"
    dependency "dunkelheit" version=">=0.9.0"
+/

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

// import dkh.array, dkh.dungeon;

int main() {
    Scanner sc = new Scanner(stdin);
    scope(exit) sc.read!true;

    int h, w;
    sc.read(h, w);
    char[][] g = new char[][](h, w);
    foreach (r; 0..h) sc.read(g[r]);

    string _s;
    sc.read(_s);
    int[] s = _s.map!(c => c-'0').map!(to!int).array;

    int ans = 0;
    foreach (idx; iota(4).permutations) {
        int[2] sv = g.findFirst2D('S');
        int[2] tv = g.findFirst2D('E');
        auto dh = Dungeon(h, w);
        bool f = true;
        foreach (_d; s) {
            int d = idx[_d];
            sv = dh.move4(sv, d);
            if (!dh.isInside(sv)) {
                f = false;
                break;
            }
            if (g.at2D(sv) == '#') {
                f = false;
                break;
            }
            if (sv == tv) break;
        }
        if (!f) continue;
        if (sv != tv) continue;
        ans++;
    }
    writeln(ans);
    return 0;
}
/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/array.d */
// module dkh.array;

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

int[2] findFirst2D(T, U)(in T mp, in U c) {
    import std.conv : to;
    int R = mp.length.to!int;
    int C = mp[0].length.to!int;
    foreach (i; 0..R) {
        foreach (j; 0..C) {
            if (mp[i][j] == c) return [i, j];
        }
    }
    assert(false);
}

auto ref at2D(T, U)(ref T mp, in U idx) {
    return mp[idx[0]][idx[1]];
}

/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;

struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
    import core.exception : RangeError;

    private T* _data;
    private uint len, cap;

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

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

    ref inout(T) opIndex(size_t i) inout {
        version(assert) if (len <= i) throw new RangeError();
        return _data[i];
    }
    ref inout(T) front() inout { return this[0]; }
    ref inout(T) back() inout { return this[$-1]; }

    void reserve(size_t newCap) {
        import core.memory : GC;
        import core.stdc.string : memcpy;
        import std.conv : to;
        if (newCap <= cap) return;
        void* newData = GC.malloc(newCap * T.sizeof);
        cap = newCap.to!uint;
        if (len) memcpy(newData, _data, len * T.sizeof);
        _data = cast(T*)(newData);
    }
    void free() {
        import core.memory : GC;
        GC.free(_data);
    }

    void clear() {
        len = 0;
    }

    void insertBack(T item) {
        import std.algorithm : max;
        if (len == cap) reserve(max(cap * 2, MINCAP));
        _data[len++] = item;
    }
    alias opOpAssign(string op : "~") = insertBack;
    void removeBack() {
        assert(!empty, "StackPayload.removeBack: Stack is empty");
        len--;
    }
}

/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/foundation.d */

// module dkh.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);
            }
        }
    }

}
/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/dungeon.d */
// module dkh.dungeon;

immutable static int[2][4] direction4 = [
    [1, 0], [0, 1], [-1, 0], [0, -1],
];

immutable static int[2][8] direction8 = [
    [1, 0],
    [1, 1],
    [0, 1],
    [-1, 1],
    [-1, 0],
    [-1, -1],
    [0, -1],
    [1, -1],
];

static int[2] addInt2(in int[2] a, in int[2] b) {
    int[2] c;
    c[] = a[] + b[];
    return c;
}

struct Dungeon {

    static int[2] move4(int[2] p, int dir) {
        return addInt2(p, direction4[dir]);
    }

    static int[2] move8(int[2] p, int dir) {
        return addInt2(p, direction8[dir]);
    }

    immutable int R, C;

    this(int R, int C) {
        this.R = R;
        this.C = C;
    }

    bool isInside(int[2] p) const {
        int r = p[0], c = p[1];
        return 0 <= r && r < R && 0 <= c && c < C;
    }

    int getID(int[2] p) const {
        int r = p[0], c = p[1];
        return r*R+c;
    }
}

auto neighbors4(int[2] p) {
    static struct Rng {
        int[2] center;
        size_t i;
        bool empty() const { return i == 4;}
        int[2] front() const { return addInt2(center, direction4[i]); }
        void popFront() { i++; }
    }
    return Rng(p, 0);
}

auto neighbors4(int[2] p, in Dungeon dg) {
    static struct Rng {
        int[2] center;
        Dungeon dg;
        size_t i;
        this(in int[2] center, in Dungeon dg) {
            this.center = center;
            this.dg = dg;
            while (!empty() && !dg.isInside(front)) i++;
        }
        bool empty() const { return i == 4;}
        int[2] front() const { return addInt2(center, direction4[i]); }
        void popFront() {
            i++;
            while (!empty() && !dg.isInside(front)) i++;
        }
    }
    return Rng(p, dg);
}

/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;

// import dkh.container.stackpayload;

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 {
                StackPayload!E buf;
                while (succW()) {
                    buf ~= line.parse!E;
                }
                x = buf.data;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }

    int unsafeRead(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);
        }
    }
    void read(bool enforceEOF = false, T, Args...)(ref T x, auto ref Args args) {
        import std.exception;
        enforce(readSingle(x));
        static if (args.length == 0) {
            enforce(enforceEOF == false || !succ());
        } else {
            read!enforceEOF(args);
        }
    }
    void read(bool enforceEOF = false, Args...)(auto ref Args args) {
        import std.exception;
        static if (args.length == 0) {
            enforce(enforceEOF == false || !succ());
        } else {
            enforce(readSingle(args[0]));
            read!enforceEOF(args);
        }
    }
}

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

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

  int h, w; rd(h, w);
  auto c=new char[][](h);
  foreach(i; 0..h) c[i]=readln.chomp.to!(char[]);
  auto t=readln.chomp.to!(char[]);

  import std.typecons;
  alias P=Tuple!(int, "i", int, "j");
  P st, gl;
  foreach(i; 0..h)foreach(j; 0..w){
    if(c[i][j]=='S') st=P(i, j);
    if(c[i][j]=='E') gl=P(i, j);
  }
  auto dir=[[-1, 0], [0, 1], [1, 0], [0, -1]]; // LURD
  auto nums=[0, 1, 2, 3];
  int tot=0;
  do{
    auto cur=st;
    foreach(char ch; t){
      int x=ch-'0';
      auto d=dir[nums[x]];
      auto nex=P(cur.i+d[0], cur.j+d[1]);
      if(nex.i<0 || nex.i>=h || nex.j<0 || nex.j>=w) break;
      if(c[nex.i][nex.j]=='#') break;
      if(c[nex.i][nex.j]=='E'){tot++; break;}
      cur=nex;
    }
  }while(nextPermutation(nums));

  writeln(tot);
}

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

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

immutable int dirs = 4;
immutable int [dirs] dRow = [-1,  0, +1,  0];
immutable int [dirs] dCol = [ 0, -1,  0, +1];

void main ()
{
	int rows, cols;
	while (readf (" %s %s", &rows, &cols) > 0)
	{
		readln;
		string [] a;
		foreach (row; 0..rows)
		{
			a ~= readln.strip;
		}
		int rowS, colS, rowF, colF;
		foreach (row; 0..rows)
		{
			foreach (col; 0..cols)
			{
				if (a[row][col] == 'S')
				{
					rowS = row;
					colS = col;
				}
				if (a[row][col] == 'E')
				{
					rowF = row;
					colF = col;
				}
			}
		}
		auto commands = readln.strip.map !(x => x - '0').array;

		int res = 0;
		auto p = dirs.iota.array;
		do
		{
			int row = rowS;
			int col = colS;
			foreach (dir; commands)
			{
				row += dRow[p[dir]];
				col += dCol[p[dir]];
				if (row < 0 || rows <= row ||
				    col < 0 || cols <= col)
				{
					break;
				}
				if (tuple (row, col) == tuple (rowF, colF))
				{
					break;
				}
			}
			res += (tuple (row, col) == tuple (rowF, colF));
		}
		while (nextPermutation (p));
		writeln (res);
	}
}


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

void main ()
{
	int n;
	while (readf (" %s ", &n) > 0)
	{
		char [] [] s;
		foreach (i; 0..n)
		{
			s ~= readln.strip.dup;
		}

		bool isValid (int row, int col)
		{
			return 0 <= row && row < n &&
			    0 <= col && col < n;
		}

		auto t = '.'.repeat (n * 2 - 1).array
		    .repeat (n * 2 - 1).map!dup.array;

		foreach (drow; -(n - 1)..n)
		{
			foreach (dcol; -(n - 1)..n)
			{
				bool canHit = true;
				foreach (row; 0..n)
				{
					foreach (col; 0..n)
					{
						if (s[row][col] == 'o')
						{
							if (isValid (row +
							    drow, col + dcol)
							    && s[row + drow]
							    [col + dcol] ==
							    '.')
							{
								canHit = false;
							}
						}
					}
				}
				if (canHit)
				{
					t[drow + (n - 1)][dcol + (n - 1)] =
					    'x';
				}
			}
		}
		t[n - 1][n - 1] = 'o';
		debug {writefln ("%-(%s\n%)", t);}

		foreach (drow; -(n - 1)..n)
		{
			foreach (dcol; -(n - 1)..n)
			{
				if (t[drow + (n - 1)][dcol + (n - 1)] == 'x')
				{
					foreach (row; 0..n)
					{
						foreach (col; 0..n)
						{
							if (s[row][col] == 'o'
							    && isValid (row +
							    drow, col + dcol)
							    && s[row + drow]
							    [col + dcol] ==
							    'x')
							{
								s[row + drow]
								    [col +
								    dcol] =
								    '.';
							}
						}
					}
				}
			}
		}
		debug {writefln ("%-(%s\n%)", s);}

		bool ok = true;
		foreach (row; 0..n)
		{
			foreach (col; 0..n)
			{
				ok &= (s[row][col] != 'x');
			}
		}

		if (ok)
		{
			writeln ("YES");
			writefln ("%-(%s\n%)", t);
		}
		else
		{
			writeln ("NO");
		}
	}
}

import std.math;
import std.conv;
import std.array;
import std.stdio;
import std.range;
import std.format;
import std.string;
import std.c.stdio : scanf;
import std.algorithm;

struct S {
	int x, y;
}

void main() {
	auto n = readln.strip.to!int, k = 2 * n - 1;
	S[] ps;
	char[][] arr, r;

	r = uninitializedArray!(typeof(r))(k, k);
	foreach(p; r) p[] = '.';
	r[n - 1][n - 1] = 'o';

	foreach(y; 0..n) {
		arr ~= readln.strip.dup;
		foreach(x, c; arr.back) if(c == 'o') ps ~= S(cast(int)x, cast(int)y);
	}

	foreach(y, a; arr)
	foreach(x, ref c; a)
		if(c == 'x') {
			foreach(s; ps) {
				auto dx = x - s.x, dy = y - s.y;
				bool b;

				foreach(u; ps) {
					auto w = u.x + dx, e = u.y + dy;
					if(w >= 0 && w < n && e >= 0 && e < n && arr[e][w] == '.') b = true;
				}

				if(!b) {
					c = 0;

					foreach(u; ps) {
						auto w = u.x + dx, e = u.y + dy;
						if(w >= 0 && w < n && e >= 0 && e < n) arr[e][w] = 0;
					}

					r[n + dy - 1][n + dx - 1] = 'x';
				}
			}
		}

	if(arr.any!(a => a.canFind('x')))
		write(`NO`);
	else
		writef("YES\n%-(%s\n%)", r);
}

import std.math;
import std.conv;
import std.array;
import std.stdio;
import std.range;
import std.format;
import std.string;
import std.c.stdio : scanf;
import std.algorithm;

struct S {
	int x, y;
}

void main() {
	auto n = readln.strip.to!int, k = 2 * n - 1;
	S[] ps;
	char[][] arr;

	foreach(y; 0..n) {
		arr ~= readln.strip.dup;
		foreach(x, c; arr.back) if(c == 'o') ps ~= S(cast(int)x, cast(int)y);
	}

	auto r = uninitializedArray!(char[][])(k, k);
	foreach(p; r) p[] = '.';
	r[n - 1][n - 1] = 'o';

	foreach(y, a; arr)
	loop: foreach(x, ref c; a)
		if(c == 'x') {
			foreach(s; ps) {
				auto dx = x - s.x, dy = y - s.y;
				bool b;

				foreach(u; ps) {
					auto w = u.x + dx, e = u.y + dy;
					if(w >= 0 && w < n && e >= 0 && e < n && arr[w][e] == '.') b = true;
				}

				if(!b) {
					c = 0;
					r[n + dx - 1][n + dy - 1] = 'x';
					continue loop;
				}
			}
		}

	if(arr.any!(a => a.canFind('x')))
		write(`NO`);
	else
		writef("YES\n%-(%s\n%)", r);
}

import std.math;
import std.conv;
import std.array;
import std.stdio;
import std.range;
import std.format;
import std.string;
import std.c.stdio : scanf;
import std.algorithm;

struct S {
	int x, y;
}

void main() {
	auto n = readln.strip.to!int, k = 2 * n - 1;
	S[] ps;
	string[] arr;

	foreach(y; 0..n) {
		arr ~= readln.strip;
		foreach(x, c; arr.back) if(c == 'o') ps ~= S(cast(int)x, cast(int)y);
	}

	auto r = uninitializedArray!(char[][])(k, k);
	foreach(p; r) p[] = '.';
	r[n - 1][n - 1] = 'o';

	foreach(y, a; arr)
	foreach(x, c; a)
		if(c == 'x') {
			foreach(s; ps) {
				auto dx = x - s.x, dy = y - s.y;

				foreach(u; ps) {
					auto w = u.x + dx, e = u.y + dy;
					if(w >= 0 && w < n && e >= 0 && e < n && arr[w][e] == '.') return write(`NO`);
				}

				r[n + dx - 1][n + dy - 1] = 'x';
			}
		}

	writef("YES\n%-(%s\n%)", r);
}

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

void main ()
{
	int n;
	while (readf (" %s ", &n) > 0)
	{
		char [] [] s;
		foreach (i; 0..n)
		{
			s ~= readln.strip.dup;
		}

		bool isValid (int row, int col)
		{
			return 0 <= row && row < n &&
			    0 <= col && col < n;
		}

		auto t = '.'.repeat (n * 2 - 1).array
		    .repeat (n * 2 - 1).map!dup.array;

		foreach (drow; -(n - 1)..n)
		{
			foreach (dcol; -(n - 1)..n)
			{
				bool canHit = true;
				foreach (row; 0..n)
				{
					foreach (col; 0..n)
					{
						if (s[row][col] == 'o')
						{
							if (isValid (row -
							    drow, col - dcol)
							    && s[row - drow]
							    [col - dcol] ==
							    '.')
							{
								canHit = false;
							}
						}
					}
				}
				if (canHit)
				{
					t[drow + (n - 1)][dcol + (n - 1)] =
					    'x';
				}
			}
		}
		t[n - 1][n - 1] = 'o';
		debug {writefln ("%-(%s\n%)", t);}

		foreach (drow; -(n - 1)..n)
		{
			foreach (dcol; -(n - 1)..n)
			{
				if (t[drow + (n - 1)][dcol + (n - 1)] == 'x')
				{
					foreach (row; 0..n)
					{
						foreach (col; 0..n)
						{
							if (s[row][col] == 'o'
							    && isValid (row -
							    drow, col - dcol)
							    && s[row - drow]
							    [col - dcol] ==
							    'x')
							{
								s[row - drow]
								    [col -
								    dcol] =
								    '.';
							}
						}
					}
				}
			}
		}
		debug {writefln ("%-(%s\n%)", s);}

		bool ok = true;
		foreach (row; 0..n)
		{
			foreach (col; 0..n)
			{
				ok &= (s[row][col] != 'x');
			}
		}

		if (ok)
		{
			writeln ("YES");
			writefln ("%-(%s\n%)", t);
		}
		else
		{
			writeln ("NO");
		}
	}
}

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

void main ()
{
	int n;
	while (readf (" %s ", &n) > 0)
	{
		char [] [] s;
		foreach (i; 0..n)
		{
			s ~= readln.strip.dup;
		}

		bool isValid (int row, int col)
		{
			return 0 <= row && row < n &&
			    0 <= col && col < n;
		}

		auto t = '.'.repeat (n * 2 - 1).array
		    .repeat (n * 2 - 1).map!dup.array;

		foreach (drow; -(n - 1)..n)
		{
			foreach (dcol; -(n - 1)..n)
			{
				bool canHit = true;
				foreach (row; 0..n)
				{
					foreach (col; 0..n)
					{
						if (s[row][col] == 'o')
						{
							if (isValid (row -
							    drow, col - dcol)
							    && s[row - drow]
							    [col - dcol] ==
							    '.')
							{
								canHit = false;
							}
						}
					}
				}
				if (canHit)
				{
					t[drow + (n - 1)][dcol + (n - 1)] =
					    'x';
				}
			}
		}
		t[n - 1][n - 1] = 'o';
		debug {writefln ("%-(%s\n%)", t);}

		bool ok = true;
		foreach (drow; -(n - 1)..n)
		{
			foreach (dcol; -(n - 1)..n)
			{
				if (t[drow + (n - 1)][dcol + (n - 1)] == 'x')
				{
					foreach (row; 0..n)
					{
						foreach (col; 0..n)
						{
							if (s[row][col] == 'o'
							    && isValid (row -
							    drow, col - dcol)
							    && s[row - drow]
							    [col - dcol] ==
							    '.')
							{
								ok = false;
							}
						}
					}
				}
			}
		}

		foreach (drow; -(n - 1)..n)
		{
			foreach (dcol; -(n - 1)..n)
			{
				if (t[drow + (n - 1)][dcol + (n - 1)] == 'x')
				{
					foreach (row; 0..n)
					{
						foreach (col; 0..n)
						{
							if (s[row][col] == 'o'
							    && isValid (row -
							    drow, col - dcol)
							    && s[row - drow]
							    [col - dcol] ==
							    'x')
							{
								s[row - drow]
								    [col -
								    dcol] =
								    '.';
							}
						}
					}
				}
			}
		}
		debug {writefln ("%-(%s\n%)", s);}

		foreach (row; 0..n)
		{
			foreach (col; 0..n)
			{
				ok &= (s[row][col] != 'x');
			}
		}

		if (ok)
		{
			writeln ("YES");
			writefln ("%-(%s\n%)", t);
		}
		else
		{
			writeln ("NO");
		}
	}
}

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

void main ()
{
	int n;
	while (readf (" %s ", &n) > 0)
	{
		char [] [] s;
		foreach (i; 0..n)
		{
			s ~= readln.strip.dup;
		}

		bool isValid (int row, int col)
		{
			return 0 <= row && row < n &&
			    0 <= col && col < n;
		}

		auto t = '.'.repeat (n * 2 - 1).array
		    .repeat (n * 2 - 1).map!dup.array;

		foreach (drow; -(n - 1)..n)
		{
			foreach (dcol; -(n - 1)..n)
			{
				bool canHit = true;
				foreach (row; 0..n)
				{
					foreach (col; 0..n)
					{
						if (s[row][col] == 'o')
						{
							if (isValid (row -
							    drow, col - dcol)
							    && s[row - drow]
							    [col - dcol] ==
							    '.')
							{
								canHit = false;
							}
						}
					}
				}
				if (canHit)
				{
					t[drow + (n - 1)][dcol + (n - 1)] =
					    'x';
				}
			}
		}
		t[n - 1][n - 1] = 'o';

		foreach (drow; -(n - 1)..n)
		{
			foreach (dcol; -(n - 1)..n)
			{
				if (t[drow + (n - 1)][dcol + (n - 1)] == 'x')
				{
					foreach (row; 0..n)
					{
						foreach (col; 0..n)
						{
							if (isValid (row -
							    drow, col - dcol)
							    && s[row - drow]
							    [col - dcol] ==
							    'x')
							{
								s[row - drow]
								    [col -
								    dcol] =
								    '.';
							}
						}
					}
				}
			}
		}

		bool ok = true;
		foreach (row; 0..n)
		{
			foreach (col; 0..n)
			{
				ok &= (s[row][col] != 'x');
			}
		}

		if (ok)
		{
			writeln ("YES");
			writefln ("%-(%s\n%)", t);
		}
		else
		{
			writeln ("NO");
		}
	}
}