Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School.In his favorite math class, the teacher taught him the following interesting definitions.A parenthesis sequence is a string, containing only characters "(" and ")".A correct parenthesis sequence is a parenthesis sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, parenthesis sequences "()()", "(())" are correct (the resulting expressions are: "(1+1)+(1+1)", "((1+1)+1)"), while ")(" and ")" are not. Note that the empty string is a correct parenthesis sequence by definition.We define that $$$|s|$$$ as the length of string $$$s$$$. A strict prefix $$$s[1\dots l]$$$ $$$(1\leq l< |s|)$$$ of a string $$$s = s_1s_2\dots s_{|s|}$$$ is string $$$s_1s_2\dots s_l$$$. Note that the empty string and the whole string are not strict prefixes of any string by the definition.Having learned these definitions, he comes up with a new problem. He writes down a string $$$s$$$ containing only characters "(", ")" and "?". And what he is going to do, is to replace each of the "?" in $$$s$$$ independently by one of "(" and ")" to make all strict prefixes of the new sequence not a correct parenthesis sequence, while the new sequence should be a correct parenthesis sequence.After all, he is just a primary school student so this problem is too hard for him to solve. As his best friend, can you help him to replace the question marks? If there are many solutions, any of them is acceptable.

The first line contains a single integer $$$|s|$$$ ($$$1\leq |s|\leq 3 \cdot 10^5$$$), the length of the string. The second line contains a string $$$s$$$, containing only "(", ")" and "?".

A single line contains a string representing the answer. If there are many solutions, any of them is acceptable. If there is no answer, print a single line containing ":(" (without the quotes).

NoteIt can be proved that there is no solution for the second sample, so print ":(".

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

void main() {
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;

    if (N % 2 == 1) {
        ":(".writeln;
        return;
    }

    int open = N / 2 - S.map!(s => s == '(').sum;
    int tmp = 0;

    dchar[] ans;

    foreach (i; 0..N) {
        if (S[i] == '(') {
            tmp += 1;
            ans ~= '(';
        } else if (S[i] == ')') {
            tmp -= 1;
            ans ~= ')';
        } else if (open > 0) {
            tmp += 1;
            open -= 1;
            ans ~= '(';
        } else {
            tmp -= 1;
            ans ~= ')';
        }
        if (i != N - 1 && tmp <= 0) {
            ":(".writeln;
            return;
        } else if (i == N - 1 && tmp != 0) {
            ":(".writeln;
            return;
        }
    }

    ans.writeln;
}

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional, std.meta;
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.ascii, std.typecons;

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

    auto s = readln.chomp;

    if (n % 2 != 0) {
        writeln(":(");
        return;
    }

    int open = n / 2 - s.count!(x => x == '(').to!int;
    int v = 0;
    string ans;
    foreach (i, e; s) {
        dchar nxt = e;
        if (e == '?') {
            if (open > 0) {
                nxt = '(';
                --open;
            } else {
                nxt = ')';
            }
        }

        ans ~= nxt;

        if (nxt == '(') { ++v; }
        else { --v; }

        if (v < 0 || (v == 0 && i < n-1)) {
            writeln(":(");
            return;
        }
    }

    if (v != 0) {
        writeln(":(");
        return;
    }

    writeln(ans);
}

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

immutable string NO = ":(";

string solve (int n, string s)
{
	if (n & 1)
	{
		return NO;
	}
	auto a = n / 2 - s.count ('(').to !(int);
	auto b = n / 2 - s.count (')').to !(int);
	if (a < 0 || b < 0)
	{
		return NO;
	}
	auto t = s.dup;
	foreach (ref c; t)
	{
		if (c == '?')
		{
			if (a > 0)
			{
				c = '(';
				a -= 1;
			}
			else
			{
				c = ')';
				b -= 1;
			}
		}
	}

	int balance = 0;
	foreach (ref c; t[0..$ - 1])
	{
		balance += (c == '(') ? +1 : -1;
		if (balance <= 0)
		{
			return NO;
		}
	}

	return t.idup;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto s = readln.strip;
		writeln (solve (n, s));
	}
}

import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

const long mod = 1_000_000_007;

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}

	int n = read.to!int;
	char[] cs = readln.chomp.to!(char[]);

	if(n % 2 > 0){ // this matters only for n = 1
		writeln(":(");
		return;
	}

	if(cs[0] == ')' || cs[$ - 1] == '('){
		writeln(":(");
		return;
	}

	auto cntleft = cs.count!(x => x == '(');
	auto cntright = cs.count!(x => x == ')');
	if( cntleft > n / 2 || cntright > n / 2){
		writeln(":(");
		return;
	}

	auto lackleft = n / 2 - cntleft;
	auto lackright = n / 2 - cntright;
	foreach(i; 0 .. n){
		if(cs[i] == '?') lackleft -= 1, cs[i] = '(';
		if(lackleft == 0) break;
	}
	foreach_reverse(i; 0 .. n){
		if(cs[i] == '?') lackright -= 1, cs[i] = ')';
		if(lackright == 0) break;
	}

	int depth = 0;
	foreach(i; 0 .. n){
		if(cs[i] == '(') depth += 1;
		else depth -= 1;
		if(i < n - 1 && depth == 0){
			writeln(":(");
			return;
		}
	}

	cs.to!string.writeln;
}

/*

- Fail if n is odd
- Fail if the leftmost is )
- Fail if the rightmost is (
- Fail if there are too many (s
- Fail if there are too many )s
~ Otherwise, try this:
  - Fill with ( from the left end until (s are enough
  - Fill with ) from the right end until )s are enough
- If the result is valid, it is valid
- Otherwise, it is failure

*/

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional, std.meta;
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.ascii, std.typecons;

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

    auto s = readln.chomp;

    if (n % 2 != 0) {
        writeln(":(");
        return;
    }

    int open = n / 2 - s.count!(x => x == '(').to!int;
    int v = 0;
    string ans;
    foreach (i, e; s) {
        dchar nxt = e;
        if (e == '?') {
            if (open > 0) {
                nxt = '(';
                --open;
            } else {
                nxt = ')';
            }
        }

        ans ~= nxt;

        if (nxt == '(') { ++v; }
        else { --v; }

        if (v < 0 || (v == 0 && i < n-1)) {
            writeln(":(");
            return;
        }
    }

    writeln(ans);
}

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

immutable string NO = ":(";

string solve (int n, string s)
{
	if (n & 1)
	{
		return NO;
	}
	auto a = n / 2 - s.count ('(');
	auto b = n / 2 - s.count (')');
	if (a < 0 || b < 0)
	{
		return NO;
	}
	auto t = s.dup;
	foreach (ref c; t)
	{
		if (c == '?')
		{
			if (a > 0)
			{
				c = '(';
				a -= 1;
			}
			else
			{
				c = ')';
				b -= 1;
			}
		}
	}

	int balance = 0;
	foreach (ref c; t[0..$ - 1])
	{
		balance += (c == '(') ? +1 : -1;
		if (balance == 0)
		{
			return NO;
		}
	}

	return t.idup;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto s = readln.strip;
		writeln (solve (n, s));
	}
}

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

immutable string NO = ":(";

string solve (int n, string s)
{
	if (n & 1)
	{
		return NO;
	}
	auto a = n / 2 - s.count ('(');
	auto b = n / 2 - s.count (')');
	if (a < 0 || b < 0)
	{
		return NO;
	}
	auto t = s.dup;
	foreach (ref c; t)
	{
		if (c == '?')
		{
			if (a > 0)
			{
				c = '(';
				a -= 1;
			}
			else
			{
				c = ')';
				b -= 1;
			}
		}
	}

	int balance = 0;
	foreach (ref c; t[0..$ - 1])
	{
		balance += (c == '(') ? +1 : -1;
		if (balance <= 0)
		{
			return NO;
		}
	}

	return t.idup;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto s = readln.strip;
		writeln (solve (n, s));
	}
}

import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

const long mod = 1_000_000_007;

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}

	int n = read.to!int;
	char[] cs = readln.chomp.to!(char[]);

	if(cs[0] == ')' || cs[$ - 1] == '('){
		writeln(":(");
		return;
	}

	auto cntleft = cs.count!(x => x == '(');
	auto cntright = cs.count!(x => x == ')');
	if( cntleft > n / 2 || cntright > n / 2){
		writeln(":(");
		return;
	}

	auto lackleft = n / 2 - cntleft;
	auto lackright = n / 2 - cntright;
	foreach(i; 0 .. n){
		if(cs[i] == '?') lackleft -= 1, cs[i] = '(';
		if(lackleft == 0) break;
	}
	foreach_reverse(i; 0 .. n){
		if(cs[i] == '?') lackright -= 1, cs[i] = ')';
		if(lackright == 0) break;
	}

	int depth = 0;
	foreach(i; 0 .. n){
		if(cs[i] == '(') depth += 1;
		else depth -= 1;
		if(i < n - 1 && depth == 0){
			writeln(":(");
			return;
		}
	}

	cs.to!string.writeln;
}

/*

- Fail if the leftmost is )
- Fail if the rightmost is (
- Fail if there are too many (s
- Fail if there are too many )s
~ Otherwise, try this:
  - Fill with ( from the left end until (s are enough
  - Fill with ) from the right end until )s are enough
- If the result is valid, it is valid
- Otherwise, it is failure

*/


You have a sequence $$$a$$$ with $$$n$$$ elements $$$1, 2, 3, \dots, k - 1, k, k - 1, k - 2, \dots, k - (n - k)$$$ ($$$k \le n < 2k$$$).Let's call as inversion in $$$a$$$ a pair of indices $$$i < j$$$ such that $$$a[i] > a[j]$$$.Suppose, you have some permutation $$$p$$$ of size $$$k$$$ and you build a sequence $$$b$$$ of size $$$n$$$ in the following manner: $$$b[i] = p[a[i]]$$$.Your goal is to find such permutation $$$p$$$ that the total number of inversions in $$$b$$$ doesn't exceed the total number of inversions in $$$a$$$, and $$$b$$$ is lexicographically maximum.Small reminder: the sequence of $$$k$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$k$$$ exactly once.Another small reminder: a sequence $$$s$$$ is lexicographically smaller than another sequence $$$t$$$, if either $$$s$$$ is a prefix of $$$t$$$, or for the first $$$i$$$ such that $$$s_i \ne t_i$$$, $$$s_i < t_i$$$ holds (in the first position that these sequences are different, $$$s$$$ has smaller number than $$$t$$$).

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first and only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$k \le n < 2k$$$; $$$1 \le k \le 10^5$$$) — the length of the sequence $$$a$$$ and its maximum. It's guaranteed that the total sum of $$$k$$$ over test cases doesn't exceed $$$10^5$$$.

For each test case, print $$$k$$$ integers — the permutation $$$p$$$ which maximizes $$$b$$$ lexicographically without increasing the total number of inversions. It can be proven that $$$p$$$ exists and is unique.

NoteIn the first test case, the sequence $$$a = [1]$$$, there is only one permutation $$$p = [1]$$$.In the second test case, the sequence $$$a = [1, 2]$$$. There is no inversion in $$$a$$$, so there is only one permutation $$$p = [1, 2]$$$ which doesn't increase the number of inversions.In the third test case, $$$a = [1, 2, 1]$$$ and has $$$1$$$ inversion. If we use $$$p = [2, 1]$$$, then $$$b = [p[a[1]], p[a[2]], p[a[3]]] = [2, 1, 2]$$$ and also has $$$1$$$ inversion.In the fourth test case, $$$a = [1, 2, 3, 2]$$$, and since $$$p = [1, 3, 2]$$$ then $$$b = [1, 3, 2, 3]$$$. Both $$$a$$$ and $$$b$$$ have $$$1$$$ inversion and $$$b$$$ is the lexicographically maximum.

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

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

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

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

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

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

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

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

void main()
{
    int T; get(T);
    while (T--) {
        int N, K; get(N, K);
        auto res = 1.iota(K + 1).array();
        if (N != K) {
            auto i = K - (N - K) - 1;
            reverse(res[i..$]);
        }
        writefln!"%(%d %)"(res);
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		ans[ti].length = k;
		auto d = n-k;
		foreach (i; 0..k-d)
		{
			ans[ti][i] = i+1;
		}
		foreach (i; k-d-1..k)
		{
			ans[ti][i] = (k-1) - (i-(k-d));
		}
	}

	foreach (e; ans)
	{
		e.map!(to!string).join(" ").writeln;
	}
	stdout.flush;
	debug readln;
}

import std.stdio, std.range, std.algorithm;
void main()
{
    int q;
    readf!"%d\n"(q);
    foreach (_; 0 .. q)
    {
        int n, k;
        readf!"%d %d\n"(n, k);
        int[] p = iota(1, k + 1).array;
        reverse(p[2 * k - n - 1 .. k]);
        p.writefln!"%(%s %)";
    }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		auto p = iota (1, k + 1).array;
		reverse (p[k + k - n - 1..k]);
		writefln !("%(%s %)") (p);
	}
}

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

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

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

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

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

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

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

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

void main()
{
    int T; get(T);
    while (T--) {
        int N, K; get(N, K);
        auto res = 1.iota(K + 1).array();
        if (N != K) swap(res[$-1], res[$-2]);
        writefln!"%(%d %)"(res);
    }
}

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

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

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

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

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

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

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

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

void main()
{
    int T; get(T);
    while (T--) {
        int N, K; get(N, K);
        auto res = 1.iota(K + 1).array();
        if (N > K) {
            auto n = K - (N - K) - 1;
            swap(res[n], res[n + 1]);
        }
        writefln!"%(%d %)"(res);
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		ans[ti].length = k;
		foreach (i; 0..k)
		{
			ans[ti][i] = i+1;
		}
		if (n == k) continue;
		auto d = n-k;
		ans[ti] = ans[ti][0..k-d-1] ~ ans[ti][k-d..$] ~ (k-d);
	}

	foreach (e; ans)
	{
		e.map!(to!string).join(" ").writeln;
	}
	stdout.flush;
	debug readln;
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		ans[ti].length = k;
		foreach (i; 0..k)
		{
			ans[ti][i] = i+1;
		}
		if (n == k) continue;
		swap(ans[ti][$-2], ans[ti][$-1]);
	}

	foreach (e; ans)
	{
		e.map!(to!string).join(" ").writeln;
	}
	stdout.flush;
	debug readln;
}


There are three sticks with integer lengths $$$l_1, l_2$$$ and $$$l_3$$$.You are asked to break exactly one of them into two pieces in such a way that:   both pieces have positive (strictly greater than $$$0$$$) integer length;  the total length of the pieces is equal to the original length of the stick;  it's possible to construct a rectangle from the resulting four sticks such that each stick is used as exactly one of its sides. A square is also considered a rectangle.Determine if it's possible to do that.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The only line of each testcase contains three integers $$$l_1, l_2, l_3$$$ ($$$1 \le l_i \le 10^8$$$) — the lengths of the sticks.

For each testcase, print "YES" if it's possible to break one of the sticks into two pieces with positive integer length in such a way that it's possible to construct a rectangle from the resulting four sticks. Otherwise, print "NO". You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as a positive answer).

NoteIn the first testcase, the first stick can be broken into parts of length $$$1$$$ and $$$5$$$. We can construct a rectangle with opposite sides of length $$$1$$$ and $$$5$$$.In the second testcase, breaking the stick of length $$$2$$$ can only result in sticks of lengths $$$1, 1, 2, 5$$$, which can't be made into a rectangle. Breaking the stick of length $$$5$$$ can produce results $$$2, 3$$$ or $$$1, 4$$$ but neither of them can't be put into a rectangle.In the third testcase, the second stick can be broken into parts of length $$$2$$$ and $$$2$$$. The resulting rectangle has opposite sides $$$2$$$ and $$$2$$$ (which is a square).In the fourth testcase, the third stick can be broken into parts of length $$$2$$$ and $$$2$$$. The resulting rectangle has opposite sides $$$2$$$ and $$$5$$$.

import std.stdio;
import std.array;
import std.conv;
import std.algorithm;

enum MOD = 998244353;

void main()
{
    ulong count = readln.split[0].to!int;
    foreach (line; 0 .. count)
    {
        ulong[3] nums;
        auto nptr = nums.ptr;
        scanf("%lu %lu %lu", nptr, nptr + 1, nptr + 2);
        if (nums.sumCase)
        {
            writeln("yes");

        }
        else if (nums.binCase)
        {
            writeln("yes");
        }
        else
            writeln("NO");

    }
}

auto sumCase(ulong[3] nums)
{
    for (int i = 0; i < 3; i++)
    {
        if (nums[(0 + i) % 3] == nums[(1 + i) % 3] + nums[(2 + i) % 3])
            return true;
    }
    return false;
}

auto binCase(ulong[3] nums)
{
    for (int i = 0; i < 3; i++)
    {
        if (nums[(0 + i) % 3] == nums[(1 + i) % 3] && nums[(2 + i) % 3] % 2 == 0)
            return true;
    }
    return false;
}

import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,
       std.container, std.typecons, std.conv, std.random, std.bigint;

void read(S...)(ref S args) {
  auto input = readln.split;
  enforce(input.length == args.length);
  foreach (i, ref arg; args) {
    arg = input[i].to!(S[i]);
  }
}

auto list(T)() { return readln.split.map!(e => e.to!T).array; }

void main() {
  int n;
  read(n);
  while (n--) {
    int[] arr = list!int();
    sort(arr);
    if (arr[2] == arr[0] + arr[1]) writeln("YES");
    else if (arr[0] == arr[1] && arr[2] % 2 == 0) writeln("YES");
    else if (arr[2] == arr[1] && arr[0] % 2 == 0) writeln("YES");
    else writeln("NO");
  }
}

import std;

void main()
{
    int t;
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        long[] nums = readln.strip.split(" ").to!(long[]);
        nums.sort();
        if (nums[2] - nums[1] == nums[0])
            writeln("YES");
        else if ((nums[0] == nums[1]) && (nums[2] % 2 == 0))
            writeln("YES");
        else if ((nums[1] == nums[2]) && (nums[0] % 2 == 0))
            writeln("YES");
        else
            writeln("NO");
    }
}

void main() { runSolver(); }

void problem() {
  auto QN = scan!long;
  auto Q = scan!long(3 * QN).chunks(3);

  auto solve() {
    bool[] ans;

    foreach(q; Q) {
      bool qa;
      foreach(i; 0..3) {
        const a = q[(i + 0) % 3];
        const b = q[(i + 1) % 3];
        const c = q[(i + 2) % 3];

        if (a > b && (a - b == c)) qa = true;
        if (a > c && (a - c == b)) qa = true;
        if (a % 2 == 0 && b == c) qa = true;
      }

      ans ~= qa;
    }

    return ans.map!(a => a ? "YES" : "NO").array;
  }

  outputForAtCoder(&solve);
}

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

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

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

import std;

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

    foreach (_; 0..t) {
        int[3] l;
        readf("%s %s %s\n", l[0], l[1], l[2]);

        l = sort(l.dup).array;

        if (l[0] + l[1] == l[2])
            writeln("YES");
        else if (l[0] == l[1] && l[2] % 2 == 0)
            writeln("YES");
        else if (l[1] == l[2] && l[0] % 2 == 0)
            writeln("YES");
        else
            writeln("NO");
    }
}
// ""

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

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto a = readln.splitter.map!(to!long).array.sort.array;
    if (a[0] + a[1] == a[2]) {
      writeln("YES");
    } else {
      if ((a[0] == a[1] && a[2] % 2 == 0) ||
          (a[1] == a[2] && a[0] % 2 == 0)) {
        writeln("YES");
      } else {
        writeln("NO");
      }
    }
  }
}


There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them. When the horse reaches a city (including the first one), it goes to one of the cities connected to the current city. But it is a strange horse, it only goes to cities in which they weren't before. In each such city, the horse goes with equal probabilities and it stops when there are no such cities. Let the length of each road be 1. The journey starts in the city 1. What is the expected length (expected value of length) of their journey? You can read about expected (average) value by the link https://en.wikipedia.org/wiki/Expected_value.

The first line contains a single integer n (1 ≤ n ≤ 100000) — number of cities. Then n - 1 lines follow. The i-th line of these lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the cities connected by the i-th road. It is guaranteed that one can reach any city from any other by the roads.

Print a number — the expected length of their journey. The journey starts in the city 1. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

NoteIn the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2.

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

void main() {
    auto N = readln.chomp.to!int;
    auto edges = new int[][](N);
    foreach (i; 0..N-1) {
        auto s = readln.split.map!(to!int);
        edges[s[0] - 1] ~= s[1] - 1;
        edges[s[1] - 1] ~= s[0] - 1;
    }

    if (N == 1) {
        writeln(0);
        return;
    }

    auto dists = new int[](N);
    auto exp = new real[](N);

    void dfs1(int n, int p, int d) {
        dists[n] = d;
        foreach (m; edges[n]) if (m != p) dfs1(m, n, d + 1);
    }

    void dfs2(int n, int p, real e) {
        exp[n] = e;
        int cnt = 0;
        foreach (m; edges[n]) if (m != p) cnt += 1;
        foreach (m; edges[n]) if (m != p) dfs2(m, n, e / cnt);
    }

    dfs1(0, -1, 0);
    dfs2(0, -1, 1);
    real ans = 0;
    foreach (i; 1..N) if (edges[i].length == 1) ans += dists[i] * exp[i];
    writefln("%.9f", ans);
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
import std.stdio, std.string, std.conv, std.algorithm, std.array;

T[] getVals(T)() { return to!(T[])(readln().chomp().split(" ")); }

struct IP { int i; double p; }

void main() {
    int n = getVals!(int)()[0];
    Appender!(int[])[100001] aps;
    for (int i=1;i<n;i++) {
        auto xy = getVals!(int)();
        int x = xy[0], y = xy[1];
        aps[x].put(y);
        aps[y].put(x);
    }
    bool[100001] flags;
    auto temp1 = appender!(IP[])();
    temp1.put(IP(1, 1.0));
    flags[1] = true;
    auto ans = 0.0;
    for (int k = 0; k <= n; k++) {
        auto temp2 = appender!(IP[])();
        foreach (v ; temp1.data) {
            int c = 0;
            foreach (j ; aps[v.i].data) {
                if (flags[j]) { continue; }
                c++;
            }
            if (c == 0) {
                ans += double(k) * v.p;
            } else {
                auto p = v.p / double(c);
                foreach (j ; aps[v.i].data) {
                    if (flags[j]) { continue; }
                    flags[j] = true;
                    temp2.put(IP(j, p));
                }
            }
        }
        if (temp2.data.length == 0) {
            break;
        }
        temp1 = temp2;
    }
    writefln("%.8f", ans);
}

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

void main() {
    auto N = readln.chomp.to!int;
    auto edges = new int[][](N);
    foreach (i; 0..N-1) {
        auto s = readln.split.map!(to!int);
        edges[s[0] - 1] ~= s[1] - 1;
        edges[s[1] - 1] ~= s[0] - 1;
    }

    if (N == 1) {
        writeln(0);
        return;
    }

    long[] dists;

    void dfs(int n, int p, int d) {
        int cnt = 0;
        foreach (m; edges[n]) if (m != p) cnt += 1;
        if (cnt == 0) {
            dists ~= d;
        } else {
            foreach (m; edges[n]) if (m != p) dfs(m, n, d + 1);
        }
    }

    dfs(0, -1, 0);
    writefln("%.9f", 1.0L * dists.sum / dists.length);
}


You are given a tree (connected graph without cycles) consisting of $$$n$$$ vertices. The tree is unrooted — it is just a connected undirected graph without cycles.In one move, you can choose exactly $$$k$$$ leaves (leaf is such a vertex that is connected to only one another vertex) connected to the same vertex and remove them with edges incident to them. I.e. you choose such leaves $$$u_1, u_2, \dots, u_k$$$ that there are edges $$$(u_1, v)$$$, $$$(u_2, v)$$$, $$$\dots$$$, $$$(u_k, v)$$$ and remove these leaves and these edges.Your task is to find the maximum number of moves you can perform if you remove leaves optimally.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$1 \le k < n$$$) — the number of vertices in the tree and the number of leaves you remove in one move, respectively. The next $$$n-1$$$ lines describe edges. The $$$i$$$-th edge is represented as two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n$$$), where $$$x_i$$$ and $$$y_i$$$ are vertices the $$$i$$$-th edge connects. It is guaranteed that the given set of edges forms a tree. It is guaranteed that the sum of $$$n$$$ does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer — the maximum number of moves you can perform if you remove leaves optimally.

NoteThe picture corresponding to the first test case of the example:There you can remove vertices $$$2$$$, $$$5$$$ and $$$3$$$ during the first move and vertices $$$1$$$, $$$7$$$ and $$$4$$$ during the second move.The picture corresponding to the second test case of the example:There you can remove vertices $$$7$$$, $$$8$$$ and $$$9$$$ during the first move, then vertices $$$5$$$, $$$6$$$ and $$$10$$$ during the second move and vertices $$$1$$$, $$$3$$$ and $$$4$$$ during the third move.The picture corresponding to the third test case of the example:There you can remove vertices $$$5$$$ and $$$7$$$ during the first move, then vertices $$$2$$$ and $$$4$$$ during the second move and vertices $$$1$$$ and $$$6$$$ during the third move.

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		auto adj = new bool [int] [n];
		foreach (i; 0..n - 1)
		{
			int u, v;
			readf !(" %s %s") (u, v);
			u -= 1;
			v -= 1;
			adj[u][v] = true;
			adj[v][u] = true;
		}

		auto d1 = new int [n];
		foreach (v; 0..n)
		{
			d1[v] = adj[v].byKey
			    .count !(u => adj[u].length == 1).to !(int);
		}

		auto inQueue = new bool [n];
		int [] q;

		auto addQueue (int v)
		{
			if (!inQueue[v])
			{
				q ~= v;
				inQueue[v] = true;
			}
		}

		foreach (v; 0..n)
		{
			addQueue (v);
		}

		void removeLeaf (int v)
		{
			if (adj[v].length != 1)
			{
				assert (false);
			}
			debug {writeln ("remove ", v + 1);}
			auto p = adj[v].byKey.front;
			addQueue (p);
			d1[v] -= (adj[p].length == 1);
			d1[p] -= (adj[v].length == 1);
			adj[v].remove (p);
			adj[p].remove (v);
			if (adj[p].length == 1)
			{
				auto w = adj[p].byKey.front;
				d1[w] += 1;
				addQueue (w);
			}
		}

		int res = 0;
		while (!q.empty)
		{
			auto v = q.front;
			inQueue[v] = false;
			q.popFront ();
			q.assumeSafeAppend ();
			debug {writeln ("v = ", v + 1);}
			if (d1[v] >= k)
			{
				res += d1[v] / k;
				auto toRemove = d1[v] / k * k;
				auto curList = adj[v].byKey.array;
				foreach (u; curList)
				{
					if (adj[u].length == 1)
					{
						removeLeaf (u);
						toRemove -= 1;
						if (toRemove == 0)
						{
							break;
						}
					}
				}
			}
		}
		writeln (res);
	}
}


You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$:  Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$.  Choose $$$k$$$ distinct array indices $$$1 \le i_1 < i_2 < \ldots < i_k \le n$$$.  Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged.  Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).

For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).

NoteIn the first test case, we can make the following transformation:  Choose $$$k = 2$$$.  Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$.  Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$.  Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.

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

void solve(){
    long n = scan;
    auto a = scanArray!int;
    auto b = scanArray!int;
    auto freqa = new ll[301];
    auto freqb = new ll[301];
    auto cache = new ll[301];
    for(int i = 0; i < n; ++i){
        ++freqa[a[i] + 100];
        ++freqb[b[i] + 100];
    }
    for(int i = 0; i <= 200; ++i){
        ll take = min(freqb[i], cache[i]);
        cache[i] -= take;
        ll left = freqb[i] - take;
        freqa[i] -= left;
        if(freqa[i] < 0){
            writeln("NO");
            return;
        }
        cache[i+1] += freqa[i];
        freqa[i] = 0;
    }
    writeln("YES");
}

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

immutable multi = true;
import std.range;

void solve(int tc)
{
	auto n = readInt!int;
	auto a = ma(n, readInt!int);
	auto b = ma(n, readInt!int);
	sort(a), sort(b);
	while (a.length && b.length)
	{
		auto fa = a.front;
		auto fb = b.front;
		if (fa > fb) return writeln("NO");
		if (fa < fb)
		{
			if (fa != fb - 1) return writeln("NO");
		}
		a.popFront; b.popFront;
	}
	if (a.length || b.length) return writeln("NO");
	return writeln("YES");
}

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

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;
		auto b = readln.splitter.map !(to !(int)).array;
		sort (a);
		sort (b);
		writeln (n.iota.map !(i => b[i] - a[i])
		    .all !(x => 0 <= x && x <= 1) ? "YES" : "NO");
	}
}


You are given a string $$$s$$$. You need to find two non-empty strings $$$a$$$ and $$$b$$$ such that the following conditions are satisfied:  Strings $$$a$$$ and $$$b$$$ are both subsequences of $$$s$$$.  For each index $$$i$$$, character $$$s_i$$$ of string $$$s$$$ must belong to exactly one of strings $$$a$$$ or $$$b$$$.  String $$$a$$$ is lexicographically minimum possible; string $$$b$$$ may be any possible string. Given string $$$s$$$, print any valid $$$a$$$ and $$$b$$$.Reminder:A string $$$a$$$ ($$$b$$$) is a subsequence of a string $$$s$$$ if $$$a$$$ ($$$b$$$) can be obtained from $$$s$$$ by deletion of several (possibly, zero) elements. For example, "dores", "cf", and "for" are subsequences of "codeforces", while "decor" and "fork" are not.A string $$$x$$$ is lexicographically smaller than a string $$$y$$$ if and only if one of the following holds:  $$$x$$$ is a prefix of $$$y$$$, but $$$x \ne y$$$;  in the first position where $$$x$$$ and $$$y$$$ differ, the string $$$x$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$y$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first and only line of each test case contains one string $$$s$$$ ($$$2 \le |s| \le 100$$$ where $$$|s|$$$ means the length of $$$s$$$). String $$$s$$$ consists of lowercase Latin letters.

For each test case, print the strings $$$a$$$ and $$$b$$$ that satisfy the given conditions. If there are multiple answers, print any.

NoteIn the first test case, there are only two choices: either $$$a =$$$ f and $$$b = $$$ c or $$$a = $$$ c and $$$b = $$$ f. And $$$a = $$$c is lexicographically smaller than $$$a = $$$ f.In the second test case, a is the only character in the string.In the third test case, it can be proven that b is the lexicographically smallest subsequence of $$$s$$$. The second string can be of two variants; one of them is given here.

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

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    string s = readln.strip;
    char minch = 'z';
    size_t minidx;
    foreach (i ; 0 .. s.length) {
      if (s[i] <= minch) {
        minch = s[i];
        minidx = i;
      }
    }
    writefln("%c %s", minch, s[0 .. minidx] ~ s[minidx + 1 .. $]);
  }
}

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 string[](t);
	foreach (ti; 0..t)
	{
		auto s = RD!string;

		char c = 'z';
		size_t pos;
		foreach (i, e; s)
		{
			if (e < c)
			{
				pos = i;
				c = e;
			}
		}

		ans[ti] = [c, ' '];
		foreach (i, e; s)
		{
			if (i == pos) continue;
			ans[ti] ~= e;
		}
	}

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


Every year Santa Claus gives gifts to all children. However, each country has its own traditions, and this process takes place in different ways. For example, in Berland you need to solve the New Year's puzzle.Polycarp got the following problem: given a grid strip of size $$$2 \times n$$$, some cells of it are blocked. You need to check if it is possible to tile all free cells using the $$$2 \times 1$$$ and $$$1 \times 2$$$ tiles (dominoes).For example, if $$$n = 5$$$ and the strip looks like this (black cells are blocked):  Then it can be tiled, for example, using two vertical and two horizontal tiles, as in the picture below (different tiles are marked by different colors).  And if $$$n = 3$$$ and the strip looks like this:  It is impossible to tile free cells.Polycarp easily solved this task and received his New Year's gift. Can you solve it?

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case is preceded by an empty line. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^9$$$, $$$1 \le m \le 2 \cdot 10^5$$$) — the length of the strip and the number of blocked cells on it. Each of the next $$$m$$$ lines contains two integers $$$r_i, c_i$$$ ($$$1 \le r_i \le 2, 1 \le c_i \le n$$$) — numbers of rows and columns of blocked cells. It is guaranteed that all blocked cells are different, i.e. $$$(r_i, c_i) \ne (r_j, c_j), i \ne j$$$. It is guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print on a separate line:    "YES", if it is possible to tile all unblocked squares with the $$$2 \times 1$$$ and $$$1 \times 2$$$ tiles;  "NO" otherwise.  You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).

NoteThe first two test cases are explained in the statement.In the third test case the strip looks like this:    It is easy to check that the unblocked squares on it can not be tiled.

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

void solve(){
    auto n = scan!int;
    auto m = scan!int;
    tup[] blocks;
    for(int i = 0; i < m; ++i){
        blocks ~= tup(scan!int - 1, scan!int);
    }
    blocks.sort!((a, b) => b[1] > a[1]);
    blocks ~= tup(0, n+1);
    blocks ~= tup(1, n+1);

    int norm = 0;
    int yprev = 0;
    foreach(ref block; blocks){
        if(block[1] == yprev){
            block[1] -= norm;
            continue;
        }
        int gap = (block[1] - (yprev + 1)) % 2;
        norm += (block[1] - (yprev+1) - gap);
        yprev = block[1];
        block[1] -= norm;
    }
    int len = (n+1) - norm;
    assert(len <= 1_000_000);

    auto table = new int[][](2, len+1);
    foreach(block; blocks){
        table[block[0]][block[1]] = 1;
    }
    table[0][0] = 1;
    table[1][0] = 1;
    show(table);

    for(int k = len-1; k > 0; --k){
        if(!table[0][k] && !table[1][k]){
            /* table[0][k] = 1; */
            /* table[1][k] = 1; */
        }else if(!table[0][k]){
            if(table[0][k-1]){
                writeln("NO");
                return;
            }
            table[0][k-1] = 1;
        }else if(!table[1][k]){
            if(table[1][k-1]){
                writeln("NO");
                return;
            }
            table[1][k-1] = 1;
        }
    }
    writeln("YES");
}

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!(int, int);

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, m;
		readf !(" %s %s") (n, m);
		alias Block = Tuple !(int, q{col}, int, q{row});
		auto b = new Block [m];
		foreach (ref c; b)
		{
			readf !(" %s %s") (c.row, c.col);
			c.row -= 1;
			c.col -= 1;
		}
		sort (b);

		int mask = 0;
		int prev = 0;
		bool ok = true;
		foreach (ref c; b)
		{
			if (prev % 2 != c.col % 2)
			{
				mask = (3 - mask) % 3;
				prev += 1;
			}
			if (prev != c.col)
			{
				mask %= 3;
				prev = c.col;
			}
			if (mask & (1 << c.row))
			{
				ok = false;
			}
			mask |= 1 << c.row;
		}

		ok &= (mask % 3 == 0);
		writeln (ok ? "Yes" : "No");
	}
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		int[int] a;
		foreach (i; 0..m)
		{
			auto r = RD!int;
			auto c = RD!int-1;
			a[c] |= r;
		}
		debug writeln("a:", a);

		auto keys = a.keys.sort;
		auto len = keys.length;
		int ud;
		int eo;
		bool ok = true;
		foreach (key; keys)
		{
			auto v = a[key];
			auto i = key;
			if (ud == 0)
			{
				if (v == 1 || v == 2)
				{
					ud = v;
					eo = i % 2;
				}
			}
			else
			{
				if (v == 3)
				{
					ok = false;
					break;
				}
				if (ud & v)
				{
					if (eo == i % 2)
					{
						ok = false;
						break;
					}
					ud = 0;
				}
				else
				{
					if (eo != i % 2)
					{
						ok = false;
						break;
					}
					ud = 0;
				}
			}
			debug writeln("ud:", ud, " eo:", eo);
		}
		if (ud != 0)
			ok = false;

		ans[ti] = ok;
	}

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

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

void solve(){
    auto n = scan!int;
    auto m = scan!int;
    tup[] blocks;
    for(int i = 0; i < m; ++i){
        blocks ~= tup(scan!int - 1, scan!int);
    }
    blocks.sort!((a, b) => b[1] > a[1]);
    blocks ~= tup(0, n+1);
    blocks ~= tup(1, n+1);

    int norm = 0;
    int yprev = 0;
    foreach(ref block; blocks){
        if(block[1] == yprev){
            block[1] -= norm;
            continue;
        }
        int gap = (block[1] - (yprev + 1)) % 2;
        norm += (block[1] - (yprev+1) - gap);
        yprev = block[1];
        block[1] -= norm;
    }
    int len = (n+1) - norm;
    assert(len <= 1_000_000);

    auto table = new bool[][](2, len+1);
    foreach(block; blocks){
        table[block[0]][block[1]] = 1;
    }
    table[0][0] = 1;
    table[1][0] = 1;

    for(int k = len-1; k > 0; --k){
        if(!table[0][k] && !table[1][k]){
            /* table[0][k] = 1; */
            /* table[1][k] = 1; */
        }else if(!table[0][k]){
            if(table[0][k-1]){
                writeln("NO");
                return;
            }
            table[0][k-1] = 1;
        }else if(!table[1][k]){
            if(table[0][k-1]){
                writeln("NO");
                return;
            }
            table[1][k-1] = 1;
        }
    }
    writeln("YES");
}

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!(int, int);

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

void solve(){
    auto n = scan!int;
    auto m = scan!int;
    tup[] blocks;
    for(int i = 0; i < m; ++i){
        blocks ~= tup(scan!int - 1, scan!int);
    }
    blocks.sort!((a, b) => b[1] > a[1]);
    blocks ~= tup(0, n+1);
    blocks ~= tup(1, n+1);

    int norm = 0;
    int yprev = 0;
    foreach(block; blocks){
        if(block[1] == yprev){
            block[1] -= norm;
            continue;
        }
        int gap = (block[1] - (yprev + 1)) % 2;
        norm += (block[1] - (yprev+1) - gap);
        yprev = block[1];
        block[1] -= norm;
    }
    int len = (n+1) - norm;
    show(len);
    assert(len <= 1_000_000);

    auto table = new bool[][](2, len+1);
    foreach(block; blocks){
        table[block[0]][block[1]] = 1;
    }
    table[0][0] = 1;
    table[1][0] = 1;

    for(int k = len-1; k > 0; --k){
        if(!table[0][k] && !table[1][k]){
            /* table[0][k] = 1; */
            /* table[1][k] = 1; */
        }else if(!table[0][k]){
            if(table[0][k-1]){
                writeln("NO");
                return;
            }
            table[0][k-1] = 1;
        }else if(!table[1][k]){
            if(table[0][k-1]){
                writeln("NO");
                return;
            }
            table[1][k-1] = 1;
        }
    }
    writeln("YES");
}

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!(int, int);