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

//	Input
string[] tokens;
int tokenId = 0;
string readToken() { for (; tokenId == tokens.length; ) tokens = readln.split, tokenId = 0; return tokens[tokenId++]; }

int readInt() { return to!int(readToken); }
long readLong() { return to!long(readToken); }
real readReal() { return to!real(readToken); }

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

void main () {
    int N; N = readInt();
    int M; M = readInt();

    int[110] valid;
    int[110] invalid;

    int best = 0;

    foreach (i; 0 .. N) {
        valid[i] = readInt();
        chmax(best, valid[i]);
    }

    foreach (i; 0 .. M) {
        invalid[i] = readInt();
        chmax(best, invalid[i]);
    }

    bool ok = false;

    foreach (i; 1 .. best + 1) {
        bool les = true;
        bool exe = false;
        bool big = true;

        foreach (j; 0 .. N) {
            if (valid[j] > i) {
                les = false;
            }
            if (valid[j] * 2 <= i) {
                exe = true;
            }
        }

        foreach (j; 0 .. M) {
            if (invalid[j] <= i) {
                big = false;
            }
        }

        if (exe && les && big) {
            ok = true;
            writeln("", i);
            break;
        }
    }

    if (!ok) {
        writeln("-1");
    }
}

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

void main() {
    int n, m; readf("%d %d\n", &n, &m);
    auto cs = stdin.readln.split.map!(to!int);
    auto ws = stdin.readln.split.map!(to!int);
    auto cmin = cs.reduce!min;
    auto cmax = cs.reduce!max;
    auto wmin = ws.reduce!min;
    int v = max(cmin * 2, cmax);
    if (v >= wmin) {
        writeln(-1);
    } else {
        writeln(v);
    }
}

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

//  Input
string[] tokens;
int tokenId = 0;
string readToken() { for (; tokenId == tokens.length; ) tokens = readln.split, tokenId = 0; return tokens[tokenId++]; }

int readInt() { return to!int(readToken); }
long readLong() { return to!long(readToken); }
real readReal() { return to!real(readToken); }

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

void main () {
    int N; N = readInt();
    int M; M = readInt();

    int[110] valid;
    int[110] invalid;

    int best = 0;

    foreach (i; 0 .. N) {
        valid[i] = readInt();
        chmax(best, valid[i]);
    }

    foreach (i; 0 .. M) {
        invalid[i] = readInt();
        chmax(best, valid[i]);
    }

    bool ok = false;

    foreach (i; 1 .. best + 1) {
        bool les = true;
        bool exe = false;
        bool big = true;

        foreach (j; 0 .. N) {
            if (valid[j] > i) {
                les = false;
            }
            if (valid[j] * 2 < i) {
                exe = true;
            }
        }

        foreach (j; 0 .. M) {
            if (invalid[j] < i) {
                big = false;
            }
        }

        if (exe && les && big) {
            ok = true;
            writeln("", i);
            break;
        }
    }

    if (!ok) {
        writeln("-1");
    }

}


import std.stdio, std.random;

alias V = long;
alias P = int;

class Node
{
    V value;
    V valueSum;
    V valuePendingAdd;
    Node left;
    Node right;
    int size;

    this(V value, Node left = null, Node right = null)
    {
        this.value = value;
        this.left = left;
        this.right = right;
        update();
    }

    void update()
    {
        size = getSize(left) + getSize(right) + 1;
        valueSum = getValueSum(left) + getValueSum(right) + value;
    }
}

int getSize(Node node)
{
    return node is null ? 0 : node.size;
}

V getValueSum(Node node)
{
    return node is null ? 0 : node.valueSum;
}

void pushPending(Node node)
{
    if (node !is null && node.valuePendingAdd != 0)
    {
        if (node.left !is null) node.left.valuePendingAdd += node.valuePendingAdd;
        if (node.right !is null) node.right.valuePendingAdd += node.valuePendingAdd;

        node.value += node.valuePendingAdd;
        node.valuePendingAdd = 0;
    }
}

Node merge(Node l, Node r)
{
    if (l is null) return r;
    if (r is null) return l;

    l.pushPending();
    r.pushPending();

    if (uniform(-l.size, r.size) < 0)
    {
        l.right = merge(l.right, r);
        l.update();
        return l;
    }
    else
    {
        r.left = merge(l, r.left);
        r.update();
        return r;
    }
}

void split(Node node, int splitIndex, out Node outL, out Node outR)
{
    if (node is null)
    {
        outL = null;
        outR = null;
        return;
    }

    node.pushPending();

    int leftSize = getSize(node.left);
    Node newNode = null;

    if (leftSize < splitIndex)
    {
        if (node.right is null) outR = null;
        else split(node.right, splitIndex - leftSize - 1, newNode, outR);

        node.right = newNode;
        node.update();
        outL = node;
    }
    else
    {
        if (node.left is null) outL = null;
        else split(node.left, splitIndex, outL, newNode);

        node.left = newNode;
        node.update();
        outR = node;
    }
}

void main()
{
    int n, k, q;
    readf("%d %d %d", &n, &k, &q);

    Node root = null;

    for (int i = 0; i < 200010; i++)
    {
        root = merge(root, new Node(0));
    }

    for (int i = 0; i < n; i++)
    {
        int l, r;
        readf(" %d %d", &l, &r);

        Node a, b, c;

        root.split(r, b, c);
        b.split(l-1, a, b);

        b.valuePendingAdd++;
        root = merge(merge(a, b), c);
    }

    Node root2 = null;

    void traverse(Node node)
    {
        if (node is null) return;

        node.pushPending();

        traverse(node.left);

        root2 = merge(root2, new Node(node.value >= k ? 1 : 0));

        traverse(node.right);
    }

    traverse(root);

    for (int i = 0; i < q; i++)
    {
        int l, r;
        readf(" %d %d", &l, &r);

        Node a, b, c;

        root2.split(r, b, c);
        b.split(l-1, a, b);
        writeln(b.valueSum);
        root2 = merge(merge(a, b), c);
    }
}

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

immutable int max = 2 * 10^^5 + 2;

int n, k, q;

void main() {
    scan(n, k, q);

    auto adm = new int[](max);

    int li, ri;

    foreach (i ; 0 .. n) {
        scan(li, ri);
        adm[li]++;
        adm[ri+1]--;
    }

    foreach (i ; 1 .. max) {
        adm[i] += adm[i - 1];
    }

    foreach (i ; 0 .. max) {
        adm[i] = (adm[i] >= k);
    }

    foreach (i ; 1 .. max) {
        adm[i] += adm[i - 1];
    }

    int ai, bi;

    foreach (i ; 0 .. q) {
        scan(ai, bi);
        writeln(adm[bi] - adm[ai - 1]);
    }
}

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

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

immutable int max = 2 * 10^^5 + 10;

int n, k, q;
//int[] l, r;

void main() {
    scan(n, k, q);

    auto adm = new int[](max);

    int li, ri;

    foreach (i ; 0 .. n) {
        scan(li, ri);
        adm[li]++;
        adm[ri+1]--;
    }

    iota(max - 1).each!(i => adm[i + 1] += adm[i]);

    debug {
        stderr.writeln("adm:", adm[0 .. 120]);
    }

    adm = adm.map!(a => (a >= k).to!int).array;

    debug {
        stderr.writeln("adm:", adm[0 .. 120]);
    }

    iota(max - 1).each!(i => adm[i + 1] += adm[i]);

    debug {
        stderr.writeln("adm:", adm[0 .. 150]);
    }

    int ai, bi, ans;

    foreach (i ; 0 .. q) {
        scan(ai, bi);
        ans = adm[bi] - adm[ai - 1];
        ans.writeln;
    }
}

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

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 LIM = 200000 + 10;

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const K = readInt();
      const Q = readInt();
      auto L = new int[N];
      auto R = new int[N];
      foreach (i; 0 .. N) {
        L[i] = readInt();
        R[i] = readInt();
      }
      auto A = new int[Q];
      auto B = new int[Q];
      foreach (q; 0 .. Q) {
        A[q] = readInt();
        B[q] = readInt();
      }

      auto fs = new int[LIM];
      foreach (i; 0 .. N) {
        ++fs[L[i]];
        --fs[R[i] + 1];
      }
      foreach (x; 1 .. LIM) {
        fs[x] += fs[x - 1];
      }
      auto gs = new int[LIM + 1];
      foreach (x; 0 .. LIM) {
        gs[x + 1] = gs[x] + ((fs[x] >= K) ? 1 : 0);
      }

      foreach (q; 0 .. Q) {
        const ans = gs[B[q] + 1] - gs[A[q]];
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}

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

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

    auto cs = new int[](200020);
    foreach (_; 0..N) {
        s = readln.split.map!(to!int);
        cs[s[0]] += 1;
        cs[s[1]+1] -= 1;
    }
    foreach (i; 0..200019) {
        cs[i+1] += cs[i];
    }

    auto st = new SegmentTree(200020);
    foreach (i; 0..200020) if (cs[i] >= K) st.add(i, 1);

    while (Q--) {
        s = readln.split.map!(to!int);
        st.sum(s[0], s[1]).writeln;
    }

}

class SegmentTree {
    int[] table;
    int size;

    this(int n) {
        assert(bsr(n) < 29);
        size = 1 << (bsr(n) + 2);
        table = new int[](size);
    }

    void add(int pos, int num) {
        return add(pos, num, 0, 0, size/2-1);
    }

    void add(int pos, int num, int i, int left, int right) {
        table[i] += num;
        if (left == right) {
            return;
        }
        auto mid = (left + right) / 2;
        if (pos <= mid)
            add(pos, num, i*2+1, left, mid);
        else
            add(pos, num, i*2+2, mid+1, right);
    }

    int sum(int pl, int pr) {
        return sum(pl, pr, 0, 0, size/2-1);
    }

    int sum(int pl, int pr, int i, int left, int right) {
        if (pl > right || pr < left)
            return 0;
        else if (pl <= left && right <= pr)
            return table[i];
        else
            return
                sum(pl, pr, i*2+1, left, (left+right)/2) +
                sum(pl, pr, i*2+2, (left+right)/2+1, right);
    }
}


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

void main ()
{
	foreach (test; 0..readln.strip.to !(int))
	{
		int p, f;
		readf !(" %s %s") (p, f);
		int cs, cw;
		readf !(" %s %s") (cs, cw);
		int s, w;
		readf !(" %s %s") (s, w);
		if (s > w)
		{
			swap (s, w);
			swap (cs, cw);
		}
		int res = 0;
		foreach (ns; 0..cs + 1)
		{
			auto ns1 = min (ns, p / s);
			auto ns2 = min (cs - ns1, f / s);
			auto nw1 = min (cw, (p - ns1 * s) / w);
			auto nw2 = min (cw - nw1, (f - ns2 * s) / w);
			res = max (res, ns1 + ns2 + nw1 + nw2);
		}
		writeln (res);
	}
}

// Vicfred
// https://codeforces.com/contest/1400/problem/B
//
import std.algorithm;
import std.stdio;

void main() {
    long t, p, f, cnts, cntw, s, w;

    readf("%s", &t);
    readln;

    while(t--) {
        readf("%s %s\n", &p, &f);
        readf("%s %s\n", &cnts, &cntw);
        readf("%s %s\n", &s, &w);

        if(s > w) {
            swap(s,w);
            swap(cnts, cntw);
        }

        long ans = long.min;
        for(long swords = 0; swords <= cnts; ++swords) {
            if(p/s < swords)
                continue;

            long goku, freezer, cnt, maxima;
            goku = p;
            freezer = f;

            goku -= swords*s;
            cnt = min(f/s, cnts - swords);
            freezer -= cnt*s;

            maxima = swords + cnt;
            maxima += min(cntw, goku/w + freezer/w);

            //writefln("goku lleva %s espadas", swords);
            //writefln("freezer lleva %s espadas", cnt);
            //writefln("hachas %s", min(cntw, goku/w + freezer/w));

            ans = max(maxima, ans);
        }

        ans.writeln;
    }
}


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		a[] -= 1;
		auto b = new int [] [n];
		foreach_reverse (i; 0..n)
		{
			b[a[i]] ~= i;
		}

		auto t = new int [n + 1];

		void add (int i)
		{
			for ( ; i <= n; i += i & -i)
			{
				t[i] += 1;
			}
		}

		int ask (int i)
		{
			int res = 0;
			for ( ; i > 0; i -= i & -i)
			{
				res += t[i];
			}
			return res;
		}

		long res = 0;
		foreach (i; 0..n)
		{
			foreach (v; b[i])
			{
				res += ask (n - v);
				add (n - v);
			}
		}
		writeln (res);
	}
}

void main() { runSolver(); }

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

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

      auto st = SegTree!("a + b", int)(new int[](N + 1));
      int ans;
      foreach(i, a; A) {
        ans += st.sum(a, N + 1);

        auto x = st.get(a);
        st.update(a, x + 1);
      }

      return ans;
    }

    foreach(i; 0..QN) {
      subSolve().writeln;
    }
  }

  outputForAtCoder(&solve);
}

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

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

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

struct SegTree(alias pred = "a + b", T = long) {
  alias predFun = binaryFun!pred;
  int size;
  T[] data;
  T monoid;

  this(T[] src, T monoid = T.init) {
    this.monoid = monoid;

    for(int i = 2; i < 2L^^32; i *= 2) {
      if (src.length <= i) {
        size = i;
        break;
      }
    }

    data = new T[](size * 2);
    foreach(i, s; src) data[i + size] = s;
    foreach_reverse(b; 1..size) {
      data[b] = predFun(data[b * 2], data[b * 2 + 1]);
    }
  }

  void update(int index, T value) {
    int i = index + size;
    data[i] = value;
    while(i > 0) {
      i /= 2;
      data[i] = predFun(data[i * 2], data[i * 2 + 1]);
    }
  }

  T get(int index) {
    return data[index + size];
  }

  T sum(int a, int b, int k = 1, int l = 0, int r = -1) {
    if (r < 0) r = size;

    if (r <= a || b <= l) return monoid;
    if (a <= l && r <= b) return data[k];

    T leftValue = sum(a, b, 2*k, l, (l + r) / 2);
    T rightValue = sum(a, b, 2*k + 1, (l + r) / 2, r);
    return predFun(leftValue, rightValue);
  }
}


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

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    uint [][] a;
    foreach ( _; 0..n ) a ~= readln.chomp.map!(c => c - '0').array;

    auto b = new uint [][] ( m, n );
    foreach ( i; 0..m ) {
        foreach ( j; 0..n ) {
            b[ i ][ j ] = a[ j ][ i ];
        }
    }

    uint[] sums;
    foreach ( j; 0..m ) {
        sums ~= b[ j ].sum;
    }

    auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == 0 || sums[ j ] > 1;
    auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );
    auto found = n.iota.any!( redundantRow );
    writeln( found ? "YES" : "NO" );
}

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

immutable int N = 2 * 1 ^^ 3 + 100;

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    auto a = new dchar [][] (n, m);
    foreach ( i; 0..n ) a[i] = readln.chomp.array;

    auto b = transposed(a.dup);

    auto sums = new int[] (m);

    foreach ( i; 0..m ) {
        foreach ( j; 0..n ) {
            sums[ i ] += a[ j ][ i ] == '1';
        }
    }

    auto found = false;
    foreach ( i; 0..n ) {
        auto cur = true;
        foreach ( j; 0..m ) {
            cur &= a[ i ][ j ] == '0' || sums[ j ] > 1;
        }
        found |= cur;
    }
    writeln ( found ? "YES" : "NO" );
}

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

immutable int N = 2 * 1 ^^ 3 + 100;

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    auto a = new dchar [][] (n, m);
    foreach ( i; 0..n ) a[i] = readln.chomp.array;

    auto sums = new int[] (m);

    foreach ( i; 0..m ) {
        foreach ( j; 0..n ) {
            sums[ i ] += a[ j ][ i ] == '1';
        }
    }

    auto found = false;
    foreach ( i; 0..n ) {
        auto cur = true;
        foreach ( j; 0..m ) {
            cur &= a[ i ][ j ] == '0' || sums[ j ] > 1;
        }
        found |= cur;
    }
    writeln ( found ? "YES" : "NO" );
}

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

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    uint [][] a;
    foreach ( _; 0..n ) a ~= readln.chomp.map!(c => c - '0').array;

    auto b = new uint [][] ( m, n );
    foreach ( i; 0..m ) {
        foreach ( j; 0..n ) {
            b[ i ][ j ] = a[ j ][ i ];
        }
    }

    ulong[] sums;
    foreach ( j; 0..m ) {
        sums ~= b[ j ].count!(c => c == 1);
    }

    auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == 0 || sums[ j ] > 1;
    auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );
    auto found = n.iota.any!( redundantRow );
    writeln( found ? "YES" : "NO" );
}

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

immutable int N = 2 * 1 ^^ 3 + 100;

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    auto a = new dchar [][] (n, m);
    foreach ( i; 0..n ) a[i] = readln.chomp.array;

    auto b = transposed(a.dup);
    auto sums = b.map!(a => a.count!(c => c == '1')).array;

    auto found = false;
    foreach ( i; 0..n ) {
        auto cur = true;
        foreach ( j; 0..m ) {
            cur &= a[ i ][ j ] == '0' || sums[ j ] > 1;
        }
        found |= cur;
    }
    writeln ( found ? "YES" : "NO" );
}

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

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    auto a = new dchar [][] ( n, m );
    foreach ( i; 0..n ) a[ i ] = readln.chomp.array;

    auto b = transposed(a.dup);
    auto sums = new int[] (m);
    foreach ( j; 0..m ) {
        foreach ( i; 0..n ) {
            sums[ j ] += a[ i ][ j ] == '1';
        }
    }

    auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == '0' || sums[ j ] > 1;
    auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );
    auto found = n.iota.any!( redundantRow );
    writeln( found ? "YES" : "NO" );
}

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

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    uint [][] a;
    foreach ( _; 0..n ) a ~= readln.chomp.map!(c => c - '0').array;

    auto b = new uint [][] ( m, n );
    foreach ( i; 0..m ) {
        foreach ( j; 0..n ) {
            b[ i ][ j ] = a[ j ][ i ];
        }
    }

    ulong[] sums;
    foreach ( j; 0..m ) {
        sums ~= b[ j ].sum;
    }

    auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == 0 || sums[ j ] > 1;
    auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );
    auto found = n.iota.any!( redundantRow );
    writeln( found ? "YES" : "NO" );
}

import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import core.bitop;
import std.algorithm;

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    string[] a;
    foreach ( i; 0..n ) a ~= readln.chomp;

    auto b = transposed(a.dup);
    auto sums = new int[] (m);
    foreach ( j; 0..m ) {
        foreach ( i; 0..n ) {
            sums[ j ] += a[ i ][ j ] == '1';
        }
    }

    auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == '0' || sums[ j ] > 1;
    auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );
    auto found = n.iota.any!( redundantRow );
    writeln( found ? "YES" : "NO" );
}

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

immutable int N = 2 * 1 ^^ 3 + 100;

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    auto a = new dchar [][] ( n, m );
    foreach ( i; 0..n ) a[ i ] = readln.chomp.array;

    auto b = transposed( a.dup );
    auto sums = b.map!( row => row.count!( c => c == '1' ) ).array;

    auto found = n.iota.any!( i => m.iota.all!( j => a[ i ][ j ] == '0' || sums[ j ] > 1 ) );
    writeln( found ? "YES" : "NO" );
}

import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import core.bitop;
import std.algorithm;

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    uint [][] a;
    foreach ( i; 0..n ) a ~= readln.chomp.map!(c => c - '0').array;

    auto b = transposed(a.dup);
    auto sums = new int[] (m);
    foreach ( j; 0..m ) {
        foreach ( i; 0..n ) {
            sums[ j ] += a[ i ][ j ];
        }
    }

    auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == 0 || sums[ j ] > 1;
    auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );
    auto found = n.iota.any!( redundantRow );
    writeln( found ? "YES" : "NO" );
}

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

immutable int N = 2 * 10 ^^ 3 + 100;

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    auto a = new dchar [][] ( n, m );
    foreach ( i; 0..n ) a[ i ] = readln.chomp.array;

    auto sums = new int [] ( m );
    foreach ( i; 0..m ) {
        foreach ( j; 0..n ) {
            sums[ i ] += a[ j ][ i ] == '1' ;
        }
    }

    auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == '0' || sums[ j ] > 1;
    auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );
    auto found = n.iota.any!( redundantRow );
    writeln( found ? "YES" : "NO" );
}

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

immutable int N = 2 * 1 ^^ 3 + 100;

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    auto a = new dchar [][] ( n, m );
    foreach ( i; 0..n ) a[ i ] = readln.chomp.array;

    auto b = transposed( a.dup );
    auto sums = b.map!( row => row.count!( c => c == '1' ) ).array;

    auto goodCell = ( int i, int j ) => a[ i ][ j ] == '0' || sums[ j ] > 1 ;
    auto goodRow = ( int i ) => m.iota.all!( j => goodCell( i , j ) );
    auto found = n.iota.any!( goodRow );
    writeln( found ? "YES" : "NO" );
}

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

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    uint [][] a;
    foreach ( _; 0..n ) a ~= readln.chomp.map!(c => c - '0').array;

    auto b = new uint [][] ( m, n );
    foreach ( i; 0..m ) {
        foreach ( j; 0..n ) {
            b[ i ][ j ] = a[ j ][ i ];
        }
    }

    uint[] sums;
    foreach ( j; 0..m ) {
        sums ~= b[ j ].sum;
    }

    debug { writeln(a, ' ', sums); }

    auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == 0 || sums[ j ] > 1;
    auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );
    auto found = n.iota.any!( redundantRow );
    writeln( found ? "YES" : "NO" );
}

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

immutable int N = 2 * 1 ^^ 3 + 100;

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    auto a = new int [][] (n, m);
    foreach ( i; 0..n ) a[i] = readln.chomp.map!( c => cast(int)c - cast(int)'0' ).array;

    auto b = transposed(a.dup);
    auto sums = b.map!sum.array;

    auto found = false;
    foreach ( i; 0..n ) {
        auto cur = true;
        foreach ( j; 0..m ) {
            cur &= a[ i ][ j ] == 0 || sums[ j ] > 1;
        }
        found |= cur;
    }
    writeln ( found ? "YES" : "NO" );
}

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

immutable int N = 2 * 1 ^^ 3 + 100;

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    auto a = new dchar [][] ( n, m );
    foreach ( i; 0..n ) a[ i ] = readln.chomp.array;

    auto b = new dchar [][] ( m, n );
    foreach ( i; 0..m ) {
        foreach ( j; 0..n ) {
            b[ i ][ j ] = a[ j ][ i ];
        }
    }
    auto sums = b.map!( row => row.count!( c => c == '1' ) ).array;

    auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == '0' || sums[ j ] > 1;
    auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );
    auto found = n.iota.any!( redundantRow );
    writeln( found ? "YES" : "NO" );
}

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

immutable int N = 2 * 1 ^^ 3 + 100;

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    auto a = new dchar [][] ( n, m );
    foreach ( i; 0..n ) a[ i ] = readln.chomp.array;

    auto b = transposed( a.dup );
    auto sums = b.map!( row => row.count!( c => c == '1' ) ).array;

    auto found = false;
    foreach ( i; 0..n ) {
        auto cur = true;
        foreach ( j; 0..m ) {
            cur &= a[ i ][ j ] == '0' || sums[ j ] > 1;
        }
        found |= cur;
    }
    writeln( found ? "YES" : "NO" );
}

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

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    auto a = new dchar [][] ( n, m );
    foreach ( i; 0..n ) a[ i ] = readln.chomp.array;

    auto b = transposed( a.dup );
    auto sums = b.map!( row => row.count!( c => c == '1' ) ).array;

    auto found = false;
    foreach ( i; 0..n ) {
        found |= m.iota.all!(j => a[ i ][ j ] == '0' || sums[ j ] > 1);
    }
    writeln( found ? "YES" : "NO" );
}

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

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    uint [][] a;
    foreach ( _; 0..n ) a ~= readln.chomp.map!(c => c - '0').array;

    auto b = new uint [][] ( m, n );
    foreach ( i; 0..m ) {
        foreach ( j; 0..n ) {
            b[ i ][ j ] = a[ j ][ i ];
        }
    }

    int[] sums;
    foreach ( j; 0..m ) {
        sums ~= b[ j ].sum;
    }

    auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == 0 || sums[ j ] > 1;
    auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );
    auto found = n.iota.any!( redundantRow );
    writeln( found ? "YES" : "NO" );
}

import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import core.bitop;
import std.algorithm;

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    auto a = new uint [][] ( n, m );
    foreach ( i; 0..n ) a[ i ] = readln.chomp.map!(q{a - '0'}).array;

    auto b = transposed(a.dup);
    auto sums = new int[] (m);
    foreach ( j; 0..m ) {
        foreach ( i; 0..n ) {
            sums[ j ] += a[ i ][ j ];
        }
    }

    auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == 0 || sums[ j ] > 1;
    auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );
    auto found = n.iota.any!( redundantRow );
    writeln( found ? "YES" : "NO" );
}

import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;
import std.bigint;

void main()
{
	int n, m;
	readln.chomp.split.tie(n, m);
	char[][] field = new char[][](n);
	foreach (ref a; field) {
		a = readln.chomp.dup;
	}
	int[] cnt = new int[](m);
	foreach (a; field) {
		foreach (i, v; a) {
			if (v == '0') {
				continue;
			}
			cnt[i]++;
		}
	}
	debug verbose(cnt);
	bool ok = false;
	foreach (i; 0..n) {
		// ignore i-th
		bool flag = true;
		foreach (j; 0..m) {
			if (field[i][j] == '0') {
				continue;
			}
			flag &= cnt[j] > 1;
		}
		ok |= flag;
	}
	writeln = ok ? "YES" : "NO";
}

void tie(R, Args...)(R arr, ref Args args)
		if (isRandomAccessRange!R || isArray!R)
in
{
	assert (arr.length == args.length);
}
body
{
	foreach (i, ref v; args) {
		alias T = typeof(v);
		v = arr[i].to!T;
	}
}

void verbose(Args...)(in Args args)
{
	stderr.write("[");
	foreach (i, ref v; args) {
		if (i) stderr.write(", ");
		stderr.write(v);
	}
	stderr.writeln("]");
}

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

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    uint [][] a;
    foreach ( _; 0..n ) a ~= readln.chomp.map!(c => c - '0').array;

    auto b = transposed(a.dup).map!array.array;
    ulong[] sums;
    foreach ( j; 0..m ) {
        sums ~= b[ j ].count!(c => c == 1);
    }

    auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == 0 || sums[ j ] > 1;
    auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );
    auto found = n.iota.any!( redundantRow );
    writeln( found ? "YES" : "NO" );
}

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

immutable int N = 2 * 1 ^^ 3 + 100;

void main()
{
    int n, m;
    readf( "%s %s", &n, &m );
    readln;
    auto a = new dchar [][] ( n, m );
    foreach ( i; 0..n ) a[ i ] = readln.chomp.array;

    auto b = transposed( a.dup ).array.map!array;
    auto sums = b.map!( row => row.count!( c => c == '1' ) ).array;

    auto replaceableCell = ( int i, int j ) => a[ i ][ j ] == '0' || sums[ j ] > 1;
    auto redundantRow = ( int i ) => m.iota.all!( j => replaceableCell( i , j ) );
    auto found = n.iota.any!( redundantRow );
    writeln( found ? "YES" : "NO" );
}


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

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

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

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

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

int N;
int[] A, B;

struct Interval {
	int s, t;
	int id;
}

void main(string[] args) {
	try {
	for (; ; ) {
		N = readInt;
		A = new int[N];
		B = new int[N];
		foreach (i; 0 .. N) {
			A[i] = readInt;
			B[i] = readInt;
			if (A[i] > B[i]) {
				swap(A[i], B[i]);
			}
		}

		Interval[] as = new Interval[N];
		foreach (i; 0 .. N) {
			as[i] = Interval(A[i], B[i], i);
		}
		as.sort!((a, b) => (a.s != b.s) ? (a.s < b.s) : (a.t < b.t));
debug{
writeln(as);
}

		int[] dp = new int[N];
		foreach (i; 0 .. N) {
			dp[i] = 1;
			foreach (j; 0 .. i) {
				if (as[j].t < as[i].s) {
					chmax(dp[i], dp[j] + 1);
				}
			}
		}
debug{
writeln("dp = ",dp);
}

		const ans = reduce!max(0, dp);
		int[] ss = new int[ans + 1];
		int[] ts = new int[ans + 1];
		ss[] = int.min;
		ts[] = int.max;
		foreach (i; 0 .. N) {
			chmax(ss[dp[i]], as[i].s);
			chmin(ts[dp[i]], as[i].t);
		}
debug{
writeln(ss," ",ts);
}
		foreach (j; 1 .. ans + 1) {
			assert(ss[j] <= ts[j]);
		}

		writeln(ans);
		writeln(ss[1 .. $].to!string.removechars("[],"));

	}
	} catch (EOFException) {}
}

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

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);
  auto n = next!int;
  alias Ev = Tuple!(int, int, int);
  enum int closeEv = +1;
  enum int openEv = -1;
  auto evs = new Ev[](2 * n);
  foreach(i; 0 .. n)
    {
      int l = next!int;
      int h = next!int;
      if (l > h) swap(l, h);
      evs[2 * i] = Ev(l, openEv, i);
      evs[2 * i + 1] = Ev(h, closeEv, i);
    }
  auto alive = new bool[](n); alive[] = true;
  auto open = redBlackTree!int();
  auto nails = new int[](0);
  sort(evs);
  foreach(ev; evs)
    {
      int i = ev[2];
      int x = ev[0];
      int t = ev[1];
      if (!alive[i]) continue;
      if (t == closeEv)
	{
	  nails ~= x;
	  foreach(oi; open) alive[oi] = false;
	  open.clear;
	}
      else if (t == openEv)
	{
	  open.insert([i]);
	}
      else
	{
	  assert(0);
	}
    }
  nails.length.writeln;
  nails.each!(x => x.write(" "));
  writeln;
}

// INPUT

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

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

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


import std.stdio;
int main()
{
	int a=0;
	readf(" %d", &a);
	string s;
	readf(" %s", &s);
	char[] m = s.dup;
	int n=0;
	for (int i=0; i<a; i++)
	{
		if (m[i]=='n')
		{
			n=n+1;
		}
	}
	for (int i=0; i<n; i++)
	{
		writeln(1);
	}
	for (int i=0; i<((a-n*3)/4); i++)
	{
		writeln(0);
	}
	return 0;
}

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

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto n = RD!int;
	auto s = RD!string;
	long[char] cnt;
	cnt['n'] = 0;
	cnt['z'] = 0;
	foreach (c; s)
	{
		++cnt[c];
	}

	long[] ans;
	foreach (i; 0..cnt['n'])
		ans ~= 1;
	foreach (i; 0..cnt['z'])
		ans ~= 0;
	ans.map!(to!string).join(" ").writeln;
	stdout.flush();
	debug readln();
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, 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 S = readToken();

      const z = S.count('z');
      const n = S.count('n');
      int ou;
      foreach (i; 0 .. n) {
        if (ou++) write(" ");
        write(1);
      }
      foreach (i; 0 .. z) {
        if (ou++) write(" ");
        write(0);
      }
      writeln();
    }
  } catch (EOFException e) {
  }
}


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

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

    int[][] arr;
    foreach (i; 0 .. n) {
        arr ~= readln.chomp.split.map!(to!int).array;
    }

    foreach (i; 0 .. n) {
        foreach (j; 0 .. m) {
            arr[i][j] -= 1;
        }
    }

    int ans = 0;
    foreach (col; 0 .. m) {
        auto dst = new int[] (n);
        dst[] = 0;
        foreach (rw; 0 .. n) {
            if (arr[rw][col] >= n*m) { continue; }

            int md = arr[rw][col] % m;
            if (md != col) { continue; }

            int rwval = arr[rw][col] / m;
            int curdst = rw >= rwval ? rw - rwval : rw + 1 + n-1 - rwval;

            dst[curdst] += 1;
        }

        int colsum = n;
        foreach (d; 0 .. n) {
            colsum = min(colsum, d + n - dst[d]);
        }

        ans += colsum;
    }

    ans.writeln;
}

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

string[] tokens;

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

int readInt()
{
    return readToken.to!int;
}

void main()
{
    int n = readInt;
    int m = readInt;
    int[][] a = new int[][n];
    for (int i = 0; i < n; ++i)
    {
        a[i] = new int[m];
        for (int j = 0; j < m; ++j)
        {
            a[i][j] = readInt - 1;
        }
    }

    int[] count = new int[n];

    int result = 0;
    for (int j = 0; j < m; ++j)
    {
        fill(count, 0);
        for (int i = 0; i < n; ++i)
        {
            int x = a[i][j];
            if (x < n * m && x % m == j)
            {
                count[(i + n - (x - j) / m) % n]++;
            }
        }
        int best = n;
        for (int i = 0; i < n; ++i)
        {
            int x = a[i][j];
            if (x < n * m && x % m == j)
            {
                int moves = (i + n - (x - j) / m) % n;
                best = min(best, n - count[moves] + moves);
            }
        }
        result += best;
    }
    writeln(result);
}

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

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

    int[][] arr;
    foreach (i; 0 .. n) {
        arr ~= readln.chomp.split.map!(to!int).array;
    }

    foreach (i; 0 .. n) {
        foreach (j; 0 .. m) {
            arr[i][j] -= 1;
        }
    }

    int ans = 0;
    foreach (col; 0 .. m) {
        auto dst = new int[] (n);
        dst[] = 0;
        foreach (rw; 0 .. n) {
            if (arr[rw][col] >= n*m) { continue; }

            int md = arr[rw][col] % m;
            if (md != col) { continue; }

            int rwval = arr[rw][col] / m;
            int curdst = (rw - rwval + n) % n;

            dst[curdst] += 1;
        }

        int colsum = n;
        foreach (d; 0 .. n) {
            colsum = min(colsum, d + n - dst[d]);
        }

        ans += colsum;
    }

    ans.writeln;
}

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

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

		int res = 0;
		foreach (j; 0..m)
		{
			auto d = n.iota.array;
			d[] += n;
			foreach (i; 0..n)
			{
				if (a[i][j] < n * m && a[i][j] % m == j)
				{
					d[(i + n - a[i][j] / m) % n] -= 1;
				}
			}
			res += minElement (d);
		}
		writeln (res);
	}
}

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

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

    auto arr = new int[][] (n);
    foreach (i; 0 .. n) {
        arr[i] = readln.chomp.split.map!(to!int).array;
    }

    foreach (i; 0 .. n) {
        foreach (j; 0 .. m) {
            arr[i][j] -= 1;
        }
    }

    int ans = 0;
    foreach (col; 0 .. m) {
        auto dst = new int[] (n);
        dst[] = 0;
        foreach (rw; 0 .. n) {
            int md = arr[rw][col] % m;
            if (md != col) { continue; }

            int rwval = arr[rw][col] / m;
            int curdst = rw >= rwval ? rw - rwval : rw + n-1 - rwval;

            dst[curdst] += 1;
        }

        int colsum = n;
        foreach (d; 0 .. n) {
            colsum = min(colsum, d + n - dst[d]);
        }

        ans += colsum;
    }

    ans.writeln;
}

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

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

    auto arr = new int[][] (n);
    foreach (i; 0 .. n) {
        arr[i] = readln.chomp.split.map!(to!int).array;
    }

    foreach (i; 0 .. n) {
        foreach (j; 0 .. m) {
            arr[i][j] -= 1;
        }
    }

    int ans = 0;
    foreach (col; 0 .. m) {
        auto dst = new int[] (n);
        foreach (rw; 0 .. n) {
            int md = arr[rw][col] % m;
            if (md != col) { continue; }

            int rwval = arr[rw][col] / m;
            int curdst = (rw - rwval + n) % n;

            dst[curdst] += 1;
        }

        int colsum = n-1;
        foreach (d; 0 .. n) {
            colsum = min(colsum, d + n - dst[d]);
        }

        ans += colsum;
    }

    ans.writeln;
}

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

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

    auto arr = new int[][] (n);
    foreach (i; 0 .. n) {
        arr[i] = readln.chomp.split.map!(to!int).array;
    }

    foreach (i; 0 .. n) {
        foreach (j; 0 .. m) {
            arr[i][j] -= 1;
        }
    }

    int ans = 0;
    foreach (col; 0 .. m) {
        auto dst = new int[] (n);
        foreach (rw; 0 .. n) {
            int md = arr[rw][col] % m;
            if (md != col) { continue; }

            int rwval = arr[rw][col] / m;
            int curdst = rw >= rwval ? rw - rwval : rw + n-1 - rwval;

            dst[curdst] += 1;
        }

        int colsum = n;
        foreach (d; 0 .. n) {
            colsum = min(colsum, d + n - dst[d]);
        }

        ans += colsum;
    }

    ans.writeln;
}

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

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

    auto arr = new int[][] (n);
    foreach (i; 0 .. n) {
        arr[i] = readln.chomp.split.map!(to!int).array;
    }

    foreach (i; 0 .. n) {
        foreach (j; 0 .. m) {
            arr[i][j] -= 1;
        }
    }

    int ans = 0;
    foreach (col; 0 .. m) {
        auto dst = new int[] (n);
        foreach (rw; 0 .. n) {
            int md = arr[rw][col] % m;
            if (md != col) { continue; }

            int rwval = arr[rw][col] / m;
            int curdst = rw >= rwval ? rw - rwval : rw + n-1 - rwval;

            dst[curdst] += 1;
        }

        int colsum = n-1;
        foreach (d; 0 .. n) {
            colsum = min(colsum, d + n - dst[d]);
        }

        ans += colsum;
    }

    ans.writeln;
}

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

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

    auto arr = new int[][] (n);
    foreach (i; 0 .. n) {
        arr[i] = readln.chomp.split.map!(to!int).array;
    }

    foreach (i; 0 .. n) {
        foreach (j; 0 .. m) {
            arr[i][j] -= 1;
        }
    }

    int ans = 0;
    foreach (col; 0 .. m) {
        auto dst = new int[] (n);
        dst[] = 0;
        foreach (rw; 0 .. n) {
            if (arr[rw][col] >= n*m) { continue; }

            int md = arr[rw][col] % m;
            if (md != col) { continue; }

            int rwval = arr[rw][col] / m;
            int curdst = rw >= rwval ? rw - rwval : rw + n-1 - rwval;

            dst[curdst] += 1;
        }

        int colsum = n;
        foreach (d; 0 .. n) {
            colsum = min(colsum, d + n - dst[d]);
        }

        ans += colsum;
    }

    ans.writeln;
}

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

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

    auto arr = new int[][] (n);
    foreach (i; 0 .. n) {
        arr[i] = readln.chomp.split.map!(to!int).array;
    }

    foreach (i; 0 .. n) {
        foreach (j; 0 .. m) {
            arr[i][j] -= 1;
        }
    }

    int ans = 0;
    foreach (col; 0 .. m) {
        auto dst = new int[] (n);
        foreach (rw; 0 .. n) {
            int md = arr[rw][col] % m;
            if (md != col) { continue; }

            int rwval = arr[rw][col] / m;
            int curdst = (rw - rwval + n-1) % (n-1);

            dst[curdst] += 1;
        }

        int colsum = n-1;
        foreach (d; 0 .. n) {
            colsum = min(colsum, d + n - dst[d]);
        }

        ans += colsum;
    }

    ans.writeln;
}

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

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

    int[][] arr;
    foreach (i; 0 .. n) {
        arr ~= readln.chomp.split.map!(to!int).array;
    }

    foreach (i; 0 .. n) {
        foreach (j; 0 .. m) {
            arr[i][j] -= 1;
        }
    }

    int ans = 0;
    foreach (col; 0 .. m) {
        auto dst = new int[] (n);
        dst[] = 0;
        foreach (rw; 0 .. n) {
            if (arr[rw][col] >= n*m) { continue; }

            int md = arr[rw][col] % m;
            if (md != col) { continue; }

            int rwval = arr[rw][col] / m;
            int curdst = rw >= rwval ? rw - rwval : rw + n-1 - rwval;

            dst[curdst] += 1;
        }

        int colsum = n;
        foreach (d; 0 .. n) {
            colsum = min(colsum, d + n - dst[d]);
        }

        ans += colsum;
    }

    ans.writeln;
}

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

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

		int res = 0;
		foreach (j; 0..m)
		{
			auto d = n.iota.array;
			d[] += n;
			foreach (i; 0..n)
			{
				if (a[i][j] % m == j)
				{
					d[(i + n - a[i][j] / m) % n] -= 1;
				}
			}
			res += minElement (d);
		}
		writeln (res);
	}
}

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

string[] tokens;

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

int readInt()
{
    return readToken.to!int;
}

void main()
{
    int n = readInt;
    int m = readInt;
    int[][] a = new int[][n];
    for (int i = 0; i < n; ++i)
    {
        a[i] = new int[m];
        for (int j = 0; j < m; ++j)
        {
            a[i][j] = readInt - 1;
        }
    }

    int[] count = new int[n];

    int result = 0;
    for (int j = 0; j < m; ++j)
    {
        fill(count, 0);
        for (int i = 0; i < n; ++i)
        {
            int x = a[i][j];
            if (x % m == j)
            {
                count[(i + n - (x - j) / m) % n]++;
            }
        }
        int best = n;
        for (int i = 0; i < n; ++i)
        {
            int x = a[i][j];
            if (x % m == j)
            {
                int moves = (i + n - (x - j) / m) % n;
                best = min(best, n - count[moves] + moves);
            }
        }
        result += best;
    }
    writeln(result);
}


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

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, a, b, c, te; readV(n, a, b, c, te);
  int[] t; readA(n, t);

  auto ans = 0;
  foreach (ti; t) {
    if (b > c) {
      ans += a;
    } else {
      ans += a + (c-b)*(te-ti);
    }
  }

  writeln(ans);
}

import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;

void main() {
	auto args = readln.chomp.split.map!(to!int).array;
	int n = args[0];
	int A = args[1];
	int B = args[2];
	int C = args[3];
	int T = args[4];
	int[] t = readln.chomp.split.map!(to!int).array;
	int[][][] dp = new int[][][](T + 2, T + 2, 2);
	int[int] dic;
	for (int i = 1; i <= T; ++i) {
		dic[i] = 0;
	}
	foreach (v; t) {
		++dic[v];
	}
	debug stderr.writeln(dic);
	for (int i = 1; i <= T; ++i) {
		for (int j = 1; j <= i; ++j) {
			debug stderr.writeln(tuple(i, j, 1));
			{
				dp[i + 1][j][1] = dp[i][j][1] + dic[j] * C;
				debug stderr.writefln("\tdp[%d][%d][1] = %d (%d + %d * %d)", i + 1, j, dp[i + 1][j][0], dp[i][j][1], dic[j], C);
			}
			{
				int pena = A - (i - j) * B;
				dp[i + 1][j][0] = max(dp[i][j][0], dp[i][j][1] + dic[j] * pena);
				debug stderr.writefln("\tdp[%d][%d][0] = %d (max(%d, %d + %d * %d)", i + 1, j, dp[i + 1][j][0], dp[i][j][0], dp[i][j][1], dic[j], pena);
			}
		}
	}
	int sum = 0;
	for (int i = 1; i <= T; ++i) {
		debug stderr.writefln("\t(%d) : %d", i, dp[T + 1][i][0]);
		sum += dp[T + 1][i][0];
	}
	sum.writeln;
}


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

immutable int base = 2020;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto q = n / base;
		auto r = n % base;
		writeln ((q >= base) || (q >= r) ? "YES" : "NO");
	}
}

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 x;
        while (N >= 2020) {
            N -= 2020;
            ++x;
        }
        writeln(x >= N ? "YES" : "NO");
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto cnt = n / 2020;
		auto rem = n % 2020;
		ans[ti] = rem <= cnt;
	}

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