Little X has n distinct integers: p1, p2, ..., pn. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied:  If number x belongs to set A, then number a - x must also belong to set A.  If number x belongs to set B, then number b - x must also belong to set B. Help Little X divide the numbers into two sets or determine that it's impossible.

The first line contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The next line contains n space-separated distinct integers p1, p2, ..., pn (1 ≤ pi ≤ 109).

If there is a way to divide the numbers into two sets, then print "YES" in the first line. Then print n integers: b1, b2, ..., bn (bi equals either 0, or 1), describing the division. If bi equals to 0, then pi belongs to set A, otherwise it belongs to set B. If it's impossible, print "NO" (without the quotes).

NoteIt's OK if all the numbers are in the same set, and the other one is empty.

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

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

//	chmin/chmax
void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(    const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; }
}
auto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

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

int[] solve() {
	int[int] ids;
	foreach (u; 0 .. N) {
		ids[P[u]] = u;
	}
	int[] cs = new int[N];
	cs[] = -1;
	foreach (src; -1 .. N) {
debug{
writeln(src," ",cs);
}
		int[] q;
		if (src == -1) {
			foreach (u; 0 .. N) {
				if (A - P[u] !in ids) {
					if (cs[u] == 0) {
						return null;
					}
					if (cs[u] == -1) {
						cs[u] = 1;
						q ~= u;
					}
				}
				if (B - P[u] !in ids) {
					if (cs[u] == 1) {
						return null;
					}
					if (cs[u] == -1) {
						cs[u] = 0;
						q ~= u;
					}
				}
			}
		} else {
			if (cs[src] != -1) {
				continue;
			}
			cs[src] = 0;
			q ~= src;
		}
		for (; !q.empty; ) {
			const u = q.front;
			q.popFront;
			if (cs[u] == 0) {
				if (A - P[u] in ids) {
					const v = ids[A - P[u]];
					if (cs[v] == 1) {
						return null;
					}
					if (cs[v] == -1) {
						cs[v] = 0;
						q ~= v;
					}
				}
				if (B - P[u] in ids) {
					const v = ids[B - P[u]];
					if (cs[v] == 1) {
						return null;
					}
					if (cs[v] == -1) {
						cs[v] = 0;
						q ~= v;
					}
				}
			} else {
				if (A - P[u] in ids) {
					const v = ids[A - P[u]];
					if (cs[v] == 0) {
						return null;
					}
					if (cs[v] == -1) {
						cs[v] = 1;
						q ~= v;
					}
				}
				if (B - P[u] in ids) {
					const v = ids[B - P[u]];
					if (cs[v] == 0) {
						return null;
					}
					if (cs[v] == -1) {
						cs[v] = 1;
						q ~= v;
					}
				}
			}
		}
	}
	return cs;
}

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

		int[] res = solve;
		if (res is null) {
			writeln("NO");
		} else {
			writeln("YES");
debug{
writeln(res);
}
			foreach (u; 0 .. N) {
				if (u > 0) {
					write(" ");
				}
				write((res[u] == 0) ? 0 : 1);
			}
			writeln;
		}

	}
	} catch (EOFException) {}
}

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

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

//	chmin/chmax
void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(    const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; }
}
auto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

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

int[] solve() {
	int[int] ids;
	foreach (u; 0 .. N) {
		ids[P[u]] = u;
	}
	int[] q;
	int[] cs = new int[N];
	cs[] = -1;
	foreach (u; 0 .. N) {
		if (A - P[u] !in ids) {
			if (cs[u] == 0) {
				return null;
			}
			if (cs[u] == -1) {
				cs[u] = 1;
				q ~= u;
			}
		}
		if (B - P[u] !in ids) {
			if (cs[u] == 1) {
				return null;
			}
			if (cs[u] == -1) {
				cs[u] = 0;
				q ~= u;
			}
		}
	}
	for (; !q.empty; ) {
		const u = q.front;
		q.popFront;
		if (cs[u] == 0) {
			if (A - P[u] in ids) {
				const v = ids[A - P[u]];
				if (cs[v] == 1) {
					return null;
				}
				if (cs[v] == -1) {
					cs[v] = 0;
					q ~= v;
				}
			}
		} else {
			if (B - P[u] in ids) {
				const v = ids[B - P[u]];
				if (cs[v] == 0) {
					return null;
				}
				if (cs[v] == -1) {
					cs[v] = 1;
					q ~= v;
				}
			}
		}
	}
	return cs;
}

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

		int[] res = solve;
		if (res is null) {
			writeln("NO");
		} else {
			writeln("YES");
debug{
writeln(res);
}
			foreach (u; 0 .. N) {
				if (u > 0) {
					write(" ");
				}
				write((res[u] == 0) ? 0 : 1);
			}
			writeln;
		}

	}
	} catch (EOFException) {}
}

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

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

//	chmin/chmax
void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(    const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; }
}
auto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

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

int[] solve() {
	int[int] ids;
	foreach (u; 0 .. N) {
		ids[P[u]] = u;
	}
	int[] ret = new int[N];
	foreach (s; 0 .. 2) {
		int a = A, b = B;
		if (s == 1) {
			swap(a, b);
		}
		foreach (u; 0 .. N) {
			if (b - P[u] !in ids) {
				if (a - P[u] !in ids) {
					return null;
				}
				ret[u] |= 1 << s;
				ret[ids[a - P[u]]] |= 1 << s;
			}
		}
	}
	foreach (u; 0 .. N) {
		if ((ret[u] & 3) == 3) {
			return null;
		}
	}
	return ret;
}

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

		int[] res = solve;
		if (res is null) {
			writeln("NO");
		} else {
			writeln("YES");
debug{
writeln(res);
}
			foreach (u; 0 .. N) {
				if (u > 0) {
					write(" ");
				}
				write((res[u] & 1 << 0) ? 0 : 1);
			}
			writeln;
		}

	}
	} catch (EOFException) {}
}


Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris.There are exactly s blocks in Chris's set, each block has a unique number from 1 to s. Chris's teacher picks a subset of blocks X and keeps it to himself. He will give them back only if Chris can pick such a non-empty subset Y from the remaining blocks, that the equality holds:  "Are you kidding me?", asks Chris.For example, consider a case where s = 8 and Chris's teacher took the blocks with numbers 1, 4 and 5. One way for Chris to choose a set is to pick the blocks with numbers 3 and 6, see figure. Then the required sums would be equal: (1 - 1) + (4 - 1) + (5 - 1) = (8 - 3) + (8 - 6) = 7.  However, now Chris has exactly s = 106 blocks. Given the set X of blocks his teacher chooses, help Chris to find the required set Y!

The first line of input contains a single integer n (1 ≤ n ≤ 5·105), the number of blocks in the set X. The next line contains n distinct space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 106), the numbers of the blocks in X. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.

In the first line of output print a single integer m (1 ≤ m ≤ 106 - n), the number of blocks in the set Y. In the next line output m distinct space-separated integers y1, y2, ..., ym (1 ≤ yi ≤ 106), such that the required equality holds. The sets X and Y should not intersect, i.e. xi ≠ yj for all i, j (1 ≤ i ≤ n; 1 ≤ j ≤ m). It is guaranteed that at least one solution always exists. If there are multiple solutions, output any of them.

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

immutable int MUCH = 10 ^^ 6;

void main ()
{
	int n;
	while (scanf (" %d", &n) > 0)
	{
		auto a = new bool [MUCH];
		foreach (i; 0..n)
		{
			int x;
			scanf (" %d", &x);
			x--;
			a[x] = true;
		}
		int [] res;
		int [] cand;
		int full = 0;
		for (int i = 0; i + i < MUCH; i++)
		{
			int num = a[i] + a[MUCH - i - 1];
			if (num == 0)
			{
				cand ~= i;
			}
			else if (num == 1)
			{
				res ~= a[i] ? (MUCH - i - 1) : i;
			}
			else if (num == 2)
			{
				full++;
			}
		}
		while (full > 0)
		{
			res ~= cand[$ - 1];
			res ~= MUCH - cand[$ - 1] - 1;
			cand = cand[0..$ - 1];
			full--;
		}
		res[] += 1;
		writeln (res.length);
		writefln ("%(%s %)", res);
	}
}


There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote. The voting procedure is rather complicated:   Each of n employees makes a statement. They make statements one by one starting from employees 1 and finishing with employee n. If at the moment when it's time for the i-th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting).  When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote. It's allowed to deny from voting people who already made the statement or people who are only waiting to do so. If someone is denied from voting he no longer participates in the voting till the very end.  When all employees are done with their statements, the procedure repeats: again, each employees starting from 1 and finishing with n who are still eligible to vote make their statements.  The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting. Of course, he votes for the decision suitable for his fraction. You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction). Predict the outcome of the vote.

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of employees.  The next line contains n characters. The i-th character is 'D' if the i-th employee is from depublicans fraction or 'R' if he is from remocrats.

Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win.

NoteConsider one of the voting scenarios for the first sample:   Employee 1 denies employee 5 to vote.  Employee 2 denies employee 3 to vote.  Employee 3 has no right to vote and skips his turn (he was denied by employee 2).  Employee 4 denies employee 2 to vote.  Employee 5 has no right to vote and skips his turn (he was denied by employee 1).  Employee 1 denies employee 4.  Only employee 1 now has the right to vote so the voting ends with the victory of depublicans.

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

void main() {
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;
    auto D = S.map!(c => c == 'D').sum;
    auto R = N - D;
    auto dead = new bool[](N);

    int can_kill_D, can_kill_R;

    while (D > 0 && R > 0) {
        foreach (i, c; enumerate(S)) {
            if (dead[i])
                continue;
            if (c == 'D' && can_kill_D > 0) {
                D--;
                can_kill_D--;
                dead[i] = true;
            }
            else if (c == 'D') {
                can_kill_R++;
            }
            else if (c == 'R' && can_kill_R > 0) {
                R--;
                can_kill_R--;
                dead[i] = true;
            }
            else if (c == 'R') {
                can_kill_D++;
            }
        }
    }

    writeln(D > 0 ? "D" : "R");

}

import core.bitop;
import core.checkedint;
import core.simd;
import core.stdc.stdlib;
import core.stdc.string;
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.bitmanip;
import std.complex;
import std.container;
import std.conv;
import std.datetime;
import std.format;
import std.functional;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.regex;
import std.stdio;
import std.string;
import std.typecons;
import std.variant;

__gshared:

bool read(T...)(T ptrs) if (ptrs.length > 0) {
    return readf(' ' ~ replicate("%s ", ptrs.length), ptrs) == ptrs.length;
}

T[ ] allocate(T)(size_t n) {
    return (cast(T*)malloc(n * T.sizeof))[0 .. n];
}

auto pairwise(R)(R range) if (isForwardRange!R) {
    return lockstep(range, dropOne(range));
}

int n;
char[200_001][2] s;

void main() {
    while (read(&n)) {
        auto s2 = s[0][ ];
        readln(s2);
        int cur = 0;
        int dcount, rcount;
        int delta = 0;
        do {
            int nextN = 0;
            dcount = rcount = 0;
            foreach (i; 0 .. n)
                if (s[cur][i] == 'D') {
                    if (delta++ >= 0) {
                        s[!cur][nextN++] = 'D';
                        dcount++;
                    }
                } else
                    if (delta-- <= 0) {
                        s[!cur][nextN++] = 'R';
                        rcount++;
                    }
            cur = !cur;
            n = nextN;
        } while (dcount && rcount);
        if (dcount)
            write("D\n");
        else
            write("R\n");
    }
}


One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.You are given an integer n no less than 12, express it as a sum of two composite numbers.

The only line contains an integer n (12 ≤ n ≤ 106).

Output two composite integers x and y (1 < x, y < n) such that x + y = n. If there are multiple solutions, you can output any of them.

NoteIn the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.

import std.stdio;
import std.string;
import std.algorithm;
import core.stdc.stdio;
import std.bigint;
import std.format;
import std.math;

string readline()
{
	string result = readln();
	if (result[result.length - 1] == '\n') result.length--;
	return result;
}

bool isPrime(long x)
{
	foreach (long i; 2..(x/2 + 1))
	{
		if (x % i == 0)
			return false;
	}
	return true;
}

int main(string[] argv)
{
	long n;
	scanf("%d", &n);
	long x, y;
	x = n / 2;
	y = n / 2;
	if (x + y != n) y++;
	foreach (long i; 0..x)
	{
		if (!isPrime(x - i) && !isPrime(y + i))
		{
			printf("%d ", x - i);
			printf("%d", y + i);
			return 0;
		}
	}
	return 0;
}

import std.stdio;

bool is_prime (int n)
{
	for (int i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			return false;
		}
	}
	return true;
}

void main ()
{
	int n;
main_loop:
	while (readf (" %s", &n) > 0)
	{
		for (int k = 4; k <= n - 4; k++)
		{
			if (!is_prime (k) && !is_prime (n - k))
			{
				writeln (k, ' ', n - k);
				continue main_loop;
			}
		}
		assert (false);
	}
}

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

int main()
{
	debug
	{
		freopen(".input","r",stdin);
		freopen(".output","w",stdout);
	}

	//int n = to!(int)(readln()[0..$-1]);
	int n;
	readf("%s",&n);

	for(int i=4;i<=n-4;i++)
	{
		bool nt = false;

		for(int j=2;j<i/2;j++)
		{
			if(i % j == 0)
			{
				for(int k=2;k<n-i;k++)
				{
					if((n-i) % k == 0)
					{
						nt = true;
						break;
					}
				}

				if(nt)
					break;
			}
		}

		if(nt)
		{
			writeln(to!(string)(i) ~ " " ~ to!(string)(n-i));
			break;
		}
	}

	return 0;
}

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

int main()
{
    debug
    {
        freopen(".input","r",stdin);
        freopen(".output","w",stdout);
    }

    int n = to!(int)(readln()[0..$-1]);

    for(int i=4;i<=n-4;i++)
    {
        bool nt = false;

        for(int j=2;j<i/2;j++)
        {
            if(i % j == 0)
            {
                for(int k=2;k<n-i;k++)
                {
                    if((n-i) % k == 0)
                    {
                        nt = true;
                        break;
                    }
                }

                if(nt)
                    break;
            }
        }

        if(nt)
        {
            writeln(to!(string)(i) ~ " " ~ to!(string)(n-i));
            break;
        }
    }

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

int N;

void main(string[] args) {
	try {
	for (; ; ) {
		N = readInt;

		bool[] isnp = new bool[N + 1];
		foreach (i; 2 .. isnp.length) if (!isnp[i]) for (int j = i * i; j < isnp.length; j += i) isnp[j] = true;

		for (int x = 2; x <= N - 2; ++x) {
			const y = N - x;
			if (isnp[x] && isnp[y]) {
				writeln(x, " ", y);
				break;
			}
		}
	}
	} catch (EOFException) {}
}

import std.stdio;
import std.string;
import std.algorithm;
import core.stdc.stdio;
import std.bigint;
import std.format;
import std.math;

string readline()
{
	string result = readln();
	if (result[result.length - 1] == '\n') result.length--;
	return result;
}

bool isPrime(long x)
{
	foreach (long i; 2..(x/2))
	{
		if (x % i == 0)
			return false;
	}
	return true;
}

int main(string[] argv)
{
	long n;
	scanf("%d", &n);
	long x, y;
	x = n / 2;
	y = n / 2;
	if (x + y != n) y++;
	foreach (long i; 0..x)
	{
		x -= i;
		y += i;
		if (!isPrime(x) && !isPrime(y))
		{
			printf("%d ", x);
			printf("%d", y);
			return 0;
		}
	}
	return 0;
}

import std.stdio;
import std.string;
import std.algorithm;
import core.stdc.stdio;
import std.bigint;
import std.format;
import std.math;

string readline()
{
	string result = readln();
	if (result[result.length - 1] == '\n') result.length--;
	return result;
}

bool isPrime(long x)
{
	foreach (long i; 2..(x/2 + 1))
	{
		if (x % i == 0)
			return false;
	}
	return true;
}

int main(string[] argv)
{
	long n;
	scanf("%d", &n);
	long x, y;
	x = n / 2;
	y = n / 2;
	if (x + y != n) y++;
	foreach (long i; 0..x)
	{
		x -= 1;
		y += 1;
		if (!isPrime(x) && !isPrime(y))
		{
			printf("%d ", x);
			printf("%d", y);
			return 0;
		}
	}
	return 0;
}


Luntik has decided to try singing. He has $$$a$$$ one-minute songs, $$$b$$$ two-minute songs and $$$c$$$ three-minute songs. He wants to distribute all songs into two concerts such that every song should be included to exactly one concert.He wants to make the absolute difference of durations of the concerts as small as possible. The duration of the concert is the sum of durations of all songs in that concert.Please help Luntik and find the minimal possible difference in minutes between the concerts durations.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of one line containing three integers $$$a, b, c$$$ $$$(1 \le a, b, c \le 10^9)$$$ — the number of one-minute, two-minute and three-minute songs.

For each test case print the minimal possible difference in minutes between the concerts durations.

NoteIn the first test case, Luntik can include a one-minute song and a two-minute song into the first concert, and a three-minute song into the second concert. Then the difference will be equal to $$$0$$$.In the second test case, Luntik can include two one-minute songs and a two-minute song and a three-minute song into the first concert, and two three-minute songs into the second concert. The duration of the first concert will be $$$1 + 1 + 2 + 3 = 7$$$, the duration of the second concert will be $$$6$$$. The difference of them is $$$|7-6| = 1$$$.

immutable multi = true;

void solve(int tc)
{
  return writeln((readInt!int + readInt!int*0 + readInt!int)&1);
}

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

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 long[](t);
	foreach (ti; 0..t)
	{
		auto a = RD;
		auto b = RD;
		auto c = RD;

		auto tot = a + b*2 + c*3;
		auto half = tot / 2;
		debug writeln(half);
		half -= min(c, half / 3) * 3;
		debug writeln(half);
		half -= min(b, half / 2) * 2;
		debug writeln(half);
		half -= min(a, half);
		debug writeln(half);
		ans[ti] = half * 2 + tot % 2;
	}

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

immutable multi = true;

void solve(int tc)
{
  return writeln((readInt!int + readInt!int + readInt!int)&1);
}

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


You have $$$n$$$ gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The $$$i$$$-th gift consists of $$$a_i$$$ candies and $$$b_i$$$ oranges.During one move, you can choose some gift $$$1 \le i \le n$$$ and do one of the following operations:  eat exactly one candy from this gift (decrease $$$a_i$$$ by one);  eat exactly one orange from this gift (decrease $$$b_i$$$ by one);  eat exactly one candy and exactly one orange from this gift (decrease both $$$a_i$$$ and $$$b_i$$$ by one). Of course, you can not eat a candy or orange if it's not present in the gift (so neither $$$a_i$$$ nor $$$b_i$$$ can become less than zero).As said above, all gifts should be equal. This means that after some sequence of moves the following two conditions should be satisfied: $$$a_1 = a_2 = \dots = a_n$$$ and $$$b_1 = b_2 = \dots = b_n$$$ (and $$$a_i$$$ equals $$$b_i$$$ is not necessary).Your task is to find the minimum number of moves required to equalize all the given gifts.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of gifts. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the number of candies in the $$$i$$$-th gift. The third line of the test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 10^9$$$), where $$$b_i$$$ is the number of oranges in the $$$i$$$-th gift.

For each test case, print one integer: the minimum number of moves required to equalize all the given gifts.

NoteIn the first test case of the example, we can perform the following sequence of moves:  choose the first gift and eat one orange from it, so $$$a = [3, 5, 6]$$$ and $$$b = [2, 2, 3]$$$;  choose the second gift and eat one candy from it, so $$$a = [3, 4, 6]$$$ and $$$b = [2, 2, 3]$$$;  choose the second gift and eat one candy from it, so $$$a = [3, 3, 6]$$$ and $$$b = [2, 2, 3]$$$;  choose the third gift and eat one candy and one orange from it, so $$$a = [3, 3, 5]$$$ and $$$b = [2, 2, 2]$$$;  choose the third gift and eat one candy from it, so $$$a = [3, 3, 4]$$$ and $$$b = [2, 2, 2]$$$;  choose the third gift and eat one candy from it, so $$$a = [3, 3, 3]$$$ and $$$b = [2, 2, 2]$$$.

import std.stdio;
import std.algorithm : map, min, minElement, sum;
import std.range : zip;
import std.string : strip, split;
import std.conv : to;

void main()
{
  int t;
  readf!"%d\n"(t);

  foreach (i; 0..t) {
    int n;
    readf!"%d\n"(n);
    auto a = readln.strip.split.map!(to!long);
    auto b = readln.strip.split.map!(to!long);

    auto mina = a.minElement;
    auto minb = b.minElement;

    auto c = zip(a, b)
      .map!(a => (a[0] - mina) + (a[1] - minb) - min(a[0] - mina, a[1] - minb))
      .sum;

    writefln("%d", c);
  }
}

import std.container;
import std.algorithm;
import std.range;
import std.array;
import std.stdio;
import std.utf;
import std.math;
import std.typecons;

alias type = multi;
struct TestCase
{
  mixin prettyPrinting;

  long n;
  @("n") long[] a;
  @("n") long[] b;

  void solve(long tc = -1)
  {
    logSym!this;
    auto oa = a.fold!min(long.max);
    auto ob = b.fold!min(long.max);
    auto res = long(0);
    foreach(i; 0 .. n)
      {
        auto opa = a.at(i) - oa;
        auto opb = b.at(i) - ob;
        auto common = min(opa, opb);
        logSym!(opa, opb, common);
        res += opa + opb - common;
      }
    writeln(res);
  }
}

mixin template prettyPrinting()
{
  string toString()
  {
    alias structType = typeof(this);
    auto res = appender!(string)();
    res.put(structType.stringof);
    res.put("(");
    static foreach(fieldName; FieldNameTuple!structType)
      {
        res.put(text(" ", fieldName, ": ", mixin(fieldName)));
      }
    res.put(" )");
    res.put("\n");
    return res[];
  }
}

struct Graph(N)
{
  size_t size;
  this(S)(S size)
  {
    adjacencyList.length = cast(size_t) size;
    this.size = cast(size_t) size;
    this.visited = makeSlice!bool(size);
  }
  N[][] adjacencyList;
  alias ne = neighbours;
  N[] neighbours(N n)
  {
    return adjacencyList.at(n);
  }
  alias bcon = biconnect;
  void biconnect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
    adjacencyList.at(b) ~= a;
  }
  alias con = connect;
  void connect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
  }
  void connect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        connect(edge[0], edge[1]);
      }
  }
  void biconnect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        biconnect(edge[0], edge[1]);
      }
  }
  alias deg = degree!long;
  auto degree(T)(N a)
  {
    return cast(T) adjacencyList.at(a).length;
  }

  auto visited = new bool[0];
  void dfs(Visitor)(long startNode)
  {
    auto visitor = Visitor.init;
    void internalDfs(long node)
    {
      visited.set(node, true);
      static if (is(typeof({visitor.n = node;})))
        visitor.n = node;
      static if (is(typeof({visitor.pre;})))
        visitor.pre;
      foreach(w; ne(node))
        if (!visited.at(w))
          {
            static if (is(typeof({visitor.w = w;})))
              visitor.w = w;
            static if (is(typeof(visitor.pren)))
              visitor.pren;
            internalDfs(w);
            static if (is(typeof(visitor.postn)))
              visitor.postn;
          }
      static if (is(typeof(visitor.post)))
        visitor.post;
    }
    internalDfs(startNode);
  }
  void dfs(long startNode)
  {
    struct DefVisitor {}
    dfs!DefVisitor(startNode);
  }
}

DList!string _words;

template baseType(W)
{
  static if (isDynamicArray!W)
    alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));
  else
    alias baseType = W;
}

auto makeSlice(E, W, T...)(W size, T otherSizes)
{
  static if (T.length == 0)
    {
      E[] res;
      res.length = cast(size_t) size;
      return res;
    }
  else
    {
      typeof(makeSlice!E(otherSizes))[] res;
      res.length = cast(size_t) size;
      foreach(ref row; res)
        row = makeSlice!E(otherSizes);
      return res;
    }
}

void read(T...)(ref T t)
{
  void basicTypeRead(W)(ref W w)
  {
    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;
    w = to!W(word);
  }
  void iterableRead(W)(ref W w)
  {
    foreach(ref element; w)
      read(element);
  }
  void tupleRead(W)(ref W w)
  {
    static foreach(j; 0 .. W.length)
      read(w[j]);
  }
  void structRead(W)(ref W w)
  {
    static foreach(fieldName; FieldNameTuple!W)
      {
        with(w)
          {
            alias fieldSymbol = mixin(W.stringof, ".", fieldName);
            alias typeOfField = typeof(mixin(fieldName));
            static if (hasUDA!(fieldSymbol, string))
              {
                static assert(isDynamicArray!(typeOfField)
                              , " A field with dimension initialization UDA must be a dynamic array.");
                enum uda = getUDAs!(fieldSymbol, string)[0];
                mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda, q{)});
              }
            else static if (isDynamicArray!typeOfField)
              {
                pragma(msg, "Warning: You probably want to add dimension to input ", fieldName);
              }
            read(mixin(fieldName));
          }
      }
  }
  static foreach(i; 0 .. T.length)
    {
      static if (isBasicType!(T[i]) || is(T[i] == string))
        basicTypeRead(t[i]);
      else static if (is(typeof({foreach(ref e; t[i]){}})))
        iterableRead(t[i]);
      else static if (isTuple!(T[i]))
        tupleRead(t[i]);
      else static if (isAggregateType!(T[i]))
        structRead(t[i]);
    }
}

auto next(T)()
{
  T t;
  read(t);
  return t;
}

size_t ind(T)(T t)
{
  return cast(size_t)t;
}

ref auto at(R, I)(ref R r, I i)
{
  return r[cast(size_t)i];
}

void set(R, I, V)(ref R r, I i, V v)
{
  r[cast(size_t)i] = v;
}

import std.conv;
import std.traits;
import std.meta;
int _loglevel = -1;
void _log(string functionName, argSeq...)()
{
  foreach(i; 0 .. _loglevel * 4)
    write(' ');
  write(functionName);
  static foreach(arg; argSeq)
    {
      write(" ", arg.stringof, " = ", arg);
    }
  writeln;
}
enum logCall =
  q{
    debug
    {
     {
     _loglevel++;
     alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, ".").back));
     static if (_parameterTuple.length > 0)
       mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(", ").array, `);`);
     else
       _log!(__FUNCTION__);
      }
     foreach(i; 0 .. _loglevel * 4) write(' ');
     writeln('{');
     scope(exit)
       {
         foreach(i; 0 .. _loglevel * 4) write(' ');
         writeln('}');
         _loglevel--;
       }
    }
};

void logSym(S...)(int line = __LINE__, string file = __FUNCTION__)
{
  debug
    {
      foreach(i; 0 .. _loglevel * 4) write(' ');
      write(file, "(", line, "):");
      static foreach(s; S)
        write(" ", s.stringof, " = ", s);
      writeln;

    }
}

Array!E makeArray(E, S)(S size, lazy E value)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  foreach(ref ai; a)
    ai = value();
  return a;
}
Array!E makeArray(E, S)(S size)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  return a;
}

template mem(alias F)
{
  ReturnType!F[Tuple!(Parameters!F)] table;
  ReturnType!F mem(Parameters!F args)
  {
    return table.require(tuple(args), F(args));
  }
}

string input(string names, string type = "long")
{
  return text(type, " ", names, "; read(", names, ");");
}

auto pmod(T, W)(T t, W w)
{
  return (t%w + w) % w;
}

void rep(S, F)(F f, S times)
{
  static if (is(typeof(f(i))))
    foreach(i; 0 .. times)
      f(i);
  else
    foreach(i; 0 .. times)
      f();
}

void multi()
{
  foreach(tc; 0 .. next!long)
    next!TestCase.solve(tc);
}

void single()
{
  auto tc = next!TestCase;
  tc.solve;
}

void main()
{
  type;
}

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(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

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

		long min_a = long.max;
		long min_b = long.max;
		foreach (i; 0..n)
		{
			min_a.chmin(a[i]);
			min_b.chmin(b[i]);
		}

		foreach (i; 0..n)
		{
			auto da = a[i] - min_a;
			auto db = b[i] - min_b;
			ans[ti] += max(da, db);
		}
	}

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


You are given circular array a0, a1, ..., an - 1. There are two types of operations with it:   inc(lf, rg, v) — this operation increases each element on the segment [lf, rg] (inclusively) by v;  rmq(lf, rg) — this operation returns minimal value on the segment [lf, rg] (inclusively). Assume segments to be circular, so if n = 5 and lf = 3, rg = 1, it means the index sequence: 3, 4, 0, 1.Write program to process given sequence of operations.

The first line contains integer n (1 ≤ n ≤ 200000). The next line contains initial state of the array: a0, a1, ..., an - 1 ( - 106 ≤ ai ≤ 106), ai are integer. The third line contains integer m (0 ≤ m ≤ 200000), m — the number of operartons. Next m lines contain one operation each. If line contains two integer lf, rg (0 ≤ lf, rg ≤ n - 1) it means rmq operation, it contains three integers lf, rg, v (0 ≤ lf, rg ≤ n - 1; - 106 ≤ v ≤ 106) — inc operation.

For each rmq operation write result for it. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).

// Cheese-Cracker: cheese-cracker.github.io
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
/*******************************It's a Me, Mario!*******************************************/

ll[] arr, segtree, delta;
const ll LMAX = to!ll(1e15);

ll build(int v, ll l, ll r){
    if(l == r){ return (segtree[v] = arr[to!int(l)]); }

    ll midd = (l + r)/2;
    return (segtree[v] = min(build(2*v, l, midd), build(2*v + 1, midd + 1, r)));
}

void apply(int v){
    segtree[2*v] += delta[v];
    segtree[2*v+1] += delta[v];
    delta[2*v] += delta[v];
    delta[2*v+1] += delta[v];
    delta[v] = 0;
}

ll query(int v, ll l, ll r, ll L, ll R){
    if(L > R){ return LMAX; }
    if(L <= l && r <= R){
        return segtree[v];
    }
    apply(v);
    ll midd = (l + r)/2;
    ll lq = query(2*v, l, midd, L, min(midd, R));
    ll hq = query(2*v + 1, midd+1, r, max(midd+1, L), R);
    /* debug writeln(lq, " ", hq); */
    return min(lq, hq);
}

void update(int v, ll l, ll r, ll L, ll R, ll incr){
    if(L > R || l > R || r < L || l > r){ return; }
    if(L <= l && r <= R){
        segtree[v] += incr;
        delta[v] += incr;
        return;
    }
    /* writeln(v, " ", l, " ", r, " ", L, " ", R); */
    apply(v);
    ll midd = (l + r)/2;
    update(2*v, l, midd, L, R, incr);
    update(2*v+1, midd+1, r, L, R, incr);

    // Note: Even if we HAVE to take Min of Segtree Values NOT update return values.
    // Since it may not update and return INF
    segtree[v] = min(segtree[2*v], segtree[2*v+1]);
}

void play(){
    int n, m;
    n = rd!int;
    segtree.length = 4*n+1;
    delta.length = 4*n+1;
    arr = rdarr;
    build(1, 0, n-1);
    m = rd!int;
    while(m--){
        ll[] reds = rdarr;
        ll l = reds[0], r = reds[1];
        if(reds.length == 3){
            if(l > r){
                update(1, 0, n-1, l, n-1, reds[2]);
                update(1, 0, n-1, 0, r, reds[2]);
            }else{
                update(1, 0, n-1, l, r, reds[2]);
            }
        }else{
            ll res;
            if(l > r){
                res = min(query(1, 0, n-1, l, n-1), query(1, 0, n-1, 0, r));
            }else{
                res = query(1, 0, n-1, l, r);
            }
            writeln(res);
        }
        /* debug{ writeln(segtree);} */
    }
}

int main(){
    long t = 1;
    /* t = rd;        // Toggle! */
    while(t--) play();  // Let's play!
    stdout.flush;
    return 0;
}

// Code By H~$~C

module main;

import core.stdc.stdlib, core.stdc.string;
import std.stdio, std.array, std.string, std.math, std.uni;
import std.algorithm, std.range, std.random, std.container;
import std.conv, std.typecons, std.functional;

immutable Maxn = 200005;

struct node {
  this()() {
    mn = lnf;
    tag = 0;
  }
  this()(in node x) { *this = x; }
  long mn, tag;
  void apply(int l, int r, long x) {
    mn += x, tag += x;
  }
}
void pullup(ref node a, in node b, in node c) {
  a.mn = min(b.mn, c.mn);
}
struct segment_tree {
  int N;
  node[] tr;
  private void pushup(int p) {
    pullup(tr[p], tr[p * 2], tr[p * 2 + 1]);
  }
  private void modify_(T...)(int p, int l, int r, int L, int R, T args) {
    if (L == l && r == R) return tr[p].apply(l, r, args);
    pushdown(p, l, r);
    int mid = (l + r) >> 1;
    if (R <= mid) modify_(p * 2, l, mid, L, R, args);
    else if (L > mid) modify_(p * 2 + 1, mid + 1, r, L, R, args);
    else {
      modify_(p * 2, l, mid, L, mid, args);
      modify_(p * 2 + 1, mid + 1, r, mid + 1, R, args);
    }
    pushup(p);
  }
  private node query_(int p, int l, int r, int L, int R) {
    if (L == l && r == R) return tr[p];
    pushdown(p, l, r);
    int mid = (l + r) >> 1;
    if (R <= mid) return query_(p * 2, l, mid, L, R);
    if (L > mid) return query_(p * 2 + 1, mid + 1, r, L, R);
    node left = query_(p * 2, l, mid, L, mid);
    node right = query_(p * 2 + 1, mid + 1, r, mid + 1, R);
    node ans; pullup(ans, left, right); return ans;
  }
  public void build(T...)(int len, T args) {
    N = len;
    tr.length = (N + 1) << 2;
    build(1, 1, N, args);
  }
  public void modify(T...)(int L, int R, T args) {
    if (L > R) return ;
    modify_(1, 1, N, L, R, args);
  }
  public node query(int L, int R) {
    if (L > R) return node();
    return query_(1, 1, N, L, R);
  }
  private void pushdown(int p, int l, int r) {
    int mid = (l + r) >> 1;
    if (tr[p].tag != 0) {
      tr[p * 2].apply(l, mid, tr[p].tag);
      tr[p * 2 + 1].apply(mid + 1, r, tr[p].tag);
      tr[p].tag = 0;
    }
  }
  private void build(int p, int l, int r, in long[] args) {
    if (l == r) {
      tr[p].apply(l, r, args[l]);
      return ;
    }
    int mid = (l + r) >> 1;
    build(p * 2, l, mid, args);
    build(p * 2 + 1, mid + 1, r, args);
    pushup(p);
  }
}
segment_tree sgt;

void solve(in int testcase) {
  int n; n.read;
  long[Maxn] arr;
  arr[1 .. n + 1] = readarray!long;
  sgt.build(n, arr);
  int q; q.read;
  while (q--) {
    int[] fuck = readarray!int.map!(a => a + 1).array;
    if (fuck.length == 2) {
      int l = fuck[0], r = fuck[1];
      if (l <= r) sgt.query(l, r).mn.writeln;
      else min(sgt.query(1, r).mn, sgt.query(l, n).mn).writeln;
    }
    else {
      int l = fuck[0], r = fuck[1];
      int x = fuck[2] - 1;
      if (l <= r) sgt.modify(l, r, x);
      else sgt.modify(1, r, x), sgt.modify(l, n, x);
    }
  }
}

// ************************************************************

T reader(T)() { return readToken().to!T; }
void read(T)(ref T t) { t = reader!T; }
T[] readarray(T)() { return readln.splitter.map!(to!T).array; }
void chmax(T)(ref T a, T b) { a = max(a, b); }
void chmin(T)(ref T a, T b) { a = min(a, b); }
alias less = (a, b) => a < b;
alias greater = (a, b) => a > b;
T min_element(T)(in T[] a) { return a.element!less; }
T max_element(T)(in T[] a) { return a.element!greater; }
alias unique = uniq;

// constant or some variables
immutable int inf = 0x3f3f3f3f;
immutable long lnf = 0x3f3f3f3f3f3f3f3f;
immutable typeof(null) NULL = null;
string[] _tokens;

// functions
T element(alias pred, T)(in T[] a) {
  int pos = 0;
  for (int i = 1; i < cast(int)(a.length); ++i)
    if (binaryFun!pred(a[i], a[pos])) pos = i;
  return a[pos];
}
string readToken() {
  for (; _tokens.empty; ) {
    if (stdin.eof) return "";
    _tokens = readln.split;
  }
  auto token = _tokens.front;
  _tokens.popFront;
  return token;
}
int binary_bearch(alias pred, T)(in T[] as) {
  int l = -1, h = cast(int)(as.length), mid;
  for (; l + 1 < h; ) {
    mid = (l + h) >> 1;
    (unaryFun!pred(as[mid]) ? h : l) = mid;
  }
  return h;
}
int lower_bound(alias pred = less, T)(in T[] as, T val) {
  return as.binary_bearch!(a => a == val || pred(val, a));
}
int upper_bound(alias pred = less, T)(in T[] as, T val) {
  return as.binary_bearch!(a => pred(val, a));
}

void main(string[] args) {
  int tests = 1;
//  tests.read();
  foreach(test; 1 .. tests + 1) solve(test);
}

// Cheese-Cracker: cheese-cracker.github.io
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
/*******************************It's a Me, Mario!*******************************************/

ll[] arr, segtree, delta;

ll build(int v, ll l, ll r){
    if(l == r){ return (segtree[v] = arr[to!int(l)]); }

    ll midd = (l + r)/2;
    return (segtree[v] = min(build(2*v, l, midd), build(2*v + 1, midd + 1, r)));
}

ll query(int v, ll l, ll r, ll L, ll R){
    if(l > r || r < L || l > R){ return to!ll(1e8); }
    if(L <= l && r <= R){
        return segtree[v];
    }
    if(delta[v]) apply(v);
    ll midd = (l + r)/2;
    return min(query(2*v, l, midd, L, R), query(2*v + 1, midd+1, r, L, R));
}

void apply(int v){
    segtree[2*v] += delta[v];
    segtree[2*v+1] += delta[v];
    delta[2*v] = (delta[2*v+1] = delta[v]);
    delta[v] = 0;
}

ll update(int v, ll l, ll r, ll L, ll R, ll incr){
    if(l > r || r < L || l > R){ return to!ll(1e8); }
    if(L <= l && r <= R){
        segtree[v] += incr;
        delta[v] += incr;
        return segtree[v];
    }
    if(delta[v]) apply(v);
    ll midd = (l + r)/2;
    return segtree[v] = min(update(2*v, l, midd, L, R, incr), update(2*v+1, midd+1, r, L, R, incr));
}

void play(){
    int n, m;
    n = rd!int;
    segtree.length = 4*n+1;
    delta.length = 4*n+1;
    arr = rdarr;
    build(1, 0, n-1);
    m = rd!int;
    while(m--){
        ll[] reds = rdarr;
        ll l = reds[0], r = reds[1];
        if(reds.length == 3){
            if(l > r){
                update(1, 0, n-1, l, n-1, reds[2]);
                update(1, 0, n-1, 0, r, reds[2]);
            }else{
                update(1, 0, n-1, l, r, reds[2]);
            }
        }else{
            ll res;
            if(l > r){
                res = min(query(1, 0, n-1, l, n-1), query(1, 0, n-1, 0, r));
            }else{
                res = query(1, 0, n-1, l, r);
            }
            writeln(res);
        }
        debug{ writeln(segtree);}
    }
}

int main(){
    long t = 1;
    /* t = rd;        // Toggle! */
    while(t--) play();  // Let's play!
    stdout.flush;
    return 0;
}

// Cheese-Cracker: cheese-cracker.github.io
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
/*******************************It's a Me, Mario!*******************************************/

ll[] arr, segtree, delta;
const ll LMAX = to!ll(1e12);

ll build(int v, ll l, ll r){
    if(l == r){ return (segtree[v] = arr[to!int(l)]); }

    ll midd = (l + r)/2;
    return (segtree[v] = min(build(2*v, l, midd), build(2*v + 1, midd + 1, r)));
}

ll query(int v, ll l, ll r, ll L, ll R){
    if(l > r || r < L || l > R){ return LMAX; }
    if(L <= l && r <= R){
        return segtree[v];
    }
    if(delta[v]) apply(v);
    ll midd = (l + r)/2;
    return min(query(2*v, l, midd, L, R), query(2*v + 1, midd+1, r, L, R));
}

void apply(int v){
    segtree[2*v] += delta[v];
    segtree[2*v+1] += delta[v];
    delta[2*v] = (delta[2*v+1] = delta[v]);
    delta[v] = 0;
}

ll update(int v, ll l, ll r, ll L, ll R, ll incr){
    if(l > r || r < L || l > R){ return LMAX; }
    if(L <= l && r <= R){
        segtree[v] += incr;
        delta[v] += incr;
        return segtree[v];
    }
    if(delta[v]) apply(v);
    ll midd = (l + r)/2;
    return segtree[v] = min(update(2*v, l, midd, L, R, incr), update(2*v+1, midd+1, r, L, R, incr));
}

void play(){
    int n, m;
    n = rd!int;
    segtree.length = 4*n+1;
    delta.length = 4*n+1;
    arr = rdarr;
    build(1, 0, n-1);
    m = rd!int;
    while(m--){
        ll[] reds = rdarr;
        ll l = reds[0], r = reds[1];
        if(reds.length == 3){
            if(l > r){
                update(1, 0, n-1, l, n-1, reds[2]);
                update(1, 0, n-1, 0, r, reds[2]);
            }else{
                update(1, 0, n-1, l, r, reds[2]);
            }
        }else{
            ll res;
            if(l > r){
                res = min(query(1, 0, n-1, l, n-1), query(1, 0, n-1, 0, r));
            }else{
                res = query(1, 0, n-1, l, r);
            }
            writeln(res);
        }
        debug{ writeln(segtree);}
    }
}

int main(){
    long t = 1;
    /* t = rd;        // Toggle! */
    while(t--) play();  // Let's play!
    stdout.flush;
    return 0;
}

// Code By H~$~C

module main;

import core.stdc.stdlib, core.stdc.string;
import std.stdio, std.array, std.string, std.math, std.uni;
import std.algorithm, std.range, std.random, std.container;
import std.conv, std.typecons, std.functional;

immutable Maxn = 200005;

struct node {
  this()() {
    mn = lnf;
    tag = 0;
  }
  this()(in node x) { *this = x; }
  long mn, tag;
  void apply(int l, int r, long x) {
    mn += x, tag += x;
  }
}
void pullup(ref node a, in node b, in node c) {
  a.mn = min(b.mn, c.mn);
}
struct segment_tree {
  int N;
  node[] tr;
  private void pushup(int p) {
    pullup(tr[p], tr[p * 2], tr[p * 2 + 1]);
  }
  private void modify_(T...)(int p, int l, int r, int L, int R, T args) {
    if (L == l && r == R) return tr[p].apply(l, r, args);
    pushdown(p, l, r);
    int mid = (l + r) >> 1;
    if (R <= mid) modify_(p * 2, l, mid, L, R, args);
    else if (L > mid) modify_(p * 2 + 1, mid + 1, r, L, r, args);
    else {
      modify_(p * 2, l, mid, L, mid, args);
      modify_(p * 2 + 1, mid + 1, r, mid + 1, R, args);
    }
    pushup(p);
  }
  private node query_(int p, int l, int r, int L, int R) {
    if (L == l && r == R) return tr[p];
    pushdown(p, l, r);
    int mid = (l + r) >> 1;
    if (R <= mid) return query_(p * 2, l, mid, L, R);
    if (L > mid) return query_(p * 2 + 1, mid + 1, r, L, R);
    node left = query_(p * 2, l, mid, L, mid);
    node right = query_(p * 2 + 1, mid + 1, r, mid + 1, R);
    node ans; pullup(ans, left, right); return ans;
  }
  public void build(T...)(int len, T args) {
    N = len;
    tr.length = (N + 1) << 2;
    build(1, 1, N, args);
  }
  public void modify(T...)(int L, int R, T args) {
    if (L > R) return ;
    modify_(1, 1, N, L, R, args);
  }
  public node query(int L, int R) {
    if (L > R) return node();
    return query_(1, 1, N, L, R);
  }
  private void pushdown(int p, int l, int r) {
    int mid = (l + r) >> 1;
    if (tr[p].tag != 0) {
      tr[p * 2].apply(l, mid, tr[p].tag);
      tr[p * 2 + 1].apply(mid + 1, r, tr[p].tag);
      tr[p].tag = 0;
    }
  }
  private void build(int p, int l, int r, in long[] args) {
    if (l == r) {
      tr[p].apply(l, r, args[l]);
      return ;
    }
    int mid = (l + r) >> 1;
    build(p * 2, l, mid, args);
    build(p * 2 + 1, mid + 1, r, args);
    pushup(p);
  }
}
segment_tree sgt;

void solve(in int testcase) {
  int n; n.read;
  long[Maxn] arr;
  arr[1 .. n + 1] = readarray!long;
  sgt.build(n, arr);
  int q; q.read;
  while (q--) {
    int[] fuck = readarray!int.map!(a => a + 1).array;
    if (fuck.length == 2) {
      int l = fuck[0], r = fuck[1];
      if (l <= r) sgt.query(l, r).mn.writeln;
      else min(sgt.query(1, r).mn, sgt.query(l, n).mn).writeln;
    }
    else {
      int l = fuck[0], r = fuck[1];
      int x = fuck[2] - 1;
      if (l <= r) sgt.modify(l, r, x);
      else sgt.modify(1, r, x), sgt.modify(l, n, x);
    }
  }
}

// ************************************************************

T reader(T)() { return readToken().to!T; }
void read(T)(ref T t) { t = reader!T; }
T[] readarray(T)() { return readln.splitter.map!(to!T).array; }
void chmax(T)(ref T a, T b) { a = max(a, b); }
void chmin(T)(ref T a, T b) { a = min(a, b); }
alias less = (a, b) => a < b;
alias greater = (a, b) => a > b;
T min_element(T)(in T[] a) { return a.element!less; }
T max_element(T)(in T[] a) { return a.element!greater; }
alias unique = uniq;

// constant or some variables
immutable int inf = 0x3f3f3f3f;
immutable long lnf = 0x3f3f3f3f3f3f3f3f;
immutable typeof(null) NULL = null;
string[] _tokens;

// functions
T element(alias pred, T)(in T[] a) {
  int pos = 0;
  for (int i = 1; i < cast(int)(a.length); ++i)
    if (binaryFun!pred(a[i], a[pos])) pos = i;
  return a[pos];
}
string readToken() {
  for (; _tokens.empty; ) {
    if (stdin.eof) return "";
    _tokens = readln.split;
  }
  auto token = _tokens.front;
  _tokens.popFront;
  return token;
}
int binary_bearch(alias pred, T)(in T[] as) {
  int l = -1, h = cast(int)(as.length), mid;
  for (; l + 1 < h; ) {
    mid = (l + h) >> 1;
    (unaryFun!pred(as[mid]) ? h : l) = mid;
  }
  return h;
}
int lower_bound(alias pred = less, T)(in T[] as, T val) {
  return as.binary_bearch!(a => a == val || pred(val, a));
}
int upper_bound(alias pred = less, T)(in T[] as, T val) {
  return as.binary_bearch!(a => pred(val, a));
}

void main(string[] args) {
  int tests = 1;
//  tests.read();
  foreach(test; 1 .. tests + 1) solve(test);
}


You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters.We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels: 'a', 'e', 'i', 'o', 'u' and 'y'.Each word of the text that contains at least one vowel can be divided into syllables. Each character should be a part of exactly one syllable. For example, the word "mamma" can be divided into syllables as "ma" and "mma", "mam" and "ma", and "mamm" and "a". Words that consist of only consonants should be ignored.The verse patterns for the given text is a sequence of n integers p1, p2, ..., pn. Text matches the given verse pattern if for each i from 1 to n one can divide words of the i-th line in syllables in such a way that the total number of syllables is equal to pi.You are given the text and the verse pattern. Check, if the given text matches the given verse pattern.

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of lines in the text. The second line contains integers p1, ..., pn (0 ≤ pi ≤ 100) — the verse pattern. Next n lines contain the text itself. Text consists of lowercase English letters and spaces. It's guaranteed that all lines are non-empty, each line starts and ends with a letter and words are separated by exactly one space. The length of each line doesn't exceed 100 characters.

If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).

4
13 11 15 15
to be or not to be that is the question
whether tis nobler in the mind to suffer
the slings and arrows of outrageous fortune
or to take arms against a sea of troubles

NoteIn the first sample, one can split words into syllables in the following way: in-telco-dech al-len-geSince the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one.

import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,
std.random,std.uni,std.traits,std.variant;
import core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
immutable int mod=1000000007;
pure nothrow T lcm (T)(auto ref T a,auto ref T b)
{
	return a/gcd(a,b)*b;
}
pure nothrow X binpow(X,Y)(X base,Y exp)
if(is(typeof(exp&1)))
{
	if(exp<0)return X(0);
	X res=X(1);
	while(exp>0)
	{
		if(exp&1)res*=base;
		base*=base;
		exp>>=1;
	}
	return res;
}
pure nothrow auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
if(is(typeof(exp&1)))
{
	if(mm==0) return binpow(base,exp);
	if(exp<0)return X(0);
	auto res=X(1)%mm;
	while(exp>0)
	{
		if(exp&1)res=(res*base)%mm;
		base*=base;
		base%=mm;
		exp>>=1;
	}
	return res;
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(X a,in int n,in int m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(" %s"~'\n', ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
	}
	this(this){fi=fi;se=se;}
	this(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))
	{
		fi=p.fi;
		se=p.se;
	}
	int opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe if(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
X sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}
X cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}
nothrow @nogc @system void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow @nogc @system void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.split.map!(to!(T)).array;}
nothrow pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (!(a[l]<g))?l:r;
}
pure nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(g<a[m])r=m;
		else l=m;
	}
	return (g<a[l])?l:r;
}
pure nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (g==a[l])?l:a.length;
}
pure nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	return binf(a,g)!=a.length;
}
pure nothrow V foldr(R,V,T)(R range,T arg,V nach) if(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))
{
	for(;!range.empty;range.popFront()) nach=arg(nach,range.front);
	return nach;
}
pure nothrow size_t countr(R,T)(R range,T fun) if(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))
{
	size_t nach;
	for(;!range.empty;range.popFront()) nach+=fun(range.front);
	return nach;
}
pure nothrow T orient_square(T)(pair!(T,T)[] figure...) if(figure.length>2 && is(typeof(figure.front*figure.front)==T))
{
	auto n=figure.front,t=figure.front;
	figure.popFront();
	T ans=0;
	for(;!figure.empty;figure.popFront())
	{
		ans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);
		t=figure.front;
	}
	return ans+(n.fi-t.fi)*(n.se+t.se);
}
pure nothrow real square(T)(pair!(T,T)[] figure...) if(figure.length>2 && is(typeof(figure.front*figure.front)==T))
{
	return abs(orient_square(figure))/2.00000000000;
}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	int n;
	string sh="aeiouy";
	while(input(&n))
	{
		auto p=arread!int;
		foreach(i;0..n)
		{
			auto s=readln;
			auto k=s.count!q{a=='a' || a=='e' || a=='i' || a=='o' || a=='u' || a=='y'};
			if(k!=p[i]){writeln("NO");return;}
		}
		writeln("YES");
	}
	debug system("pause");
}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(int)).array;
		bool ok = true;
		foreach (c; a)
		{
			auto s = readln.strip;
			auto t = s.count !(x => "aeiouy".canFind (x));
			ok &= (c == t);
		}
		writeln (ok ? "YES" : "NO");
	}
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,
std.random,std.uni,std.traits,std.variant;
import core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
immutable int mod=1000000007;
pure nothrow T lcm (T)(auto ref T a,auto ref T b)
{
	return a/gcd(a,b)*b;
}
pure nothrow X binpow(X,Y)(X base,Y exp)
if(is(typeof(exp&1)))
{
	if(exp<0)return X(0);
	X res=X(1);
	while(exp>0)
	{
		if(exp&1)res*=base;
		base*=base;
		exp>>=1;
	}
	return res;
}
pure nothrow auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
if(is(typeof(exp&1)))
{
	if(mm==0) return binpow(base,exp);
	if(exp<0)return X(0);
	auto res=X(1)%mm;
	while(exp>0)
	{
		if(exp&1)res=(res*base)%mm;
		base*=base;
		base%=mm;
		exp>>=1;
	}
	return res;
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(X a,in int n,in int m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(" %s"~'\n', ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
	}
	this(this){fi=fi;se=se;}
	this(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))
	{
		fi=p.fi;
		se=p.se;
	}
	int opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe if(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
X sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}
X cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}
nothrow @nogc @system void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow @nogc @system void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.split.map!(to!(T)).array;}
nothrow pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (!(a[l]<g))?l:r;
}
pure nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(g<a[m])r=m;
		else l=m;
	}
	return (g<a[l])?l:r;
}
pure nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (g==a[l])?l:a.length;
}
pure nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	return binf(a,g)!=a.length;
}
pure nothrow V foldr(R,V,T)(R range,T arg,V nach) if(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))
{
	for(;!range.empty;range.popFront()) nach=arg(nach,range.front);
	return nach;
}
pure nothrow size_t countr(R,T)(R range,T fun) if(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))
{
	size_t nach;
	for(;!range.empty;range.popFront()) nach+=fun(range.front);
	return nach;
}
pure nothrow T orient_square(T)(pair!(T,T)[] figure...) if(figure.length>2 && is(typeof(figure.front*figure.front)==T))
{
	auto n=figure.front,t=figure.front;
	figure.popFront();
	T ans=0;
	for(;!figure.empty;figure.popFront())
	{
		ans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);
		t=figure.front;
	}
	return ans+(n.fi-t.fi)*(n.se+t.se);
}
pure nothrow real square(T)(pair!(T,T)[] figure...) if(figure.length>2 && is(typeof(figure.front*figure.front)==T))
{
	return abs(orient_square(figure))/2.00000000000;
}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	int n;
	string sh="aeiouy";
	while(input(&n))
	{
		auto p=arread!int;
		foreach(i;0..n)
		{
			auto s=readln;
			auto k=s.count!q{a=='a' || a=='e' || a=='i' || a=='o' || a=='u' || a=='y'};
			if(k<p[i]){writeln("NO");return;}
		}
		writeln("YES");
	}
	debug system("pause");
}


Let $$$s(x)$$$ be sum of digits in decimal representation of positive integer $$$x$$$. Given two integers $$$n$$$ and $$$m$$$, find some positive integers $$$a$$$ and $$$b$$$ such that   $$$s(a) \ge n$$$,  $$$s(b) \ge n$$$,  $$$s(a + b) \le m$$$.

The only line of input contain two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1129$$$).

Print two lines, one for decimal representation of $$$a$$$ and one for decimal representation of $$$b$$$. Both numbers must not contain leading zeros and must have length no more than $$$2230$$$.

NoteIn the first sample, we have $$$n = 6$$$ and $$$m = 5$$$. One valid solution is $$$a = 6$$$, $$$b = 7$$$. Indeed, we have $$$s(a) = 6 \ge n$$$ and $$$s(b) = 7 \ge n$$$, and also $$$s(a + b) = s(13) = 4 \le m$$$.

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

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

    dchar[] a, b;
    a ~= '5';
    b ~= '5';
    foreach (i; 0 .. 400) {
       a ~= i % 2 == 0 ? '4' : '5';
       b ~= i % 2 == 0 ? '5' : '4';
    }

    reverse(a);
    reverse(b);
    a.writeln;
    b.writeln;
}


You are given two binary strings $$$x$$$ and $$$y$$$, which are binary representations of some two integers (let's denote these integers as $$$f(x)$$$ and $$$f(y)$$$). You can choose any integer $$$k \ge 0$$$, calculate the expression $$$s_k = f(x) + f(y) \cdot 2^k$$$ and write the binary representation of $$$s_k$$$ in reverse order (let's denote it as $$$rev_k$$$). For example, let $$$x = 1010$$$ and $$$y = 11$$$; you've chosen $$$k = 1$$$ and, since $$$2^1 = 10_2$$$, so $$$s_k = 1010_2 + 11_2 \cdot 10_2 = 10000_2$$$ and $$$rev_k = 00001$$$.For given $$$x$$$ and $$$y$$$, you need to choose such $$$k$$$ that $$$rev_k$$$ is lexicographically minimal (read notes if you don't know what does "lexicographically" means).It's guaranteed that, with given constraints, $$$k$$$ exists and is finite.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. Next $$$2T$$$ lines contain a description of queries: two lines per query. The first line contains one binary string $$$x$$$, consisting of no more than $$$10^5$$$ characters. Each character is either 0 or 1. The second line contains one binary string $$$y$$$, consisting of no more than $$$10^5$$$ characters. Each character is either 0 or 1. It's guaranteed, that $$$1 \le f(y) \le f(x)$$$ (where $$$f(x)$$$ is the integer represented by $$$x$$$, and $$$f(y)$$$ is the integer represented by $$$y$$$), both representations don't have any leading zeroes, the total length of $$$x$$$ over all queries doesn't exceed $$$10^5$$$, and the total length of $$$y$$$ over all queries doesn't exceed $$$10^5$$$.

Print $$$T$$$ integers (one per query). For each query print such $$$k$$$ that $$$rev_k$$$ is lexicographically minimal.

NoteThe first query was described in the legend.In the second query, it's optimal to choose $$$k = 3$$$. The $$$2^3 = 1000_2$$$ so $$$s_3 = 10001_2 + 110_2 \cdot 1000_2 = 10001 + 110000 = 1000001$$$ and $$$rev_3 = 1000001$$$. For example, if $$$k = 0$$$, then $$$s_0 = 10111$$$ and $$$rev_0 = 11101$$$, but $$$rev_3 = 1000001$$$ is lexicographically smaller than $$$rev_0 = 11101$$$.In the third query $$$s_0 = 10$$$ and $$$rev_0 = 01$$$. For example, $$$s_2 = 101$$$ and $$$rev_2 = 101$$$. And $$$01$$$ is lexicographically smaller than $$$101$$$.The quote from Wikipedia: "To determine which of two strings of characters comes when arranging in lexicographical order, their first letters are compared. If they differ, then the string whose first letter comes earlier in the alphabet comes before the other string. If the first letters are the same, then the second letters are compared, and so on. If a position is reached where one string has no more letters to compare while the other does, then the first (shorter) string is deemed to come first in alphabetical order."

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 x = RD!(char[]);
		auto y = RD!(char[]);
		x.reverse;
		y.reverse;
		int pos;
		while (y[pos] == '0')
			++pos;

		long tmp;
		foreach (j; pos..x.length)
		{
			if (x[j] == '1')
			{
				debug writeln("j:pos ", j, " ", pos);
				tmp = j - pos;
				break;
			}
		}
		ans[i] = tmp;
	}

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


A and B are preparing themselves for programming contests.After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes.A likes lowercase letters of the Latin alphabet. He has assigned to each letter a number that shows how much he likes that letter (he has assigned negative numbers to the letters he dislikes). B likes substrings. He especially likes the ones that start and end with the same letter (their length must exceed one).Also, A and B have a string s. Now they are trying to find out how many substrings t of a string s are interesting to B (that is, t starts and ends with the same letter and its length is larger than one), and also the sum of values of all letters (assigned by A), except for the first and the last one is equal to zero.Naturally, A and B have quickly found the number of substrings t that are interesting to them. Can you do it?

The first line contains 26 integers xa, xb, ..., xz ( - 105 ≤ xi ≤ 105) — the value assigned to letters a, b, c, ..., z respectively. The second line contains string s of length between 1 and 105 characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer.

NoteIn the first sample test strings satisfying the condition above are abca and bcab.In the second sample test strings satisfying the condition above are two occurences of aa.

import std.stdio, std.string;

void solve(int[] x, string s)
{
    auto n = cast(int)s.length;
    auto c = new int[long][26];
    long sum = 0, ans = 0;
    foreach (i; 0 .. n)
    {
        auto p = s[i] - 'a';
        if (sum in c[p])
        {
            ans += c[p][sum];
        }
        sum += x[p];
        if (sum !in c[p])
        {
            c[p][sum] = 0;
        }
        ++ c[p][sum];
    }
    writeln(ans);
}

int main(string[] args)
{
    auto x = new int[26];
    foreach (i; 0 .. 26)
    {
        readf(" %d", &x[i]);
    }
    readln;
    auto s = readln().strip();
    solve(x, s);
    return 0;
}


Anu has created her own function $$$f$$$: $$$f(x, y) = (x | y) - y$$$ where $$$|$$$ denotes the bitwise OR operation. For example, $$$f(11, 6) = (11|6) - 6 = 15 - 6 = 9$$$. It can be proved that for any nonnegative numbers $$$x$$$ and $$$y$$$ value of $$$f(x, y)$$$ is also nonnegative. She would like to research more about this function and has created multiple problems for herself. But she isn't able to solve all of them and needs your help. Here is one of these problems.A value of an array $$$[a_1, a_2, \dots, a_n]$$$ is defined as $$$f(f(\dots f(f(a_1, a_2), a_3), \dots a_{n-1}), a_n)$$$ (see notes). You are given an array with not necessarily distinct elements. How should you reorder its elements so that the value of the array is maximal possible?

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). Elements of the array are not guaranteed to be different.

Output $$$n$$$ integers, the reordering of the array with maximum value. If there are multiple answers, print any.

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

immutable int limit = 32;

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto c = new int [limit];
		foreach (ref x; a)
		{
			foreach (i; 0..limit)
			{
				if (x & (1 << i))
				{
					c[i] += 1;
				}
			}
		}

		int res = -1;
		int pos = -1;
		foreach (j, x; a)
		{
			int cur = 0;
			foreach (i; 0..limit)
			{
				if (x & (1 << i))
				{
					if (c[i] == 1)
					{
						cur |= 1 << i;
					}
				}
			}
			if (res < cur)
			{
				res = cur;
				pos = j.to !(int);
			}
		}

		write (a[pos]);
		writefln ("%( %s%)", chain (a[0..pos], a[pos + 1..$]));
	}
}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
	int n = rint;
	long[] as = rlong(n);

	int[] cnt = new int[](30);
	foreach(a; as){
		foreach(i; 0 .. 30){
			long m = 1L << i;
			if(m & a) cnt[i] += 1;
		}
	}

	int maxi = -1;
	foreach(i; 0 .. 30) if(cnt[i] == 1) maxi = i;

	long[] ans;
	if(maxi >= 0){
		foreach(a; as){
			long m = 1L << maxi;
			if(m & a) ans ~= a;
		}
		foreach(a; as) if(a != ans[0]) ans ~= a;
	}
	else ans = as;

	ans.map!(to!string).array.join(" ").writeln;

}

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 N = readInt();
      auto A = new long[N];
      foreach (i; 0 .. N) {
        A[i] = readLong();
      }

      auto ls = new long[N + 1];
      foreach (i; 0 .. N) {
        ls[i + 1] = ls[i] | A[i];
      }
      auto rs = new long[N + 1];
      foreach_reverse (i; 0 .. N) {
        rs[i] = A[i] | rs[i + 1];
      }

      long ans = -1;
      int im = -1;
      foreach (i; 0 .. N) {
        if (chmax(ans, A[i] & ~ls[i] & ~rs[i + 1])) {
          im = i;
        }
      }
      debug {
        writeln(ans, " ", im);
      }
      auto as = A.dup;
      swap(as[0], as[im]);
      foreach (j; 0 .. N) {
        if (j > 0) write(" ");
        write(as[j]);
      }
      writeln();
    }
  } catch (EOFException e) {
  }
}

import std.algorithm : max, maxElement;
import std.container : Array;
import std.stdio : stdin, write, writeln;
import std.typecons : Tuple, tuple;

struct IO {
    string readToken() {
        import std.range : empty, front, popFront, split;
        import std.stdio : readln;

        while (tokens.empty) {
            tokens = readln.split;
        }
        auto token = tokens.front;
        tokens.popFront;
        return token;
    }

    int readInt() {
        import std.conv : to;

        return readToken.to!int;
    }

    string[] tokens;
}

void main() {
    import std.algorithm : swap;

    IO io;
    int n = io.readInt;
    int[] a = new int[n];
    for (int i = 0; i < n; ++i) {
        a[i] = io.readInt;
    }
    int m = 0;
    for (int k = 30; k >= 0; --k) {
        int found = -1;
        for (int i = m; i < n; ++i) {
            if (a[i] >> k & 1) {
                if (found == -1) {
                    found = i;
                }
                else {
                    found = n;
                }
            }
        }
        if (m <= found && found < n) {
            swap(a[m++], a[found]);
        }
    }
    for (int i = 0; i < n; ++i) {
        writeln(a[i]);
    }
}

import std.container;
import std.algorithm;
import std.range;
import std.array;
import std.stdio;
import std.utf;
import std.math;
import std.typecons;

DList!string _words;

void read(T...)(ref T t)
{
  void singleRead(W)(ref W w)
  {
    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;
    w = to!W(word);
  }
  static foreach(i; 0 .. T.length)
    {
      static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))
        {
          foreach(ref element; t[i])
            read(element);
        }
      else
        {
          singleRead(t[i]);
        }
    }
}

auto next(T)()
{
  T t;
  read(t);
  return t;
}

size_t ind(T)(T t)
{
  return cast(size_t)t;
}

ref auto at(R, I)(ref R r, I i)
{
  return r[cast(size_t)i];
}

void set(R, I, V)(ref R r, I i, V v)
{
  r[cast(size_t)i] = v;
}

import std.conv;
import std.traits;
import std.meta;
int _loglevel = -1;
void _log(string functionName, argSeq...)()
{
  foreach(i; 0 .. _loglevel * 4)
    write(' ');
  write(functionName);
  static foreach(arg; argSeq)
    {
      write(" ", arg.stringof, " = ", arg);
    }
  writeln;
}
enum logCall =
  q{
    debug
    {
     {
     _loglevel++;
     alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, ".").back));
     static if (_parameterTuple.length > 0)
       mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(", ").array, `);`);
     else
       _log!(__FUNCTION__);
      }
     foreach(i; 0 .. _loglevel * 4) write(' ');
     writeln('{');
     scope(exit)
       {
         foreach(i; 0 .. _loglevel * 4) write(' ');
         writeln('}');
         _loglevel--;
       }
    }
};

void logSym(S...)(int line = __LINE__, string file = __FUNCTION__)
{
  debug
    {
      foreach(i; 0 .. _loglevel * 4) write(' ');
      write(file, "(", line, "):");
      static foreach(s; S)
        write(" ", s.stringof, " = ", s);
      writeln;

    }
}

Array!E makeArray(E, S)(S size, lazy E value)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  foreach(ref ai; a)
    ai = value();
  return a;
}
Array!E makeArray(E, S)(S size)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  return a;
}

E[] makeSlice(E, S)(S size, lazy E value)
{
  auto a = new E[size.ind];
  foreach(ref ai; a)
    ai = value();
  return a;
}

E[] makeSlice(E, S)(S size = 0)
{
  return new E[size.ind];
}

template mem(alias F)
{
  ReturnType!F[Tuple!(Parameters!F)] table;
  ReturnType!F mem(Parameters!F args)
  {
    return table.require(tuple(args), F(args));
  }
}

string input(string names, string type = "long")
{
  return text(type, " ", names, "; read(", names, ");");
}

auto pmod(T, W)(T t, W w)
{
  return (t%w + w) % w;
}

void rep(S, F)(F f, S times)
{
  foreach(i; 0 .. times)
    {
      static if (is(typeof(f(i))))
        {
          f(i);
        }
      else
        {
          f();
        }
    }
}

void main()
{
  static assert(uint.max >= 1_000_000_000);
  auto n = next!uint;
  auto a = makeSlice(n, next!uint);
  foreach_reverse(i; 0 .. 31)
    {
      auto has = a.filter!(ai => (ai & (1 << i)) != 0).array;
      if (has.length == 1)
        {
          auto initial = has[0];
          write(initial, " ");
          a.filter!(ai => ai != initial).each!(ai => write(ai, " "));
          writeln;
          return;
        }
    }
  a.each!(ai => write(ai, " "));
  writeln;
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto n = RD!int;
	auto a = RDA!int;
	int pos = -1;
	foreach_reverse (i; 0..32)
	{
		auto bit = 1L << i;
		foreach (j; 0..n)
		{
			if (a[j] & bit)
			{
				if (pos == -1)
					pos = j;
				else
				{
					pos = -1;
					break;
				}
			}
		}
		if (pos != -1)
			break;
	}

	if (pos == -1)
		a.map!(to!string).join(" ").writeln;
	else
	{
		int[] ans;
		ans ~= a[pos];
		foreach (i; 0..n)
		{
			if (i == pos) continue;
			ans ~= a[i];
		}
		ans.map!(to!string).join(" ").writeln;
	}

	stdout.flush;
	debug readln;
}


Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?

The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.

Print one integer — the number of times Kolya will have to empty the waste section.

NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.

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

void main()
{
    auto s1 = split(readln);
    //auto a = map(to!int)(s1);
    auto s2 = split(readln);
    long count;
    long sum;
    foreach (val; s2)
    {
        if (to!long(val) <= to!long(s1[1]))
            sum += to!long(val);
        if (sum > to!long(s1[2]))
        {
            sum = 0;
            count++;
        }
    }
    writeln(count);
}

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

void main()
{
    auto s1 = split(readln);
    //auto a = map(to!int)(s1);
    auto s2 = split(readln);
    long count;
    long sum;
    foreach (val; s2)
    {
        if (to!long(val) < to!long(s1[1]))
            sum += to!long(val);
        if (sum > to!long(s1[2]))
        {
            sum = 0;
            count++;
        }
    }
    writeln(count);
}