Given a set of integers (it can contain equal elements).You have to split it into two subsets $$$A$$$ and $$$B$$$ (both of them can contain equal elements or be empty). You have to maximize the value of $$$mex(A)+mex(B)$$$.Here $$$mex$$$ of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:   $$$mex(\{1,4,0,2,2,1\})=3$$$  $$$mex(\{3,3,2,1,3,0,0\})=4$$$  $$$mex(\varnothing)=0$$$ ($$$mex$$$ for empty set) The set is splitted into two subsets $$$A$$$ and $$$B$$$ if for any integer number $$$x$$$ the number of occurrences of $$$x$$$ into this set is equal to the sum of the number of occurrences of $$$x$$$ into $$$A$$$ and the number of occurrences of $$$x$$$ into $$$B$$$.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1\leq t\leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1\leq n\leq 100$$$) — the size of the set. The second line of each testcase contains $$$n$$$ integers $$$a_1,a_2,\dots a_n$$$ ($$$0\leq a_i\leq 100$$$) — the numbers in the set.

For each test case, print the maximum value of $$$mex(A)+mex(B)$$$.

NoteIn the first test case, $$$A=\left\{0,1,2\right\},B=\left\{0,1,5\right\}$$$ is a possible choice.In the second test case, $$$A=\left\{0,1,2\right\},B=\varnothing$$$ is a possible choice.In the third test case, $$$A=\left\{0,1,2\right\},B=\left\{0\right\}$$$ is a possible choice.In the fourth test case, $$$A=\left\{1,3,5\right\},B=\left\{2,4,6\right\}$$$ is a possible choice.

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;
bool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void main(string[] args){ args ~= ["", ""]; string cmd = args[1]; if(cmd == "-debug") DEBUG = 1;
if(cmd == "-gen") gen; else if(cmd == "-jury") jury; else solve; }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ std.stdio.write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void gen(){
}
void jury(){
}
void solve(){
    foreach(_; 0 .. scan!int){
        int n = scan!int;
        int[] as = scan!int(n);

        int[int] acnt;
        foreach(a; as){
            if(a !in acnt) acnt[a] = 0;
            acnt[a] += 1;
        }

        int ans = 0;
        int i = 0;

        while(i in acnt && acnt[i] >= 2) i ++;
        ans += i;

        while(i in acnt && acnt[i] >= 1) i ++;
        ans += i;

        ans.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 = 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;
		a.sort();

		long x, y;
		foreach (i; 0..n)
		{
			if (x == a[i])
				++x;
			else if (y == a[i])
				++y;
		}
		ans[ti] = x+y;
	}

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


Bob is an avid fan of the video game "League of Leesins", and today he celebrates as the League of Leesins World Championship comes to an end! The tournament consisted of $$$n$$$ ($$$n \ge 5$$$) teams around the world. Before the tournament starts, Bob has made a prediction of the rankings of each team, from $$$1$$$-st to $$$n$$$-th. After the final, he compared the prediction with the actual result and found out that the $$$i$$$-th team according to his prediction ended up at the $$$p_i$$$-th position ($$$1 \le p_i \le n$$$, all $$$p_i$$$ are unique). In other words, $$$p$$$ is a permutation of $$$1, 2, \dots, n$$$.As Bob's favorite League player is the famous "3ga", he decided to write down every $$$3$$$ consecutive elements of the permutation $$$p$$$. Formally, Bob created an array $$$q$$$ of $$$n-2$$$ triples, where $$$q_i = (p_i, p_{i+1}, p_{i+2})$$$ for each $$$1 \le i \le n-2$$$. Bob was very proud of his array, so he showed it to his friend Alice.After learning of Bob's array, Alice declared that she could retrieve the permutation $$$p$$$ even if Bob rearranges the elements of $$$q$$$ and the elements within each triple. Of course, Bob did not believe in such magic, so he did just the same as above to see Alice's respond.For example, if $$$n = 5$$$ and $$$p = [1, 4, 2, 3, 5]$$$, then the original array $$$q$$$ will be $$$[(1, 4, 2), (4, 2, 3), (2, 3, 5)]$$$. Bob can then rearrange the numbers within each triple and the positions of the triples to get $$$[(4, 3, 2), (2, 3, 5), (4, 1, 2)]$$$. Note that $$$[(1, 4, 2), (4, 2, 2), (3, 3, 5)]$$$ is not a valid rearrangement of $$$q$$$, as Bob is not allowed to swap numbers belong to different triples.As Alice's friend, you know for sure that Alice was just trying to show off, so you decided to save her some face by giving her any permutation $$$p$$$ that is consistent with the array $$$q$$$ she was given.

The first line contains a single integer $$$n$$$ ($$$5 \le n \le 10^5$$$) — the size of permutation $$$p$$$. The $$$i$$$-th of the next $$$n-2$$$ lines contains $$$3$$$ integers $$$q_{i, 1}$$$, $$$q_{i, 2}$$$, $$$q_{i, 3}$$$ ($$$1 \le q_{i, j} \le n$$$) — the elements of the $$$i$$$-th triple of the rearranged (shuffled) array $$$q_i$$$, in random order. Remember, that the numbers within each triple can be rearranged and also the positions of the triples can be rearranged. It is guaranteed that there is at least one permutation $$$p$$$ that is consistent with the input.

Print $$$n$$$ distinct integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \le p_i \le n$$$) such that $$$p$$$ is consistent with array $$$q$$$.  If there are multiple answers, print any.

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

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 = 998244353;
//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 n = RD!int;
	auto q = new int[][](n-2, 3);
	auto pos = new int[][](n);
	foreach (i; 0..n-2)
	{
		q[i] = [RD!int-1, RD!int-1, RD!int-1];
		foreach (j; 0..3)
		{
			pos[q[i][j]] ~= i;
		}
	}

	size_t[] ans;
	int p;
	foreach (i, e; pos)
	{
		if (e.length == 1)
		{
			p = e[0];
			break;
		}
	}

	auto used = new bool[](n-2);
	while (ans.length != n)
	{
		used[p] = true;
		int[3] cnt;
		auto cnt2 = new int[](3);
		foreach (i, e; q[p])
		{
			foreach (ee; pos[e])
			{
				++cnt2[i];
				if (!used[ee])
					++cnt[i];
			}
		}
		if (cnt2.sum == 6)
		{
			if (!ans.empty)
			{
				auto index = cnt2.MAKE_IDX!"a > b";
				foreach (i; index)
				{
					ans ~= q[p][i]+1;
				}
				break;
			}
		}
		foreach (i, e; q[p])
		{
			if (cnt[i] == 0)
				ans ~= e+1;
			if (cnt[i] == 1)
			{
				foreach (ee; pos[e])
				{
					if (!used[ee])
						p = ee;
				}
			}
		}
		debug writeln(ans);
	}

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

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.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; }

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 = 998244353;
//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 n = RD!int;
	auto q = new int[][](n-2, 3);
	auto pos = new int[][](n);
	foreach (i; 0..n-2)
	{
		q[i] = [RD!int-1, RD!int-1, RD!int-1];
		foreach (j; 0..3)
		{
			pos[q[i][j]] ~= i;
		}
	}

	size_t[] ans;
	int p;
	foreach (i, e; pos)
	{
		if (e.length == 1)
		{
			p = e[0];
			break;
		}
	}

	auto used = new bool[](n-2);
	while (ans.length != n)
	{
		used[p] = true;
		int[3] cnt;
		foreach (i, e; q[p])
		{
			foreach (ee; pos[e])
			{
				if (!used[ee])
					++cnt[i];
			}
		}
		foreach (i, e; q[p])
		{
			if (cnt[i] == 0)
				ans ~= e+1;
			if (cnt[i] == 1)
			{
				foreach (ee; pos[e])
				{
					if (!used[ee])
						p = ee;
				}
			}
		}
		debug writeln(ans);
	}

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


William is hosting a party for $$$n$$$ of his trader friends. They started a discussion on various currencies they trade, but there's an issue: not all of his trader friends like every currency. They like some currencies, but not others.For each William's friend $$$i$$$ it is known whether he likes currency $$$j$$$. There are $$$m$$$ currencies in total. It is also known that a trader may not like more than $$$p$$$ currencies.Because friends need to have some common topic for discussions they need to find the largest by cardinality (possibly empty) subset of currencies, such that there are at least $$$\lceil \frac{n}{2} \rceil$$$ friends (rounded up) who like each currency in this subset.

The first line contains three integers $$$n, m$$$ and $$$p$$$ $$$(1 \le n \le 2 \cdot 10^5, 1 \le p \le m \le 60, 1 \le p \le 15)$$$, which is the number of trader friends, the number of currencies, the maximum number of currencies each friend can like. Each of the next $$$n$$$ lines contain $$$m$$$ characters. The $$$j$$$-th character of $$$i$$$-th line is $$$1$$$ if friend $$$i$$$ likes the currency $$$j$$$ and $$$0$$$ otherwise. It is guaranteed that the number of ones in each line does not exceed $$$p$$$.

Print a string of length $$$m$$$, which defines the subset of currencies of the maximum size, which are liked by at least half of all friends. Currencies belonging to this subset must be signified by the character $$$1$$$. If there are multiple answers, print any.

NoteIn the first sample test case only the first currency is liked by at least $$$\lceil \frac{3}{2} \rceil = 2$$$ friends, therefore it's easy to demonstrate that a better answer cannot be found.In the second sample test case the answer includes $$$2$$$ currencies and will be liked by friends $$$1$$$, $$$2$$$, and $$$5$$$. For this test case there are other currencies that are liked by at least half of the friends, but using them we cannot achieve a larger subset size.

import core.bitop;
import std.algorithm;
import std.conv;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int steps = 30;

void main ()
{
	int n, m, p;
	while (readf !(" %s %s %s") (n, m, p) > 0)
	{
		auto s = new long [n];
		foreach (ref x; s)
		{
			readf !(" %b") (x);
		}

		long answer = 0;
		foreach (step; 0..steps)
		{
			auto z = s[uniform (0, $)];
			auto k = popcnt (z);
			auto k2 = 1 << k;

			int [] bits;
			foreach (i; 0..m)
			{
				if (z & (1L << i))
				{
					bits ~= i;
				}
			}

			auto c = new int [k2];
			foreach (ref x; s)
			{
				int bx = 0;
				foreach (j; 0..k)
				{
					if (x & (1L << bits[j]))
					{
						bx |= 1 << j;
					}
				}
				c[bx] += 1;
			}

			auto d = new int [k2];
			for (auto y = k2 - 1; y > 0; y--)
			{
				auto cur = c[y];
				for (auto x = y; x > 0; x = (x - 1) & y)
				{
					d[x] += cur;
				}
			}

			for (auto y = k2 - 1; y > 0; y--)
			{
				auto cur = d[y];
				if (cur >= (n + 1) / 2)
				{
					if (popcnt (answer) < popcnt (y))
					{
						long ey = 0;
						foreach (j; 0..k)
						{
							if (y & (1 << j))
							{
								ey |= 1L <<
								    bits[j];
							}
						}
						answer = ey;
					}
				}
			}
		}

		writefln !("%0*b") (m, answer);
	}
}


For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations.Max is a young biologist. For $$$n$$$ days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All the distances are distinct. Max wants to know now how many locations the shark visited. He assumed there is such an integer $$$k$$$ that if the shark in some day traveled the distance strictly less than $$$k$$$, then it didn't change the location; otherwise, if in one day the shark traveled the distance greater than or equal to $$$k$$$; then it was changing a location in that day. Note that it is possible that the shark changed a location for several consecutive days, in each of them the shark traveled the distance at least $$$k$$$.The shark never returned to the same location after it has moved from it. Thus, in the sequence of $$$n$$$ days we can find consecutive nonempty segments when the shark traveled the distance less than $$$k$$$ in each of the days: each such segment corresponds to one location. Max wants to choose such $$$k$$$ that the lengths of all such segments are equal.Find such integer $$$k$$$, that the number of locations is as large as possible. If there are several such $$$k$$$, print the smallest one.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of days. The second line contains $$$n$$$ distinct positive integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the distance traveled in each of the day.

Print a single integer $$$k$$$, such that    the shark was in each location the same number of days,  the number of locations is maximum possible satisfying the first condition,  $$$k$$$ is smallest possible satisfying the first and second conditions.

NoteIn the first example the shark travels inside a location on days $$$1$$$ and $$$2$$$ (first location), then on $$$4$$$-th and $$$5$$$-th days (second location), then on $$$7$$$-th and $$$8$$$-th days (third location). There are three locations in total.In the second example the shark only moves inside a location on the $$$2$$$-nd day, so there is only one location.

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

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto B = N.iota.map!(i => tuple(A[i], i)).array;
    B.sort();

    auto used = new int[](N);
    auto uf = new UnionFind(N);

    used[B[0][1]] = true;
    int max_locs = 1;
    int ans = B[0][0] + 1;
    uf.cnt = 1;
    uf.lens[1] = 1;

    foreach (i; 1..N) {
        int v = B[i][0];
        int n = B[i][1];
        used[n] = true;
        uf.cnt += 1;
        uf.lens[1] += 1;
        int lens = uf.lens[1];
        if (n > 0 && used[n-1]) lens = uf.unite(n, n-1);
        if (n < N-1 && used[n+1]) lens = uf.unite(n, n+1);
        if (lens == uf.cnt) {
            if (uf.cnt > max_locs) {
                max_locs = uf.cnt;
                ans = v + 1;
            }
        }
    }

    ans.writeln;
}

class UnionFind {
    int N;
    int[] table;
    Tuple!(int, int)[] segs;
    int[] lens;
    int cnt;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
        segs = N.iota.map!(i => tuple(i, i)).array;
        lens = new int[](N+10);
        cnt = 0;
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    int unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return -1;
        if (table[x] > table[y]) swap(x, y);
        cnt -= 1;
        table[x] += table[y];
        lens[segs[x][1] - segs[x][0] + 1] -= 1;
        lens[segs[y][1] - segs[y][0] + 1] -= 1;
        segs[x] = tuple(min(segs[x][0], segs[y][0]), max(segs[x][1], segs[y][1]));
        lens[segs[x][1] - segs[x][0] + 1] += 1;
        table[y] = x;
        return lens[segs[x][1] - segs[x][0] + 1];
    }
}

import std.stdio;
import std.range;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;

auto biggestBit(T)(T t)
{
  debug assert(t != 0);
  int bitpos = -1;
  while(t)
    {
      t >>= 1;
      bitpos++;
    }
  return bitpos;
}

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);

  auto n = next!int;
  auto a = next!int(n);
  auto numRows = n.biggestBit;
  auto maxIn = new int[][](numRows + 1, n);
  foreach(r; 0 .. numRows + 1)
    maxIn[r][] = -1;
  foreach(i; 0 .. n)
    maxIn[0][i] = i;
  foreach(p; 1 .. numRows + 1)
    {
      foreach(i; 0 .. n)
        {
          if ((i + (1 << (p)) - 1) >= n)
            continue;
          auto v0 = a[maxIn[p - 1][i]];
          auto v1 = a[maxIn[p - 1][i + (1 << (p - 1))]];
          if (v0 > v1)
            maxIn[p][i] = maxIn[p - 1][i];
          else
            maxIn[p][i] = maxIn[p - 1][i + (1 << (p - 1))];
        }
    }
  debug writeln(maxIn);
  auto maxInRange(int s, int e)
  {
    auto len = e - s + 1;
    auto p = len.biggestBit;
    auto lenwithoutbb = len - (1 << p);
    auto v0 = a[maxIn[p][s]];
    auto v1 = a[maxIn[p][s + lenwithoutbb]];
    if (v0 > v1)
      return maxIn[p][s];
    return maxIn[p][s + lenwithoutbb];
  }

  auto poolSize = new int[](n);
  void doPoolSize(int s, int e)
  {
    if (s > e)
      return;
    auto len = e - s + 1;
    auto mxi = maxInRange(s, e);
    debug writeln("in range ", s, " - ", e, " max is ", a[mxi], " with len ", len);
    assert(mxi >= s && mxi <= e);
    poolSize[mxi] = len;
    doPoolSize(s, mxi - 1);
    doPoolSize(mxi + 1, e);
  }
  doPoolSize(0, n - 1);
  debug writeln(poolSize);
  auto sortedIndexes = iota(0, n).array.sort!((i, j) => a[i] < a[j]).array;
  auto lastInd = new int[](n + 1);
  auto bestBySize = new int[](n + 1);
  int bestSize = 0;
  lastInd[] = -1;
  debug foreach(i, ind; sortedIndexes)
    {
      write(poolSize[ind], " ");
    }
  debug writeln;
  foreach(i, ind; sortedIndexes)
    {
      auto s = poolSize[ind];
      auto l = lastInd[s];
      if (i - l == s)
        {
          bestBySize[s]++;
          bestSize = max(bestBySize[s], bestSize);
          lastInd[s] = cast(int)i;
        }
    }
  debug writeln(bestBySize);
  int minimalUp = int.max;
  foreach(s, b; bestBySize)
    {
      if (s != 0 && b == bestSize)
        {
          minimalUp = min(minimalUp, s * b - 1);
        }
    }
  auto minV = a[sortedIndexes[minimalUp]];
  (minV + 1).writeln;
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

import std.stdio;
import std.range;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;

auto biggestBit(T)(T t)
{
  debug assert(t != 0);
  int bitpos = -1;
  while(t)
    {
      t >>= 1;
      bitpos++;
    }
  return bitpos;
}

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);

  auto n = next!int;
  auto a = next!int(n);
  auto numRows = n.biggestBit;
  auto maxIn = new int[][](numRows + 1, n);
  foreach(r; 0 .. numRows + 1)
    maxIn[r][] = -1;
  foreach(i; 0 .. n)
    maxIn[0][i] = i;
  auto maxInd(int i, int j)
  {
    return a[i] > a[j]? i : j;
  }
  foreach(p; 1 .. numRows + 1)
    {
      foreach(i; 0 .. n)
        {
          if ((i + (1 << (p)) - 1) >= n)
            continue;
          maxIn[p][i] = maxInd(maxIn[p - 1][i], maxIn[p - 1][i + (1 << (p - 1))]);
        }
    }
  debug writeln(maxIn);
  auto maxInRange(int s, int e)
  {
    auto len = e - s + 1;
    auto p = len.biggestBit;
    auto lenwithoutbb = len - (1 << p);
    return maxInd(maxIn[p][s], maxIn[p][s + lenwithoutbb]);
  }

  auto poolSize = new int[](n);
  void doPoolSize(int s, int e)
  {
    if (s > e)
      return;
    auto len = e - s + 1;
    auto mxi = maxInRange(s, e);
    debug writeln("in range ", s, " - ", e, " max is ", a[mxi], " with len ", len);
    assert(mxi >= s && mxi <= e);
    poolSize[mxi] = len;
    doPoolSize(s, mxi - 1);
    doPoolSize(mxi + 1, e);
  }
  doPoolSize(0, n - 1);
  debug writeln(poolSize);
  auto sortedIndexes = iota(0, n).array.sort!((i, j) => a[i] < a[j]).array;
  auto sizeCnt = new int[](n + 1);
  auto bestBySize = new int[](n + 1);
  int bestSize = 0;
  debug foreach(i, ind; sortedIndexes)
    {
      write(poolSize[ind], " ");
    }
  debug writeln;
  foreach(i, ind; sortedIndexes)
    {
      auto s = poolSize[ind];
      sizeCnt[s]++;
      debug if (s == 3) {writeln("sizeCnt ", s, " ", sizeCnt[s], " i ", i);}
      if (sizeCnt[s] * s - 1 == i)
        {
          bestBySize[s] = sizeCnt[s];
          bestSize = max(bestBySize[s], bestSize);
        }
    }
  debug writeln("bestBySize: ", bestBySize);
  int minimalUp = int.max;
  foreach(s, b; bestBySize)
    {
      if (s != 0 && b == bestSize)
        {
          minimalUp = min(minimalUp, s * b - 1);
        }
    }
  auto minV = a[sortedIndexes[minimalUp]];
  (minV + 1).writeln;
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

import std.stdio;
import std.range;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;

auto biggestBit(T)(T t)
{
  debug assert(t != 0);
  int bitpos = -1;
  while(t)
    {
      t >>= 1;
      bitpos++;
    }
  return bitpos;
}

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);

  auto n = next!int;
  auto a = next!int(n);
  auto numRows = n.biggestBit;
  auto maxIn = new int[][](numRows + 1, n);
  foreach(r; 0 .. numRows + 1)
    maxIn[r][] = -1;
  foreach(i; 0 .. n)
    maxIn[0][i] = i;
  auto maxInd(int i, int j)
  {
    return a[i] > a[j]? i : j;
  }
  foreach(p; 1 .. numRows + 1)
    {
      foreach(i; 0 .. n)
        {
          if ((i + (1 << (p)) - 1) >= n)
            continue;
          maxIn[p][i] = maxInd(maxIn[p - 1][i], maxIn[p - 1][i + (1 << (p - 1))]);
        }
    }
  debug writeln(maxIn);
  auto maxInRange(int s, int e)
  {
    auto len = e - s + 1;
    auto p = len.biggestBit;
    auto lenwithoutbb = len - (1 << p);
    return maxInd(maxIn[p][s], maxIn[p][s + lenwithoutbb]);
  }

  auto poolSize = new int[](n);
  void doPoolSize(int s, int e)
  {
    if (s > e)
      return;
    auto len = e - s + 1;
    auto mxi = maxInRange(s, e);
    debug writeln("in range ", s, " - ", e, " max is ", a[mxi], " with len ", len);
    assert(mxi >= s && mxi <= e);
    poolSize[mxi] = len;
    doPoolSize(s, mxi - 1);
    doPoolSize(mxi + 1, e);
  }
  doPoolSize(0, n - 1);
  debug writeln(poolSize);
  auto sortedIndexes = iota(0, n).array.sort!((i, j) => a[i] < a[j]).array;
  auto lastInd = new int[](n + 1);
  auto sizeCnt = new int[](n + 1);
  auto bestBySize = new int[](n + 1);
  int bestSize = 0;
  lastInd[] = -1;
  debug foreach(i, ind; sortedIndexes)
    {
      write(poolSize[ind], " ");
    }
  debug writeln;
  foreach(i, ind; sortedIndexes)
    {
      auto s = poolSize[ind];
      sizeCnt[s]++;
      auto l = lastInd[s];
      debug if (s == 3) {writeln("sizeCnt ", s, " ", sizeCnt[s], " i ", i);}
      if (sizeCnt[s] * s - 1 == i)
        {
          bestBySize[s] = sizeCnt[s];
          bestSize = max(bestBySize[s], bestSize);
          lastInd[s] = cast(int)i;
        }
    }
  debug writeln("bestBySize: ", bestBySize);
  int minimalUp = int.max;
  foreach(s, b; bestBySize)
    {
      if (s != 0 && b == bestSize)
        {
          minimalUp = min(minimalUp, s * b - 1);
        }
    }
  auto minV = a[sortedIndexes[minimalUp]];
  (minV + 1).writeln;
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

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

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto B = N.iota.map!(i => tuple(A[i], i)).array;
    B.sort();

    auto used = new int[](N);
    auto uf = new UnionFind(N);

    used[0] = true;
    int max_locs = 1;
    int ans = B[0][1] + 1;
    uf.cnt = 1;

    foreach (i; 1..N) {
        int v = B[i][0];
        int n = B[i][1];
        used[n] = true;
        uf.cnt += 1;
        int lens = -1;
        if (n > 0 && used[n-1]) lens = uf.unite(n, n-1);
        if (n < N-1 && used[n+1]) lens = uf.unite(n, n+1);
        if (lens > 0 && lens == uf.cnt) {
            if (uf.cnt > max_locs) {
                max_locs = uf.cnt;
                ans = v + 1;
            }
        }
    }

    ans.writeln;
}

class UnionFind {
    int N;
    int[] table;
    Tuple!(int, int)[] segs;
    int[] lens;
    int cnt;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
        segs = N.iota.map!(i => tuple(i, i)).array;
        lens = new int[](N+1);
        cnt = 0;
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    int unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return -1;
        if (table[x] > table[y]) swap(x, y);
        cnt -= 1;
        table[x] += table[y];
        lens[segs[x][1] - segs[x][0] + 1] -= 1;
        lens[segs[y][1] - segs[y][0] + 1] -= 1;
        segs[x] = tuple(min(segs[x][0], segs[y][0]), max(segs[x][1], segs[y][1]));
        lens[segs[x][1] - segs[x][0] + 1] += 1;
        table[y] = x;
        return lens[segs[x][1] - segs[x][0] + 1];
    }
}


Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases:   They are equal.  If we split string a into two halves of the same size a1 and a2, and string b into two halves of the same size b1 and b2, then one of the following is correct:   a1 is equivalent to b1, and a2 is equivalent to b2  a1 is equivalent to b2, and a2 is equivalent to b1  As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.Gerald has already completed this home task. Now it's your turn!

The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200 000 and consists of lowercase English letters. The strings have the same length.

Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.

NoteIn the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa".

import std.stdio, std.string;
T x(T)(T a) {
	if (a.length&1) return a;
	auto b=a[0..$/2].x, c=a[$/2..$].x;
	return b<c ? b~c : c~b;
}
void main() {writeln (readln.strip.x==readln.strip.x ? "YES" : "NO");}

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

string canonize (string a)
{
	if (a.length % 2 == 0)
	{
		string b = canonize (a[0..$ / 2]);
		string c = canonize (a[$ / 2..$]);
		return min (b, c) ~ max (b, c);
	}
	return a;
}

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		string t = readln.strip;
		writeln ((canonize (s) == canonize (t)) ? "YES" : "NO");
	}
}

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

T x (T) (T a)
{
	if (a.length & 1) return a;
	auto b = x (a[0..$ / 2]), c = x (a[$ / 2..$]);
	return min (b, c) ~ max (b, c);
}

void main ()
{
	writeln (readln.strip.x == readln.strip.x ? "YES" : "NO");
}

T x(T)(T a){if(a.length&1)return a;auto b=a[0..$/2].x,c=a[$/2..$].x;return b<c?b~c:c~b;}
void main(){import std.stdio;writeln(readln[0..$-1].x==readln[0..$-1].x?"YES":"NO");}

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

bool ok (string a, string b)
{
	if (a.length % 2 == 0)
	{
		if ((a[0..$ / 2] < a[$ / 2..$]) ==
		    (b[0..$ / 2] < b[$ / 2..$]))
		{
			return ok (a[0..$ / 2], b[0..$ / 2]) &&
			    ok (a[$ / 2..$], b[$ / 2..$]);
		}
		else
		{
			return ok (a[0..$ / 2], b[$ / 2..$]) &&
			    ok (a[$ / 2..$], b[0..$ / 2]);
		}
	}
	else
	{
		return a == b;
	}
}

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		string t = readln.strip;
		writeln (ok (s, t) ? "YES" : "NO");
	}
}


Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to the player with the larger number and returns the balls to the jar. The winner of the game is the one who wins at least two of the three rounds.Andrew wins rounds 1 and 2 while Jerry wins round 3, so Andrew wins the game. However, Jerry is unhappy with this system, claiming that he will often lose the match despite having the higher overall total. What is the probability that the sum of the three balls Jerry drew is strictly higher than the sum of the three balls Andrew drew?

The first line of input contains a single integer n (2 ≤ n ≤ 2000) — the number of balls in the jar. The second line contains n integers ai (1 ≤ ai ≤ 5000) — the number written on the ith ball. It is guaranteed that no two balls have the same number.

Print a single real value — the probability that Jerry has a higher total, given that Andrew wins the first two rounds and Jerry wins the third. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.  Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

NoteIn the first case, there are only two balls. In the first two rounds, Andrew must have drawn the 2 and Jerry must have drawn the 1, and vice versa in the final round. Thus, Andrew's sum is 5 and Jerry's sum is 4, so Jerry never has a higher total.In the second case, each game could've had three outcomes — 10 - 2, 10 - 1, or 2 - 1. Jerry has a higher total if and only if Andrew won 2 - 1 in both of the first two rounds, and Jerry drew the 10 in the last round. This has probability .

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 MAX_DELTA = 5007;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(int)).array;

		auto d = new real [MAX_DELTA];
		d[] = 0.0;
		foreach (i; 0..n)
		{
			foreach (j; 0..n)
			{
				if (a[i] > a[j])
				{
					d[a[i] - a[j]]++;
				}
			}
		}
		d[] /= n * (n - 1) * 0.5;

		auto e = new real [MAX_DELTA * 2];
		e[] = 0.0;
		foreach (i; 0..MAX_DELTA)
		{
			foreach (j; 0..MAX_DELTA)
			{
				e[i + j] += d[i] * d[j];
			}
		}

		real res = 0.0;
		foreach (i; 0..MAX_DELTA)
		{
			foreach (j; 0..i)
			{
				res += d[i] * e[j];
			}
		}

		writeln (res);
	}
}


It is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfortunately, he lives far from kindergarten, and his father is too busy to drive him there. The only choice for this poor little boy is to wait for a bus on this rainy day. Under such circumstances, the poor boy will use the first bus he sees no matter where it goes. If several buses come at the same time, he will choose one randomly.Serval will go to the bus station at time $$$t$$$, and there are $$$n$$$ bus routes which stop at this station. For the $$$i$$$-th bus route, the first bus arrives at time $$$s_i$$$ minutes, and each bus of this route comes $$$d_i$$$ minutes later than the previous one.As Serval's best friend, you wonder which bus route will he get on. If several buses arrive at the same time, you can print any of them.

The first line contains two space-separated integers $$$n$$$ and $$$t$$$ ($$$1\leq n\leq 100$$$, $$$1\leq t\leq 10^5$$$) — the number of bus routes and the time Serval goes to the station.  Each of the next $$$n$$$ lines contains two space-separated integers $$$s_i$$$ and $$$d_i$$$ ($$$1\leq s_i,d_i\leq 10^5$$$) — the time when the first bus of this route arrives and the interval between two buses of this route.

Print one number — what bus route Serval will use. If there are several possible answers, you can print any of them.

NoteIn the first example, the first bus of the first route arrives at time $$$6$$$, and the first bus of the second route arrives at time $$$9$$$, so the first route is the answer.In the second example, a bus of the third route arrives at time $$$5$$$, so it is the answer.In the third example, buses of the first route come at times $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$, and so fourth, buses of the second route come at times $$$2$$$, $$$5$$$, $$$8$$$, and so fourth and buses of the third route come at times $$$2$$$, $$$6$$$, $$$10$$$, and so on, so $$$1$$$ and $$$2$$$ are both acceptable answers while $$$3$$$ is not.

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

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto T = s[1].to!long;

    long idx = -1;
    long ans = 1L << 59;

    foreach (i; 0..N) {
        s = readln.split.map!(to!int);
        auto a = s[0].to!long;
        auto b = s[1].to!long;
        long tmp;
        if (a >= T) {
            tmp = a;
        } else {
            long m1 = T % b;
            long m2 = a % b;
            if (m1 <= m2) {
                tmp = T + m2 - m1;
            } else {
                tmp = T + b - m1 + m2;
            }
        }
        if (tmp < ans) {
            ans = tmp;
            idx = i + 1;
        }
    }

    idx.writeln;
}

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

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

const long mod = 1_000_000_007;

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

	int n = read.to!int;
	long t = read.to!long;

	long[] ss, ds;
	foreach(i; 0 .. n){
		ss ~= read.to!long;
		ds ~= read.to!long;
	}

	long bestx = 10_000_000, ans = -1;
	foreach(i; 0 .. n){
		long s = ss[i], d = ds[i];
		long x;
		if(s >= t) x = s;
		else x = s + (t - s + d - 1) / d * d;

		if(x < bestx){
			bestx = x;
			ans = i + 1;
		}
	}

	ans.writeln;

}

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; }
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; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
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 N = RD;
	auto T = RD;

	long best = long.max;
	long ans;
	foreach (i; 0..N)
	{
		auto s = RD;
		auto d = RD;
		auto x = s - T;
		auto y = abs(x / d);
		if (x < 0)
		{
			x += (y+1) * d;
			x %= d;
		}
		if (x < best)
		{
			best = x;
			ans = i + 1;
		}
		debug writeln(i, " ", best, " ", ans);
	}

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


Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.One day Petya encountered a tree with n vertexes. Besides, the tree was weighted, i. e. each edge of the tree has weight (a positive integer). An edge is lucky if its weight is a lucky number. Note that a tree with n vertexes is an undirected connected graph that has exactly n - 1 edges.Petya wondered how many vertex triples (i, j, k) exists that on the way from i to j, as well as on the way from i to k there must be at least one lucky edge (all three vertexes are pairwise distinct). The order of numbers in the triple matters, that is, the triple (1, 2, 3) is not equal to the triple (2, 1, 3) and is not equal to the triple (1, 3, 2). Find how many such triples of vertexes exist.

The first line contains the single integer n (1 ≤ n ≤ 105) — the number of tree vertexes. Next n - 1 lines contain three integers each: ui vi wi (1 ≤ ui, vi ≤ n, 1 ≤ wi ≤ 109) — the pair of vertexes connected by the edge and the edge's weight.

On the single line print the single number — the answer. Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is recommended to use the cin, cout streams or the %I64d specificator.

NoteThe 16 triples of vertexes from the first sample are: (1, 2, 4), (1, 4, 2), (2, 1, 3), (2, 1, 4), (2, 3, 1), (2, 3, 4), (2, 4, 1), (2, 4, 3), (3, 2, 4), (3, 4, 2), (4, 1, 2), (4, 1, 3), (4, 2, 1), (4, 2, 3), (4, 3, 1), (4, 3, 2).In the second sample all the triples should be counted: 4·3·2 = 24.

import std.stdio;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;
import std.range;
import std.numeric;

void main(string[] args)
{
  inputFile = stdin;
  auto n = next!int;
  struct Adj
  {
    int nei;
    bool lucky;
  }
  auto adj = new Adj[][](n);
  foreach(e; 0 .. n - 1)
    {
      auto u = next!int - 1;
      auto v = next!int - 1;
      auto w = next!string;
      auto lucky = w.all!(c => c == '4' || c == '7');
      adj[u] ~= Adj(v, lucky);
      adj[v] ~= Adj(u, lucky);
    }
  auto luckyPaths = new int[](n);
  auto subtreeSize = new int[](n);
  void dfs1(int v, int p)
  {
    luckyPaths[v] = 0;
    subtreeSize[v] = 1;
    foreach(edge; adj[v])
      if (edge.nei != p)
	{
	  dfs1(edge.nei, v);

	  if (edge.lucky)
	    luckyPaths[v] += subtreeSize[edge.nei];
	  else
	    luckyPaths[v] += luckyPaths[edge.nei];

	  subtreeSize[v] += subtreeSize[edge.nei];
	}
  }
  dfs1(0, -1);
  long notrips = 0;
  void dfs2(int v, int p, int parentLuckyPaths)
  {
    int countLucky = parentLuckyPaths;
    foreach(edge; adj[v])
      if (edge.nei != p)
	{
	  if (edge.lucky)
	    countLucky += subtreeSize[edge.nei];
	  else
	    countLucky += luckyPaths[edge.nei];
	}
    debug writeln("lucky count for ", v + 1, " is ", countLucky);
    notrips += (cast(long)countLucky) * (cast(long) countLucky - 1);
    foreach(edge; adj[v])
      if (edge.nei != p)
	{
	  if (edge.lucky)
	    {
	      dfs2(edge.nei, v, n - subtreeSize[edge.nei]);
	    }
	  else
	    {
	      dfs2(edge.nei, v, countLucky - luckyPaths[edge.nei]);
	    }
	}
  }
  dfs2(0, -1, 0);
  notrips.writeln;
}
ulong bitCnt(long x)
{
  ulong cnt = 0;
  while(x) {cnt += x & 1; x>>=1;}
  return cnt;
}
alias Arr(T) = Mat!(T, 1);
struct Mat(T, size_t dimension)
{
  T[] _baseArray;
  T[] _slice;
  size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}
  size_t[dimension] _indexer;
  this(T[] baseArray, size_t[dimension] sizes)
  {
    _baseArray = baseArray;
    _sizes = sizes;
    _indexer[dimension - 1] = 1;
    static foreach_reverse(i; 0 .. dimension - 1)
      _indexer[i] = _indexer[i + 1] * _sizes[i + 1];
    auto requiredSize = _indexer[0] * _sizes[0];
    debug assert(_baseArray.length >= requiredSize);
    _slice = _baseArray[0 .. requiredSize];
  }
  this(size_t[dimension] sizes)
  {
    size_t reqSize = 1;
    static foreach(i; 0 .. dimension)
      reqSize *= sizes[i];
    this(new T[](reqSize), sizes);
  }
  ref auto opIndex()
  {
    pragma(inline, true);
    return _slice[];
  }
  ref auto opIndex(I...)(I i)
  {
    pragma(inline, true);
    debug assert(i.length <= dimension);
    size_t index = mixin(iota(0, i.length).map!(j => text("i[", j, "]*_indexer[", j, "]")).join("+"));
    static if (i.length == dimension)
      {
	return _slice[index];
      }
    else
      {
	enum sliceDimension = dimension - i.length;
	size_t[sliceDimension] remSizes = _sizes[i.length .. $];
	auto basePortion = _slice[index .. index + _indexer[i.length - 1]];
 	return Mat!(T, sliceDimension)(basePortion, remSizes);
      }
  }
  static if (dimension == 2)
    {
      auto identity()
      {
	debug assert(dim(0) == dim(1));
	auto n = dim(0);
	auto id = Mat!(T, 2)([n, n]);
	foreach(k; 0 .. n)
	  id[k, k] = T(1);
	return id;
      }
      bool canMultiply(Mat!(T, 2) b)
      {
	return this.dim(1) == b.dim(0);
      }
      auto opBinary(string op)(Mat!(T, 2) b)
	if (op == "*")
	  {
	    debug assert(canMultiply(b));
	    auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);
	    foreach(i; 0 .. res.dim(0))
	      foreach(k; 0 .. this.dim(1))
		foreach(j; 0 .. res.dim(1))
		  res[i, j] = res[i, j] + this[i, k] * b[k, j];
	    return res;
	  }
      auto opBinary(string op)(ulong exp)
	if (op == "^^")
	  {
	    return this.pow(identity, exp);
	  }
      mixin interiorBinPow;
    }
}

struct Mod(T, ulong mod)
{
  alias This = Mod!(T, mod);
  T _rep; T rep() {return _rep;}
  this(W)(W w)
  {
    _rep = ((cast(T) w)%mod + mod) % mod;
  }
  static auto plainConstruct(T t)
  {
    pragma(inline, true);
    debug assert(t >= 0 && t < mod);
    auto res = Mod!(T, mod).init;
    res._rep = t;
    return res;
  }
  string toString()
  {
    return to!string(rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plainConstruct(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plainConstruct(resrep);
      }
    else static if (op == "*")
      {
	return This(_rep * b._rep);
      }
  }
}

mixin template interiorBinPow()
{
  alias ThisType = typeof(this);
  auto pow(ThisType res, ulong exp)
    {
      if (exp < 0) debug assert(0);
      auto pow = this;
      while(exp)
	{
	  if (exp & 1)
	    res = res * pow;
	  pow = pow * pow;
	  exp >>= 1;
	}
      return res;
    }
}

// INPUT
File inputFile;
DList!string _words;
void _wordsFill()
{
  while (_words.empty) _words.insertBack(inputFile.readln.split);
}
string popWord()
{
  _wordsFill;
  auto word = _words.front;
  _words.removeFront;
  return word;
}
string peekWord()
{
  _wordsFill;
  return _words.front;
}
T next(T)()
{
  return to!T(popWord);
}
T peek(T)()
{
  return to!T(peekWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}


Given an array $$$a$$$ of length $$$n$$$, you can do at most $$$k$$$ operations of the following type on it:  choose $$$2$$$ different elements in the array, add $$$1$$$ to the first, and subtract $$$1$$$ from the second. However, all the elements of $$$a$$$ have to remain non-negative after this operation. What is lexicographically the smallest array you can obtain?An array $$$x$$$ is lexicographically smaller than an array $$$y$$$ if there exists an index $$$i$$$ such that $$$x_i<y_i$$$, and $$$x_j=y_j$$$ for all $$$1 \le j < i$$$. Less formally, at the first index $$$i$$$ in which they differ, $$$x_i<y_i$$$.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 20$$$) – the number of test cases you need to solve. The first line of each test case contains $$$2$$$ integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 100$$$, $$$1 \le k \le 10000$$$) — the number of elements in the array and the maximum number of operations you can make. The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$0 \le a_i \le 100$$$) — the elements of the array $$$a$$$.

For each test case, print the lexicographically smallest array you can obtain after at most $$$k$$$ operations.

NoteIn the second test case, we start by subtracting $$$1$$$ from the first element and adding $$$1$$$ to the second. Then, we can't get any lexicographically smaller arrays, because we can't make any of the elements negative.

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

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

while(t--) {
    int n, k;
    readf("%s %s\n", &n, &k);

    int[] a = readln.split.map!(to!int).array;

    int idx = 0;
    while(k > 0 && idx < n) {
        while(a[idx] <= 0) {
            idx += 1;
        }
        if (idx >= n - 1) break;
        a[idx]--;
        a[$ - 1]++;
        k -= 1;
    }

    foreach(item; a)
        writef("%s ", item);
    "".writeln;
}
}

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

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto param = readln().chomp.splitter(" ").array;
        int k = to!int(param[1]);
        auto arr = readln().chomp.split(" ").map!(to!int).array;
        int e = arr.length-1;
        int b = 0;

        while(b < e && k > 0)
        {
            if(arr[b] > 0 && arr[e] < int.max)
            {
                arr[b]--;
                arr[e]++;
                k--;
            }
            else if(arr[b] <= 0)
            {
                b++;
            }
            else
            {
                e--;
            }
        }

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

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

string FMT_F = "%.10f";

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

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

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

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

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

		foreach (i; 0..n-1)
		{
			auto x = min(k, a[i]);
			a[i] -= x;
			a[$-1] += x;
			k -= x;
		}
		ans[ti] = a;
	}

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

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

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

while(t--) {
    int n, k;
    readf("%s %s\n", &n, &k);

    int[] a = readln.split.map!(to!int).array;

    int idx = 0;
    while(k > 0 && idx < n - 1) {
        while(a[idx] <= 0) {
            idx += 1;
        }
        a[idx]--;
        a[$ - 1]++;
        k -= 1;
    }

    foreach(item; a)
        writef("%s ", item);
    "".writeln;
}
}

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

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

while(t--) {
    int n, k;
    readf("%s %s\n", &n, &k);

    int[] a = readln.split.map!(to!int).array;

    int idx = 0;
    while(k > 0 && idx <= n - 1) {
        while(a[idx] <= 0) {
            idx += 1;
        }
        a[idx]--;
        a[$ - 1]++;
        k -= 1;
    }

    foreach(item; a)
        writef("%s ", item);
    "".writeln;
}
}

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

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

while(t--) {
    int n, k;
    readf("%s %s\n", &n, &k);

    int[] a = readln.split.map!(to!int).array;

    int idx = 0;
    while(k-- && idx <= n - 1) {
        while(a[idx] <= 0) {
            idx += 1;
        }
        a[idx]--;
        a[$ - 1]++;
    }

    foreach(item; a)
        writef("%s ", item);
    "".writeln;
}
}

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

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

while(t--) {
    int n, k;
    readf("%s %s\n", &n, &k);

    int[] a = readln.split.map!(to!int).array;

    int idx = 0;
    while(k-- && idx <= n - 1) {
        if(a[idx] <= 0) {
            idx += 1;
        }
        a[idx]--;
        a[$ - 1]++;
    }

    foreach(item; a)
        writef("%s ", item);
    "".writeln;
}
}

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

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto param = readln().chomp.splitter(" ").array;
        int k = to!int(param[1]);
        auto arr = readln().chomp.split(" ").map!(to!int).array;
        int e = arr.length-1;
        int b = 0;

        while(b < e && k > 0)
        {
            if(arr[b] > 0)
            {
                arr[b]--;
                b++;
            }
            else
            {
                b++;
            }

            if(arr[e] < 10)
            {
                arr[e]++;
            }
            else
            {
                e--;
            }

            k--;
        }

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

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

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto param = readln().chomp.splitter(" ").array;
        int k = to!int(param[1]);
        auto arr = readln().chomp.split(" ").map!(to!int).array;
        int e = arr.length-1;
        int b = 0;

        while(b < e && k > 0)
        {
            if(arr[b] > 0)
            {
                arr[b]--;
                arr[e]++;
                e--;
                k--;
            }
            b++;
        }

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

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

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto param = readln().chomp.splitter(" ").array;
        int k = to!int(param[1]);
        auto arr = readln().chomp.split(" ").map!(to!int).array;
        int e = arr.length-1;
        int b = 0;

        while(b < e && k > 0)
        {
            while(b < arr.length && arr[b] == 0) b++;
            if(b == arr.length) continue;

            arr[b]--;
            arr[e]++;
            b++;
            e--;
            k--;
        }

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

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

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto param = readln().chomp.splitter(" ").array;
        int k = to!int(param[1]);
        auto arr = readln().chomp.split(" ").map!(to!int).array;
        int e = arr.length-1;
        int b = 0;

        while(b < e && k > 0)
        {
            while(b < arr.length && arr[b] <= k) b++;
            if(b == arr.length) continue;

            arr[b]--;
            arr[e]++;
            b++;
            e--;
            k--;
        }

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

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

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto param = readln().chomp.splitter(" ").array;
        int k = to!int(param[1]);
        auto arr = readln().chomp.split(" ").map!(to!int).array;
        int e = arr.length-1;
        int b = 0;

        while(b < e && k > 0)
        {
            while(b < arr.length && arr[b] <= k) b++;
            if(b == arr.length) continue;

            arr[b]--;
            arr[e]++;
            b++;
            e--;
            k--;
        }

        writeln(arr[]);
    }
}


Consider the following problem: given an array $$$a$$$ containing $$$n$$$ integers (indexed from $$$0$$$ to $$$n-1$$$), find $$$\max\limits_{0 \leq l \leq r \leq n-1} \sum\limits_{l \leq i \leq r} (r-l+1) \cdot a_i$$$. In this problem, $$$1 \leq n \leq 2\,000$$$ and $$$|a_i| \leq 10^6$$$.In an attempt to solve the problem described, Alice quickly came up with a blazing-fast greedy algorithm and coded it. Her implementation in pseudocode is as follows:function find_answer(n, a)    # Assumes n is an integer between 1 and 2000, inclusive    # Assumes a is a list containing n integers: a[0], a[1], ..., a[n-1]    res = 0    cur = 0    k = -1    for i = 0 to i = n-1        cur = cur + a[i]        if cur < 0            cur = 0            k = i        res = max(res, (i-k)*cur)    return resAlso, as you can see, Alice's idea is not entirely correct. For example, suppose $$$n = 4$$$ and $$$a = [6, -8, 7, -42]$$$. Then, find_answer(n, a) would return $$$7$$$, but the correct answer is $$$3 \cdot (6-8+7) = 15$$$.You told Alice that her solution is incorrect, but she did not believe what you said.Given an integer $$$k$$$, you are to find any sequence $$$a$$$ of $$$n$$$ integers such that the correct answer and the answer produced by Alice's algorithm differ by exactly $$$k$$$. Note that although the choice of $$$n$$$ and the content of the sequence is yours, you must still follow the constraints earlier given: that $$$1 \leq n \leq 2\,000$$$ and that the absolute value of each element does not exceed $$$10^6$$$. If there is no such sequence, determine so.

The first and only line contains one integer $$$k$$$ ($$$1 \leq k \leq 10^9$$$).

If there is no sought sequence, print "-1". Otherwise, in the first line, print one integer $$$n$$$ ($$$1 \leq n \leq 2\,000$$$), denoting the number of elements in the sequence. Then, in the second line, print $$$n$$$ space-separated integers: $$$a_0, a_1, \ldots, a_{n-1}$$$ ($$$|a_i| \leq 10^6$$$).

NoteThe first sample corresponds to the example given in the problem statement.In the second sample, one answer is $$$n = 7$$$ with $$$a = [30, -12, -99, 123, -2, 245, -300]$$$, in which case find_answer(n, a) returns $$$1098$$$, while the correct answer is $$$1710$$$.

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

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

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

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

int K;

int N;
int[] A;

int Alice() {
  int res = 0;
  int cur = 0;
  int k = -1;
  foreach (i; 0 .. N) {
    cur += A[i];
    if (cur < 0) {
      cur = 0;
      k = i;
    }
    chmax(res, (i - k) * cur);
  }
  return res;
}

int Bob() {
  int ret = 0;
  foreach (i; 0 .. N) {
    int sum;
    foreach (j; i .. N) {
      sum += A[j];
      chmax(ret, (j + 1 - i) * sum);
    }
  }
  return ret;
}

void main() {
  try {
    for (; ; ) {
      K = readInt();
      foreach (b; 2 .. 10^^6 + 1) {
        const x0 = min(K / (b - 1), 2000);
        for (int x = x0; x < x0 + 10; ++x) {
          const y = x * (b - 1) - K;
          if (y >= 1 && x + y <= 2000) {
            N = x + y;
            A = new int[N];
            A[0 .. x - 1] = 0;
            A[x - 1] = -1;
            foreach (i; 0 .. y) {
              A[x + i] = b / y + ((i < b % y) ? 1 : 0);
            }
            goto found;
          }
        }
      }
     found:
      debug {
        writeln("Alice = ", Alice());
        writeln("Bob = ", Bob());
      }
      writeln(N);
      writeln(A.to!string.replaceAll(regex(`[\[\],]`), ""));
    }
  } catch (EOFException e) {
  }
}


Piet Mondrian is an artist most famous for his minimalist works, consisting only of the four colors red, yellow, blue, and white. Most people attribute this to his style, but the truth is that his paint behaves in a very strange way where mixing two primary colors only produces another primary color!  A lesser known piece, entitled "Pretentious rectangles" A sequence of primary colors (red, yellow, blue) is mixed as follows. While there are at least two colors, look at the first two. If they are distinct, replace them with the missing color. If they are the same, remove them from the sequence. In the end, if there is one color, that is the resulting color. Otherwise, if the sequence is empty, we say the resulting color is white. Here are two example mixings:       Piet has a color palette with cells numbered from $$$1$$$ to $$$n$$$. Each cell contains a primary color or is empty. Piet is very secretive, and will not share his palette with you, so you do not know what colors belong to each cell.However, he did perform $$$k$$$ operations. There are four kinds of operations:   In a mix operation, Piet chooses a subset of cells and mixes their colors together in some order. The order is not necessarily by increasing indexes. He records the resulting color. Empty cells are skipped over, having no effect on the mixing process. The mixing does not change the color values stored in the cells.  In a RY operation, Piet chooses a subset of cells. Any red cells in this subset become yellow, and any yellow cells in this subset become red. Blue and empty cells remain unchanged.  In a RB operation, Piet chooses a subset of cells. Any red cells in this subset become blue, and any blue cells in this subset become red. Yellow and empty cells remain unchanged.  In a YB operation, Piet chooses a subset of cells. Any yellow cells in this subset become blue, and any blue cells in this subset become yellow. Red and empty cells remain unchanged. Piet only tells you the list of operations he performs in chronological order, the indexes involved, and the resulting color of each mix operation. For each mix operation, you also know the order in which the cells are mixed. Given this information, determine the color of each cell in the initial palette. That is, you should find one possible state of the palette (before any operations were performed), or say that the described situation is impossible.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1\le n,k\le 1000$$$) — the number of cells in the palette and the number of operations, respectively. The next $$$k$$$ lines describe the operations. The $$$i$$$-th line begins with the name of the $$$i$$$-th operation and an integer $$$m$$$ ($$$1\le m\le n$$$) — the number of indexes involved. Then follow $$$m$$$ integers $$$j_1,\ldots,j_m$$$ ($$$1\le j_i\le n$$$) — the indexes of the operation. It is guaranteed that all $$$j_i$$$ are distinct within an operation. If it is a mix operation, the indexes are listed in the order the colors are mixed, and the line also ends with a character representing the resulting color: "R" for red, "Y" for yellow, "B" for blue, and "W" for white.

Output "YES" if a solution exists, or "NO" otherwise. You can print each character in any case (upper or lower). If the answer is "YES", on the next line output a string of length $$$n$$$, consisting of characters "R", "Y", "B", and ".", representing the paint colors in the $$$n$$$ cells of the initial palette (red, yellow, blue, and empty, respectively). If there are multiple solutions, print any. You can print each character in any case (upper or lower).

3 8
mix 2 1 2 R
mix 2 1 3 Y
RY 2 2 3
RB 3 1 2 3
YB 3 1 2 3
mix 1 1 W
mix 1 2 B
mix 1 3 Y

NoteFor the first test case, the answer "YB." is consistent with both mixings. The first mixing "BY" results in red, while the second mixing "Y" results in yellow (the empty cell is ignored). Other valid solutions include "BYR" and ".RY".For the second test case, we can show that no solution exists.For the third test case, the answer "R" is consistent with all operations. In the first two operations it changes to "Y", then "B". In the final operation, the mixing "B" results in blue.For the fourth test case, the answer ".RY" is consistent with all operations. The first two mixings are "R" and "Y", resulting in red and yellow, respectively. During the next three operations, the palette changes to ".YR", then ".YB", then ".BY". The final three mixings agree with this palette.

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

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

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

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

enum MUL = [
  [0, 0, 0, 0],
  [0, 1, 2, 3],
  [0, 2, 3, 1],
  [0, 3, 1, 2],
];

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const K = readInt();
      auto typ = new string[K];
      auto mix = new string[K];
      auto M = new int[K];
      auto J = new int[][K];
      foreach (k; 0 .. K) {
        typ[k] = readToken();
        M[k] = readInt();
        J[k] = new int[M[k]];
        foreach (m; 0 .. M[k]) {
          J[k][m] = readInt() - 1;
        }
        if (typ[k] == "mix") {
          mix[k] = readToken();
        }
      }

      // F_2[X] / (1 + X + X^2)
      // W: 0, R: 1, Y: X, B: 1 + X
      // t -> fs[i] t^(2^gs[i])
      auto fs = new int[N];
      auto gs = new int[N];
      fs[] = 1;
      gs[] = 0;
      int aLen;
      auto a = new BitArray[K << 1];
      foreach (k; 0 .. K) {
        switch (typ[k]) {
          case "mix": {
            const num = "WRYB".indexOf(mix[k]);
            a[aLen + 0] = BitArray(new bool[N << 1 | 1]);
            a[aLen + 1] = BitArray(new bool[N << 1 | 1]);
            foreach (i; J[k]) {
              const p = (fs[i] >> 0) & 1;
              const q = (fs[i] >> 1) & 1;
              switch (gs[i]) {
                case 0: {
                  // (p + q X) (a + b X) = (p a + q b) + (q a + (p + q) b) X
                  a[aLen + 0][i << 1 | 0] = p;
                  a[aLen + 0][i << 1 | 1] = q;
                  a[aLen + 1][i << 1 | 0] = q;
                  a[aLen + 1][i << 1 | 1] = p ^ q;
                } break;
                case 1: {
                  // (p + q X) (a + b X)^2 = (p a + (p + q) b) + (q a + p b) X
                  a[aLen + 0][i << 1 | 0] = p;
                  a[aLen + 0][i << 1 | 1] = p ^ q;
                  a[aLen + 1][i << 1 | 0] = q;
                  a[aLen + 1][i << 1 | 1] = p;
                } break;
                default: assert(false);
              }
            }
            a[aLen + 0][N << 1] = (num >> 0) & 1;
            a[aLen + 1][N << 1] = (num >> 1) & 1;
            aLen += 2;
          } break;
          case "RY": {
            // 1 <-> X
            // t -> X t^2
            foreach (i; J[k]) {
              fs[i] = MUL[2][MUL[fs[i]][fs[i]]];
              gs[i] ^= 1;
            }
          } break;
          case "RB": {
            // 1 <-> 1 + X
            // t -> (1 + X) t^2
            foreach (i; J[k]) {
              fs[i] = MUL[3][MUL[fs[i]][fs[i]]];
              gs[i] ^= 1;
            }
          } break;
          case "YB": {
            // X <-> 1 + X
            // t -> t^2
            foreach (i; J[k]) {
              fs[i] = MUL[1][MUL[fs[i]][fs[i]]];
              gs[i] ^= 1;
            }
          } break;
          default: assert(false);
        }
      }
      a.length = aLen;
      debug {
        foreach (i; 0 .. aLen) {
          foreach (j; 0 .. (N << 1) + 1) {
            write(a[i][j] ? 1 : 0);
          }
          writeln();
        }
        writeln("----");
      }

      int r;
      int[] hs;
      foreach (h; 0 .. N << 1) {
        foreach (i; r .. aLen) {
          if (a[i][h]) {
            swap(a[r], a[i]);
            break;
          }
        }
        if (r < aLen && a[r][h]) {
          foreach (i; r + 1 .. aLen) {
            if (a[i][h]) {
              a[i] ^= a[r];
            }
          }
          ++r;
          hs ~= h;
        }
      }
      bool ok = true;
      foreach (i; r .. aLen) {
        ok = ok && !a[i][N << 1];
      }
      if (ok) {
        auto sol = new bool[N << 1];
        foreach_reverse (i; 0 .. r) {
          bool x = a[i][N << 1];
          foreach (j; hs[i] + 1 .. N << 1) {
            if (a[i][j] && sol[j]) {
              x = !x;
            }
          }
          sol[hs[i]] = x;
        }
        writeln("YES");
        foreach (i; 0 .. N) {
          write(".RYB"[cast(int)(sol[i << 1 | 0]) << 0 | cast(int)(sol[i << 1 | 1]) << 1]);
        }
        writeln();
      } else {
        writeln("NO");
      }
    }
  } catch (EOFException e) {
  }
}


You are given the array of integer numbers a0, a1, ..., an - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.

The first line contains integer n (1 ≤ n ≤ 2·105) — length of the array a. The second line contains integer elements of the array separated by single spaces ( - 109 ≤ ai ≤ 109).

Print the sequence d0, d1, ..., dn - 1, where di is the difference of indices between i and nearest j such that aj = 0. It is possible that i = j.

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

string TASK = "dominoes";

void main(){
//    File fin = File(TASK ~ ".in", "r");
//    File fout = File(TASK ~ ".out", "w");
    int n;
    readf("%s", &n);
    readln;
    auto a = readln.split.map !(to !(int)).array;
    int[] zero = new int[0];
    foreach (i; 0..n)
        if (!a[i])
            zero ~= i;
    int[] ans = new int[n];
    int prev = -1, next = 0;
    foreach (i; 0..n){
        if (next < zero.length && zero[next] <= i){
            ++prev;
            ++next;
        }
        if (prev == -1)
            ans[i] = zero[next] - i;
        else if (next == zero.length)
            ans[i] = i - zero[prev];
        else
            ans[i] = min(i - zero[prev], zero[next] - i);
    }
    foreach (ANS; ans)
        write(ANS, " ");
}


Given an array $$$a$$$ of positive integers with length $$$n$$$, determine if there exist three distinct indices $$$i$$$, $$$j$$$, $$$k$$$ such that $$$a_i + a_j + a_k$$$ ends in the digit $$$3$$$.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$3 \leq n \leq 2 \cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array. The sum of $$$n$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.

Output $$$t$$$ lines, each of which contains the answer to the corresponding test case. Output "YES" if there exist three distinct indices $$$i$$$, $$$j$$$, $$$k$$$ satisfying the constraints in the statement, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

NoteIn the first test case, you can select $$$i=1$$$, $$$j=4$$$, $$$k=3$$$. Then $$$a_1 + a_4 + a_3 = 20 + 84 + 19 = 123$$$, which ends in the digit $$$3$$$.In the second test case, you can select $$$i=1$$$, $$$j=2$$$, $$$k=3$$$. Then $$$a_1 + a_2 + a_3 = 1 + 11 + 1 = 13$$$, which ends in the digit $$$3$$$.In the third test case, it can be proven that no such $$$i$$$, $$$j$$$, $$$k$$$ exist. Note that $$$i=4$$$, $$$j=4$$$, $$$k=4$$$ is not a valid solution, since although $$$a_4 + a_4 + a_4 = 1111 + 1111 + 1111 = 3333$$$, which ends in the digit $$$3$$$, the indices need to be distinct.In the fourth test case, it can be proven that no such $$$i$$$, $$$j$$$, $$$k$$$ exist.In the fifth test case, you can select $$$i=4$$$, $$$j=3$$$, $$$k=1$$$. Then $$$a_4 + a_3 + a_1 = 4 + 8 + 1 = 13$$$, which ends in the digit $$$3$$$.In the sixth test case, you can select $$$i=1$$$, $$$j=2$$$, $$$k=6$$$. Then $$$a_1 + a_2 + a_6 = 16 + 38 + 99 = 153$$$, which ends in the digit $$$3$$$.

void main() { runSolver(); }

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

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

      auto modded = new int[](10);
      foreach(a; A) modded[a % 10]++;

      int[] cmb;
      foreach(i; 0..10) cmb ~= i.repeat(min(3, modded[i])).array;
      auto l = cmb.length;

      foreach(i; 0..l - 2) {
        foreach(j; i + 1..l - 1) {
          foreach(k; j + 1..l) {
            if ((cmb[i] + cmb[j] + cmb[k]) % 10 == 3) return "YES";
          }
        }
      }

      return "NO";
    }

    foreach(i; 0..QN) {
      outputForAtCoder(&subSolve);
    }
  }

  outputForAtCoder(&solve);
}

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

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

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


We just discovered a new data structure in our research group: a suffix three!It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in.It's super simple, 100% accurate, and doesn't involve advanced machine learning algorithms.Let us tell you how it works.  If a sentence ends with "po" the language is Filipino.  If a sentence ends with "desu" or "masu" the language is Japanese.  If a sentence ends with "mnida" the language is Korean. Given this, we need you to implement a suffix three that can differentiate Filipino, Japanese, and Korean.Oh, did I say three suffixes? I meant four.

The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 30$$$) denoting the number of test cases. The next lines contain descriptions of the test cases.  Each test case consists of a single line containing a single string denoting the sentence. Spaces are represented as underscores (the symbol "_") for ease of reading. The sentence has at least $$$1$$$ and at most $$$1000$$$ characters, and consists only of lowercase English letters and underscores. The sentence has no leading or trailing underscores and no two consecutive underscores. It is guaranteed that the sentence ends with one of the four suffixes mentioned above.

For each test case, print a single line containing either "FILIPINO", "JAPANESE", or "KOREAN" (all in uppercase, without quotes), depending on the detected language.

8
kamusta_po
genki_desu
ohayou_gozaimasu
annyeong_hashimnida
hajime_no_ippo
bensamu_no_sentou_houhou_ga_okama_kenpo
ang_halaman_doon_ay_sarisari_singkamasu
si_roy_mustang_ay_namamasu

FILIPINO
JAPANESE
JAPANESE
KOREAN
FILIPINO
FILIPINO
JAPANESE
JAPANESE

NoteThe first sentence ends with "po", so it is written in Filipino.The second and third sentences end with "desu" and "masu", so they are written in Japanese.The fourth sentence ends with "mnida", so it is written in Korean.

module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

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

        int read_int() {
                return read_string.to!int;
        }

        double read_double() {
                return read_string.to!double;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        t = cin.read_int;
        while (t--) {
                string s = cin.read_string;
                if (endsWith(s, "po")) writeln("FILIPINO");
                else if (endsWith(s, "desu") || endsWith(s, "masu")) writeln("JAPANESE");
                else writeln("KOREAN");
        }
}

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; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//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 string[](t);
	foreach (ti; 0..t)
	{
		auto s = RD!string;
		if (s.length >= 2)
		{
			if (s[$-2..$] == "po")
			{
				ans[ti] = "FILIPINO";
				continue;
			}
			if (s.length >= 4)
			{
				if (s[$-4..$] == "desu" || s[$-4..$] == "masu")
				{
					ans[ti] = "JAPANESE";
					continue;
				}
				if (s.length >= 5)
				{
					if (s[$-5..$] == "mnida")
					{
						ans[ti] = "KOREAN";
						continue;
					}
				}
			}
		}
	}
	foreach (e; ans)
		writeln(e);

	stdout.flush;
	debug readln;
}


Phoenix has $$$n$$$ coins with weights $$$2^1, 2^2, \dots, 2^n$$$. He knows that $$$n$$$ is even.He wants to split the coins into two piles such that each pile has exactly $$$\frac{n}{2}$$$ coins and the difference of weights between the two piles is minimized. Formally, let $$$a$$$ denote the sum of weights in the first pile, and $$$b$$$ denote the sum of weights in the second pile. Help Phoenix minimize $$$|a-b|$$$, the absolute value of $$$a-b$$$.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 30$$$; $$$n$$$ is even) — the number of coins that Phoenix has.

For each test case, output one integer — the minimum possible difference of weights between the two piles.

NoteIn the first test case, Phoenix has two coins with weights $$$2$$$ and $$$4$$$. No matter how he divides the coins, the difference will be $$$4-2=2$$$.In the second test case, Phoenix has four coins of weight $$$2$$$, $$$4$$$, $$$8$$$, and $$$16$$$. It is optimal for Phoenix to place coins with weights $$$2$$$ and $$$16$$$ in one pile, and coins with weights $$$4$$$ and $$$8$$$ in another pile. The difference is $$$(2+16)-(4+8)=6$$$.

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_t; 0..T) {
        auto N = readln.chomp.to!long;
        long a = 2L^^N, b;
        foreach (i; 1..N/2) {
            a += 2L^^i;
        }
        foreach (i; N/2..N) {
            b += 2L^^i;
        }
        writeln(a - b);
    }
}

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

void main ()
{
	readln;
	int n;
	while (readf !(" %s") (n) > 0)
	{
		int res = 0;
		foreach (i; 0..n)
		{
			auto add = (i + 1 == n || i + 1 < n / 2);
			res += (2 << i) * (add ? +1 : -1);
		}
		writeln (res);
	}
}

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

string FMT_F = "%.10f";

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

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

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

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(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) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		long x, y;
		foreach (i; 0..n-1)
		{
			if (i < n/2-1)
			{
				x += 2^^(i+1);
			}
			else
			{
				y += 2^^(i+1);
			}
		}
		x += 2^^n;
		ans[ti] = x - y;
	}

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