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

void main() {
  string s = readln.strip;
  string t = readln.strip;
  int n = to!(int)(s.length);
  int m = to!(int)(t.length);
  auto to = new int[n];
  to[] = -1;
  for (int i = 0; i < n; i++) {
    int j = i, count = 0;
    while (j < n && count < m) {
      count += s[j] == t[count];
      j++;
    }
    if (count == m) {
      to[i] = j;
    }
  }
  auto f = new int[][](n + 1, n + 1);
  foreach (ref g; f) {
    g[] = int.min;
  }
  for (int i = 0; i <= n; i++) {
    f[i][0] = 0;
  }
  for (int j = 0; j <= n; j++) {
    for (int i = 0; i < n; i++) {
      if (f[i][j] != int.min) {
        if (j + 1 <= n) {
          f[i + 1][j + 1] = max(f[i + 1][j + 1], f[i][j]);
        }
        f[i + 1][j] = max(f[i + 1][j], f[i][j]);
        if (to[i] != -1) {
          f[to[i]][j + to[i] - i - m] = max(f[to[i]][j + to[i] - i - m], f[i][j] + 1);
        }
      }
    }
  }
  auto ans = new int[n + 1];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      ans[j] = max(ans[j], f[i][j]);
    }
  }
  writefln("%(%s %)", ans);
}

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 M, N;
string S, T;

void main(string[] args) {
	try {
	for (; ; ) {
		S = readToken;
		T = readToken;

		M = S.length;
		N = T.length;
		int[][] dp = new int[][](M + 1, M + 1);
		foreach (i; 0 .. M + 1) {
			dp[i][] = -1;
		}
		dp[0][0] = 0;
		foreach (i; 0 .. M)	{
			{
				bool ok = true;
				int ii = i;
				foreach (j; 0 .. N) {
					for (; ii < M && S[ii] != T[j]; ++ii) {}
					if (ii < M) {
						++ii;
					} else {
						ok = false;
						break;
					}
				}
				if (ok) {
					const dk = (ii - i) - N;
					foreach (k; 0 .. M + 1) if (k + dk <= M) {
						if (dp[i][k] >= 0) {
							chmax(dp[ii][k + dk], dp[i][k] + 1);
						}
					}
				}
			}
			foreach (k; 0 .. M + 1) {
				if (dp[i][k] >= 0) {
					chmax(dp[i + 1][k], dp[i][k]);
				}
			}
			foreach (k; 0 .. M + 1) if (k + 1 <= M) {
				if (dp[i][k] >= 0) {
					chmax(dp[i + 1][k + 1], dp[i][k]);
				}
			}
		}
		writeln(dp[M].to!string.removechars("[],"));
	}
	} catch (EOFException) {}
}

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

void main() {
  string s = readln.strip;
  string t = readln.strip;
  int n = to!(int)(s.length);
  int m = to!(int)(t.length);
  auto to = new int[n];
  to[] = -1;
  for (int i = 0; i < n; i++) {
    int j = i, count = 0;
    while (j < n && count < m) {
      count += s[j] == t[count];
      j++;
    }
    if (count == m) {
      to[i] = j;
    }
  }
  auto f = new int[][](n + 1, n + 1);
  foreach (ref g; f) {
    g[] = int.min;
  }
  for (int i = 0; i <= n; i++) {
    f[i][0] = 0;
  }
  for (int j = 0; j <= n; j++) {
    for (int i = 0; i < n; i++) {
      if (f[i][j] != int.min) {
        if (j + 1 <= n) {
          f[i + 1][j + 1] = max(f[i + 1][j + 1], f[i][j]);
        }
        if (to[i] != -1) {
          f[to[i]][j + to[i] - i - m] = max(f[to[i]][j + to[i] - i - m], f[i][j] + 1);
        }
      }
    }
  }
  auto ans = new int[n + 1];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      ans[j] = max(ans[j], f[i][j]);
    }
  }
  writefln("%(%s %)", ans);
}

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

void main() {
  string s = readln.strip;
  string t = readln.strip;
  int n = to!(int)(s.length);
  int m = to!(int)(t.length);
  auto to = new int[n];
  to[] = -1;
  for (int i = 0; i < n; i++) {
    int j = i, count = 0;
    while (j < n && count < m) {
      count += s[j] == t[count];
      j++;
    }
    if (count == m) {
      to[i] = j;
    }
  }
  auto f = new int[][](n + 1, n + 1);
  foreach (ref g; f) {
    g[] = int.min;
  }
  f[0][0] = 0;
  for (int j = 0; j <= n; j++) {
    for (int i = 0; i < n; i++) {
      if (f[i][j] != int.min) {
        if (i + 1 <= n && j + 1 <= n) {
          f[i + 1][j + 1] = max(f[i + 1][j + 1], f[i][j]);
        }
        if (to[i] != -1) {
          assert(j + to[i] - i - m <= n);
          f[to[i]][j + to[i] - i - m] = max(f[to[i]][j + to[i] - i - m], f[i][j] + 1);
        }
      }
    }
  }
  auto ans = new int[n + 1];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      ans[j] = max(ans[j], f[i][j]);
    }
  }
  writefln("%(%s %)", ans);
}


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() {
  enum LIM = 1000;
  auto isnp = new bool[LIM];
  foreach (p; 2 .. LIM) {
    if (!isnp[p]) {
      for (int n = 2 * p; n < LIM; n += p) {
        isnp[n] = true;
      }
    }
  }
  auto dp = new int[LIM];
  dp[] = -1;
  dp[0] = 0;
  foreach (x; 0 .. LIM) {
    if (dp[x] >= 0) {
      foreach (n; 2 .. LIM - x) {
        if (isnp[n]) {
          chmax(dp[x + n], dp[x] + 1);
        }
      }
    }
  }
  debug {
    writeln(dp[0 .. 100]);
  }

  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const N = readInt();
        int ans;
        if (N < LIM) {
          ans = dp[N];
        } else {
          ans = N / 4;
          if (N % 2 != 0) {
            --ans;
          }
        }
        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 Q = readln.chomp.to!int;
    long ans;
    while (Q--) {
        auto n = readln.chomp.to!long;
        if (n % 4 == 0) {
            writeln(n / 4);
        } else if (n % 4 == 1) {
            if (n <= 5) writeln(-1);
            else writeln((n-9)/4 + 1);
        } else if (n % 4 == 2) {
            if (n == 2) writeln(-1);
            else writeln((n-6)/4 + 1);
        } else {
            if (n <= 11) writeln(-1);
            else writeln((n-15)/4 + 2);
        }
    }
}

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() {
    const long MAX = 10^^9 + 1;
    long[] primes;
    auto table = new bool[](10^^5);
    table.fill(true);
    table[0] = table[1] = false;
    foreach (i; 2..10^^5) {
        if (table[i]) {
            for (int j = i+i; j < 10^^5; j += i) {
                table[j] = false;
            }
        }
    }

    for (long i = 2; i * i < MAX; ++i) {
        if (table[i.to!int]) primes ~= i;
    }

    auto Q = readln.chomp.to!int;
    while (Q--) {
        auto n = readln.chomp.to!long;
        auto nn = n;
        long[] hoge;
        foreach (p; primes) {
            while (n % p == 0) {
                n /= p;
                hoge ~= p;
            }
        }
        if (n > 1) hoge ~= n;
        hoge.sort();
        if (hoge.length <= 1) writeln(-1);
        else writeln(nn / (hoge[0] * hoge[1]));
    }
}

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() {
    const long MAX = 10^^9 + 1;
    long[] primes;
    auto table = new bool[](10^^5);
    table.fill(true);
    table[0] = table[1] = false;
    foreach (i; 2..10^^5) {
        if (table[i]) {
            for (int j = i+i; j < 10^^5; j += i) {
                table[j] = false;
            }
        }
    }

    for (long i = 2; i * i < MAX; ++i) {
        if (table[i.to!int]) primes ~= i;
    }

    auto Q = readln.chomp.to!int;
    while (Q--) {
        auto n = readln.chomp.to!long;
        auto nn = n;
        long[] hoge;
        foreach (p; primes) {
            while (n % p == 0) {
                n /= p;
                hoge ~= p;
            }
        }
        hoge.sort();
        if (hoge.length <= 1) writeln(-1);
        else writeln(nn / (hoge[0] * hoge[1]));
    }
}


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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_t; 0..T) {
        auto N = readln.chomp.to!int;
        auto aa = readln.split.to!(int[]);
        int[] os, es;
        foreach (i, a; aa) {
            if (a%2 == 0) {
                es ~= i.to!int+1;
            } else {
                os ~= i.to!int+1;
            }
        }
        int cnt;
        while (cnt < N-1 && os.length > 1) {
            writeln(os[0], " ", os[1]);
            ++cnt;
            os = os[2..$];
        }
        while (cnt < N-1) {
            writeln(es[0], " ", es[1]);
            ++cnt;
            es = es[2..$];
        }
    }
}

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;
		int [2] cur;
		int [2] [] ans;
		foreach (int i, c; a[0..$ - 1])
		{
			if (cur[c & 1])
			{
				ans ~= [cur[c & 1], i + 1];
				cur[c & 1] = 0;
			}
			else
			{
				cur[c & 1] = i + 1;
			}
		}
		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;
	int[][] ans;
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA!int;

		debug writeln("n:", n);
		int cnt;
		int x = -1;
		foreach (i; 0..n*2)
		{
			if (cnt == n-1) break;
			if (a[i] % 2)
			{
				if (x == -1)
				{
					x = i;
				}
				else
				{
					ans ~= [x, i];
					x = -1;
					++cnt;
				}
			}
		}
		debug writeln("ti:", ti, " cnt:", cnt);
		x = -1;
		foreach (i; 0..n*2)
		{
			if (cnt == n-1) break;
			debug writeln("i:", i);
			if ((a[i] % 2) == 0)
			{
				if (x == -1)
				{
					x = i;
				}
				else
				{
					ans ~= [x, i];
					x = -1;
					++cnt;
				}
			}
		}
		debug writeln("ti:", ti, " cnt:", cnt);
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

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

		debug writeln("n:", n);
		int cnt;
		int x = -1;
		foreach (i; 0..n*2)
		{
			if (cnt == n-1) break;
			if (a[i] % 2)
			{
				if (x == -1)
				{
					x = a[i];
				}
				else
				{
					ans ~= [x, a[i]];
					x = -1;
					++cnt;
				}
			}
		}
		debug writeln("ti:", ti, " cnt:", cnt);
		x = -1;
		foreach (i; 0..n*2)
		{
			if (cnt == n-1) break;
			debug writeln("i:", i);
			if ((a[i] % 2) == 0)
			{
				if (x == -1)
				{
					x = a[i];
				}
				else
				{
					ans ~= [x, a[i]];
					x = -1;
					++cnt;
				}
			}
		}
		debug writeln("ti:", ti, " cnt:", cnt);
	}

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


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		auto x = readln.strip.to !(int);

		auto f = new int [4] [n + 1];
		f[0][0] = 0;
		foreach (i; 0..n)
		{
			f[i + 1][0] = f[i][].maxElement;
			f[i + 1][1] = f[i][0] + 1;
			if (i >= 1 &&
			    a[i] + a[i - 1] >= x * 2)
			{
				f[i + 1][2] = f[i][1] + 1;
				if (i >= 2 &&
				    a[i] + a[i - 1] + a[i - 2] >= x * 3)
				{
					f[i + 1][3] =
					    f[i][2..$].maxElement + 1;
				}
			}
		}
		f[n][].maxElement.writeln;
	}
}

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

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

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

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

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

        auto B = new long[N + 1];
        foreach (i; 0 .. N) {
          B[i + 1] = B[i] + (A[i] - X);
        }
        debug {
          writeln("B = ", B);
        }

        auto dp = new int[][](N + 2, 2);
        foreach (i; 0 .. N + 2) {
          dp[i][] = -1;
        }
        dp[0][0] = 0;
        foreach (i; 0 .. N + 2) foreach (s; 0 .. 2) if (dp[i][s] >= 0) {
          // cut
          if (i + 1 <= N + 1) {
            chmax(dp[i + 1][0], dp[i][s]);
          }
          if (i + 2 <= N + 1 && B[i] > B[i + 1]) {
            chmax(dp[i + 2][1], dp[i][s] + 1);
          }
          // 1
          if (i + 1 <= N + 1) {
            if (i == 0 || B[s ? (i - 2) : (i - 1)] <= B[i]) {
              chmax(dp[i + 1][0], dp[i][s] + 1);
            }
          }
          // 2
          if (i + 2 <= N + 1 && B[i] > B[i + 1]) {
            if (i == 0 || B[s ? (i - 2) : (i - 1)] <= B[i + 1]) {
              chmax(dp[i + 2][1], dp[i][s] + 2);
            }
          }
        }

        const ans = dp[$ - 1].maxElement;
        writeln(ans - 1);
      }
    }
  } 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)); }

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

        auto B = new long[N + 1];
        foreach (i; 0 .. N) {
          B[i + 1] = B[i] + (A[i] - X);
        }
        debug {
          writeln("B = ", B);
        }

        auto dp = new int[][](N + 2, 2);
        foreach (i; 0 .. N + 2) {
          dp[i][] = -1;
        }
        dp[0][0] = 0;
        foreach (i; 0 .. N + 2) foreach (s; 0 .. 2) if (dp[i][s] >= 0) {
          // cut
          if (i + 1 <= N + 1) {
            chmax(dp[i + 1][0], dp[i][s]);
          }
          if (i + 2 <= N + 1 && B[i] > B[i + 1]) {
            chmax(dp[i + 2][0], dp[i][s] + 1);
          }
          // 1
          if (i + 1 <= N + 1) {
            if (i == 0 || B[s ? (i - 2) : (i - 1)] <= B[i]) {
              chmax(dp[i + 1][0], dp[i][s] + 1);
            }
          }
          // 2
          if (i + 2 <= N + 1 && B[i] > B[i + 1]) {
            if (i == 0 || B[s ? (i - 2) : (i - 1)] <= B[i + 1]) {
              chmax(dp[i + 2][1], dp[i][s] + 2);
            }
          }
        }

        const ans = dp[$ - 1].maxElement;
        writeln(ans - 1);
      }
    }
  } 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)); }

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

        auto B = new long[N + 1];
        foreach (i; 0 .. N) {
          B[i + 1] = B[i] + (A[i] - X);
        }
        debug {
          writeln("B = ", B);
        }

        auto dp = new int[][](N + 2, 2);
        foreach (i; 0 .. N + 2) {
          dp[i][] = -1;
        }
        dp[0][0] = 0;
        foreach (i; 0 .. N + 2) foreach (s; 0 .. 2) if (dp[i][s] >= 0) {
          // cut
          if (i + 1 <= N + 1) {
            chmax(dp[i + 1][0], dp[i][s]);
          }
          // 1
          if (i + 1 <= N + 1) {
            if (i == 0 || B[s ? (i - 2) : (i - 1)] <= B[i]) {
              chmax(dp[i + 1][0], dp[i][s] + 1);
            }
          }
          // 2
          if (i + 2 <= N + 1 && B[i] > B[i + 1]) {
            if (i == 0 || B[s ? (i - 2) : (i - 1)] <= B[i + 1]) {
              chmax(dp[i + 2][1], dp[i][s] + 2);
            }
          }
        }

        const ans = dp[$ - 1].maxElement;
        writeln(ans - 1);
      }
    }
  } catch (EOFException e) {
  }
}

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;
		auto x = readln.strip.to !(int);

		auto f = new int [4] [n + 1];
		f[0][0] = 0;
		foreach (i; 0..n)
		{
			f[i + 1][0] = f[i][].maxElement;
			f[i + 1][1] = f[i][0] + 1;
			if (i >= 1 &&
			    a[i] + a[i - 1] >= x * 2)
			{
				f[i + 1][2] = f[i][1] + 1;
				if (i >= 2 &&
				    a[i] + a[i - 1] + a[i - 2] >= x * 3)
				{
					f[i + 1][3] = f[i][2] + 1;
				}
			}
		}
		f[n][].maxElement.writeln;
	}
}


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

struct IO {
        string[] tk;
        string readString() {
                while (tk.empty)
                        tk = readln.split;
                auto tkt = tk.front;
                tk.popFront;
                return tkt;
        }
        int readInt() {
                return readString.to!int;
        }
        double readDouble() {
                return readString.to!double;
        }
}

void main() {
        IO cin;
        int t = 1;
        t = cin.readInt;
        while (t--) {
                int n = cin.readInt;
                int k = cin.readInt;
                if (k == 0) {
                        if (n % 2 == 0) writeln(0);
                        else writeln(1);
                } else {
                        if (k > n) writeln(k - n);
                        else {
                                if (n % 2 == 0 && k % 2 == 1) writeln(1);
                                else if (n % 2 == 1 && k % 2 == 0) writeln(1);
                                else writeln(0);
                        }
                }
        }
}

// unihernandez22
// https://codeforces.com/contest/1401/problem/A
// implementation

import std.stdio;

void main() {
  int n, k, t;
  scanf("%d", &t);
  foreach (_; 0 .. t) {
    scanf("%d %d", &n, &k);
    if (k <= n) {
      if (n%2 == k%2) {
        writeln("0");
      } else {
        writeln("1");
      }
    } else
      writeln(k - n);
  }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		writeln (k > n ? k - n : ((n ^ k) & 1));
	}
}

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 k = RD!int;
		if (k >= n)
		{
			ans[ti] = k - n;
		}
		else
		{
			n -= k;
			ans[ti] = n % 2;
		}
	}

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

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

struct IO {
        string[] tk;
        string readString() {
                while (tk.empty)
                        tk = readln.split;
                auto tkt = tk.front;
                tk.popFront;
                return tkt;
        }
        int readInt() {
                return readString.to!int;
        }
        double readDouble() {
                return readString.to!double;
        }
}

void main() {
        IO cin;
        int t = 1;
        t = cin.readInt;
        while (t--) {
                int n = cin.readInt;
                int k = cin.readInt;
                if (n > k) {
                        if (n % 2 == 0) writeln(0);
                        else writeln(1);
                } else {
                        writeln(k - n);
                }
        }
}


module acmd;

import std.stdio;
import std.conv;

int main () {
   version (offline_judje) {
      stdin.reopen ("input.txt", "rt");
   }
   int n;
   readf!" %d" (n);
   foreach (i; 0 .. n) {
      int num;
      readf!" %d" (num);
      if (num % 2 == 0)
         num--;
      writef!"%d " (num);
   }

   return 0;
}

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

void main()
{
    int n;
    readf !"%s\n" (n);
    auto arr = readln.splitter.map!(to!int).map!(x => x-(1 - x%2));
    writefln("%-(%d %)", arr);
}

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

void main()
{
    auto n = readln.strip.to!ulong;
    auto a = readln.strip.split();
    foreach (i, v; a)
    {
        auto va = v.to!ulong;
        if (va % 2 == 1)
            write(va, " ");
        else
         write(va - 1, " ");
    }
}

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

void main()
{
    readln;

    auto arr = readln.chomp.split.map!(to!int).array;

    arr = arr.map!(x => x % 2 == 0 ? x - 1 : x).array;

    arr.writefln!("%(%s %)");
}

import std.algorithm;
import std.array;
import std.bitmanip;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.range.interfaces;
void main(){
    auto n = readln.strip.to!ulong;
    auto s = readln.strip.split();
    foreach (i, k; s){
        auto ans = k.to!ulong;
        if (ans % 2) write(ans, " ");
        else write(ans - 1, " ");
    }
}

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


// Vicfred
// https://codeforces.com/contest/1426/problem/A
// math
import std.stdio;

void main() {
    int t;
    readf("%s\n", &t);

    int n, x;
    while(t--) {
        readf("%s %s\n", &n, &x);
        if(n <= 2) {
            "1".writeln;
            continue;
        }
        int ans = (n - 3)/x + 2;
        ans.writeln;
    }
}

// Cheese-Cracker: cheese-cracker.github.io
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
void show(A...)(A a) { debug{ foreach(t; a){ write(t, "| "); } writeln; } }
/*******************************It's a Me, Mario!*******************************************/

void play(){
    int n, x;
    n = rd!int;
    x = rd!int;
    if(n <= 2){
        writeln(1);
    }else{
        n -= 3;
        int apt = n/x;
        writeln(2 + apt);
    }
}

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


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

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

void solve(){
	int n = rint, q = rint;

	bool[][] xf = new bool[][](2, n);
	int cnt;

	foreach(_; 0 .. q){
		int r = rint - 1, c = rint - 1;
		if(xf[r][c]){
			xf[r][c] = 0;
			if(c > 0 && xf[1 - r][c - 1]) cnt -= 1;
			if(xf[1 - r][c]) cnt -= 1;
			if(c < n - 1 && xf[1 - r][c + 1]) cnt -= 1;
		}
		else{
			xf[r][c] = 1;
			if(c > 0 && xf[1 - r][c - 1]) cnt += 1;
			if(xf[1 - r][c]) cnt += 1;
			if(c < n - 1 && xf[1 - r][c + 1]) cnt += 1;
		}
		if(cnt > 0) "No".writeln;
		else "Yes".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, q;
    readf("%s %s", &n, &q);
    readln;

    auto board = new bool[][] (2, n);

    alias t = Tuple!(int, int);
    auto vert = make!(RedBlackTree!int);
    auto cross = make!(RedBlackTree!t);

    foreach (_; 0 .. q) {
        int r, c;
        readf("%s %s", &r, &c);
        readln;

        --r, --c;
        board[r][c] = !board[r][c];

        if (board[r][c]) {
            if (board[1 - r][c]) { vert.insert(c); }

            if (c > 0 && board[1-r][c-1]) { cross.insert(tuple(1-r, c-1)); }
            if (c < n-1 && board[1-r][c+1]) { cross.insert(tuple(r, c)); }
        } else {
            if (c in vert) { vert.removeKey(c); }

            if (c > 0 && tuple(1-r, c-1) in cross) { cross.removeKey(tuple(1-r, c-1)); }
            if (c < n-1 && tuple(r, c) in cross) { cross.removeKey(tuple(r, c)); }
        }

        writeln(vert.empty() && cross.empty() ? "Yes" : "No");
    }
}

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

DList!string _words;

void read(T...)(ref T t)
{
  void singleRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  static foreach(i; 0 .. T.length)
    {
      static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))
        {
          foreach(ref element; t[i])
            read(element);
        }
      else
        {
          singleRead(t[i]);
        }
    }
}

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

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

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

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

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

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

    }
}

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

void main()
{
  auto n = next!long, q = next!long;
  auto state = new bool[][2];
  foreach(ref row; state)
    row = new bool[n.ind];
  auto conns = long(0);
  foreach(i; 0 .. q)
    {
      auto r = next!long - 1, c = next!long - 1;
      state[r.ind][c.ind] = !state[r.ind][c.ind];
      if (state[r.ind][c.ind])
        {
          foreach(oc; c - 1 .. c + 2)
            if (oc >= 0 && oc < n)
              if (state[(r^1).ind][oc.ind])
                conns++;
        }
      else
        {
          foreach(oc; c - 1 .. c + 2)
            if (oc >= 0 && oc < n)
              if (state[(r^1).ind][oc.ind])
                conns--;
        }
      if (conns > 0 || state[0][0] || state[1][$ - 1])
        writeln("No");
      else
        writeln("Yes");
    }
}

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 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 main()
{
	auto n = RD!int;
	auto q = RD!int;
	auto ans = new bool[](q);
	auto cell = new bool[][](2, n);
	bool[int] set;
	foreach (i; 0..q)
	{
		auto r = RD!int-1;
		auto c = RD!int-1;
		cell[r][c] = !cell[r][c];
		debug writeln(cell[0]);
		debug writeln(cell[1]);
		if (cell[r][c])
		{
			bool ok = i == 0 ? true : ans[i-1];
			foreach (j; max(0, c-1)..min(n, c+2))
			{
				if (cell[r^1][j])
				{
					ok = false;
					set[r*n+c] = true;
				}
			}
			ans[i] = ok;
		}
		else
		{
			if (set.get(r*n+c, false))
				set.remove(r*n+c);

			foreach (j; max(0, c-1)..min(n, c+2))
			{
				if (!cell[r^1][j]) continue;
				if (set.get((r^1)*n+j, false) == false) continue;
				bool ok = true;
				foreach (k; max(0, j-1)..min(n, j+2))
				{
					if (cell[r][k])
						ok = false;
				}
				if (ok)
					set.remove((r^1)*n+j);
			}
			ans[i] = set.length == 0;
		}
	}

	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;
import std.typecons;

void main ()
{
	int n, q;
	while (readf !(" %s %s") (n, q) > 0)
	{
		auto wall = new bool [] [] (2, n + 2);
		int block = 0;
		foreach (r; 0..q)
		{
			int u, v;
			readf !(" %s %s") (u, v);
			u -= 1;
			int mult = wall[u][v] ? -1 : +1;
			foreach (k; -1..+2)
			{
				block += wall[u ^ 1][v + k] * mult;
			}
			wall[u][v] ^= true;
			writeln (block == 0 ? "Yes" : "No");
		}
	}
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const Q = readInt();
      auto R = new int[Q];
      auto C = new int[Q];
      foreach (q; 0 .. Q) {
        R[q] = readInt() - 1;
        C[q] = readInt() - 1;
      }

      auto can = new bool[][](2, N);
      foreach (x; 0 .. 2) {
        can[x][] = true;
      }

      auto vals = new int[N - 1];
      vals[] = 1;
      int now = N - 1;

      void check(int y) {
        if (0 <= y && y < N - 1) {
          now -= vals[y];
          vals[y] = (can[0][y] && can[0][y + 1] || can[1][y] && can[1][y + 1]) ? 1 : 0;
          now += vals[y];
        }
      }

      foreach (q; 0 .. Q) {
        can[R[q]][C[q]] = !can[R[q]][C[q]];
        check(C[q] - 1);
        check(C[q]);
        writeln((now == N - 1) ? "Yes" : "No");
      }
    }
  } catch (EOFException e) {
  }
}


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

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

void solve(){
	int n = rint;

	X[] as, bs;
	foreach(i; 2 .. n){
		if(ask(2, 0, 1, i) < 0) as ~= X(i, ask(1, 0, 1, i));
		else bs ~= X(i, ask(1, 1, 0, i));
	}

	X az = X(-1, -1), bz = X(-1, -1);
	foreach(a; as) if(a.v > az.v) az = a;
	foreach(b; bs) if(b.v > bz.v) bz = b;

	X[] a0s, a1s, b0s, b1s;
	foreach(a; as){
		if(a.u == az.u) continue;
		if(ask(2, 0, az.u, a.u) < 0) a0s ~= a;
		else a1s ~= a;
	}
	foreach(b; bs){
		if(b.u == bz.u) continue;
		if(ask(2, 1, bz.u, b.u) < 0) b0s ~= b;
		else b1s ~= b;
	}
	a0s.sort!"a.v<b.v"();
	a1s.sort!"a.v>b.v"();
	b0s.sort!"a.v<b.v"();
	b1s.sort!"a.v>b.v"();

	X[] ans = [X(0, 0)] ~ a0s;
	if(az.u >= 0) ans ~= az;
	ans ~= a1s ~ [X(1, 0)] ~ b0s;
	if(bz.u >= 0) ans ~= bz;
	ans ~= b1s;
	writeln("0 ", ans.map!(x => x.u + 1).map!(to!string).array.join(" "));
}

struct X{
	int u;
	long v;
}

long ask(int t, int i, int j, int k){
	writeln(t, " ", i + 1, " ", j + 1, " ", k + 1);
	stdout.flush;
	return rlong;
}

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

long askArea (int i, int j, int k)
{
	writeln (1, " ", i + 1, " ", j + 1, " ", k + 1);
	stdout.flush ();
	auto res = readln.strip.to !(long);
	return res;
}

int askSign (int i, int j, int k)
{
	writeln (2, " ", i + 1, " ", j + 1, " ", k + 1);
	stdout.flush ();
	auto res = readln.strip.to !(int);
	return res;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;

		int i = 0;
		int j = 1;
		foreach (k; 2..n)
		{
			if (askSign (i, j, k) < 0)
			{
				j = k;
			}
		}

		alias Pair = Tuple !(long, q{area}, int, q{num});
		Pair [] p;
		foreach (k; 1..n)
		{
			if (k != j)
			{
				auto cur = askArea (i, j, k);
				p ~= Pair (cur, k);
			}
		}
		sort (p);

		int [] left = [];
		int [] right = [i, j];
		foreach (const ref c; p)
		{
			auto num = c.num;
			if (askSign (right[$ - 2], right[$ - 1], num) < 0)
			{
				left ~= right[$ - 1];
				right.length -= 1;
				right.assumeSafeAppend ();
			}
			right ~= num;
		}

		auto ans = right ~ left.retro.array;
		ans[] += 1;
		writefln ("0 %(%s %)", ans);
		stdout.flush ();
	}
}

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

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

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

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

int N;

debug {
  long[] X, Y;
}

long Ask(int t, int i, int j, int k) {
  long ret;
  debug {
    ret = (X[j] - X[i]) * (Y[k] - Y[i]) - (Y[j] - Y[i]) * (X[k] - X[i]);
    if (t == 1) {
      ret = abs(ret);
    } else {
      ret = sgn(ret);
    }
  } else {
    writeln(t, " ", i + 1, " ", j + 1, " ", k + 1);
    stdout.flush;
    ret = readLong();
  }
  return ret;
}

void main() {
  N = readInt();
  debug {
    X = new long[N];
    Y = new long[N];
    foreach (i; 0 .. N) {
      X[i] = readLong();
      Y[i] = readLong();
    }
  }

  auto as = new long[N];
  foreach (i; 2 .. N) {
    as[i] = Ask(1, 0, 1, i);
    as[i] *= Ask(2, 0, 1, i);
  }
  debug {
    writeln("as = ", as);
  }

  int[] ans;
  ans ~= 0;
  {
    int im;
    foreach (i; 2 .. N) {
      if (as[im] > as[i]) {
        im = i;
      }
    }
    if (im != 0) {
      int[] ims, ips;
      foreach (i; 2 .. N) {
        if (as[i] < 0 && i != im) {
          const res = Ask(2, 0, im, i);
          (res < 0) ? (ims ~= i) : (ips ~= i);
        }
      }
      ims.sort!((i, j) => (as[i] > as[j]));
      ips.sort!((i, j) => (as[i] < as[j]));
      foreach (i; ims) ans ~= i;
      ans ~= im;
      foreach (i; ips) ans ~= i;
    }
  }
  ans ~= 1;
  {
    int im;
    foreach (i; 2 .. N) {
      if (as[im] < as[i]) {
        im = i;
      }
    }
    if (im != 0) {
      int[] ims, ips;
      foreach (i; 2 .. N) {
        if (as[i] > 0 && i != im) {
          const res = Ask(2, 0, im, i);
          (res < 0) ? (ims ~= i) : (ips ~= i);
        }
      }
      ims.sort!((i, j) => (as[i] < as[j]));
      ips.sort!((i, j) => (as[i] > as[j]));
      foreach (i; ims) ans ~= i;
      ans ~= im;
      foreach (i; ips) ans ~= i;
    }
  }

  write(0);
  foreach (i; ans) {
    write(" ", i + 1);
  }
  writeln();
  stdout.flush;
}

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

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

void solve(){
	int n = rint;

	X[] as, bs;
	foreach(i; 2 .. n){
		if(ask(2, 0, 1, i) < 0) as ~= X(i, ask(1, 0, 1, i));
		else bs ~= X(i, ask(1, 1, 0, i));
	}

	X az = X(-1, -1), bz = X(-1, -1);
	foreach(a; as) if(a.v > az.v) az = a;
	foreach(b; bs) if(b.v > bz.v) bz = b;

	X[] a0s, a1s, b0s, b1s;
	foreach(a; as){
		if(a.u == az.u || ask(2, 0, az.u, a.u) < 0) a0s ~= a;
		else a1s ~= a;
	}
	foreach(b; bs){
		if(b.u == bz.u || ask(2, 1, bz.u, b.u) < 0) b0s ~= b;
		else b1s ~= b;
	}
	a0s.sort!"a.v<b.v"();
	a1s.sort!"a.v>b.v"();
	b0s.sort!"a.v<b.v"();
	b1s.sort!"a.v>b.v"();

	X[] ans = [X(0, 0)] ~ a0s ~ a1s ~ [X(1, 0)] ~ b0s ~ b1s;
	writeln("0 ", ans.map!(x => x.u + 1).map!(to!string).array.join(" "));
}

struct X{
	int u;
	long v;
}

long ask(int t, int i, int j, int k){
	writeln(t, " ", i + 1, " ", j + 1, " ", k + 1);
	stdout.flush;
	return rlong;
}

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

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

void solve(){
	int n = rint;
	int p = uniform(0, n);
	int q = uniform(0, n);
	if(p == q) q += 1, q %= n;

	int[] as, bs;
	foreach(i; 0 .. n){
		if(i == p || i == q) continue;
		long x = ask(2, p, q, i);
		if(x < 0) as ~= i;
		else bs ~= i;
	}
	int[] ans = [p] ~ calc(as, p, q) ~ [q] ~ calc(bs, q, p);

	int i0;
	while(ans[i0] != 0) i0 += 1;

	ans = ans[i0 .. $] ~ ans[0 .. i0];
	ans.map!(x => x + 1).map!(to!string).array.join(" ").writeln;
}

int[] calc(int[] us, int p, int q){
	if(us.length <= 1) return us;
	int[] as, bs;
	int r = 0;
	long highest = 0;
	foreach(u; us){
		long w = ask(1, p, q, u);
		if(w > highest) r = u, highest = w;
	}
	foreach(u; us){
		if(r == u) continue;
		long x = ask(2, p, r, u);
		if(x < 0) as ~= u;
		else bs ~= u;
	}
	return calc(as, p, r) ~ [r] ~ calc(bs, r, q);
}

long ask(int t, int i, int j, int k){
	writeln(t, " ", i + 1, " ", j + 1, " ", k + 1);
	stdout.flush;
	return rlong;
}

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

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

void solve(){
	int n = rint;

	X[] as, bs;
	X az = X(-1, -1), bz = X(-1, -1);
	foreach(i; 2 .. n){
		if(ask(2, 0, 1, i) < 0){
			X a = X(i, ask(1, 0, 1, i));
			as ~= a;
			if(az.v < a.v) az = a;
		}
		else{
			X b = X(i, ask(1, 1, 0, i));
			bs ~= b;
			if(bz.v < b.v) bz = b;
		}
	}
	X[] a0s, a1s, b0s, b1s;
	foreach(a; as){
		if(a.u == az.u) continue;
		if(ask(2, 0, az.u, a.u) < 0) a0s ~= a;
		else a1s ~= a;
	}
	foreach(b; bs){
		if(b.u == bz.u) continue;
		if(ask(2, 1, bz.u, b.u) < 0) b0s ~= b;
		else b1s ~= b;
	}
	a0s.sort!"a.v<b.v"();
	a1s.sort!"a.v>b.v"();
	b0s.sort!"a.v<b.v"();
	b1s.sort!"a.v>b.v"();

	X[] ans = [X(0, 0)] ~ a0s ~ az ~ a1s ~ [X(1, 0)] ~ b0s ~ bz ~ b1s;
	writeln("0 ", ans.map!(x => x.u + 1).map!(to!string).array.join(" "));
}

struct X{
	int u;
	long v;
}

long ask(int t, int i, int j, int k){
	writeln(t, " ", i + 1, " ", j + 1, " ", k + 1);
	stdout.flush;
	return rlong;
}


module main;

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

int main()
{
    auto n = readln().strip().to! (int);
    auto f = [0] ~ readln().strip().split().map! (to! (int)).array();

    auto dict = new int [n + 2];
    foreach (int i; 1..f.length)
        dict[f[i]] = i;

    long result;
    for (int i = 2; i <= n; i++)
        result += abs(dict[i] - dict[i - 1]);

    writeln(result);

	return 0;
}

import std.stdio;
import std.string;
import std.conv;
import std.regex;
import std.file;
import std.math;
void main()
{

    string[] inp = split(strip(readln()));
    int n = to!int(inp[0]);
    string[] s = split(strip(readln()));
    int[] a=new int[s.length];
    for(int i = 0 ; i < s.length ; i++)
    {
        a[to!int(s[i])-1]=i;
    }
    long res;
    for(int i = 1 ; i < a.length ; i++)
    {
        res+=abs(a[i]-a[i-1]);
    }
    writeln(res);

    //writeln("-1");

}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto p = readln.split.map !(to !(int)).array;
		auto q = new int [n];
		foreach (i, c; p)
		{
			q[c - 1] = i;
		}
		(n - 1).iota.map !(i => abs (q[i + 1] - q[i]))
		    .sum (0L).writeln;
	}
}

module main;

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

int main()
{
    auto n = readln().strip().to! (int);
    auto f = readln().strip().split().map! (to! (int)).array();

    int[int] dict;
    foreach (int i; 0..f.length)
        dict[f[i] - 1] = i;

    int result;
    for (int i = 0; i < n - 1; i++)
        result += abs(dict[i + 1] - dict[i]);

    writeln(result);

	return 0;
}

module main;

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

int main()
{
    auto n = readln().strip().to! (int);
    auto f = [0] ~ readln().strip().split().map! (to! (int)).array();

    auto dict = new int [n + 2];
    foreach (int i; 1..f.length)
        dict[f[i]] = i;

    int result;
    for (int i = 2; i <= n; i++)
        result += abs(dict[i] - dict[i - 1]);

    writeln(result);

	return 0;
}

module main;

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

int main()
{
    auto n = readln().strip().to! (int);
    auto f = [0] ~ readln().strip().split().map! (to! (int)).array();

    int[int] dict;
    foreach (int i; 1..f.length)
        dict[f[i]] = i;

    int result;
    for (int i = 1; i <= n - 1; i++)
        result += abs(dict[i + 1] - dict[i]);

    writeln(result);

	return 0;
}


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

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		long res = long.max;
		foreach (k; 0..n)
		{
			long cur = 0;
			long lo = 0;
			foreach_reverse (i; 0..k)
			{
				long steps = lo / a[i] - 1;
				cur -= steps;
				lo = steps * a[i];
			}
			long hi = 0;
			foreach (j; k + 1..n)
			{
				long steps = hi / a[j] + 1;
				cur += steps;
				hi = steps * a[j];
			}
			res = min (res, cur);
		}
		writeln (res);
	}
}

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

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

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

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

enum INF = 10L^^18;

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

      long ans = INF;
      foreach (i; 0 .. N) {
        long cost;
        {
          long b = 0;
          foreach_reverse (j; 0 .. i) {
            const k = b / A[j] + 1;
            cost += k;
            b = A[j] * k;
          }
        }
        {
          long b = 0;
          foreach (j; i + 1 .. N) {
            const k = b / A[j] + 1;
            cost += k;
            b = A[j] * k;
          }
        }
        debug {
          writeln(i, ": ", cost);
        }
        chmin(ans, cost);
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }
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 n = RD!int;
	auto a = RDA;

	long ans = long.max;
	foreach (i; 0..n)
	{
		long cnt;
		{
			long last;
			foreach_reverse (j; 0..i)
			{
				auto c = (last+a[j]) / a[j];
				last = a[j] * c;
				cnt += c;
			}
		}
		{
			long last;
			foreach (j; i+1..n)
			{
				auto c = (last+a[j]) / a[j];
				last = a[j] * c;
				cnt += c;
			}
		}
		ans.chmin(cnt);
	}

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


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.ascii, std.typecons;

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

    auto p = new int[] (k+1);
    auto g = new int[][] (n+1);
    foreach (i; 1 .. k+1) {
        int x, y;
        readf("%s %s", &x, &y);
        readln;

        p[i] = x;
        g[x] ~= y;
        g[y] ~= x;
    }

    int ok = 0;
    auto vis = new bool[] (n+1);
    vis[] = false;
    foreach (i; 1 .. k+1) {
        if (vis[p[i]]) { continue; }

        int dfs(int v) {
            vis[v] = true;
            int subn = 0;
            foreach (u; g[v]) {
                if (vis[u]) { continue; }
                subn += dfs(u);
            }

            return 1 + subn;
        }

        ok += dfs(p[i]) - 1;
    }

    int ans = k - ok;

    ans.writeln;
}

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(); }
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
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 rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtype!real;
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
	int n = rint, k = rint;

	Node[] nodes;
	foreach(i; 0 .. n) nodes ~= new Node(i, 0);

	Edge[] edges;
	foreach(j; 0 .. k){
		int x = rint - 1, y = rint - 1;
		edges ~= new Edge(nodes[x], nodes[y], 0);
		nodes[x].value += 1, nodes[y].value += 1;
	}

	foreach(ed; edges){
		if(ed.node1.group.id != ed.node2.group.id){
			ed.node1.group.eat(ed.node2.group);
		}
	}

	long ans;
	foreach(nd; nodes){
		if(nd.group.id != nd.id) continue;
		long edcnt;
		foreach(nx; nd.group.nodes) edcnt += nx.value;
		ans += edcnt / 2 - (nd.group.nodes.length - 1);
	}

	ans.writeln;

}

// Union-find ※多分使いやすいやつ
class Edge{
	Node node1;
	Node node2;
	long value;
	this(Node node1, Node node2, long value){
		this.node1 = node1, this.node2 = node2;
		this.value = value;
	}
	override string toString(){
		return [node1.id, node2.id, value].to!string;
	}
}

class Node{
	long id;
	long value;
	Group group;
	this(long id, long value){
		this.id = id;
		this.value = value;
		this.group = new Group(this);
	}
	override string toString(){
		return [id, group.id, value].to!string;
	}
}

class Group{
	long value;
	long pendingEdgeCount;
	long id;
	long edgecount;
	Node[] nodes;
	this(Node node){
		this.id = node.id;
		this.nodes = [node];
		this.value = node.value;
	}
	void eat(Group gp){
		if(gp.nodes.length > this.nodes.length) gp.eat(this);
		else{
			foreach(nd; gp.nodes){
				this.nodes ~= nd;
				nd.group = this;
				this.value += nd.value;
			}
			this.edgecount += gp.edgecount;
			this.pendingEdgeCount += gp.pendingEdgeCount;
		}
	}
}

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

struct UnionFind
{
	void init(int n) { par = new int[](n); foreach (i; 0..n) par[i] = i; cnt = new int[](n); fill(cnt, 1); }
	int root(int i) { return par[i] == i ? i : (par[i] = root(par[i])); }
	bool same(int i, int j) { return root(i) == root(j); }
	void unite(int i, int j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; cnt[j] += cnt[i]; }
	int size(int i) { return cnt[root(i)]; }
	int[] par, cnt;
}

void main()
{
	auto n = RD!int;
	auto k = RD!int;
	//auto edges = new int[][](n);
	UnionFind uf;
	uf.init(n);
	foreach (i; 0..k)
	{
		auto a = RD!int-1;
		auto b = RD!int-1;
		//edges[a] ~= b;
		//edges[b] ~= a;
		uf.unite(a, b);
	}

	auto cnt = new int[](n);
	foreach (i; 0..n)
	{
		cnt[i] = uf.size(i);
	}

	long ans;
	auto index = cnt.MAKE_IDX!("a > b")();
	auto used = new bool[](n);
	foreach (i; index)
	{
		auto r = uf.root(cast(int)i);
		if (used[r]) continue;
		ans += cnt[i]-1;
		used[r] = true;
	}

	writeln(max(k-ans, 0));
	stdout.flush();
	debug readln();
}