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

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

    int[int] used;
    auto acm = new int[](N);
    for (int i = N-1; i >= 0; i--) {
        if (i < N -1)
            acm[i] = acm[i+1];
        if (!(A[i] in used)) {
            used[A[i]] = true;
            acm[i]++;
        }
    }

    foreach (_; 0..M) {
        auto x = readln.chomp.to!int;
        acm[x-1].writeln;
    }
}

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

void main() {
  auto input = readln.chomp.split.map!(to!int).array;
  auto n = input.front;
  auto m = input.back;
  auto a = readln.chomp.split.map!(to!int).array;
  bool[int] memAssoc;
  auto ans = new ulong[n];
  for (int i = n - 1; i >= 0; i--) {
    memAssoc[a[i]] = true;
    ans[i] = memAssoc.length;
  }
  for (int i = 0; i < m; i++) {
    int l = readln.chomp.to!int;
    ans[l - 1].writeln;
  }
}

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

void main()
{
    bool [int] s;
	auto nm = readln.chomp.split.map!"a.to!int";
    auto as = readln.chomp.split.map!"a.to!int";
    auto n = nm[0], m = nm[1];
    auto count = 0;
    auto dp = new int[n];
    foreach_reverse (i;0..n) {
        if (!(as[i] in s)) {
            count++;
            s[as[i]]=true;
        }
        dp[i] = count;

    }
    foreach (i; 0..m)
        writeln(dp[readln.chomp.to!int - 1]);

}

//ahmat
import std.stdio,std.string,std.math,std.algorithm,
std.array,std.container,std.algorithm,std.numeric,std.bitmanip,
std.range,std.random,std.complex,std.functional,std.typecons,
std.format,std.bigint,core.vararg,core.bitop,std.conv;

void cin(...){}
void cout(...){}
int sz(T)(ref T a){return cast(int)a.length;}

int n,m,l;
void main(){
    readf("%d %d\n",&n,&m);
    int[] arr=readln.splitter.map!(to!int).array;
    bool[int] map;
    int[] a=new int[n];
    for(int i=n-1;i>=0;i--){
        map[arr[i]]=true;
        a[i]=cast(int)map.length;
    }
    //debug writeln(a);
    while(m--){
        readf("%d\n",l);
        writeln(a[l-1]);
    }
}


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() {
  const N = readInt();

  auto board = new long[][](N, N);
  foreach (s; 1 .. 2 * N - 2) {
    foreach (x; 0 .. N) {
      const y = s - x;
      if (0 <= y && y < N) {
        board[x][y] = (cast(long)(x & 1)) << s;
      }
    }
  }
  foreach (x; 0 .. N) {
    board[x][N - 1 - x] = (cast(long)(x)) << (2 * N - 2);
  }
  foreach (x; 0 .. N) foreach (y; 0 .. N) {
    assert(0 <= board[x][y] && board[x][y] <= 10L^^16);
  }

  foreach (x; 0 .. N) {
    foreach (y; 0 .. N) {
      if (y > 0) write(" ");
      write(board[x][y]);
    }
    writeln;
  }
  stdout.flush;

  const Q = readInt();
  foreach (q; 0 .. Q) {
    const K = readLong();

    auto xs = new int[2 * N - 1];
    xs[0] = 0;
    xs[2 * N - 2] = N - 1;
    xs[N - 1] = cast(int)(K >> (2 * N - 2));
    foreach_reverse (s; 1 .. N - 1) {
      xs[s] = xs[s + 1];
      if ((xs[s] & 1) != ((K >> s) & 1)) {
        --xs[s];
      }
    }
    foreach (s; N .. 2 * N - 2) {
      xs[s] = xs[s - 1];
      if ((xs[s] & 1) != ((K >> s) & 1)) {
        ++xs[s];
      }
    }

    foreach (s; 0 .. 2 * N - 1) {
      writeln(xs[s] + 1, " ", (s - xs[s]) + 1);
    }
    stdout.flush;

    long k;
    foreach (s; 0 .. 2 * N - 1) {
      k += board[xs[s]][s - xs[s]];
    }
    assert(k == K);
  }
}

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

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto ways = new long [] [] (n, n);
		foreach (row; 0..n)
		{
			foreach (col; 0..n)
			{
				if (row + col == 0)
				{
					ways[row][col] += 1;
				}
				if (row > 0)
				{
					ways[row][col] += ways[row - 1][col];
				}
				if (col > 0)
				{
					ways[row][col] += ways[row][col - 1];
				}
			}
		}

		auto num = new long [] [] (n, n);
		auto board = new long [] [] (n, n);
		long temp = 1;
		foreach (col; 1..n)
		{
			foreach_reverse (row; 0..n - 1)
			{
				long lo = 0;
				foreach (row2; 0..row)
				{
					lo += board[row2][0];
				}
				foreach (col2; 0..col)
				{
					lo += board[row][col2];
				}
				long hi = 0;
				foreach (col2; 0..col - 1)
				{
					hi += board[0][col2];
				}
				foreach (row2; 0..row + 1)
				{
					hi += board[row2][col - 1];
				}
				long span = hi - lo + 1;
				num[row][col] = temp;
				temp += span;

				board[row][col] = num[row][col];
				foreach (col2; 0..col)
				{
					board[row][col] -= board[row][col2];
				}
				foreach (row2; row + 1..n)
				{
					board[row][col] -= board[row2][col];
				}
			}
		}
		writefln !("%(%(%s %)\n%)") (board);
		stdout.flush ();

		auto q = readln.strip.to !(int);
		foreach (r; 0..q)
		{
			auto k = readln.strip.to !(long);
			int [2] [] ans;
			int row = n - 1;
			int col = n - 1;
			while (row + col > 0)
			{
				ans ~= [row + 1, col + 1];
				if (col > 0 && k < ways[row][col - 1])
				{
					col -= 1;
				}
				else
				{
					if (col > 0)
					{
						k -= ways[row][col - 1];
					}
					row -= 1;
				}
			}
			ans ~= [row + 1, col + 1];
			writefln !("%(%(%s %)\n%)") (ans.retro);
			stdout.flush ();
		}
	}
}


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)); }
T euDist2(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return c.sum; }
double euDist(T)(T[] a, T[] b) { return sqrt(cast(double)euDist2(a,b)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
double norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }
double dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }

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

		bool f(int h, int w)
		{
			auto b = a.dup;
			b[] /= h;
			bool has3;
			foreach (e; b)
			{
				if (e < 2) continue;
				if (e >= 3)
					has3 = true;
				if (w == 1 && !has3) continue;
				w -= e;
				if (w <= 0) return true;
			}
			return false;
		}
		ans[ti] = f(n, m);
		if (ans[ti]) continue;
		ans[ti] = f(m, n);
	}

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

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

bool go (long n, long m, long k, long [] a)
{
	if (n % 2 == 1 && a.maxElement < m * 3)
	{
		return false;
	}
	foreach (x; a)
	{
		if (x >= m * 2)
		{
			x /= m;
			n -= x;
		}
	}
	return n <= 0;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		long n, m, k;
		readf !(" %s %s %s") (n, m, k);
		readln;
		auto a = readln.splitter.map !(to !(long)).array;
		writeln (go (n, m, k, a) || go (m, n, k, a) ? "Yes" : "No");
	}
}

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

const bool dbg = true;
void DBG(alias x)() { static if (dbg) stderr.writefln("DBG: %s = %s", x.stringof, x); }
void MSG(in string x) { static if (dbg) stderr.writefln("MSG: %s", x); }

void solve() {
    long n, m; int k; scanf("%Ld %Ld %d\n", &n, &m, &k);
    auto a = readln.chomp.split(" ").map!(to!long).array;
    bool ok(long x, long y) {
        long sum = 0;
        auto b = a.map!((c) => c / x).filter!((c) => c >= 2).array.sort!"a > b".array;
        int z = cast(int)b.length;
        auto sb = new long[z+1];
        for (int i = 0; i < z; i++) {
            sb[i + 1] = sb[i] + b[i];
        }
        foreach (int u; 1 .. z + 1) {
            // use u colors
            if (y >= 2 * u && sb[u] >= y) return true;
        }
        return false;
    }
    (ok(n, m) || ok(m, n) ? "Yes" : "No").writeln;
}

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

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

long M, N;
int K;
long[] A;

bool check(long m, long n) {
  long sum;
  bool all2 = true;
  foreach (k; 0 .. K) {
    const num = A[k] / n;
    if (num >= 2) {
      sum += num;
      all2 = all2 && (num == 2);
    }
  }
  if (m % 2 != 0 && all2) {
    return false;
  }
  if (sum >= m) {
    return true;
  }
  return false;
}

bool solve() {
  if (check(M, N)) return true;
  if (check(N, M)) return true;
  return false;
}

void main() {
  try {
    for (; ; ) {
      const numCases = readInt;
      foreach (caseId; 0 .. numCases) {
        M = readLong;
        N = readLong;
        K = readInt;
        A = new long[K];
        foreach (k; 0 .. K) {
          A[k] = readLong;
        }

        const ans = solve;
        writeln(ans ? "Yes" : "No");
      }
    }
  } catch (EOFException e) {
  }
}

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

const bool dbg = true;
void DBG(alias x)() { static if (dbg) stderr.writefln("DBG: %s = %s", x.stringof, x); }
void MSG(in string x) { static if (dbg) stderr.writefln("MSG: %s", x); }

void solve() {
    long n, m, k; scanf("%Ld %Ld %Ld\n", &n, &m, &k);
    auto a = readln.chomp.split(" ").map!(to!long).array;
    bool ok(long x, long y) {
        long sum = 0;
        auto b = a.map!((c) => c / x).map!((c) => c < 2 ? 0 : c).array;
        foreach (int i; 0 .. cast(int)k) {
            sum += b[i];
        }
        return sum >= y && !(b.all!((c) => c == 2) && y % 2 == 1);
    }
    (ok(n, m) || ok(m, n) ? "Yes" : "No").writeln;
}

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

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

long M, N;
int K;
long[] A;

bool check(long m, long n) {
  long sum;
  bool all2 = true;
  foreach (k; 0 .. K) {
    const num = A[k] / n;
    if (num >= 2) {
      sum += num;
      all2 = all2 && (num == 2);
    }
  }
  if (sum >= m + 2) {
    return true;
  }
  if (sum == m + 1 && !all2) {
    return true;
  }
  if (sum == m) {
    return true;
  }
  return false;
}

bool solve() {
  if (check(M, N)) return true;
  if (check(N, M)) return true;
  return false;
}

void main() {
  try {
    for (; ; ) {
      const numCases = readInt;
      foreach (caseId; 0 .. numCases) {
        M = readLong;
        N = readLong;
        K = readInt;
        A = new long[K];
        foreach (k; 0 .. K) {
          A[k] = readLong;
        }

        const ans = solve;
        writeln(ans ? "Yes" : "No");
      }
    }
  } catch (EOFException e) {
  }
}

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

long M, N;
int K;
long[] A;

bool check(long m, long n) {
  long sum;
  bool all2 = true;
  foreach (k; 0 .. K) {
    const num = A[k] / n;
    if (num >= 2) {
      sum += num;
    }
    all2 = all2 && (num == 2);
  }
  if (sum >= m + 2) {
    return true;
  }
  if (sum == m + 1 && !all2) {
    return true;
  }
  if (sum == m) {
    return true;
  }
  return false;
}

bool solve() {
  if (check(M, N)) return true;
  if (check(N, M)) return true;
  return false;
}

void main() {
  try {
    for (; ; ) {
      const numCases = readInt;
      foreach (caseId; 0 .. numCases) {
        M = readLong;
        N = readLong;
        K = readInt;
        A = new long[K];
        foreach (k; 0 .. K) {
          A[k] = readLong;
        }

        const ans = solve;
        writeln(ans ? "Yes" : "No");
      }
    }
  } catch (EOFException e) {
  }
}


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

void main() {
    auto N = readln.chomp.to!int;
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto L = new Tuple!(int, int)[](N);
    auto R = new Tuple!(int, int)[](N);
    auto T = new Tuple!(int, int)[](N);
    auto B = new Tuple!(int, int)[](N);
    auto LRTB = new int[][](N);
    foreach (i; 0..N) {
        s = readln.split.map!(to!int);
        L[i] = tuple(min(s[0], s[2]), i);
        R[i] = tuple(max(s[0], s[2]), i);
        T[i] = tuple(min(s[1], s[3]), i);
        B[i] = tuple(max(s[1], s[3]), i);
        LRTB[i] = [L[i][0], R[i][0], T[i][0], B[i][0]];
    }
    auto C = readln.split.map!(to!int).array;

    auto A = new int[][](N, 4);

    L.sort();
    R.sort();
    T.sort();
    B.sort();
    foreach (i; 0..N) A[i][0] = L.assumeSorted.lowerBound(tuple(LRTB[i][1], -1)).length;
    foreach (i; 0..N) A[i][1] = R.assumeSorted.upperBound(tuple(LRTB[i][0], 1 << 29)).length;
    foreach (i; 0..N) A[i][2] = T.assumeSorted.lowerBound(tuple(LRTB[i][3], -1)).length;
    foreach (i; 0..N) A[i][3] = B.assumeSorted.upperBound(tuple(LRTB[i][2], 1 << 29)).length;

    foreach (i; 0..N) {
        if (LRTB[i][0] < LRTB[i][1]) A[i][0] -= 1, A[i][1] -= 1;
        if (LRTB[i][2] < LRTB[i][3]) A[i][2] -= 1, A[i][3] -= 1;
        if (A[i] == C) {
            writeln(i + 1);
            return;
        }
    }

    writeln(-1);

}

// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

int d, n, m;

void main() {
    scan(d);
    scan(n, m);

    n = max(n, m);

    alias Sofa = Tuple!(int, "x1", int, "y1", int, "x2", int, "y2");

    auto xls = new int[](n + 10);
    auto xrs = new int[](n + 10);
    auto yts = new int[](n + 10);
    auto ybs = new int[](n + 10);
    auto ss = new Sofa[](d);

    int x1, x2, y1, y2;

    foreach (i ; 0 .. d) {
        scan(x1, y1, x2, y2);

        if (x1 == x2 && y1 > y2) {
            swap(y1, y2);
        }
        if (y1 == y2 && x1 > x2) {
            swap(x1, x2);
        }

        xls[x1]++;
        xrs[x2]++;
        yts[y1]++;
        ybs[y2]++;

        ss[i] = Sofa(x1, y1, x2, y2);
    }

    foreach (i ; 0 .. n + 5) {
        xls[i + 1] += xls[i];
        yts[i + 1] += yts[i];
    }

    foreach_reverse (i ; 1 .. n + 5) {
        xrs[i - 1] += xrs[i];
        ybs[i - 1] += ybs[i];
    }

    debug {
        writeln("xls:", xls);
        writeln("xrs:", xrs);
        writeln("yts:", yts);
        writeln("ybs:", ybs);
    }

    int cntl, cntr, cntt, cntb;
    scan(cntl, cntr, cntt, cntb);

    foreach (i ; 0 .. d) {
        int left = xls[ss[i].x2 - 1] - (ss[i].x1 != ss[i].x2);
        int right = xrs[ss[i].x1 + 1] - (ss[i].x1 != ss[i].x2);
        int top = yts[ss[i].y2 - 1] - (ss[i].y1 != ss[i].y2);
        int btm = ybs[ss[i].y1 + 1] - (ss[i].y1 != ss[i].y2);

        debug {
            writefln("%d %d %d %d", left, right, top, btm);
        }

        if (cntl == left && cntr == right && cntt == top && cntb == btm) {
            writeln(i + 1);
            return;
        }
    }

    writeln(-1);
}

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

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


import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
    foreach(_; 0 .. scan!int){
        int n = scan!int;
        long[] as = scan!long(n);

        bool[long] aset;
        foreach(a; as) aset[a] = 1;

        aset.length.print;
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;
		bool[long] set;
		foreach (e; a)
		{
			set[e] = true;
		}
		ans[ti] = cast(int)set.keys.length;
	}

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


/** CodeForces Problem 381.A (2)
 * ACM summer training contest (3)
 * Noein
 */

import std.stdio;

T mut(T)(in T inval) {
    import std.traits;

    Unqual!T new_val = inval;

    return new_val;
}

T imut(T)(in T inval) {
    immutable new_val = inval;

    return new_val;
}

void main() {
    auto n = 0.mut;

    auto deck = new uint[](1000);

    readf("%s\n", &n);
    //writeln(n);

    for(int i; i < n; ++i) {
        readf("%s ", &deck[i]);
    }
    //writeln(deck);

    auto sS = 0, sD = 0, pF = 0, pR = (n-1);

    auto turn = false;

    for( int i; i < n; ++i ) {
        ( turn ? sD : sS )
        += (deck[pF] > deck[pR]
        ? deck[pF++]
        : deck[pR--]);

        turn ^= true;
    }

    writeln(sS, " ", sD);
}


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

void main() {
  int n = readln().strip().to!int;
  long ans = 0;
  foreach(i; 0..n) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    ans += (x2 - x1 + 1) * (y2 - y1 + 1);
  }
  writeln(ans);
}

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

void main() {
    int n = readln.chomp.to!int;
    int ans = 0;
    foreach (i; 0..n) {
        int x1, y1, x2, y2;
        readf("%d %d %d %d\n", &x1, &y1, &x2, &y2);
        ans += (x2 - x1 + 1) * (y2 - y1 + 1);
    }

    ans.writeln;
}


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

void main(string[] args)
{
  debug stdin = File(args[1]);
  auto n = next!int;
  auto a = next!int(n);
  auto dist = new int[][](2, n);
  auto invAdj = new int[][](n);
  debug writeln(a);
  foreach(i, ai; a)
    {
      debug writeln(i, " ", ai, " ",  cast(int)i - ai);
      if (cast(int)i - ai >= 0)
        invAdj[i - ai] ~= cast(int)i;
      if (cast(int)i + ai < n)
        invAdj[i + ai] ~= cast(int)i;
    }
  foreach(p; 0 .. 2)
    {
      dist[p][] = -1;
      auto visited = new bool[](n);
      auto queue = DList!int();
      foreach(i, ai; a)
        {
          if (ai % 2 == p)
            {
              visited[i] = true;
              queue.insertBack(cast(int)i);
              dist[p][i] = 0;
            }
        }
      while(!queue.empty)
        {
          auto node = queue.front;
          queue.removeFront;
          foreach(nei; invAdj[node])
            {
              if (!visited[nei])
                {
                  visited[nei] = true;
                  dist[p][nei] = dist[p][node] + 1;
                  queue.insertBack(nei);
                }
            }
        }
    }
  foreach(i, ai; a)
    write(dist[(ai + 1) % 2][i], " ");
  writeln;
}

// INPUT

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

string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (stdin.eof)
        currChunk = null;
      else
        currChunk = stdin.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; stdin.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

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

immutable int INF = 1 << 29;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto B = A.map!(a => a & 1).array;

    auto G = new int[][](N);

    DList!(Tuple!(int, int)) que;
    auto ans = new int[](N);
    ans[] = -1;

    foreach (i; 0..N) {
        int j = i + A[i];
        int k = i - A[i];
        if (j < N) {
            G[j] ~= i;
        }
        if (k >= 0) {
            G[k] ~= i;
        }
        if (j < N && (B[i] ^ B[j])) {
            que.insertBack(tuple(i, 2));
            ans[i] = 1;
        } else if (k >= 0 && (B[i] ^ B[k])) {
            que.insertBack(tuple(i, 2));
            ans[i] = 1;
        }
    }

    while (!que.empty) {
        auto t = que.front;
        auto i = t[0];
        auto d = t[1];
        que.removeFront;
        foreach (j; G[i]) {
            if (ans[j] == -1) {
                ans[j] = d;
                que.insertBack(tuple(j, d + 1));
            }
        }
    }

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

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto n = RD!int;
	auto a = RDA!int;
	auto ans = new int[](n);
	ans[] = int.max;
	auto edges = new int[][](n);
	foreach (i; 0..n)
	{
		auto l = i - a[i];
		auto r = i + a[i];
		int u = -1, v = -1;
		if (l >= 0)
		{
			if (a[i] % 2 != a[l] % 2)
				ans[i] = 1;
			else
				u = l;
		}
		if (r < n)
		{
			if (a[i] % 2 != a[r] % 2)
				ans[i] = 1;
			else
				v = r;
		}
		if (ans[i] != 1)
		{
			if (u != -1)
				edges[u] ~= i;
			if (v != -1)
				edges[v] ~= i;
			if (u == -1 && v == -1)
				ans[i] = -1;
		}
	}

	int[][] open;
	foreach (i; 0..n)
	{
		if (ans[i] == 1)
		{
			open ~= [i, 1];
		}
	}

	while (!open.empty)
	{
		auto nd = open.front; open.popFront;
		auto from = nd[0];
		auto c = nd[1];
		foreach (to; edges[from])
		{
			if (c+1 < ans[to])
			{
				ans[to] = c + 1;
				open ~= [to, c + 1];
			}
		}
	}

	foreach (ref e; ans)
		if (e == int.max)
			e = -1;

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

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto n = RD!int;
	auto a = RDA!int;
	auto ans = new int[](n);
	ans[] = int.max;
	auto edges = new int[][](n);
	foreach (i; 0..n)
	{
		auto l = i - a[i];
		auto r = i + a[i];
		int u = -1, v = -1;
		if (l >= 0)
		{
			if (a[i] % 2 != a[l] % 2)
				ans[i] = 1;
			else
				u = l;
		}
		if (r < n)
		{
			if (a[i] % 2 != a[r] % 2)
				ans[i] = 1;
			else
				v = r;
		}
		if (ans[i] != 1)
		{
			if (u != -1)
				edges[u] ~= i;
			if (v != -1)
				edges[v] ~= i;
			if (u == -1 && v == -1)
				ans[i] = -1;
		}
	}

	int[][] open;
	foreach (i; 0..n)
	{
		if (ans[i] == 1)
		{
			open ~= [i, 1];
		}
	}

	while (!open.empty)
	{
		auto nd = open.front; open.popFront;
		auto from = nd[0];
		auto c = nd[1];
		foreach (to; edges[from])
		{
			if (c+1 < ans[to])
			{
				ans[to] = c + 1;
				open ~= [to, c + 1];
			}
		}
	}

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


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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto N = readln.chomp.to!long;
        writeln((N+1)/2-1);
    }
}

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

void main ()
{
	int tests;
	readf !(" %s") (tests);
	foreach (test; 0..tests)
	{
		int n;
		readf !(" %s") (n);
		writeln ((n - 1) / 2);
	}
}

import std.stdio;
int main()
{
	int t=0;
	readf(" %d", &t);
	for (int i=0; i<t; i++)
	{
		int a=0;
		readf(" %d", &a);
		if (a==1)
		{
			writeln(0);
		}
		else
		{
			if (a%2==0)
			{
				writeln(a/2-1);
			}
			else
			{
				writeln(a/2);
			}
		}
	}
	return 0;
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD;
		if (n <= 2) continue;

		auto half = n / 2 - (n % 2 == 0 ? 1 : 0);
		ans[ti] = half;
	}

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


import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

void main() {
    int N; scanf("%d\n", &N);
    auto T = new int[][N];
    foreach (i; 0 .. N - 1) {
        int u, v; scanf("%d %d\n", &u, &v);
        u--; v--;
        T[u] ~= v;
        T[v] ~= u;
    }
    auto I = readln.chomp.split(" ").map!(to!int).array;
    auto G = readln.chomp.split(" ").map!(to!int).array;

    auto used = new bool[N];
    int[] ans;
    void dfs(int v, bool a, bool b) {
        if (a) I[v] = !I[v];
        used[v] = true;
        if (I[v] != G[v]) { ans ~= v + 1; a = !a;}
        foreach (next; T[v]) {
            if (used[next]) continue;
            dfs(next, b, a);
        }
    }
    dfs(0, false, false);
    writefln("%d", ans.length);
    writefln("%(%s\n%)", ans);
}

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

immutable int NA = -1;

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

		auto p = new int [n];
		foreach (ref x; p)
		{
			readf (" %s", &x);
		}

		auto q = new int [n];
		foreach (ref x; q)
		{
			readf (" %s", &x);
		}

		int [] ans;

		void recur (int v, int w, int z0, int z1)
		{
			if (z0 ^ (p[v] != q[v]))
			{
				ans ~= v + 1;
				z0 ^= 1;
			}

			foreach (u; a[v])
			{
				if (u != w)
				{
					recur (u, v, z1, z0);
				}
			}
		}

		recur (0, NA, 0, 0);

		writeln (ans.length);
		writefln ("%(%s\n%)", ans);
	}
}

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

struct node {
    bool visited;
    int[] child;
}

__gshared {
    node[] tree;
    int[] diff;
    int answer;
    int[] answerlist;
}

void dfs(int v, bool iseven, bool evenpar, bool oddpar) {
    tree[v].visited = true;
    if (iseven) {
        if (diff[v] != evenpar) {
            answer += 1;
            answerlist ~= v;
            evenpar = !evenpar;
        }
    }
    else {
        if (diff[v] != oddpar) {
            answer += 1;
            answerlist ~= v;
            oddpar = !oddpar;
        }
    }
    foreach (i; tree[v].child) {
        if (!tree[i].visited) dfs(i, !iseven, evenpar, oddpar);
    }
}

int main() {
    debug stdin = File("in.txt", "r");

    int n;
    readf(" %s\n", &n);
    tree.length = n + 1;
    diff.length = n + 1;
    foreach (i; 1 .. n) {
        int u, v;
        readf(" %s %s\n", &u, &v);
        tree[u].child ~= v;
        tree[v].child ~= u;
    }
    foreach (i; 1 .. n + 1) {
        readf(" %s", &diff[i]);
    }
    readf("\n");
    foreach (i; 1 .. n + 1) {
        int b;
        readf(" %s", &b);
        diff[i] = diff[i] ^ b;
    }
    dfs(1, true, false, false);
    writeln(answer);
    foreach (i; answerlist) writeln(i);

    return 0;
}

import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

void main() {
    int N; scanf("%d\n", &N);
    auto T = new int[][N];
    foreach (i; 0 .. N - 1) {
        int u, v; scanf("%d %d\n", &u, &v);
        u--; v--;
        T[u] ~= v;
        T[v] ~= u;
    }
    auto I = readln.chomp.split(" ").map!(to!int).array;
    auto G = readln.chomp.split(" ").map!(to!int).array;

    auto used = new bool[N];
    int[] ans;
    void dfs(int v, bool a, bool b) {
        if (a) { I[v] = !I[v]; }
        used[v] = true;
        foreach (next; T[v]) {
            if (used[next]) continue;
            if (I[next] == G[next]) {
                dfs(next, b, a);
            } else {
                ans ~= next + 1;
                dfs(next, !b, a);
            }
        }
    }
    dfs(0, I[0] != G[0], false);
    writefln("%d", ans.length);
    writefln("%(%s\n%)", ans);
}

import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

void main() {
    int N; scanf("%d\n", &N);
    auto T = new int[][N];
    foreach (i; 0 .. N - 1) {
        int u, v; scanf("%d %d\n", &u, &v);
        u--; v--;
        T[u] ~= v;
        T[v] ~= u;
    }
    auto I = readln.chomp.split(" ").map!(to!int).array;
    auto G = readln.chomp.split(" ").map!(to!int).array;

    auto used = new bool[N];
    int[] ans;
    void dfs(int v, bool a, bool b) {
        foreach (next; T[v]) {
            if (used[next]) continue;
            used[next] = true;
            if (I[next] == G[next]) {
                dfs(next, b, a);
            } else {
                ans ~= next + 1;
                I[next] = !I[next];
                dfs(next, !b, a);
            }
        }
    }
    used[0] = true;
    dfs(0, I[0] != G[0], false);
    writefln("%d", ans.length);
    writefln("%(%s\n%)", ans);
}

import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

void main() {
    int N; scanf("%d\n", &N);
    auto T = new int[][N];
    foreach (i; 0 .. N - 1) {
        int u, v; scanf("%d %d\n", &u, &v);
        u--; v--;
        T[u] ~= v;
        T[v] ~= u;
    }
    auto I = readln.chomp.split(" ").map!(to!int).array;
    auto G = readln.chomp.split(" ").map!(to!int).array;

    auto used = new bool[N];
    int[] ans;
    void dfs(int v, bool a, bool b) {
        foreach (next; T[v]) {
            if (used[next]) continue;
            used[next] = true;
            if (I[next] == G[next]) {
                dfs(next, b, a);
            } else {
                ans ~= next + 1;
                I[next] = !I[next];
                dfs(next, !b, a);
            }
        }
    }
    used[0] = true;
    if (I[0] != G[0]) {
        ans ~= 1;
        I[0] = !I[0];
        dfs(0, true, false);
    } else {
        dfs(0, false, false);
    }
    writefln("%d", ans.length);
    writefln("%(%s\n%)", ans);
}

import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

void main() {
    int N; scanf("%d\n", &N);
    auto T = new int[][N];
    foreach (i; 0 .. N - 1) {
        int u, v; scanf("%d %d\n", &u, &v);
        u--; v--;
        T[u] ~= v;
        T[v] ~= u;
    }
    auto I = readln.chomp.split(" ").map!(to!int).array;
    auto G = readln.chomp.split(" ").map!(to!int).array;

    auto used = new bool[N];
    int[] ans;
    void dfs(int v, bool a, bool b) {
        if (a) { I[v] = !I[v]; }
        foreach (next; T[v]) {
            if (used[next]) continue;
            used[next] = true;
            if (I[next] == G[next]) {
                dfs(next, b, a);
            } else {
                ans ~= next + 1;
                dfs(next, !b, a);
            }
        }
    }
    used[0] = true;
    dfs(0, I[0] != G[0], false);
    writefln("%d", ans.length);
    writefln("%(%s\n%)", ans);
}

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

struct node {
    int[] child;
}

__gshared {
    node[] tree;
    int[] diff;
    int answer;
    int[] answerlist;
}

void dfs(int v, bool iseven, bool evenpar, bool oddpar) {
    if (iseven) {
        if (diff[v] != evenpar) {
            answer += 1;
            answerlist ~= v;
            evenpar = !evenpar;
        }
    }
    else {
        if (diff[v] != oddpar) {
            answer += 1;
            answerlist ~= v;
            oddpar = !oddpar;
        }
    }
    foreach (i; tree[v].child) dfs(i, !iseven, evenpar, oddpar);
}

int main() {
    debug stdin = File("in.txt", "r");

    int n;
    readf(" %s\n", &n);
    tree.length = n + 1;
    diff.length = n + 1;
    foreach (i; 1 .. n) {
        int u, v;
        readf(" %s %s\n", &u, &v);
        int p = min(u, v);
        int c = max(u, v);
        tree[p].child ~= c;
    }
    foreach (i; 1 .. n + 1) {
        readf(" %s", &diff[i]);
    }
    readf("\n");
    foreach (i; 1 .. n + 1) {
        int b;
        readf(" %s", &b);
        diff[i] = diff[i] ^ b;
    }
    dfs(1, true, false, false);
    writeln(answer);
    foreach (i; answerlist) writeln(i);

    return 0;
}

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

struct node {
    int[] child;
}

__gshared node[] tree;
__gshared int[] diff;
__gshared int answer;
__gshared int[] answerlist;

void dfs(int v, bool iseven, bool evenpar, bool oddpar) {
    if (iseven) {
        if (diff[v] != evenpar) {
            answer += 1;
            answerlist ~= v;
            evenpar = !evenpar;
        }
    }
    else {
        if (diff[v] != oddpar) {
            answer += 1;
            answerlist ~= v;
            oddpar = !oddpar;
        }
    }
    foreach (i; tree[v].child) dfs(i, !iseven, evenpar, oddpar);
}

int main() {
    debug stdin = File("in.txt", "r");

    int n;
    readf(" %s\n", &n);
    tree.length = n + 1;
    diff.length = n + 1;
    foreach (i; 1 .. n) {
        int u, v;
        readf(" %s %s\n", &u, &v);
        int p = min(u, v);
        int c = max(u, v);
        tree[p].child ~= c;
    }
    foreach (i; 1 .. n + 1) {
        readf(" %s", &diff[i]);
    }
    readf("\n");
    foreach (i; 1 .. n + 1) {
        int b;
        readf(" %s", &b);
        diff[i] = diff[i] ^ b;
    }
    dfs(1, true, false, false);
    writeln(answer);
    foreach (i; answerlist) writeln(i);

    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;
import core.bitop;

immutable int NA = -1;

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

		auto p = new int [n];
		foreach (ref x; p)
		{
			readf (" %s", &x);
		}

		auto q = new int [n];
		foreach (ref x; q)
		{
			readf (" %s", &x);
		}

		int [] ans;

		void recur (int v, int w, int z)
		{
			if (z ^ (p[v] != q[v]))
			{
				ans ~= v + 1;
				z ^= 1;
			}

			foreach (u; a[v])
			{
				if (u != w)
				{
					recur (u, v, z);
				}
			}
		}

		recur (0, NA, 0);

		writeln (ans.length);
		writefln ("%(%s\n%)", ans);
	}
}


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 s = RD!string;

		long cnt0, cnt1;
		foreach (i; 0..n)
		{
			if (s[i] == '<')
				++cnt0;
			else if (s[i] == '>')
				++cnt1;
			if (s[(n+i-1)%n] == '-' || s[i] == '-')
				++ans[ti];
		}

		if (cnt0 == 0 || cnt1 == 0)
			ans[ti] = n;
	}

	foreach (e; ans)
		writeln(e);

	stdout.flush;
	debug readln;
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto s = readln.strip;
		if (s.all !(q{a != '>'}) || s.all !(q{a != '<'}))
		{
			writeln (n);
			continue;
		}
		int res = n;
		foreach (i; 0..n)
		{
			if (s[i] != '-' && s[(i + 1) % n] != '-')
			{
				res -= 1;
			}
		}
		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)
	{
		auto n = readln.strip.to !(int);
		auto s = readln.strip;
		int res = n;
		if (s.all !(q{a == '>'}) || s.all !(q{a == '<'}))
		{
			writeln (n);
			continue;
		}
		foreach (i; 0..n)
		{
			if (s[i] != '-' && s[(i + 1) % n] != '-')
			{
				res -= 1;
			}
		}
		writeln (res);
	}
}

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

string FMT_F = "%.10f";

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

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

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

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { 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 s = RD!string;

		ans[ti] = n;
		foreach (i; 0..n)
		{
			if (s[(n+i-1)%n] == '<' && s[i] == '>')
				--ans[ti];
			else if (s[(n+i-1)%n] == '>' && s[i] == '<')
				--ans[ti];
		}

	}

	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 s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto K = s[2];
    auto A = readln.split.map!(to!long).array;
    auto X = M.iota.map!(_ => readln.split.map!(to!int).array).array;

    A = A.sort().take(K).array;
    auto B = new long[](K+1);
    foreach (i; 0..K) B[i+1] = B[i] + A[i];

    auto dp = new long[](K+1);
    dp[] = 1L << 59;
    dp[0] = 0;

    foreach (i; 0..K) {
        dp[i+1] = min(dp[i+1], dp[i] + A[i]);
        foreach (x; X) {
            if (i + x[0] <= K) {
                dp[i+x[0]] = min(dp[i+x[0]], dp[i] + B[i+x[0]] - B[i+x[1]]);
            }
        }
    }

    dp[K].writeln;
}

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(){

	long n = read!long;
	long m = read!long;
	int k = read!int;
	long[] as = read!long(n);
	log("as:", as);

	as.sort();
	as = as[0 .. k];
	log("as:", as);

	int[] qs = new int[](k + 10);
	foreach(i; 0 .. m){
		int x = read!int;
		int y = read!int;
		if(x > k) continue;
		if(qs[x] < y) qs[x] = y;
	}
	log("qs:", qs);

	long[] us = new long[](k + 10);
	us[0] = 0;
	foreach(i; 1 .. k + 1){
		foreach(j; 0 .. i){
			int y = qs[i - j];
			long u = us[j] + as[j .. j + y].sum;
			if(u > us[i]) us[i] = u;
			log("i:", i, "j:", j, "u:", u);
		}
	}
	log("us:", us);

	(as.sum - us[k]).writeln;

}