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

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

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

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

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

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

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

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

void main()
{
    int N; get(N);
    int a, b, c;
    int[] aa; get(aa);
    foreach (i, x; aa) {
        if (a == x && b == x) {
            continue;
        } else if (a != x && b != x) {
            if (i+1 < aa.length) {
                auto y = aa[i+1];
                if (a == y) {
                    a = x;
                } else {
                    b = x;
                }
            }
        } else if (a != x) {
            a = x;
        } else if (b != x) {
            b = x;
        }
        ++c;
    }
    writeln(c);
}

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

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

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

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

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

      const gs = A.group.array;
      const gsLen = cast(int)(gs.length);
      debug {
        writeln("A = ", A);
        writeln("gs = ", gs);
      }

      int ans;
      for (int j = 0, k; j < gsLen; j = k) {
        for (k = j; k < gsLen && (gs[j][1] == 1) == (gs[k][1] == 1); ++k) {}
        if (gs[j][1] == 1) {
          ans += (k - j);
          if (0 < j && k < gsLen && gs[j - 1][0] == gs[k][0]) {
            if ((k - j) % 2 != 0) {
              bool bad = true;
              for (int l = j + 1; l < k; l += 2) {
                bad = bad && (gs[j - 1][0] == gs[l][0]);
              }
              if (bad) {
                debug {
                  writeln("bad ", gs[j .. k]);
                }
                ans -= 1;
              }
            }
          }
        } else {
          ans += 2 * (k - j);
        }
      }
      writeln(ans);

      debug {
        int brt = 0;
        foreach (p; 0 .. 1 << N) {
          int cost;
          int[2] bs = [-1, -1];
          foreach (i; 0 .. N) {
            const s = (p >> i) & 1;
            if (bs[s] != A[i]) {
              ++cost;
              bs[s] = A[i];
            }
          }
          chmax(brt, cost);
        }
        writeln("brt = ", brt);
        assert(brt == 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)); }

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(-1);

	auto pos = new int[][](n+1);
	foreach (i; 0..n)
	{
		pos[a[i]] ~= i;
	}

	int[] a0 = [n], a1 = [n];
	foreach (i; 0..n)
	{
		pos[a[i]].popFront;
		if (a0.back == a[i])
			a1 ~= a[i];
		else if (a1.back == a[i])
			a0 ~= a[i];
		else
		{
			int x = n, y = n;
			if (!pos[a0.back].empty)
				x = pos[a0.back].front;
			if (!pos[a1.back].empty)
				y = pos[a1.back].front;
			if (x < y)
				a0 ~= a[i];
			else
				a1 ~= a[i];
		}
	}

	debug writeln("a0:", a0);
	debug writeln("a1:", a1);
	a0.popFront;
	a1.popFront;
	long ans;
	if (!a0.empty)
	{
		++ans;

		foreach (i; 1..a0.length)
		{
			if (a0[i-1] != a0[i])
				++ans;
		}
	}
	if (!a1.empty)
	{
		++ans;
		foreach (i; 1..a1.length)
		{
			if (a1[i-1] != a1[i])
				++ans;
		}
	}

	writeln(ans);
	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;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		int res = 0;
		int [2] [] p = [[-1, -1]];
		foreach (ref c; a)
		{
			int [2] [] [2] q;
			int next = res;
			foreach (ref prev; p)
			{
				foreach (j; 0..2)
				{
					auto good = (prev[j] != c);
					q[good] ~= [c, prev[!j]];
	                	}
			}
			foreach (j; 0..2)
			{
				if (!q[j].empty)
				{
					res = next + j;
					p = q[j];
				}
			}
			foreach (ref prev; p)
			{
				sort (prev[]);
			}
			p = p.sort.uniq.take (4).array;
		}
		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)); }

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

      const gs = A.group.array;
      const gsLen = cast(int)(gs.length);
      debug {
        writeln("gs = ", gs);
      }

      int ans;
      for (int j = 0, k; j < gsLen; j = k) {
        for (k = j; k < gsLen && (gs[j][1] == 1) == (gs[k][1] == 1); ++k) {}
        if (gs[j][1] == 1) {
          ans += (k - j);
          if (0 < j && k < gsLen) {
            if ((k - j) % 2 != 0) {
              bool bad = true;
              for (int l = j + 1; l < k; l += 2) {
                bad = bad && (gs[j - 1][0] == gs[l][0] && gs[l][0] == gs[k][0]);
              }
              if (bad) {
                debug {
                  writeln("bad ", gs[j .. k]);
                }
                ans -= 1;
              }
            }
          }
        } else {
          ans += 2 * (k - j);
        }
      }
      writeln(ans);
    }
  } 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 N = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }

      auto nxt = new int[N + 1];
      nxt[N] = -1;
      foreach_reverse (i; 0 .. N) {
        nxt[i] = (i + 1 < N && A[i] != A[i + 1]) ? A[i + 1] : nxt[i + 1];
      }
      debug {
        writeln("nxt = ", nxt);
      }

      int ans;
      int[2] bs = [-1, -1];
      foreach (i; 0 .. N) {
        void add(int s) {
          if (bs[s] != A[i]) {
            ++ans;
          }
          bs[s] = A[i];
        }
        add(i % 2);
      }
      writeln(ans);
    }
  } 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 N = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }

      auto nxt = new int[N + 1];
      nxt[N] = -1;
      foreach_reverse (i; 0 .. N) {
        nxt[i] = (i + 1 < N && A[i] != A[i + 1]) ? A[i + 1] : nxt[i + 1];
      }
      debug {
        writeln("nxt = ", nxt);
      }

      int ans;
      int[2] bs = [-1, -1];
      foreach (i; 0 .. N) {
        void add(int s) {
          if (bs[s] != A[i]) {
            ++ans;
          }
          bs[s] = A[i];
        }
        if (bs[0] == A[i]) {
          add(1);
        } else if (bs[1] == A[i]) {
          add(0);
        } else if (bs[0] == nxt[i]) {
          add(1);
        } else if (bs[1] == nxt[i]) {
          add(0);
        } else {
          add(0);
        }
      }
      writeln(ans);
    }
  } 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 N = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }

      int ans;
      foreach (g; A.group) {
        ans += (g[1] >= 2) ? 2 : 1;
      }
      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)); }

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[] a0 = [a[0]], a1;
	foreach (i; 1..n)
	{
		if (a0.back == a[i])
			a1 ~= a[i];
		else
			a0 ~= a[i];
	}

	long ans = 1;
	foreach (i; 1..a0.length)
	{
		if (a0[i-1] != a0[i])
			++ans;
	}
	if (!a1.empty)
	{
		++ans;
		foreach (i; 1..a1.length)
		{
			if (a1[i-1] != a1[i])
				++ans;
		}
	}

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

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

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

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

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

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

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

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

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

void main()
{
    int N; get(N);
    int a, b, c;
    foreach (x; readln.split.to!(int[])) {
        if (a != x) {
            a = x;
            ++c;
        } else if (b != x) {
            b = x;
            ++c;
        }
    }
    writeln(c);
}


import std.algorithm, std.conv, std.range, std.stdio, std.typecons, std.string;
void main () {
	int n, x, r, res, cur = int.min;
	string s;
	readf (" %s%s", &n, &s);
	auto a = s.split.map!(to!int).chunks (2)
		.map!"tuple(a[0]+a[1],a[0]-a[1])".array.sort;
	foreach (c; a) if (cur <= c[1]) res++, cur = c[0];
	res.writeln;
}

import std.algorithm, std.stdio, std.typecons;
void main () {
	int n, x, r, res, cur = int.min;
	readf (" %s", &n);
	Tuple !(int, int) [] a;
	foreach (i; 0..n) readf (" %s %s", &x, &r), a ~= tuple (x + r, x - r);
	a.sort;
	foreach (c; a) if (cur <= c[1]) res++, cur = c[0];
	res.writeln;
}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		alias Pair = Tuple !(int, q{hi}, int, q{lo});
		Pair [] a;
		foreach (i; 0..n)
		{
			int x, r;
			readf (" %s %s", &x, &r);
			a ~= Pair (x + r, x - r);
		}
		sort (a);
		long res = 0;
		int cur = int.min;
		foreach (c; a)
		{
			if (cur <= c.lo)
			{
				res++;
				cur = c.hi;
			}
		}
		writeln (res);
	}
}

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

alias XW = Tuple!(long, "x", long, "w");

void main()
{
    auto N = readln.chomp.to!int;
    XW[] xws;
    foreach (_; 0..N) {
        auto xw = readln.split.to!(long[]);
        xws ~= XW(xw[0], xw[1]);
    }
    sort!"a.x + a.w < b.x + b.w"(xws);
    int r;
    long last = long.min;
    foreach (xw; xws) {
        if (last <= xw.x - xw.w) {
            ++r;
            last = xw.x + xw.w;
        }
    }
    writeln(r);
}

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

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

		alias Pair = Tuple !(int, q{lo}, int, q{hi});
		Pair [] a;
		foreach (i; 0..n)
		{
			a ~= Pair (x[i] - r[i], x[i] + r[i]);
		}
		a.sort !(q{a.hi < b.hi}, SwapStrategy.stable);
		long res = 0;
		int cur = int.min;
		foreach (c; a)
		{
			if (cur <= c.lo)
			{
				res++;
				cur = c.hi;
			}
		}
		writeln (res);
	}
}


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

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

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

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

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

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

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

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

void main()
{
    int T; get(T);
    while (T--) {
        int n, k; get(n, k);
        int[] hs; get(hs);

        int p;
        while (k--) {
            foreach (i, ref h; hs) {
                if (i == hs.length - 1) goto ng;
                if (h >= hs[i+1]) continue;
                p = i.to!int;
                ++h;
                break;
            }
        }
        writeln(p + 1);
        continue;

        ng:
        writeln(-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(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

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

		while (k > 0)
		{
			bool ok;
			foreach (i; 0..n-1)
			{
				if (h[i] < h[i+1])
				{
					--k;
					++h[i];
					ans[ti] = i+1;
					ok = true;
					break;
				}
			}
			if (!ok)
			{
				ans[ti] = -1;
				break;
			}
		}
	}

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

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

long solve (int n, int k, int [] h)
{
	while (true)
	{
		int i = 0;
		while (i < n - 1 && h[i + 1] <= h[i])
		{
			i += 1;
		}
		if (i == n - 1)
		{
			return -1;
		}
		h[i] += 1;
		k -= 1;
		if (k <= 0)
		{
			return i + 1;
		}
	}
}

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

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

string FMT_F = "%.10f";

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

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

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

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

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

		ans[ti] = -1;
		long[][] s;
		(){
		foreach (i; 0..n)
		{
			if (s.empty)
				s ~= [h[i], i];
			else if (h[i] <= s[$-1][0])
				s ~= [h[i], i];
			else
			{
				auto x = h[i];
				while (!s.empty)
				{
					if (s[$-1][0] > x)
					{
						s ~= [x, s[$-1][1]+1];
						break;
					}
					auto nd = s.back; s.popBack;
					auto y = nd[0];
					auto p = nd[1];
					k -= (x - y) * (i - p);
					debug writeln("i:", i, " p:", p, " x:", x, " y:", y, " k:", k);
					if (k <= 0)
					{
						debug writeln("i:", i, " p:", p, " k:", k);
						ans[ti] = p + 1 - k;
						return;
					}
				}
			}
		}}();
	}

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

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

long solve (int n, long k, int [] h)
{
	while (true)
	{
		if (isSorted !(q{a > b}) (h))
		{
			return -1;
		}
		int i = 1;
		while (h[i] <= h[i - 1])
                {
                	i += 1;
                }
                int j = i - 1;
                while (j > 0 && h[j - 1] == h[j])
                {
                	j -= 1;
                }
                int len = i - j;
		int cur = h[i] - h[j];
		k -= cur * 1L * (i - j);
		if (k <= 0)
		{
			return i - (k + cur * 1L * (i - j) - 1) % len;
		}
		h[j..i] += cur;
	}
}

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


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 s = [0];
		foreach (ref x; a)
		{
			s ~= s.back ^ x;
		}

		bool [int] v;
		int cur = 0;
		v[cur] = true;
		int res = 0;
		foreach (ref x; a)
		{
			if ((x ^ cur) in v)
			{
				v = null;
				cur = 0;
				v[cur] = true;
				continue;
			}
			res += 1;
			cur ^= x;
			v[cur] = true;
		}
		writeln (res);
	}
}

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

alias Tuple!(int,int) K;
enum int INF = 1<<29;

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

    /*
    int[K] cache;
    int f(int k, int s) {
        // turn [k, N) into 0
        if (k == N) return 0;
        auto key = K(k, s);
        if (key in cache) return cache[key];
        int ans = int.max;
        // don't use s
        ans = min(ans, f(k + 1, A[k]) + (A[k] > 0));
        // use s
        ans = min(ans, f(k + 1, A[k] ^ s) + ((A[k] ^ s) > 0));
        return cache[key] = ans;
    }
    */

    int L = 8191;
    auto f = new int[][](N + 1, L + 1);
    foreach (ref l; f) l[] = INF;
    f[0][0] = 0;
    for (int k = 0; k < N; k++) {
        for (int s = 0; s <= L; s++) {
            // use x = A[k]
            f[k + 1][A[k]] = min(f[k + 1][A[k]], f[k][s] + (A[k] > 0));
            // use x = A[k] ^ s
            int x = A[k] ^ s;
            f[k + 1][x] = min(f[k + 1][x], f[k][s] + (x > 0));
        }
    }
    writeln(f[N].reduce!min);
}

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

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

alias Tuple!(int,int) K;
enum int INF = 1<<29;

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

    /*
    int[K] cache;
    int f(int k, int s) {
        // turn [k, N) into 0
        if (k == N) return 0;
        auto key = K(k, s);
        if (key in cache) return cache[key];
        int ans = int.max;
        // don't use s
        ans = min(ans, f(k + 1, A[k]) + (A[k] > 0));
        // use s
        ans = min(ans, f(k + 1, A[k] ^ s) + ((A[k] ^ s) > 0));
        return cache[key] = ans;
    }
    */

    int L = 8191;
    auto f = new int[][](N + 1, L + 1);
    foreach (ref l; f) l[] = INF;
    f[0][] = 0;
    for (int k = 0; k < N; k++) {
        for (int s = 0; s <= L; s++) {
            // use x = A[k]
            f[k + 1][A[k]] = min(f[k + 1][A[k]], f[k][s] + (A[k] > 0));
            // use x = A[k] ^ s
            int x = A[k] ^ s;
            f[k + 1][x] = min(f[k + 1][x], f[k][s] + (x > 0));
        }
    }
    writeln(f[N].reduce!min);
}

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

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 cur = 0;
		int res = 0;
		foreach (ref c; a)
		{
			if (c == 0)
			{
				cur = 0;
				continue;
			}
			res += 1;
			cur ^= c;
			if (cur == 0)
			{
				res -= 1;
			}
		}
		writeln (res);
	}
}


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

void main ()
{
	int n;
	while (scanf (" %d", &n) > 0)
	{
		bool s = false;
		foreach (i; 0..n)
		{
			foreach (j; 0..n)
			{
				int t;
				scanf (" %d", &t);
				if (i == j)
				{
					if (t)
					{
						s ^= true;
					}
				}
			}
		}

		int q;
		scanf (" %d", &q);
		string res;
		foreach (k; 0..q)
		{
			int t, i;
			scanf (" %d", &t);
			switch (t)
			{
				case 1:
				case 2:
					scanf (" %d", &i);
					s ^= true;
					break;
				case 3:
					res ~= s ? '1' : '0';
					break;
				default:
					assert (false);
			}
		}
		writeln (res);
	}
}

/// https://codeforces.com/contest/405/problem/C
/// PS> dmd cf.d; if($?) {cat in.txt | .\cf.exe}
import std.stdio : stdin, write, writeln;

void main()
{
  int n, q, sum = 0;
  stdin.readf!"%d\n"(n);

  for (int i=0; i<n; i++)
    sum += stdin.readln()[i << 1];

  stdin.readf!"%d\n"(q);
  for (int i=0; i<q; i++) {
    int cmd = stdin.readln()[0];
    if (cmd == '3')
      write(sum & 1);
    else
      sum++;
  }
  writeln();
}

/// https://codeforces.com/contest/405/problem/C
/// PS> dmd cf.d; if($?) {cat in.txt | .\cf.exe}
import std.stdio : stdin, writeln;

void main()
{
  int n, q, sum = 0;
  stdin.readf!"%d\n"(n);

  for (int i=0; i<n<<1; i+=2)
    sum += stdin.readln()[i];
  stdin.readf!"%d\n"(q);

  char[] res; res.reserve(q);
  for (int i=0; i<q; i++)
    if (stdin.readln()[0] == '3')
      res ~= '0' + (sum & 1);
    else
      sum++;
  writeln(res);
}


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

int main()
{
    int n = readInt!int;
    auto a = new long[](n);
    foreach(ref ai; a) ai = readInt!long;
    int pos = cast(int) a.count!(ai => ai >= 0);
    long[][] maxSum = new long[][](n + 1, n + 1);
    maxSum[0][0] = (a[0] < 0)? 0 : a[0];
    foreach(i; 1 .. n)
    {
        maxSum[i][0] = (a[i] < 0)? maxSum[i-1][0] : (maxSum[i-1][0] + a[i]);
    }
    foreach(p; 1 .. n)
    {
        foreach(i; 0 .. n)
        {
            if (a[i] < 0)
            {
                if (i == 0)
                {
                    maxSum[i][p] = -1;
                }
                else
                {
                    maxSum[i][p] = max(maxSum[i-1][p], maxSum[i-1][p-1] + a[i]);
                }
            }
            else
            {
                if (i == 0)
                {
                    maxSum[i][p] = -1;
                }
                else
                {
                    maxSum[i][p] = (maxSum[i-1][p] >= 0)? (maxSum[i-1][p] + a[i]) : maxSum[i-1][p];
                }
            }
        }
    }
    int p = 0;
    while (p + 1 < n && maxSum[n-1][p + 1] >= 0)
    {
        p++;
    }
    writeln(pos + p);
    return 0;
}

/* INPUT ROUTINES */
int currChar;
static this()
{
    currChar = getchar();
}
char topChar()
{
    return cast(char) currChar;
}
void popChar()
{
    currChar = getchar();
}
auto readInt(T)()
{
    T num = 0;
    int sgn = 0;
    while (topChar.isWhite) popChar;
    while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }
    while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }
    if (sgn) return -num; return num;
}
string readString()
{
    string res = "";
    while (topChar.isWhite) popChar;
    while (!topChar.isWhite) { res ~= topChar; popChar; }
    return res;
}

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

int solve(int[] a)
{
    auto n = to!int(a.length);
    auto pdp = new long[n + 1];
    auto ndp = new long[n + 1];
    fill(pdp, -1);
    pdp[0] = 0;
    foreach (i; 0 .. n)
    {
        ndp[0] = pdp[0];
        foreach (j; 1 .. i + 2)
        {
            ndp[j] = pdp[j];
            if (pdp[j - 1] >= 0 && pdp[j - 1] + a[i] >= 0)
            {
                ndp[j] = max(ndp[j], pdp[j - 1] + a[i]);
            }
        }
        ndp[0 .. i + 2].copy(pdp);
    }
    auto res = 0;
    foreach_reverse (i; 0 .. n + 1) if (pdp[i] >= 0)
    {
        res = i;
        break;
    }
    return res;
}

int main(string[] args)
{
    readln;
    auto a = map!(to!int)(readln.strip.split(" ")).array;
    auto ret = solve(a);
    writeln(ret);
    return 0;
}

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

int main()
{
    int n = readInt!int;
    auto a = new int[](n);
    foreach(ref ai; a) ai = readInt!int;
    int pos = cast(int) a.count!(ai => ai >= 0);
    int[][] maxSum = new int[][](n + 1, n + 1);
    maxSum[0][0] = (a[0] < 0)? 0 : a[0];
    foreach(i; 1 .. n)
    {
        maxSum[i][0] = (a[i] < 0)? maxSum[i-1][0] : (maxSum[i-1][0] + a[i]);
    }
    foreach(p; 1 .. n)
    {
        foreach(i; 0 .. n)
        {
            if (a[i] < 0)
            {
                if (i == 0)
                {
                    maxSum[i][p] = a[i];
                }
                else
                {
                    maxSum[i][p] = max(maxSum[i-1][p], maxSum[i-1][p-1] + a[i]);
                }
            }
            else
            {
                if (i == 0)
                {
                    maxSum[i][p] = -1;
                }
                else
                {
                    maxSum[i][p] = (maxSum[i-1][p] >= 0)? (maxSum[i-1][p] + a[i]) : maxSum[i-1][p];
                }
            }
        }
    }
    int p = 0;
    while (p + 1 < n && maxSum[n-1][p + 1] >= 0)
    {
        p++;
    }
    writeln(pos + p);
    return 0;
}

/* INPUT ROUTINES */
int currChar;
static this()
{
    currChar = getchar();
}
char topChar()
{
    return cast(char) currChar;
}
void popChar()
{
    currChar = getchar();
}
auto readInt(T)()
{
    T num = 0;
    int sgn = 0;
    while (topChar.isWhite) popChar;
    while (topChar == '-' || topChar == '+') { sgn ^= (topChar == '-'); popChar; }
    while (topChar.isDigit) { num *= 10; num += (topChar - '0'); popChar; }
    if (sgn) return -num; return num;
}
string readString()
{
    string res = "";
    while (topChar.isWhite) popChar;
    while (!topChar.isWhite) { res ~= topChar; popChar; }
    return res;
}


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

immutable int BASE = 10;
immutable int MOD = 1_000_000_007;
immutable int NA = -1;

struct ModInt
{
	int contents;
//	alias contents this;

	invariant
	{
		assert (0 <= contents && contents < MOD);
	}

	this (int newContents)
	in
	{
		assert (0 <= newContents && newContents < MOD);
	}
	body
	{
		contents = newContents;
	}

	ref ModInt opOpAssign (string op) (const ModInt rhs)
	in
	{
		assert (0 <= rhs.contents && rhs.contents < MOD);
	}
	body
	{
		static if (op == "+")
		{
			contents += rhs.contents;
			if (contents >= MOD)
			{
				contents -= MOD;
			}
		}
		else static if (op == "-")
		{
			contents -= rhs.contents;
			if (contents < 0)
			{
				contents += MOD;
			}
		}
		else static if (op == "*")
		{
			contents = (contents * 1L * rhs.contents) % MOD;
		}
		else
		{
			static assert (false);
		}
		return this;
	}

	ref ModInt opOpAssign (string op) (const int rhs)
	in
	{
		assert (0 <= rhs && rhs < MOD);
	}
	body
	{
		mixin (q{this } ~ op ~ q{= ModInt (rhs);});
		return this;
	}

	ModInt opBinary (string op) (const ModInt rhs)
	in
	{
		assert (0 <= rhs.contents && rhs.contents < MOD);
	}
	body
	{
		ModInt res = this;
		mixin (q{res } ~ op ~ q{= rhs;});
		return res;
	}

	ModInt opBinary (string op) (const int rhs)
	in
	{
		assert (0 <= rhs && rhs < MOD);
	}
	body
	{
		ModInt res = this;
		mixin (q{res } ~ op ~ q{= ModInt (rhs);});
		return res;
	}

	string toString () const
	{
		return text (contents);
	}
}

void main ()
{
	int m, d;
	while (readf (" %s %s", &m, &d) > 0)
	{
		readln;
		auto a = readln.strip;
		int n = a.length;
		a = format ("%0*d", n, BigInt (a) - 1);
		auto b = readln.strip;
		assert (n == b.length);

		auto fun (string s)
		{
			auto z = s.map !(x => x - '0').array;
			auto f = new ModInt [] [] (2, m);
			int t = 0;
			int cur = 0;
			foreach (i; 0..n)
			{
				t ^= 1;
				f[t][] = ModInt (0);

				if (cur != NA)
				{
					cur = (cur * BASE) % m;
					foreach (e; 0..z[i])
					{
						if ((i & 1) == (e == d))
						{
							f[t][cur] += 1;
						}
						cur = (cur + 1) % m;
					}
				}
				if ((i & 1) != (z[i] == d))
				{
					cur = NA;
				}

				foreach (r; 0..m)
				{
					int nr = (r * BASE) % m;
					foreach (e; 0..BASE)
					{
						if ((i & 1) == (e == d))
						{
							f[t][nr] += f[!t][r];
						}
						nr = (nr + 1) % m;
					}
				}
				debug {writeln (cur, " ", f[t]);}
			}

			ModInt res = (cur == 0);
			res += f[t][0];
			return res;
		}

		writeln (fun (b) - fun (a));
	}
}

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

immutable int BASE = 10;
immutable int MOD = 1_000_000_007;
immutable int NA = -1;

void main ()
{
	int m, d;
	while (readf (" %s %s", &m, &d) > 0)
	{
		readln;
		auto a = readln.strip;
		int n = a.length;
		a = format ("%0*d", n, BigInt (a) - 1);
		auto b = readln.strip;
		assert (n == b.length);

		auto fun (string s)
		{
			auto z = s.map !(x => x - '0').array;
			auto f = new int [] [] (2, m);
			int t = 0;
			int cur = 0;
			foreach (i; 0..n)
			{
				t ^= 1;
				f[t][] = 0;

				if (cur != NA)
				{
					cur = (cur * BASE) % m;
					foreach (e; 0..z[i])
					{
						if ((i & 1) == (e == d))
						{
							f[t][cur] += 1;
							if (f[t][cur] >= MOD)
							{
								f[t][cur] -=
								    MOD;
							}
						}
						cur = (cur + 1) % m;
					}
				}
				if ((i & 1) != (z[i] == d))
				{
					cur = NA;
				}

				foreach (r; 0..m)
				{
					int nr = (r * BASE) % m;
					foreach (e; 0..BASE)
					{
						if ((i & 1) == (e == d))
						{
							f[t][nr] += f[!t][r];
							if (f[t][nr] >= MOD)
							{
								f[t][nr] -=
								    MOD;
							}
						}
						nr = (nr + 1) % m;
					}
				}
				debug {writeln (cur, " ", f[t]);}
			}

			int res = (cur == 0) + f[t][0];
			if (res >= MOD)
			{
				res -= MOD;
			}
			return res;
		}

		writeln ((fun (b) - fun (a) + MOD) % MOD);
	}
}

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

immutable int BASE = 10;
immutable int MOD = 1_000_000_007;
immutable int NA = -1;

struct ModInt
{
	int contents;
	alias contents this;

	invariant
	{
		assert (0 <= contents && contents < MOD);
	}

	this (int newContents)
	in
	{
		assert (0 <= newContents && newContents < MOD);
	}
	body
	{
		contents = newContents;
	}

	ref ModInt opOpBinary (string op, T) (const T rhs)
	in
	{
		assert (0 <= rhs && rhs < MOD);
	}
	body
	{
		static if (op == "+")
		{
			contents += rhs;
			if (contents >= MOD)
			{
				contents -= MOD;
			}
		}
		else if (op == "-")
		{
			contents -= rhs;
			if (contents < 0)
			{
				contents += MOD;
			}
		}
		else if (op == "*")
		{
			contents = (contents * 1L * rhs) % MOD;
		}
		else
		{
			static assert (false);
		}
		return this;
	}

	ModInt opBinary (string op, T) (const T rhs)
	in
	{
		assert (0 <= rhs && rhs < MOD);
	}
	body
	{
		ModInt res = this;
		mixin (q{res} ~ op ~ q{= rhs;});
		return res;
	}
}

void main ()
{
	int m, d;
	while (readf (" %s %s", &m, &d) > 0)
	{
		readln;
		auto a = readln.strip;
		int n = a.length;
		a = format ("%0*d", n, BigInt (a) - 1);
		auto b = readln.strip;
		assert (n == b.length);

		auto fun (string s)
		{
			auto z = s.map !(x => x - '0').array;
			auto f = new ModInt [] [] (2, m);
			int t = 0;
			int cur = 0;
			foreach (i; 0..n)
			{
				t ^= 1;
				f[t][] = ModInt (0);

				if (cur != NA)
				{
					cur = (cur * BASE) % m;
					foreach (e; 0..z[i])
					{
						if ((i & 1) == (e == d))
						{
							f[t][cur] += 1;
						}
						cur = (cur + 1) % m;
					}
				}
				if ((i & 1) != (z[i] == d))
				{
					cur = NA;
				}

				foreach (r; 0..m)
				{
					int nr = (r * BASE) % m;
					foreach (e; 0..BASE)
					{
						if ((i & 1) == (e == d))
						{
							f[t][nr] += f[!t][r];
						}
						nr = (nr + 1) % m;
					}
				}
				debug {writeln (cur, " ", f[t]);}
			}

			ModInt res = (cur == 0);
			res += f[t][0];
			return res;
		}

		writeln (fun (b) - fun (a));
	}
}


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

long solve(long l, long a, long b)
{
  if (l == 0)
    return 0;
  long x1 = (a + b) * l;
  long x2 = b + l * a;
  return max(x1, x2);
}

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long n, a, b;
    readf!" %d %d %d "(n, a, b);
    auto s = readln.strip.split("").map!(to!int).array;
    long l = 1;
    int i = 1;
    int prev = s[0];
    long[] x;
    long result = 0;
    while (i < n) {
      while (i < n && s[i] == prev) {
        l++;
        i++;
      }
      x ~= l;
      l = 0;
      prev = !prev;
    }
    if (l != 0)
      x ~= l;
    long firstodd = 0;
    long sumodd = 0;
    long firsteven = 0;
    long sumeven = 0;
    foreach (j ; 0 .. x.length) {
      if (j % 2 == 1) {
        firstodd += solve(x[j], a, b);
        sumodd += x[j];
      } else {
        firsteven += solve(x[j], a, b);
        sumeven += x[j];
      }
    }
    firstodd += solve(sumeven, a, b);
    firsteven += solve(sumodd, a, b);
//    writeln(firstodd);
//    writeln(firsteven);
    writeln(max(firstodd, firsteven));
  }
}

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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

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

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RD;
		auto b = RD;
		auto s = RD!string;

		if (b >= 0)
			ans[ti] = (a+b) * n;
		else
		{
			long cnt;
			foreach (i; 1..n)
			{
				if (s[i] != s[i-1])
					++cnt;
			}
			cnt = (cnt+1) / 2 + 1;

			ans[ti] = a * n + b * cnt;
		}
	}

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

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

long solve(long l, long a, long b)
{
  long x1 = (a + b) * l;
  long x2 = b + l * a;
  return max(x1, x2);
}

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long n, a, b;
    readf!" %d %d %d "(n, a, b);
    auto s = readln.strip.split("").map!(to!int).array;
    long l = 1;
    int i = 1;
    int prev = s[0];
    long[] x;
    long result = 0;
    while (i < n) {
      while (i < n && s[i] == prev) {
        l++;
        i++;
      }
      x ~= l;
      l = 0;
      prev = !prev;
    }
    if (l != 0)
      x ~= l;
//    writeln(x);
    long firstodd = 0;
    long sumodd = 0;
    long firsteven = 0;
    long sumeven = 0;
    foreach (j ; 0 .. x.length) {
      if (j % 2 == 1) {
        firstodd += solve(x[j], a, b);
        sumodd += x[j];
      } else {
        firsteven += solve(x[j], a, b);
        sumeven += x[j];
      }
    }
    firstodd += solve(sumeven, a, b);
    firsteven += solve(sumodd, a, b);
//    writeln(firstodd);
//    writeln(firsteven);
    writeln(max(firstodd, firsteven));
  }
}

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

long solve(long l, long a, long b)
{
  long x1 = (a + b) * l;
  long x2 = b + l * a;
  return max(x1, x2);
}

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long n, a, b;
    readf!" %d %d %d "(n, a, b);
    auto s = readln.strip.split("").map!(to!int).array;
    long l = 1;
    int i = 1;
    int prev = s[0];
    long[] x;
    long result = 0;
    while (i < n) {
      while (i < n && s[i] == prev) {
        l++;
        i++;
      }
      x ~= l;
      l = 0;
      prev = !prev;
    }
    long firstodd = 0;
    long sumodd = 0;
    long firsteven = 0;
    long sumeven = 0;
    foreach (j ; 0 .. x.length) {
      if (j % 2 == 1) {
        firstodd += solve(x[j], a, b);
        sumodd += x[j];
      } else {
        firsteven += solve(x[j], a, b);
        sumeven += x[j];
      }
    }
    firstodd += solve(sumeven, a, b);
    firsteven += solve(sumodd, a, b);
    writeln(max(firstodd, firsteven));
  }
}

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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

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

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RD;
		auto b = RD;
		auto s = RD!string;

		if (b >= 0)
			ans[ti] = (a+b) * n;
		else
		{
			long cnt;
			foreach (i; 1..n)
			{
				if (s[i] != s[i-1])
					++cnt;
			}
			if (cnt <= 1)
				++cnt;

			ans[ti] = a * n + b * cnt;
		}
	}

	foreach (e; ans)
	{
		writeln(e);
	}
	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)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

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

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RD;
		auto b = RD;
		auto s = RD!string;

		if (b >= 0)
			ans[ti] = (a+b) * n;
		else
		{
			long cnt;
			foreach (i; 1..n)
			{
				if (s[i] != s[i-1])
					++cnt;
			}
			cnt.chmax(1);

			ans[ti] = a * n + b * cnt;
		}
	}

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


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

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		real [] m;
		m ~= 1;
		real res = 0;
		foreach (i; 0..n)
		{
			auto command = readln.split;
			if (command[0] == "add")
			{
				res += m.back;
			}
			else if (command[0] == "for")
			{
				m ~= m.back * command[1].to !(int);
			}
			else if (command[0] == "end")
			{
				m.popBack ();
				m.assumeSafeAppend ();
			}
			else
			{
				assert (false);
                        }
		}
		if (res >= (1L << 32))
		{
			writeln ("OVERFLOW!!!");
		}
		else
		{
			writefln ("%.0f", res);
		}
	}
}

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

alias T = Tuple!(int, ulong);

void overflow () {
  writeln ("OVERFLOW!!!");
}

void main() {
  string s;
  readf!" %s" (s);
  auto z = s.splitter;
  string rs () {
    auto r = z.front;
    z.popFront ();
    return r;
  }
  immutable ulong m = 1L << 32;

  immutable l = rs().strip().to!int;
  auto st = new T[5 * l];
  int k;
  foreach (qid; 0 .. l) {
    auto t = rs ();
    if (t[0] == 'a') {
      st[k++] = tuple (1, 1);
    } else if (t[0] == 'f') {
      st[k++] = tuple (2, rs().strip().to!ulong);
    } else if (t[0] == 'e') {
      ulong x;
      while (st[k-1][0] != 2) {
        x += st[k-1][1];
        if (x >= m) {
          overflow ();
          return;
        }
        --k;
      }
      x *= st[k-1][1];
      if (x >= m) {
        overflow ();
        return;
      }
      st[k-1] = tuple (1, x);
    }
  }
  ulong y;
  foreach (i; 0 .. k) {
    y += st[i][1];
    if (y >= m) {
      overflow ();
      return;
    }
  }
  writeln (y);
}

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

void solve(){

	int l = read.to!int;

	long infty = 1L<<32;

	long[] depths = [1];
	long ans;
	foreach(_; 0 .. l){

		string cmd = read;
		if(cmd == "for"){
			long val = read.to!long;
			long d = depths[$ - 1] * val;
			if(d >= infty) d = infty;

			depths ~= d;
		}
		else if(cmd == "add"){
			long d = depths[$ - 1];
			ans += d;
			if(ans >= infty){
				"OVERFLOW!!!".writeln;
				return;
			}
		}
		else if(cmd == "end"){
			depths.length -= 1;
		}

	}
	ans.writeln;
}

import std.typecons;

import core.stdc.stdio : scanf;
import std.stdio;
import std.algorithm;
import std.range;
import std.bigint;

alias PII = Tuple!(int, int);
alias PLL = Tuple!(long, long);

void main() {

    long n;

    scanf("%d\n", &n);

    long x = 0;

    long[] stack;

    stack ~= 1L;

    long INF = (1L << 32);

    foreach (cmd; 0 .. n) {
        char[100] c;
        scanf("%s", &c);
        if (c[0] == 'a') {
            x = x + stack.back;
            if (x >= INF) {
                writeln("OVERFLOW!!!");
                return;
            }
        }

        if (c[0] == 'f') {
            long tt;
            scanf("%lld\n", &tt);
            stack ~= stack.back * tt;
            if (stack.back >= INF)
                stack.back = INF;

        }

        if (c[0] == 'e') {
            stack.popBack();
        }
    }

    writeln(x);
}

import std.typecons;

// import core.stdc.stdio;
import std.stdio;
import std.algorithm;
import std.range;
import std.bigint;

alias PII = Tuple!(int, int);
alias PLL = Tuple!(long, long);

void main() {

    long n;

    stdin.readf("%d", n);

    BigInt x;

    BigInt[] stack;

    stack ~= BigInt(1);

    foreach (cmd; 0 .. n) {
        string c = stdin.readln();
        if (c[0] == 'a') {
            x = x + stack.back;
            if (x > (1L << 32) - 1) {
                writeln("OVERFLOW!!!");
                return;
            }
        }

        if (c[0] == 'f') {
            auto t = BigInt(c.split[1]);
            // writeln(t);
            stack ~= stack.back * t;
        }

        if (c[0] == 'e') {
            stack.popBack();
        }
    }

    writeln(x);
}


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!long);
    auto R = s[0];
    auto D = s[1];
    auto C = R - D;
    auto N = readln.chomp.to!int;

    bool ok1(long x, long y, long r) {
        return x * x + y * y >= (r + C) * (r + C);
    }

    bool ok2(long x, long y, long r) {
        return x * x + y * y <= (r - R) * (r - R);
    }

    int ans = 0;
    while (N--) {
        s = readln.split.map!(to!long);
        auto x = s[0];
        auto y = s[1];
        auto r = s[2];
        ans += ok1(x, y, r) && ok2(x, y, r);
    }

    ans.writeln;
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
import std.stdio      : readln, writeln;
import std.array      : split;
import std.string     : chomp;
import std.conv       : to;
import std.math       : sqrt;

auto gets() { return readln.chomp; }
auto getVals(T)() { return gets.split.to!(T[]); }

void main() {
    auto rd = getVals!double;
    auto r = rd[0], d = rd[1];
    auto n = gets.to!int;
    auto ans = 0;
    for (auto i = 0; i < n; i++) {
        auto xyr = getVals!double;
        auto xi = xyr[0], yi = xyr[1], ri = xyr[2];
        auto di = sqrt(xi * xi + yi * yi);
        if (di + ri <= r && di - ri >= r - d) {
            ans++;
        }
    }
    writeln(ans);
}


import std;

int t,n;
uint k;
static const uint N = 500007;

struct node {
    uint l, r, id;
    int opCmp(ref const node rhs) const {
        if (r == rhs.r)
            return l > rhs.l ? -1 : 1;
        return r < rhs.r ? -1 : 1;
    }
}

node[N] q;
uint[N] a, ans, f;
bool[N] st;

uint find(uint x) {
    if (x == f[x])
        return f[x];
    return f[x] = find(f[x]);
}

void main()
{
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        scanf("%d", &n);
        getchar();
        foreach(i; 1 .. (n + 1)) {
            f[i] = i;
            st[i] = false;
            scanf("%u", &k);
            a[i] = k;
        }
        foreach(i; 1 .. (n + 1)) {
            if (a[i] == 0)
                q[i] = node(i+1,n,i);
            else
                q[i] = node(i/(a[i]+1)+1,i/a[i],i);
        }
        sort!"a < b"(q[1..n+1]).array;
        foreach(i;1 .. (n + 1)) {
            uint l = find(q[i].l);
            while(st[l]) {
                f[l] = find(l + 1);
                l = find(q[i].l);
            }
            ans[q[i].id] = l;
            st[l] = true;
        }
        writefln("%(%s %)", ans[1..n+1]);
    }
}

import std;

int t,n;
uint k;
static const uint N = 500007;

struct node {
    uint l, r, id;
    int opCmp(ref const node rhs) const {
        if (r == rhs.r)
            return l > rhs.l ? -1 : 1;
        return r < rhs.r ? -1 : 1;
    }
}

node[N] q;
uint[N] a, ans, f;
bool[N] st;

uint find(uint x) {
    if (x == f[x])
        return f[x];
    return f[x] = find(f[x]);
}

void main()
{
    import core.stdc.stdio;

    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        scanf("%d", &n);
        getchar();
        foreach(i; 1 .. (n + 1)) {
            f[i] = i;
            st[i] = false;
            scanf("%u", &k);
            a[i] = k;
        }
        foreach(i; 1 .. (n + 1)) {
            if (a[i] == 0)
                q[i] = node(i+1,n,i);
            else
                q[i] = node(i/(a[i]+1)+1,i/a[i],i);
        }
        sort!"a < b"(q[1..n+1]).array;
        foreach(i;1 .. (n + 1)) {
            uint l = find(q[i].l);
            while(st[l]) {
                f[l] = find(l + 1);
                l = find(q[i].l);
            }
            ans[q[i].id] = l;
            st[l] = true;
        }
        for(int i = 1;i<=n;i++)
            printf("%d ", ans[i]);
        printf("\n");
        //writefln("%(%s %)", ans[1..n+1]);
    }
}

import std;

int t,n;
uint k;
static const uint N = 500007;

struct node {
    uint l, r, id;
    int opCmp(ref const node rhs) const {
        if (r == rhs.r)
            return l > rhs.l ? -1 : 1;
        return r < rhs.r ? -1 : 1;
    }
}

node[N] q;
uint[N] a, ans, f;
bool[N] st;

uint find(uint x) {
    if (x == f[x])
        return f[x];
    return f[x] = find(f[x]);
}

void main()
{
    import std.outbuffer: OutBuffer;

    OutBuffer buf = new OutBuffer();

    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        scanf("%d", &n);
        getchar();
        foreach(i; 1 .. (n + 1)) {
            f[i] = i;
            st[i] = false;
            scanf("%u", &k);
            a[i] = k;
        }
        foreach(i; 1 .. (n + 1)) {
            if (a[i] == 0)
                q[i] = node(i+1,n,i);
            else
                q[i] = node(i/(a[i]+1)+1,i/a[i],i);
        }
        sort!"a < b"(q[1..n+1]).array;
        foreach(i;1 .. (n + 1)) {
            uint l = find(q[i].l);
            while(st[l]) {
                f[l] = find(l + 1);
                l = find(q[i].l);
            }
            ans[q[i].id] = l;
            st[l] = true;
        }
        buf.writefln("%(%s %)", ans[1..n+1]);
    }
    write(buf.toString());
}

import std;

int t,n;
uint k;
static const uint N = 500007;

struct node {
    uint l, r, id;
    bool opCmp(node rhs) const {
        if (r == rhs.r)
            return l > rhs.l;
        return r < rhs.r;
    }
}

node[N] q;
uint[N] a, ans, f;
bool[N] st;

uint find(uint x) {
    if (x == f[x])
        return f[x];
    f[x] = find(f[x]);
    return f[x];
}

void main()
{
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        scanf("%d", &n);
        getchar();
        foreach(i; 1 .. (n + 1)) {
            f[i] = i;
            st[i] = false;
            scanf("%u", &k);
            a[i] = k;
        }
        foreach(i; 1 .. (n + 1))
            if (a[i] == 0L)
                q[i] = node(i+1,n,i);
            else
                q[i] = node(i/(a[i]+1)+1,i/a[i],i);
        q[1..n+1].sort();
        foreach(i;1 .. (n + 1)) {
            uint l = find(q[i].l);
            while(st[l]) {
                f[l] = find(l + 1);
                l = find(q[i].l);
            }
            ans[q[i].id] = l;
            st[l] = true;
        }
        writefln("%(%s %)", ans[1..n+1]);
    }
}


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

int n;
int[] a;

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

    int[] leftmin = new int[](n);
    auto st = Stack!int(n + 10);

    foreach (i ; 0 .. n) {
        while (!st.empty && a[st.top] > a[i]) st.pop;

        leftmin[i] = (st.empty ? -1 : st.top);
        st.push(i);
    }

    st.clear;

    int[] rightmin = new int[](n);

    foreach_reverse (i ; 0 .. n) {
        while (!st.empty && a[st.top] >= a[i]) st.pop;

        rightmin[i] = (st.empty ? n : st.top);
        st.push(i);
    }

    st.clear;

    int[] leftmax = new int[](n);

    foreach (i ; 0 .. n) {
        while (!st.empty && a[st.top] < a[i]) st.pop;

        leftmax[i] = (st.empty ? -1 : st.top);
        st.push(i);
    }

    st.clear;

    int[] rightmax = new int[](n);

    foreach_reverse (i ; 0 .. n) {
        while (!st.empty && a[st.top] <= a[i]) st.pop;

        rightmax[i] = (st.empty ? n : st.top);
        st.push(i);
    }

    long ans;

    foreach (i ; 0 .. n) {
        ans += 1L * (i - leftmax[i]) * (rightmax[i] - i) * a[i];
        ans -= 1L * (i - leftmin[i]) * (rightmin[i] - i) * a[i];
    }

    writeln(ans);
}

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

struct Stack(T) {
private:
    int N, peek;
    T[] data;

public:
    this(int size)
    {
        N = size;
        data = new T[](N);
    }

    bool empty() @property
    {
        return peek == 0;
    }

    bool full() @property
    {
        return peek == N;
    }

    void push(T x) @property
    {
        assert(!full);
        data[peek++] = x;
    }

    void pop() @property
    {
        assert(!empty);
        --peek;
    }

    T top() @property
    {
        return data[peek - 1];
    }

    void clear() @property
    {
        peek = 0;
    }

    int length() @property
    {
        return peek;
    }

}

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

immutable int mod = 10^^9 + 7;

int n;
int[] a;

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

    auto leftmin = new int[](n);
    auto rightmin = new int[](n);
    auto stack = new Stack!int(n + 10);

    //debug stack.empty.writeln;

    foreach (i ; 0 .. n) {
        while (!stack.empty && a[stack.top] > a[i]) {
            //debug {writeln("i:", i, " ", "stack top:", stack.front);}
            stack.pop;
        }

        if (stack.empty) {
            leftmin[i] = -1;
        }
        else {
            //debug {writeln("i:", i, " ", "stack top:", stack.front);}
            leftmin[i] = stack.top;
        }

        debug {
            //writeln("leftmin:", leftmin);
        }
        stack.push(i);
    }

    stack.clear;
    //debug stack.empty.writeln;

    foreach_reverse (i ; 0 .. n) {
        while (!stack.empty && a[stack.top] >= a[i]) {
            stack.pop;
        }

        if (stack.empty) rightmin[i] = n;
        else rightmin[i] = stack.top;

        stack.push(i);
    }

    stack.clear;

    debug {
        writeln("leftmin:", leftmin);
        writeln("rightmin", rightmin);
    }

    auto leftmax = new int[](n);
    auto rightmax = new int[](n);
    stack.clear;

    foreach (i ; 0 .. n) {
        while (!stack.empty && a[stack.top] < a[i]) stack.pop;

        leftmax[i] = (stack.empty ? -1 : stack.top);
        stack.push(i);
    }

    stack.clear;

    foreach_reverse (i ; 0 .. n) {
        while (!stack.empty && a[stack.top] <= a[i]) stack.pop;

        rightmax[i] = (stack.empty ? n : stack.top);
        stack.push(i);
    }

    debug {
        writeln("leftmax:", leftmax);
        writeln("rightmax:", rightmax);
    }

    long ans, v;

    foreach (i ; 0 .. n) {
        v = (i - leftmin[i]).to!long * (rightmin[i] - i) * a[i];
        ans -= v;
        v = (i - leftmax[i]).to!long * (rightmax[i] - i) * a[i];
        ans += v;
    }

    writeln(ans);
}

class Stack(T) {
    private:
    int N, peek;
    T[] data;

    public:
    this(int size) {
        N = size;
        data = new T[](N);
    }

    bool empty() @property {
        return peek == 0;
    }

    bool full() @property {
        return peek == N;
    }

    void push(T x) {
        if (full) throw new Exception("Stack is Full.");
        data[peek++] = x;
    }

    void pop() @property {
        if (empty) throw new Exception("Stack is Empty.");
        --peek;
    }

    T top() @property {
        if (empty) throw new Exception("Stack is Empty.");
        return data[peek - 1];
    }

    void clear() @property
    {
        peek = 0;
    }
}

unittest {
    auto st = new Stack!int(5);
    assert(st.empty);
    st.push(3);
    st.push(1);
    st.push(4);
    st.push(1);
    st.push(5);
    assert(st.full);
    assert(st.top == 5);
    st.pop;
    assert(st.top == 1);
    st.pop;
    assert(st.top == 4);
    st.pop;
    st.pop;
    assert(st.top == 3);
    st.pop;
    assert(st.empty);

    st.push(3);
    st.push(5);
    st.push(100);

    assert(!st.empty);

    st.clear;

    assert(st.empty);

    st.push(5);
    st.push(1);

    assert(st.top == 1);
    st.pop;
    assert(st.top == 5);
    st.pop;

    assert(st.empty);

    stderr.writeln("Unittest has passed.");
}

void readVariables(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg ; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if (!line.empty) {
        throw new Exception("args num < input num");
    }
}

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

immutable int mod = 10^^9 + 7;

int n;
int[] a;

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

    auto leftmin = new int[](n);
    auto rightmin = new int[](n);
    auto stack = new SList!(int)();

    //debug stack.empty.writeln;

    foreach (i ; 0 .. n) {
        while (!stack.empty && a[stack.front] > a[i]) {
            //debug {writeln("i:", i, " ", "stack top:", stack.front);}
            stack.removeFront;
        }

        if (stack.empty) {
            leftmin[i] = -1;
        }
        else {
            //debug {writeln("i:", i, " ", "stack top:", stack.front);}
            leftmin[i] = stack.front;
        }

        debug {
            //writeln("leftmin:", leftmin);
        }
        stack.insert(i);
    }

    stack.clear;
    //debug stack.empty.writeln;

    foreach_reverse (i ; 0 .. n) {
        while (!stack.empty && a[stack.front] >= a[i]) {
            stack.removeFront;
        }

        if (stack.empty) rightmin[i] = n;
        else rightmin[i] = stack.front;

        stack.insert(i);
    }

    stack.clear;

    debug {
        writeln("leftmin:", leftmin);
        writeln("rightmin", rightmin);
    }

    auto leftmax = new int[](n);
    auto rightmax = new int[](n);
    stack.clear;

    foreach (i ; 0 .. n) {
        while (!stack.empty && a[stack.front] < a[i]) stack.removeFront;

        leftmax[i] = (stack.empty ? -1 : stack.front);
        stack.insert(i);
    }

    stack.clear;

    foreach_reverse (i ; 0 .. n) {
        while (!stack.empty && a[stack.front] <= a[i]) stack.removeFront;

        rightmax[i] = (stack.empty ? n : stack.front);
        stack.insert(i);
    }

    debug {
        writeln("leftmax:", leftmax);
        writeln("rightmax:", rightmax);
    }

    long ans, v;

    foreach (i ; 0 .. n) {
        v = (i - leftmin[i]).to!long * (rightmin[i] - i) * a[i];
        ans -= v;
        v = (i - leftmax[i]).to!long * (rightmax[i] - i) * a[i];
        ans += v;
    }

    writeln(ans);
}

void readVariables(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg ; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if (!line.empty) {
        throw new Exception("args num < input num");
    }
}

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

immutable int mod = 10^^9 + 7;

int n;
int[] a;

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

    Stack!int st = Stack!int(n + 10);

    auto leftmin = new int[](n);

    foreach (i ; 0 .. n) {
        while (!st.empty && a[st.top] > a[i]) st.pop;

        leftmin[i] = (st.empty ? -1 : st.top);
        st.push(i);
    }

    st.clear;

    auto rightmin = new int[](n);

    foreach_reverse (i ; 0 .. n) {
        while (!st.empty && a[st.top] >= a[i]) st.pop;

        rightmin[i] = (st.empty ? n : st.top);
        st.push(i);
    }

    st.clear;

    auto leftmax = new int[](n);

    foreach (i ; 0 .. n) {
        while (!st.empty && a[st.top] < a[i]) st.pop;

        leftmax[i] = (st.empty ? -1 : st.top);
        st.push(i);
    }

    st.clear;

    auto rightmax = new int[](n);

    foreach_reverse (i ; 0 .. n) {
        while (!st.empty && a[st.top] <= a[i]) st.pop;

        rightmax[i] = (st.empty ? n : st.top);
        st.push(i);
    }

    long ans;

    foreach (i ; 0 .. n) {
        ans += 1L * (i - leftmax[i]) * (rightmax[i] - i) * a[i];
        ans -= 1L * (i - leftmin[i]) * (rightmin[i] - i) * a[i];
    }

    writeln(ans);
}

struct Stack(T) {
private:
    int N, peek;
    T[] data;

public:
    this(int size)
    {
        N = size;
        data = new T[](N);
    }

    bool empty() @property
    {
        return peek == 0;
    }

    bool full() @property
    {
        return peek == N;
    }

    void push(T x) @property
    {
        assert(!full);
        data[peek++] = x;
    }

    void pop() @property
    {
        assert(!empty);
        --peek;
    }

    T top() @property
    {
        return data[peek - 1];
    }

    void clear() @property
    {
        peek = 0;
    }

}

void readVariables(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg ; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if (!line.empty) {
        throw new Exception("args num < input num");
    }
}

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

immutable int mod = 10^^9 + 7;

int n;
int[] a;

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

    auto pmini = new int[](n);
    auto pmaxi = new int[](n);

    int maxa = a[0], mina = a[0];

    foreach (i ; 1 .. n) {
        pmini[i] = pmini[i - 1];
        pmaxi[i] = pmaxi[i - 1];

        if (a[i] > maxa) {
            maxa = a[i];
            pmaxi[i] = i;
        }

        if (a[i] < mina) {
            mina = a[i];
            pmini[i] = i;
        }
    }

    debug {
        writeln("pmini:",pmini);
        writeln("pmaxi:",pmaxi);
    }

    auto smini = new int[](n);
    auto smaxi = new int[](n);

    smini[n - 1] = n - 1;
    smaxi[n - 1] = n - 1;

    maxa = a[n - 1], mina = a[n - 1];

    foreach_reverse (i ; 0 .. n - 1) {
        smini[i] = smini[i + 1];
        smaxi[i] = smaxi[i + 1];

        if (a[i] >= maxa) {
            maxa = a[i];
            smaxi[i] = i;
        }

        if (a[i] <= mina) {
            mina = a[i];
            smini[i] = i;
        }
    }

    debug {
        writeln("smini:", smini);
        writeln("smaxi:", smaxi);
    }

    long ans, v;

    int j, k;

    foreach (i ; 0 .. n) {

        if (i == pmaxi[i])
            j = binsearch1(smaxi, i);
        else
            j = i;

        if (i == pmaxi[i])
            k = binsearch2(pmaxi, i);
        else
            k = i;

        debug {
            //writeln(j, " ", i, " ", k);
        }

        ans += (i - j + 1).to!long * (k - i + 1) * a[i];

        if (i == smini[i])
            j = binsearch1(smini, i);
        else
            j = i;

        if (i == pmini[i])
            k = binsearch2(pmini, i);
        else
            k = i;

        ans -= (i - j + 1).to!long * (k - i + 1) * a[i];
    }

    assert(ans >= 0);

    writeln(ans);
}

int binsearch1(int[] s, int i) {
    int btm, top, mid;
    btm = -1;
    top = i;

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

        if (s[mid] == s[i]) {
            top = mid;
        }
        else {
            btm = mid;
        }
    }

    return top;
}

int binsearch2(int[] s, int i) {
    int btm, top, mid;
    btm = i;
    top = n;

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

        if (s[mid] == s[i]) {
            btm = mid;
        }
        else {
            top = mid;
        }
    }

    return btm;
}

void readVariables(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg ; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if (!line.empty) {
        throw new Exception("args num < input num");
    }
}

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

immutable int mod = 10^^9 + 7;

int n;
int[] a;

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

    auto pmini = new int[](n);
    auto pmaxi = new int[](n);

    int maxa = a[0], mina = a[0];

    foreach (i ; 1 .. n) {
        pmini[i] = pmini[i - 1];
        pmaxi[i] = pmaxi[i - 1];

        if (a[i] > maxa) {
            maxa = a[i];
            pmaxi[i] = i;
        }

        if (a[i] < mina) {
            mina = a[i];
            pmini[i] = i;
        }
    }

    debug {
        writeln("pmini:",pmini);
        writeln("pmaxi:",pmaxi);
    }

    auto smini = new int[](n);
    auto smaxi = new int[](n);

    smini[n - 1] = n - 1;
    smaxi[n - 1] = n - 1;

    maxa = a[n - 1], mina = a[n - 1];

    foreach_reverse (i ; 0 .. n - 1) {
        smini[i] = smini[i + 1];
        smaxi[i] = smaxi[i + 1];

        if (a[i] >= maxa) {
            maxa = a[i];
            smaxi[i] = i;
        }

        if (a[i] <= mina) {
            mina = a[i];
            smini[i] = i;
        }
    }

    debug {
        writeln("smini:", smini);
        writeln("smaxi:", smaxi);
    }

    long ans, v;

    int j, k;

    foreach (i ; 0 .. n) {

        if (i == pmaxi[i])
            j = binsearch1(smaxi, i);
        else
            j = i;

        if (i == pmaxi[i])
            k = binsearch2(pmaxi, i);
        else
            k = i;

        debug {
            writeln(j, " ", i, " ", k);
        }

        ans += (i - j + 1).to!long * (k - i + 1) * a[i];

        if (i == smini[i])
            j = binsearch1(smini, i);
        else
            j = i;

        if (i == pmini[i])
            k = binsearch2(pmini, i);
        else
            k = i;

        debug {

        }

        ans -= (i - j + 1).to!long * (k - i + 1) * a[i];
    }

    writeln(ans);
}

int binsearch1(int[] s, int i) {
    int btm, top, mid;
    btm = -1;
    top = i;

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

        if (s[mid] == s[i]) {
            top = mid;
        }
        else {
            btm = mid;
        }
    }

    return top;
}

int binsearch2(int[] s, int i) {
    int btm, top, mid;
    btm = i;
    top = n;

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

        if (s[mid] == s[i]) {
            btm = mid;
        }
        else {
            top = mid;
        }
    }

    return btm;
}

void readVariables(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg ; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if (!line.empty) {
        throw new Exception("args num < input num");
    }
}


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 s = readln.strip;
		auto res = s.count ('0') * 1L * s.count ('1');
		res = max (res,
		    s.group.map !(c => c[1]).maxElement.to !(long) ^^ 2);
		writeln (res);
	}
}

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

// Lengths of sequences satisfying the condition (moving to the right)
int[] seq_length_right(alias less = "a < b", T)(T[] a)
{
  if (a.length == 0)
    return new int[](0);
  auto tmp = new int[](a.length);
  int count = 1;
  tmp[$ - 1] = count;
  foreach_reverse (i ; 0 .. a.length - 1) {
    if (binaryFun!less(a[i], a[i + 1]))
      count++;
    else
      count = 1;
    tmp[i] = count;
  }
  return tmp;
}

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto n = readln.strip.to!long;
    auto s = readln.strip;
    auto a = s.seq_length_right!"a==b";
    long x = s.count('0');
    long y = s.count('1');
    long z = a.maxElement;
    writeln(max(x * y, z * z));
  }
}

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

// Lengths of sequences satisfying the condition (moving to the right)
int[] seq_length_right(alias less = "a < b", T)(T[] a)
{
  if (a.length == 0)
    return new int[](0);
  auto tmp = new int[](a.length);
  int count = 1;
  tmp[$ - 1] = count;
  foreach_reverse (i ; 0 .. a.length - 1) {
    if (binaryFun!less(a[i], a[i + 1]))
      count++;
    else
      count = 1;
    tmp[i] = count;
  }
  return tmp;
}

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto n = readln.strip.to!long;
    auto s = readln.strip;
    auto a = s.seq_length_right!"a==b";
    auto x = s.count('0');
    auto y = s.count('1');
    writeln(max(cast(long)x * y, cast(long)a.maxElement * a.maxElement));
  }
}

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

// Lengths of sequences satisfying the condition (moving to the right)
int[] seq_length_right(alias less = "a < b", T)(T[] a)
{
  if (a.length == 0)
    return new int[](0);
  auto tmp = new int[](a.length);
  int count = 1;
  tmp[$ - 1] = count;
  foreach_reverse (i ; 0 .. a.length - 1) {
    if (binaryFun!less(a[i], a[i + 1]))
      count++;
    else
      count = 1;
    tmp[i] = count;
  }
  return tmp;
}

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto n = readln.strip.to!long;
    auto s = readln.strip;
    auto a = s.seq_length_right!"a==b";
    auto x = s.count('0');
    auto y = s.count('1');
    writeln(max(x * y, a.maxElement * a.maxElement));
  }
}


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

void play(){
    int n, x;
    n = rd!int; x = rd!int;
    ll[] a =  rdarr;
    ll[] b = rdarr;
    a.sort;
    b.sort;
    b.reverse;
    foreach(i; 0..n){
        if(a[i] + b[i] > x){
            writeln("No");
            return;
        }
    }
    writeln("Yes");
}

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

/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }
void show(A...)(A a) { debug{ foreach(t; a){ write(t, "| "); } writeln; } }
alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, "x",  long, "y");
T max(T = long)(T a, T b){ return (a > b) ? a : b; }
T min(T = long)(T a, T b){ return (a < b) ? a : b; }

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

void main () {
    int t;
	readf("%d\n", &t);
	while(t--) {
		int n, x;
		readf("%d %d\n", &n, &x);
		auto a = readln.split.to!(int[]);
		auto b = readln.split.to!(int[]);
		sort(a);
		sort(b);
		auto result = true;
		for(int i = 0; i < n; i++) {
			if(a[i] + b[n-i-1] > x) {
				result = false;
				break;
			}
		}
		if(result)
			writeln("Yes");
		else
			writeln("No");

		if(t)
			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)
	{
		int n, x;
		readf !(" %s %s") (n, x);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto b = readln.splitter.map !(to !(int)).array;
		sort !(q{a < b}) (a);
		sort !(q{a > b}) (b);
		auto res = zip (a, b).all !(p => p[0] + p[1] <= x);
		writeln (res ? "Yes" : "No");
	}
}


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

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto Q = s[1];
    auto C = s[2];
    auto X = new int[](N);
    auto Y = new int[](N);
    auto S = new int[](N);
    foreach (i; 0..N) {
        s = readln.split.map!(to!int);
        X[i] = s[0];
        Y[i] = s[1];
        S[i] = s[2];
    }

    auto A = new int[][][](C + 1, 110, 110);
    foreach (t; 0..C+1) {
        foreach (i; 0..N) {
            A[t][X[i] + 1][Y[i] + 1] += (S[i] + t) % (C + 1);
        }
    }

    foreach (t; 0..C+1)
        foreach (i; 0..102)
            foreach (j; 0..102)
                A[t][i][j + 1] += A[t][i][j];
    foreach (t; 0..C+1)
        foreach (j; 0..102)
            foreach (i; 0..102)
                A[t][i + 1][j] += A[t][i][j];

    int cumsum(int t, int x1, int y1, int x2, int y2) {
        return A[t][x2 + 1][y2 + 1] - A[t][x2 + 1][y1] - A[t][x1][y2 + 1] + A[t][x1][y1];
    }

    while (Q--) {
        s = readln.split.map!(to!int);
        auto t = s[0] % (C + 1);
        auto x1 = s[1];
        auto y1 = s[2];
        auto x2 = s[3];
        auto y2 = s[4];
        cumsum(t, x1, y1, x2, y2).writeln;
    }
}

// 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;
import std.datetime, std.bigint;

immutable lim = 110;
int n, q, c;

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

    auto star = new int[][][](c + 1, lim, lim);

    int xi, yi, si;

    foreach (i ; 0 .. n) {
        scan(xi, yi, si);
        star[si][xi][yi]++;
    }

    foreach (k ; 0 .. c + 1) {
        foreach (i ; 1 .. lim) {
            foreach (j ; 1 .. lim) {
                star[k][i][j] += star[k][i - 1][j] + star[k][i][j - 1] - star[k][i - 1][j - 1];
            }
        }
    }

    int acc2d(int k, int x1, int y1, int x2, int y2) {
        return star[k][x2][y2] - star[k][x2][y1 - 1] - star[k][x1 - 1][y2] + star[k][x1 - 1][y1 - 1];
    }

    int ti, x1i, y1i, x2i, y2i;

    foreach (qi ; 0 .. q) {
        scan(ti, x1i, y1i, x2i, y2i);

        int ans;

        foreach (k ; 0 .. c + 1) {
            int p = (k + ti) % (c + 1);
            ans += acc2d(k, x1i, y1i, x2i, y2i) * p;
        }

        writeln(ans);
    }
}

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

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

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

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto Q = s[1];
    auto C = s[2];
    auto X = new int[](N);
    auto Y = new int[](N);
    auto S = new int[](N);
    foreach (i; 0..N) {
        s = readln.split.map!(to!int);
        X[i] = s[0];
        Y[i] = s[1];
        S[i] = s[2];
    }

    auto A = new int[][][](C + 1, 110, 110);
    foreach (t; 0..C+1) {
        foreach (i; 0..N) {
            A[t][X[i] + 1][Y[i] + 1] += (S[i] + t) % (C + 1);
        }
    }

    foreach (t; 0..C+1)
        foreach (i; 0..102)
            foreach (j; 0..102)
                A[t][i][j + 1] += A[t][i][j];
    foreach (t; 0..C+1)
        foreach (j; 0..102)
            foreach (i; 0..102)
                A[t][i + 1][j] += A[t][i][j];

    int cumsum(int t, int x1, int y1, int x2, int y2) {
        return A[t][x2 + 1][y2 + 1] - A[t][x2 + 1][y1] - A[t][x1][y2 - 1] + A[t][x1][y1];
    }

    while (Q--) {
        s = readln.split.map!(to!int);
        auto t = s[0] % (C + 1);
        auto x1 = s[1];
        auto y1 = s[2];
        auto x2 = s[3];
        auto y2 = s[4];
        cumsum(t, x1, y1, x2, y2).writeln;
    }
}

// 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;
import std.datetime, std.bigint;

immutable lim = 110;

int n, q, c;

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

    auto kido = new int[][][](c + 1, lim, lim);
    auto exst = new bool[][](lim, lim);

    int xi, yi, si;

    foreach (i ; 0 .. n) {
        scan(xi, yi, si);
        kido[0][xi][yi] = si;
        exst[xi][yi] = true;
    }

    foreach (k ; 0 .. c) {
        foreach (i ; 0 .. lim) {
            foreach (j ; 0 .. lim) {
                if (exst[i][j]) {
                    kido[k + 1][i][j] = (kido[k][i][j] + 1) % (c + 1);
                }
            }
        }
    }

    foreach (k; 0 .. c + 1) {
        foreach (i ; 0 .. lim) {
            foreach (j ; 0 .. lim - 1) {
                kido[k][i][j + 1] += kido[k][i][j];
            }
        }

        foreach (j ; 0 .. lim) {
            foreach (i ; 0 .. lim - 1) {
                kido[k][i + 1][j] += kido[k][i][j];
            }
        }
    }

    int ti, x1i, y1i, x2i, y2i;

    foreach (qi ; 0 .. q) {
        scan(ti, x1i, y1i, x2i, y2i);
        ti %= (c + 1);

        int ans;
        ans += kido[ti][x2i][y2i];
        ans -= kido[ti][x2i][y1i - 1];
        ans -= kido[ti][x1i - 1][y2i];
        ans += kido[ti][x1i - 1][y1i - 1];

        writeln(ans);
    }
}

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

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

// 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;
import std.datetime, std.bigint;

immutable lim = 110;

int n, q, c;

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

    auto kido = new int[][][](c + 1, lim, lim);
    auto exst = new bool[][](lim, lim);

    int xi, yi, si;

    foreach (i ; 0 .. n) {
        scan(xi, yi, si);

        if (exst[xi][yi]) {
            writeln("Error");
            return;
        }

        kido[0][xi][yi] = si;
        exst[xi][yi] = true;
    }

    foreach (k ; 0 .. c) {
        foreach (i ; 0 .. lim) {
            foreach (j ; 0 .. lim) {
                if (exst[i][j]) {
                    kido[k + 1][i][j] = (kido[k][i][j] + 1) % (c + 1);
                }
            }
        }
    }

    debug {
        foreach (k ; 0 .. c + 1) {
            writefln("%(%(%s %)\n%)", kido[k]);
            writeln;
        }
    }

    foreach (k; 0 .. c + 1) {
        foreach (i ; 0 .. lim) {
            foreach (j ; 0 .. lim - 1) {
                kido[k][i][j + 1] += kido[k][i][j];
            }
        }

        foreach (j ; 0 .. lim) {
            foreach (i ; 0 .. lim - 1) {
                kido[k][i + 1][j] += kido[k][i][j];
            }
        }
    }

    int ti, x1i, y1i, x2i, y2i;

    foreach (qi ; 0 .. q) {
        scan(ti, x1i, y1i, x2i, y2i);
        ti %= (c + 1);

        int ans;
        ans += kido[ti][x2i][y2i];
        ans -= kido[ti][x2i][y1i - 1];
        ans -= kido[ti][x1i - 1][y2i];
        ans += kido[ti][x1i - 1][y1i - 1];

        writeln(ans);
    }
}

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

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

// 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;
import std.datetime, std.bigint;

immutable lim = 10;

int n, q, c;

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

    auto kido = new int[][][](c + 1, lim, lim);
    auto exst = new bool[][](lim, lim);

    int xi, yi, si;

    foreach (i ; 0 .. n) {
        scan(xi, yi, si);

        if (exst[xi][yi]) {
            writeln("Error");
            return;
        }

        kido[0][xi][yi] = si;
        exst[xi][yi] = true;
    }

    foreach (k ; 0 .. c) {
        foreach (i ; 0 .. lim) {
            foreach (j ; 0 .. lim) {
                if (exst[i][j]) {
                    kido[k + 1][i][j] = (kido[k][i][j] + 1) % (c + 1);
                }
            }
        }
    }

    debug {
        foreach (k ; 0 .. c + 1) {
            writefln("%(%(%s %)\n%)", kido[k]);
            writeln;
        }
    }

    foreach (k; 0 .. c + 1) {
        foreach (i ; 0 .. lim) {
            foreach (j ; 0 .. lim - 1) {
                kido[k][i][j + 1] += kido[k][i][j];
            }
        }

        foreach (j ; 0 .. lim) {
            foreach (i ; 0 .. lim - 1) {
                kido[k][i + 1][j] += kido[k][i][j];
            }
        }
    }

    int ti, x1i, y1i, x2i, y2i;

    foreach (qi ; 0 .. q) {
        scan(ti, x1i, y1i, x2i, y2i);
        ti %= (c + 1);

        int ans;
        ans += kido[ti][x2i][y2i];
        ans -= kido[ti][x2i][y1i - 1];
        ans -= kido[ti][x1i - 1][y2i];
        ans += kido[ti][x1i - 1][y1i - 1];

        writeln(ans);
    }
}

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

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