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 n = RD!int;
	auto a = RDA!int;
	auto q = RD!int;

	auto cnt = new int[](10^^5+1);
	long a2, a4, a6, a8;
	void update1(int x)
	{
		if (cnt[x] == 8)
		{
			++a8;
			--a6;
		}
		else if (cnt[x] == 6)
		{
			++a6;
			--a4;
		}
		else if (cnt[x] == 4)
		{
			++a4;
			--a2;
		}
		else if (cnt[x] == 2)
		{
			++a2;
		}
	}
	void update2(int x)
	{
		if (cnt[x] == 7)
		{
			--a8;
			++a6;
		}
		else if (cnt[x] == 5)
		{
			--a6;
			++a4;
		}
		else if (cnt[x] == 3)
		{
			--a4;
			++a2;
		}
		else if (cnt[x] == 1)
		{
			--a2;
		}
	}
	foreach (i; 0..n)
	{
		++cnt[a[i]];
		update1(a[i]);
	}
	foreach (i; 0..q)
	{
		auto s = RD!string;
		auto x = RD!int;
		if (s == "+")
		{
			++cnt[x];
			update1(x);
		}
		else
		{
			--cnt[x];
			update2(x);
		}
		auto ans = a4 >= 1 || a6 >= 1 || a8 >= 1;
		ans &= a2 + a4*2 + a6*3 + a8*4 >= 4;
		writeln(ans ? "YES" : "NO");
	}

	stdout.flush;
	debug readln;
}

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

immutable int limit = 9;

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		int [int] num;
		int [limit] good;

		void account (int v, int delta)
		{
			num[v] += 0;
			foreach (i; 0..min (limit, num[v] + 1))
			{
				good[i] += delta;
			}
		}

		void change (int v, int delta)
		{
			account (v, -1);
			num[v] += delta;
			account (v, +1);
		}

		foreach (ref c; a)
		{
			change (c, +1);
		}
		int q;
		readf !(" %s") (q);
		readln;

		bool can ()
		{
			if (good[8] >= 1)
			{
				return true;
			}
			if (good[6] >= 1 && good[2] >= 2)
			{
				return true;
			}
			if (good[4] >= 2)
			{
				return true;
			}
			if (good[4] >= 1 && good[2] >= 3)
			{
				return true;
			}
			return false;
		}

		foreach (j; 0..q)
		{
			auto t = readln.split;
			change (t[1].to !(int), (t[0] == "+" ? +1 : -1));
			writeln (can () ? "YES" : "NO");
		}
	}
}

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

alias type = single;
struct TestCase
{
  mixin prettyPrinting;

  long n;
  @Dim("n") long[] a;
  long q;
  @Dim("q") Tuple!(string, long)[] events;

  void solve(long tc = -1)
  {
    long[long] store;
    foreach(ai; a)
      {
        store.require(ai, 0)++;
      }
    auto mostUnits = redBlackTree!((a, b) {
        if (a[0] > b[0])
          return true;
        if (a[0] < b[0])
          return false;
        return a[1] < b[1];
      }, Tuple!(long, long))();
    foreach(t, c; store)
      {
        mostUnits.insert(tuple(c, t));
      }

  nextEvent:foreach(event; events)
      {
        string type = event[0];
        long x = event[1];
        store.require(x, 0);
        mostUnits.removeKey(tuple(store[x], x));
        store[x] += type == "+"? 1 : -1;
        mostUnits.insert(tuple(store[x], x));
        auto arr = mostUnits[].take(3).map!(t => t[0]).array;
        if (arr[0] >= 4)
          {
            arr[0] -= 4;
            foreach(v; arr)
              {
                if (v >= 4)
                  {
                    writeln("YES");
                    continue nextEvent;
                  }
              }
            foreach(i; 0 .. arr.length - 1)
              {
                if (arr[i] >= 2 && arr[i + 1] >= 2)
                  {
                    writeln("YES");
                    continue nextEvent;
                  }
              }
            writeln("NO");
          }
        else
          {
            writeln("NO");
          }
      }
  }
}

struct Interval
{
  long l, h;

  bool empty()
  {
    return l > h;
  }
}

Interval intersect(Interval a, Interval b)
{
  return Interval(max(a.l, b.l), min(a.h, b.h));
}

struct If
{
  string condition;
}
enum ignore = If("false");
struct Dim
{
  string dimensions;
  int levels;
  this(string dimensions)
  {
    this.dimensions = dimensions;
    levels = cast(int)dimensions.count(",") + 1;
  }
}

template getArrayLevel(W)
{
  static if (isDynamicArray!W && !is(W == string))
    enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));
  else
    enum getArrayLevel = 0;
}

static foreach(fieldName; 'a' .. cast(char)('z' + 1))
  {
    static if (fieldName != 'o')
      mixin("enum d", fieldName, " = Dim(\"", fieldName, "\");");
  }

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

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

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

DList!string _words;

template removeArray(W, int times)
{
  static if (times == 0)
    alias removeArray = W;
  else static if (times == 1)
    alias removeArray = typeof(function(){W w; return w[0];}());
  else
    {
      static assert(isDynamicArray!W);
      alias removeArray = removeArray!(removeArray!(W, 1), times - 1);
    }
}

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

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

void read(T...)(ref T t)
{
  void basicTypeRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  void iterableRead(W)(ref W w)
  {
    foreach(ref element; w)
      read(element);
  }
  void tupleRead(W)(ref W w)
  {
    static foreach(j; 0 .. W.length)
      read(w[j]);
  }
  void structRead(W)(ref W readStruct)
  {
    static foreach(fieldName; FieldNameTuple!W)
      {
        with(readStruct)
          {
            alias fieldSymbol = mixin(W.stringof, ".", fieldName);
            alias typeOfField = typeof(mixin(fieldName));
            static if (hasUDA!(fieldSymbol, If))
              enum condition = getUDAs!(fieldSymbol, If)[0].condition;
            else
              enum condition = "true";

            if (mixin(condition))
              {
                static if (hasUDA!(fieldSymbol, Dim))
                  {
                    static assert(isDynamicArray!(typeOfField)
                                  , text(W.stringof, ".", fieldName, " has Dim UDA but isn't a Dynamic Array."));
                    enum uda = getUDAs!(fieldSymbol, Dim)[0];
                    static assert(getArrayLevel!(typeOfField) == uda.levels,
                                  text(W.stringof, ".", fieldName, " has a Dim UDA with different number of dimensions than it's type."));
                    mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});
                  }
                else static if (isDynamicArray!typeOfField && !is(typeOfField == string))
                  {
                    pragma(msg, "Warning: You probably want to add dimension to input ", W.stringof, ".", fieldName);
                  }
                read(mixin(fieldName));
              }
          }
      }
  }
  static foreach(i; 0 .. T.length)
    {
      static if (isBasicType!(T[i]) || is(T[i] == string))
        basicTypeRead(t[i]);
      else static if (is(typeof({foreach(ref e; t[i]){}})))
        iterableRead(t[i]);
      else static if (isTuple!(T[i]))
        tupleRead(t[i]);
      else static if (isAggregateType!(T[i]))
        structRead(t[i]);
    }
}

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

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

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

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

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

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

    }
}

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

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

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

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

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

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

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

void main()
{
  type;
}


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

void solve() {
    int N, K; readf("%d %d\n", &N, &K);
    auto S = readln.chomp;

    int[char] s;
    foreach (c; S) {
        s[c] = s.get(c, 0) + 1;
    }

    char[] ans = new char[K];
    for (int i = 0; i < K; i++) {
        char x = '?';
        int n = 0;
        for (char c = 'a'; c <= 'z'; c++, n++) {
            if (n == N/K) {
                x = c;
                break;
            } else if (c !in s || s[c] == 0) {
                x = c;
                break;
            } else {
                s[c]--;
            }
        }
        ans[i] = x;
    }
    writeln(ans);
}

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

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

immutable int letters = 26;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		readln;
		auto s = readln.strip;
		auto c = new int [letters];
		foreach (ref x; s)
		{
			c[x - 'a'] += 1;
		}
		string res;
		foreach (i; 0..k)
		{
			int x = 0;
			while (x < n / k && c[x] > 0)
			{
				c[x] -= 1;
				x += 1;
			}
			res ~= cast (char) (x + 'a');
		}
		writeln (res);
	}
}


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 n, l, r;
		readf !(" %s %s %s") (n, l, r);
		readln;
		auto c = readln.splitter.map !(to !(int)).array;
		c[] -= 1;

		auto b = new int [n];
		foreach (i; 0..l)
		{
			b[c[i]] += 1;
		}
		foreach (i; l..n)
		{
			b[c[i]] -= 1;
		}
		debug {writeln (b);}

		int lo = 0;
		int hi = 0;
		foreach (j; 0..n)
		{
			if (b[j] & 1)
			{
				if (b[j] > 0)
				{
					hi += 1;
					b[j] -= 1;
				}
				else
				{
					lo += 1;
					b[j] += 1;
				}
			}
		}

		int res = min (lo, hi);
		lo -= res;
		hi -= res;
		debug {writeln (res, " ", lo, " ", hi);}
		debug {writeln (b);}

		foreach (j; 0..n)
		{
			if (lo > 0 && b[j] > 0)
			{
				int cur = min (+b[j], lo);
				res += cur;
				b[j] -= cur;
				lo -= cur;
			}
			if (hi > 0 && b[j] < 0)
			{
				int cur = min (-b[j], hi);
				res += cur;
				b[j] += cur;
				hi -= cur;
			}
		}
		res += lo;
		res += hi;

		foreach (j; 0..n)
		{
			res += abs (b[j]) / 2;
			b[j] %= 2;
		}

		res += b.map !(abs).sum;
		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)); }
double[] rotate(double[] vec, double rad) { return [cos(rad) * vec[0] - sin(rad) * vec[1], sin(rad) * vec[0] + cos(rad) * vec[1]]; }

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

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto l = RD!int;
		auto r = RD!int;
		auto c = RDA!int(-1);

		auto cnt = new int[](n);
		foreach (i; 0..l)
			++cnt[c[i]];
		foreach (i; l..n)
			--cnt[c[i]];

		long[] ls, rs;
		long odd_l, odd_r;
		long cnt_l, cnt_r;
		foreach (i; 0..n)
		{
			if (cnt[i] > 0)
			{
				ls ~= cnt[i];
				cnt_l += cnt[i];
				if (cnt[i] % 2)
					++odd_l;
			}
			else if (cnt[i] < 0)
			{
				rs ~= -cnt[i];
				cnt_r += -cnt[i];
				if ((-cnt[i]) % 2)
					++odd_r;
			}
		}
		{
			auto x = min(odd_l, odd_r);
			odd_l -= x;
			odd_r -= x;
			cnt_l -= x;
			cnt_r -= x;
			ans[ti] += x;

			if (odd_l != 0)
			{
				auto y = min(odd_l, cnt_r);
				odd_l -= y;
				cnt_l -= y;
				cnt_r -= y;
				ans[ti] += y;
			}
			else if (odd_r != 0)
			{
				auto y = min(odd_r, cnt_l);
				odd_r -= y;
				cnt_l -= y;
				cnt_r -= y;
				ans[ti] += y;
			}

			if (odd_l != 0)
			{
				cnt_l -= odd_l;
				ans[ti] += odd_l;
			}
			else if (odd_r != 0)
			{
				cnt_r -= odd_r;
				ans[ti] += odd_r;
			}

			ans[ti] += (cnt_l + cnt_r) / 2;
		}
	}

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

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

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

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

void main() {
  int t;
  read(t);

  while (t--) {
    int n, l, r;
    read(n, l, r);

    auto data = list!int;
    auto count = new int[n + 1];
    foreach (i; 0 .. l) {
      count[data[i]]--;
    }
    foreach (i; l .. n) {
      count[data[i]]++;
    }

    alias Sock = Tuple!(bool, "odd", int, "count");
    auto left = count.filter!(a => a < 0).map!(a => Sock(-a % 2 == 1, -a)).array.heapify;
    auto right = count.filter!(a => a > 0).map!(a => Sock(a % 2 == 1, a)).array.heapify;

    int cost = 0;

    while (!left.empty && !right.empty && (left.front.odd || right.front.odd)) {
      auto x = left.removeAny;
      auto y = right.removeAny;
      if (x.count > 1) left.insert(Sock(!x.odd, x.count - 1));
      if (y.count > 1) right.insert(Sock(!y.odd, y.count - 1));
      cost++;
    }

    foreach (h; [left, right]) {
      while (!h.empty) {
        auto x = h.removeAny;
        if (x.odd) {
          h.insert(Sock(!x.odd, x.count - 1));
          cost++;
        } else {
          cost += x.count / 2;
        }
      }
    }

    writeln(cost);
  }
}


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 read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T read(T)(){ return read.to!T; }
T[] read(T)(long n){ return n.iota.map!(_ => read!T).array; }
T[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = read.to!int;

	bool[][] as;
	foreach(i; 0 .. n){
		as ~= readln.to!(char[]).map!(x => x == '#').array;
	}

	string ans = "YES";

	foreach(i; 0 .. n) foreach(j; 0 .. n){
		if(as[i][j]) continue;
		if(j - 1 < 0 || i + 2 >= n || j + 1 >= n){
			"NO".writeln;
			return;
		}
		if(as[i + 1][j - 1] || as[i + 1][j] || as[i + 1][j + 1] || as[i + 2][j]){
			"NO".writeln;
			return;
		}
		as[i][j] = 1;
		as[i + 1][j - 1] = 1;
		as[i + 1][j] = 1;
		as[i + 1][j + 1]  = 1;
		as[i + 2][j] = 1;
	}

	"YES".writeln;
	return;

}

import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array;
import std.algorithm : sort, each, maxElement, minElement;
import std.conv : to;
import std.range : iota, tee;
import std.algorithm.comparison : equal;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;

alias Tree = RBT!int;

void main()
{
    GC.disable();

    uint n;
    readf(" %s\n", n);

    char[][] s;
    foreach (i; 0 .. n)
    {
        auto ss = readln();
        s ~= ss.strip.dup;
    }

    foreach (i; 0 .. n)
    {
        foreach (j; 0 .. n)
        {
            if (s[i][j] == '.')
            {
                foreach (delta; [[0, 0], [1, -1], [1, 0], [1, 1], [2, 0]])
                {
                    auto ni = i + delta[0];
                    auto nj = j + delta[1];
                    if (ni >= n || nj >= n || s[ni][nj] != '.')
                    {
                        writeln("NO");
                        return;
                    }
                    else
                    {
                        s[ni][nj] = '#';
                    }

                }

            }

        }

    }

    writeln("YES");

}

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!uint;
	auto s = new char[][](N);
	foreach (i; 0..N)
	{
		s[i] = RD!(char[]);
	}

	bool visit(uint y, uint x)
	{
		if (s[y+1][x] == '#' ||
			s[y+1][x-1] == '#' ||
			s[y+1][x+1] == '#' ||
			s[y+2][x] == '#')
			return false;

		s[y][x] = '#';
		s[y+1][x] = '#';
		s[y+1][x-1] = '#';
		s[y+1][x+1] = '#';
		s[y+2][x] = '#';
		return true;
	}

	bool ans = true;
	(){
	foreach (y; 0..N)
	{
		foreach (x; 0..N)
		{
			if (s[y][x] == '#') continue;

			debug writeln(y, ":", x);
			if (x == 0 || x == N-1)
			{
				ans = false;
				return;
			}
			else if (y >= N-2)
			{
				ans = false;
				return;
			}

			auto r = visit(y, x);
			if (!r)
			{
				ans = false;
				return;
			}
		}
	}}();

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

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

  int n;
  rd(n);
  auto a = new char[][](n);
  foreach (i; 0 .. n) {
    a[i] = readln.chomp.to!(char[]);
  }
  if (a[0][0] == '.' || a[0][n - 1] == '.' || a[n - 1][0] == '.' || a[n - 1][n - 1] == '.') {
    writeln("NO");
    return;
  }
  for (int i = 1; i + 1 < n; i++) {
    for (int j = 1; j + 1 < n; j++) {
      if (a[i][j] == '.') {
        if (a[i - 1][j] == '#' || a[i][j - 1] == '#' || a[i + 1][j] == '#' || a[i][j + 1] == '#') {
          continue;
        }
        a[i][j] = a[i - 1][j] = a[i][j - 1] = a[i + 1][j] = a[i][j + 1] = '#';
      }
    }
  }
  foreach (i; 0 .. n) {
    foreach (j; 0 .. n) {
      if (a[i][j] == '.') {
        writeln("NO");
        return;
      }
    }
  }
  writeln("YES");
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


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

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

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

void main() {
  int n;
  read(n);

  alias Item = Tuple!(long, "discount", long, "need");
  auto arr = new Item[n];

  foreach (i; 0 .. n) {
    read(arr[i][1], arr[i][0]);
  }

  sort(arr);

  long purchased = 0;
  long answer = 0;

  while (arr.length) {
    if (arr.front.discount <= purchased) {
      purchased += arr.front.need;
      answer += arr.front.need;
      arr.popFront();
    } else {
      auto buy = min(arr.front.discount - purchased, arr.back.need);
      answer += 2 * buy;
      purchased += buy;
      arr.back.need -= buy;
      if (arr.back.need == 0) arr.popBack();
    }
  }

  writeln(answer);
}

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

void main()
{
  long n;
  readf!" %d "(n);
  long[] a;
  long[] b;
  for (long i = 0; i < n; i++) {
    long ai, bi;
    readf!" %d %d "(ai, bi);
    if (ai > 0) {
      a ~= ai;
      b ~= bi;
    }
  }
  auto c = zip(a, b).sort!((x, y) => x[1] < y[1]).array;
//  writeln(c);

  size_t l = 0;
  size_t r = c.length - 1;

  long result = 0;
  long bought = 0;

  while (true) {
    auto x = c[l];
    auto y = c[r];

    if (bought >= x[1]) {
      result += x[0];
      bought += x[0];
      if (l == r)
        break;
      l++;
      continue;
    }

    long buy_from_last = x[1] - bought;
    if (y[0] > buy_from_last) {
      result += buy_from_last * 2;
      bought += buy_from_last;
      y[0] -= buy_from_last;
      c[r] = y;
      continue;
    }

    result += y[0] * 2;
    bought += y[0];
    if (l == r)
      break;
    r--;
  }
  writeln(result);
}


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;
        Node[] nodes;
        foreach(i; 0 .. n) nodes ~= new Node(i);
        foreach(__; 0 .. n - 1){
            int a = scan!int - 1, b = scan!int - 1;
            nodes[a].connectTo(nodes[b]);
        }
        foreach(ed; nodes[0].edgesIn) ed.calcIn;
        nodes[0].calc;
        foreach(ed; nodes[0].edgesOut) ed.calcOut;

        log("node values:", nodes.map!(nd => nd.value));
        //log("edge values:", edges.map!(ed => ed.node0.id.to!string ~ "->" ~ ed.node1.id.to!string ~ ":" ~ ed.value.to!string));

        long bestvalue = nodes[0].value;
        foreach(nd; nodes) bestvalue.lowerTo(nd.value);

        Node[] bestnodes;
        foreach(nd; nodes) if(nd.value == bestvalue) bestnodes ~= nd;

        if(bestnodes.length == 1){
            Edge ed = nodes[0].edgesIn[0];
            print(ed.node0.id + 1, ed.node1.id + 1);
            print(ed.node0.id + 1, ed.node1.id + 1);
        }
        else{
            Edge ed = bestnodes[0].edgesIn[0];
            if(ed.node0.id == bestnodes[1].id) ed = bestnodes[0].edgesIn[1];
            print(ed.node0.id + 1, bestnodes[0].id + 1);
            print(ed.node0.id + 1, bestnodes[1].id + 1);
        }

    }
}

// 双方向木DP

class Node{
    int id;
    long value;
    Edge[] edgesIn, edgesOut;
    this(int id){
        this.id = id;
    }
    void connectTo(Node nd){
        Edge edIn = new Edge(nd, this);
        Edge edOut = new Edge(this, nd);
        edIn.inv = edOut, edOut.inv = edIn;
        this.edgesIn ~= edIn, this.edgesOut ~= edOut;
        nd.edgesIn ~= edOut, nd.edgesOut ~= edIn;
    }
    void calc(){
        log("calc node", id);
        value = 0;
        long sum = 1;
        foreach(ed; edgesIn){
            sum += ed.value;
            value.raiseTo(ed.value);
        }
        foreach(ed; edgesOut){
            ed.value = sum - ed.inv.value;
        }
    }
}
class Edge{
    static int nextId = 0;
    int id;
    Node node0, node1;
    Edge inv;
    long value;
    this(Node node0, Node node1){
        this.id = nextId ++;
        this.node0 = node0;
        this.node1 = node1;
    }
    void calcIn(){
        log("calcin edge", id);
        foreach(ed; node0.edgesIn) if(ed.node0.id != this.node1.id){
            ed.calcIn;
        }
        calc;
    }
    void calcOut(){
        log("calcout edge", id);
        node1.calc;
        foreach(ed; node1.edgesOut) if(ed.node1.id != this.node0.id){
            ed.calcOut;
        }
    }
    void calc(){
        value = 1;
        foreach(ed; node0.edgesIn) if(ed.node0.id != this.node1.id){
            value += ed.value;
        }
    }

}

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 int[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto edges = new int[][](n);
		foreach (i; 0..n-1)
		{
			auto x = RD!int-1;
			auto y = RD!int-1;
			edges[x] ~= y;
			edges[y] ~= x;
		}

		auto cnt = new int[](n);
		int dfs(int pos, int last)
		{
			int m, tot = 1;
			foreach (v; edges[pos])
			{
				if (v == last) continue;

				auto r = dfs(v, pos);
				m.chmax(r);
				tot += r;
			}
			cnt[pos] = max(m, n-tot);
			return tot;
		}
		dfs(0, -1);

		auto index = cnt.MAKE_IDX;
		int i = cast(int)index[0];
		int j = cast(int)index[1];
		if (cnt[i] != cnt[j])
		{
			ans[ti] = [i, edges[i][0], i, edges[i][0]];
		}
		else
		{
			int dfs2(int pos, int last)
			{
				if (edges[pos].length == 1) return pos;

				foreach (v; edges[pos])
				{
					if (v == last) continue;
					return dfs2(v, pos);
				}
				return -1;
			}
			auto k = dfs2(j, i);
			ans[ti] = [k, edges[k][0], i, k];
		}
	}

	foreach (e; ans)
	{
		writeln(e[0]+1, " ", e[1]+1);
		writeln(e[2]+1, " ", e[3]+1);
	}
	stdout.flush;
	debug readln;
}

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

string FMT_F = "%.10f";

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

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

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

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(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 int[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto edges = new int[][](n);
		foreach (i; 0..n-1)
		{
			auto x = RD!int-1;
			auto y = RD!int-1;
			edges[x] ~= y;
			edges[y] ~= x;
		}

		auto cnt = new int[](n);
		int dfs(int pos, int last)
		{
			int m, tot = 1;
			foreach (v; edges[pos])
			{
				if (v == last) continue;

				auto r = dfs(v, pos);
				m.chmax(r);
				tot += m;
			}
			cnt[pos] = max(m, n-tot);
			return tot;
		}
		dfs(0, -1);

		auto index = cnt.MAKE_IDX;
		int i = cast(int)index[0];
		int j = cast(int)index[1];
		if (cnt[i] != cnt[j])
		{
			ans[ti] = [i, edges[i][0], i, edges[i][0]];
		}
		else
		{
			int dfs2(int pos, int last)
			{
				if (edges[pos].length == 1) return pos;

				foreach (v; edges[pos])
				{
					if (v == last) continue;
					return dfs2(v, pos);
				}
				return -1;
			}
			auto k = dfs2(j, i);
			ans[ti] = [k, edges[k][0], i, k];
		}
	}

	foreach (e; ans)
	{
		writeln(e[0]+1, " ", e[1]+1);
		writeln(e[2]+1, " ", e[3]+1);
	}
	stdout.flush;
	debug readln;
}


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

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		readln;
		auto s = readln.strip;
		auto t = readln.strip;
		while (!s.empty && !t.empty && s.front == t.front)
		{
			s.popFront ();
			t.popFront ();
		}
		while (!s.empty && !t.empty && s.back == t.back)
		{
			s.popBack ();
			t.popBack ();
		}
		writeln (((t == "" && s == "" ) || s == "*") ? "YES" : "NO");
	}
}

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.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto S = readln.chomp;
    auto T = readln.chomp;

    if (S.canFind('*')) {
        if (N > M + 1) {
            writeln("NO");
            return;
        }
        bool ok = true;
        for (int i = 0; S[i] != '*'; ++i) {
            if (S[i] != T[i]) {
                ok = false;
                break;
            }
        }
        for (int i = 0; S[N-i-1] != '*'; ++i) {
            if (S[N-i-1] != T[M-i-1]) {
                ok = false;
                break;
            }
        }
        writeln(ok ? "YES" : "NO");
    } else {
        writeln( S == T ? "YES" : "NO" );
    }

}

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

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

    auto s = readln.chomp;
    auto t = readln.chomp;

    if (!s.canFind('*')) {
        writeln(s == t ? "YES" : "NO");
        return;
    }

    if (n > m +1) {
        writeln("NO");
        return;
    }

    auto parts = findSplit(s, "*");

    debug { parts.writeln; t.writeln; }

    auto ok = t.startsWith(parts[0]) && t.endsWith(parts[2]);
    writeln(ok ? "YES" : "NO");
}

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

void main()
{
    readln;
    auto a = readln[0 .. $ - 1];
    auto b = readln[0 .. $ - 1];
    auto c = a.split('*');
    bool ok;
    if (c.length > 1) {
        ok = b.length >= a.length - 1
            && b[0 .. c[0].length] == c[0]
            && b[b.length - c[1].length .. $] == c[1];
    } else {
        ok = a == b;
    }
    if (ok)
        writeln("YES");
    else
        writeln("NO");
}

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.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();
      const M = readInt();
      const S = readToken();
      const T = readToken();

      bool ans;
      const pos = S.indexOf('*');
      if (pos == -1) {
        ans = (S == T);
      } else {
        ans = (N - 1 <= M && S[0 .. pos] == T[0 .. pos] && S[pos + 1 .. N] == T[M - (N - pos - 1) .. M]);
      }
      writeln(ans ? "YES" : "NO");
    }
  } catch (EOFException e) {
  }
}


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!string;
		ans[ti] = cast(int)n.length;
	}

	foreach (e; ans)
		writeln(e);
	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)
	{
		readln.strip.length.writeln;
	}
}


import std.stdio;
import std.math;
import std.algorithm;
import std.range;
import std.random;
import std.regex;
import std.string;
import std.numeric;
import std.functional;
import std.bigint;
import std.bitmanip;
import std.conv;
import std.container;
alias redBlackTree rbt;
alias RedBlackTree Rbt;
alias BigInt big;
//writeln readf readln string wstring dstring delegate function static
//double float real foreach immutable assert unittest continue break
//class enum remove insert length struct return
struct chis
{
	long val;
	int pos;
};
long[200000] a,ans;
void main()
{
	alias fun=binaryFun!("a.val<b.val ||(a.val==b.val && a.pos<b.pos)");

	uint n,k,x;
	readf(" %d %d %d\n",&n,&k,&x);
	//writeln(n,' ',k,' ',x);
	foreach(i;0..n-1)readf(" %d ",&a[i]);
	readf(" %d\n",&a[n-1]);
	uint p=0,o=0;
	ulong m=10000000000;
	foreach(i;0..n)
	{
		if(a[i]<0)o++;
		if(abs(a[i])<m)
		{
			m=abs(a[i]);
			p=i;
		}
	}
	//writeln(a[p]);
	if(o%2==0)
	{
		if(a[p]<0)
		{
			while(k>0 && a[p]<=0){a[p]+=x;k--;}
		}
		else
		{
			while(k>0 && a[p]>=0){a[p]-=x;k--;}
		}
	}
	//Rbt!(chis,"abs(a.val)<abs(b.val) ||(abs(a.val)==abs(b.val) && a.pos<b.pos)",false) q;
	auto q=rbt!("abs(a.val)<abs(b.val) ||(abs(a.val)==abs(b.val) && a.pos<b.pos)",chis)(chis(0,-1));
	foreach(i;0..n)
	{
		q.insert(chis(a[i],i));
	}
	q.removeKey(chis(0,-1));
	//foreach(h;q)writeln(h.val);
	while(k>0)
	{
		auto f=q.front;
		q.removeFront;
		if(f.val<0) f.val-=x;
		else f.val+=x;
		q.insert(f);
		k--;
	}
	foreach(h;q)ans[h.pos]=h.val;
	foreach(i;0..n)write(ans[i],' ');
}

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

__gshared:

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

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

int n, k, magic;
long[200_000] _a;
long[ ] a;

void main() {
    while (read(&n, &k, &magic)) {
        a = _a[0 .. n];
        bool neg = false;
        Array!int z;
        foreach (int i, ref x; a) {
            read(&x);
            if (!x)
                z ~= i;
            else if (x < 0)
                neg = !neg;
        }
        if (!z.empty) {
            if (k < z.length)
                goto end;
            k -= z.length;
            if (neg)
                foreach (i; z)
                    a[i] = magic;
            else {
                a[z[0]] = -magic;
                foreach (i; z[1 .. $])
                    a[i] = magic;
            }
        } else if (!neg) {
            auto r = a.minPos!`abs(a) < abs(b)`;
            assert(r[0]);
            if (r[0] > 0)
                while (r[0] >= 0 && k) {
                    r[0] -= magic;
                    k--;
                }
            else
                while (r[0] <= 0 && k) {
                    r[0] += magic;
                    k--;
                }
        }
        if (k) {
            Array!(Tuple!(long, int)) store;
            store.length = n;
            foreach (int i, x; a)
                store[i] = tuple(x, i);
            auto h = heapify!`abs(a[0]) > abs(b[0])`(store);
            do {
                long x;
                int pos;
                AliasSeq!(x, pos) = h.front;
                h.removeFront();
                if (x > 0)
                    x += magic;
                else
                    x -= magic;
                a[pos] = x;
                h.insert(tuple(x, pos));
            } while (--k);
        }
    end:
        foreach (x; a)
            write(x, ' ');
        writeln();
    }
}

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

__gshared:

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

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

enum N = 200_000;

int n, k, x;
long[N] _a;
long[ ] a;

void main() {
    while (read(&n, &k, &x)) {
        a = _a[0 .. n];
        bool neg = false;
        Array!int z;
        foreach (int i, ref e; a) {
            read(&e);
            if (!e)
                z.insertBack(i);
            else if (e < 0)
                neg = !neg;
        }
        if (!z.empty) {
            if (k < z.length) {
                foreach (x; a)
                    write(x, ' ');
                writeln();
                continue;
            }
            k -= z.length;
            if ((z.length & 0x1) != neg)
                foreach (i; z)
                    a[i] = -x;
            else {
                a[z[0]] = -x;
                foreach (i; z[1 .. $])
                    a[i] = x;
            }
        } else if (!neg) {
            auto r = a.minPos!`abs(a) < abs(b)`;
            assert(r[0]);
            if (r[0] > 0)
                while (r[0] >= 0 && k) {
                    r[0] -= x;
                    k--;
                }
            else
                while (r[0] <= 0 && k) {
                    r[0] += x;
                    k--;
                }
        }
        if (k) {
            auto r = a.minPos!`abs(a) < abs(b)`;
            assert(r[0]);
            if (r[0] > 0)
                r[0] += cast(long)x * k;
            else
                r[0] -= cast(long)x * k;
        }
        foreach (e; a)
            write(e, ' ');
        writeln();
    }
}

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

__gshared:

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

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

enum N = 200_000;

int n, k, x;
long[N] _a;
long[ ] a;

void main() {
    while (read(&n, &k, &x)) {
        a = _a[0 .. n];
        bool neg = false;
        Array!int z;
        foreach (int i, ref e; a) {
            read(&e);
            if (!e)
                z.insertBack(i);
            else if (e < 0)
                neg = !neg;
        }
        if (!z.empty) {
            if (k < z.length) {
                foreach (x; a)
                    write(x, ' ');
                writeln();
                continue;
            }
            k -= z.length;
            if ((z.length & 0x1) != neg)
                foreach (i; z)
                    a[i] = -x;
            else {
                a[z[0]] = -x;
                foreach (i; z[1 .. $])
                    a[i] = x;
            }
        } else if (!neg) {
            auto r = a.minPos!`abs(a) < abs(b)`;
            assert(r[0]);
            if (r[0] > 0)
                while (r[0] >= 0 && k) {
                    r[0] -= x;
                    k--;
                }
            else
                while (r[0] <= 0 && k) {
                    r[0] += x;
                    k--;
                }
        }
        if (k) {
            Array!(Tuple!(long, int)) store;
            store.length = n;
            foreach (int i, e; a)
                store[i] = tuple(e, i);
            auto h = heapify!`abs(a[0]) > abs(b[0])`(store);
            do {
                long e;
                int pos;
                AliasSeq!(e, pos) = h.front;
                h.removeFront();
                if (e > 0)
                    e += x;
                else
                    e -= x;
                a[pos] = e;
                h.insert(tuple(e, pos));
            } while (--k);
        }
        foreach (e; a)
            write(e, ' ');
        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 H = readInt();
      auto A = new int[H + 1];
      foreach (d; 0 .. H + 1) {
        A[d] = readInt();
      }

      bool amb;
      foreach (d; 0 .. H) {
        amb = amb || (A[d] >= 2 && A[d + 1] >= 2);
      }
      if (!amb) {
        writeln("perfect");
      } else {
        auto ASum = new int[H + 2];
        foreach (d; 0 .. H + 1) {
          ASum[d + 1] = ASum[d] + A[d];
        }
        auto ans = new int[][2];
        ans[0] ~= -1;
        ans[1] ~= -1;
        foreach (d; 1 .. H + 1) {
          foreach (j; 0 .. A[d]) {
            ans[0] ~= ASum[d - 1];
            ans[1] ~= ASum[d - 1] + j % A[d - 1];
          }
        }
        writeln("ambiguous");
        foreach (s; 0 .. 2) {
          foreach (u; 0 .. ASum[H + 1]) {
            if (u > 0) write(" ");
            write(ans[s][u] + 1);
          }
          writeln();
        }
      }
    }
  } catch (EOFException e) {
  }
}

/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.9.0"
+/

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

import std.typecons;

int main() {
    Scanner sc = new Scanner(stdin);

    int h; int[] a;
    sc.read(h, a); h++;
    int[] as = new int[h+1];
    foreach (i; 0..h) {
        as[i+1] = as[i] + a[i];
    }
    int n = as.back;
    int[] ap = new int[n], bp = new int[n];
    ap[0] = -1; bp[0] = -1;
    foreach (i; 1..h) {
        foreach (j; as[i]..as[i+1]) {
            ap[j] = bp[j] = as[i-1];
        }
    }
    foreach (i; 0..h-1) {
        if (a[i] > 1 && a[i+1] > 1) {
            bp[as[i+1]+1]++;

            writeln("ambiguous");
            writeln(ap.map!"a+1".map!(to!string).join(" "));
            writeln(bp.map!"a+1".map!(to!string).join(" "));
            return 0;
        }
    }
    writeln("perfect");
    return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */

// module dcomp.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/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

// import dcomp.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 read(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);
        }
    }
}

/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/container/stackpayload.d */
// module dcomp.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--;
    }
}

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

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 H = readInt();
      auto A = new int[H + 1];
      foreach (d; 0 .. H + 1) {
        A[d] = readInt();
      }

      bool perfect = true;
      foreach (d; 0 .. H) {
        perfect = perfect && (A[d] == 1);
      }
      if (perfect) {
        writeln("perfect");
      } else {
        auto ASum = new int[H + 2];
        foreach (d; 0 .. H + 1) {
          ASum[d + 1] = ASum[d] + A[d];
        }
        auto ans = new int[][2];
        ans[0] ~= -1;
        ans[1] ~= -1;
        foreach (d; 1 .. H + 1) {
          foreach (_; 0 .. A[d]) {
            ans[0] ~= ASum[d - 1];
            ans[1] ~= ASum[d - 1] + A[d - 1] - 1;
          }
        }
        writeln("ambiguous");
        foreach (s; 0 .. 2) {
          foreach (u; 0 .. ASum[H + 1]) {
            if (u > 0) write(" ");
            write(ans[s][u] + 1);
          }
          writeln();
        }
      }
    }
  } catch (EOFException e) {
  }
}


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

struct Point
{
	int x;
	int y;

	Point opBinary (string op) (const auto ref Point that)
	    if (op == "+" || op == "-")
	{
		Point res = void;
		res.x = mixin (q{this.x } ~ op ~ q{ that.x});
		res.y = mixin (q{this.y } ~ op ~ q{ that.y});
		return res;
	}

	int opCmp () (const auto ref Point that)
	{
		auto thisUp = this.y > 0 || this.y == 0 && this.x > 0;
		auto thatUp = that.y > 0 || that.y == 0 && that.x > 0;
		if (thisUp != thatUp)
		{
			return thisUp - thatUp;
		}
		auto cur = vp (this, that);
		return (cur > 0) - (cur < 0);
	}
}

long vp () (const auto ref Point a, const auto ref Point b)
{
	return a.x * 1L * b.y - a.y * 1L * b.x;
}

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		auto p = new Point [n];
		foreach (ref c; p)
		{
			readf !(" %s %s") (c.x, c.y);
		}

		long res = n * (n - 1L) * (n - 2L) * (n - 3L) * (n - 4L) / 24;
		debug {writeln (res);}
		foreach (i; 0..n)
		{
			Point [] q;
			q.reserve (n - 1);
			foreach (j; 0..n)
			{
				if (j != i)
				{
					q ~= p[j] - p[i];
				}
			}
			sort (q);
			debug {writeln (q);}
			q ~= q;
			int v = 0;
			foreach (u; 0..n - 1)
			{
				v = max (v, u + 1);
				while (v - u < n - 1 && vp (q[v], q[u]) > 0)
				{
					v += 1;
				}
				debug {writeln (u, " ", v);}
				int w = v - u - 1;
				res -= w * (w - 1L) * (w - 2L) / 6;
			}
		}
		writeln (res);
	}
}

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

alias Pt = Tuple!(long, "x", long, "y");

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

      long ans;
      foreach (i; 0 .. N) {
        Pt[] ps;
        foreach (j; 0 .. N) {
          if (j != i) {
            ps ~= Pt(P[j].x - P[i].x, P[j].y - P[i].y);
          }
        }
        ps.sort!((ref Pt a, ref Pt b) {
          const sa = (a.y > 0) ? 1 : (a.y < 0) ? 3 : (a.x > 0) ? 0 : 2;
          const sb = (b.y > 0) ? 1 : (b.y < 0) ? 3 : (b.x > 0) ? 0 : 2;
          if (sa != sb) return (sa < sb);
          return (a.x * b.y > a.y * b.x);
        });
        int r;
        foreach (l; 0 .. N - 1) {
          for (chmax(r, l + 1); r < l + (N - 1) && ps[l].x * ps[r % (N - 1)].y > ps[l].y * ps[r % (N - 1)].x; ++r) {}
          const long m = r - l - 1;
          ans += m * (m - 1) * (m - 2) / 6;
        }
      }

      const long n = N;
      ans = n * (n - 1) * (n - 2) * (n - 3) * (n - 4) / 120 * 5 - ans;
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


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

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

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

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

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

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

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

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

void main()
{
    int T; get(T);
    while (T--) {
        int N; get(N);
        int[] aa; get(aa);
        int min_a = int.max, c;
        foreach (a; aa) {
            if (min_a > a) {
                min_a = a;
                c = 1;
            } else if (a == min_a) {
                ++c;
            }
        }
        writeln(N - c);
    }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		writeln (n - a.count (a.minElement));
	}
}

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;

		foreach (i; 0..n)
		{
			if (a[i] != a[0])
			{
				ans[ti] = n - i;
				break;
			}
		}
	}

	foreach (e; ans)
		writeln(e);
	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 N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    int ans = 0;

    foreach (i; 0..N) {
        foreach (j; i+1..N) {
            if (A[i] > A[j]) {
                ans ^= 1;
            }
        }
    }

    auto Q = readln.chomp.to!int;
    while (Q--) {
        auto lr = readln.split.map!(to!int);
        auto d = lr[1] - lr[0] + 1;
        ans ^= (d * (d - 1) / 2) % 2;
        writeln(ans%2 ? "odd" : "even");
    }

}

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

alias Pair = Tuple!(dchar, "col", int, "len");

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

    int inv;
    foreach (i ; 0 .. n) {
        foreach (j ; i + 1 .. n) {
            if (a[i] > a[j]) inv++;
        }
    }

    inv &= 1;

    foreach (i ; 0 .. m) {
        int l, r;
        scan(l, r);
        inv ^= ((r - l + 1) * (r - l) / 2) & 1;
        writeln(inv ? "odd" : "even");
    }
}

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;

int main()
{
	int a=0;
	int b=0;
	readf(" %d", &a);
	readf(" %d", &b);
	int count=0;
	for (int i=0; i<a; i++)
	{
		int c=0;
		readf(" %d", &c);
		if (c>b)
		{
			count=count+1;
		}
	}
	writeln(a+count);
	return 0;
}

import std.stdio;

void main()
{
	int n, h, x;
	int result = 0;

	scanf("%d%d", &n, &h);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		result += (x > h) ? 2 : 1;
	}
	printf("%d\n", result);
}

import std.stdio: writeln, stdin;
import std.string: strip,tr;
import std.algorithm.iteration: uniq, map, sum;
import std.algorithm.mutation: copy;
import std.algorithm.sorting: sort;
import std.regex;
import std.conv;
import std.array;

void main()
{
  auto nh = stdin.readln.strip.split(regex(` +`)).map!(to!int).array;
  auto as = stdin.readln.strip.split(regex(` +`)).map!(to!int);
  auto h = nh[1];
  writeln (as.map!(a=>a<=h?1:2).sum);
}

import std.stdio;
import core.stdc.stdio;
import std.algorithm;
import std.math;
import std.array;

int main(string[] argv)
{
	int n, h;
	scanf("%d %d", &n, &h);
	int width = 0;
	foreach (int i; 0..n)
	{
		int fh;
		scanf("%d", &fh);
		width += (fh > h ? 2 : 1);
	}
	printf("%d", width);
	return 0;
}

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

void main(){

	int n, h, x;
	int result = 0;

	scanf("%d%d", &n, &h);
	for (int i = 0; i < n; i++){
		scanf("%d", &x);
		result += (x > h) ? 2 : 1;
	}

	printf("%d\n", result);
}

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

void main() {
  int n, h;
  readf!" %s %s "(n, h);
  auto ans = readln.splitter
    .map!(to!int)
    .map!(x => x > h ? 2 : 1)
    .sum;
  writeln(ans);
}

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

void main() {
  int n, h;
  readf!" %s %s "(n, h);
  // auto ans = readln.splitter
  //   .map!(to!int)
  //   .map!(x => x > h ? 2 : 1)
  //   .sum;
  // writeln(ans);
  int ans = 0;
  foreach (i; 0 .. n) {
    int x;
    readf!" %s"(x);
    ans += 1;
    if (x > h) {
      ans += 1;
    }
  }
  writeln(ans);
}


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

int solve(long[] a, long h, long[] mulorder)
{
  int i = 0;
  while (i < a.length) {
    if (a[i] < h) {
      h += a[i] / 2;
      i++;
      continue;
    }
    if (mulorder.length > 0) {
      h *= mulorder.front;
      mulorder = mulorder[1 .. $];
      continue;
    }
    break;
  }
  return i;
}

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    long n, h;
    readf!" %d %d "(n, h);
    auto a = readln.splitter.map!(to!long).array.sort.array;
    int best = -1;
    foreach (p ; [2L, 2L, 3L].permutations) {
      best = max(best, solve(a, h, p.array));
    }
    writeln(best);
  }
}

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

int solve (int n, long h, int [] a, int [] p)
{
	foreach (int k, ref c; a)
	{
		while (h <= c && !p.empty)
		{
			h *= p.front;
			p.popFront ();
		}
		if (h <= c)
		{
			return k;
		}
		h += c / 2;
	}
	return n;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, h;
		readf !(" %s %s") (n, h);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		sort (a);

		auto p = [2, 2, 3];
		int res = 0;
		do
		{
			res = max (res, solve (n, h, a, p));
		}
		while (nextPermutation (p));
		writeln (res);
	}
}

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

int solve1(long[] a, long h)
{
    int mul2cnt = 2;
    int mul3cnt = 1;
    int i = 0;
    while (i < a.length) {
      if (a[i] < h) {
        h += a[i] / 2;
      } else if (a[i] < h * 2 && mul2cnt > 0) {
        h *= 2;
        h += a[i] / 2;
        mul2cnt--;
      } else if (a[i] < h * 3 && mul3cnt > 0) {
        h *= 3;
        h += a[i] / 2;
        mul3cnt--;
      } else {
        if (mul2cnt > 0) {
          h *= 2;
          mul2cnt--;
          continue;
        }
        if (mul3cnt > 0) {
          h *= 3;
          mul3cnt--;
          continue;
        }
        break;
      }
      i++;
    }
    return i;
}

int solve2(long[] a, long h)
{
    int mul2cnt = 2;
    int mul3cnt = 1;
    int i = 0;
    while (i < a.length) {
      if (a[i] < h) {
        h += a[i] / 2;
      } else if (a[i] < h * 3 && mul3cnt > 0) {
        h *= 3;
        h += a[i] / 2;
        mul3cnt--;
      } else if (a[i] < h * 2 && mul2cnt > 0) {
        h *= 2;
        h += a[i] / 2;
        mul2cnt--;
      } else {
        if (mul3cnt > 0) {
          h *= 3;
          mul3cnt--;
          continue;
        }
        if (mul2cnt > 0) {
          h *= 2;
          mul2cnt--;
          continue;
        }
        break;
      }
      i++;
    }
    return i;
}

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    long n, h;
    readf!" %d %d "(n, h);
    auto a = readln.splitter.map!(to!long).array.sort.array;
    writeln(max(solve1(a, h), solve2(a, h)));
  }
}

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

int solve1(long[] a, long h)
{
    int mul2cnt = 2;
    int mul3cnt = 1;
    int i = 0;
    while (i < a.length) {
      if (a[i] < h) {
        h += a[i] / 2;
      } else if (a[i] < h * 2 && mul2cnt > 0) {
        h *= 2;
        h += a[i] / 2;
        mul2cnt--;
      } else if (a[i] < h * 3 && mul3cnt > 0) {
        h *= 3;
        h += a[i] / 2;
        mul3cnt--;
      } else {
        break;
      }
      i++;
    }
    return i;
}

int solve2(long[] a, long h)
{
    int mul2cnt = 2;
    int mul3cnt = 1;
    int i = 0;
    while (i < a.length) {
      if (a[i] < h) {
        h += a[i] / 2;
      } else if (a[i] < h * 3 && mul3cnt > 0) {
        h *= 3;
        h += a[i] / 2;
        mul3cnt--;
      } else if (a[i] < h * 2 && mul2cnt > 0) {
        h *= 2;
        h += a[i] / 2;
        mul2cnt--;
      } else {
        break;
      }
      i++;
    }
    return i;
}

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    long n, h;
    readf!" %d %d "(n, h);
    auto a = readln.splitter.map!(to!long).array.sort.array;
    writeln(max(solve1(a, h), solve2(a, h)));
  }
}


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

void main() {
	int tt = readln().chomp.to!int;
	foreach (t; 0 .. tt) {
		readln();
		int[] a = readln().chomp.split(" ").map!(to!int).array;
		int[] b = readln().chomp.split(" ").map!(to!int).array;
		bool[int] aSet;
		foreach (i; a) {
			aSet[i] = true;
		}
		Nullable!int ans;
		foreach (i; b) {
			if (i in aSet) {
				ans = Nullable!int(i);
			}
		}
		if (ans.isNull) {
			writeln("NO");
		}
		else {
			writeln("YES");
			writeln("1 ", ans.get);
		}
	}
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
multitest_loop:
	foreach (test; 0..tests)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto b = readln.splitter.map !(to !(int)).array;
		foreach (x; a)
		{
			foreach (y; b)
			{
				if (x == y)
				{
					writeln ("YES");
					writeln (1, " ", x);
					continue multitest_loop;
				}
			}
		}
		writeln ("NO");
	}
}


import std.container;
import std.stdio;
import std.typecons;

immutable int infinity = int.max / 4;

void main ()
{
	int n, m;
	while (readf !(" %s %s") (n, m) > 0)
	{
		auto adj = new int [] [n];
		auto adjR = new int [] [n];
		auto deg = new int [n];
		foreach (j; 0..m)
		{
			int u, v;
			readf !(" %s %s") (u, v);
			u -= 1;
			v -= 1;
			adj[u] ~= v;
			adjR[v] ~= u;
			deg[u] += 1;
		}

		auto d = new int [n];
		d[] = infinity;
		d[n - 1] = 0;
		auto used = new bool [n];
		alias Record = Tuple !(int, q{dist}, int, q{v});
		auto t = redBlackTree !(Record) ();
		foreach (i; 0..n)
		{
			t.insert (Record (d[i], i));
		}
		while (!t.empty)
		{
			auto cur = t.front;
			t.removeFront ();
			used[cur.v] = true;
			foreach (u; adjR[cur.v])
			{
				deg[u] -= 1;
				if (!used[u] && d[u] > deg[u] + d[cur.v] + 1)
				{
					t.removeKey (Record (d[u], u));
					d[u] = deg[u] + d[cur.v] + 1;
					t.insert (Record (d[u], u));
				}
			}
		}

		writeln (d[0]);
	}
}

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 INF = 10^^9;

void main() {
  try {
    for (; ; ) {
      const N = readInt;
      const M = readInt;
      auto A = new int[M];
      auto B = new int[M];
      foreach (i; 0 .. M) {
        A[i] = readInt - 1;
        B[i] = readInt - 1;
      }

      auto ds = new int[N];
      auto G = new int[][N];
      foreach (i; 0 .. M) {
        ++ds[A[i]];
        G[B[i]] ~= i;
      }

      alias Entry = Tuple!(int, "c", int, "u");
      BinaryHeap!(Array!Entry, "a.c > b.c") que;
      auto vis = new bool[N];
      auto dist = new int[N];
      dist[] = INF;
      dist[N - 1] = 0;
      que.insert(Entry(0, N - 1));
      for (; !que.empty; ) {
        const c = que.front.c;
        const u = que.front.u;
        que.removeFront;
        if (!vis[u]) {
          vis[u] = true;
          foreach (i; G[u]) {
            const v = A[i];
            const cc = c + 1 + (--ds[v]);
            debug {
              writefln("%s <- %s: %s", u, v, cc);
            }
            if (chmin(dist[v], cc)) {
              que.insert(Entry(cc, v));
            }
          }
        }
      }
      debug {
        writeln("dist = ", dist);
      }
      writeln(dist[0]);
    }
  } catch (EOFException e) {
  }
}


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 int[](t);
	foreach (ti; 0..t)
	{
		auto xyz1 = RDA;
		auto xyz2 = RDA;

		auto x = min(xyz1[2], xyz2[1]);
		ans[ti] += x * 2;
		xyz1[0] -= x;
		xyz2[1] -= x;
		auto y = xyz2[2] - (xyz1[0]+xyz1[2]);
		if (y > 0)
			ans[ti] -= y * 2;
	}

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

// Ported to D by unihernandez22
// Solution by Vicfred
// https://codeforces.com/contest/1401/problem/B

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

void main() {
  int t = readln.chomp.to!int;
  foreach (_; 0 .. t) {
    int[] a = readln.split.map!(to!int).array,
      b = readln.split.map!(to!int).array;
    int ans = 0;

    if (a[2] > 0) {
      int taken = min(b[1], a[2]);
      a[2] -= taken;
      b[1] -= taken;

      ans += taken*2;
    }

    if (a[2] > 0) {
      int taken = min(b[2],a[2]);
      a[2] -= taken;
      b[2] -= taken;
    }

    if (a[2] > 0) {
      int taken = min(b[0],a[2]);
      a[2] -= taken;
      b[0] -= taken;
    }

    if (a[1] > 0) {
      int taken = min(b[1],a[1]);
      a[1] -= taken;
      b[1] -= taken;
    }

    if (a[1] > 0) {
      int taken = min(b[0],a[1]);
      a[1] -= taken;
      b[0] -= taken;
    }

    if (a[1] > 0) {
      int taken = min(b[2],a[1]);
      a[1] -= taken;
      b[2] -= taken;
      ans += taken*(-2);
    }

    writeln(ans);
  }
}

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 a = readln.splitter.map !(to !(int)).array;
		auto b = readln.splitter.map !(to !(int)).array;

		auto num (int i, int j)
		{
			int res = min (a[i], b[j]);
			a[i] -= res;
			b[j] -= res;
			return res;
		}

		int res = num (2, 1) * 2;
		num (1, 1);
		num (1, 0);
		res -= num (1, 2) * 2;
		writeln (res);
	}
}


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

int saiki(int i, int j, int k, string a, string b, string v, int[][][] dp, Tuple!(int, int, int)[][][] result, int[][] jump)
{
    auto la = cast(int)a.length;
    auto lb = cast(int)b.length;
    auto lv = cast(int)v.length;
    if (dp[i][j][k] != -1)
    {
        return dp[i][j][k];
    }
    if (k == lv)
    {
        dp[i][j][k] = int.max;
        return int.max;
    }
    if (i == la || j == lb)
    {
        dp[i][j][k] = 0;
        return 0;
    }
    auto res = 0;
    if (a[i] == b[j])
    {
        auto ret = saiki(i + 1, j + 1, jump[k][a[i] - 'A'], a, b, v, dp, result, jump);
        if (ret + 1 > res)
        {
            result[i][j][k] = Tuple!(int, int, int)(i + 1, j + 1, jump[k][a[i] - 'A']);
            res = ret + 1;
        }
    }
    auto ret = saiki(i + 1, j, k, a, b, v, dp, result, jump);
    if (ret > res)
    {
        res = ret;
        result[i][j][k] = Tuple!(int, int, int)(i + 1, j, k);
    }
    ret = saiki(i, j + 1, k, a, b, v, dp, result, jump);
    if (ret > res)
    {
        res = ret;
        result[i][j][k] = Tuple!(int, int, int)(i, j + 1, k);
    }
    dp[i][j][k] = res;
    return res;
}

int[][] getJump(string s)
{
    auto n = cast(int)s.length;
    auto jump = new int[][](n + 1, 26);
    foreach (i; 0 .. n)
    {
        foreach (j; 0 .. 26)
        {
            if (s[i] == 'A' + j)
            {
                jump[i][j] = i + 1;
            }
            else
            {
                jump[i][j] = 0;
                for (int k = i - 1; k >= 0; -- k)
                {
                    if (s[k] == 'A' + j)
                    {
                        auto x = k - 1, y = i - 1;
                        while (x >= 0 && y >= 0)
                        {
                            if (s[x] != s[y])
                            {
                                break;
                            }
                            -- x;
                            -- y;
                        }
                        if (x < 0)
                        {
                            jump[i][j] = k + 1;
                            break;
                        }
                    }
                }
            }
        }
    }
    return jump;
}

string construct(string a, string b, string v, Tuple!(int, int, int)[][][] result, int[][] jump)
{
    auto la = cast(int)a.length;
    auto lb = cast(int)b.length;
    auto lv = cast(int)v.length;
    auto i = 0, j = 0, k = 0;
    string res;
    while (i < la && j < lb)
    {
        if (result[i][j][k] == tuple(-1, -1, -1))
        {
            break;
        }
        auto ni = result[i][j][k][0];
        auto nj = result[i][j][k][1];
        auto nk = result[i][j][k][2];
        if (ni == i + 1 && nj == j + 1)
        {
            auto c = a[i];
            res ~= c;
        }
        i = ni;
        j = nj;
        k = nk;
    }
    return res;
}

void solve(string a, string b, string v)
{
    auto la = cast(int)a.length;
    auto lb = cast(int)b.length;
    auto lv = cast(int)v.length;
    auto jump = getJump(v);
    auto dp = new int[][][](la + 1, lb + 1, lv + 1);
    auto result = new Tuple!(int, int, int)[][][](la + 1, lb + 1, lv + 1);
    foreach (i; 0 .. la + 1)
    {
        foreach (j; 0 .. lb + 1)
        {
            fill(dp[i][j], -1);
            fill(result[i][j], tuple(-1, -1, -1));
        }
    }
    auto ans = saiki(0, 0, 0, a, b, v, dp, result, jump);
    if (ans == 0)
    {
        writeln(0);
    }
    else
    {
        auto res = construct(a, b, v, result, jump);
        writeln(res);
    }
}

int main(string[] args)
{
    string s0, s1, virus;
    s0 = readln().strip();
    s1 = readln().strip();
    virus = readln().strip();
    solve(s0, s1, virus);
    return 0;
}

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

int saiki(int i, int j, int k, int la, int lb, int lv, int[][][] dp, Tuple!(int, int, int)[][][] result, int[][] nexta, int[][] nextb, int[][] jump)
{
    if (dp[i][j][k] != -1)
    {
        return dp[i][j][k];
    }
    if (k == lv)
    {
        dp[i][j][k] = int.max;
        return int.max;
    }
    if (i == la || j == lb)
    {
        dp[i][j][k] = 0;
        return 0;
    }
    auto res = 0;
    foreach (idx; 0 .. 26)
    {
        if (nexta[i][idx] != -1 && nextb[j][idx] != -1)
        {
            auto ret = saiki(nexta[i][idx] + 1, nextb[j][idx] + 1, jump[k][idx], la, lb, lv, dp, result, nexta, nextb, jump);
            if (ret != int.max)
            {
                if (ret + 1 > res)
                {
                    result[i][j][k] = Tuple!(int, int, int)(nexta[i][idx], nextb[j][idx], jump[k][idx]);
                    res = ret + 1;
                }
            }
        }
    }
    dp[i][j][k] = res;
    return res;
}

int[][] getNext(string s)
{
    auto n = cast(int)s.length;
    auto next = new int[][](n + 1, 26);
    foreach (i; 0 .. n)
    {
        foreach (j; 0 .. 26)
        {
            next[i][j] = -1;
            foreach (k; i .. n)
            {
                if (s[k] == 'A' + j)
                {
                    next[i][j] = k;
                    break;
                }
            }
        }
    }
    return next;
}

int[][] getJump(string s)
{
    auto n = cast(int)s.length;
    auto jump = new int[][](n + 1, 26);
    foreach (i; 0 .. n)
    {
        foreach (j; 0 .. 26)
        {
            if (s[i] == 'A' + j)
            {
                jump[i][j] = i + 1;
            }
            else
            {
                jump[i][j] = 0;
                for (int k = i - 1; k >= 0; -- k)
                {
                    if (s[k] == 'A' + j)
                    {
                        auto x = k - 1, y = i - 1;
                        while (x >= 0 && y >= 0)
                        {
                            if (s[x] != s[y])
                            {
                                break;
                            }
                            -- x;
                            -- y;
                        }
                        if (x < 0)
                        {
                            jump[i][j] = k + 1;
                            break;
                        }
                    }
                }
            }
        }
    }
    return jump;
}

string configure(string a, string b, string v, Tuple!(int, int, int)[][][] result, int[][] jump)
{
    auto la = cast(int)a.length;
    auto lb = cast(int)b.length;
    auto lv = cast(int)v.length;
    auto i = 0, j = 0, k = 0;
    string res;
    while (i < la && j < lb)
    {
        if (result[i][j][k] == tuple(-1, -1, -1))
        {
            break;
        }
        auto c = a[result[i][j][k][0]];
        res ~= c;
        auto ni = result[i][j][k][0] + 1;
        auto nj = result[i][j][k][1] + 1;
        auto nk = jump[k][c - 'A'];
        i = ni;
        j = nj;
        k = nk;
    }
    return res;
}

void solve(string a, string b, string v)
{
    auto la = cast(int)a.length;
    auto lb = cast(int)b.length;
    auto lv = cast(int)v.length;
    auto nexta = getNext(a);
    auto nextb = getNext(b);
    auto jump = getJump(v);
    auto dp = new int[][][](la + 1, lb + 1, lv + 1);
    auto result = new Tuple!(int, int, int)[][][](la + 1, lb + 1, lv + 1);
    foreach (i; 0 .. la + 1)
    {
        foreach (j; 0 .. lb + 1)
        {
            fill(dp[i][j], -1);
            fill(result[i][j], tuple(-1, -1, -1));
        }
    }
    auto ans = saiki(0, 0, 0, la, lb, lv, dp, result, nexta, nextb, jump);
    if (ans == 0)
    {
        writeln(0);
    }
    else
    {
        auto res = configure(a, b, v, result, jump);
        writeln(res);
    }
}

int main(string[] args)
{
    string s0, s1, virus;
    s0 = readln().strip();
    s1 = readln().strip();
    virus = readln().strip();
    solve(s0, s1, virus);
    return 0;
}

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;

void main ()
{
	string r;
	while ((r = readln ().strip ()) != "")
	{
		string s = readln ().strip ();
		string t = readln ().strip ();
		int u = r.length;
		int v = s.length;
		int w = t.length;
		auto p = new int [w + 1];
		p[] = 0;
		foreach (i; 1..w + 1)
		{
			foreach (j; 1..i)
			{
				if (t[0..j] == t[i - j..i])
				{
					p[i] = max (p[i], j);
				}
			}
		}
		auto f = new int [] [] [] (u + 1, v + 1, w + 1);
		alias Tuple !(int, int, int) prev;
		auto q = new prev [] [] [] (u + 1, v + 1, w + 1);
		foreach (i; 0..u + 1)
		{
			foreach (j; 0..v + 1)
			{
				foreach (k; 0..w + 1)
				{
					f[i][j][k] = -3;
					q[i][j][k] = prev (-3, -3, -3);
				}
			}
		}
		f[0][0][0] = 0;
		foreach (int i; 0..u + 1)
		{
			foreach (int j; 0..v + 1)
			{
				foreach (int k; 0..w)
				{
					auto cur = f[i][j][k];
					if (cur == -3)
					{
						continue;
					}

					void move (int x, int y, int z)
					{
						if (f[x][y][z] < cur)
						{
							f[x][y][z] = cur;
							q[x][y][z] =
								prev (i, j, k);
						}
					}

					if (i < u)
					{
						move (i + 1, j, k);
					}
					if (j < v)
					{
						move (i, j + 1, k);
					}
					if (i < u && j < v && r[i] == s[j])
					{
						auto z = k;
						while (z > 0 && r[i] != t[z])
						{
							z = p[z];
						}
						if (r[i] == t[z])
						{
							z++;
						}
						cur++;
						move (i + 1, j + 1, z);
					}
				}
			}
		}
		int pi = u, pj = v, pk = -3;
		int res = -3;
		foreach (k; 0..w)
		{
			if (res < f[pi][pj][k])
			{
				res = f[pi][pj][k];
				pk = k;
			}
		}
		if (res <= 0)
		{
			writeln (0);
		}
		else
		{
			char [] ans;
			while (pk != -3)
			{
				int qi, qj, qk;
				qi = q[pi][pj][pk][0];
				qj = q[pi][pj][pk][1];
				qk = q[pi][pj][pk][2];
				if (qi == pi - 1 && qj == pj - 1)
				{
					ans ~= r[qi];
				}
				pi = qi;
				pj = qj;
				pk = qk;
			}
			ans.reverse ();
			writeln (ans);
		}
	}
}