This is an interactive problemYou are given a grid $$$n\times n$$$, where $$$n$$$ is odd. Rows are enumerated from $$$1$$$ to $$$n$$$ from up to down, columns are enumerated from $$$1$$$ to $$$n$$$ from left to right. Cell, standing on the intersection of row $$$x$$$ and column $$$y$$$, is denoted by $$$(x, y)$$$.Every cell contains $$$0$$$ or $$$1$$$. It is known that the top-left cell contains $$$1$$$, and the bottom-right cell contains $$$0$$$.We want to know numbers in all cells of the grid. To do so we can ask the following questions: "$$$?$$$ $$$x_1$$$ $$$y_1$$$ $$$x_2$$$ $$$y_2$$$", where $$$1 \le x_1 \le x_2 \le n$$$, $$$1 \le y_1 \le y_2 \le n$$$, and $$$x_1 + y_1 + 2 \le x_2 + y_2$$$. In other words, we output two different cells $$$(x_1, y_1)$$$, $$$(x_2, y_2)$$$ of the grid such that we can get from the first to the second by moving only to the right and down, and they aren't adjacent.As a response to such question you will be told if there exists a path between $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$, going only to the right or down, numbers in cells of which form a palindrome.For example, paths, shown in green, are palindromic, so answer for "$$$?$$$ $$$1$$$ $$$1$$$ $$$2$$$ $$$3$$$" and "$$$?$$$ $$$1$$$ $$$2$$$ $$$3$$$ $$$3$$$" would be that there exists such path. However, there is no palindromic path between $$$(1, 1)$$$ and $$$(3, 1)$$$.  Determine all cells of the grid by asking not more than $$$n^2$$$ questions. It can be shown that the answer always exists.

The first line contains odd integer ($$$3 \le n < 50$$$) — the side of the grid.

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = read.to!int;

	int[][] xf = new int[][](n, n);

	xf[0][0] = 1;
	xf[n - 1][n - 1] = 0;

	bool ask(int ai, int aj, int bi, int bj){
		int[] q;
		if(ai < bi || ai == bi && aj < bj) q = [ai + 1, aj + 1, bi + 1, bj + 1];
		else q = [bi + 1, bj + 1, ai + 1, aj + 1];
		("? " ~ q.map!(to!string).array.join(" ")).writeln;
		stdout.flush;
		return (readln.chomp == "1");
	}

	void set(int i, int j, int bi, int bj){
		bool b = ask(bi, bj, i, j);
		if(b) xf[i][j] = xf[bi][bj];
		else xf[i][j] = 1 - xf[bi][bj];
	}

	foreach(i; 0 .. n){
		foreach(j; 0 .. n){
			if(i == 0 && j == 1) xf[i][j] = 3; // 3 or -2
			if(i == 1 && j == 1) set(i, j, 0, 0);
			if(i == 1 && j == 2){
				set(i, j, 0, 1);
				set(1, 0, 1, 2);
			}
			else if(i >= 2) set(i, j, i - 2, j);
			else if(j >= 2) set(i, j, i, j - 2);
		}
	}

	void equalize(int ai, int aj, int bi, int bj){
		bool b = ask(ai, aj, bi, bj);
		int x = xf[ai][aj], y = xf[bi][bj];
		int[int] m;
		m[0] = 0, m[1] = 1;
		if(x == 0 || x == 1){
			if(b) m[y] = x, m[1 - y] = 1 - x;
			else m[y] = 1 - x, m[1 - y] = x;
		}
		else{
			if(b) m[x] = y, m[1 - x] = 1 - y;
			else m[x] = 1 - y, m[1 - x] = y;
		}
		foreach(i; 0 .. n) foreach(j; 0 .. n){
			xf[i][j] = m[xf[i][j]];
		}
	}

	foreach(i; 0 .. n){
		foreach(j; 0 .. n){
			if(i > 0 && j < n - 1){
				if(xf[i][j] != xf[i - 1][j + 1]){
					if(i >= 2) equalize(i - 2, j, i, j + 1);
					else equalize(i - 1, j, i + 1, j + 1);
					goto A;
				}
			}
		}
	}

	foreach(i; 0 .. n - 2){
		if(xf[i][i] == xf[i + 1][i + 1] && xf[i][i + 1] == xf[i + 1][i + 2]
				|| xf[i][i] != xf[i + 1][i + 1] && xf[i][i + 1] != xf[i + 1][i + 2]){
			equalize(i, i, i + 1, i + 2);
			goto A;
		}
		if(xf[i][i + 1] == xf[i + 1][i + 2] && xf[i + 1][i + 1] == xf[i + 2][i + 2]
				|| xf[i][i + 1] != xf[i + 1][i + 2] && xf[i + 1][i + 1] != xf[i + 2][i + 2]){
			equalize(i, i + 1, i + 2, i + 2);
			goto A;
		}
	}

	A:
	"!".writeln;
	foreach(i; 0 .. n){
		xf[i].map!(x => x.to!string).array.join("").writeln;
	}

}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = read.to!int;

	int[][] xf = new int[][](n, n);

	xf[0][0] = 1;
	xf[n - 1][n - 1] = 0;

	bool ask(int ai, int aj, int bi, int bj){
		("? " ~ [ai + 1, aj + 1, bi + 1, bj + 1].map!(to!string).array.join(" ")).writeln;
		stdout.flush;
		return (readln.chomp == "1");
	}

	void set(int i, int j, int bi, int bj){
		bool b = ask(bi, bj, i, j);
		if(b) xf[i][j] = xf[bi][bj];
		else xf[i][j] = 1 - xf[bi][bj];
	}

	foreach(i; 0 .. n){
		foreach(j; 0 .. n){
			if(i == 0 && j == 1) xf[i][j] = 3; // 3 or -2
			if(i == 1 && j == 0) set(i, j, 0, 1);
			if(i == 1 && j == 1) set(i, j, 0, 0);
			if(i >= 2) set(i, j, i - 2, j);
			else if(j >= 2) set(i, j, i, j - 2);
		}
	}

	void equalize(int ai, int aj, int bi, int bj){
		bool b = ask(ai, aj, bi, bj);
		int x = xf[ai][aj], y = xf[bi][bj];
		int[int] m;
		m[0] = 0, m[1] = 1;
		if(x == 0 || x == 1){
			if(b) m[y] = x, m[1 - y] = 1 - x;
			else m[y] = 1 - x, m[1 - y] = x;
		}
		else{
			if(b) m[x] = y, m[1 - x] = 1 - y;
			else m[x] = 1 - y, m[1 - x] = y;
		}
		foreach(i; 0 .. n) foreach(j; 0 .. n){
			xf[i][j] = m[xf[i][j]];
		}
	}

	foreach(i; 0 .. n){
		foreach(j; 0 .. n){
			if(i > 0 && j < n - 1){
				if(xf[i][j] != xf[i - 1][j + 1]){
					if(i >= 2) equalize(i - 2, j, i, j + 1);
					else equalize(i - 1, j, i + 1, j + 1);
					goto A;
				}
			}
		}
	}

	foreach(i; 0 .. n - 2){
		if(xf[i][i] == xf[i + 1][i + 1] && xf[i][i + 1] == xf[i + 1][i + 2]
				|| xf[i][i] != xf[i + 1][i + 1] && xf[i][i + 1] != xf[i + 1][i + 2]){
			equalize(i, i, i + 1, i + 2);
			goto A;
		}
		if(xf[i][i + 1] == xf[i + 1][i + 2] && xf[i + 1][i + 1] == xf[i + 2][i + 2]
				|| xf[i][i + 1] != xf[i + 1][i + 2] && xf[i + 1][i + 1] != xf[i + 2][i + 2]){
			equalize(i, i + 1, i + 2, i + 2);
			goto A;
		}
	}

	A:
	"!".writeln;
	foreach(i; 0 .. n){
		xf[i].map!(x => x.to!string).array.join("").writeln;
	}

}


You have $$$r$$$ red and $$$b$$$ blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet:   has at least one red bean (or the number of red beans $$$r_i \ge 1$$$);  has at least one blue bean (or the number of blue beans $$$b_i \ge 1$$$);  the number of red and blue beans should differ in no more than $$$d$$$ (or $$$|r_i - b_i| \le d$$$) Can you distribute all beans?

The first line contains the single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first and only line of each test case contains three integers $$$r$$$, $$$b$$$, and $$$d$$$ ($$$1 \le r, b \le 10^9$$$; $$$0 \le d \le 10^9$$$) — the number of red and blue beans and the maximum absolute difference in each packet.

For each test case, if you can distribute all beans, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

NoteIn the first test case, you can form one packet with $$$1$$$ red and $$$1$$$ blue bean. The absolute difference $$$|1 - 1| = 0 \le d$$$.In the second test case, you can form two packets: $$$1$$$ red and $$$4$$$ blue beans in the first packet and $$$1$$$ red and $$$3$$$ blue beans in the second one.In the third test case, since $$$b = 1$$$, you can form only one packet with $$$6$$$ red and $$$1$$$ blue beans. The absolute difference $$$|6 - 1| = 5 > d$$$.In the fourth test case, since $$$d = 0$$$ so each packet should contain the same number of red and blue beans, but $$$r \neq b$$$.

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

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

        if(params[0] == 0 || params[1] == 0)
        {
            writeln("NO");
        }
        else
        {
            long min = params[0] > params[1] ? params[1] : params[0];
            long max = params[0] > params[1] ? params[0] : params[1];
            long res = (max / min) + (max % min != 0 ? 1 : 0) - 1;
            writeln(res <= d ? "YES" : "NO");
        }
    }
}

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

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

        if(abs(params[0] - params[1]) <= d)
        {
            writeln("YES");
        }
        else
        {
            long min = params[0] > params[1] ? params[1] : params[0];
            long max = params[0] > params[1] ? params[0] : params[1];
            long res = (max / min) + (max % min != 0 ? 1 : 0) - 1;
            writeln(res <= d ? "YES" : "NO");
        }
    }
}

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

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

while(t--) {
    long r, b, d;
    readf("%s %s %s\n", &r, &b, &d);
    if(r > b)
        swap(r,b);
    if(b <= r*(d + 1))
        "YES".writeln;
    else
        "NO".writeln;
}
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto r = RD;
		auto b = RD;
		auto d = RD;

		auto x = min(b, r);
		auto y = max(b, r);
		ans[ti] = y-x <= d * x;
	}

	foreach (e; ans)
		writeln(e ? "YES" : "NO");
	stdout.flush;
	debug readln;
}

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

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

        if(params[0] == 0 || params[1] == 0)
        {
            writeln("NO");
        }
        else if(abs(params[0] - params[1]) <= d)
        {
            writeln("YES");
        }
        else
        {
            long min = params[0] > params[1] ? params[1] : params[0];
            long max = params[0] > params[1] ? params[0] : params[1];
            long res = (max / min) + (max % min) - 1;
            writeln(res <= d ? "YES" : "NO");
        }
    }
}

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

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

        if(params[0] <= 0 || params[1] <= 0)
        {
            writeln("NO");
        }
        else
        {
            long min = params[0] > params[1] ? params[1] : params[0];
            long max = params[0] > params[1] ? params[0] : params[1];
            long res = (max / min) + (max % min) - 1;
            writeln(res <= d ? "YES" : "NO");
        }
    }
}

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

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

        if(params[0] <= 0 || params[1] <= 0)
        {
            writeln("NO");
        }
        else
        {
            long min = params[0] > params[1] ? params[1] : params[0];
            long max = params[0] > params[1] ? params[0] : params[1];
            long res = (max / min) - 1;
            writeln(max % min <= d && res <= d ? "YES" : "NO");
        }
    }
}

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

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

        if(params[0] <= 0 || params[1] <= 0)
        {
            writeln("NO");
        }
        else
        {
            long min = params[0] > params[1] ? params[1] : params[0];
            long max = params[0] > params[1] ? params[0] : params[1];
            long res = (max / min) - min;
            writeln(res >= 0 && res <= d ? "YES" : "NO");
        }
    }
}

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

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

        if(params[0] <= 0 || params[1] <= 0)
        {
            writeln("NO");
        }
        else
        {
            long min = params[0] > params[1] ? params[1] : params[0];
            long max = params[0] > params[1] ? params[0] : params[1];

            writeln(abs((max / min) - min) <= d ? "YES" : "NO");
        }
    }
}

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

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

        if(params[0] == 0 || params[1] == 0)
        {
            writeln("NO");
        }
        if(params[0] == 1 || params[1] == 1)
        {
            writeln(d == 0 ? "YES" : "NO");
        }
        else
        {
            int min = params[0] > params[1] ? params[1] : params[0];
            int max = params[0] > params[1] ? params[0] : params[1];

            writeln(abs((max / min) - min) <= d ? "YES" : "NO");
        }
    }
}

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

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

        if(params[0] == 0 || params[1] == 0)
        {
            writeln("NO");
        }
        else
        {
            int min = params[0] > params[1] ? params[1] : params[0];
            int max = params[0] > params[1] ? params[0] : params[1];

            writeln(abs((max / min) - min) <= d ? "YES" : "NO");
        }
    }
}

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

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

while(t--) {
    int r, b, d;
    readf("%s %s %s\n", &r, &b, &d);
    if(r > b)
        swap(r,b);
    if(b <= r*(d + 1))
        "YES".writeln;
    else
        "NO".writeln;
}
}


There are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburger you need two buns and a beef patty. To assemble a chicken burger you need two buns and a chicken cutlet. You have $$$b$$$ buns, $$$p$$$ beef patties and $$$f$$$ chicken cutlets in your restaurant. You can sell one hamburger for $$$h$$$ dollars and one chicken burger for $$$c$$$ dollars. Calculate the maximum profit you can achieve.You have to answer $$$t$$$ independent queries.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) – the number of queries. The first line of each query contains three integers $$$b$$$, $$$p$$$ and $$$f$$$ ($$$1 \le b, ~p, ~f \le 100$$$) — the number of buns, beef patties and chicken cutlets in your restaurant. The second line of each query contains two integers $$$h$$$ and $$$c$$$ ($$$1 \le h, ~c \le 100$$$) — the hamburger and chicken burger prices in your restaurant.

For each query print one integer — the maximum profit you can achieve.

NoteIn first query you have to sell two hamburgers and three chicken burgers. Your income is $$$2 \cdot 5 + 3 \cdot 10 = 40$$$.In second query you have to ell one hamburgers and two chicken burgers. Your income is $$$1 \cdot 10 + 2 \cdot 12 = 34$$$.In third query you can not create any type of burgers because because you have only one bun. So your income is zero.

import std.stdio;
import std.algorithm;
int main()
{
	int t=0;
	readf(" %d", &t);
	for (int i=0; i<t; i++)
	{
		int a=0;
		int b=0;
		int c=0;
		int d=0;
		int e=0;
		readf(" %d", &a);
		readf(" %d", &b);
		readf(" %d", &c);
		readf(" %d", &d);
		readf(" %d", &e);
		int r=a/2;
		int sum=0;
		if (d==e)
		{
			sum=sum+min(r,b+c)*d;
		}
		else
		{
			if (d>e)
			{
				sum=sum+min(r, b)*d+min(r-min(r,b),c)*e;
			}
			else
			{
				sum=sum+min(r, c)*e+min(r-min(r,c),b)*d;
			}
		}
		writeln(sum);
	}
	return 0;
}

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

string FMT_F = "%.10f";

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; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
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; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

//long mod = 10^^9 + 7;
long mod = 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 main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (i; 0..t)
	{
		auto bpf = RDA;
		auto b   = bpf[0];
		auto hc  = RDA;
		long cnt1, cnt2;
		if (hc[0] > hc[1])
		{
			cnt1 = bpf[1];
			cnt2 = bpf[2];
		}
		else
		{
			cnt1 = bpf[2];
			cnt2 = bpf[1];
		}
		auto c1 = min(cnt1, b/2);
		b      -= c1 * 2;
		ans[i] += c1 * max(hc[0], hc[1]);
		auto c2 = min(cnt2, b/2);
		ans[i] += c2 * min(hc[0], hc[1]);
	}

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


William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $$$a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$$$ and can be one of two types:   Add an item $$$a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$$$ (starting a list of a deeper level), or  Add an item $$$a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$$$ (continuing the current level).  Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section.When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number.William wants you to help him restore a fitting original nested list.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^3$$$), which is the number of lines in the list. Each of the next $$$n$$$ lines contains a single integer $$$a_i$$$ ($$$1 \le a_i \le n$$$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $$$n$$$ across all test cases does not exceed $$$10^3$$$.

For each test case output $$$n$$$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any.

NoteIn the second example test case one example of a fitting list is:11.1 1.1.11.1.21.21.2.122.12.2This list can be produced by using the sequence of operations shown below:    Original list with a single item $$$1$$$.  Insert item $$$2$$$ by using the insertion operation of the second type after item $$$1$$$.  Insert item $$$1.1$$$ by using the insertion operation of the first type after item $$$1$$$.  Insert item $$$1.2$$$ by using the insertion operation of the second type after item $$$1.1$$$.  Insert item $$$1.1.1$$$ by using the insertion operation of the first type after item $$$1.1$$$.  Insert item $$$1.1.2$$$ by using the insertion operation of the second type after item $$$1.1.1$$$.  Insert item $$$1.2.1$$$ by using the insertion operation of the first type after item $$$1.2$$$.  Insert item $$$2.1$$$ by using the insertion operation of the first type after item $$$2$$$.  Insert item $$$2.2$$$ by using the insertion operation of the second type after item $$$2.1$$$.

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		int [] c;
		foreach (i; 0..n)
		{
			c ~= readln.strip.to !(int);
		}

		int [] stack;
		foreach (ref x; c)
		{
			if (x == 1)
			{
				stack ~= x;
			}
			else
			{
				while (stack.back != x - 1)
				{
					stack.popBack ();
				}
				stack.assumeSafeAppend ();
				stack.back += 1;
			}
			writefln !("%(%s.%)") (stack);
		}
	}
}


"The Chamber of Secrets has been opened again" — this news has spread all around Hogwarts and some of the students have been petrified due to seeing the basilisk. Dumbledore got fired and now Harry is trying to enter the Chamber of Secrets. These aren't good news for Lord Voldemort. The problem is, he doesn't want anybody to be able to enter the chamber. The Dark Lord is going to be busy sucking life out of Ginny.The Chamber of Secrets is an n × m rectangular grid in which some of the cells are columns. A light ray (and a basilisk's gaze) passes through the columns without changing its direction. But with some spell we can make a column magic to reflect the light ray (or the gaze) in all four directions when it receives the ray. This is shown in the figure below.   The left light ray passes through a regular column, and the right ray — through the magic column.  The basilisk is located at the right side of the lower right cell of the grid and is looking to the left (in the direction of the lower left cell). According to the legend, anyone who meets a basilisk's gaze directly dies immediately. But if someone meets a basilisk's gaze through a column, this person will get petrified. We know that the door to the Chamber is located on the left side of the upper left corner of the grid and anyone who wants to enter will look in the direction of its movement (in the direction of the upper right cell) from that position.   This figure illustrates the first sample test.  Given the dimensions of the chamber and the location of regular columns, Lord Voldemort has asked you to find the minimum number of columns that we need to make magic so that anyone who wants to enter the chamber would be petrified or just declare that it's impossible to secure the chamber.

The first line of the input contains two integer numbers n and m (2 ≤ n, m ≤ 1000). Each of the next n lines contains m characters. Each character is either "." or "#" and represents one cell of the Chamber grid. It's "." if the corresponding cell is empty and "#" if it's a regular column.

Print the minimum number of columns to make magic or -1 if it's impossible to do.

NoteThe figure above shows the first sample test. In the first sample we should make both columns magic. The dragon figure represents the basilisk and the binoculars represent the person who will enter the Chamber of secrets. The black star shows the place where the person will be petrified. Yellow lines represent basilisk gaze moving through columns.

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

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

    string[] arr;
    foreach (i; 0 .. n) { arr ~= readln.chomp; }

    debug { arr.writefln!"%(%s %)"; }

    auto rows = new bool[] (n);
    auto cols = new bool[] (m);

    auto rq = make!(DList!int), cq = make!(DList!int);
    rq ~= n-1;

    int step = 0;
    bool reach = false;
    outer: while (!rq.empty()) {
        step += 2;
        while (!rq.empty()) {
            int x = rq.front();
            rq.removeFront();

            if (rows[x]) { continue; }

            rows[x] = true;
            foreach (i; 0 .. m) {
                if (arr[x][i] == '.') { continue; }
                if (cols[i]) { continue; }

                cq ~= i;
            }
        }

        while (!cq.empty()) {
            int x = cq.front();
            cq.removeFront();

            if (cols[x]) { continue; }

            cols[x] = true;
            foreach (i; 0 .. n) {
                if (arr[i][x] == '.') { continue; }
                if (rows[i]) { continue; }

                if (i == 0) {
                    reach = true;
                    break outer;
                }

                rq ~= i;
            }
        }
    }

    if (!reach) {
        writeln(-1);
        return;
    }

    step.writeln;
}


The only difference between the easy and hard versions is that the given string $$$s$$$ in the easy version is initially a palindrome, this condition is not always true for the hard version.A palindrome is a string that reads the same left to right and right to left. For example, "101101" is a palindrome, while "0101" is not.Alice and Bob are playing a game on a string $$$s$$$ (which is initially a palindrome in this version) of length $$$n$$$ consisting of the characters '0' and '1'. Both players take alternate turns with Alice going first.In each turn, the player can perform one of the following operations:   Choose any $$$i$$$ ($$$1 \le i \le n$$$), where $$$s[i] =$$$ '0' and change $$$s[i]$$$ to '1'. Pay 1 dollar.  Reverse the whole string, pay 0 dollars. This operation is only allowed if the string is currently not a palindrome, and the last operation was not reverse. That is, if Alice reverses the string, then Bob can't reverse in the next move, and vice versa. Reversing a string means reordering its letters from the last to the first. For example, "01001" becomes "10010" after reversing.The game ends when every character of string becomes '1'. The player who spends minimum dollars till this point wins the game and it is a draw if both spend equal dollars. If both players play optimally, output whether Alice wins, Bob wins, or if it is a draw.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^3$$$). The second line of each test case contains the string $$$s$$$ of length $$$n$$$, consisting of the characters '0' and '1'. It is guaranteed that the string $$$s$$$ is a palindrome and contains at least one '0'.  Note that there is no limit on the sum of $$$n$$$ over test cases.

For each test case print a single word in a new line:    "ALICE", if Alice will win the game,  "BOB", if Bob will win the game,  "DRAW", if the game ends in a draw.

NoteIn the first test case of the example,   in the $$$1$$$-st move Alice has to perform the $$$1$$$-st operation, since the string is currently a palindrome.  in the $$$2$$$-nd move Bob reverses the string.  in the $$$3$$$-rd move Alice again has to perform the $$$1$$$-st operation. All characters of the string are '1', game over.  Alice spends $$$2$$$ dollars while Bob spends $$$0$$$ dollars. Hence, Bob always wins.

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

string FMT_F = "%.10f";

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

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

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

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

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

		long cnt;
		foreach (c; s)
		{
			if (c == '0')
				++cnt;
		}

		if (cnt % 2)
			ans[ti] = cnt == 1 ? -1 : 1;
		else
			ans[ti] = -1;
	}

	foreach (e; ans)
	{
		writeln(e == 1 ? "ALICE" : e == -1 ? "BOB" : "DRAW");
	}
	stdout.flush;
	debug readln;
}

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

void main() {
    foreach(t; 0 .. to!int(readln.chomp)) {
        int n = to!int(readln.chomp);
        string s = readln.chomp;
        bool pal = true;
        int open = 0;
        foreach(i; 0 .. s.length/2) {
            if(s[i] == s[$-(1+i)]) {
                if(s[i] == '0') open += 2;
            } else {
                open++;
                pal = false;
            }
        }
        if(pal) {
            if(n == 1) {
                writeln("BOB");
            } else if(n%2) {
                if(s[$/2] == '0' && open) writeln("ALICE");
                else writeln("BOB");
            } else {
                writeln("BOB");
            }

        } else {
        }
    }
}

import std.stdio, std.string;
void main()
{
    int q;
    readf!"%d\n"(q);
    foreach (_; 0 .. q)
    {
        readln;
        ulong cnt = readln.chomp.count('0');
        if (cnt == 1)
            writeln("BOB");
        else if (cnt % 2)
            writeln("ALICE");
        else
            writeln("BOB");
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		long cnt;
		foreach (c; s)
		{
			if (c == '0')
				++cnt;
		}

		if (cnt % 2)
			ans[ti] = cnt <= 3 ? -1 : 1;
		else
			ans[ti] = -1;
	}

	foreach (e; ans)
	{
		writeln(e == 1 ? "ALICE" : e == -1 ? "BOB" : "DRAW");
	}
	stdout.flush;
	debug readln;
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		long cnt;
		foreach (c; s)
		{
			if (c == '0')
				++cnt;
		}

		if (cnt % 2)
			ans[ti] = ((cnt/2) % 2) ? 1 : -1;
		else
			ans[ti] = -1;
	}

	foreach (e; ans)
	{
		writeln(e == 1 ? "ALICE" : e == -1 ? "BOB" : "DRAW");
	}
	stdout.flush;
	debug readln;
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		long cnt;
		foreach (c; s)
		{
			if (c == '0')
				++cnt;
		}

		if (cnt % 2)
			ans[ti] = ((cnt/2) % 2) ? 1 : -1;
		else
			ans[ti] = ((cnt/2) % 2) ? -1 : 0;
	}

	foreach (e; ans)
	{
		writeln(e == 1 ? "ALICE" : e == -1 ? "BOB" : "DRAW");
	}
	stdout.flush;
	debug readln;
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		long cnt;
		foreach (c; s)
		{
			if (c == '0')
				++cnt;
		}
		if (cnt == 0) continue;

		if (cnt % 2)
			ans[ti] = (cnt/2) % 2 ? 1 : -1;
		else
			ans[ti] = cnt % 4 ? -1 : 0;
	}

	foreach (e; ans)
	{
		writeln(e == 1 ? "ALICE" : e == -1 ? "BOB" : "DRAW");
	}
	stdout.flush;
	debug readln;
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		long cnt;
		foreach (c; s)
		{
			if (c == '0')
				++cnt;
		}
		if (cnt == 0) continue;

		if (n % 2 && s[n/2] == '0')
		{
			if (cnt % 2 == 0)
				ans[ti] = 0;
			else
				ans[ti] = (cnt/2) % 2 ? 1 : -1;
		}
		else
			ans[ti] = cnt % 4 ? -1 : 0;
	}

	foreach (e; ans)
	{
		writeln(e == 1 ? "ALICE" : e == -1 ? "BOB" : "DRAW");
	}
	stdout.flush;
	debug readln;
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		long cnt;
		foreach (c; s)
		{
			if (c == '0')
				++cnt;
		}
		if (cnt == 0) continue;
		ans[ti] = cnt % 4 ? -1 : 0;
	}

	foreach (e; ans)
	{
		writeln(e == 1 ? "ALICE" : e == -1 ? "BOB" : "DRAW");
	}
	stdout.flush;
	debug readln;
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		long cnt;
		foreach (c; s)
		{
			if (c == '0')
				++cnt;
		}
		ans[ti] = cnt % 4 ? -1 : 0;
	}

	foreach (e; ans)
	{
		writeln(e == 1 ? "ALICE" : e == -1 ? "BOB" : "DRAW");
	}
	stdout.flush;
	debug readln;
}

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

void main() {
    foreach(t; 0 .. to!int(readln.chomp)) {
        int n = to!int(readln.chomp);
        string s = readln.chomp;
        bool pal = true;
        int open = 0;
        foreach(i; 0 .. s.length/2) {
            if(s[i] == s[$-(1+i)]) {
                if(s[i] == '0') open += 2;
            } else {
                open++;
                pal = false;
            }
        }
        if(pal) {
            if(n == 1) {
                writeln("BOB");
            } else if(n%2) {
                if(s[$/2] == '0') writeln("ALICE");
                else writeln("BOB");
            } else {
                writeln("BOB");
            }

        } else {
        }
    }
}

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

void main() {
    foreach(t; 0 .. to!int(readln.chomp)) {
        int n = to!int(readln.chomp);
        string s = readln.chomp;
        bool pal = true;
        int open = 0;
        foreach(i; 0 .. s.length/2) {
            if(s[i] == s[$-(1+i)]) {
                if(s[i] == '0') open += 2;
            } else {
                open++;
                pal = false;
            }
        }
        if(pal) {
            if(n == 1) {
                writeln("BOB");
            } else if(n%2) {
                if(s[$/2+1] == '0') writeln("ALICE");
                else writeln("BOB");
            } else {
                writeln("BOB");
            }

        } else {
        }
    }
}

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

void main() {
    foreach(t; 0 .. to!int(readln.chomp)) {
        int n = to!int(readln.chomp);
        string s = readln.chomp;
        bool pal = true;
        int open = 0;
        foreach(i; 0 .. s.length/2) {
            if(s[i] == s[$-(1+i)]) {
                if(s[i] == '0') open += 2;
            } else {
                open++;
                pal = false;
            }
        }
        if(pal) {
            if(n == 1) {
                writeln("BOB");
            } else if(n%2) {
                writeln("ALICE");
            } else {
                writeln("BOB");
            }

        } else {
        }
    }
}


Even polar bears feel cold when lying on the ice. Therefore, a polar bear Alice is going to make a carpet. The carpet can be viewed as a grid with height h and width w. Then the grid is divided into h × w squares. Alice is going to assign one of k different colors to each square. The colors are numbered from 1 to k. She may choose not to use all of the colors.However, there are some restrictions. For every two adjacent squares (squares that shares an edge) x and y, there is a color constraint in one of the forms:   color(x) = color(y), or  color(x) ≠ color(y). Example of the color constraints:  Ideally, Alice wants to satisfy all color constraints. But again, life in the Arctic is hard. It is not always possible to satisfy all color constraints. Fortunately, she will still be happy if at least  of the color constraints are satisfied. If she has 4 colors she can color the carpet in the following way:  And she is happy because  of the color constraints are satisfied, and . Your task is to help her color the carpet.

The first line contains three integers h, w, k (2 ≤ h, w ≤ 1000, 1 ≤ k ≤ w·h). The next 2h - 1 lines describe the color constraints from top to bottom, left to right. They contain w - 1, w, w - 1, w, ..., w - 1 characters respectively. Each color constraint is represented by a character "E" or "N", where "E" means " = " and "N" means " ≠ ". The color constraints listed in the order they are depicted on the picture.

If there is a coloring that satisfies at least  of the color constraints, print "YES" (without quotes) in the first line. In each of the next h lines, print w integers describing the coloring. Otherwise, print "NO" (without quotes).

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, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(    const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	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)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(in T[] as, in 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)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

int M, N, K;
char[][] A;

int[][] solve() {
	if (K == 1) {
		int nmr, dnm;
		foreach (x; 0 .. M) foreach (y; 0 .. N) {
			if (x > 0) {
				if (A[(x - 1) + x][y + y] == 'E') {
					++nmr;
				}
				++dnm;
			}
			if (y > 0) {
				if (A[x + x][(y - 1) + y] == 'E') {
					++nmr;
				}
				++dnm;
			}
		}
		if (nmr * 4 >= dnm * 3) {
			return new int[][](M, N);
		} else {
			return null;
		}
	} else {
		int m, n;
		char[][] a;
		if ((M - 1) * N <= M * (N - 1)) {
			m = M;
			n = N;
			a = A;
		} else {
			m = N;
			n = M;
			a = new char[][](m * 2, n * 2);
			foreach (x; 0 .. m * 2) foreach (y; 0 .. n * 2) {
				a[x][y] = A[y][x];
			}
		}
		int[][] ret = new int[][](m, n);
		foreach (x; 0 .. m) {
			foreach (src; 0 .. 2) {
				ret[x][0] = src;
				foreach (y; 1 .. n) {
					ret[x][y] = ret[x][y - 1] ^ ((a[x + x][(y - 1) + y] != 'E') ? 1 : 0);
				}
				if (x > 0) {
					int cnt;
					foreach (y; 0 .. n) {
						if ((a[(x - 1) + x][y + y] == 'E') == (ret[x - 1][y] == ret[x][y])) {
							++cnt;
						}
					}
					if (cnt * 2 >= n) {
						break;
					}
				} else {
					break;
				}
			}
		}
		int[][] RET;
		if ((M - 1) * N <= M * (N - 1)) {
			RET = ret;
		} else {
			RET = new int[][](M, N);
			foreach (x; 0 .. M) foreach (y; 0 .. N) {
				RET[x][y] = ret[y][x];
			}
		}
		return RET;
	}
}

void main(string[] args) {
	try {
	for (; ; ) {
		M = readInt;
		N = readInt;
		K = readInt;
		A = new char[][](M * 2, N * 2);
		foreach (x; 0 .. M) {
			if (x > 0) {
				auto str = readToken;
				foreach (y; 0 .. N) {
					A[(x - 1) + x][y + y] = str[y];
				}
			}
			{
				auto str = readToken;
				foreach (y; 1 .. N) {
					A[x + x][(y - 1) + y] = str[y - 1];
				}
			}
		}

		if (auto res = solve) {
			writeln("YES");
			foreach (line; res) {
				line[] += 1;
				writeln(line.to!string.removechars("[],"));
			}
		} else {
			writeln("NO");
		}
	}
	} catch (EOFException) {}
}

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, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(    const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	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)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(in T[] as, in 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)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

int M, N, K;
char[][] A;

int[][] solve() {
	if (K == 1) {
		int nmr, dnm;
		foreach (x; 0 .. M) foreach (y; 0 .. N) {
			if (x > 0) {
				if (A[(x - 1) + x][y + y] == 'E') {
					++nmr;
				}
				++dnm;
			}
			if (y > 0) {
				if (A[x + x][(y - 1) + y] == 'E') {
					++nmr;
				}
				++dnm;
			}
		}
		if (nmr * 2 >= dnm) {
			return new int[][](M, N);
		} else {
			return null;
		}
	} else {
		int m, n;
		char[][] a;
		if ((M - 1) * N <= M * (N - 1)) {
			m = M;
			n = N;
			a = A;
		} else {
			m = N;
			n = M;
			a = new char[][](m * 2, n * 2);
			foreach (x; 0 .. m * 2) foreach (y; 0 .. n * 2) {
				a[x][y] = A[y][x];
			}
		}
		int[][] ret = new int[][](m, n);
		foreach (x; 0 .. m) {
			foreach (src; 0 .. 2) {
				ret[x][0] = src;
				foreach (y; 1 .. n) {
					ret[x][y] = ret[x][y - 1] ^ ((a[x + x][(y - 1) + y] != 'E') ? 1 : 0);
				}
				if (x > 0) {
					int cnt;
					foreach (y; 0 .. n) {
						if ((a[(x - 1) + x][y + y] == 'E') == (ret[x - 1][y] == ret[x][y])) {
							++cnt;
						}
					}
					if (cnt * 2 >= n) {
						break;
					}
				} else {
					break;
				}
			}
		}
		int[][] RET;
		if ((M - 1) * N <= M * (N - 1)) {
			RET = ret;
		} else {
			RET = new int[][](M, N);
			foreach (x; 0 .. M) foreach (y; 0 .. N) {
				RET[x][y] = ret[y][x];
			}
		}
		return RET;
	}
}

void main(string[] args) {
	try {
	for (; ; ) {
		M = readInt;
		N = readInt;
		K = readInt;
		A = new char[][](M * 2, N * 2);
		foreach (x; 0 .. M) {
			if (x > 0) {
				auto str = readToken;
				foreach (y; 0 .. N) {
					A[(x - 1) + x][y + y] = str[y];
				}
			}
			{
				auto str = readToken;
				foreach (y; 1 .. N) {
					A[x + x][(y - 1) + y] = str[y - 1];
				}
			}
		}

		if (auto res = solve) {
			writeln("YES");
			foreach (line; res) {
				line[] += 1;
				writeln(line.to!string.removechars("[],"));
			}
		} else {
			writeln("NO");
		}
	}
	} catch (EOFException) {}
}


You are given array $$$a_1, a_2, \dots, a_n$$$. Find the subsegment $$$a_l, a_{l+1}, \dots, a_r$$$ ($$$1 \le l \le r \le n$$$) with maximum arithmetic mean $$$\frac{1}{r - l + 1}\sum\limits_{i=l}^{r}{a_i}$$$ (in floating-point numbers, i.e. without any rounding).If there are many such subsegments find the longest one.

The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — length of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the array $$$a$$$.

Print the single integer — the length of the longest subsegment with maximum possible arithmetic mean.

NoteThe subsegment $$$[3, 4]$$$ is the longest among all subsegments with maximum arithmetic mean.

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

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

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

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

    auto mx = a.maxElement;

    int ans = 1;
    for (int i = 0; i < n; ) {
        if (a[i] != mx) {
            i += 1;
            continue;
        }

        int j = i+1;
        while (j < n && a[j] == mx) ++j;

        ans = max(ans, j - i);

        i = j;
    }

    ans.writeln;
}


Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$).   If $$$a_i = a_j$$$, change one of them to $$$0$$$.  Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.

The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.

For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.

NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 < a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 < a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 < a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.

void main() { runSolver(); }

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

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto A = scan!int(N);

      long ans;
      if (!A.canFind(0)) {
        if (A.sort.uniq.array.length == N) ans++;
        ans += N;
      } else {
        ans = A.count!"a != 0";
      }

      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"];

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


You are given $$$n$$$ elements numbered from $$$1$$$ to $$$n$$$, the element $$$i$$$ has value $$$a_i$$$ and color $$$c_i$$$, initially, $$$c_i = 0$$$ for all $$$i$$$.The following operation can be applied:  Select three elements $$$i$$$, $$$j$$$ and $$$k$$$ ($$$1 \leq i < j < k \leq n$$$), such that $$$c_i$$$, $$$c_j$$$ and $$$c_k$$$ are all equal to $$$0$$$ and $$$a_i = a_k$$$, then set $$$c_j = 1$$$. Find the maximum value of $$$\sum\limits_{i=1}^n{c_i}$$$ that can be obtained after applying the given operation any number of times.

The first line contains an integer $$$n$$$ ($$$3 \leq n \leq 2 \cdot 10^5$$$) — the number of elements. The second line consists of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq n$$$), where $$$a_i$$$ is the value of the $$$i$$$-th element.

Print a single integer in a line — the maximum value of $$$\sum\limits_{i=1}^n{c_i}$$$ that can be obtained after applying the given operation any number of times.

NoteIn the first test, it is possible to apply the following operations in order:

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

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto hi = new int [n + 1];
		hi[] = int.min;
		foreach (int i, ref c; a)
		{
			hi[c] = max (hi[c], i);
		}

		int best = -1;
		int next = -1;
		int res = 0;
		foreach (int i, ref c; a)
		{
			next = max (next, hi[c]);
			if (i < best)
			{
				res += 1;
			}
			else
			{
				best = next;
			}
		}
		writeln (res);
	}
}

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

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto hi = new int [n + 1];
		hi[] = int.min;
		foreach (int i, ref c; a)
		{
			hi[c] = max (hi[c], i);
		}

		int best = -1;
		int lo = -1;
		int res = 0;
		foreach (int i, ref c; a)
		{
			if (best < hi[c])
			{
				best = hi[c];
				if (lo < i)
				{
					lo = best;
				}
				else
				{
					res += 1;
				}
			}
			else if (i < best)
			{
				res += 1;
			}
		}
		writeln (res);
	}
}

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

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto lo = new int [n + 1];
		lo[] = int.max;
		auto hi = new int [n + 1];
		hi[] = int.min;
		foreach (int i, ref c; a)
		{
			lo[c] = min (lo[c], i);
			hi[c] = max (hi[c], i);
		}

		int best = 0;
		int res = 0;
		foreach (int i, ref c; a)
		{
			if (best < hi[c])
			{
				best = hi[c];
			}
			else if (best > i)
			{
				res += 1;
			}
		}
		writeln (res);
	}
}


Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n.Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, that is, a teleportation pipe from city x to city y cannot be used to travel from city y to city x. The transportation within each city is extremely developed, therefore if a pipe from city x to city y and a pipe from city y to city z are both constructed, people will be able to travel from city x to city z instantly.Mr. Kitayuta is also involved in national politics. He considers that the transportation between the m pairs of city (ai, bi) (1 ≤ i ≤ m) is important. He is planning to construct teleportation pipes so that for each important pair (ai, bi), it will be possible to travel from city ai to city bi by using one or more teleportation pipes (but not necessarily from city bi to city ai). Find the minimum number of teleportation pipes that need to be constructed. So far, no teleportation pipe has been constructed, and there is no other effective transportation between cities.

The first line contains two space-separated integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105), denoting the number of the cities in Shuseki Kingdom and the number of the important pairs, respectively. The following m lines describe the important pairs. The i-th of them (1 ≤ i ≤ m) contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), denoting that it must be possible to travel from city ai to city bi by using one or more teleportation pipes (but not necessarily from city bi to city ai). It is guaranteed that all pairs (ai, bi) are distinct.

Print the minimum required number of teleportation pipes to fulfill Mr. Kitayuta's purpose.

NoteFor the first sample, one of the optimal ways to construct pipes is shown in the image below:   For the second sample, one of the optimal ways is shown below:

import std.stdio, std.array, std.range, std.string, std.typecons;
import std.algorithm, std.container, std.math, std.numeric, std.random;
void scan(T...)(ref T args) { foreach (ref arg; args) readf(" %s", &arg); }
void minify(T)(ref T a, in T b) { if (a > b) a = b; }
void maxify(T)(ref T a, in T b) { if (a < b) a = b; }
void ewriteln(T...)(T args) { stderr.writeln("\033[35m", args, "\033[0m"); }
int ilen(T)(const ref T a) { return cast(int)(a.length); }

enum int N = 10 ^^ 5 + 8;
int n, m;
Array!int[N] graph;
Array!int[N] antigraph;
int[N] outdeg;
bool[N] vis;
Array!int curv;
int cost = 0;

void dfs(int v) {
	if (vis[v]) return;
	curv ~= v;
	vis[v] = true;
	foreach (w; graph[v]) { dfs(w); }
	foreach (w; antigraph[v]) { dfs(w); }
}

SList!int out0;
void solveFrom(int v0) {
	if (!vis[v0]) {
		curv.length = 0;
		dfs(v0);
		out0.clear();
		debug {
			ewriteln("solving from: ", v0);
			ewriteln("  curv cap ", curv.capacity);
			ewriteln("  out0 cap ", out0.capacity);
		}
		int ovs = 0;
		foreach (v; curv) {
			outdeg[v] = graph[v].ilen;
			if (outdeg[v] == 0) {
				out0.insertFront(v);
				ovs++;
			}
		}
		while (!out0.empty) {
			int v = out0.front; out0.removeFront();
			foreach (w; antigraph[v]) {
				assert(outdeg[w] >= 1);
				outdeg[w]--;
				if (outdeg[w] == 0) {
					out0.insertFront(w);
					ovs++;
				}
			}
		}
		cost += ovs == curv.ilen ? curv.ilen - 1 : curv.ilen;
	}
}

int solve() {
	foreach (i; 1..n+1) { solveFrom(i); }
	return cost;
}

void main() {
	scan(n, m);
	foreach(_; 0..m) {
		int a, b;
		scan(a, b);
		graph[a] ~= b;
		antigraph[b] ~= a;
	}
	writeln(solve());
}

import std.stdio, std.array, std.range, std.string, std.typecons;
import std.algorithm, std.container, std.math, std.numeric, std.random;
void scan(T...)(ref T args) { foreach (ref arg; args) readf(" %s", &arg); }
void minify(T)(ref T a, in T b) { if (a > b) a = b; }
void maxify(T)(ref T a, in T b) { if (a < b) a = b; }
void ewriteln(T...)(T args) { stderr.writeln("\033[35m", args, "\033[0m"); }
int ilen(T)(const ref T a) { return cast(int)(a.length); }
void push(T)(ref Array!T a, in T b) {
	if (a.length == a.capacity) a.reserve(2*a.capacity + 1);
	a ~= b;
}

enum int N = 10 ^^ 5 + 8;
int n, m;
Array!int[N] graph;
Array!int[N] antigraph;
int[N] outdeg;
bool[N] vis;
Array!int curv;
int cost = 0;

void dfs(int v) {
	if (vis[v]) return;
	curv.push(v);
	vis[v] = true;
	foreach (w; graph[v]) { dfs(w); }
	foreach (w; antigraph[v]) { dfs(w); }
}

Array!int out0;
void solveFrom(int v0) {
	if (!vis[v0]) {
		curv.length = 0;
		dfs(v0);
		out0.length = 0;
		debug {
			ewriteln("solving from: ", v0);
			ewriteln("  curv cap ", curv.capacity);
			ewriteln("  out0 cap ", out0.capacity);
		}
		int ovs = 0;
		foreach (v; curv) {
			outdeg[v] = graph[v].ilen;
			if (outdeg[v] == 0) {
				out0.push(v);
				ovs++;
			}
		}
		while (!out0.empty) {
			int v = out0.back; out0.removeBack();
			foreach (w; antigraph[v]) {
				assert(outdeg[w] >= 1);
				outdeg[w]--;
				if (outdeg[w] == 0) {
					out0.push(w);
					ovs++;
				}
			}
		}
		cost += ovs == curv.ilen ? curv.ilen - 1 : curv.ilen;
	}
}

int solve() {
	foreach (i; 1..n+1) { solveFrom(i); }
	return cost;
}

void main() {
	scan(n, m);
	foreach(_; 0..m) {
		int a, b;
		scan(a, b);
		graph[a].push(b);
		antigraph[b].push(a);
	}
	writeln(solve());
}

import std.stdio, std.array, std.range, std.string, std.typecons;
import std.algorithm, std.container, std.math, std.numeric, std.random;
void scan(T...)(ref T args) { foreach (ref arg; args) scanf("%d", &arg); }
void minify(T)(ref T a, in T b) { if (a > b) a = b; }
void maxify(T)(ref T a, in T b) { if (a < b) a = b; }
void ewriteln(T...)(T args) { stderr.writeln("\033[35m", args, "\033[0m"); }
int ilen(T)(const ref T a) { return cast(int)(a.length); }
void push(T)(ref Array!T a, in T b) {
	// if (a.length == a.capacity) a.reserve(2*a.capacity + 1);
	a ~= b;
}

enum int N = 10 ^^ 5 + 8;
int n, m;
Array!int[N] graph;
Array!int[N] antigraph;
int[N] outdeg;
bool[N] vis;
Array!int curv;
int cost = 0;

void dfs(int v) {
	if (vis[v]) return;
	curv.push(v);
	vis[v] = true;
	foreach (w; graph[v]) { dfs(w); }
	foreach (w; antigraph[v]) { dfs(w); }
}

Array!int out0;
void solveFrom(int v0) {
	if (!vis[v0]) {
		curv.length = 0;
		dfs(v0);
		out0.length = 0;
		debug {
			ewriteln("solving from: ", v0);
			ewriteln("  curv cap ", curv.capacity);
			ewriteln("  out0 cap ", out0.capacity);
		}
		int ovs = 0;
		foreach (v; curv) {
			outdeg[v] = graph[v].ilen;
			if (outdeg[v] == 0) {
				out0.push(v);
				ovs++;
			}
		}
		while (!out0.empty) {
			int v = out0.back; out0.removeBack();
			foreach (w; antigraph[v]) {
				assert(outdeg[w] >= 1);
				outdeg[w]--;
				if (outdeg[w] == 0) {
					out0.push(w);
					ovs++;
				}
			}
		}
		cost += ovs == curv.ilen ? curv.ilen - 1 : curv.ilen;
	}
}

int solve() {
	foreach (i; 1..n+1) { solveFrom(i); }
	return cost;
}

void main() {
	scan(n, m);
	foreach(_; 0..m) {
		int a, b;
		scan(a, b);
		graph[a].push(b);
		antigraph[b].push(a);
	}
	writeln(solve());
}

import std.stdio, std.array, std.range, std.string, std.typecons;
import std.algorithm, std.container, std.math, std.numeric, std.random;
void scan(T...)(ref T args) { foreach (ref arg; args) readf(" %s", &arg); }
void minify(T)(ref T a, in T b) { if (a > b) a = b; }
void maxify(T)(ref T a, in T b) { if (a < b) a = b; }
void ewriteln(T...)(T args) { stderr.writeln("\033[35m", args, "\033[0m"); }
int ilen(T)(const ref T a) { return cast(int)(a.length); }

enum int N = 10 ^^ 5 + 8;
int n, m;
Array!int[N] graph;
Array!int[N] antigraph;
int[N] outdeg;
bool[N] vis;
Array!int curv;
int cost = 0;

void dfs(int v) {
	if (vis[v]) return;
	curv ~= v;
	vis[v] = true;
	foreach (w; graph[v]) { dfs(w); }
	foreach (w; antigraph[v]) { dfs(w); }
}

Array!int out0;
void solveFrom(int v0) {
	if (!vis[v0]) {
		curv.length = 0;
		dfs(v0);
		out0.length = 0;
		debug {
			ewriteln("solving from: ", v0);
			ewriteln("  curv cap ", curv.capacity);
			ewriteln("  out0 cap ", out0.capacity);
		}
		int ovs = 0;
		foreach (v; curv) {
			outdeg[v] = graph[v].ilen;
			if (outdeg[v] == 0) {
				out0 ~= v;
				ovs++;
			}
		}
		while (!out0.empty) {
			int v = out0.back; out0.removeBack();
			foreach (w; antigraph[v]) {
				assert(outdeg[w] >= 1);
				outdeg[w]--;
				if (outdeg[w] == 0) {
					out0 ~= w;
					ovs++;
				}
			}
		}
		cost += ovs == curv.ilen ? curv.ilen - 1 : curv.ilen;
	}
}

int solve() {
	foreach (i; 1..n+1) { solveFrom(i); }
	return cost;
}

void main() {
	scan(n, m);
	foreach(_; 0..m) {
		int a, b;
		scan(a, b);
		graph[a] ~= b;
		antigraph[b] ~= a;
	}
	writeln(solve());
}

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, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(    const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	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)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }
auto pair(S, T)(inout(S) x,       T  y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(in T[] as, in 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)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

int root(int[] uf, int u) {
	return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));
}
bool conn(int[] uf, int u, int v) {
	u = uf.root(u);
	v = uf.root(v);
	if (u == v) return false;
	if (uf[u] > uf[v]) swap(u, v);
	uf[u] += uf[v];
	uf[v] = u;
	return true;
}

Pair!(int, int[]) scc(int[][] g0, int[][] g1) {
	int n = g0.length;
	int compN;
	int[] compIds = new int[n];
	void dfs(int[][] g, int u, int a, int b, ref int[] st) {
		if (compIds[u] == a) {
			compIds[u] = b;
			foreach (v; g[u]) dfs(g, v, a, b, st);
			st ~= u;
		}
	}
	int[] stack, dump;
	foreach (u; 0 .. n) {
		dfs(g0, u, 0, -1, stack);
	}
	for (; !stack.empty; ) {
		int u = stack[$ - 1];
		if (compIds[u] == -1) {
			dfs(g1, u, -1, compN, dump);
			++compN;
		}
		stack.popBack;
	}
	return pair(compN, compIds);
}

int N, M;
int[] A, B;

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

		int[] uf = new int[N];
		fill(uf, -1);
		foreach (i; 0 .. M) {
			uf.conn(A[i], B[i]);
		}
		int[][] uComps = new int[][N];
		foreach (u; 0 .. N) {
			uComps[uf.root(u)] ~= u;
		}

		int[][] g0 = new int[][N];
		int[][] g1 = new int[][N];
		foreach (i; 0 .. M) {
			g0[A[i]] ~= B[i];
			g1[B[i]] ~= A[i];
		}
		int[] compIds = scc(g0, g1).y;

		int ans;
		foreach (uComp; uComps) if (!uComp.empty) {
			const int sz = uComp.length;
			int[] ids = new int[sz];
			foreach (j; 0 .. sz) {
				ids[j] = compIds[uComp[j]];
			}
			ids.sort();
			bool ok = true;
			foreach (j; 1 .. sz) {
				ok = ok && (ids[j - 1] != ids[j]);
			}
			ans += ok ? (sz - 1) : sz;
		}
		writeln(ans);
	}
	} catch (EOFException) {}
}


You are given $$$k$$$ sequences of integers. The length of the $$$i$$$-th sequence equals to $$$n_i$$$.You have to choose exactly two sequences $$$i$$$ and $$$j$$$ ($$$i \ne j$$$) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence $$$i$$$ (its length will be equal to $$$n_i - 1$$$) equals to the sum of the changed sequence $$$j$$$ (its length will be equal to $$$n_j - 1$$$).Note that it's required to remove exactly one element in each of the two chosen sequences.Assume that the sum of the empty (of the length equals $$$0$$$) sequence is $$$0$$$.

The first line contains an integer $$$k$$$ ($$$2 \le k \le 2 \cdot 10^5$$$) — the number of sequences. Then $$$k$$$ pairs of lines follow, each pair containing a sequence. The first line in the $$$i$$$-th pair contains one integer $$$n_i$$$ ($$$1 \le n_i < 2 \cdot 10^5$$$) — the length of the $$$i$$$-th sequence. The second line of the $$$i$$$-th pair contains a sequence of $$$n_i$$$ integers $$$a_{i, 1}, a_{i, 2}, \dots, a_{i, n_i}$$$. The elements of sequences are integer numbers from $$$-10^4$$$ to $$$10^4$$$. The sum of lengths of all given sequences don't exceed $$$2 \cdot 10^5$$$, i.e. $$$n_1 + n_2 + \dots + n_k \le 2 \cdot 10^5$$$.

If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers $$$i$$$, $$$x$$$ ($$$1 \le i \le k, 1 \le x \le n_i$$$), in the third line — two integers $$$j$$$, $$$y$$$ ($$$1 \le j \le k, 1 \le y \le n_j$$$). It means that the sum of the elements of the $$$i$$$-th sequence without the element with index $$$x$$$ equals to the sum of the elements of the $$$j$$$-th sequence without the element with index $$$y$$$. Two chosen sequences must be distinct, i.e. $$$i \ne j$$$. You can print them in any order. If there are multiple possible answers, print any of them.

NoteIn the first example there are two sequences $$$[2, 3, 1, 3, 2]$$$ and $$$[1, 1, 2, 2, 2, 1]$$$. You can remove the second element from the first sequence to get $$$[2, 1, 3, 2]$$$ and you can remove the sixth element from the second sequence to get $$$[1, 1, 2, 2, 2]$$$. The sums of the both resulting sequences equal to $$$8$$$, i.e. the sums are equal.

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

void main() {
    auto N = readln.chomp.to!int;
    Tuple!(int, int)[long] D;

    foreach (i; 0..N) {
        auto M = readln.chomp.to!int;
        auto A = readln.split.map!(to!long).array;
        auto S = A.sum;
        foreach (j; 0..M) {
            auto T = S - A[j];
            if (T in D) {
                if (D[T][0] != i + 1) {
                    writeln("YES");
                    writeln(D[T][0], " ", D[T][1]);
                    writeln(i+1, " ", j+1);
                    return;
                }
            } else {
                D[T] = tuple(i+1, j+1);
            }
        }
    }

    writeln("NO");
}

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

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

    int[][] a;
    foreach (_; 0..n) {
        readln;
        a ~= readln.chomp.split.map!(to!int).array;
    }

    debug { a.writeln; }

    Tuple!(int, int) [int] v;

    foreach (i, s; a.enumerate(1)) {
        int sm = s.sum;
        foreach (j, e; s.enumerate(1)) {
            int cur = sm - e;
            if (cur in v) {
                writeln("YES");
                writeln(v[cur][0], ' ', v[cur][1]);
                writeln(i, ' ', j);
                return;
            }
        }

        foreach (j, e; s.enumerate(1)) {
            int cur = sm - e;
            v[cur] = tuple(i, j);
        }
    }

    writeln("NO");
}

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

  struct P{
    int idx1, idx2;
  }
  int K; rd(K);
  P[int] set;
  for(int k=1; k<=K; k++){
    int n; rd(n);
    auto as=readln.split.to!(int[]);
    int s=reduce!"a+b"(as);
    P[] cand;
    foreach(int i, a; as){
      int t=s-a;
      if(t in set){
        if(set[t].idx1<k){
          writeln("YES");
          writeln(set[t].idx1, " ", set[t].idx2);
          writeln(k, " ", i+1);
          return;
        }
      }else{
        set[t]=P(k, i+1);
      }
    }
  }

  writeln("NO");
}

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