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

string FMT_F = "%.10f";

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

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

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

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

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

		long x, y;
		foreach (i; 0..n)
		{
			if (i % 2 == a[i] % 2)
			{
				if (i % 2)
					y += a[i];
				else
					x += a[i];
			}
		}
		ans[ti] = x > y ? -1 : x < y ? 1 : 0;
	}

	foreach (e; ans)
		writeln(e == -1 ? "Alice" : e == 1 ? "Bob" : "Tie");
	stdout.flush;
	debug readln;
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		sort !(q{a > b}) (a);
		long balance = 0;
		foreach (i; 0..n)
		{
			if (a[i] % 2 == 0 && i % 2 == 0)
			{
				balance += a[i];
			}
			if (a[i] % 2 == 1 && i % 2 == 1)
			{
				balance -= a[i];
			}
		}
		writeln (balance == 0 ? "Tie" : balance > 0 ? "Alice" : "Bob");
	}
}


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

immutable int maxLog = 18;

struct Node
{
	int a;
	int c;
	int [maxLog] p;
}

void main ()
{
	int q, a0, c0;
	while (readf !(" %s %s %s") (q, a0, c0) > 0)
	{
		readln;
		auto t = new Node [q + 2];
		t[0].a = a0;
		t[0].c = c0;
		t[0].p[] = q + 1;
		t[q + 1].p[] = q + 1;
		foreach (i; 1..q + 1)
		{
			auto z = readln.split;
			if (z[0] == "1")
			{
				auto p = z[1].to !(int);
				auto a = z[2].to !(int);
				auto c = z[3].to !(int);
				t[i].a = a;
				t[i].c = c;
				t[i].p[0] = p;
				foreach (d; 1..maxLog)
				{
					t[i].p[d] = t[t[i].p[d - 1]].p[d - 1];
				}
				debug {writeln (t[i].p);}
			}
			else if (z[0] == "2")
			{
				auto v = z[1].to !(int);
				auto w = z[2].to !(int);
				int step = 0;
				int r = v;
				foreach_reverse (d; 0..maxLog)
				{
					int u = t[r].p[d];
					if (t[u].a > 0)
					{
						r = u;
						step += 1 << d;
					}
				}
				int gold = 0;
				long cost = 0;
				foreach_reverse (x; 0..step + 1)
				{
					if (gold == w)
					{
						break;
					}
					int y = x;
					int u = v;
					foreach_reverse (d; 0..maxLog)
					{
						if (y >= 1 << d)
						{
							u = t[u].p[d];
							y -= 1 << d;
						}
					}
					int cur = min (w - gold, t[u].a);
					debug {writefln !("step %s, " ~
					    "take %s from %s") (x, cur, u);}
					t[u].a -= cur;
					gold += cur;
					cost += cur * 1L * t[u].c;
				}
				writeln (gold, " ", cost);
				stdout.flush ();
			}
			else
			{
				assert (false);
			}
		}
	}
}

import std.stdio;
import std.ascii;
import std.algorithm;
static import core.stdc.stdio;

long[300_000+2] a;
long[300_000+2] c;

int main()
{
    int[][] parent = new int[][](300_000+2, 20);
    int q = readInt!int;
    a[0] = readInt!long;
    c[0] = readInt!long;
    parent[0][] = -1;
    int getNthParent(int v, int n)
    {
        int i = 0;
        while (n)
        {
            if (n & 1)
                v = parent[v][i];
            n >>= 1;
            i++;
        }
        return v;
    }
    foreach(i; 1 .. q + 1)
    {
        int type = readInt!int;
        if (type == 1)
        {
            int pi = readInt!int;
            long ai = readInt!long;
            long ci = readInt!long;
            parent[i][0] = pi;
            foreach(j; 1 .. 20)
            {
                if (parent[i][j - 1] > 0)
                    parent[i][j] = parent[parent[i][j - 1]][j - 1];
                else parent[i][j] = -1;
            }
            a[i] = ai;
            c[i] = ci;
        }
        else
        {
            int vi = readInt!int;
            long wi = readInt!long;
            int root = vi;
            int no = 0;
            long spent = 0;
            long bought = 0;
            foreach_reverse(j; 0 .. 20)
            {
                int possibleParent = parent[root][j];
                if (possibleParent < 0) continue;
                if (a[possibleParent] > 0)
                {
                    root = possibleParent;
                    no += (long(1) << j);
                }
            }
            debug writeln("for node ", vi, " root is ", root, " depth = ", no);
            while (wi > 0 && no >= 0)
            {
                int p = getNthParent(vi, no);
                debug writeln("Now is ", no, " ", p, " ap = ", a[p], " wi = ", wi);
                long taken = min(wi, a[p]);
                wi -= taken;
                bought += taken;
                spent += taken * c[p];
                a[p] -= taken;
                no--;
            }
            writeln(bought, " ", spent);
            stdout.flush;
        }
    }
    return 0;
}

/* INPUT ROUTINES */
int currChar;
static this()
{
    currChar = core.stdc.stdio.getchar();
}
char topChar()
{
    return cast(char) currChar;
}
void popChar()
{
    currChar = core.stdc.stdio.getchar();
}
auto readInt(T)()
{
    T num = 0;
    int sgn = 0;
    while (topChar.isWhite) popChar;
    while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }
    while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }
    if (sgn) return -num; return num;
}
string readString()
{
    string res = "";
    while (topChar.isWhite) popChar;
    while (!topChar.isWhite) { res ~= topChar; popChar; }
    return res;
}
/**MODULAR SYSTEM*/
struct Z(immutable long m)
{
    long rep;
    this(long num)
    {
        rep = num;
    }
    Z!m opBinary(string operator)(Z!m rhs)
    {
        static if (operator == "+")
        {
            long result = rhs.rep + this.rep;
            if (result >= m) result -= m;
            return Z!m(result);
        }
        else static if (operator == "-")
        {
            long result = this.rep - rhs.rep;
            if (result < 0) result += m;
            return Z!m(result);
        }
        else static if (operator == "*")
        {
            long result = this.rep * rhs.rep;
            if (result >= m) result %= m;
            return Z!m(result);
        } else static assert(text("Operator ", operator, " not supported"));
    }
    Z!m opBinary(string operator)(long exponent) if (operator == "^^")
    {
        assert(exponent >= 0);
        Z!m base = this;
        Z!m result = 1;
        while (exponent)
        {
            if (exponent & 1)
                result = result * base;
            base = base * base;
            exponent >>= 1;
        }
        return result;
    }
    invariant
    {
        assert(rep >= 0 && rep < m);
    }
}


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

// Main Logic Here
void play(){
    int x, y;
    x = rd!int;
    y = rd!int;
    ll tim = 2*max(x, y) - (x != y);
    writeln(tim);
}

int main(){
    long t = 1;
    t = rd;        // Toggle for testcases!
    while(t--) play();  // Let's play!
    return 0;
}

/**********That's All Folks!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
static string[] inp;    // Read input
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }
alias ll = long;
alias tup = Tuple!(long, "x",  long, "y");
void show(A...)(A a) { debug{ foreach(t; a){ stderr.write(t, "| "); } stderr.writeln; } } // Debug
/* Add if TLE, T max(T = long)(T a, T b){ return (a > b) ? a : b; } */

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int x, y;
		readf !(" %s %s") (x, y);
		x = abs (x);
		y = abs (y);
		if (x < y)
		{
			swap (x, y);
		}
		string s = "***";
		int res = 0;
		while (x || y)
		{
			if (x == y)
			{
				res += x + y;
				break;
			}
			if (s[$ - 1..$] != "a")
			{
				s ~= 'a';
				x -= 1;
				res += 1;
			}
			else
			{
				s ~= 'b';
				y = max (0, y - 1);
				res += 1;
			}
		}
		debug {writeln (s);}
		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(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 x = RD!int;
		auto y = RD!int;

		ans[ti] += min(x.abs, y.abs) * 2;
		auto d = max(x.abs, y.abs) - min(x.abs, y.abs);
		if (d == 0) continue;
		ans[ti] += (d-1) * 2 + 1;
	}

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

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int x, y;
		readf !(" %s %s") (x, y);
		x = abs (x);
		y = abs (y);
		if (x < y)
		{
			swap (x, y);
		}
		string s = "***";
		int res = 0;
		while (x || y)
		{
			if (x == y)
			{
				res += x + y;
				break;
			}
			if (s[$ - 1..$] != "a")
			{
				s ~= 'a';
				x -= 1;
				res += 1;
			}
			else
			{
				s ~= 'b';
				y = max (0, y - 1);
				res += 1;
			}
		}
		writeln (s);
		writeln (res);
	}
}


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

void main() {
    string s = readln.chomp;
    int n = s.length.to!int;

    bool check(int k, char ch) {
        int v = s[0 .. k].count!(a => a == ch);

        if (!v) return false;

        foreach (i ; k .. n) {
            v += (s[i] == ch);
            v -= (s[i - k] == ch);

            if (!v) return false;
        }

        return true;
    }

    int ans = n;

    foreach (char ch ; 'a' .. 'z' + 1) {
        if (!s.canFind(ch)) continue;

        int btm = 0, top = n;

        while (top - btm > 1) {
            int mid = (btm + top) / 2;

            if (check(mid, ch)) {
                top = mid;
            }
            else {
                btm = mid;
            }
        }

        ans = min(ans, top);
    }

    writeln(ans);
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

void main() {
    string s;
    scan(s);

    int n = s.length.to!int;

    int ans = n;

    foreach (char ch ; 'a' .. 'z' + 1) {
        int p = -1;
        int span;

        foreach (i ; 0 .. n) {
            if (s[i] == ch) {
                span = max(span, i - p);
                p = i;
            }
        }

        span = max(span, n - p);

        ans = min(span, ans);
    }

    writeln(ans);
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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;

immutable long MOD = 998244353;

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

    A.sort();
    long ans = 0;

    foreach (i; 0..N/2) {
        ans += (A[i] + A[N-i-1]) * (A[i] + A[N-i-1]);
    }

    ans.writeln;
}

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

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(long[]);

    a.sort();

    long ans;

    foreach (i ; 0 .. n / 2) {
        ans += a[i]^^2 + a[n - 1 - i]^^2 + 2L * a[i] * a[n - 1 - i];
    }

    writeln(ans);
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

void main() {
    auto s = readln.split;
    auto N = s[0].to!int;
    auto H = s[1].to!long;
    auto A = N.iota.map!(_ => readln.split.map!(to!long).array).array;
    long ans = 0;
    long tmp = 0;
    long h = 0;

    for (int i = 0, j = 0; i < N; ++i) {
        if (j <= i) {
            tmp = A[i][1] - A[i][0];
            h = H;
            j = i;
        } else {
            tmp -= A[i][0] - A[i - 1][0];
            h += A[i][0] - A[i - 1][1];
        }
        while (j + 1 < N && h - (A[j + 1][0] - A[j][1]) > 0) {
            tmp += A[j + 1][1] - A[j][1];
            h -= A[j + 1][0] - A[j][1];
            ++j;
        }
        ans = max(ans, tmp + h);
    }

    ans.writeln;
}

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

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

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

    Tuple!(int, int)[] sg;
    foreach (_; 0 .. n) {
        int x1, x2;
        readf("%s %s", &x1, &x2);
        readln;

        sg ~= tuple(x1, x2);
    }

    debug { sg.writeln; }

    int lst = 0;
    int covered = 0;
    int cur = sg[0][1] - sg[0][0];
    int ans = cur;
    foreach (i; 1 .. n) {
        cur += sg[i][1] - sg[i][0];
        covered += sg[i][0] - sg[i-1][1];
        while (covered > h-1) {
            cur -= sg[lst][1] - sg[lst][0];
            covered -= sg[lst+1][0] - sg[lst][1];
            ++lst;
        }
        ans = max(ans, cur);
    }

    ans += h;

    ans.writeln;
}

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

  int n, h; rd(n, h);
  auto l=new int[](n), r=new int[](n);
  foreach(i; 0..n) rd(l[i], r[i]);

  int mx=0, len=0;
  for(int i=0, j=0, height=h; i<n; i++){
    while(j<n && height>0){
      mx=max(mx, len+(r[j]-l[j])+height);
      if((++j)<n){
        len+=l[j]-l[j-1];
        height-=l[j]-r[j-1];
      }
    }
    if(i+1<n){
      len-=l[i+1]-l[i];
      height+=l[i+1]-r[i];
    }
  }
  writeln(mx);

}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}

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

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

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

    Tuple!(int, int)[] sg;
    foreach (_; 0 .. n) {
        int x1, x2;
        readf("%s %s", &x1, &x2);
        readln;

        sg ~= tuple(x1, x2);
    }

    debug { sg.writeln; }

    int lst = 0;
    int covered = 0;
    int cur = sg[0][1] - sg[0][0];
    int ans = cur;
    foreach (i; 1 .. n) {
        cur += sg[i][1] - sg[i][0];
        covered += sg[i][0] - sg[i-1][1];
        while (covered > h) {
            cur -= sg[lst][1] - sg[lst][0];
            covered -= sg[lst+1][0] - sg[lst][1];
            ++lst;
        }
        ans = max(ans, cur);
    }

    ans += h;

    ans.writeln;
}


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto v = '9'.repeat (n).array;
		v[0..(n + 3) / 4] = '8';
		writeln (v.retro);
	}
}

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

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

void main()
{
  int t;
  read(t);
  while(t--)
    {
      int n;
      read(n);
      int eights = (n + ((-n)%4+4)%4) / 4;
      foreach(i; 0 .. n - eights)
        write("9");
      foreach(i; 0 .. eights)
        write("8");
      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 string[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto m = (n+3) / 4;
		foreach (i; 0..n-m)
			ans[ti] ~= "9";
		foreach (i; 0..m)
			ans[ti] ~= "8";
	}

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


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

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

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

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

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      auto P = new long[N];
      foreach (i; 0 .. N) {
        P[i] = readLong();
      }

      long ans;
      auto set = new RedBlackTree!(long, "a < b", true);
      foreach (i; 0 .. N) {
        // +1, -P[i]
        set.insert(P[i]);
        // -1, +P[i]
        ans += P[i];
        set.insert(P[i]);
        ans -= set.front;
        set.removeFront;
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

/+ dub.sdl:
    name "D"
    dependency "dunkelheit" version=">=0.9.0"
+/

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

// import dkh.container.pairingheap;

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

    int n;
    long[] p;
    sc.read(n, p);

    PairingHeap!(long[2], "a>b") q;

    long ans = 0;
    foreach (d; p) {
        if (q.empty || q.front[0] >= d) {
            q.insert([d, 0]);
        } else {
            auto x = q.front; q.removeFront();
            ans += d - x[0];
            q.insert([d, 1]);
            if (x[1]) {
                q.insert([x[0], 0]);
            }
        }
    }
    writeln(ans);
    return 0;
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;

struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
    import core.exception : RangeError;

    private T* _data;
    private uint len, cap;

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

    inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }

    ref inout(T) opIndex(size_t i) inout {
        version(assert) if (len <= i) throw new RangeError();
        return _data[i];
    }
    ref inout(T) front() inout { return this[0]; }
    ref inout(T) back() inout { return this[$-1]; }

    void reserve(size_t newCap) {
        import core.memory : GC;
        import core.stdc.string : memcpy;
        import std.conv : to;
        if (newCap <= cap) return;
        void* newData = GC.malloc(newCap * T.sizeof);
        cap = newCap.to!uint;
        if (len) memcpy(newData, _data, len * T.sizeof);
        _data = cast(T*)(newData);
    }
    void free() {
        import core.memory : GC;
        GC.free(_data);
    }

    void clear() {
        len = 0;
    }

    void insertBack(T item) {
        import std.algorithm : max;
        if (len == cap) reserve(max(cap * 2, MINCAP));
        _data[len++] = item;
    }
    alias opOpAssign(string op : "~") = insertBack;
    void removeBack() {
        assert(!empty, "StackPayload.removeBack: Stack is empty");
        len--;
    }
}

/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;

// import dkh.container.stackpayload;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray;
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succW() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (!line.empty && line.front.isWhite) {
            line.popFront;
        }
        return !line.empty;
    }
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            line = lineBuf[];
            f.readln(line);
            if (!line.length) return false;
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {

                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else static if (isStaticArray!T) {
                foreach (i; 0..T.length) {
                    bool f = succW();
                    assert(f);
                    x[i] = line.parse!E;
                }
            } else {
                StackPayload!E buf;
                while (succW()) {
                    buf ~= line.parse!E;
                }
                x = buf.data;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }

    int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
    void read(Args...)(auto ref Args args) {
        import std.exception;
        static if (args.length != 0) {
            enforce(readSingle(args[0]));
            read(args[1..$]);
        }
    }
    bool hasNext() {
        return succ();
    }
}

/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/foundation.d */

// module dkh.foundation;

static if (__VERSION__ <= 2070) {
    /*
    Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
    Copyright: Andrei Alexandrescu 2008-.
    License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
    */
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            import std.algorithm : reduce;
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                import std.typecons : tuple;
                return reduce!fun(tuple(seed), r);
            }
        }
    }

}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/pairingheap.d */
// module dkh.container.pairingheap;

private NP meldPairingHeapNode(alias less, NP)(NP x, NP y) {
    import std.algorithm : swap;
    if (!x) return y;
    if (!y) return x;
    if (less(x._item, y._item)) swap(x, y);
    y.next = x.head;
    x.head = y;
    return x;
}

struct PairingHeap(T, alias less = "a < b") {
    import std.functional : binaryFun;
    private alias _less = binaryFun!less;

    private alias NP = Node*;
    private static struct Node {
        T _item;
        NP head, next;
        this(T item) {
            _item = item;
        }
    }

    private struct Payload {
        import std.algorithm : swap;
        private NP node;
        private uint len;

        void insert(T item) {
            len++;
            node = meldPairingHeapNode!_less(node, new Node(item));
        }
        inout(T) front() inout { return node._item; }
        void removeFront() {
            len--;

            NP s = node.head;
            NP t;

            while (s) {

                NP first, second;
                first = s; s = s.next; first.next = null;
                if (s) {
                    second = s; s = s.next; second.next = null;
                }

                auto v = meldPairingHeapNode!_less(first, second);
                v.next = t;
                t = v;
            }
            node = null;

            while (t) {
                NP first = t; t = t.next; first.next = null;
                node = meldPairingHeapNode!_less(first, node);
            }
        }
        void meld(Payload* r) {
            len += r.len; r.len = 0;
            node = meldPairingHeapNode!_less(node, r.node);
            r.node = null;
        }
    }
    private Payload* _p;

    @property bool empty() const { return !_p || _p.len == 0; }
    @property size_t length() const { return (!_p) ? 0 : _p.len; }

    void insert(T item) {
        if (!_p) _p = new Payload();
        _p.insert(item);
    }
    inout(T) front() inout {
        assert(!empty, "PairingHeap.front: heap is empty");
        return _p.front;
    }
    void removeFront() {
        assert(!empty, "PairingHeap.removeFront: heap is empty");
        _p.removeFront;
    }

    void meld(PairingHeap r) { _p.meld(r._p); }
}

/*
This source code generated by dunkelheit and include dunkelheit's source code.
dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)
dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)
*/


import std.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 t = RD!int;
	auto ans = new bool[](t);
	foreach (i; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;
		auto b = RDA;
		auto c = new long[](n);
		foreach (j; 0..n)
		{
			c[j] = b[j] - a[j];
		}
		int l, r=1;
		foreach (j; 0..n)
		{
			if (c[j] != 0)
			{
				l = j;
				break;
			}
		}
		foreach_reverse (j; 0..n)
		{
			if (c[j] != 0)
			{
				r = j+1;
				break;
			}
		}
		debug writeln(l, ":", r);
		bool ok = c[l] >= 0;
		foreach (j; l+1..r)
		{
			if (c[j] < 0) ok = false;
			if (c[j] != c[j-1])
				ok = false;
		}
		ans[i] = ok;
	}

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

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

void main() {
    auto T = readln.chomp.to!int;
    while (T--) {
        auto N = readln.chomp.to!int;
        auto A = readln.split.map!(to!int).array;
        auto B = readln.split.map!(to!int).array;
        B[] -= A[];
        B = B.uniq.array;
        if (B.map!(b => b < 0).any) {
            writeln("NO");
        } else if (B.length == 1) {
            writeln("YES");
        } else if (B.length == 2 && (B.front == 0 || B.back == 0)) {
            writeln("YES");
        } else if (B.length == 3 && (B.front == 0 && B.back == 0)) {
            writeln("YES");
        } else {
            writeln("NO");
        }
    }
}

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

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

void solve(){
	int t = rint;
	foreach(_; 0 .. t){
		int n = rint;
		long[] as = rlong(n);
		long[] bs = rlong(n);

		long[] us;
		foreach(i; 0 .. n) us ~= bs[i] - as[i];
		log("us:", us);

		int s = 0; // 0=まだない 1=今その途中 2=終わった -1=だめ
		long xu;
		foreach(u; us){
			if(u < 0) s = -1;
			else if(u == 0){
				if(s == 1) s = 2;
			}
			else{
				if(s == 0){
					s = 1;
					xu = u;
				}
				else if(s == 1){
					if(u != xu) s = -1;
				}
				else if(s == 2){
					s = -1;
				}
			}
		}

		if(s == -1) "NO".writeln;
		else "YES".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 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 t = RD!int;
	auto ans = new bool[](t);
	foreach (i; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;
		auto b = RDA;
		auto c = new long[](n);
		foreach (j; 0..n)
		{
			c[j] = b[j] - a[j];
		}
		int l, r;
		foreach (j; 0..n)
		{
			if (c[j] != 0)
			{
				l = j;
				break;
			}
		}
		foreach_reverse (j; 0..n)
		{
			if (c[j] != 0)
			{
				r = j;
				break;
			}
		}
		debug writeln(l, ":", r);
		bool ok = c[l] >= 0;
		foreach (j; l+1..r)
		{
			if (c[j] < 0) ok = false;
			if (c[j] != c[j-1])
				ok = false;
		}
		ans[i] = ok;
	}

	foreach (e; ans)
		writeln(e ? "YES" : "NO");
	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 t = RD!int;
	auto ans = new bool[](t);
	foreach (i; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;
		auto b = RDA;
		auto c = new long[](n);
		foreach (j; 0..n)
		{
			c[j] = b[j] - a[j];
		}
		bool ok = true;
		long last;
		foreach (j; 0..n)
		{
			if (c[j] == 0) continue;
			else if (c[j] < 0)
				ok = false;

			if (last == 0)
				last = c[j];
			else if (c[j] != last)
				ok = false;
		}
		ans[i] = ok;
	}

	foreach (e; ans)
		writeln(e ? "YES" : "NO");
	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 t = RD!int;
	auto ans = new bool[](t);
	foreach (i; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;
		auto b = RDA;
		auto c = new long[](n);
		foreach (j; 0..n)
		{
			c[j] = b[j] - a[j];
		}
		int l, r=1;
		foreach (j; 0..n)
		{
			if (c[j] != 0)
			{
				l = j;
				break;
			}
		}
		foreach_reverse (j; 0..n)
		{
			if (c[j] != 0)
			{
				r = j;
				break;
			}
		}
		debug writeln(l, ":", r);
		bool ok = c[l] >= 0;
		foreach (j; l+1..r)
		{
			if (c[j] < 0) ok = false;
			if (c[j] != c[j-1])
				ok = false;
		}
		ans[i] = ok;
	}

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


import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ 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 solve(){
    int n = scan!int, m = scan!int;
    long p = scan!long;

    long[] as = scan!long(n);
    long[] bs = scan!long(m);

    int imin, jmin;
    foreach(i, a; as) if(a % p != 0){
        imin = i.to!int;
        break;
    }
    foreach(j, b; bs) if(b % p != 0){
        jmin = j.to!int;
        break;
    }
    print(imin + jmin);
}

//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.random;

final class InputReader {
  private:
  ubyte[] p, buffer;
  bool eof;
  bool rawRead () {
    if (eof) {
      return false;
    }
    p = stdin.rawRead (buffer);
    if (p.empty) {
      eof = true;
      return false;
    }
    return true;
  }
  ubyte nextByte(bool check) () {
    static if (check) {
      if (p.empty) {
        if (!rawRead ()) {
          return 0;
        }
      }
    }
    auto r = p.front;
    p.popFront ();
    return r;
  }
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
  }
  bool seekByte (in ubyte lo) {
    while (true) {
      p = p.find! (c => c >= lo);
      if (!p.empty) {
        return false;
      }
      if (!rawRead ()) {
        return true;
      }
    }
  }
  template next(T) if (isSigned!T) {
    T next ()  {
      if (seekByte (45)) {
        return 0;
      }
      T res;
      ubyte b = nextByte!false ();
      if (b == 45) {
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    T next () {
      if (seekByte (48)) {
        return 0;
      }
      T res = nextByte!false () - 48;
      while (true) {
        ubyte b = nextByte!true ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  T[] nextA(T) (in int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

void main() {
  auto r = new InputReader ();
  const n = r.next!uint ();
  const m = r.next!uint ();
  const p = r.next!uint ();
  auto a = r.nextA!uint (n);
  auto b = r.nextA!uint (m);
  int i, j;
  for (i = n - 1; i >= 0 && !(a[i] % p); --i) {}
  for (j = m - 1; j >= 0 && !(b[j] % p); --j) {}
  writeln (i + j);
}

//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.random;

final class InputReader {
  private:
  ubyte[] p, buffer;
  bool eof;
  bool rawRead () {
    if (eof) {
      return false;
    }
    p = stdin.rawRead (buffer);
    if (p.empty) {
      eof = true;
      return false;
    }
    return true;
  }
  ubyte nextByte(bool check) () {
    static if (check) {
      if (p.empty) {
        if (!rawRead ()) {
          return 0;
        }
      }
    }
    auto r = p.front;
    p.popFront ();
    return r;
  }
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
  }
  bool seekByte (in ubyte lo) {
    while (true) {
      p = p.find! (c => c >= lo);
      if (!p.empty) {
        return false;
      }
      if (!rawRead ()) {
        return true;
      }
    }
  }
  template next(T) if (isSigned!T) {
    T next ()  {
      if (seekByte (45)) {
        return 0;
      }
      T res;
      ubyte b = nextByte!false ();
      if (b == 45) {
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    T next () {
      if (seekByte (48)) {
        return 0;
      }
      T res = nextByte!false () - 48;
      while (true) {
        ubyte b = nextByte!true ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  T[] nextA(T) (in int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

void main() {
  auto r = new InputReader ();
  const n = r.next!uint ();
  const m = r.next!uint ();
  const p = r.next!uint ();
  auto a = r.nextA!uint (n);
  auto b = r.nextA!uint (m);
  int i, j;
  for (i = n - 1; i >= 0 && !(a[i] % p); --i) {}
  for (j = m - 1; j >= 0 && !(a[j] % p); --j) {}
  writeln (i + j);
}


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

void main()
{
    int[] fst = readln().split.map!"a.to!int".array;
    int[] snd = readln().split.map!"a.to!int".array;
    int[] thr = readln().split.map!"a.to!int".array;

    int aUG = snd.filter!(x => x % 2 == 1)
        .array
        .length
        .to!int;
    int aG = snd.filter!(x => x % 2 == 0)
        .array
        .length
        .to!int;
    int bUG = thr.filter!(x => x % 2 == 1)
        .array
        .length
        .to!int;
    int bG = thr.filter!(x => x % 2 == 0)
        .array
        .length
        .to!int;

    (min(aUG, bG) + min(aG, bUG)).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); }

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;
	int m = read.to!int;

	long[] as = readln.chomp.split.to!(long[]);
	long[] bs = readln.chomp.split.to!(long[]);

	int oddacnt, oddbcnt, evenacnt, evenbcnt;
	foreach(a; as) if(a % 2 == 0) evenacnt += 1; else oddacnt += 1;
	foreach(b; bs) if(b % 2 == 0) evenbcnt += 1; else oddbcnt += 1;

	int ans = min(evenacnt, oddbcnt) + min(oddacnt, evenbcnt);

	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!int;
	auto M = RD!int;
	auto a = RDR.ARR;
	auto b = RDR.ARR;

	long cnt_a;
	foreach (i; 0..N)
	{
		if (a[i] % 2 == 1)
			++cnt_a;
	}
	long cnt_b;
	foreach (i; 0..M)
	{
		if (b[i] % 2 == 1)
			++cnt_b;
	}
	long ans;
	ans += min(cnt_a, M - cnt_b);
	ans += min(cnt_b, N - cnt_a);

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

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

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

    long a = A.map!(a => a % 2 == 0).sum;
    long b = A.map!(a => a % 2 == 1).sum;
    long c = B.map!(a => a % 2 == 0).sum;
    long d = B.map!(a => a % 2 == 1).sum;

    writeln(min(a, d) + min(b, c));
}

//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;

class InputReader {
  private:
  ubyte[] p;
  ubyte[] buffer;
  size_t cur;
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
    p = stdin.rawRead (buffer);
  }
  final ubyte skipByte (ubyte lo) {
    while (true) {
      auto a = p[cur .. $];
      auto r = a.find! (c => c >= lo);
      if (!r.empty) {
        cur += a.length - r.length;
        return p[cur++];
      }
      p = stdin.rawRead (buffer);
      cur = 0;
      if (p.empty) return 0;
    }
  }
  final ubyte nextByte () {
    if (cur < p.length) {
       return p[cur++];
    }
    p = stdin.rawRead (buffer);
    if (p.empty) return 0;
    cur = 1;
    return p[0];
  }

  template next(T) if (isSigned!T) {
    final T next ()  {
      T res;
      ubyte b = skipByte (45);
      if (b == 45) {
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    final T next () {
      T res = skipByte (48) - 48;
      while (true) {
        ubyte b = nextByte ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
}

void main() {
  auto r = new InputReader;
  int n = r.next!int, m = r.next!int;
  auto f (int k) {
    auto c = new int[2];
    foreach (i; 0 .. k) {
      ++c[1 & r.next!int];
    }
    return c;
  }
  auto a = f (n), b = f (m);
  writeln (min (a[0], b[1]) + min (a[1], b[0]));
}

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

void main()
{
    int[] fst = readln().split.map!"a.to!int".array;
    int[] snd = readln().split.map!"a.to!int".array;
    int[] thr = readln().split.map!"a.to!int".array;

    int a = snd.filter!(x => x % 2 == 1)
        .array
        .length
        .to!int;
    int b = snd.filter!(x => x % 2 == 0)
        .array
        .length
        .to!int;
    int c = thr.filter!(x => x % 2 == 1)
        .array
        .length
        .to!int;
    int d = thr.filter!(x => x % 2 == 0)
        .array
        .length
        .to!int;

    min(a, b, c, d).writeln;
}

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

void main()
{
    int[] fst = readln().split.map!"a.to!int".array;
    int[] snd = readln().split.map!"a.to!int".array;
    int[] thr = readln().split.map!"a.to!int".array;

    int aUG = snd.filter!(x => x % 2 == 1)
        .array
        .length
        .to!int;
    int aG = snd.filter!(x => x % 2 == 0)
        .array
        .length
        .to!int;
    int bUG = thr.filter!(x => x % 2 == 1)
        .array
        .length
        .to!int;
    int bG = thr.filter!(x => x % 2 == 0)
        .array
        .length
        .to!int;

    max(min(aUG, bG), min(aG, bUG)).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(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;
		foreach (i; 0..n)
		{
			ans[ti] ~= (i+1)%n + 1;
		}
	}

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

import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main () {
	auto tests = readln.strip.to!int;
	foreach (test; 0..tests)
		readln.strip.to!int.iota.map!q{a+1}.drop(1).chain(1.only).writefln!"%(%s %)";
}


import std.stdio;
import std.algorithm;

struct Score
{
    public string player;
    public int score;
}

void main()
{
    int n;
    Score[] game;
    int[string] totalScores;

    readf(" %d", &n);
    for (int i = 0; i < n; ++i)
    {
        string player;
        int score;

        readf(" %s %d", &player, &score);
        game ~= Score(player, score);
        totalScores[player] += score;
    }

    int maxScore = 0;
    foreach (score; totalScores.values)
    {
        if (score > maxScore)
        {
            maxScore = score;
        }
    }

    string[] potentialWinners;
    foreach (player, score; totalScores)
    {
        if (score == maxScore)
        {
            potentialWinners ~= player;
        }
    }

    totalScores.clear();

    string winner;
    foreach (con; game)
    {
        totalScores[con.player] += con.score;
        if (totalScores[con.player] >= maxScore && canFind(potentialWinners, con.player))
        {
            winner = con.player;
            break;
        }
    }

    writeln(winner);
}

import std.stdio, std.array, std.algorithm;

void main() {
	uint n;
	long[string] score;
	long[string] s2;
	string[] gn;
	long[] gs;
	readf("%s", &n);
	string mname;
	foreach(i; 0 .. n) {
		long sc;
		string name;
		readf("\n%s %d", &name, &sc);
		score[name] += sc;
		gn ~= name;
		gs ~= sc;
	}
	auto m = score.reduce!(max);

	foreach(i; 0 .. n) {
		s2[gn[i]] += gs[i];
		if (s2[gn[i]] >= m && score[gn[i]] == m) {
			writeln(gn[i]);
			break;
		}
	}
}

import std.stdio;
import std.algorithm;
import std.regex;
import std.math;
import std.conv;
import std.string;
import core.stdc.stdio;
import core.stdc.string;
import std.array;

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

struct Round
{
	string name;
	int points;
}

int main()
{
	int n;
	string l = readline();
	n = parse!int(l);
	int[string] scoreboard;
	Round[] rounds; rounds.length = n;
	foreach (int i; 0..n)
	{
		int points;
		l = readline();
		string[] values = split(l);
		points = parse!int(values[1]);
		string nm = values[0];
		scoreboard[nm] += points;
		rounds[i].name = nm;
		rounds[i].points = points;
	}

	int max = int.min;
	foreach (string key; scoreboard.byKey)
	{
		if (scoreboard[key] > max) max = scoreboard[key];
	}

	bool[string] maxers;
	foreach (string key; scoreboard.byKey)
	{
		if (scoreboard[key] == max)
			maxers[key] = true;
		scoreboard[key] = 0;
	}

	string name = "";
	foreach (int i; 0..n)
	{
		scoreboard[rounds[i].name] += rounds[i].points;
		if (rounds[i].name in maxers && scoreboard[rounds[i].name] >= max)
		{
			name = rounds[i].name;
			break;
		}
	}

	write (name);
	return 0;
}

import std.stdio;
import std.ascii;
import std.conv;
import std.algorithm;
import std.container;
import std.exception;

string nextToken() {
    char c;
    string res;
    while (readf("%s", &c) == 1) {
        if (isWhite(c)) {
            if (res.length > 0)
                break;
        } else
            res ~= c;
    }
    return res;
}

auto read(T)() {
    return nextToken.to!T;
}
bool read(T)(ref T val) {
    try {
        val = read!T;
        return true;
    } catch (ConvException)
        return false;
}

void reset(T)(ref T val) {
    val = T.init;
}

bool solve(int test) {
    int n;
    if (!read(n))
        return false;

    struct op {
        string name;
        int val;
    }
    op[] ops = new op[n];
    int score[string];

    foreach (ref cur; ops) {
        cur.name = read!string;
        cur.val = read!int;

        if (cur.name !in score)
            score[cur.name] = 0;
        score[cur.name] += cur.val;
    }
    int maxScore = 0;
    foreach (cur; score.byValue)
        maxScore = max(maxScore, cur);

    byte[string] maxPlayers;
    foreach (name, cur; score) {
        if (cur == maxScore)
            maxPlayers[name] = 0;
    }

    score.reset;
    bool found = false;
    foreach (cur; ops) {
        if (cur.name !in maxPlayers)
            continue;
        if (cur.name !in score)
            score[cur.name] = 0;
        score[cur.name] += cur.val;
        if (score[cur.name] >= maxScore) {
            writeln(cur.name);
            found = true;
            break;
        }
    }
    assert(found);
    return true;
}

void main() {
    int test = 0;
    while (solve(test))
        test++;
}

import std.stdio;
import std.algorithm;
import std.regex;
import std.math;
import std.conv;

int main()
{
	int n;
	scanf("%d", &n);
	int[string] scoreboard;
	char[32] name;
	string max = "";
	int max_points = 0;
	foreach (int i; 0..n)
	{
		int points;
		scanf("%s %d", &name, &points);
		string nm = to!string(name);
		scoreboard[nm] += points;
		if (scoreboard[nm] > max_points)
		{
			max = nm;
			max_points = scoreboard[nm];
		}
	}
	write(max);
	return 0;
}

import std.stdio;
import std.algorithm;
import std.regex;
import std.math;
import std.conv;
import std.string;
import core.stdc.stdio;
import core.stdc.string;
import std.array;

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

int main()
{
	int n;
	string l = readline();
	n = parse!int(l);
	int[string] scoreboard;
	string[] max;
	max ~= "";
	int[] max_points;
	max_points ~= int.min;
	foreach (int i; 0..n)
	{
		int points;
		l = readline();
		string[] values = split(l);
		points = parse!int(values[1]);
		string nm = values[0];
		scoreboard[nm] += points;
		if (nm == max.back)
		{
			max_points.back = scoreboard[nm];
			if (max_points[$-1] < max_points[$-2])
			{
				max_points.popBack();
				max.popBack();
			}
		} else
		if (scoreboard[nm] > max_points.back)
		{
			max ~= nm;
			max_points ~= scoreboard[nm];
		}
	}
	write(max.back);
	return 0;
}

import std.stdio;
import std.algorithm;
import std.regex;
import std.math;
import std.conv;
import std.string;
import core.stdc.stdio;
import core.stdc.string;

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

int main()
{
	int n;
	string l = readline();
	n = parse!int(l);
	int[string] scoreboard;
	string max = "";
	int max_points = int.min;
	foreach (int i; 0..n)
	{
		int points;
		l = readline();
		string[] values = split(l);
		points = parse!int(values[1]);
		string nm = values[0];
		scoreboard[nm] += points;
		if (nm == max)
		{
			max_points = scoreboard[nm];
		} else
		if (scoreboard[nm] > max_points)
		{
			max = nm;
			max_points = scoreboard[nm];
		}
	}
	write(max);
	return 0;
}

import std.stdio;
import std.algorithm;
import std.regex;
import std.math;
import std.conv;
import std.string;
import core.stdc.stdio;
import core.stdc.string;
import std.array;

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

int main()
{
	int n;
	string l = readline();
	n = parse!int(l);
	int[string] scoreboard;
	string[int] maxers;
	foreach (int i; 0..n)
	{
		int points;
		l = readline();
		string[] values = split(l);
		points = parse!int(values[1]);
		string nm = values[0];
		scoreboard[nm] += points;
		if (!(scoreboard[nm] in maxers))
		{
			maxers[scoreboard[nm]] = nm;
		}
	}

	int max = int.min;
	foreach (string key; scoreboard.byKey)
	{
		if (scoreboard[key] > max)
			max = scoreboard[key];
	}
	write(maxers[max]);
	return 0;
}

import std.stdio;
import std.algorithm;
import std.regex;
import std.math;
import std.conv;
import std.string;
import core.stdc.stdio;
import core.stdc.string;
import std.array;

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

int main()
{
	int n;
	string l = readline();
	n = parse!int(l);
	int[string] scoreboard;
	int[string] pos;
	int[string] ms;
	foreach (int i; 0..n)
	{
		int points;
		l = readline();
		string[] values = split(l);
		points = parse!int(values[1]);
		string nm = values[0];
		int pv = (nm in scoreboard ? scoreboard[nm] : int.min);
		scoreboard[nm] += points;
		if (nm in ms)
		{
			if (scoreboard[nm] > ms[nm])
			{
				ms[nm] = scoreboard[nm];
				pos[nm] = i;
			}
		} else {
			ms[nm] = scoreboard[nm];
			pos[nm] = i;
		}
	}

	int max = int.min;
	int idx = -1;
	string name = "";
	foreach (string key; scoreboard.byKey)
	{
		if (scoreboard[key] > max)
		{
			max = scoreboard[key];
			name = key;
			idx = pos[key];
		} else
		if (scoreboard[key] == max && pos[key] < idx)
		{
			idx = pos[key];
			max = scoreboard[key];
			name = key;
		}
	}
	write(name);
	return 0;
}

import std.stdio;
import std.algorithm;
import std.regex;
import std.math;
import std.conv;
import std.string;
import core.stdc.stdio;
import core.stdc.string;

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

int main()
{
	int n;
	string l = readline();
	n = parse!int(l);
	int[string] scoreboard;
	string max = "";
	int max_points = int.min;
	foreach (int i; 0..n)
	{
		int points;
		l = readline();
		string[] values = split(l);
		points = parse!int(values[1]);
		string nm = values[0];
		scoreboard[nm] += points;
		if (scoreboard[nm] > max_points)
		{
			max = nm;
			max_points = scoreboard[nm];
		}
	}
	write(max);
	return 0;
}

import std.stdio;
import std.algorithm;
import std.regex;
import std.math;
import std.conv;
import std.string;
import core.stdc.stdio;
import core.stdc.string;

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

int main()
{
	int n;
	string l = readline();
	n = parse!int(l);
	int[string] scoreboard;
	string max = "";
	int max_points = 0;
	foreach (int i; 0..n)
	{
		int points;
		l = readline();
		string[] values = split(l);
		points = parse!int(values[1]);
		string nm = values[0];
		scoreboard[nm] += points;
		if (scoreboard[nm] > max_points)
		{
			max = nm;
			max_points = scoreboard[nm];
		}
	}
	write(max);
	return 0;
}

import std.stdio;
import std.algorithm;
import std.regex;
import std.math;
import std.conv;
import std.string;
import core.stdc.stdio;
import core.stdc.string;
import std.array;

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

int main()
{
	int n;
	string l = readline();
	n = parse!int(l);
	int[string] scoreboard;
	string[] max;
	max ~= "";
	int[] max_points;
	max_points ~= int.min;
	string[int] maxers;
	foreach (int i; 0..n)
	{
		int points;
		l = readline();
		string[] values = split(l);
		points = parse!int(values[1]);
		string nm = values[0];
		scoreboard[nm] += points;
		if (nm == max.back)
		{
			max_points.back = scoreboard[nm];
			if (max_points[$-1] < max_points[$-2])
			{
				max_points.popBack();
				max.popBack();
			} else {
				if (!(scoreboard[nm] in maxers))
					maxers[scoreboard[nm]] = nm;
			}
		} else
		if (scoreboard[nm] > max_points.back)
		{
			if (!(scoreboard[nm] in maxers))
				maxers[scoreboard[nm]] = nm;
			max ~= nm;
			max_points ~= scoreboard[nm];
		}
	}
	write(maxers[max_points.back]);
	return 0;
}

import std.stdio;

struct Score
{
    public string player;
    public int score;
}

void main()
{
    int n;
    Score[] game;
    int[string] totalScores;

    readf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        string player;
        int score;

        readf("%s %d", &player, &score);
        game ~= Score(player, score);
        totalScores[player] += score;
    }

    int maxScore = 0;
    foreach (score; totalScores.values)
    {
        if (score > maxScore)
        {
            maxScore = score;
        }
    }
    totalScores.clear();

    string winner;
    foreach (con; game)
    {
        totalScores[con.player] += con.score;
        if (totalScores[con.player] == maxScore)
        {
            winner = con.player;
            break;
        }
    }

    writeln(winner);
}

import std.stdio, std.array, std.algorithm;

void main() {
	long n;
	long[string] score;
	readf("%s\n", &n);
	long max = 0;
	string mname;
	foreach(i; 0 .. n) {
		long sc;
		string name;
		readf("%s %d\n", &name, &sc);
		score[name] += sc;
		if (score[name] > max) {
			mname = name;
			max = score[name];
		}
	}
	writeln(mname);
}


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, m;
		readf !(" %s %s") (n, m);
		readln;
		int [] [] a;
		foreach (i; 0..n)
		{
			a ~= readln.splitter.map !(to !(int)).array;
		}
		foreach (i; 0..n)
		{
			sort (a[i]);
		}
		auto answer = new int [] [] (n, m);
		foreach (j; 0..m)
		{
			int best = 0;
			foreach (i; 1..n)
			{
				if (!a[i].empty && a[best].front > a[i].front)
				{
					best = i;
				}
			}
			answer[best][j] = a[best].front;
			a[best].popFront ();
		}
		foreach (i; 0..n)
		{
			foreach (j; 0..m)
			{
				if (answer[i][j] == 0)
				{
					answer[i][j] = a[i].front;
					a[i].popFront ();
				}
			}
		}
		foreach (i; 0..n)
		{
			writefln !("%(%s %)") (answer[i]);
		}
	}
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const N = readInt();
        const M = readInt();
        auto B = new long[][](N, M);
        foreach (i; 0 .. N) {
          foreach (j; 0 .. M) {
            B[i][j] = readLong();
          }
          B[i].sort;
        }
        debug {
          writeln("B = ", B);
        }

        auto ls = new int[N];
        auto rs = new int[N];
        ls[] = 0;
        rs[] = M;

        auto ans = new long[][](M, N);
        foreach (h; 0 .. M) {
          int im = -1;
          foreach (i; 0 .. N) {
            if (im == -1 || B[im][ls[im]] > B[i][ls[i]]) {
              im = i;
            }
          }
          debug {
            writeln(ls, " ", rs, " ", im, " ", B[im][ls[im]]);
          }
          ans[h][im] = B[im][ls[im]++];
          foreach (i; 0 .. N) {
            if (im != i) {
              ans[h][i] = B[i][--rs[i]];
            }
          }
        }

        foreach (i; 0 .. N) {
          foreach (h; 0 .. M) {
            if (h > 0) write(" ");
            write(ans[h][i]);
          }
          writeln;
        }
      }
    }
  } catch (EOFException e) {
  }
}


import std;

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto n = readln.strip.to!long;
    auto s = readln.strip;
    int ans = 0;
    foreach (ch ; s)
      ans = max(ans, ch - 'a' + 1);
    writeln(ans);
  }
}

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

void main()
{
    auto t = readln().strip().to!int;
    foreach (i; 0..t)
    {
        auto n = readln().strip().to!int;
        auto s = readln().strip().dup.array;
        sort(s);
        writefln("%d", s[$-1] - 'a' + 1);
    }
}


module cf_296A;

import std.stdio;

void main() {
    immutable MAX_NUMBER = 1000;

    int n, num;
    int[MAX_NUMBER + 1] counters;

    readf("%d", &n);
    for (int i = 0; i < n; ++i) {
        readf(" %d", &num);
        ++counters[num];
    }

    bool canExchange = true;
    for (int i = counters.length - 1; i >= 0; --i) {
        if (2 * counters[i] - 1 > n) {
            canExchange = false;
            break;
        }
    }

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

module sigod.codeforces.p296A;

import std.stdio;

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

	int[] array = new int[n];

	foreach (ref a; array) {
		stdin.readf(" %s", &a);
	}

	stdout.writeln(solve(array) ? "YES" : "NO");
}

bool solve(int[] array)
{
	if (array.length == 1) return true;

	int[int] counts;

	foreach (e; array) {
		++counts[e];
	}

	int max = 0;
	foreach (value; counts.byValue) {
		if (value > max) max = value;
	}

	return (max - 1) <= (array.length - max);
}

unittest {
	assert(solve([1]) == true);
	assert(solve([1, 1, 2]) == true);
	assert(solve([7, 7, 7, 7]) == false);
}


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

string FMT_F = "%.10f";

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

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

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

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

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

		auto index = a.MAKE_IDX;
		bool ok = true;
		foreach (i; index)
		{
			if (B <= 0)
			{
				ok = false;
				break;
			}
			auto cnt = (b[i]+A-1) / A;
			B -= a[i] * cnt;
			if (B <= -a[i])
			{
				ok = false;
				break;
			}
		}
		ans[ti] = ok;
	}

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

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

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

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

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

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

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

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

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

alias E = Tuple!(long, "a", long, "b");

void main()
{
    int T; get(T);
    while (T--) {
        long A, B; int N; get(A, B, N);
        auto es = new E[](N);
        foreach (i, a; readln.split) es[i].a = a.to!long;
        foreach (i, b; readln.split) es[i].b = b.to!long;
        sort!"a.a < b.a"(es);
        foreach (e; es) with (e) {
            auto t = b / A - (b % A == 0 ? 1 : 0);
            B -= a * t;
            if (B <= 0) {
                writeln("NO");
                goto next;
            }
            B -= a;
        }
        writeln("YES");
        next:
    }
}

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

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

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

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

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

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

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

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

void main()
{
    int T; get(T);
    while (T--) {
        long A, B; int N; get(A, B, N);
        long[] aa; get(aa);
        long[] bb; get(bb);
        foreach (i; 0..N) {
            auto a = aa[i];
            auto b = bb[i];
            auto t = b / A - (b % A == 0 ? 1 : 0);
            B -= a * t;
            if (B <= 0) {
                writeln("NO");
                goto next;
            }
            B -= a;
        }
        writeln("YES");
        next:
    }
}


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;

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		auto a = new int [] [] (n, m);
		foreach (i; 0..n)
		{
			foreach (j; 0..m)
			{
				readf (" %s", &a[i][j]);
			}
		}

		auto f = new int [4] [] [] (n, m);
		foreach (k; 0..4)
		{
			foreach (i; 0..n)
			{
				foreach (j; 0..m)
				{
					int cur = 0;
					if (i > 0)
					{
						cur = max (cur, f[i - 1][j][k]);
					}
					if (j > 0)
					{
						cur = max (cur, f[i][j - 1][k]);
					}
					f[i][j][k] = cur + a[i][j];
				}
			}

			auto b = new int [] [] (m, n);
			auto g = new int [4] [] [] (m, n);
			foreach (i; 0..n)
			{
				foreach (j; 0..m)
				{
					b[j][n - 1 - i] = a[i][j];
					g[j][n - 1 - i] = f[i][j];
				}
			}
			a = b;
			f = g;
			swap (m, n);
		}
		debug {writeln (f);}

		int res = 0;
		foreach (i; 1..n - 1)
		{
			foreach (j; 1..m - 1)
			{
				int cur = max (f[i - 1][j][0] +
				               f[i + 1][j][2] +
				               f[i][j - 1][1] +
				               f[i][j + 1][3],
				               f[i - 1][j][3] +
				               f[i + 1][j][1] +
				               f[i][j - 1][0] +
				               f[i][j + 1][2]);
				res = max (res, cur);
			}
		}
		writeln (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, core.stdc.stdio;

void main() {
    auto T = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    foreach (a; A) {
        auto m = a % 14;
        if (a <= 14) {
            writeln("NO");
        } else if (m != 0 && m <= 6) {
            writeln("YES");
        } else {
            writeln("NO");
        }
    }
}

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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
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 x = RDA;
	foreach (i; 0..t)
	{
		if (x[i] < 15)
			writeln("NO");
		else
		{
			auto y = x[i] % 14;
			writeln(y <= 6 && y != 0 ? "YES" : "NO");
		}
	}

	stdout.flush;
	debug readln;
}

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

bool solve (long n)
{
	return n > 14 && 1 <= n % 14 && n % 14 <= 6;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		long n;
		readf !(" %s") (n);
		writeln (solve (n) ? "YES " : "NO");
	}
}

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

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

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

	foreach(a; as){
		if(a < 15) "NO".writeln;
		else if(a % 14 >= 1 && a % 14 <= 6) "YES".writeln;
		else "NO".writeln;
	}
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const X = readLong();
        const q = X / 14, r = X % 14;
        const ans = (q >= 1 && 1 <= r && r <= 6);
        writeln(ans ? "YES" : "NO");
      }
    }
  } catch (EOFException e) {
  }
}

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

void main() {
    auto T = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    foreach (a; A) {
        auto m = a % 14;
        if (a <= 14) {
            writeln("NO");
        } else if (m <= 6) {
            writeln("YES");
        } else {
            writeln("NO");
        }
    }
}

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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
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 x = RDA;
	foreach (i; 0..t)
	{
		auto y = x[i] % 14;
		writeln(y <= 6 && y != 0 ? "YES" : "NO");
	}

	stdout.flush;
	debug readln;
}