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

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

    long ans = 0L;
    while (n--) {
        int t, T, x, cost;
        readf("%s %s %s %s", &t, &T, &x, &cost);
        readln;

        int capacity = T - t;

        if (m <= capacity) {
            ans += cost;
            continue;
        }

        if (capacity <= 0) {
            ans += cost + m.to!long * x;
            continue;
        }

        auto cur1 = (m + capacity - 1).to!long / capacity * cost;
        auto cur2 = m % capacity == 0 ? 10L ^^ 18 :
            m.to!long / capacity * cost + (capacity + m % capacity).to!long * x;
        auto cur3 = cost + m.to!long * x;

        auto cur = min(cur1, min(cur2, cur3));

        debug { cur.writeln; }

        ans += cur;
    }

    ans.writeln;
}

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

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

    long ans = 0L;
    while (n--) {
        int t, T, x, cost;
        readf("%s %s %s %s", &t, &T, &x, &cost);
        readln;

        int capacity = T - t;

        if (m <= capacity) {
            ans += cost;
            continue;
        }

        if (capacity <= 0) {
            ans += cost + m.to!long * x;
            continue;
        }

        auto cur1 = (m + capacity - 1).to!long / capacity * cost;
        auto cur2 = cost + m.to!long * x;

        auto cur = min(cur1, cur2);

        debug { cur.writeln; }

        ans += cur;
    }

    ans.writeln;
}

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

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

    long ans = 0L;
    while (n--) {
        int t, T, x, cost;
        readf("%s %s %s %s", &t, &T, &x, &cost);
        readln;

        int capacity = T - t;

        if (capacity >= m) {
            ans += cost;
            continue;
        }

        if (capacity <= 0) {
            ans += cost + m.to!long * x;
            continue;
        }

        auto cur1 = (m + capacity - 1).to!long / capacity * cost;
        auto cur2 = m % capacity == 0 ? 10 ^^ 9 :
            max(m.to!long / capacity, 1L) * cost + (capacity + m % capacity).to!long * x;
        auto cur3 = cost + m.to!long * x;

        auto cur = min(cur1, min(cur2, cur3));

        debug { cur.writeln; }

        ans += cur;
    }

    ans.writeln;
}

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

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

    auto ans = 0L;
    while (n--) {
        int t, T, x, cost;
        readf("%s %s %s %s", &t, &T, &x, &cost);
        readln;

        int capacity = T - t;

        if (capacity >= m) {
            ans += cost;
            continue;
        }

        if (capacity <= 0) {
            ans += cost + m.to!long * x;
            continue;
        }

        auto cur1 = (m + capacity - 1).to!long / capacity * cost;
        auto cur2 = m % capacity == 0 ? 10 ^^ 9 :
            m.to!long / capacity * cost + (capacity + m % capacity).to!long * x;
        auto cur3 = cost + m.to!long * x;

        auto cur = min(cur1, min(cur2, cur3));

        debug { cur.writeln; }

        ans += cur;
    }

    ans.writeln;
}

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

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

    auto ans = 0L;
    while (n--) {
        int t, T, x, cost;
        readf("%s %s %s %s", &t, &T, &x, &cost);
        readln;

        int capacity = T - t;

        if (capacity >= m) {
            ans += cost;
            continue;
        }

        if (capacity <= 0) {
            ans += cost + m.to!long * x;
            continue;
        }

        auto cur1 = (m + capacity - 1).to!long / capacity * cost;
        auto cur2 = m % capacity == 0 ? 10 ^^ 9 :
            max(m.to!long / capacity, 1) * cost + (capacity + m % capacity).to!long * x;
        auto cur3 = cost + m.to!long * x;

        auto cur = min(cur1, min(cur2, cur3));

        debug { cur.writeln; }

        ans += cur;
    }

    ans.writeln;
}

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

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

    auto ans = 0L;
    while (n--) {
        int t, T, x, cost;
        readf("%s %s %s %s", &t, &T, &x, &cost);
        readln;

        int capacity = T - t;

        if (capacity >= m) {
            ans += cost;
            continue;
        }

        if (capacity <= 0) {
            ans += cost + m.to!long * x;
            continue;
        }

        auto cur1 = (m + capacity - 1).to!long / capacity * cost;
        auto cur2 = m % capacity == 0 ? 10 ^^ 9 :
            m.to!long / capacity * cost + (capacity + m % capacity) * x;
        auto cur3 = cost + m.to!long * x;

        auto cur = min(cur1, min(cur2, cur3));

        debug { cur.writeln; }

        ans += cur;
    }

    ans.writeln;
}


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto s = readln.strip.map !(q{a == 'L'}).array;
		auto fwd = new int [] [] (2, n);

		auto go ()
		{
			auto res = new int [] [] (2, n + 1);
			foreach (i; 0..n)
			{
				foreach (d; 0..2)
				{
					if (d ^ s[i])
					{
						res[d][i + 1] = res[!d][i] + 1;
					}
				}
			}
			return res;
		}

		auto lo = go ();
		reverse (s);
		s[] ^= 1;
		auto hi = go ();
		foreach (ref line; hi)
		{
			reverse (line);
		}
		writefln !("%(%s %)")
		    (iota (n + 1).map !(i => lo[0][i] + hi[0][i] + 1));
	}
}

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

void main()
{
    auto t = readln.chomp.to!int;

    while (t--) {
        auto n = readln.chomp.to!int;
        auto v = readln.chomp.array;

        void go(dchar[] v, int[dchar][] arr) {
            arr[0]['L'] = 0;
            arr[0]['R'] = 0;
            foreach (i, e; v.enumerate(1)) {
                auto calc = (dchar now, dchar other) =>
                    e == now ? 1 + arr[i-1][other] : 0;

                arr[i]['L'] = calc('L', 'R');
                arr[i]['R'] = calc('R', 'L');
            }
        }

        auto pref = new int[dchar][] (n+1);
        go(v, pref);

        auto suf = new int[dchar][] (n+1);
        go(v.retro().array, suf);
        suf.reverse();

        debug { pref.writeln; suf.writeln; }

        auto ans = (n+1).iota.map!(x => 1 + pref[x]['L'] + suf[x]['R']);

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

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

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

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

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

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

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

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

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

void main()
{
    int T; get(T);
    while (T--) {
        int N; get(N);
        char[] ds; get(ds);
        auto ls = new int[][](N + 1, 2);
        auto rs = new int[][](N + 1, 2);
        foreach (i; 0..N) {
            if (ds[i] == 'L') ls[i+1][0] = ls[i][1] + 1;
            if (ds[i] == 'R') ls[i+1][1] = ls[i][0] + 1;
        }
        foreach_reverse (i; 0..N) {
            if (ds[i] == 'R') rs[i][0] = rs[i+1][1] + 1;
            if (ds[i] == 'L') rs[i][1] = rs[i+1][0] + 1;
        }
        writefln!"%(%d %)"(0.iota(N + 1).map!(i => ls[i][0] + rs[i][0] + 1));
    }
}


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

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);

  auto mp = 1_500_000;
  auto p = primes(mp);

  auto f = new int[][](mp);
  foreach (i; 2..mp) {
    auto m = i;
    while (m > 1) {
      auto fi = factor(m, p);
      if (f[i].empty || f[i][$-1] != fi) f[i] ~= fi;
      m /= fi;
    }
  }

  auto b = new int[](n), v = new bool[](mp), mi = -1;
  foreach (i; 0..n) {
    for (auto c = mi == -1 ? a[i] : mi;; ++c) {
      if (f[c].any!(fi => v[fi])) continue;
      b[i] = c;
      foreach (fi; f[c]) v[fi] = true;
      if (mi == -1 && c > a[i])
        mi = 2;
      else if (mi > 1)
        mi = c;
      break;
    }
  }

  foreach (i; 0..n) {
    write(b[i]);
    if (i < n-1) write(" ");
  }
  writeln;
}

pure T[] primes(T)(T n)
{
  import std.algorithm, std.bitmanip, std.conv, std.range;

  auto sieve = BitArray();
  sieve.length((n+1)/2);
  sieve = ~sieve;

  foreach (p; 1..((nsqrt(n)-1)/2+1))
    if (sieve[p])
      for (auto q = p*3+1; q < (n+1)/2; q += p*2+1)
        sieve[q] = false;

  auto r = sieve.bitsSet.map!(to!T).map!("a*2+1").array;
  r[0] = 2;

  return r;
}

pure T factor(T)(T n, const T[] p)
{
  auto ma = nsqrt(n)+1;
  foreach (pi; p)
    if (pi > ma) return n;
    else if (n%pi == 0) return pi;
  return n;
}

pure T nsqrt(T)(T n)
{
  import std.algorithm, std.conv, std.range, core.bitop;
  if (n <= 1) return n;
  T m = 1 << (n.bsr/2+1);
  return iota(1, m).map!"a*a".assumeSorted!"a <= b".lowerBound(n).length.to!T;
}

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

void main()
{
	int n = readln.chomp.to!int;
	int[] a = readln.chomp.split.map!(to!int).array;
	int[] primes = [2];
	for (int i = 3; i <= 2000000; i += 2) {
		bool yes = true;
		foreach (v; primes) {
			if (v * v > i) {
				break;
			}
			if (!yes) {
				break;
			}
			yes &= i % v != 0;
		}
		if (yes) {
			primes ~= i;
		}
	}
	auto pr = assumeSorted(primes);
	bool[int] done;

	int m = 0;
	foreach (i, v; a) {
		if (m) write = " ";
		++m;
		int w = v;
		for (;;) {
			bool dame = false;
			int z = w;
			foreach (p; primes) {
				if (p > z) {
					break;
				}
				dame |= z % p == 0 && p in done;
				if (z % p == 0) {
					z /= p;
				}
			}
			if (!dame) {
				break;
			}
			++w;
		}
		int z = w;
		foreach (p; primes) {
			if (p > z) {
				break;
			}
			if (z % p == 0) {
				z /= p;
				done[p] = true;
			}
		}
		done[w] = true;
		w.write;
		if (w > v)
			break;
	}
	foreach (p; primes) {
		if (m >= n) {
			break;
		}
		if (p in done) {
			continue;
		}
		if (m) write = " ";
		++m;
		p.write;
	}
	writeln;
}

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

void main()
{
	int n = readln.chomp.to!int;
	int[] a = readln.chomp.split.map!(to!int).array;
	int[] primes = [2];
	for (int i = 3; i <= 1000000; i += 2) {
		bool yes = true;
		foreach (v; primes) {
			if (v * v > i) {
				break;
			}
			if (!yes) {
				break;
			}
			yes &= i % v != 0;
		}
		if (yes) {
			primes ~= i;
		}
	}
	auto pr = assumeSorted(primes);
	bool[int] done;

	int m = 0;
	foreach (i, v; a) {
		if (m) write = " ";
		++m;
		int w = v;
		for (;;) {
			bool dame = false;
			int z = w;
			foreach (p; primes) {
				if (p > z) {
					break;
				}
				dame |= z % p == 0 && p in done;
				if (z % p == 0) {
					z /= p;
				}
			}
			if (!dame) {
				break;
			}
			++w;
		}
		int z = w;
		foreach (p; primes) {
			if (p > z) {
				break;
			}
			if (z % p == 0) {
				z /= p;
				done[p] = true;
			}
		}
		done[w] = true;
		w.write;
		if (w > v)
			break;
	}
	foreach (p; primes) {
		if (m >= n) {
			break;
		}
		if (p in done) {
			continue;
		}
		if (m) write = " ";
		++m;
		p.write;
	}
	writeln;
}

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

void main()
{
	int n = readln.chomp.to!int;
	int[] a = readln.chomp.split.map!(to!int).array;
	int[] primes = [2];
	for (int i = 3; i <= 200000; i += 2) {
		bool yes = true;
		foreach (v; primes) {
			yes &= i % v != 0;
		}
		if (yes) {
			primes ~= i;
		}
	}
	auto pr = assumeSorted(primes);
	bool[int] done;

	int m = 0;
	foreach (i, v; a) {
		if (m) write = " ";
		++m;
		int w = v;
		for (;;) {
			bool dame = false;
			foreach (p; primes) {
				if (p > w) {
					break;
				}
				dame |= w % p == 0 && p in done;
			}
			if (!dame) {
				break;
			}
			++w;
		}
		foreach (p; primes) {
			if (p > w) {
				break;
			}
			if (w % p == 0) {
				done[p] = true;
			}
		}
		done[w] = true;
		w.write;
		if (w > v)
			break;
	}
	foreach (p; primes) {
		if (m >= n) {
			break;
		}
		if (p in done) {
			continue;
		}
		if (m) write = " ";
		++m;
		p.write;
	}
	writeln;
}

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

void main()
{
	int n = readln.chomp.to!int;
	int[] a = readln.chomp.split.map!(to!int).array;
	int[] primes = [2];
	for (int i = 3; i <= 100100; i += 2) {
		bool yes = true;
		foreach (v; primes) {
			yes &= i % v != 0;
		}
		if (yes) {
			primes ~= i;
		}
	}
	auto pr = assumeSorted(primes);
	int[] ans;
	bool[int] done;

	foreach (i, v; a) {
		if (pr.contains(v)) {
			ans ~= v;
			done[v] = true;
		} else {
			int w = v;
			for (;;) {
				bool dame = false;
				foreach (p; primes) {
					if (p > w) {
						break;
					}
					dame |= w % p == 0 && p in done;
				}
				if (!dame) {
					break;
				}
				++w;
			}
			foreach (p; primes) {
				if (p * p > w) {
					break;
				}
				if (w % p == 0) {
					done[p] = true;
				}
			}
			ans ~= w;
			if (w > v)
				break;
		}
	}
	foreach (p; primes) {
		if (ans.length >= n) {
			break;
		}
		if (p in done) {
			continue;
		}
		ans ~= p;
	}
	writefln("%(%d %)", ans);
}

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

void main()
{
	int n = readln.chomp.to!int;
	int[] a = readln.chomp.split.map!(to!int).array;
	int[] primes = [2];
	for (int i = 3; i <= 300000; i += 2) {
		bool yes = true;
		foreach (v; primes) {
			if (!yes) {
				break;
			}
			yes &= i % v != 0;
		}
		if (yes) {
			primes ~= i;
		}
	}
	auto pr = assumeSorted(primes);
	bool[int] done;

	int m = 0;
	foreach (i, v; a) {
		if (m) write = " ";
		++m;
		int w = v;
		for (;;) {
			bool dame = false;
			int z = w;
			foreach (p; primes) {
				if (p > z) {
					break;
				}
				dame |= z % p == 0 && p in done;
				if (z % p == 0) {
					z /= p;
				}
			}
			if (!dame) {
				break;
			}
			++w;
		}
		int z = w;
		foreach (p; primes) {
			if (p > z) {
				break;
			}
			if (z % p == 0) {
				z /= p;
				done[p] = true;
			}
		}
		done[w] = true;
		w.write;
		if (w > v)
			break;
	}
	foreach (p; primes) {
		if (m >= n) {
			break;
		}
		if (p in done) {
			continue;
		}
		if (m) write = " ";
		++m;
		p.write;
	}
	writeln;
}

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

void main()
{
	int n = readln.chomp.to!int;
	int[] a = readln.chomp.split.map!(to!int).array;
	int[] primes = [2];
	for (int i = 3; i <= 200000; i += 2) {
		bool yes = true;
		foreach (v; primes) {
			yes &= i % v != 0;
		}
		if (yes) {
			primes ~= i;
		}
	}
	auto pr = assumeSorted(primes);
	int[] ans;
	bool[int] done;

	foreach (i, v; a) {
		int w = v;
		for (;;) {
			bool dame = false;
			foreach (p; primes) {
				if (p > w) {
					break;
				}
				dame |= w % p == 0 && p in done;
			}
			if (!dame) {
				break;
			}
			++w;
		}
		foreach (p; primes) {
			if (p > w) {
				break;
			}
			if (w % p == 0) {
				done[p] = true;
			}
		}
		ans ~= w;
		done[w] = true;
		if (w > v)
			break;
	}
	foreach (p; primes) {
		if (ans.length >= n) {
			break;
		}
		if (p in done) {
			continue;
		}
		ans ~= p;
	}
	writefln("%(%d %)", ans);
}

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

void main()
{
	int n = readln.chomp.to!int;
	int[] a = readln.chomp.split.map!(to!int).array;
	int[] primes = [2];
	for (int i = 3; i <= 200000; i += 2) {
		bool yes = true;
		foreach (v; primes) {
			if (!yes) {
				break;
			}
			yes &= i % v != 0;
		}
		if (yes) {
			primes ~= i;
		}
	}
	auto pr = assumeSorted(primes);
	bool[int] done;

	int m = 0;
	foreach (i, v; a) {
		if (m) write = " ";
		++m;
		int w = v;
		for (;;) {
			bool dame = false;
			int z = w;
			foreach (p; primes) {
				if (p > w) {
					break;
				}
				dame |= z % p == 0 && p in done;
				if (z % p == 0) {
					z /= p;
				}
			}
			if (!dame) {
				break;
			}
			++w;
		}
		int z = w;
		foreach (p; primes) {
			if (p > z) {
				break;
			}
			if (z % p == 0) {
				z /= p;
				done[p] = true;
			}
		}
		done[w] = true;
		w.write;
		if (w > v)
			break;
	}
	foreach (p; primes) {
		if (m >= n) {
			break;
		}
		if (p in done) {
			continue;
		}
		if (m) write = " ";
		++m;
		p.write;
	}
	writeln;
}

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

void main()
{
	int n = readln.chomp.to!int;
	int[] a = readln.chomp.split.map!(to!int).array;
	int[] primes = [2];
	for (int i = 3; i <= 100100; i += 2) {
		bool yes = true;
		foreach (v; primes) {
			yes &= i % v != 0;
		}
		if (yes) {
			primes ~= i;
		}
	}
	auto pr = assumeSorted(primes);
	int[] ans;
	bool[int] done;

	foreach (i, v; a) {
		if (pr.contains(v)) {
			ans ~= v;
			done[v] = true;
		} else {
			int w = v;
			for (;;) {
				bool dame = false;
				foreach (p; primes) {
					if (p > w) {
						break;
					}
					dame |= w % p == 0 && p in done;
				}
				if (!dame) {
					break;
				}
				++w;
			}
			foreach (p; primes) {
				if (p * p > w) {
					break;
				}
				if (w % p == 0) {
					done[p] = true;
				}
			}
			ans ~= w;
			done[w] = true;
			if (w > v)
				break;
		}
	}
	foreach (p; primes) {
		if (ans.length >= n) {
			break;
		}
		if (p in done) {
			continue;
		}
		ans ~= p;
	}
	writefln("%(%d %)", ans);
}

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

void main()
{
	int n = readln.chomp.to!int;
	int[] a = readln.chomp.split.map!(to!int).array;
	int[] primes = [2];
	for (int i = 3; i <= 100100; i += 2) {
		bool yes = true;
		foreach (v; primes) {
			yes &= i % v != 0;
		}
		if (yes) {
			primes ~= i;
		}
	}
	auto pr = assumeSorted(primes);
	int[] ans;
	bool[int] done;

	foreach (i, v; a) {
		int w = v;
		for (;;) {
			bool dame = false;
			foreach (p; primes) {
				if (p > w) {
					break;
				}
				dame |= w % p == 0 && p in done;
			}
			if (!dame) {
				break;
			}
			++w;
		}
		foreach (p; primes) {
			if (p > w) {
				break;
			}
			if (w % p == 0) {
				done[p] = true;
			}
		}
		ans ~= w;
		done[w] = true;
		if (w > v)
			break;
	}
	foreach (p; primes) {
		if (ans.length >= n) {
			break;
		}
		if (p in done) {
			continue;
		}
		ans ~= p;
	}
	writefln("%(%d %)", ans);
}

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

void main()
{
	int n = readln.chomp.to!int;
	int[] a = readln.chomp.split.map!(to!int).array;
	int[] primes = [2];
	for (int i = 3; i <= 100100; i += 2) {
		bool yes = true;
		foreach (v; primes) {
			yes &= i % v != 0;
		}
		if (yes) {
			primes ~= i;
		}
	}
	auto pr = assumeSorted(primes);
	int m = 0;
	int index = 0;
	int[] ans;
	bool[int] done;
	foreach (i, v; a) {
		if (pr.contains(v)) {
			ans ~= v;
			done[v] = true;
		} else {
			int ite = v;
			for (;;) {
				auto ret = pr.upperBound(ite);
				ite = ret.front;
				if (ite !in done) {
					break;
				}
			}
			ans ~= ite;
			done[ite] = true;
			break;
		}
	}
	foreach (p; primes) {
		if (ans.length >= n) {
			break;
		}
		if (p in done) {
			continue;
		}
		ans ~= p;
	}
	writefln("%(%d %)", ans);
}

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

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);

  auto mp = 1_500_000;
  auto p = primes(mp);

  auto f = new int[][](mp);
  foreach (i; 2..mp) {
    auto m = i;
    while (m > 1) {
      auto fi = factor(m, p);
      if (f[i].empty || f[i][$-1] != fi) f[i] ~= fi;
      m /= fi;
    }
  }

  auto b = new int[](n), v = new bool[](mp), mi = -1;
  foreach (i; 0..n) {
    for (auto c = mi == -1 ? a[i] : b[i-1];; ++c) {
      if (f[c].any!(fi => v[fi])) continue;
      b[i] = c;
      foreach (fi; f[c]) v[fi] = true;
      if (mi == -1 && c > a[i])
        mi = 2;
      else if (mi > 1)
        mi = c;
      break;
    }
  }

  foreach (i; 0..n) {
    write(b[i]);
    if (i < n-1) write(" ");
  }
  writeln;
}

pure T[] primes(T)(T n)
{
  import std.algorithm, std.bitmanip, std.conv, std.range;

  auto sieve = BitArray();
  sieve.length((n+1)/2);
  sieve = ~sieve;

  foreach (p; 1..((nsqrt(n)-1)/2+1))
    if (sieve[p])
      for (auto q = p*3+1; q < (n+1)/2; q += p*2+1)
        sieve[q] = false;

  auto r = sieve.bitsSet.map!(to!T).map!("a*2+1").array;
  r[0] = 2;

  return r;
}

pure T factor(T)(T n, const T[] p)
{
  auto ma = nsqrt(n)+1;
  foreach (pi; p)
    if (pi > ma) return n;
    else if (n%pi == 0) return pi;
  return n;
}

pure T nsqrt(T)(T n)
{
  import std.algorithm, std.conv, std.range, core.bitop;
  if (n <= 1) return n;
  T m = 1 << (n.bsr/2+1);
  return iota(1, m).map!"a*a".assumeSorted!"a <= b".lowerBound(n).length.to!T;
}

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

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);

  auto mp = 200_000;
  auto p = primes(mp);

  auto f = new int[][](mp);
  foreach (i; 2..mp) {
    auto m = i;
    while (m > 1) {
      auto fi = factor(m, p);
      if (f[i].empty || f[i][$-1] != fi) f[i] ~= fi;
      m /= fi;
    }
  }

  auto b = new int[](n), v = new bool[](mp), mi = -1;
  foreach (i; 0..n) {
    for (auto c = mi == -1 ? a[i] : mi;; ++c) {
      if (f[c].any!(fi => v[fi])) continue;
      b[i] = c;
      foreach (fi; f[c]) v[fi] = true;
      if (mi == -1 && c > a[i])
        mi = 2;
      else if (mi > 1)
        mi = c;
      break;
    }
  }

  foreach (i; 0..n) {
    write(b[i]);
    if (i < n-1) write(" ");
  }
  writeln;
}

pure T[] primes(T)(T n)
{
  import std.algorithm, std.bitmanip, std.conv, std.range;

  auto sieve = BitArray();
  sieve.length((n+1)/2);
  sieve = ~sieve;

  foreach (p; 1..((nsqrt(n)-1)/2+1))
    if (sieve[p])
      for (auto q = p*3+1; q < (n+1)/2; q += p*2+1)
        sieve[q] = false;

  auto r = sieve.bitsSet.map!(to!T).map!("a*2+1").array;
  r[0] = 2;

  return r;
}

pure T factor(T)(T n, const T[] p)
{
  auto ma = nsqrt(n)+1;
  foreach (pi; p)
    if (pi > ma) return n;
    else if (n%pi == 0) return pi;
  return n;
}

pure T nsqrt(T)(T n)
{
  import std.algorithm, std.conv, std.range, core.bitop;
  if (n <= 1) return n;
  T m = 1 << (n.bsr/2+1);
  return iota(1, m).map!"a*a".assumeSorted!"a <= b".lowerBound(n).length.to!T;
}

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

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);

  auto mp = 1_000_000;
  auto p = primes(mp);

  auto f = new int[][](mp);
  foreach (i; 2..mp) {
    auto m = i;
    while (m > 1) {
      auto fi = factor(m, p);
      if (f[i].empty || f[i][$-1] != fi) f[i] ~= fi;
      m /= fi;
    }
  }

  auto b = new int[](n), v = new bool[](mp), mi = -1;
  foreach (i; 0..n) {
    for (auto c = mi == -1 ? a[i] : mi;; ++c) {
      if (f[c].any!(fi => v[fi])) continue;
      b[i] = c;
      foreach (fi; f[c]) v[fi] = true;
      if (mi == -1 && c > a[i])
        mi = 2;
      else if (mi > 1)
        mi = c;
      break;
    }
  }

  foreach (i; 0..n) {
    write(b[i]);
    if (i < n-1) write(" ");
  }
  writeln;
}

pure T[] primes(T)(T n)
{
  import std.algorithm, std.bitmanip, std.conv, std.range;

  auto sieve = BitArray();
  sieve.length((n+1)/2);
  sieve = ~sieve;

  foreach (p; 1..((nsqrt(n)-1)/2+1))
    if (sieve[p])
      for (auto q = p*3+1; q < (n+1)/2; q += p*2+1)
        sieve[q] = false;

  auto r = sieve.bitsSet.map!(to!T).map!("a*2+1").array;
  r[0] = 2;

  return r;
}

pure T factor(T)(T n, const T[] p)
{
  auto ma = nsqrt(n)+1;
  foreach (pi; p)
    if (pi > ma) return n;
    else if (n%pi == 0) return pi;
  return n;
}

pure T nsqrt(T)(T n)
{
  import std.algorithm, std.conv, std.range, core.bitop;
  if (n <= 1) return n;
  T m = 1 << (n.bsr/2+1);
  return iota(1, m).map!"a*a".assumeSorted!"a <= b".lowerBound(n).length.to!T;
}


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

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

        int read_int() {
                return read_string.to!int;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // int t = cin.read_int;
        while (t--) {
                int n = cin.read_int;
                string[] arr = new string[n];

                for (int i = 0; i < n; i++) {
                        arr[i] = cin.read_string;
                }
                int count = 0;
                bool flag = true;
                for (int i = 0; i < arr[0].length; i++) {
                        for (int j = 0; j < n - 1; j++) {
                                if (arr[j][i] != arr[j + 1][i]) {
                                        flag = false;
                                        break;
                                }
                        }
                        if (flag) count++;
                }
                writeln(count);
        }
}

module cf_172A;

import std.stdio;

void main() {
    int n;
    string phoneNumber;
    string prevPhoneNumber;
    int[] count;

    readf("%d ", &n);
    for (int i = 0; i < n; ++i) {
        readf("%s\n", &phoneNumber);

        if (i > 0) {
            for (int j = 0; j < phoneNumber.length; ++j) {
                if (prevPhoneNumber[j] != phoneNumber[j]) {
                    ++count[j];
                }
            }
        } else {
            count = new int[phoneNumber.length];
        }
        prevPhoneNumber = phoneNumber.idup;
    }

    int pref = 0;
    while (pref < count.length && count[pref] == 0) {
        ++pref;
    }

    writeln(pref);
}


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;

void iteration(int i, int n, int[] a)
{
  if (i % 2 == 0) {
    for (int j = 0; j <= n - 2 - 1; j += 2) {
      if (a[j] > a[j + 1])
        swap(a[j], a[j + 1]);
    }
  } else {
    for (int j = 1; j <= n - 1 - 1; j += 2) {
      if (a[j] > a[j + 1])
        swap(a[j], a[j + 1]);
    }
  }
}

void main()
{
  int t;
  readf!" %d "(t);
  while (t--) {
    int n;
    readf!" %d "(n);
    auto a = readln.strip.split.map!(to!int).array;
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (a.isSorted!"a<b")
        break;
      iteration(i, n, a);
      ans++;
    }
    writeln(ans);
  }
}

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

string FMT_F = "%.10f";

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

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

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

		while (true)
		{
			bool ok = true;
			foreach (i; 0..n)
			{
				if (a[i] != i+1)
				{
					ok = false;
					break;
				}
			}
			if (ok) break;

			foreach (i; 0..n-1)
			{
				if (i % 2 != ans[ti] % 2) continue;
				if (a[i] > a[i+1])
					swap(a[i], a[i+1]);
			}
			++ans[ti];
		}
	}

	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;

void iteration(int i, int n, int[] a)
{
  if (i % 2 == 0) {
    for (int j = 0; j <= n - 2 - 1; j += 2) {
      if (a[j] > a[j + 1])
        swap(a[j], a[j + 1]);
    }
  } else {
    for (int j = 1; j <= n - 1 - 1; j += 2) {
      if (a[j] > a[j + 1])
        swap(a[j], a[j + 1]);
    }
  }
}

void main()
{
  int t;
  readf!" %d "(t);
  while (t--) {
    int n;
    readf!" %d "(n);
    auto a = readln.strip.split.map!(to!int).array;
    writeln(a);
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (a.isSorted!"a<b")
        break;
      iteration(i, n, a);
      ans++;
    }
    writeln(ans);
  }
}


// cheese-cracker [2022-07-15]

void solve(){
    int n = scan!int;
    auto s = scan!(dchar[]);
    auto t = scan!(dchar[]);
    int[] ixs, ixt;
    dchar[] ws, wt;

    ws ~= s[0];
    wt ~= t[0];
    ixs ~= 0;
    ixt ~= 0;

    for(int i = 1; i < n; ++i){
        if(s[i] != s[i-1]){
            ws ~= s[i];
            ixs ~= i;
        }
        if(t[i] != t[i-1]){
            wt ~= t[i];
            ixt ~= i;
        }
    }
    if(ws != wt){
        writeln(-1);
        return;
    }
    long ans = 0;
    for(int i = 0; i < ixt.length; ++i){
        ans += abs(ixt[i] - ixs[i]);
    }
    writeln(ans);
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/*_________________________*That's All Folks!*__________________________*/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm;
import std.container, std.math, std.numeric, std.functional;
string[] tk; alias tup = Tuple!(long, long);
T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }

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

void solve() {
    int N = readln.chomp.to!int;
    string S = readln.chomp;
    string T = readln.chomp;

    long C() {
        if (S[0] != T[0] || S[$-1] != T[$-1]) return -1;
        auto s = new int[0], t = new int[0];
        for (int i = 1; i < N; i++) {
            s ~= S[i-1] != S[i];
            t ~= T[i-1] != T[i];
        }
        if (s.reduce!"a+b" != t.reduce!"a+b") return -1;
        int[] xs, xt;
        for (int i = 0; i < N-1; i++) {
            if (s[i]) xs ~= i;
            if (t[i]) xt ~= i;
        }
        long ans = 0;
        for (int i = 0; i < xs.length; i++) {
            ans += abs(xs[i] - xt[i]);
        }
        return ans;
    }

    writeln(C());
}

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


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

alias Tuple !(int, "x", int, "y") point;

void fill_extrema (long [] b, ref long [] tmin, ref long [] tmax)
{
	tmin ~= +(1L << 36);
	tmax ~= -(1L << 36);
	foreach (d; b)
	{
		tmin ~= min (tmin[$ - 1], d);
		tmax ~= max (tmax[$ - 1], d);
	}
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new point [n];
		foreach (i; 0..n)
		{
			readf (" %s %s", &a[i].x, &a[i].y);
		}
		sort !("a.x - a.y < b.x - b.y") (a);

		long [] z;
		foreach (c; a)
		{
			z ~= c.x - c.y;
		}

		long [] b;
		foreach (c; a)
		{
			b ~= c.x + c.y;
		}

		long [] pmin;
		long [] pmax;
		fill_extrema (b, pmin, pmax);

		long [] smin;
		long [] smax;
		reverse (b);
		fill_extrema (b, smin, smax);
		reverse (b);
		reverse (smin);
		reverse (smax);

		bool check (long lim)
		{
			int j = 0;
			foreach (i; 0..n)
			{
				while ((j < n) && (z[j] - z[i] <= lim))
				{
					j++;
				}

				long lo = min (pmin[i], smin[j]);
				long hi = max (pmax[i], smax[j]);
				if (hi - lo <= lim)
				{
					return true;
				}
			}
			return false;
		}

		long lo = 0;
		long hi = 1L << 32;
		while (lo < hi)
		{
			long me = lo + ((hi - lo) >> 1);
			if (check (me))
			{
				hi = me;
			}
			else
			{
				lo = me + 1;
			}
		}

		writefln ("%.20f", lo * 0.5);
	}
}

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

alias Tuple !(long, "x", long, "y") point;

void fill_extrema (long [] b, ref long [] tmin, ref long [] tmax)
{
	tmin ~= +(1L << 36);
	tmax ~= -(1L << 36);
	foreach (d; b)
	{
		tmin ~= min (tmin[$ - 1], d);
		tmax ~= max (tmax[$ - 1], d);
	}
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new point [n];
		foreach (i; 0..n)
		{
			readf (" %s %s", &a[i].x, &a[i].y);
		}
		sort !("a.x - a.y < b.x - b.y") (a);

		long [] z;
		foreach (c; a)
		{
			z ~= c.x - c.y;
		}

		long [] b;
		foreach (c; a)
		{
			b ~= c.x + c.y;
		}

		long [] pmin;
		long [] pmax;
		fill_extrema (b, pmin, pmax);

		long [] smin;
		long [] smax;
		reverse (b);
		fill_extrema (b, smin, smax);
		reverse (b);
		reverse (smin);
		reverse (smax);

		bool check (long lim)
		{
			int i = 0;
			int j = 0;
			while (i < n)
			{
				while ((j < n) && (z[j] - z[i] <= lim))
				{
					j++;
				}

				long lo = min (pmin[i], smin[j]);
				long hi = max (pmax[i], smax[j]);
				if (hi - lo <= lim)
				{
					return true;
				}

				do
				{
					i++;
				}
				while ((i < n) && (z[i] == z[i - 1]));
			}
			return false;
		}

		long lo = 0;
		long hi = 1L << 32;
		while (lo < hi)
		{
			long me = lo + ((hi - lo) >> 1);
			if (check (me))
			{
				hi = me;
			}
			else
			{
				lo = me + 1;
			}
		}

		writefln ("%.20f", lo * 0.5);
	}
}

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

alias Tuple !(long, "x", long, "y") point;

bool less_plus (T) (auto ref T a, auto ref T b)
{
	return a.x + a.y < b.x + b.y;
}

bool less_minus (T) (auto ref T a, auto ref T b)
{
	return a.x - a.y < b.x - b.y;
}

void fill_extrema (long [] b, ref long [] tmin, ref long [] tmax)
{
	tmin ~= +(1L << 36);
	tmax ~= -(1L << 36);
	foreach (d; b)
	{
		tmin ~= min (tmin[$ - 1], d);
		tmax ~= max (tmax[$ - 1], d);
	}
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new point [n];
		foreach (i; 0..n)
		{
			readf (" %s %s", &a[i].x, &a[i].y);
		}
		sort !(less_minus, SwapStrategy.stable) (a);

		long [] z;
		foreach (c; a)
		{
			z ~= c.x - c.y;
		}

		long [] b;
		foreach (c; a)
		{
			b ~= c.x + c.y;
		}

		long [] pmin;
		long [] pmax;
		fill_extrema (b, pmin, pmax);

		long [] smin;
		long [] smax;
		reverse (b);
		fill_extrema (b, smin, smax);
		reverse (b);
		reverse (smin);
		reverse (smax);

		debug {writeln (a);}
		debug {writeln (b);}
		debug {writeln (z);}
		debug {writeln (pmin);}
		debug {writeln (pmax);}
		debug {writeln (smin);}
		debug {writeln (smax);}

		bool check (long lim)
		{
			int i = 0;
			int j = 0;
			while (i < n)
			{
				while ((j < n) && (z[j] - z[i] <= lim))
				{
					j++;
				}
				debug {writefln ("i = %s, j = %s", i, j);}

				long lo = min (pmin[i], smin[j]);
				long hi = max (pmax[i], smax[j]);
				debug {writefln ("%s %s", lo, hi);}
				if (hi - lo <= lim)
				{
					return true;
				}

				do
				{
					i++;
				}
				while ((i < n) && (z[i] == z[i - 1]));
			}
			debug {writefln ("check (%s)", lim);}
			return false;
		}

		long lo = 0;
		long hi = 1L << 32;
		while (lo < hi)
		{
			long me = lo + ((hi - lo) >> 1);
			debug {writefln ("%10s %10s %10s", lo, me, hi);}
			if (check (me))
			{
				hi = me;
			}
			else
			{
				lo = me + 1;
			}
			debug {writefln ("%10s %10s %10s", lo, me, hi);}
		}

		writefln ("%.20f", lo * 0.5);
	}
}

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

alias Tuple !(int, "x", int, "y") point;

void fill_extrema (long [] b, ref long [] tmin, ref long [] tmax)
{
	tmin ~= +(1L << 36);
	tmax ~= -(1L << 36);
	foreach (d; b)
	{
		tmin ~= min (tmin[$ - 1], d);
		tmax ~= max (tmax[$ - 1], d);
	}
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new point [n];
		foreach (i; 0..n)
		{
			readf (" %s %s", &a[i].x, &a[i].y);
		}
		sort !("a.x - a.y < b.x - b.y") (a);

		long [] z;
		foreach (c; a)
		{
			z ~= c.x - c.y;
		}

		long [] b;
		foreach (c; a)
		{
			b ~= c.x + c.y;
		}

		long [] pmin;
		long [] pmax;
		fill_extrema (b, pmin, pmax);

		long [] smin;
		long [] smax;
		reverse (b);
		fill_extrema (b, smin, smax);
		reverse (b);
		reverse (smin);
		reverse (smax);

		bool check (long lim)
		{
			int i = 0;
			int j = 0;
			while (i < n)
			{
				while ((j < n) && (z[j] - z[i] <= lim))
				{
					j++;
				}

				long lo = min (pmin[i], smin[j]);
				long hi = max (pmax[i], smax[j]);
				if (hi - lo <= lim)
				{
					return true;
				}

				do
				{
					i++;
				}
				while ((i < n) && (z[i] == z[i - 1]));
			}
			return false;
		}

		long lo = 0;
		long hi = 1L << 32;
		while (lo < hi)
		{
			long me = lo + ((hi - lo) >> 1);
			if (check (me))
			{
				hi = me;
			}
			else
			{
				lo = me + 1;
			}
		}

		writefln ("%.20f", lo * 0.5);
	}
}


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

void solve()
{
    int n, k;
    readf!(" %s %s")(n, k);
    readln;
    int[] arr = readln.splitter.map!(to!int).array;
    assert(arr.length == n);
    if (k == 1)
    {
        iota(1, arr.length-1, 2).count().writeln();
        return;
    }
    iota(1, arr.length-1).filter!(i => arr[i] > arr[i - 1] + arr[i + 1]).count()
        .writeln();
}

void main()
{
    size_t TC = 1;
    TC = readln.strip.to!int;
    foreach (_; 0 .. TC)
        solve();
}

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

void solve()
{
    int n, k;
    readf!(" %s %s")(n, k);
    readln;
    int[] arr = readln.splitter.map!(to!int).array;
    assert(arr.length == n);
    if (k == 1)
    {
        writeln((n - 1) / 2);
        return;
    }
    iota(1, arr.length - 1).count!(i=>arr[i] > arr[i - 1] + arr[i + 1]).writeln();
}

void main()
{
    size_t TC = 1;
    TC = readln.strip.to!int;
    foreach (_; 0 .. TC)
        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)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		writeln ((k == 1) ? (n - 1) / 2 :
		    iota (1, n - 1).count !(i => a[i] > a[i - 1] + a[i + 1]));
	}
}

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

void solve()
{
    int n, k;
    readf!(" %s %s")(n, k);
    readln;
    int[] arr = readln.splitter.map!(to!int).array;
    assert(arr.length == n);
    if (k == 1)
    {
        iota(1, arr.length-1, 2).count().writeln();
        return;
    }
    iota(1, arr.length-1, 2).filter!(i => arr[i] > arr[i - 1] + arr[i + 1]).count()
        .writeln();
}

void main()
{
    size_t TC = 1;
    TC = readln.strip.to!int;
    foreach (_; 0 .. TC)
        solve();
}

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

void solve()
{
    int n, k;
    readf!(" %s %s")(n, k);
    readln;
    int[] arr = readln.splitter.map!(to!int).array;
    assert(arr.length == n);
    if (k == 1)
    {
        iota(1, arr.length, 2).count().writeln();
        return;
    }
    iota(1, arr.length-1, 2).filter!(i => arr[i] > arr[i - 1] + arr[i + 1]).count()
        .writeln();
}

void main()
{
    size_t TC = 1;
    TC = readln.strip.to!int;
    foreach (_; 0 .. TC)
        solve();
}


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

immutable int INF = 10L ^^ 9 + 23;

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

    auto mx = new bool[][] (n+1, n+1);

    foreach (i; 1 .. n+1) {
        foreach (j; 0 .. n/4) {
            char c;
            readf("%s", &c);

            int v = c >= 'A' ? c - 'A' + 10 : c - '0';
            foreach (k; 0 .. 4) {
                mx[i][1 + j*4 + k] = (v & (1 << (3 - k))) > 0;
            }
        }

        readln;
    }

    debug { mx.each!writeln; }

    auto val = new int[][] (n+1, n+1);

    foreach (i; 1 .. n+1) {
        foreach (j; 1 .. n+1) {
            val[i][j] = mx[i][j] + val[i-1][j] + val[i][j-1] - val[i-1][j-1];
        }
    }

    debug { val.each!writeln; }

    bool isOk(int x) {
        int sz = x*x;
        foreach (i; 1 .. n/x + 1) {
            foreach (j; 1 .. n/x + 1) {
                int cval = val[i*x][j*x] - val[(i-1)*x][j*x] - val[i*x][(j-1)*x] + val[(i-1)*x][(j-1)*x];
                if (cval != 0 && cval != sz) { return false; }
            }
        }

        return true;
    }

    int ans = 1;
    foreach (m; 2 .. n+1) {
        if (n % m != 0) { continue; }
        if (isOk(m)) { ans = m; }
    }

    ans.writeln;
}

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

immutable int INF = 10L ^^ 9 + 23;

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

    auto mx = new bool[][] (n+1, n+1);

    foreach (i; 1 .. n+1) {
        foreach (j; 0 .. n/4) {
            char c;
            readf("%s", &c);

            int v = c >= 'A' ? c - 'A' + 10 : c - '0';
            foreach (k; 0 .. 4) {
                mx[i][1 + j*4 + k] = (v & (1 << (3 - k))) > 0;
            }
        }

        readln;
    }

    debug { mx.each!writeln; }

    auto val = new int[][] (n+1, n+1);

    foreach (i; 1 .. n+1) {
        foreach (j; 1 .. n+1) {
            val[i][j] = mx[i][j] + val[i-1][j] + val[i][j-1] - val[i-1][j-1];
        }
    }

    debug { val.each!writeln; }

    bool isOk(int x) {
        int sz = x*x;
        foreach (i; 1 .. n/x + 1) {
            foreach (j; 1 .. n/x + 1) {
                int cval = val[i*x][j*x] - val[(i-1)*x][j*x] - val[i*x][(j-1)*x] + val[(i-1)*x][(j-1)*x];
                if (cval != 0 && cval != sz) { return false; }
            }
        }

        return true;
    }

    int ans = (n+1).iota[1 .. $].filter!(x => n % x == 0 && isOk(x)).array.back;

    ans.writeln;
}

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

immutable int INF = 10L ^^ 9 + 23;

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

    auto mx = new bool[][] (n+1, n+1);

    foreach (i; 1 .. n+1) {
        foreach (j; 0 .. n/4) {
            char c;
            readf("%s", &c);

            int v = c >= 'A' ? c - 'A' + 10 : c - '0';
            foreach (k; 0 .. 4) {
                mx[i][1 + j*4 + k] = (v & (1 << (3 - k))) > 0;
            }
        }

        readln;
    }

    debug { mx.each!writeln; }

    auto val = new int[][] (n+1, n+1);

    foreach (i; 1 .. n+1) {
        foreach (j; 1 .. n+1) {
            val[i][j] = mx[i][j] + val[i-1][j] + val[i][j-1] - val[i-1][j-1];
        }
    }

    debug { val.each!writeln; }

    bool isOk(int x) {
        x = ((x+3) / 4) * 4;
        int sz = x*x;
        foreach (i; 1 .. n/x + 1) {
            foreach (j; 1 .. n/x + 1) {
                int cval = val[i*x][j*x] - val[(i-1)*x][j*x] - val[i*x][(j-1)*x] + val[(i-1)*x][(j-1)*x];
                if (cval != 0 && cval != sz) { return false; }
            }
        }

        return true;
    }

    int le = 1, r = n;
    while (le < r) {
        int m = (le + r) / 2 + 1;
        if (isOk(m)) { le = m; }
        else { r = m-1; }
    }

    le.writeln;
}

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

immutable int INF = 10L ^^ 9 + 23;

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

    auto mx = new bool[][] (n+1, n+1);

    foreach (i; 1 .. n+1) {
        foreach (j; 0 .. n/4) {
            char c;
            readf("%s", &c);

            int v = c >= 'A' ? c - 'A' + 10 : c - '0';
            foreach (k; 0 .. 4) {
                mx[i][1 + j*4 + k] = (v & (1 << (3 - k))) > 0;
            }
        }

        readln;
    }

    debug { mx.each!writeln; }

    auto val = new int[][] (n+1, n+1);

    foreach (i; 1 .. n+1) {
        foreach (j; 1 .. n+1) {
            val[i][j] = mx[i][j] + val[i-1][j] + val[i][j-1] - val[i-1][j-1];
        }
    }

    debug { val.each!writeln; }

    bool isOk(int x) {
        int sz = x*x;
        foreach (i; 1 .. n/x + 1) {
            foreach (j; 1 .. n/x + 1) {
                int cval = val[i*x][j*x] - val[(i-1)*x][j*x] - val[i*x][(j-1)*x] + val[(i-1)*x][(j-1)*x];
                if (cval != 0 && cval != sz) { return false; }
            }
        }

        return true;
    }

    int ans = 1;
    foreach (m; 2 .. n+1) {
        if (isOk(m)) { ans = m; }
    }

    ans.writeln;
}

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

immutable int INF = 10L ^^ 9 + 23;

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

    auto mx = new bool[][] (n+1, n+1);

    foreach (i; 1 .. n+1) {
        foreach (j; 0 .. n/4) {
            char c;
            readf("%s", &c);

            int v = c >= 'A' ? c - 'A' + 10 : c - '0';
            foreach (k; 0 .. 4) {
                mx[i][1 + j*4 + k] = (v & (1 << (3 - k))) > 0;
            }
        }

        readln;
    }

    debug { mx.each!writeln; }

    auto val = new int[][] (n+1, n+1);

    foreach (i; 1 .. n+1) {
        foreach (j; 1 .. n+1) {
            val[i][j] = mx[i][j] + val[i-1][j] + val[i][j-1] - val[i-1][j-1];
        }
    }

    debug { val.each!writeln; }

    bool isOk(int x) {
        int sz = x*x;
        foreach (i; 1 .. n/x + 1) {
            foreach (j; 1 .. n/x + 1) {
                int cval = val[i*x][j*x] - val[(i-1)*x][j*x] - val[i*x][(j-1)*x] + val[(i-1)*x][(j-1)*x];
                if (cval != 0 && cval != sz) { return false; }
            }
        }

        return true;
    }

    int le = 1, r = n;
    while (le < r) {
        int m = (le + r) / 2 + 1;
        if (isOk(m)) { le = m; }
        else { r = m-1; }
    }

    le.writeln;
}


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

DList!string _words;
void read(T)(out T t)
{
  import std.stdio: readln;
  while(_words.empty)
    {
      import std.array: split;
      foreach(word; readln.split)
        {
          _words.insertBack(word);
        }
    }
  import std.conv: to;
  string word = _words.front;
  _words.removeFront;
  t = to!T(word);
}

long n, h, m, k;

int opCmp(long[2] a, long[2] b)
{
  if (a[0] < b[0])
    return -1;
  if (a[0] > b[0])
    return +1;
  if (a[1] < b[1])
    return -1;
  if (a[1] > b[1])
    return +1;
  return 0;
}

long pmod(long a, long m)
{
  return (a%m + m)%m;
}

void main()
{
  read(n), read(h), read(m), read(k);
  import std.container: redBlackTree, RedBlackTree;
  auto positions = redBlackTree!long();
  auto freights = new long[cast(size_t)n];
  foreach(i; 0 .. n)
    {
      long hi, mi;
      read(hi), read(mi); // realmente no importa hi??
      positions.insert(mi % (m / 2));
      freights[cast(size_t)i] = mi % (m / 2);
    }
  auto originalFreights = freights.dup;
  auto sortedFreights = sort(freights);
  import std.algorithm: min;
  long minRemoved = long.max;
  long bestPosition = -1;
  foreach(position; positions)
    {
      long r = position;
      long l = r - k;
      l = pmod(l, m / 2);
      long removed;
      if (l <= r)
        removed = sortedFreights.upperBound(l).lowerBound(r).length;
      else
        removed = sortedFreights.upperBound(l).length + sortedFreights.lowerBound(r).length;

      if (removed < minRemoved)
        {
          bestPosition = position;
          minRemoved = removed;
        }
    }
  writeln(minRemoved, " ", bestPosition);
  long written = 0;
  foreach(i, freight; originalFreights)
    {
      long r = bestPosition;
      long l = r - k;
      l = pmod(l, m / 2);
      if (l <= r)
        {
          if (freight > l && freight < r)
            {
              written++;
              write(i + 1, " ");
              continue;
            }
        }
      else
        {
          if (freight > l || freight < r)
            {
              written++;
              write(i + 1, " ");
              continue;
            }
        }
    }
  writeln;
  assert(written == minRemoved);
}

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

void main ()
{
	int n, h, m, k;
	while (readf !(" %s %s %s %s") (n, h, m, k) > 0)
	{
		auto m2 = m / 2;
		auto r = new int [n];
		auto t = new int [n];
		foreach (i; 0..n)
		{
			readf !(" %s %s") (r[i], t[i]);
			t[i] %= m2;
		}
		auto p = n.iota.array;
		p.schwartzSort !(i => t[i]);
		foreach (i; 0..n)
		{
			p ~= p[i];
		}
		int best = n + 1;
		int pos = -1;
		int j = 0;
		foreach (i; 0..n)
		{
			auto cur = t[p[i]];
			while (j < n * 2)
			{
				auto next = t[p[j]] + m2 * (j >= n);
				if (next >= cur + k)
				{
					break;
				}
				j++;
			}
			if (best > j - i - 1)
			{
				best = j - i - 1;
				pos = t[p[j]];
			}
		}

		writeln (best, " ", pos);
		int [] answer;
		foreach (i; 0..n)
		{
			if ((0 < pos - t[i] && pos - t[i] < k) ||
			    (0 < pos - t[i] + m2 && pos - t[i] + m2 < k))
			{
				answer ~= i + 1;
			}
		}
		writefln !("%(%s %)") (answer);
	}
}


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

struct ModInt(int M_) {
  import std.conv : to;
  alias M = M_;
  int x;
  this(ModInt a) { x = a.x; }
  this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }
  ref ModInt opAssign(long a) { return (this = ModInt(a)); }
  ref ModInt opOpAssign(string op)(ModInt a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x < 0) x += M; }
    else static if (op == "*") { x = cast(int)((cast(long)(x) * a.x) % M); }
    else static if (op == "/") { this *= a.inv(); }
    else static assert(false);
    return this;
  }
  ref ModInt opOpAssign(string op)(long a) {
    static if (op == "^^") {
      if (a < 0) return (this = inv()^^(-a));
      ModInt t2 = this, te = ModInt(1);
      for (long e = a; e > 0; e >>= 1) {
        if (e & 1) te *= t2;
        t2 *= t2;
      }
      x = cast(int)(te.x);
      return this;
    } else return mixin("this " ~ op ~ "= ModInt(a)");
  }
  ModInt inv() const {
    int a = x, b = M, y = 1, z = 0, t;
    for (; ; ) {
      t = a / b; a -= t * b;
      if (a == 0) {
        assert(b == 1 || b == -1);
        return ModInt(b * z);
      }
      y -= t * z;
      t = b / a; b -= t * a;
      if (b == 0) {
        assert(a == 1 || a == -1);
        return ModInt(a * y);
      }
      z -= t * y;
    }
  }
  ModInt opUnary(string op: "-")() const { return ModInt(-x); }
  ModInt opBinary(string op, T)(T a) const {
    return mixin("ModInt(this) " ~ op ~ "= a");
  }
  ModInt opBinaryRight(string op)(long a) const {
    return mixin("ModInt(a) " ~ op ~ "= this");
  }
  bool opCast(T: bool)() const { return (x != 0); }
  string toString() const { return x.to!string; }
}

enum MO = 998244353;
alias Mint = ModInt!MO;

void main() {
  try {
    for (; ; ) {
      const S = readToken();
      const T = readToken();
      const L = cast(int)(S.length);
      const M = cast(int)(T.length);

      auto dp = new Mint[][](L + 1, L + 1);
      foreach (j; M .. L + 1) {
        dp[0][j] += 1;
      }
      foreach_reverse (w; 1 .. L + 1) {
        foreach (i; 0 .. L - w + 1) {
          const j = i + w;
          // front
          if (i >= M || S[w - 1] == T[i]) {
            dp[i + 1][j] += dp[i][j];
          }
          // back
          if (j - 1 >= M || S[w - 1] == T[j - 1]) {
            dp[i][j - 1] += dp[i][j];
          }
        }
      }
      Mint ans;
      foreach (i; 0 .. L + 1) {
        ans += dp[i][i];
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

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

immutable int mod = 998_244_353;

void main ()
{
	string s;
	while ((s = readln.strip ()) != "")
	{
		auto t = readln.strip;
		auto n = s.length.to !(int);
		auto m = t.length.to !(int);
		auto f = new int [] [] (n + 1, n + 1);
		foreach (i; 0..n + 1)
		{
			f[i][i] = 1;
		}
		foreach (len; 0..n)
		{
			auto letter = s[len];
			foreach (start; 0..n + 1 - len)
			{
				auto finish = start + len;
				auto cur = f[start][finish];
				if (start > 0 &&
				    (start - 1 >= m || letter == t[start - 1]))
				{
					f[start - 1][finish] += cur;
					if (f[start - 1][finish] >= mod)
					{
						f[start - 1][finish] -= mod;
					}
				}
				if (finish < n &&
				    (finish >= m || letter == t[finish]))
				{
					f[start][finish + 1] += cur;
					if (f[start][finish + 1] >= mod)
					{
						f[start][finish + 1] -= mod;
					}
				}
			}
		}
		writeln (sum (f[0][m..$], 0L) % mod);
	}
}


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;

bool solve(int[] a, int sum, ref Tuple!(int, int)[] ans)
{
  if (a.length == 0)
    return sum == 0;

  if (sum == 0) {
    ans ~= tuple(cast(int)a.length, cast(int)a.length);
    return solve(a[0 .. $ - 1], sum, ans);
    return true;
  }

  if (sum < 0) {
    if (a.length >= 2 && a[$ - 1] < 0) {
      ans ~= tuple(cast(int)a.length - 1, cast(int)a.length);
      return solve(a[0 .. $ - 2], sum - 2 * a[$ - 1], ans);
    } else {
      ans ~= tuple(cast(int)a.length, cast(int)a.length);
      return solve(a[0 .. $ - 1], sum, ans);
    }
  } else {
    if (a.length >= 2 && a[$ - 1] > 0) {
      ans ~= tuple(cast(int)a.length - 1, cast(int)a.length);
      return solve(a[0 .. $ - 2], sum - 2 * a[$ - 1], ans);
    } else {
      ans ~= tuple(cast(int)a.length, cast(int)a.length);
      return solve(a[0 .. $ - 1], sum, ans);
    }
  }
}

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    int n;
    readf!" %d "(n);
    auto a = readln.splitter.map!(to!int).array;
    Tuple!(int, int)[] ans;
    if (solve(a, a.sum, ans)) {
      ans.reverse;
      writeln(ans.length);
      foreach (x; ans) {
        writefln("%d %d", x[0], x[1]);
      }
    } else {
      writeln(-1);
    }
  }
}

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

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;
		if (sum (a) % 2 != 0)
		{
			writeln (-1);
			continue;
		}
		auto b = a.enumerate.filter !(x => x.value != 0).array;
		b ~= typeof (b.front) (n, 0);
		int [] [] answer;
		if (b[0].index > 0)
		{
			answer ~= [0, b[0].index];
		}
		for (int i = 0; i + 2 < b.length; i += 2)
		{
			if (b[i].value == b[i + 1].value)
			{
				if ((b[i].index & 1) != (b[i + 1].index & 1))
				{
					answer ~= [b[i].index, b[i + 2].index];
				}
				else
				{
					answer ~= [b[i].index, b[i + 1].index - 1];
					answer ~= [b[i + 1].index - 1, b[i + 2].index];
				}
			}
			else
			{
				answer ~= [b[i].index, b[i + 1].index];
				answer ~= [b[i + 1].index, b[i + 2].index];
			}
		}
		writeln (answer.length);
		foreach (ref line; answer)
		{
			writeln (line[0] + 1, " ", line[1]);
		}
	}
}

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

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

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

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

int N;
int[] A;

int[] solve() {
  const sumA = A.sum;
  if (sumA % 2 != 0) {
    return null;
  }

  auto fs = new bool[N];
  bool greedy(int a, int k) {
    foreach (i; 0 .. N) {
      if (i == 0 || fs[i - 1]) {
        continue;
      }
      if (A[i] == a && k > 0) {
        fs[i] = true;
        --k;
      }
    }
    return (k == 0);
  }
  if (sumA >= 0) {
    if (!greedy(+1, sumA / 2)) return null;
  } else {
    if (!greedy(-1, -sumA / 2)) return null;
  }
  debug {
    writeln("fs = ", fs);
  }

  int[] cuts;
  cuts ~= 0;
  foreach (i; 1 .. N) {
    if (fs[i - 1] == fs[i]) {
      assert(!fs[i]);
      cuts ~= i;
    }
  }
  cuts ~= N;
  return cuts;
}

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

        const ans = solve;
        debug {
          writeln(A, ": ", ans);
        }
        const len = cast(int)(ans.length) - 1;
        if (len >= 0) {
          writeln(len);
          foreach (i; 0 .. len) {
            writeln(ans[i] + 1, " ", ans[i + 1]);
          }
        } else {
          writeln(-1);
        }
      }
    }
  } catch (EOFException e) {
  }
}

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

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;
		if (sum (a) % 2 != 0)
		{
			writeln (-1);
			continue;
		}
		if (!any (a))
		{
			writeln (1);
			writeln (1, " ", n);
			continue;
		}
		auto b = a.enumerate.filter !(x => x.value != 0).array;
		b ~= typeof (b.front) (n, 0);
		int [] [] answer;
		for (int i = 0; i + 2 < b.length; i += 2)
		{
			if (b[i].value == b[i + 1].value)
			{
				if ((b[i].index & 1) != (b[i + 1].index & 1))
				{
					answer ~= [b[i].index, b[i + 2].index];
				}
				else
				{
					answer ~= [b[i].index, b[i + 1].index - 1];
					answer ~= [b[i + 1].index - 1, b[i + 2].index];
				}
			}
			else
			{
				answer ~= [b[i].index, b[i + 1].index];
				answer ~= [b[i + 1].index, b[i + 2].index];
			}
		}
		writeln (answer.length);
		foreach (ref line; answer)
		{
			writeln (line[0] + 1, " ", line[1]);
		}
	}
}

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

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;
		if (sum (a) % 2 != 0)
		{
			writeln (-1);
			continue;
		}
		if (!any (a))
		{
			writeln (1);
			writeln (1, " ", n);
			continue;
		}
		auto b = a.enumerate.filter !(x => x.value != 0).array;
		b ~= typeof (b.front) (n, 0);
		int [] [] answer;
		for (int i = 0; i + 2 < b.length; i += 2)
		{
			if (b[i].value == b[i + 1].value)
			{
				answer ~= [b[i].index, b[i + 2].index];
			}
			else
			{
				answer ~= [b[i].index, b[i + 1].index];
				answer ~= [b[i + 1].index, b[i + 2].index];
			}
		}
		writeln (answer.length);
		foreach (ref line; answer)
		{
			writeln (line[0] + 1, " ", line[1]);
		}
	}
}

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

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

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

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

int N;
int[] A;

int[] solve() {
  const sumA = A.sum;
  if (sumA % 2 != 0) {
    return null;
  }

  auto fs = new bool[N];
  bool greedy(int a, int k) {
    foreach (i; 0 .. N) {
      if (i > 0 && fs[i - 1]) {
        continue;
      }
      if (A[i] == a && k > 0) {
        fs[i] = true;
        --k;
      }
    }
    return (k == 0);
  }
  if (sumA >= 0) {
    if (!greedy(+1, sumA / 2)) return null;
  } else {
    if (!greedy(-1, -sumA / 2)) return null;
  }

  int[] cuts;
  cuts ~= 0;
  foreach (i; 1 .. N) {
    if (fs[i - 1] == fs[i]) {
      assert(!fs[i]);
      cuts ~= i;
    }
  }
  cuts ~= N;
  return cuts;
}

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

        const ans = solve;
        debug {
          writeln(A, ": ", ans);
        }
        const len = cast(int)(ans.length) - 1;
        if (len >= 0) {
          writeln(len);
          foreach (i; 0 .. len) {
            writeln(ans[i] + 1, " ", ans[i + 1]);
          }
        } else {
          writeln(-1);
        }
      }
    }
  } catch (EOFException e) {
  }
}


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

string FMT_F = "%.10f";

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

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

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

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

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

		foreach (i; 1..min(k+1, n))
		{
			a[0] += a[i];
		}
		ans[ti] = a[0];
	}

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

// Vicfred
// https://codeforces.com/contest/1430/problem/B
// greedy
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    int t = readln.chomp.to!int;

    while(t--) {
        int n, k;
        readf("%s %s\n", &n, &k);

        long[] a = readln.split.map!(to!long).array;

        a.sort;
        a.reverse;

        long ans = 0L;
        for(int i = 0; i <= k; ++i)
            ans += a[i];

        ans.writeln;
    }
}


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

T read(T)() { return readln.chomp.to!T; }
T[] readarray(T)() { return readln.chomp.split(" ").map!(to!T).array; }

void solve() {
    int n = read!int;
    auto a = readarray!int;
    auto s = readln.strip;
    dchar[int] dict;
    foreach (tup; zip(a, s))
    {
        if (tup[0] in dict)
            if (dict[tup[0]] != tup[1]) {
                writeln("NO");
                return;
            }
        dict[tup[0]] = tup[1];
    }
    writeln("YES");
}

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

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;

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto n = readln.strip.to!int;
    auto a = readln.splitter.map!(to!int).array;
    auto s = readln.strip;
    char[int] m;
    bool good = true;
    foreach (i ; 0 .. a.length) {
      if (a[i] in m) {
        if (m[a[i]] != s[i]) {
          good = false;
          break;
        }
      } else {
        m[a[i]] = s[i];
      }
    }
    writeln(good ? "YES" : "NO");
  }
}


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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		sort (a);
		a ~= int.max;
		auto b = group (a);
		debug {writeln (b);}

		int [] res;
		int [] cur;
		int prev = int.min;
		int total = 0;
		foreach (ref g; b)
		{
			auto value = g[0];
			auto amount = g[1].to !(int);

			if (prev + 1 < value)
			{
				if (res.length < cur.length)
				{
					res = cur;
				}
				cur = null;
			}

			if (amount == 1)
			{
				cur ~= value;
				if (res.length < cur.length)
				{
					res = cur;
				}
				cur = [value];
			}
			else
			{
				cur ~= value.repeat (amount).array;
			}

			prev = value;
		}

		int [] temp;
		int [] add;
		int last = res.front;
		foreach (ref x; res)
		{
			if (last < x)
			{
				add ~= x;
				last = x;
			}
			else
			{
				temp ~= x;
			}
		}
		reverse (add);
		res = temp ~ add;

		writeln (res.length);
		writefln ("%(%s %)", res);
	}
}

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

void solve(){

	int n = read.to!int;

	int[] as;
	foreach(i; 0 .. n) as ~= read.to!int;
	log("as:", as);
	int amax = -1;
	foreach(a; as) amax = max(amax, a);

	int[] acount = new int[](amax + 1);
	foreach(a; as) acount[a] += 1;
	log("acount:", acount);

	int l, r, sum;
	int bestl = 0, bestr = -1, bestsum = 0;
	int s = 0; // 0=not selecting, 1=selecting
	foreach(i; 0 .. amax + 1){
		if(s == 0){
			if(acount[i] == 0) continue;
			if(acount[i] >= 1){
				sum = acount[i];
				s = 1;
				l = r = i;
				if(sum > bestsum) bestl = l, bestr = r, bestsum = sum;
			}
		}
		else{
			sum += acount[i];
			r = i;
			if(sum > bestsum) bestl = l, bestr = r, bestsum = sum;
			if(acount[i] == 0) s = 0;
			if(acount[i] == 1){
				sum = acount[i];
				s = 1;
				l = r = i;
			}
		}
		log("i:", i, "l:", l, "r:", r, "sum:", sum, "bestl:", bestl, "bestr:", bestr, "bestsum:", bestsum);
	}

	int[] ans;
	foreach(i; bestl .. bestr + 1) ans ~= i, acount[i] -= 1;

	foreach_reverse(i; bestl .. bestr + 1) while(acount[i] > 0) ans ~= i, acount[i] -= 1;

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

}

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

void solve(){

	int n = read.to!int;

	int[] as;
	foreach(i; 0 .. n) as ~= read.to!int;
	log("as:", as);
	int amax = -1;
	foreach(a; as) amax = max(amax, a);

	int[] acount = new int[](amax + 1);
	foreach(a; as) acount[a] += 1;
	log("acount:", acount);

	int l, r, sum;
	int bestl = 0, bestr = -1, bestsum = 0;
	int s = 0; // 0=not selecting, 1=selecting
	foreach(i; 0 .. amax + 1){
		if(acount[i] == 0){
			s = 0, sum = 0;
			l = i + 1;
		}
		else if(acount[i] == 1){
			if(s == 0){
				l = r = i, sum += acount[i];
				if(sum > bestsum) bestr = r, bestl = l, bestsum = sum;
				s = 1, sum = 1;
				l = r = i;
			}
			else{
				r = i, sum += acount[i];
				if(sum > bestsum) bestr = r, bestl = l, bestsum = sum;
				s = 0, sum = 0;
				l = i + 1;
			}
		}
		else{
			if(s == 0) s = 1;
			r = i, sum += acount[i];
			if(sum > bestsum) bestr = r, bestl = l, bestsum = sum;
		}
		log("i:", i, "l:", l, "r:", r, "sum:", sum, "bestl:", bestl, "bestr:", bestr, "bestsum:", bestsum);
	}

	int[] ans;
	foreach(i; bestl .. bestr + 1) ans ~= i, acount[i] -= 1;

	foreach_reverse(i; bestl .. bestr + 1) while(acount[i] > 0) ans ~= i, acount[i] -= 1;

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

}

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

void solve(){

	int n = read.to!int;

	int[] as;
	foreach(i; 0 .. n) as ~= read.to!int;
	log("as:", as);
	int amax = -1;
	foreach(a; as) amax = max(amax, a);

	int[] acount = new int[](amax + 1);
	foreach(a; as) acount[a] += 1;
	log("acount:", acount);

	int l, r, sum;
	int bestl = 0, bestr = -1, bestsum = 0;
	int s = 0; // 0=not selecting, 1=selecting
	foreach(i; 0 .. amax + 1){
		if(acount[i] == 0){
			s = 0, sum = 0;
			l = i + 1;
		}
		else if(acount[i] == 1){
			if(s == 0){
				l = r = i, sum += acount[i];
				if(sum > bestsum) bestr = r, bestl = l, bestsum = sum;
				s = 1, sum = 1;
				l = r = i;
			}
			else{
				r = i, sum += acount[i];
				if(sum > bestsum) bestr = r, bestl = l, bestsum = sum;
				s = 0, sum = 0;
				l = i + 1;
			}
		}
		else{
			if(s == 0) s = 1;
			r = i, sum += acount[i];
			if(sum > bestsum) bestr = r, bestl = l, bestsum = sum;
		}
		log("i:", i, "l:", l, "r:", r, "sum:", sum, "bestl:", bestl, "bestr:", bestr, "bestsum:", bestsum);
	}

	int[] ans;
	foreach(i; bestl .. bestr + 1) ans ~= i, acount[i] -= 1;

	foreach_reverse(i; bestl .. bestr + 1) while(acount[i] > 0) ans ~= i, acount[i] -= 1;

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

}

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

void solve(){

	int n = read.to!int;

	int[] as;
	foreach(i; 0 .. n) as ~= read.to!int;
	log("as:", as);
	int amax = -1;
	foreach(a; as) amax = max(amax, a);

	int[] acount = new int[](amax + 1);
	foreach(a; as) acount[a] += 1;
	log("acount:", acount);

	int l, r, sum;
	int bestl = 0, bestr = -1, bestsum = 0;
	int s = 0; // 0=not selecting, 1=selecting
	foreach(i; 0 .. amax + 1){
		if(s == 0){
			if(acount[i] == 0) continue;
			if(acount[i] >= 1){
				sum = acount[i];
				s = 1;
				l = r = i;
				if(sum > bestsum) bestl = l, bestr = r, bestsum = sum;
			}
		}
		else{
			sum += acount[i];
			r = i;
			if(sum > bestsum) bestl = l, bestr = r, bestsum = sum;
			if(acount[i] <= 1) s = 0;
		}
		log("i:", i, "l:", l, "r:", r, "sum:", sum, "bestl:", bestl, "bestr:", bestr, "bestsum:", bestsum);
	}

	int[] ans;
	foreach(i; bestl .. bestr + 1) ans ~= i, acount[i] -= 1;

	foreach_reverse(i; bestl .. bestr + 1) while(acount[i] > 0) ans ~= i, acount[i] -= 1;

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

}


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

  int n, x; rd(n, x);
  auto a=readln.split.to!(int[]);

  int[int] bef, aft;
  foreach(e; a){
    if(e in bef) bef[e]++;
    else bef[e]=1;
    if ((e&x) in aft) aft[e&x]++;
    else aft[e&x]=1;
  }
  int mn=3;
  foreach(e; a){
    if(bef[e]>1) mn=0;
    else{
      bef[e]--;
      if(((e&x) in bef) && bef[e&x]>0) mn=min(mn, 1);
      if(aft[e&x]>1) mn=min(mn, 2);
      bef[e]++;
    }
  }
  if(mn>2) writeln(-1);
  else writeln(mn);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}

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

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

    int[int] cnt;
    readln.chomp.split.map!(to!int).each!(v => ++cnt[v]);

    debug { cnt.writeln; }

    int ans = 3;
    bool [int] afterAnd;
    foreach (k, v; cnt) {
        if (v > 1) {
            ans = 0;
            break;
        }

        auto now = k & x;
        if (now != k && now in cnt) ans = min(ans, 1);
        else if (now in afterAnd) ans = min(ans, 2);

        afterAnd[now] = true;
    }

    if (ans == 3) ans = -1;

    ans.writeln;
}


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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.strip;
		auto b = readln.strip;
		int res = 0;
		int pos = -1;
		char last = '*';
		foreach (i; 0..n)
		{
			if (a[i] != b[i])
			{
				res += 1;
				if (pos + 1 == i && last == b[i])
				{
					res -= 1;
				}
				else
				{
					pos = i;
					last = a[i];
				}
			}
		}
		writeln (res);
	}
}

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

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

    auto s = readln.chomp;
    auto t = readln.chomp;
    auto ans = 0;
    auto chg = false;
    foreach (i; 0 .. n) {
        if ((s[i] == t[i]) || (i > 0 && s[i-1] != s[i] && chg)) {
            chg = false;
            continue;
        }

        ++ans;
        chg = true;
    }

    ans.writeln;
}

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

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.chomp;
    auto B = readln.chomp;
    long ans = 0;

    for (int i = 0; i < N; ++i) {
        if (A[i] == B[i]) continue;
        if (i == N - 1) {
            ans += 1;
        } else if (A[i+1] != B[i+1] && A[i] != A[i+1]) {
            ans += 1;
            i += 1;
        } else {
            ans += 1;
        }
    }

    ans.writeln;
}

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

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.chomp;
    auto B = readln.chomp;
    long ans = 0;

    for (int i = 0; i < N; ++i) {
        if (A[i] != B[i]) {
            if (i == N - 1 || A[i+1] == B[i+1]) {
                ans += 1;
            } else {
                ans += 1;
                ++i;
            }
        }
    }

    ans.writeln;
}

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

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

    auto s = readln.chomp;
    auto t = readln.chomp;
    auto ans = 0;
    foreach (i; 0 .. n) {
        if (s[i] == t[i]) continue;
        if (i > 0 && s[i-1] != s[i] && s[i-1] != t[i-1]) continue;

        ++ans;
    }

    ans.writeln;
}


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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new long[][](t, 26);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto m = RD!int;
		auto s = RD!string;
		auto p = RDA!int;
		auto cnt = new long[][](n+1, 26);
		foreach (i; 0..n)
		{
			auto num = s[i]-'a';
			cnt[i+1] = cnt[i].dup;
			++cnt[i+1][num];
		}
		foreach (i; 0..m)
		{
			ans[ti][] += cnt[p[i]][];
		}
		ans[ti][] += cnt[n][];
	}

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

module C;

import std.stdio : readln, write, writeln;

struct IO {
  import std.conv : to;
  import std.range : empty, front, popFront, split;

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

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

  string[] tokens;
}

void main() {
  IO io;
  int T = io.readInt;
  while (T--) {
    int n = io.readInt;
    int m = io.readInt;
    string s = io.readToken;
    long[] sum = new long[n];
    sum[n - 1]++;
    for (int i = 0; i < m; ++i) {
      sum[io.readInt - 1]++;
    }
    for (int i = n - 1; i--;) {
      sum[i] += sum[i + 1];
    }
    long[] count = new long[26];
    for (int i = 0; i < n; ++i) {
      count[s[i] - 'a'] += sum[i];
    }
    for (int i = 0; i < 26; ++i) {
      write(count[i], " \n"[i == 25]);
    }
  }
}

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

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

void solve(){
        foreach(_; 0 .. rint){
        int n = rint, m = rint;
        int[] as = readln.chomp.map!ctoi.array;
        int[] ps = rint(m).map!(x => x - 1).array;

        int[] us = new int[](n); // mistake just after position p (; 0 .. n)
        foreach(p; ps) us[p] += 1;

        int[] ans = new int[](26);
        int[] cs = new int[](26);
        foreach(i; 0 .. n){
            cs[as[i]] += 1;
            foreach(k; 0 .. 26) ans[k] += cs[k] * us[i];
        }

        foreach(k; 0 .. 26) ans[k] += cs[k];

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

}


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

string FMT_F = "%.10f";

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

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

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

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

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

		auto cnt = new long[](n+1);
		foreach (i; 0..n)
		{
			cnt[i+1] = cnt[i];
			if (a[i] == '1')
				++cnt[i+1];
			else
				--cnt[i+1];
		}

		bool ok = true;
		long inv;
		foreach_reverse (i; 0..n)
		{
			auto x = a[i]-'0';
			auto y = b[i]-'0';
			if ((x^inv) == y) continue;

			if (cnt[i+1] != 0)
			{
				debug writeln("i:", i);
				ok = false;
				break;
			}
			inv ^= 1;
		}
		ans[ti] = ok;
	}

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

// Vicfred
// https://codeforces.com/contest/1504/problem/B
// greedy
import std.stdio;

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

while(t--) {
    int n;
    readf("%s\n", &n);
    string a, b;
    readf("%s\n", &a);
    readf("%s\n", &b);

    a ~= '0';
    b ~= '0';

    int cumulative = 0;
    bool valid = true;
    for(uint i = 0; i < n; ++i) {
        if(a[i] == '0')
            cumulative += 1;
        else
            cumulative -= 1;
        if((a[i] == b[i]) != (a[i+1] == b[i+1]) && cumulative != 0) {
            valid = false;
            break;
        }
    }
    if(valid)
        "YES".writeln;
    else
        "NO".writeln;
}
}

// Vicfred
// https://codeforces.com/contest/1504/problem/B
// greedy
import std.stdio;

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

while(t--) {
    int n;
    readf("%s\n", &n);
    string a, b;
    readf("%s\n", &a);
    readf("%s\n", &b);

    int cumulative = 0;
    bool valid = true;
    for(uint i = 0; i < n - 1; ++i) {
        if(a[i] == '0')
            cumulative += 1;
        else
            cumulative -= 1;
        if((a[i] == b[i]) != (a[i+1] == b[i+1]) && cumulative != 0) {
            valid = false;
            break;
        }
    }
    if(valid)
        "YES".writeln;
    else
        "NO".writeln;
}
}

// Vicfred
// https://codeforces.com/contest/1504/problem/B
// greedy
import std.stdio;

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

while(t--) {
    int n;
    readf("%s\n", &n);
    string a, b;
    readf("%s\n", &a);
    readf("%s\n", &b);

    int cumulative = 0;
    bool valid = true;
    for(uint i = 0; i < n - 1; ++i) {
        if(a[i] == '0')
            cumulative += 1;
        else
            cumulative -= 1;
        if((a[i] == b[i]) && a[i+1] != b[i+1] && cumulative != 0) {
            valid = false;
            break;
        }
    }
    if(valid)
        "YES".writeln;
    else
        "NO".writeln;
}
}