$$$n$$$ towns are arranged in a circle sequentially. The towns are numbered from $$$1$$$ to $$$n$$$ in clockwise order. In the $$$i$$$-th town, there lives a singer with a repertoire of $$$a_i$$$ minutes for each $$$i \in [1, n]$$$.Each singer visited all $$$n$$$ towns in clockwise order, starting with the town he lives in, and gave exactly one concert in each town. In addition, in each town, the $$$i$$$-th singer got inspired and came up with a song that lasts $$$a_i$$$ minutes. The song was added to his repertoire so that he could perform it in the rest of the cities.Hence, for the $$$i$$$-th singer, the concert in the $$$i$$$-th town will last $$$a_i$$$ minutes, in the $$$(i + 1)$$$-th town the concert will last $$$2 \cdot a_i$$$ minutes, ..., in the $$$((i + k) \bmod n + 1)$$$-th town the duration of the concert will be $$$(k + 2) \cdot a_i$$$, ..., in the town $$$((i + n - 2) \bmod n + 1)$$$ — $$$n \cdot a_i$$$ minutes.You are given an array of $$$b$$$ integer numbers, where $$$b_i$$$ is the total duration of concerts in the $$$i$$$-th town. Reconstruct any correct sequence of positive integers $$$a$$$ or say that it is impossible.

The first line contains one integer $$$t$$$ $$$(1 \le t \le 10^3$$$) — the number of test cases. Then the test cases follow. Each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \le n \le 4 \cdot 10^4$$$) — the number of cities. The second line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 10^{9}$$$) — the total duration of concerts in $$$i$$$-th city. The sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print the answer as follows: If there is no suitable sequence $$$a$$$, print NO. Otherwise, on the first line print YES, on the next line print the sequence $$$a_1, a_2, \dots, a_n$$$ of $$$n$$$ integers, where $$$a_i$$$ ($$$1 \le a_i \le 10^{9}$$$) is the initial duration of repertoire of the $$$i$$$-th singer. If there are multiple answers, print any of them.

NoteLet's consider the $$$1$$$-st test case of the example:  the $$$1$$$-st singer in the $$$1$$$-st city will give a concert for $$$3$$$ minutes, in the $$$2$$$-nd — for $$$6$$$ minutes, in the $$$3$$$-rd — for $$$9$$$ minutes;  the $$$2$$$-nd singer in the $$$1$$$-st city will give a concert for $$$3$$$ minutes, in the $$$2$$$-nd — for $$$1$$$ minute, in the $$$3$$$-rd - for $$$2$$$ minutes;  the $$$3$$$-rd singer in the $$$1$$$-st city will give a concert for $$$6$$$ minutes, in the $$$2$$$-nd — for $$$9$$$ minutes, in the $$$3$$$-rd — for $$$3$$$ minutes.

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

void solve(){
    auto n = scan;
    auto arr = scanArray;
    long summ = 0;
    for(int i = 0; i < n; ++i){
        summ += arr[i];
    }
    long asum = 2*summ;
    if(asum % n != 0 || asum % (n + 1) != 0){
        writeln("NO");
        return;
    }
    asum /= n;
    asum /= (n+1);
    long[] res;
    for(int i = 0; i < n; ++i){
        int previ = (i - 1 + n.to!int) % n.to!int;
        long diff = arr[i] - arr[previ];
        long nai = asum - diff;
        if(nai % n != 0 || nai <= 0){
            writeln("NO");
            return;
        }
        long ai = nai / n.to!long;
        res ~= ai;
    }
    writeln("YES");
    assert(res.length == n);
    res.each!(a => write(a, " "));
    writeln;
}

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

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

import std.stdio;
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 main() {
    int T = read!int;
    foreach (t; 0 .. T) solve();
}

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

    auto A = new long[N];
    bool f() {
        auto sB = B.reduce!"a + b";
        long Z = N * (N + 1L) / 2L;
        if (sB % Z > 0) {
            return false;
        }
        long sA = sB / Z;
        for (int k = 0; k < N; k++) {
            int pk = (k + N - 1) % N;
            long na = (sA - B[k] + B[pk]);
            if (na % N > 0) return false;
            if (na <= 0) return false;
            A[k] = na / N;
        }
        return true;
    }
    auto pos = f();
    writeln(pos ? "YES" : "NO");
    if (pos) {
        writefln("%(%s %)", A);
    }
}

immutable multi = true;

void solve(int tc)
{
  auto n = readInt!int;
  auto b = ma(n, readInt!long);
  if (n == 1) { writeln("YES"); writeln(b[0]); return; }
  auto dlt = new long[](n);
  dlt[0] = b[0] - b[n-1];
  foreach(i; 1 .. n)
    dlt[i] = b[i] - b[i-1];
  debug writeln("dlt ", dlt);
  long[] aDlt = new long[](n);
  foreach(i; 0 .. n)
    {
      aDlt[i] = -dlt[i] + dlt[0];
      if (aDlt[i]%n != 0) return writeln("NO");
      aDlt[i] /= n;
    }
  debug writeln("aDlt ", aDlt);
  long wsum = 0;
  foreach(i; 0 .. n)
    {
      long fact = n - i + 1;
      wsum += fact * aDlt[i];
    }
  long rhs = b[0] - wsum;
  long lhsFact = cast(long)n * (cast(long)n + 1) / 2L;
  if (rhs <= 0) return writeln("NO");
  if (rhs % lhsFact != 0) return writeln("NO");
  rhs /= lhsFact;

  aDlt[] += rhs;
  if (aDlt.fold!min <= 0) return writeln("NO");

  writeln("YES");
  foreach(d; aDlt)
    {
      write(d, " ");
    }
  writeln;
}

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

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

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

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

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

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

void solve(){
    auto n = scan;
    auto arr = scanArray;
    long summ = 0;
    for(int i = 0; i < n; ++i){
        summ += arr[i];
    }
    long asum = 2*summ;
    asum /= n;
    asum /= (n+1);
    long[] res;
    for(int i = 0; i < n; ++i){
        int previ = (i - 1 + n.to!int) % n.to!int;
        long diff = arr[i] - arr[previ];
        long nai = asum - diff;
        if(nai % n != 0 || nai <= 0){
            writeln("NO");
            return;
        }
        long ai = nai / n.to!long;
        res ~= ai;
    }
    writeln("YES");
    assert(res.length == n);
    res.each!(a => write(a, " "));
    writeln;
}

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

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

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

void solve(){
    auto n = scan!int;
    auto arr = scanArray;
    long summ = arr.sum;
    long asum = 2*summ;
    asum /= n.to!long;
    asum /= (n+1).to!long;
    long[] res;
    for(int i = 0; i < n; ++i){
        long diff = arr[i] - arr[(i - 1 + n) % n];
        long nai = asum - diff;
        if(nai % n != 0 || nai < n){
            writeln("NO");
            return;
        }
        long ai = nai / n.to!long;
        assert(ai <= 1_000_000_000);
        res ~= ai;
    }
    assert(asum == res.sum);
    if(asum != res.sum){
        writeln("NO");
        return;
    }
    writeln("YES");
    res.each!(a => write(a, " "));
    writeln;
}

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

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

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

void solve(){
    auto n = scan!int;
    auto arr = scanArray;
    long summ = arr.sum;
    long asum = 2*summ;
    asum /= n;
    asum /= (n+1);
    long[] res;
    for(int i = 0; i < n; ++i){
        long diff = arr[i] - arr[(i - 1 + n) % n];
        long nai = asum - diff;
        if(nai % n != 0 || nai < n){
            writeln("NO");
            return;
        }
        res ~= nai / n;
    }
    writeln("YES");
    res.each!(a => write(a, " "));
    writeln;
}

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

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

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

void solve(){
    auto n = scan!int;
    auto arr = scanArray;
    long summ = arr.sum;
    long asum = (2*summ) /(n * (n + 1));
    long[] res;
    for(int i = 0; i < n; ++i){
        long diff = arr[i] - arr[(i - 1 + n) % n];
        long nai = asum - diff;
        if(nai % n != 0 || nai < n){
            writeln("NO");
            return;
        }
        res ~= nai / n;
    }
    writeln("YES");
    res.each!(a => write(a, " "));
    writeln;
}

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

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


Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:(1n + 2n + 3n + 4n) mod 5for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).

The single line contains a single integer n (0 ≤ n ≤ 10105). The number doesn't contain any leading zeroes.

Print the value of the expression without leading zeros.

NoteOperation x mod y means taking remainder after division x by y.Note to the first sample:

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

void main() {
	string number = stdin.readln().stripRight;
	auto n = to!int(number[max(2, $)-2..$]) % 4;
	writeln(sum(iota(1, 5).map!(i => i ^^ n)) % 5);
}

static immutable MOD = 4;
static immutable MOD_OVERAL = 5;
static immutable MODS = [
	[1, 1, 1, 1],
	[1, 2, 4, 3],
	[1, 3, 4, 2],
	[1, 4, 1, 4]
];

uint solve(const string n) {
	uint sum = 0;
	foreach (ch; n) {
		if (ch < '0' || ch > '9') {break;}
		sum = ( (sum * 10) + (ch - '0') ) % MOD;
	}

	sum %= MOD;
	uint res = 0;
	foreach (curMod; MODS) {
		res += curMod[sum];
	}

	return res % MOD_OVERAL;
}

unittest {
	assert(4 == solve("4"));
	assert(0 == solve("124356983594583453458888889"));
	assert(4 == solve("0"));
	assert(0 == solve("5"));
	assert(0 == solve("6"));
	assert(0 == solve("7"));
	assert(4 == solve("8"));
}

int main(string[] argv) {
	import std.stdio;
	writeln(solve(readln));
    return 0;
}

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

string S;

void main(string[] args) {
	try {
	for (; ; ) {
		S = readToken;

		const n = S[max(cast(int)($) - 2, 0) .. $].to!int % 4;
		int ans;
		foreach (a; 1 .. 5) {
			int tmp = 1;
			foreach (_; 0 .. n) {
				tmp *= a;
			}
			ans += tmp;
		}
		ans %= 5;
		writeln(ans);

	}
	} catch (EOFException) {}
}


You are given an array $$$a$$$ of $$$n$$$ integers. You are asked to find out if the inequality $$$$$$\max(a_i, a_{i + 1}, \ldots, a_{j - 1}, a_{j}) \geq a_i + a_{i + 1} + \dots + a_{j - 1} + a_{j}$$$$$$ holds for all pairs of indices $$$(i, j)$$$, where $$$1 \leq i \leq j \leq n$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$)  — the size of the array. The next line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, on a new line output "YES" if the condition is satisfied for the given array, and "NO" otherwise. You can print each letter in any case (upper or lower).

NoteIn test cases $$$1$$$ and $$$2$$$, the given condition is satisfied for all $$$(i, j)$$$ pairs. In test case $$$3$$$, the condition isn't satisfied for the pair $$$(1, 2)$$$ as $$$\max(2, 3) < 2 + 3$$$.

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

struct SegmentTree(T, T unit, alias binop) {
    int n;
    T[] dat;
    this(int n_) {
        n = 1;
        while (n < n_) n *= 2;
        dat = new T[2*n+2];
        dat[] = unit;
    }
    void update(int k, in T a) {
        k += n - 1;
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = binop(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
    T query(int a, int b) const {
        return query(a, b, 0, 0, n);
    }
    T query(int a, int b, int k, int l, int r) const {
        if (r <= a || b <= l) return unit;
        if (a <= l && r <= b) return dat[k];
        T vl = query(a, b, k * 2 + 1, l, (l + r) / 2),
          vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return binop(vl, vr);
    }
}

enum long INF = 1L<<56;
alias RMQ = SegmentTree!(Tuple!(long,int), tuple(-INF, -1), (a, b) => a[0] > b[0] ? a : b);
struct T {
    long prefix_sum_max, suffix_sum_max, range_sum_max, all_sum;
}
enum unit = T(-INF, -INF, -INF, 0);
T binop(in T a, in T b) {
    return T (
            max(a.prefix_sum_max, a.all_sum + b.prefix_sum_max)
            , max(b.suffix_sum_max, a.suffix_sum_max + b.all_sum)
            , max(a.range_sum_max, b.range_sum_max, a.suffix_sum_max + b.prefix_sum_max)
            , a.all_sum + b.all_sum );
}
alias RangeSumMax = SegmentTree!(T, unit, binop);

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

    auto rmq = RMQ(N);
    auto rsmq = RangeSumMax(N);
    for (int i = 0; i < N; i++) {
        rmq.update(i, tuple(A[i], i));
        rsmq.update(i, T(A[i], A[i], A[i], A[i]));
    }

    bool f(int l, int r) {
        if (r - l <= 1) return true;
        auto m = cast(int)(rmq.query(l, r))[1];
        auto x = rsmq.query(l, m).suffix_sum_max;
        auto y = rsmq.query(m+1, r).prefix_sum_max;
        //writeln([l, r, m, x, y]);
        if (x > 0 || y > 0) return false;
        return f(l, m) && f(m + 1, r);
    }
    writeln(f(0, N) ? "YES" : "NO");

}

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

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

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

    bool C() {
        int l = 0, r = 0; // closed-open
        long s = 0;
        while (true) {
            assert(l <= r);
            assert(l == r || A[l] > 0);
            s += A[r];
            r++;
            if (s > 0) {
                if (r < N && A[r] > 0) {
                    return false;
                }
            } else {
                l = r;
                s = 0;
            }
            if (r == N) break;
        }
        return true;
    }

    writeln(C() ? "YES" : "NO");
}

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

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

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

    bool C() {
        int l = 0, r = 0; // closed-open
        long s = 0;
        while (true) {
            s += A[r];
            r++;
            if (s > 0) {
                if (r < N && A[r] > 0) {
                    return false;
                }
            } else {
                l = r;
                s = 0;
            }
            if (r == N) break;
        }
        return true;
    }

    writeln(C() ? "YES" : "NO");
}

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

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

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

    bool C() {
        int l = 0, r = 0; // closed-open
        long s = 0;
        while (true) {
            s += A[r];
            r++;
            if (s > 0) {
                if (r < N && A[r] > 0) {
                    return false;
                }
            } else {
                l = r;
                s = 0;
            }
            if (r == N) break;
        }
        return true;
    }

    writeln(C() ? "YES" : "NO");
}

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

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

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

    bool C() {
        int l = 0, r = 0; // closed-open
        long s = 0;
        while (true) {
            s += A[r];
            r++;
            if (s > 0) {
                if (r < N && A[r] > 0) {
                    return false;
                }
            } else {
                l = r;
            }
            if (r == N) break;
        }
        return true;
    }

    writeln(C() ? "YES" : "NO");
}

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


Polycarp has $$$26$$$ tasks. Each task is designated by a capital letter of the Latin alphabet.The teacher asked Polycarp to solve tasks in the following way: if Polycarp began to solve some task, then he must solve it to the end, without being distracted by another task. After switching to another task, Polycarp cannot return to the previous task.Polycarp can only solve one task during the day. Every day he wrote down what task he solved. Now the teacher wants to know if Polycarp followed his advice.For example, if Polycarp solved tasks in the following order: "DDBBCCCBBEZ", then the teacher will see that on the third day Polycarp began to solve the task 'B', then on the fifth day he got distracted and began to solve the task 'C', on the eighth day Polycarp returned to the task 'B'. Other examples of when the teacher is suspicious: "BAB", "AABBCCDDEEBZZ" and "AAAAZAAAAA".If Polycarp solved the tasks as follows: "FFGZZZY", then the teacher cannot have any suspicions. Please note that Polycarp is not obligated to solve all tasks. Other examples of when the teacher doesn't have any suspicious: "BA", "AFFFCC" and "YYYYY".Help Polycarp find out if his teacher might be suspicious.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of days during which Polycarp solved tasks. The second line contains a string of length $$$n$$$, consisting of uppercase Latin letters, which is the order in which Polycarp solved the tasks.

For each test case output:    "YES", if the teacher cannot be suspicious;  "NO", otherwise.  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).

5
3
ABA
11
DDBBCCCBBEZ
7
FFGZZZY
1
Z
2
AB

// Vicfred
// https://codeforces.com/contest/1520/problem/A
// implementation, greedy
import std.stdio;

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

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);
    char[] u;
    char last = 'a';
    foreach(ch; s) {
        if(ch != last) {
            last = ch;
            u ~= ch;
        }
    }
    bool suspicious = false;
    int[] seen = new int[27];
    foreach(ch; u) {
        if(seen[ch - 65] == 1) {
            suspicious = true;
            break;
        }
        seen[ch - 65] = 1;
    }
    if(suspicious)
        "NO".writeln;
    else
        "YES".writeln;
}
}

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;
import std.container.binaryheap;
import std.typecons;

void main()
{
    auto t = to!long(readln().chomp);
    OUTER: foreach(_; 0..t)
    {
        auto n = readln().chomp.to!int;

        auto tasks = readln().chomp;
        bool[] count = new bool[26];
        int i = 0;

        while(i < tasks.length)
        {
            if(count[tasks[i]-'A'])
            {
                writeln("NO");
                continue OUTER;
            }

            char cur = tasks[i];
            count[tasks[i]-'A'] = true;
            while(i < tasks.length -1 && tasks[i+1] == cur) i++;
            i++;
        }

        writeln("YES");
    }
}

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 n = RD!int;
		auto s = RD!string;

		string s2 = [s[0]];
		foreach (i; 1..n)
		{
			if (s[i] == s[i-1]) continue;
			s2 ~= s[i];
		}

		bool ok = true;
		bool[char] used;
		foreach (c; s2)
		{
			if (used.get(c, false))
			{
				ok = false;
				break;
			}
			used[c] = true;
		}
		ans[ti] = ok;
	}

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


Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer $$$n$$$, he encrypts it in the following way: he picks three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$l \leq a,b,c \leq r$$$, and then he computes the encrypted value $$$m = n \cdot a + b - c$$$.Unfortunately, an adversary intercepted the values $$$l$$$, $$$r$$$ and $$$m$$$. Is it possible to recover the original values of $$$a$$$, $$$b$$$ and $$$c$$$ from this information? More formally, you are asked to find any values of $$$a$$$, $$$b$$$ and $$$c$$$ such that  $$$a$$$, $$$b$$$ and $$$c$$$ are integers,  $$$l \leq a, b, c \leq r$$$,  there exists a strictly positive integer $$$n$$$, such that $$$n \cdot a + b - c = m$$$.

The first line contains the only integer $$$t$$$ ($$$1 \leq t \leq 20$$$) — the number of test cases. The following $$$t$$$ lines describe one test case each. Each test case consists of three integers $$$l$$$, $$$r$$$ and $$$m$$$ ($$$1 \leq l \leq r \leq 500\,000$$$, $$$1 \leq m \leq 10^{10}$$$). The numbers are such that the answer to the problem exists.

For each test case output three integers $$$a$$$, $$$b$$$ and $$$c$$$ such that, $$$l \leq a, b, c \leq r$$$ and there exists a strictly positive integer $$$n$$$ such that $$$n \cdot a + b - c = m$$$. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions.

NoteIn the first example $$$n = 3$$$ is possible, then $$$n \cdot 4 + 6 - 5 = 13 = m$$$. Other possible solutions include: $$$a = 4$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 3$$$); $$$a = 5$$$, $$$b = 4$$$, $$$c = 6$$$ (when $$$n = 3$$$); $$$a = 6$$$, $$$b = 6$$$, $$$c = 5$$$ (when $$$n = 2$$$); $$$a = 6$$$, $$$b = 5$$$, $$$c = 4$$$ (when $$$n = 2$$$).In the second example the only possible case is $$$n = 1$$$: in this case $$$n \cdot 2 + 2 - 3 = 1 = m$$$. Note that, $$$n = 0$$$ is not possible, since in that case $$$n$$$ is not a strictly positive integer.

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

void main ()
{
	auto tests = readln.strip.to !(int);
multitest_loop:
	foreach (test; 0..tests)
	{
		long l, r, m;
		readf !(" %s %s %s") (l, r, m);
		auto d = r - l;
		foreach (a; l..r + 1)
		{
			auto start = max (m - d, 1);
			start = (start + a - 1) / a * a;
			for (auto s = start; s <= m + d; s += a)
			{
				auto n = s / a;
				long b, c;
				if (s < m)
				{
					b = r;
					c = b + s - m;
				}
				else
				{
					b = l;
					c = b + s - m;
				}
				writeln (a, " ", b, " ", c);
				continue multitest_loop;
			}
		}
	}
}

import std.container: DList;
import std.algorithm: all, map, count, filter;
import std.range: iota;
import std.array: array;
import std.stdio;
import std.utf;

DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

void main()
{
  size_t t;
  read(t);
 testCase:foreach(tc; 0 .. t)
    {
      long l, r, m;
      read(l), read(r), read(m);
      foreach(ca; l .. r + 1)
        {
          long a = cast(long) ca;
          long b, c;
          long nm = m % a < (a - m % a)? (m - m % a) : (m - m % a + a);
          if (nm == 0)
            nm = a;
          long rem = m - nm;
          if (rem > r - l || rem < l - r) continue;
          long n = nm / a;
          if (rem >= 0)
            c = l;
          else
            c = r;
          b = c + rem;
          assert(a * n + b - c == m);
          assert(l <= a && a <= r && l <= b && b <= r && l <= c && c <= r);
          writeln(a, " ", b, " ", c);
          continue testCase;
        }
    }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
multitest_loop:
	foreach (test; 0..tests)
	{
		long l, r, m;
		readf !(" %s %s %s") (l, r, m);
		auto d = r - l;
		foreach (a; l..r + 1)
		{
			auto start = max (m - d, 1);
			start = (start + a - 1) / a * a;
			for (auto s = start; s <= m + d; s += a)
			{
				auto n = s / a;
				long b, c;
				if (s < 0)
				{
					c = r;
					b = c + s - m;
				}
				else
				{
					b = l;
					c = b + s - m;
				}
				writeln (a, " ", b, " ", c);
				continue multitest_loop;
			}
		}
	}
}

import std.container: DList;
import std.algorithm: all, map, count, filter;
import std.range: iota;
import std.array: array;
import std.stdio;
import std.utf;

DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

void main()
{
  size_t t;
  read(t);
 testCase:foreach(tc; 0 .. t)
    {
      long l, r, m;
      read(l), read(r), read(m);
      if (m <= r)
        {
          if (l <= m)
            {
              long a = m;
              long b = l;
              long c = l;
              assert(a * 1 + b - c == m);
              assert(l <= a && a <= r && l <= b && b <= r && l <= c && c <= r);
              writeln(a, " ", b, " ", c);
              continue testCase;
            }
          long a = l;
          long c = r;
          long b = m - a + c;
          assert(a * 1 + b - c == m);
          assert(l <= a && a <= r && l <= b && b <= r && l <= c && c <= r);
          writeln(a, " ", b, " ", c);
          continue testCase;
        }
      long a = r;
      long n = m / a;
      long bmc = m - a * n;
      assert(bmc <= r - l);
      long c = l;
      long b = c + bmc;
      assert(a * n + b - c == m);
      assert(l <= a && a <= r && l <= b && b <= r && l <= c && c <= r);
      writeln(a, " ", b, " ", c);
    }
}

import std.container: DList;
import std.algorithm: all, map, count, filter;
import std.range: iota;
import std.array: array;
import std.stdio;
import std.utf;

DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

void main()
{
  size_t t;
  read(t);
 testCase:foreach(tc; 0 .. t)
    {
      long l, r, m;
      read(l), read(r), read(m);
      foreach(ca; l .. r + 1)
        {
          long a = cast(long) ca;
          long b, c;
          long nm = m % a < (a - m % a)? (m - m % a) : (m - m % a + a);
          long rem = m - nm;
          if (rem > r - l || rem < l - r) continue;
          long n = nm / a;
          if (rem >= 0)
            c = l;
          else
            c = r;
          b = c + rem;
          assert(a * n + b - c == m);
          assert(l <= a && a <= r && l <= b && b <= r && l <= c && c <= r);
          writeln(a, " ", b, " ", c);
          continue testCase;
        }
    }
}


Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.

The first line contains integer n (1 ≤ n ≤ 200 000) — the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.

Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.

8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina

NoteIn the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:   alex Then Polycarpus writes to friend by name "ivan" and the list looks as follows:  ivan  alex Polycarpus writes the third message to friend by name "roman" and the list looks as follows:  roman  ivan  alex Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:  ivan  roman  alex

import std.stdio;

struct Deque(T) {
private:
    size_t size = 0, capacity = 1;
    int frontmark = 0, backmark = 0;
    T[] store = [T.init];
    void resize() {
        store.length *= 3;
        foreach(i; 0 .. capacity) {
            advance(frontmark);
            store[i + capacity] = store[frontmark];
        }
        frontmark = capacity - 1;
        backmark = 2 * capacity;
        capacity *= 3;
    }
    void advance(ref int mark) {
        ++mark;
        if (mark >= capacity) mark = 0;
    }
    void retreat(ref int mark) {
        --mark;
        if (mark < 0) mark = capacity - 1;
    }
public:
    string toString() {
        import std.conv : to;
        string result = "[ " ~ to!string(store[0]);
        foreach(i; 1 .. capacity) {
            result ~= ", ";
            result ~= to!string(store[i]);
        }
        result ~= " ]";
        return result;
    }
    @property bool empty() {
        return (size == 0);
    }
    @property T back() {
        if (empty()) return T.init;
        retreat(backmark);
        immutable savedmark = backmark;
        advance(backmark);
        return store[savedmark];
    }
    void popBack() {
        if (!empty()) {
            retreat(backmark);
            --size;
        }
    }
    void pushBack(T item) {
        if (size == capacity) resize();
        store[backmark] = item;
        advance(backmark);
        ++size;
    }
    @property T front() {
        if (empty()) return T.init;
        advance(frontmark);
        immutable savedmark = frontmark;
        retreat(frontmark);
        return store[savedmark];
    }
    void popFront() {
        if (!empty()) {
            advance(frontmark);
            --size;
        }
    }
    void pushFront(T item) {
        if (size == capacity) resize();
        store[frontmark] = item;
        retreat(frontmark);
        ++size;
    }
}

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

    Deque!(string) stack;
    bool[string] set;
    char[15][200000] buf = void;
    int n;
    readf(" %s\n", &n);
    foreach(i; 0 .. n) {
        char[] pbuf = buf[i];
        readln(pbuf);
        stack.pushBack(cast(string)pbuf);
    }
    while (!stack.empty) {
        string str = stack.back;
        stack.popBack();
        if (!(str in set)) {
            write(str);
            set[str] = true;
        }
    }

    return 0;
}

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

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

    char[12][200000] buf;
    bool[string] set;
    int n;
    readf(" %s\n", &n);
    char[] pbuf;
    foreach(i; 0 .. n) {
        readln(pbuf);
        buf[i][0 .. pbuf.length] = pbuf[];
    }
    foreach_reverse(i; 0 .. n) {
        string str = to!string(buf[i]);
        while (str[$ - 1] == 255) str.length -= 1;
        if (str !in set) {
            write(str);
            set[str] = true;
        }
    }

    return 0;
}

import std.stdio;

struct Deque(T) {
private:
    size_t size = 0, capacity = 1;
    int frontmark = 0, backmark = 0;
    T[] store = [T.init];
    void resize() {
        store.length *= 3;
        foreach(i; 0 .. capacity) {
            advance(frontmark);
            store[i + capacity] = store[frontmark];
        }
        frontmark = capacity - 1;
        backmark = 2 * capacity;
        capacity *= 3;
    }
    void advance(ref int mark) {
        ++mark;
        if (mark >= capacity) mark = 0;
    }
    void retreat(ref int mark) {
        --mark;
        if (mark < 0) mark = capacity - 1;
    }
public:
    string toString() {
        import std.conv : to;
        string result = "[ " ~ to!string(store[0]);
        foreach(i; 1 .. capacity) {
            result ~= ", ";
            result ~= to!string(store[i]);
        }
        result ~= " ]";
        return result;
    }
    @property bool empty() {
        return (size == 0);
    }
    @property T back() {
        if (empty()) return T.init;
        retreat(backmark);
        immutable savedmark = backmark;
        advance(backmark);
        return store[savedmark];
    }
    void popBack() {
        if (!empty()) {
            retreat(backmark);
            --size;
        }
    }
    void pushBack(T item) {
        if (size == capacity) resize();
        store[backmark] = item;
        advance(backmark);
        ++size;
    }
    @property T front() {
        if (empty()) return T.init;
        advance(frontmark);
        immutable savedmark = frontmark;
        retreat(frontmark);
        return store[savedmark];
    }
    void popFront() {
        if (!empty()) {
            advance(frontmark);
            --size;
        }
    }
    void pushFront(T item) {
        if (size == capacity) resize();
        store[frontmark] = item;
        retreat(frontmark);
        ++size;
    }
}

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

    Deque!string stack;
    bool[string] set;
    int n;
    readf(" %s", &n);
    foreach(i; 0 .. n) {
        string str;
        readf(" %s\n", &str);
        stack.pushBack(str);
    }
    while (!stack.empty()) {
        string str = stack.back;
        stack.popBack();
        if (!(str in set)) {
            writeln(str);
            set[str] = true;
        }
    }

    return 0;
}

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

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

    char[12][200000] buf;
    bool[const(char)[12]] set;
    int n;
    readf(" %s\n", &n);
    char[] pbuf;
    foreach(i; 0 .. n) {
        readln(pbuf);
        buf[i][0 .. pbuf.length] = pbuf[];
    }

    foreach_reverse(i; 0 .. n) {
        if (cast(const)buf[i] !in set) {
            foreach (c; buf[i]) {
                if (c == 255) break;
                write(c);
            }
            set[cast(const)buf[i]] = true;
        }
    }

    return 0;
}

import std.stdio;
import std.algorithm.sorting;
import std.range.primitives;

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

    string[] stack;
    bool[string] set;
    int n;
    readf(" %s", &n);
    foreach(i; 0 .. n) {
        string str;
        readf(" %s\n", &str);
        stack ~= str;
    }
    while (!stack.empty) {
        string str = stack.back;
        stack.popBack();
        if (str !in set) {
            writeln(str);
            set[str] = true;
        }
    }

    return 0;
}

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

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

    char[15][200000] buf = void;
    bool[string] set;
    int n;
    readf(" %s\n", &n);
    foreach(i; 0 .. n) {
        char[] pbuf;
        readln(pbuf);
        buf[i][0 .. pbuf.length] = pbuf[];
    }
    foreach_reverse(i; 0 .. n) {
        string str = to!string(buf[i]);
        while (str[$ - 1] == 0) str.length -= 1;
        if (str !in set) {
            write(str);
            set[str] = true;
        }
    }

    return 0;
}

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

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

    char[15][200000] buf = void;
    bool[string] set;
    int n;
    readf(" %s\n", &n);
    foreach(i; 0 .. n) {
        char[] pbuf = buf[i];
        readln(pbuf);
    }
    foreach_reverse(i; 0 .. n) {
        string str = cast(string)buf[i];
        while (str[$ - 1] == 0) str.length -= 1;
        if (str !in set) {
            write(str);
            set[str] = true;
        }
    }

    return 0;
}

import std.stdio;
import std.string;

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

    char[15][200000] buf = void;
    bool[string] set;
    int n;
    readf(" %s\n", &n);
    foreach(i; 0 .. n) {
        char[] pbuf = buf[i];
        readln(pbuf);
    }
    foreach_reverse(i; 0 .. n) {
        string str = cast(string)fromStringz(cast(char*)buf[i]);
        if (str !in set) {
            write(str);
            set[str] = true;
        }
    }

    return 0;
}

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

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

    char[15][200000] buf = void;
    bool[string] set;
    int n;
    readf(" %s\n", &n);
    foreach(i; 0 .. n) {
        char[] pbuf;
        readln(pbuf);
        buf[i][0 .. pbuf.length] = pbuf[];
    }
    foreach_reverse(i; 0 .. n) {
        string str = cast(string)buf[i];
        while (str[$ - 1] == 0) str.length -= 1;
        if (str !in set) {
            write(str);
            set[str] = true;
        }
    }

    return 0;
}


You have received your birthday gifts — $$$n$$$ triples of integers! The $$$i$$$-th of them is $$$\lbrace a_{i}, b_{i}, c_{i} \rbrace$$$. All numbers are greater than or equal to $$$0$$$, and strictly smaller than $$$2^{k}$$$, where $$$k$$$ is a fixed integer.One day, you felt tired playing with triples. So you came up with three new integers $$$x$$$, $$$y$$$, $$$z$$$, and then formed $$$n$$$ arrays. The $$$i$$$-th array consists of $$$a_i$$$ repeated $$$x$$$ times, $$$b_i$$$ repeated $$$y$$$ times and $$$c_i$$$ repeated $$$z$$$ times. Thus, each array has length $$$(x + y + z)$$$.You want to choose exactly one integer from each array such that the XOR (bitwise exclusive or) of them is equal to $$$t$$$. Output the number of ways to choose the numbers for each $$$t$$$ between $$$0$$$ and $$$2^{k} - 1$$$, inclusive, modulo $$$998244353$$$.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^{5}$$$, $$$1 \leq k \leq 17$$$) — the number of arrays and the binary length of all numbers. The second line contains three integers $$$x$$$, $$$y$$$, $$$z$$$ ($$$0 \leq x,y,z \leq 10^{9}$$$) — the integers you chose. Then $$$n$$$ lines follow. The $$$i$$$-th of them contains three integers $$$a_{i}$$$, $$$b_{i}$$$ and $$$c_{i}$$$ ($$$0 \leq a_{i} , b_{i} , c_{i} \leq 2^{k} - 1$$$) — the integers forming the $$$i$$$-th array.

Print a single line containing $$$2^{k}$$$ integers. The $$$i$$$-th of them should be the number of ways to choose exactly one integer from each array so that their XOR is equal to $$$t = i-1$$$ modulo $$$998244353$$$.

NoteIn the first example, the array we formed is $$$(1, 0, 0, 1, 1, 1)$$$, we have two choices to get $$$0$$$ as the XOR and four choices to get $$$1$$$.In the second example, two arrays are $$$(0, 1, 1, 2)$$$ and $$$(1, 2, 2, 3)$$$. There are sixteen $$$(4 \cdot 4)$$$ choices in total, $$$4$$$ of them ($$$1 \oplus 1$$$ and $$$2 \oplus 2$$$, two options for each) give $$$0$$$, $$$2$$$ of them ($$$0 \oplus 1$$$ and $$$2 \oplus 3$$$) give $$$1$$$, $$$4$$$ of them ($$$0 \oplus 2$$$ and $$$1 \oplus 3$$$, two options for each) give $$$2$$$, and finally $$$6$$$ of them ($$$0 \oplus 3$$$, $$$2 \oplus 1$$$ and four options for $$$1 \oplus 2$$$) give $$$3$$$.

import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.range, 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 long MO = 998244353;
enum M = 3;

int N, K;
long[] X;
int[][] A;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      K = readInt();
      X = new long[M];
      foreach (m; 0 .. M) {
        X[m] = readLong();
      }
      A = new int[][](N, M);
      foreach (i; 0 .. N) {
        foreach (m; 0 .. M) {
          A[i][m] = readInt();
        }
      }

      // pw[p][j] := ((-1)^p[0] X[0] + ... + (-1)^p[M-1] X[M-1])^j
      auto pw = new long[][](1 << M, N + 1);
      foreach (p; 0 .. 1 << M) {
        pw[p][0] = 1;
        pw[p][1] = 0;
        foreach (m; 0 .. M) {
          pw[p][1] += (((p >> m) & 1) ? -1 : +1) * X[m];
          pw[p][1] %= MO;
        }
        foreach (j; 2 .. N + 1) {
          pw[p][j] = (pw[p][j - 1] * pw[p][1]) % MO;
        }
      }

      // d[p] := Sum_i (-1)^<v, XOR{A[i][m] | m in p}>
      auto d = new int[][](1 << M, 1 << K);
      foreach (p; 0 .. 1 << M) {
        foreach (i; 0 .. N) {
          int v;
          foreach (m; 0 .. M) {
            if ((p >> m) & 1) {
              v ^= A[i][m];
            }
          }
          ++d[p][v];
        }

        // Hadamard d[p]
        foreach (k; 0 .. K) {
          foreach (v; 0 .. 1 << K) {
            const w = v ^ 1 << k;
            if (v < w) {
              const tmpV = d[p][v];
              const tmpW = d[p][w];
              d[p][v] = tmpV + tmpW;
              d[p][w] = tmpV - tmpW;
            }
          }
        }
      }

      auto f = new long[1 << K];
      foreach (v; 0 .. 1 << K) {
        auto e = new int[1 << M];
        foreach (p; 0 .. 1 << M) {
          e[p] = d[p][v];
        }

        // Hadamard e
        foreach (m; 0 .. M) {
          foreach (p; 0 .. 1 << M) {
            const q = p ^ 1 << m;
            if (p < q) {
              const tmpP = e[p];
              const tmpQ = e[q];
              e[p] = tmpP + tmpQ;
              e[q] = tmpP - tmpQ;
            }
          }
        }

        foreach (p; 0 .. 1 << M) {
          e[p] >>= M;
        }
        // e[p] := #{i | <v, A[i][m]> = p[m]}
        debug {
          writefln("v = %s: e = %s", v, e);
        }
        f[v] = 1;
        foreach (p; 0 .. 1 << M) {
          f[v] *= pw[p][e[p]];
          f[v] %= MO;
        }
      }

      // Hadamard f
      foreach (k; 0 .. K) {
        foreach (v; 0 .. 1 << K) {
          const w = v ^ 1 << k;
          if (v < w) {
            const tmpV = f[v];
            const tmpW = f[w];
            f[v] = (tmpV + tmpW) % MO;
            f[w] = (tmpV - tmpW) % MO;
          }
        }
      }

      // 2^(-K)
      const INV2 = (1 + MO) / 2;
      long INV2K = 1;
      foreach (_; 0 .. K) {
        INV2K *= INV2;
        INV2K %= MO;
      }
      foreach (v; 0 .. 1 << K) {
        f[v] *= INV2K;
        f[v] %= MO;
      }

      foreach (v; 0 .. 1 << K) {
        f[v] = (f[v] % MO + MO) % MO;
        if (v > 0) {
          write(" ");
        }
        write(f[v]);
      }
      writeln();
    }
  } catch (EOFException e) {
  }
}


There are $$$n$$$ logs, the $$$i$$$-th log has a length of $$$a_i$$$ meters. Since chopping logs is tiring work, errorgorn and maomao90 have decided to play a game.errorgorn and maomao90 will take turns chopping the logs with errorgorn chopping first. On his turn, the player will pick a log and chop it into $$$2$$$ pieces. If the length of the chosen log is $$$x$$$, and the lengths of the resulting pieces are $$$y$$$ and $$$z$$$, then $$$y$$$ and $$$z$$$ have to be positive integers, and $$$x=y+z$$$ must hold. For example, you can chop a log of length $$$3$$$ into logs of lengths $$$2$$$ and $$$1$$$, but not into logs of lengths $$$3$$$ and $$$0$$$, $$$2$$$ and $$$2$$$, or $$$1.5$$$ and $$$1.5$$$.The player who is unable to make a chop will be the loser. Assuming that both errorgorn and maomao90 play optimally, who will be the winner?

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$)  — the number of logs. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 50$$$)  — the lengths of the logs. Note that there is no bound on the sum of $$$n$$$ over all test cases.

For each test case, print "errorgorn" if errorgorn wins or "maomao90" if maomao90 wins. (Output without quotes).

NoteIn the first test case, errorgorn will be the winner. An optimal move is to chop the log of length $$$4$$$ into $$$2$$$ logs of length $$$2$$$. After this there will only be $$$4$$$ logs of length $$$2$$$ and $$$1$$$ log of length $$$1$$$.After this, the only move any player can do is to chop any log of length $$$2$$$ into $$$2$$$ logs of length $$$1$$$. After $$$4$$$ moves, it will be maomao90's turn and he will not be able to make a move. Therefore errorgorn will be the winner.In the second test case, errorgorn will not be able to make a move on his first turn and will immediately lose, making maomao90 the winner.

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		writeln (["maomao90", "errorgorn"][(a.sum - n) % 2]);
	}
}

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

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

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

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

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

        int ans;
        foreach (i; 0 .. N) {
          ans += (A[i] - 1);
        }
        writeln((ans % 2 != 0) ? "errorgorn" : "maomao90");
      }
    }
  } catch (EOFException e) {
  }
}


Nikolay lives in a two-storied house. There are $$$n$$$ rooms on each floor, arranged in a row and numbered from one from left to right. So each room can be represented by the number of the floor and the number of the room on this floor (room number is an integer between $$$1$$$ and $$$n$$$). If Nikolay is currently in some room, he can move to any of the neighbouring rooms (if they exist). Rooms with numbers $$$i$$$ and $$$i+1$$$ on each floor are neighbouring, for all $$$1 \leq i \leq n - 1$$$. There may also be staircases that connect two rooms from different floors having the same numbers. If there is a staircase connecting the room $$$x$$$ on the first floor and the room $$$x$$$ on the second floor, then Nikolay can use it to move from one room to another.     The picture illustrates a house with $$$n = 4$$$. There is a staircase between the room $$$2$$$ on the first floor and the room $$$2$$$ on the second floor, and another staircase between the room $$$4$$$ on the first floor and the room $$$4$$$ on the second floor. The arrows denote possible directions in which Nikolay can move. The picture corresponds to the string "0101" in the input.  Nikolay wants to move through some rooms in his house. To do this, he firstly chooses any room where he starts. Then Nikolay moves between rooms according to the aforementioned rules. Nikolay never visits the same room twice (he won't enter a room where he has already been). Calculate the maximum number of rooms Nikolay can visit during his tour, if:  he can start in any room on any floor of his choice,  and he won't visit the same room twice.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then test cases follow. Each test case consists of two lines. The first line contains one integer $$$n$$$ $$$(1 \le n \le 1\,000)$$$ — the number of rooms on each floor. The second line contains one string consisting of $$$n$$$ characters, each character is either a '0' or a '1'. If the $$$i$$$-th character is a '1', then there is a staircase between the room $$$i$$$ on the first floor and the room $$$i$$$ on the second floor. If the $$$i$$$-th character is a '0', then there is no staircase between the room $$$i$$$ on the first floor and the room $$$i$$$ on the second floor. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.

For each test case print one integer — the maximum number of rooms Nikolay can visit during his tour, if he can start in any room on any floor, and he won't visit the same room twice.

NoteIn the first test case Nikolay may start in the first room of the first floor. Then he moves to the second room on the first floor, and then — to the third room on the first floor. Then he uses a staircase to get to the third room on the second floor. Then he goes to the fourth room on the second floor, and then — to the fifth room on the second floor. So, Nikolay visits $$$6$$$ rooms.There are no staircases in the second test case, so Nikolay can only visit all rooms on the same floor (if he starts in the leftmost or in the rightmost room).In the third test case it is possible to visit all rooms: first floor, first room $$$\rightarrow$$$ second floor, first room $$$\rightarrow$$$ second floor, second room $$$\rightarrow$$$ first floor, second room $$$\rightarrow$$$ first floor, third room $$$\rightarrow$$$ second floor, third room $$$\rightarrow$$$ second floor, fourth room $$$\rightarrow$$$ first floor, fourth room $$$\rightarrow$$$ first floor, fifth room $$$\rightarrow$$$ second floor, fifth room.In the fourth test case it is also possible to visit all rooms: second floor, third room $$$\rightarrow$$$ second floor, second room $$$\rightarrow$$$ second floor, first room $$$\rightarrow$$$ first floor, first room $$$\rightarrow$$$ first floor, second room $$$\rightarrow$$$ first floor, third room.

import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      {
	static foreach(n; 0 .. T[i].Types.length)
	  {
	    read(args[i][n]);
	  }
      }
    else
      readf!" %s "(args[i]);
}
auto brange(alias low, alias high, alias pred, bool value)()
{
  return iota(low, high + 1).map!((a) => cast(int) pred(a)).assumeSorted.equalRange(value);
}
auto ftrue(alias low, alias high, alias pred)()
{
  return brange!(low, high, pred, false).length + low;
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t;
      get(t);
      F(t);
    }
}
alias get = read;
alias w = writeln;
alias ln = long;

ln maxsum(string str)
{
  size_t i = 0;
  ln res = 0;
  while(i < str.length && str[i] == '0')
    {
      i++;
      res++;
    }
  if (i >= str.length)
    {
      return res;
    }
  assert(str[i] == '1');
  res += 2;
  res += max(i, maxsum(str[i + 1 .. $]));
  return res;
}

int main()
{
  ln t; readf!" %s "(t);
  while(t--)
    {
      import std.conv;
      string strn = readln();
      strn = strn[0 .. $ - 1];
      ln n = to!ln(strn);
      string str = readln();
      str = str[0 .. $ - 1];
      ln maxi = -1;
      ln lowi = n + 1;
      foreach(i, c; str)
	{
	  if ( c == '1' )
	    {
	      maxi = i;
	      lowi = min(lowi, i);
	    }
	}

      import std.algorithm: reverse;
      w(max(maxsum(str), maxsum(reverse(dup(str))), 2 * (maxi + 1), 2 * (n - lowi)));
    }
  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 n = RD!int;
		auto s = RD!string;
		long cnt1, cnt2;
		foreach (j; 0..n)
		{
			if (s[j] == '1')
				break;
			++cnt1;
		}
		foreach_reverse (j; 0..n)
		{
			if (s[j] == '1')
				break;
			++cnt2;
		}
		if (cnt1 == n)
			ans[i] = n;
		else
			ans[i] = n*2 - min(cnt1, cnt2)*2;
	}

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

import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      {
	static foreach(n; 0 .. T[i].Types.length)
	  {
	    read(args[i][n]);
	  }
      }
    else
      readf!" %s "(args[i]);
}
auto brange(alias low, alias high, alias pred, bool value)()
{
  return iota(low, high + 1).map!((a) => cast(int) pred(a)).assumeSorted.equalRange(value);
}
auto ftrue(alias low, alias high, alias pred)()
{
  return brange!(low, high, pred, false).length + low;
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t;
      get(t);
      F(t);
    }
}
alias get = read;
alias w = writeln;
alias ln = long;

ln maxsum(string str)
{
  size_t i = 0;
  ln res = 0;
  while(i < str.length && str[i] == '0')
    {
      i++;
      res++;
    }
  if (i >= str.length)
    {
      return res;
    }
  assert(str[i] == '1');
  res += 2;
  res += max(i, maxsum(str[i + 1 .. $]));
  return res;
}

int main()
{
  ln t; readf!" %s "(t);
  while(t--)
    {
      import std.conv;
      string strn = readln();
      strn = strn[0 .. $ - 1];
      ln n = to!ln(strn);
      string str = readln();
      str = str[0 .. $ - 1];
      w(maxsum(str));
    }
  return 0;
}


Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it?The book contains a single string of characters "a", "b" and "c". It has been pointed out that no two consecutive characters are the same. It has also been conjectured that the string contains an unusually long subsequence that reads the same from both sides. Help Alice verify this by finding such subsequence that contains at least half of the characters of the original string, rounded down. Note that you don't have to maximise the length of it.A string $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters.

The input consists of a single string $$$s$$$ ($$$2 \leq |s| \leq 10^6$$$). The string $$$s$$$ consists only of characters "a", "b", "c". It is guaranteed that no two consecutive characters are equal.

Output a palindrome $$$t$$$ that is a subsequence of $$$s$$$ and $$$|t| \geq \lfloor \frac{|s|}{2} \rfloor$$$. If there are multiple solutions, you may print any of them. You don't have to maximise the length of $$$t$$$. If there are no solutions, output a string "IMPOSSIBLE" (quotes for clarity).

NoteIn the first example, other valid answers include "cacac", "caac", "aca" and "ccc".

/+ dub.sdl:
    name "E"
    dependency "dunkelheit" version="1.0.1"
+/

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

int main() {
    Scanner sc = new Scanner(stdin);
    scope(exit) assert(!sc.hasNext);

    string s;
    sc.read(s);

    string l, r;
    while (s.length) {
        if (s.length == 1) {
            l ~= s;
            break;
        }
        if (s.front == s.back) {
            l ~= s.front;
            r ~= s.back;
            s = s[1..$-1];
            continue;
        }
        if (s[1] == s.back) {
            s = s[1..$];
            continue;
        }
        if (s.front == s[$-1]) {
            s = s[0..$-1];
            continue;
        }
        s = s[1..$-1];
        continue;
    }
    writeln(l ~ r.dup.reverse);
    return 0;
}
/* IMPORT /home/yosupo/Programs/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 /home/yosupo/Programs/dunkelheit/source/dkh/container/deque.d */
// module dkh.container.deque;

struct DequePayload(T) {
    import core.exception : RangeError;

    private T* _data;
    private uint start, len, cap;

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

    ref inout(T) opIndex(size_t i) inout {
        version(assert) if (len <= i) throw new RangeError();
        if (start + i < cap) return _data[start + i];
        else return _data[start + i - cap];
    }
    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 std.algorithm : max;
        import std.conv : to;
        if (newCap <= cap) return;
        T* newData = cast(T*)GC.malloc(newCap * T.sizeof);
        foreach (i; 0..length) {
            newData[i] = this[i];
        }
        _data = newData; start = 0; cap = newCap.to!uint;
    }
    void clear() {
        start = len = 0;
    }
    import std.algorithm : max;
    void insertFront(T item) {
        if (len == cap) reserve(max(cap * 2, 4));
        if (start == 0) start += cap;
        start--; len++;
        this[0] = item;
    }
    void insertBack(T item) {
        if (len == cap) reserve(max(cap * 2, 4));
        len++;
        this[len-1] = item;
    }
    void removeFront() {
        assert(!empty, "Deque.removeFront: Deque is empty");
        start++; len--;
        if (start == cap) start = 0;
    }
    void removeBack() {
        assert(!empty, "Deque.removeBack: Deque is empty");
        len--;
    }
}

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

    alias Payload = DequePayload!T;
    Payload* _p;

    static if (!mayNull) @disable this();

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

    this(Range)(Range r)
    if (isInputRange!Range &&
    isImplicitlyConvertible!(ElementType!Range, T) &&
    !is(Range == T[])) {
        _p = new Payload();
        foreach (v; r) {
            insertBack(v);
        }
    }
    private this(Payload* p) { _p = p; }
    static Deque make() { return Deque(new Payload()); }

    private bool havePayload() const { return (!mayNull || _p); }
    @property bool empty() const { return (!havePayload || _p.empty); }
    @property size_t length() const { return (havePayload ? _p.length : 0); }
    alias opDollar = length;

    ref inout(T) opIndex(size_t i) inout {
        assert(!empty, "Deque.opIndex: Deque is empty");
        return (*_p)[i];
    }
    ref inout(T) front() inout { return this[0]; }
    ref inout(T) back() inout { return this[$-1]; }

    void clear() { if (_p) _p.clear(); }

    void insertFront(T item) {
        if (mayNull && !_p) _p = new Payload();
        _p.insertFront(item);
    }
    void insertBack(T item) {
        if (mayNull && !_p) _p = new Payload();
        _p.insertBack(item);
    }
    alias opOpAssign(string op : "~") = insertBack;
    alias stableInsertBack = insertBack;

    void removeFront() {
        assert(!mayNull || _p, "Deque.removeFront: Deque is empty");
        _p.removeFront();
    }
    void removeBack() {
        assert(!mayNull || _p, "Deque.removeBack: Deque is empty");
        _p.removeBack();
    }
    alias stableRemoveBack = removeBack;

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

    size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) const {
        assert(start <= end && end <= length);
        return [start, end];
    }
    Range opIndex(size_t[2] rng) { return Range(_p, rng[0], rng[1]); }
    ConstRange opIndex(size_t[2] rng) const { return ConstRange(_p, rng[0], rng[1]); }
    ImmutableRange opIndex(size_t[2] rng) immutable { return ImmutableRange(_p, rng[0], rng[1]); }
    auto opIndex() inout { return this[0..$]; }

    static struct RangeT(QualifiedPayload) {
        alias A = QualifiedPayload;
        import std.traits : CopyTypeQualifiers;
        alias E = CopyTypeQualifiers!(A, T);
        A *p;
        size_t l, r;

        @property bool empty() const { return r <= l; }
        @property size_t length() const { return r - l; }
        alias opDollar = length;

        @property auto save() { return this; }

        ref inout(E) opIndex(size_t i) inout {
            version(assert) if (empty) throw new RangeError();
            return (*p)[l+i];
        }
        @property ref inout(E) front() inout { return this[0]; }
        @property ref inout(E) back() inout { return this[$-1]; }

        void popFront() {
            version(assert) if (empty) throw new RangeError();
            l++;
        }
        void popBack() {
            version(assert) if (empty) throw new RangeError();
            r--;
        }

        size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) const {
            assert(start <= end && end <= length);
            return [start, end];
        }
        auto opIndex(size_t[2] rng) { return RangeT(p, l+rng[0], l+rng[1]); }
        auto opIndex(size_t[2] rng) const { return RangeT!(const A)(p, l+rng[0], l+rng[1]); }
        auto opIndex(size_t[2] rng) immutable { return RangeT!(immutable A)(p, l+rng[0], l+rng[1]); }
        auto opIndex() inout { return this[0..$]; }
    }
}

/* IMPORT /home/yosupo/Programs/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 /home/yosupo/Programs/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;
    private File f;

    this(File f) {
        this.f = f;
    }
    private char[512] lineBuf;
    private 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) {
                    assert(succW());
                    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(Args...)(auto ref Args args) {
        import std.exception : enforce;
        static if (args.length != 0) {
            enforce(readSingle(args[0]));
            read(args[1..$]);
        }
    }

    bool hasNext() {
        return succ();
    }
}

/*
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)
*/

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.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    auto s = readln.chomp;
    if (s.length < 4) {
        writeln(s[0]);
        return;
    }

    dchar[] ans;
    foreach (i; (s.length/2 - 1).iota.stride(2)) {
        dchar c = 'a';
        while ((s[i] != c && s[i+1] != c)
               || (s[s.length - 1 - i] != c && s[s.length - 1 - i - 1] != c)) {
            c += 1;
        }
        ans ~= c;
    }

    auto tail = ans.dup;
    tail.reverse();

    if (s.length % 4 != 0) { ans ~= s[s.length/2]; }

    ans = ans.chain(tail).array;

    ans.writeln;
}

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

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

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

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

string S;
int N;

void main() {
  try {
    for (; ; ) {
      S = readToken();
      N = cast(int)(S.length);

      char[] ansL, ansM;
      for (int l = 0, r = N; l < r; ) {
        if (l + 4 <= r) {
          bool found;
          foreach (d; "abc") {
            if ((S[l] == d || S[l + 1] == d) && (S[r - 2] == d || S[r - 1] == d)) {
              found = true;
              ansL ~= d;
              break;
            }
          }
          assert(found);
          l += 2;
          r -= 2;
        } else {
          ansM ~= S[l];
          break;
        }
      }
      write(ansL.to!string);
      write(ansM.to!string);
      ansL.reverse;
      write(ansL.to!string);
      writeln();
    }
  } catch (EOFException e) {
  }
}

/+ dub.sdl:
    name "E"
    dependency "dunkelheit" version="1.0.1"
+/

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

int main() {
    Scanner sc = new Scanner(stdin);
    scope(exit) assert(!sc.hasNext);

    string s;
    sc.read(s);

    string l, r;
    while (s.length) {
        if (s.length == 1) {
            l ~= s;
            break;
        }
        if (s.front == s.back) {
            l ~= s.front;
            r ~= s.back;
            s = s[1..$-1];
            continue;
        }
        if (s[1] == s.back) {
            s = s[1..$];
            continue;
        }
        if (s.front == s[$-1]) {
            s = s[0..$-1];
            continue;
        }
        s = s[1..$-1];
        continue;
    }
    r.dup.reverse;
    writeln(l ~ r);
    return 0;
}
/* IMPORT /home/yosupo/Programs/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 /home/yosupo/Programs/dunkelheit/source/dkh/container/deque.d */
// module dkh.container.deque;

struct DequePayload(T) {
    import core.exception : RangeError;

    private T* _data;
    private uint start, len, cap;

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

    ref inout(T) opIndex(size_t i) inout {
        version(assert) if (len <= i) throw new RangeError();
        if (start + i < cap) return _data[start + i];
        else return _data[start + i - cap];
    }
    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 std.algorithm : max;
        import std.conv : to;
        if (newCap <= cap) return;
        T* newData = cast(T*)GC.malloc(newCap * T.sizeof);
        foreach (i; 0..length) {
            newData[i] = this[i];
        }
        _data = newData; start = 0; cap = newCap.to!uint;
    }
    void clear() {
        start = len = 0;
    }
    import std.algorithm : max;
    void insertFront(T item) {
        if (len == cap) reserve(max(cap * 2, 4));
        if (start == 0) start += cap;
        start--; len++;
        this[0] = item;
    }
    void insertBack(T item) {
        if (len == cap) reserve(max(cap * 2, 4));
        len++;
        this[len-1] = item;
    }
    void removeFront() {
        assert(!empty, "Deque.removeFront: Deque is empty");
        start++; len--;
        if (start == cap) start = 0;
    }
    void removeBack() {
        assert(!empty, "Deque.removeBack: Deque is empty");
        len--;
    }
}

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

    alias Payload = DequePayload!T;
    Payload* _p;

    static if (!mayNull) @disable this();

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

    this(Range)(Range r)
    if (isInputRange!Range &&
    isImplicitlyConvertible!(ElementType!Range, T) &&
    !is(Range == T[])) {
        _p = new Payload();
        foreach (v; r) {
            insertBack(v);
        }
    }
    private this(Payload* p) { _p = p; }
    static Deque make() { return Deque(new Payload()); }

    private bool havePayload() const { return (!mayNull || _p); }
    @property bool empty() const { return (!havePayload || _p.empty); }
    @property size_t length() const { return (havePayload ? _p.length : 0); }
    alias opDollar = length;

    ref inout(T) opIndex(size_t i) inout {
        assert(!empty, "Deque.opIndex: Deque is empty");
        return (*_p)[i];
    }
    ref inout(T) front() inout { return this[0]; }
    ref inout(T) back() inout { return this[$-1]; }

    void clear() { if (_p) _p.clear(); }

    void insertFront(T item) {
        if (mayNull && !_p) _p = new Payload();
        _p.insertFront(item);
    }
    void insertBack(T item) {
        if (mayNull && !_p) _p = new Payload();
        _p.insertBack(item);
    }
    alias opOpAssign(string op : "~") = insertBack;
    alias stableInsertBack = insertBack;

    void removeFront() {
        assert(!mayNull || _p, "Deque.removeFront: Deque is empty");
        _p.removeFront();
    }
    void removeBack() {
        assert(!mayNull || _p, "Deque.removeBack: Deque is empty");
        _p.removeBack();
    }
    alias stableRemoveBack = removeBack;

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

    size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) const {
        assert(start <= end && end <= length);
        return [start, end];
    }
    Range opIndex(size_t[2] rng) { return Range(_p, rng[0], rng[1]); }
    ConstRange opIndex(size_t[2] rng) const { return ConstRange(_p, rng[0], rng[1]); }
    ImmutableRange opIndex(size_t[2] rng) immutable { return ImmutableRange(_p, rng[0], rng[1]); }
    auto opIndex() inout { return this[0..$]; }

    static struct RangeT(QualifiedPayload) {
        alias A = QualifiedPayload;
        import std.traits : CopyTypeQualifiers;
        alias E = CopyTypeQualifiers!(A, T);
        A *p;
        size_t l, r;

        @property bool empty() const { return r <= l; }
        @property size_t length() const { return r - l; }
        alias opDollar = length;

        @property auto save() { return this; }

        ref inout(E) opIndex(size_t i) inout {
            version(assert) if (empty) throw new RangeError();
            return (*p)[l+i];
        }
        @property ref inout(E) front() inout { return this[0]; }
        @property ref inout(E) back() inout { return this[$-1]; }

        void popFront() {
            version(assert) if (empty) throw new RangeError();
            l++;
        }
        void popBack() {
            version(assert) if (empty) throw new RangeError();
            r--;
        }

        size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) const {
            assert(start <= end && end <= length);
            return [start, end];
        }
        auto opIndex(size_t[2] rng) { return RangeT(p, l+rng[0], l+rng[1]); }
        auto opIndex(size_t[2] rng) const { return RangeT!(const A)(p, l+rng[0], l+rng[1]); }
        auto opIndex(size_t[2] rng) immutable { return RangeT!(immutable A)(p, l+rng[0], l+rng[1]); }
        auto opIndex() inout { return this[0..$]; }
    }
}

/* IMPORT /home/yosupo/Programs/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 /home/yosupo/Programs/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;
    private File f;

    this(File f) {
        this.f = f;
    }
    private char[512] lineBuf;
    private 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) {
                    assert(succW());
                    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(Args...)(auto ref Args args) {
        import std.exception : enforce;
        static if (args.length != 0) {
            enforce(readSingle(args[0]));
            read(args[1..$]);
        }
    }

    bool hasNext() {
        return succ();
    }
}

/*
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)
*/

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

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

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

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

string S;
int N;

void main() {
  try {
    for (; ; ) {
      S = readToken();
      N = cast(int)(S.length);

      string ans;
      foreach (d; "abc") {
        string t;
        foreach (e; S) {
          if (e != d) {
            t ~= e;
          }
        }
        t = t.uniq.array.to!string;
        if (!t.empty) {
          if (t.length % 2 == 0) {
            t = t[0 .. $ - 1];
          }
          if (ans.length < t.length) {
            ans = t;
          }
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

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

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

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

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

string S;
int N;

void main() {
  try {
    for (; ; ) {
      S = readToken();
      N = cast(int)(S.length);

      char[] ansL, ansM;
      for (int l = 0, r = N; l <= r; ) {
        if (l + 4 <= r) {
          bool found;
          foreach (d; "abc") {
            if ((S[l] == d || S[l + 1] == d) && (S[r - 2] == d || S[r - 1] == d)) {
              found = true;
              ansL ~= d;
              break;
            }
          }
if(!found)writeln(l," ",r);
          assert(found);
          l += 2;
          r -= 2;
        } else {
          ansM ~= S[l];
          break;
        }
      }
      write(ansL.to!string);
      write(ansM.to!string);
      ansL.reverse;
      write(ansL.to!string);
      writeln();
    }
  } catch (EOFException e) {
  }
}


Let's define $$$f(x)$$$ for a positive integer $$$x$$$ as the length of the base-10 representation of $$$x$$$ without leading zeros. I like to call it a digital logarithm. Similar to a digital root, if you are familiar with that.You are given two arrays $$$a$$$ and $$$b$$$, each containing $$$n$$$ positive integers. In one operation, you do the following:   pick some integer $$$i$$$ from $$$1$$$ to $$$n$$$;  assign either $$$f(a_i)$$$ to $$$a_i$$$ or $$$f(b_i)$$$ to $$$b_i$$$. Two arrays are considered similar to each other if you can rearrange the elements in both of them, so that they are equal (e. g. $$$a_i = b_i$$$ for all $$$i$$$ from $$$1$$$ to $$$n$$$).What's the smallest number of operations required to make $$$a$$$ and $$$b$$$ similar to each other?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of the testcase contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in each of the arrays. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i < 10^9$$$). The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_j < 10^9$$$). The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print the smallest number of operations required to make $$$a$$$ and $$$b$$$ similar to each other.

NoteIn the first testcase, you can apply the digital logarithm to $$$b_1$$$ twice.In the second testcase, the arrays are already similar to each other.In the third testcase, you can first apply the digital logarithm to $$$a_1$$$, then to $$$b_2$$$.

import std;

int t;
uint n;

void main()
{
    scanf("%d\n", &t);
    foreach(_; 0..t)
    {
        scanf("%ud\n", &n);
        long result;
        long tmp;
        long[] a = new long[n];
        long[] b = new long[n];
        foreach(id; 0 .. n){
            scanf("%lld", &tmp);
            getchar();
            a[id] = tmp;
        }
        foreach(id; 0 .. n){
            scanf("%lld", &tmp);
            getchar();
            b[id] = tmp;
        }

        a.sort!("a < b");
        b.sort!("a < b");

        auto diffA = setDifference(a, b).array;
        auto diffB = setDifference(b, a).array;
        if (diffA.length == 0) {
            writeln(0);
            continue;
        }
        foreach(ref e; diffA) {
            long l = cast(long) to!string(e).length;
            if (l > 1) {
                e = l;
                result++;
            }
        }
        foreach(ref e; diffB) {
            long l = cast(long) to!string(e).length;
            if (l > 1) {
                e = l;
                result++;
            }
        }
        auto diff2 = setSymmetricDifference(sort(diffA), sort(diffB)).array;
        auto r = diff2.filter!(a => a > 1).array;
        result += r.length;

        writeln(result);
    }

}