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 a = RDA!int;

		auto dp = new int[][](n+1, 2);
		foreach (i; 0..dp.length)
		{
			dp[i][] = n;
		}
		dp[0][0] = 0;

		foreach (i; 0..n)
		{
			dp[i+1][1].chmin(dp[i][0]+a[i]);
			if (i < n-1)
				dp[i+2][1].chmin(dp[i][0]+a[i]+a[i+1]);
			dp[i+1][0].chmin(dp[i][1]);
			if (i < n-1)
				dp[i+2][0].chmin(dp[i][1]);
		}

		ans[ti] = min(dp[n][0], dp[n][1]);
	}

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

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

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

void solve(){
    int n;
    n = rd!int;
    int[] arr = rdarr!int;
    int[][] dp = new int[][](2, n+1);
    if(n == 1){
        writeln(to!int(arr[0] == 1));
        return;
    }
    dp[1][0] = arr[0];
    dp[1][1] = dp[1][0] + arr[1];
    dp[0][0] = to!int(1e7);
    dp[0][1] = dp[1][0];
    foreach(i; 2..(n)){
        dp[0][i] = min(dp[1][i-2], dp[1][i-1]);
        dp[1][i] = min(arr[i-1] + dp[0][i-2], dp[0][i-1]) + arr[i];
    }
    int res = min(dp[1][n-1], dp[0][n-1]);
    /* writeln(dp); */
    writeln(res);
}

void main(){
    long t = 1;
    t = rd;
    while(t--) solve();
    stdout.flush;
}

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

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

void solve(){
    int n;
    n = rd!int;
    int[] arr = rdarr!int;
    int[][] dp = new int[][](2, n+1);
    if(n == 1){
        writeln(to!int(arr[0] == 1));
        return;
    }
    dp[1][0] = arr[0];
    dp[1][1] = dp[1][0] + arr[1];
    dp[0][0] = to!int(1e8);
    dp[0][1] = dp[1][0];
    foreach(i; 2..(n)){
        dp[0][i] = min(dp[1][i-2], dp[1][i-1]);
        dp[1][i] = min(arr[i-1] + dp[0][i-2], dp[0][i-1]) + arr[i];
    }
    int res = min(dp[1][n-1], dp[0][n-1]);
    /* writeln(dp); */
    writeln(res);
}

void main(){
    long t = 1;
    t = rd;
    while(t--) solve();
    stdout.flush;
}

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

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

void solve(){
    int n;
    n = rd!int;
    int[] arr = rdarr!int;
    int[][] dp = new int[][](2, n+1);
    if(n == 1){
        writeln(to!int(arr[0] == 1));
    }

    dp[1][0] = arr[0];
    dp[1][1] = dp[1][0] + arr[1];
    dp[0][0] = to!int(1e7);
    dp[0][1] = dp[1][0];
    foreach(i; 2..(n)){
        dp[0][i] = min(dp[1][i-2], dp[1][i-1]);
        dp[1][i] = min(arr[i-1] + dp[0][i-2], dp[0][i-1]) + arr[i];
    }
    int res = min(dp[1][n-1], dp[0][n-1]);
    /* writeln(dp); */
    writeln(res);
}

void main(){
    long t = 1;
    t = rd;
    while(t--) solve();
    stdout.flush;
}

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

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

void solve(){
    int n;
    n = rd!int;
    int[] arr = rdarr!int;
    int[][] dp = new int[][](2, n);
    int pt = (arr[0] == 1);
    dp[1][0] = pt;
    dp[0][0] = to!int(1e8);
    foreach(i; 1..(n)){
        dp[0][i] = dp[1][i-1];
        dp[1][i] = dp[1][i-1] + (arr[i] == 1);
        if(i > 1){
            dp[0][i] = min(dp[1][i-2], dp[1][i]);
            dp[1][i] = min((arr[i-1] == 1) + dp[0][i-2], dp[0][i-1]) + (arr[i] == 1);
        }
    }
    int res = min(dp[1][n-1], dp[0][n-1]);
    if(n == 1){ res = pt; }
    /* writeln(dp); */
    writeln(res);
}

void main(){
    long t = 1;
    t = rd;
    while(t--) solve();
    stdout.flush;
}

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

string FMT_F = "%.10f";

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

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

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

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 a = RDA;

		int i;
		bool turn;
		while (i < n)
		{
			if (turn)
			{
				++i;
				if (i < n)
				{
					if (a[i] == 1)
						++i;
				}
				turn = !turn;
			}
			else
			{
				if (a[i] == 1)
				{
					++ans[ti];
				}
				++i;
				if (i < n)
				{
					if (a[i] == 0)
						++i;
				}
				turn = !turn;
			}
		}
	}

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

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

string FMT_F = "%.10f";

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

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

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

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 a = RDA;

		int i;
		bool turn;
		while (i < n)
		{
			if (turn)
			{
				i += 2;
				turn = !turn;
			}
			else
			{
				if (a[i] == 1)
				{
					++ans[ti];
				}
				++i;
				if (i < n)
				{
					if (a[i] == 0)
						++i;
				}
				turn = !turn;
			}
		}
	}

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


import std.algorithm;
import std.stdio;

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		auto p = new int [n];
		foreach (ref x; p)
		{
			readf (" %s", &x);
			x--;
		}

		real total = 0;
		real answer = 0;

		real calc ()
		{
			int res = 0;
			foreach (i; 0..n - 1)
			{
				foreach (j; i + 1..n)
				{
					res += (p[i] > p[j]);
				}
			}
			return res;
		}

		void recur (int d)
		{
			if (d == 0)
			{
				total += 1;
				answer += calc ();
				return;
			}

			foreach (i; 0..n)
			{
				foreach (j; i..n)
				{
					reverse (p[i..j + 1]);
					recur (d - 1);
					reverse (p[i..j + 1]);
				}
			}
		}

		recur (k);
		writefln ("%.20f", answer / total);
	}
}

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

int mul(int n)
{
    auto res = 1;
    foreach (i; 2 .. n + 1)
    {
        res *= i;
    }
    return res;
}

int calc(int[] p)
{
    auto n = cast(int)p.length;
    auto f = new bool[n + 1];
    fill(f, false);
    auto res = 0;
    foreach (i; 0 .. n)
    {
        auto cnt = 0;
        foreach (j; 1 .. p[i])
        {
            if (!f[j])
            {
                ++ cnt;
            }
        }
        res += cnt * mul(n - i - 1);
        f[p[i]] = true;
    }
    return res;
}

int countReverse(int[] p)
{
    auto res = 0;
    foreach (i; 0 .. p.length)
    {
        foreach (j; i + 1 .. p.length)
        {
            if (p[i] > p[j])
            {
                ++ res;
            }
        }
    }
    return res;
}

void reverse(int[] p, int left, int right)
{
    while (left < right)
    {
        swap(p[left], p[right]);
        ++ left;
        -- right;
    }
}

double saiki(int[] p, int n, int c, int k, double[][] dp)
{
    auto r = calc(p);
    if (dp[r][c] != -1)
    {
        return dp[r][c];
    }
    if (c == k)
    {
        auto cnt = countReverse(p);
        dp[r][c] = cnt;
        return cnt;
    }
    auto res = 0.0;
    auto prob = 1.0 / ((1 + n) * n / 2);
    foreach (i; 0 .. n)
    {
        foreach (j; i .. n)
        {
            reverse(p, i, j);
            auto ret = saiki(p, n, c + 1, k, dp);
            res += prob * ret;
            reverse(p, i, j);
        }
    }
    dp[r][c] = res;
    return res;
}

void solve(int[] p, int n, int k)
{
    auto r = mul(n);
    auto dp = new double[][](r + 1, k + 1);
    foreach (i; 0 .. r + 1)
    {
        fill(dp[i], -1);
    }
    auto ans = saiki(p, n, 0, k, dp);
    writefln("%.10f", ans);
}

int main(string[] args)
{
    int n, k;
    while (readf("%d %d\n", &n, &k) == 2)
    {
        auto p = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &p[i]);
        }
        readln;
        solve(p, n, k);
    }
    return 0;
}

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, k;
    readf("%s %s", &n, &k);
    readln;

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

    DList!(Tuple!(int, int[])) arrs;
    arrs ~= tuple(k, arr);

    while (!arrs.empty && arrs.front[0] > 0) {
        auto cur = arrs.front;
        arrs.removeFront();

        foreach (i; 0 .. n) {
            foreach (j; i .. n) {
                debug { writeln(i, ' ', j); }
                auto rev = cur[1].dup;
                for (int le = i, r = j; le < r; ++le, --r) { swap(rev[le], rev[r]); }

                arrs ~= tuple(cur[0] - 1, rev);
            }
        }
    }

    debug { arrs.each!writeln; }

    long invsum = 0;
    foreach (a; arrs) {
        auto cur = a[1];
        foreach (i; 0 .. n) {
            foreach (j; i+1 .. n) {
                if (cur[i] > cur[j]) { ++invsum; }
            }
        }
    }

    auto ans = invsum.to!double / arrs.array.length;
    ans.writefln!"%.12f";
}

import std.algorithm;
import std.range;
import std.stdio;

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		auto p = new int [n];
		foreach (ref x; p)
		{
			readf (" %s", &x);
			x--;
		}

		if (n < 2)
		{
			writeln (0);
			continue;
		}

		auto f = new real [] [] [] (2, n, n);
		int d = 0;
		foreach (ref g; f[d])
		{
			g[] = 0.0;
		}
		foreach (a; 0..n - 1)
		{
			foreach (b; a + 1..n)
			{
				if (p[a] < p[b])
				{
					f[d][b][a] += 1.0;
				}
				else
				{
					f[d][a][b] += 1.0;
				}
			}
		}

		real total = 2.0 / n / (n + 1);
		foreach (t; 0..k)
		{
			d ^= 1;
			foreach (ref g; f[d])
			{
				g[] = 0.0;
			}
			foreach (lo; 0..n)
			{
				foreach (hi; lo..n)
				{
					auto z = n.iota.array;
					reverse (z[lo..hi + 1]);
					foreach (a; 0..n)
					{
						foreach (b; 0..n)
						{
							f[d][z[a]][z[b]] +=
							    f[!d][a][b];
						}
					}
				}
			}

			foreach (a; 0..n)
			{
				foreach (b; 0..n)
				{
					f[d][a][b] *= total;
				}
			}
		}

		real answer = 0;
		foreach (a; 0..n - 1)
		{
			foreach (b; a + 1..n)
			{
				answer += f[d][a][b];
			}
		}
		writefln ("%.20f", answer);
	}
}

import std.algorithm;
import std.range;
import std.stdio;

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		auto p = new int [n];
		foreach (ref x; p)
		{
			readf (" %s", &x);
			x--;
		}

		if (n < 2)
		{
			writeln (0);
			continue;
		}

		auto f = new real [] [] [] (2, n, n);
		int d = 0;
		foreach (ref g; f[d])
		{
			g[] = 0.0;
		}
		foreach (a; 0..n - 1)
		{
			foreach (b; a + 1..n)
			{
				if (p[a] < p[b])
				{
					f[d][b][a] += 1.0;
				}
				else
				{
					f[d][a][b] += 1.0;
				}
			}
		}

		real total = 1.0 / n / (n - 1);
		foreach (t; 0..k)
		{
			d ^= 1;
			foreach (ref g; f[d])
			{
				g[] = 0.0;
			}
			foreach (lo; 0..n)
			{
				foreach (hi; lo..n)
				{
					auto z = n.iota.array;
					reverse (z[lo..hi + 1]);
					foreach (a; 0..n)
					{
						foreach (b; 0..n)
						{
							f[d][z[a]][z[b]] +=
							    f[!d][a][b];
						}
					}
				}
			}

			foreach (a; 0..n)
			{
				foreach (b; 0..n)
				{
					f[d][a][b] *= total;
				}
			}
		}

		real answer = 0;
		foreach (a; 0..n - 1)
		{
			foreach (b; a + 1..n)
			{
				answer += f[d][a][b];
			}
		}
		writefln ("%.20f", answer);
	}
}


/+ dub.sdl:
    name "B"
    dependency "dcomp" version=">=0.6.0"
+/

import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner, dcomp.array;
import std.typecons;
import std.container.rbtree;

int main() {
    auto sc = new Scanner(stdin);
    int n, k;
    int[] a;
    sc.read(n, k, a); a[] -= 1;

    int[][] l = new int[][n];
    foreach (int i, d; a) {
        l[d] ~= i;
    }
    l.each!((ref v) => v ~= n);
    auto used = new bool[n];
    int sm = 0;

    auto tr = redBlackTree!(int[2]);
    foreach (d; a) {
        int ba = l[d][0];
        l[d] = l[d][1..$];
        int nx = l[d][0];
        if (used[d]) {
            tr.removeKey([ba, d].fixed);
            tr.insert([nx, d].fixed);
            continue;
        }
        // add d
        if (tr.length == k) {
            auto u = tr.back();
            tr.removeBack();
            used[u[1]] = false;
        }
        sm++;
        tr.insert([nx, d].fixed);
        used[d] = true;
    }
    writeln(sm);
    return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/array.d */
// module dcomp.array;

T[N] fixed(T, size_t N)(T[N] a) {return a;}

struct FastAppender(A) {
    import std.algorithm : max;
    import std.range.primitives : ElementEncodingType;
    import core.stdc.string : memcpy;

    private alias T = ElementEncodingType!A;
    private T* _data;
    private size_t len, cap;

    @property size_t length() {return len;}

    void reserve(size_t nlen) {
        import core.memory : GC;
        if (nlen <= cap) return;

        void* nx = GC.malloc(nlen * T.sizeof);

        cap = nlen;
        if (len) memcpy(nx, _data, len * T.sizeof);
        _data = cast(T*)(nx);
    }

    void opOpAssign(string op : "~")(T item) {
        if (len == cap) {
            reserve(max(4, cap*2));
        }
        _data[len++] = item;
    }

    void clear() {
        len = 0;
    }

    T[] data() {
        return (_data) ? _data[0..len] : null;
    }
}

/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray;
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            if (f.eof) return false;
            line = lineBuf[];
            f.readln(line);
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {

                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else {
                auto buf = line.split.map!(to!E).array;
                static if (isStaticArray!T) {

                    assert(buf.length == T.length);
                }
                x = buf;
                line.length = 0;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;

static if (__VERSION__ <= 2070) {
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            import std.algorithm : reduce;
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                import std.typecons : tuple;
                return reduce!fun(tuple(seed), r);
            }
        }
    }

}
version (X86) static if (__VERSION__ < 2071) {
    int bsf(ulong v) {
        foreach (i; 0..64) {
            if (v & (1UL << i)) return i;
        }
        return -1;
    }
    int bsr(ulong v) {
        foreach_reverse (i; 0..64) {
            if (v & (1UL << i)) return i;
        }
        return -1;
    }
    int popcnt(ulong v) {
        int c = 0;
        foreach (i; 0..64) {
            if (v & (1UL << i)) c++;
        }
        return c;
    }
}

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, k;
    readf("%s %s", &n, &k);
    readln;

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

    auto nxtpos = new int[] (n+1);
    auto lst = new int[] (n+1);
    lst[] = n+1;

    foreach_reverse (i, e; arr) {
        nxtpos[i] = lst[e];
        lst[e] = i.to!int;
    }

    int ans = 0;
    auto rbt = make!(RedBlackTree!(Tuple!(int, int)));
    auto nxtel = new int[] (n+1);
    foreach (i, e; arr) {
        auto cur = tuple(nxtel[e], e);

        if (cur in rbt) {
            rbt.removeKey(cur);
            nxtel[e] = nxtpos[i];
            rbt.insert(tuple(nxtel[e], e));
            continue;
        }

        if (rbt.length() < k) {
            nxtel[e] = nxtpos[i];
            ans += 1;
            rbt.insert(tuple(nxtel[e], e));
            continue;
        }

        rbt.removeBack();
        nxtel[e] = nxtpos[i];
        ans += 1;
        rbt.insert(tuple(nxtel[e], e));
    }

    ans.writeln;
}

/+ dub.sdl:
    name "B"
    dependency "dcomp" version=">=0.6.0"
+/

import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner, dcomp.array;
import std.typecons;
import std.container.rbtree;

int main() {
    auto sc = new Scanner(stdin);
    int n, k;
    int[] a;
    sc.read(n, k, a); a[] -= 1;

    int[][] l = new int[][n];
    foreach (int i, d; a) {
        l[d] ~= i;
    }
    l.each!((ref v) => v ~= n);
    auto used = new bool[n];
    int sm = 0;

    auto tr = redBlackTree!(int[2]);
    foreach (d; a) {
        int ba = l[d][0];
        l[d] = l[d][1..$];
        int nx = l[d][0];
        if (used[d]) {
            tr.removeKey([d, ba].fixed);
            tr.insert([d, nx].fixed);
            continue;
        }
        // add d
        if (tr.length == k) {
            auto u = tr.back();
            tr.removeBack();
            used[u[1]] = false;
        }
        sm++;
        tr.insert([nx, d].fixed);
        used[d] = true;
    }
    writeln(sm);
    return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/array.d */
// module dcomp.array;

T[N] fixed(T, size_t N)(T[N] a) {return a;}

struct FastAppender(A) {
    import std.algorithm : max;
    import std.range.primitives : ElementEncodingType;
    import core.stdc.string : memcpy;

    private alias T = ElementEncodingType!A;
    private T* _data;
    private size_t len, cap;

    @property size_t length() {return len;}

    void reserve(size_t nlen) {
        import core.memory : GC;
        if (nlen <= cap) return;

        void* nx = GC.malloc(nlen * T.sizeof);

        cap = nlen;
        if (len) memcpy(nx, _data, len * T.sizeof);
        _data = cast(T*)(nx);
    }

    void opOpAssign(string op : "~")(T item) {
        if (len == cap) {
            reserve(max(4, cap*2));
        }
        _data[len++] = item;
    }

    void clear() {
        len = 0;
    }

    T[] data() {
        return (_data) ? _data[0..len] : null;
    }
}

/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray;
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            if (f.eof) return false;
            line = lineBuf[];
            f.readln(line);
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {

                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else {
                auto buf = line.split.map!(to!E).array;
                static if (isStaticArray!T) {

                    assert(buf.length == T.length);
                }
                x = buf;
                line.length = 0;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;

static if (__VERSION__ <= 2070) {
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            import std.algorithm : reduce;
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                import std.typecons : tuple;
                return reduce!fun(tuple(seed), r);
            }
        }
    }

}
version (X86) static if (__VERSION__ < 2071) {
    int bsf(ulong v) {
        foreach (i; 0..64) {
            if (v & (1UL << i)) return i;
        }
        return -1;
    }
    int bsr(ulong v) {
        foreach_reverse (i; 0..64) {
            if (v & (1UL << i)) return i;
        }
        return -1;
    }
    int popcnt(ulong v) {
        int c = 0;
        foreach (i; 0..64) {
            if (v & (1UL << i)) c++;
        }
        return c;
    }
}

/+ dub.sdl:
    name "B"
    dependency "dcomp" version=">=0.6.0"
+/

import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner, dcomp.array;
import std.typecons;
import std.container.rbtree;

int main() {
    auto sc = new Scanner(stdin);
    int n, k;
    int[] a;
    sc.read(n, k, a); a[] -= 1;

    int[][] l = new int[][n];
    foreach (int i, d; a) {
        l[d] ~= i;
    }
    l.each!((ref v) => v ~= n);
    auto used = new bool[n];
    int sm = 0;

    auto tr = redBlackTree!(int[2]);
    foreach (d; a) {
        l[d] = l[d][1..$];
        int nx = l[d][0];
        if (used[d]) continue;
        // add d
        if (tr.length == k) {
            auto u = tr.back();
            tr.removeBack();
            used[u[1]] = false;
        }
        sm++;
        tr.insert([nx, d].fixed);
        used[d] = true;
    }
    writeln(sm);
    return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/array.d */
// module dcomp.array;

T[N] fixed(T, size_t N)(T[N] a) {return a;}

struct FastAppender(A) {
    import std.algorithm : max;
    import std.range.primitives : ElementEncodingType;
    import core.stdc.string : memcpy;

    private alias T = ElementEncodingType!A;
    private T* _data;
    private size_t len, cap;

    @property size_t length() {return len;}

    void reserve(size_t nlen) {
        import core.memory : GC;
        if (nlen <= cap) return;

        void* nx = GC.malloc(nlen * T.sizeof);

        cap = nlen;
        if (len) memcpy(nx, _data, len * T.sizeof);
        _data = cast(T*)(nx);
    }

    void opOpAssign(string op : "~")(T item) {
        if (len == cap) {
            reserve(max(4, cap*2));
        }
        _data[len++] = item;
    }

    void clear() {
        len = 0;
    }

    T[] data() {
        return (_data) ? _data[0..len] : null;
    }
}

/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray;
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            if (f.eof) return false;
            line = lineBuf[];
            f.readln(line);
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {

                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else {
                auto buf = line.split.map!(to!E).array;
                static if (isStaticArray!T) {

                    assert(buf.length == T.length);
                }
                x = buf;
                line.length = 0;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;

static if (__VERSION__ <= 2070) {
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            import std.algorithm : reduce;
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                import std.typecons : tuple;
                return reduce!fun(tuple(seed), r);
            }
        }
    }

}
version (X86) static if (__VERSION__ < 2071) {
    int bsf(ulong v) {
        foreach (i; 0..64) {
            if (v & (1UL << i)) return i;
        }
        return -1;
    }
    int bsr(ulong v) {
        foreach_reverse (i; 0..64) {
            if (v & (1UL << i)) return i;
        }
        return -1;
    }
    int popcnt(ulong v) {
        int c = 0;
        foreach (i; 0..64) {
            if (v & (1UL << i)) c++;
        }
        return c;
    }
}


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.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

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

    auto isFree = new bool[] (2^^n + 1);
    isFree[] = true;
    isFree[0] = false;
    if (x < 2^^n) { isFree[x] = false; }

    int nextFreeVal(int idx) {
        while (!isFree[idx]) { ++idx; }
        return idx;
    }

    int sm = 0;
    int[] ans;
    int nxtsm = 1;
    while ((nxtsm = nextFreeVal(nxtsm)) < 2^^n && (sm ^ nxtsm) < 2^^n) {
        isFree[nxtsm] = false;
        if ((x ^ nxtsm) < 2^^n) { isFree[nxtsm ^ x] = false; }
        ans ~= sm ^ nxtsm;
        sm = nxtsm;
    }

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

module D;

import std.typecons;
import core.stdc.stdio;
import std.stdio;
import std.algorithm;
import std.range;
import std.container.rbtree;

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

void main()
{
    int n, x;
    scanf("%d%d", &n, &x);

    bool[int] mm;

    int[] ans;
    mm[0] = true;
    mm[x] = true;

    int prefix = 0;

    foreach (i; 1 .. (1 << n))
    {
        if (i !in mm)
        {
            ans ~= (i ^ prefix);

            prefix = i;
            mm[prefix] = true;
            mm[prefix ^ x] = true;

        }
    }

    writeln(ans.length);
    if (ans.length > 0)
        writefln("%(%d%| %)", ans);
}

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

immutable long MOD = 10^^9 + 7;
immutable long INF = 1L << 59;

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

    if (N == 1 && X == 1) {
        writeln(0);
        return;
    }
    if (N == 1) {
        writeln(1);
        writeln(1);
        return;
    }

    auto Y = N.iota.filter!(i => bsr(X) != i).map!(i => 1 << i).array;
    int[] ans;

    void dfs(int idx) {
        if (idx == 0) {
            ans ~= Y[idx];
            return;
        }
        dfs(idx-1);
        ans ~= Y[idx];
        dfs(idx-1);
    }

    dfs(Y.length.to!int-1);
    ans.length.writeln;
    ans.map!(to!string).join(" ").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.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

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

    auto isFree = new bool[] (2^^n + 1);
    isFree[] = true;
    isFree[0] = false;
    if (x < 2^^n) { isFree[x] = false; }

    int nextFreeVal(int idx) {
        while (!isFree[idx]) { ++idx; }
        return idx;
    }

    int sm = 0;
    int[] ans;
    int nxtsm = 1;
    while ((nxtsm = nextFreeVal(nxtsm)) < 2^^n && (sm ^ nxtsm) < 2^^n) {
        ans ~= sm ^ nxtsm;
        sm = nxtsm;
        isFree[sm] = false;
        if ((sm ^ x) < 2^^n) { isFree[sm ^ x] = false; }
    }

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

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

void main() {
  int n, x;
  readf!" %d %d" (n, x);
  immutable m = 1 << n;
  int[] s;
  auto t = redBlackTree!int ();
  foreach (i; 1 .. m) {
    if (i != x) {
      t.insert (i);
    }
  }
  while (!t.empty) {
    int i = t.front;
    s ~= i;
    t.removeFront();
    t.removeKey (i ^ x);
  }
  if (!s.length) {
    writeln (0);
    return;
  }
  auto a = new int[s.length];
  a[0] = s[0];
  foreach (i; 1 .. s.length) {
    a[i] = s[i] ^ s[i-1];
  }
  debug stderr.writeln (s);
  writeln (a.length);
  writefln ("%(%s %)", a);
}


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 x = RD;
		auto w = RDA;

		long tot;
		while (!w.empty)
		{
			long y;
			if (tot+w.front != x)
			{
				y = w.front; w.popFront;
			}
			else
			{
				y = w.back; w.popBack;
			}
			tot += y;
			ans[ti] ~= y;
		}
		if (tot == x)
			ans[ti].length = 0;
	}

	foreach (e; ans)
	{
		if (e.empty)
			writeln("NO");
		else
		{
			writeln("YES");
			e.map!(to!string).join(" ").writeln;
		}
	}
	stdout.flush;
	debug readln;
}

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

void main()
{
	int t = readInt!int;
	while (t--) solve;
}

void solve()
{
	int n = readInt!int;
	int x = readInt!int;
	auto a = new int[](n); foreach(ref ai; a) ai = readInt!int;
	int acc = 0;
	foreach(i, ref ai; a)
	{
		acc += ai;
		if (acc == x)
		{
			if (i + 1 < n)
			{
				swap(a[i+1], a[i]);
			}
			else
			{
				return "NO".writeln;
			}
		}
	}
	"YES".writeln;
	foreach(ai; a) ai.write(" "); writeln; return;
}

/* INPUT ROUTINES */
int currChar;
static this()
{
	currChar = getchar();
}

char topChar()
{
	return cast(char) currChar;
}

void popChar()
{
	currChar = getchar();
}

auto readInt(T)()
{
	T num = 0;
	int sgn = 0;
	while (topChar.isWhite)
		popChar;
	while (topChar == '-' || topChar == '+')
	{
		sgn ^= (topChar == '-');
		popChar;
	}
	while (topChar.isDigit)
	{
		num *= 10;
		num += (topChar - '0');
		popChar;
	}
	if (sgn)
		return -num;
	return num;
}

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
/**MODULAR SYSTEM*/
struct Z(immutable long m)
{
	long rep;
	this(long num)
	{
		rep = num;
	}

	Z!m opBinary(string operator)(Z!m rhs)
	{
		static if (operator == "+")
		{
			long result = rhs.rep + this.rep;
			if (result >= m)
				result -= m;
			return Z!m(result);
		}
		else static if (operator == "-")
		{
			long result = this.rep - rhs.rep;
			if (result < 0)
				result += m;
			return Z!m(result);
		}
		else static if (operator == "*")
		{
			long result = this.rep * rhs.rep;
			if (result >= m)
				result %= m;
			return Z!m(result);
		}
		else
			static assert(text("Operator ", operator, " not supported"));
	}

	Z!m opBinary(string operator)(long exponent) if (operator == "^^")
	{
		assert(exponent >= 0);
		Z!m base = this;
		Z!m result = 1;
		while (exponent)
		{
			if (exponent & 1)
				result = result * base;
			base = base * base;
			exponent >>= 1;
		}
		return result;
	}

	invariant
	{
		assert(rep >= 0 && rep < m);
	}
}

import std.stdio, std.string, std.algorithm, std.conv, std.range;
void main()
{
    int q;
    readf!"%d\n"(q);
    foreach (_; 0 .. q)
    {
        int n, x;
        readf!"%d %d\n"(n, x);
        int[] w = readln.split.map!(to!int).array;
        if (w.sum == x)
            writeln("NO");
        else
        {
            writeln("YES");
            foreach (i; 0 .. n)
            {
                if (x == w[i])
                    swap(w[i], w[i + 1]);
                writef!"%d "(w[i]);
                x -= w[i];
            }
            writeln();
        }
    }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, x;
		readf !(" %s %s") (n, x);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		if (x == 0 || x == sum (a) || (a.minElement == a.maxElement &&
		    0 < x && x < sum (a) && x % a[0] == 0))
		{
			writeln ("NO");
			continue;
		}
		while (true)
		{
			randomShuffle (a);
			bool ok = true;
			int cur = 0;
			foreach (ref c; a)
			{
				cur += c;
				ok &= (cur != x);
			}
			if (ok)
			{
				writeln ("YES");
				writefln !("%(%s %)") (a);
				break;
			}
		}
	}
}


void main() { runSolver(); }

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

  auto solve() {
    foreach(_; 0..QN) {
      auto N = scan!int;
      auto L = scan!int;
      auto A = scan!long(N);

      long[] bits;
      foreach(i; 0..L) {
        long count;
        foreach(ref a; A) {
          if (a % 2 == 1) count++;
          a /= 2;
        }

        bits ~= count > N / 2 ? 1 : 0;
      }

      long ans;
      foreach_reverse(b; bits) {
        ans *= 2;
        ans += b;
      }

      ans.writeln;
    }
  }

  outputForAtCoder(&solve);
}

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

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

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

import std;

T
read (alias T, string end = "") () {
    T x;
    readf!("%s" ~ end)(x);
    return x;
}

void main () {
    immutable tests = read!(uint, "\n");
    TEST_LOOP: foreach (test_index; 0 .. tests) {
        immutable n = read!(uint, " ");
        immutable l = read!(uint, "\n");

        immutable vec =
            readln.chomp.split(' ')
            .to!(uint[]);

        iota(0, l)
            .map!(bit =>
                        vec.count!(x => cast(bool)(x & (1 << bit)))
                        > n / 2)
            .array
            .to!BitArray
            .opCast!(size_t[])
            .front
            .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)); }
double euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
double norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }
double dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }

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

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

		auto cnt = new long[](l);
		foreach (i; 0..n)
		{
			foreach (j; 0..l)
			{
				auto bit = 1L << j;
				if (x[i] & bit)
					++cnt[j];
			}
		}

		foreach (i; 0..l)
		{
			auto bit = 1L << i;
			if (cnt[i] >= (n+1)/2)
				ans[ti] |= bit;
		}
	}

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


import std.stdio;
import std.string;
import core.stdc.stdio;
import std.container;
import std.algorithm.sorting;
import std.algorithm.comparison;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int[4] s;
	int capacity = 4;
	foreach (i; 0 .. n)
	{
		int num;
		scanf("%d", &num);
		s[num - 1]++;
	}

	int result = 0;
	for (int i = 3; i >= 0; i--)
	{
		switch (i)
		{
			case (3): result += s[i]; break;
			case (2):{
				result += s[i];
				s[0] -= min(s[i], s[0]);
				break;
			}
			case (1):{
				result += (s[i] / 2);
				s[i] -= (s[i] / 2) * 2;
				result += s[i];
				s[0] -= min(2*s[i], s[0]);
				break;
			}
			case (0):{
				result += (s[i] / 4);
				s[i] -= (s[i] / 4) * 4;
				result += s[i] > 0 ? 1 : 0;
				break;
			}
			default:continue;
		}
	}
	printf("%d", result);
	return 0;
}

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

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

void main(){
  auto n = readln.chomp.to!int;
  auto groups = readln.chomp.split(" ").map!(to!int);
  int[int] hash = [1: 0, 2: 0, 3: 0, 4: 0];
  foreach(g; groups){ hash[g] += 1; }
  int taxiNum;

  taxiNum += hash[4];
  taxiNum += hash[3];

  hash[1] = max(0, hash[1] - hash[3]);
  taxiNum += hash[2] / 2;

  hash[2] = hash[2] % 2;
  if(hash[2]){ taxiNum += 1; hash[1] = max(0, hash[1] - 2); }

  taxiNum += hash[1] / 4;
  if(hash[1] % 4){ taxiNum += 1; }

  taxiNum.writeln;
}

import std.stdio;
import std.algorithm;
import std.range;
import std.conv : to;
import std.string : strip;

auto min(T)(T a, T b)
{
    return a <= b ? a : b;
}

void main()
{
    readln;
    uint[5] nums;
    foreach(group; readln.strip.splitter(' ').array.sort.group)
        nums[to!uint(group[0])] = group[1];

    uint taxiNum = nums[4];

    auto oneAndTree = min(nums[3], nums[1]);

    taxiNum += oneAndTree;
    nums[1] -= oneAndTree;
    nums[3] -= oneAndTree;
    taxiNum += nums[3];

    auto ones = nums[1]/4;
    taxiNum += ones;
    nums[1] -= ones*4;

    auto twos = nums[2]/2;
    taxiNum += twos;
    nums[2] -= twos*2;

    if ((nums[1] + nums[2]) > 0)
        taxiNum += (nums[1] + nums[2]*2) > 4 ? 2 : 1;

    writeln(taxiNum);
}

import std.stdio;
import std.array;
import std.algorithm;
import std.conv;

int main() {
    auto s = stdin.byLine;
    s.popFront();
    auto arr = s.front.split(" ");
    int[4] grps;
    foreach (g; arr) {
        grps[to!int(g) - 1]++;
    }
    int num = grps[3];
    if (grps[0] > grps[2]) grps[0] -= grps[2];
    else grps[0] = 0;
    if (grps[1] % 2) {
        if (grps[0] <= 2) grps[0] = 0;
        else grps[0] -= 2;
        grps[1] /= 2;
        grps[1]++;
    } else {
        grps[1] /= 2;
    }
    if (grps[0] % 4) grps[0] = grps[0] / 4 + 1;
    else grps[0] /= 4;
    num += grps[2] + grps[1] + grps[0];
    writeln(num);
    return 0;
}

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

void main() {
	readln();
	int[] a = readln().chomp.split(" ").map!(to!int).array;
	int[] count = new int[5];
	foreach (i; a) {
		count[i]++;
	}
	a.sort();
	int taxis = 0;
	foreach (i; a.retro) {
		if (count[i] > 0) {
			int cap = 4 - i;
			count[i]--;
			for (int j = i; j >= 1; j--) {
				if (count[j] > 0 && cap >= j) {
					cap -= j;
					count[j]--;
					j++;
				}
			}
			taxis++;
		}
	}
	writeln(taxis);

}

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

void main() {
    readln;
    auto s = readln.chomp.split.map!(to!int);

    int[5] a;
    foreach (e; s) a[e]++;
    a[1] = max(a[1] - a[3], 0);

    writeln(a[4] + a[3] + (a[1] + 2 * a[2] + 3) / 4);
}

import std.c.stdio;
import std.algorithm;
import std.math;

int main()
{
	int n;
	scanf("%d", &n);
	int[] groups = new int[4];
	int temp;
	foreach(i; 0..n)
	{
		scanf("%d", &temp);
		groups[temp-1]++;
	}
	int ansv;
	//4
	ansv += groups[3];
	// 1 and 3
	int temp13 = min(groups[0], groups[2]);
	ansv += temp13;
	groups[0] -= temp13;
	groups[2] -= temp13;
	//2
	ansv += groups[1]/2;
	groups[1] %= 2;
	//1 and 2
	if(groups[1] != 0) {
		ansv++;
		groups[1] = 0;
		if(groups[0] > 2)
			groups[0] -= 2;
		else
			groups[0] = 0;
	}
	if(groups[0] % 4 == 0)
		ansv += groups[0]/4;
	else
		ansv += groups[0]/4 + 1;
	//3
	ansv += groups[2];
	printf("%d", ansv);
	return 0;
}

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

void main(string[] args)
{
  inputFile = stdin;
  auto n = next!int;
  auto s = next!int(n);
  int[5] cnt;
  foreach(si; s) cnt[si]++;
  int res = 0;
  res += cnt[4];
  res += cnt[3];
  cnt[1] -= min(cnt[3], cnt[1]);
  auto p21 = min(cnt[2], cnt[1] / 2);
  res += p21;
  cnt[2] -= p21;
  cnt[1] -= 2 * p21;
  auto p21b = min(cnt[2], cnt[1]);
  res += p21b;
  cnt[2] -= p21b;
  cnt[1] -= p21b;
  res += cnt[2] / 2 + cnt[2] % 2;
  res += cnt[1] / 4;
  if (cnt[1] % 4 != 0)
    res += 1;
  return res.writeln;
}
ulong bitCnt(long x)
{
  ulong cnt = 0;
  while(x) {cnt += x & 1; x>>=1;}
  return cnt;
}
alias Arr(T) = Mat!(T, 1);
struct Mat(T, size_t dimension)
{
  T[] _baseArray;
  T[] _slice;
  size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}
  size_t[dimension] _indexer;
  this(T[] baseArray, size_t[dimension] sizes)
  {
    _baseArray = baseArray;
    _sizes = sizes;
    _indexer[dimension - 1] = 1;
    static foreach_reverse(i; 0 .. dimension - 1)
      _indexer[i] = _indexer[i + 1] * _sizes[i + 1];
    auto requiredSize = _indexer[0] * _sizes[0];
    debug assert(_baseArray.length >= requiredSize);
    _slice = _baseArray[0 .. requiredSize];
  }
  this(size_t[dimension] sizes)
  {
    size_t reqSize = 1;
    static foreach(i; 0 .. dimension)
      reqSize *= sizes[i];
    this(new T[](reqSize), sizes);
  }
  ref auto opIndex()
  {
    pragma(inline, true);
    return _slice[];
  }
  ref auto opIndex(I...)(I i)
  {
    pragma(inline, true);
    debug assert(i.length <= dimension);
    size_t index = mixin(iota(0, i.length).map!(j => text("i[", j, "]*_indexer[", j, "]")).join("+"));
    static if (i.length == dimension)
      {
	return _slice[index];
      }
    else
      {
	enum sliceDimension = dimension - i.length;
	size_t[sliceDimension] remSizes = _sizes[i.length .. $];
	auto basePortion = _slice[index .. index + _indexer[i.length - 1]];
 	return Mat!(T, sliceDimension)(basePortion, remSizes);
      }
  }
  static if (dimension == 2)
    {
      auto identity()
      {
	debug assert(dim(0) == dim(1));
	auto n = dim(0);
	auto id = Mat!(T, 2)([n, n]);
	foreach(k; 0 .. n)
	  id[k, k] = T(1);
	return id;
      }
      bool canMultiply(Mat!(T, 2) b)
      {
	return this.dim(1) == b.dim(0);
      }
      auto opBinary(string op)(Mat!(T, 2) b)
	if (op == "*")
	  {
	    debug assert(canMultiply(b));
	    auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);
	    foreach(i; 0 .. res.dim(0))
	      foreach(k; 0 .. this.dim(1))
		foreach(j; 0 .. res.dim(1))
		  res[i, j] = res[i, j] + this[i, k] * b[k, j];
	    return res;
	  }
      auto opBinary(string op)(ulong exp)
	if (op == "^^")
	  {
	    return this.pow(identity, exp);
	  }
      mixin interiorBinPow;
    }
}

struct Mod(T, ulong mod)
{
  alias This = Mod!(T, mod);
  T _rep; T rep() {return _rep;}
  this(W)(W w)
  {
    _rep = ((cast(T) w)%mod + mod) % mod;
  }
  static auto plainConstruct(T t)
  {
    pragma(inline, true);
    debug assert(t >= 0 && t < mod);
    auto res = Mod!(T, mod).init;
    res._rep = t;
    return res;
  }
  string toString()
  {
    return to!string(rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plainConstruct(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plainConstruct(resrep);
      }
    else static if (op == "*")
      {
	return This(_rep * b._rep);
      }
  }
}

mixin template interiorBinPow()
{
  alias ThisType = typeof(this);
  auto pow(ThisType res, ulong exp)
    {
      if (exp < 0) debug assert(0);
      auto pow = this;
      while(exp)
	{
	  if (exp & 1)
	    res = res * pow;
	  pow = pow * pow;
	  exp >>= 1;
	}
      return res;
    }
}

// INPUT
File inputFile;
DList!string _words;
void _wordsFill()
{
  while (_words.empty) _words.insertBack(inputFile.readln.split);
}
string popWord()
{
  _wordsFill;
  auto word = _words.front;
  _words.removeFront;
  return word;
}
string peekWord()
{
  _wordsFill;
  return _words.front;
}
T next(T)()
{
  return to!T(popWord);
}
T peek(T)()
{
  return to!T(peekWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

void main() {
    import std.algorithm : min;
    import std.stdio : readf, writeln;

    int n;
    readf!"%d"(n);
    int[4] a;
    foreach (_; 0 .. n) {
        readf!" %d"(n);
        a[n - 1]++;
    }

    int res;
    res += a[3];
    a[0] -= min(a[0], a[2]);
    res += a[2];
    if (a[1] % 2 == 1) {
        a[0] -= min(a[0], 2);
        res++;
    }
    res += a[1] / 2;
    res += a[0] / 4;
    if (a[0] % 4 != 0) {
        res++;
    }
    writeln(res);
}

import std.stdio;
import std.string;
import core.stdc.stdio;
import std.container;
import std.algorithm.sorting;
import std.algorithm.comparison;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int[4] s;
	foreach (i; 0 .. n)
	{
		int num;
		scanf("%d", &num);
		s[num - 1]++;
	}

	int m = min(s[2], s[0]);
	s[3] += m;
	s[2] -= m;
	s[0] -= m;
	m = s[1] / 2;
	s[1] -= m * 2;
	s[3] += m;
	m = min(s[0], s[1]);
	s[0] -= m;
	s[1] -= m;
	s[3] += m;
	m = s[0] / 4;
	s[3] += m;
	s[0] -= m * 4;
	if (s[0] > 0) {
		s[3] += 1;
		s[0] = 0;
	}
	printf ("%d", s[0] + s[1] + s[2] + s[3]);
	return 0;
}

import std.stdio;
import std.string;
import core.stdc.stdio;
import std.container;
import std.algorithm.sorting;
import std.algorithm.comparison;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int[4] s;
	int capacity = 4;
	foreach (i; 0 .. n)
	{
		int num;
		scanf("%d", &num);
		s[num - 1]++;
	}

	int result = 0;
	for (int i = 3; i >= 0; i--)
	{
		switch (i)
		{
			case (3): result += s[i]; break;
			case (2):{
				result += s[i];
				s[0] -= min(s[i], s[0]);
				break;
			}
			case (1):{
				result += (s[i] / 2);
				s[i] -= (s[i] / 2) * 2;
				result += s[i];
				s[0] -= min(2*s[i], s[0]);
				break;
			}
			case (0):{
				result += (s[i] / 4);
				s[i] -= (s[i] / 4) * 4;
				result += s[i];
				break;
			}
			default:continue;
		}
	}
	printf("%d", result);
	return 0;
}

import std.stdio;
import std.string;
import core.stdc.stdio;
import std.container;
import std.algorithm.sorting;
import std.algorithm.comparison;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int[4] s;
	foreach (i; 0 .. n)
	{
		int num;
		scanf("%d", &num);
		s[num - 1]++;
	}

	int m = min(s[2], s[0]);
	s[3] += m;
	s[2] -= m;
	s[0] -= m;
	m = s[1] / 2;
	s[1] -= m * 2;
	s[3] += m;
	printf ("%d", s[0] + s[1] + s[2] + s[3]);
	return 0;
}

import std.stdio;
import std.string;
import core.stdc.stdio;
import std.container;
import std.algorithm.sorting;
import std.algorithm.comparison;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int[4] s;
	foreach (i; 0 .. n)
	{
		int num;
		scanf("%d", &num);
		s[num - 1]++;
	}

	int m = min(s[2], s[0]);
	s[3] += m;
	s[2] -= m;
	s[0] -= m;
	m = s[1] / 2;
	s[1] -= m * 2;
	s[3] += m;
	m = min(s[0], s[1]);
	s[0] -= m;
	s[1] -= m;
	s[3] += m;
	m = s[0] / 4;
	s[3] += m;
	s[0] -= m * 4;
	printf ("%d", s[0] + s[1] + s[2] + s[3]);
	return 0;
}

import std.stdio;
import std.string;
import core.stdc.stdio;
import std.container;
import std.algorithm.sorting;
import std.algorithm.comparison;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int[4] s;
	foreach (i; 0 .. n)
	{
		int num;
		scanf("%d", &num);
		s[num - 1]++;
	}

	int m = min(s[2], s[0]);
	s[3] += m;
	s[2] -= m;
	s[0] -= m;
	m = s[1] / 2;
	s[1] -= m * 2;
	s[3] += m;
	m = s[0] / 4;
	s[3] += m;
	s[0] -= m * 4;
	printf ("%d", s[0] + s[1] + s[2] + s[3]);
	return 0;
}

import std.stdio;
import std.array;
import std.algorithm;
import std.conv;

int main() {
    auto s = stdin.byLine;
    s.popFront();
    auto arr = s.front.split(" ");
    int[4] grps;
    foreach (g; arr) {
        grps[to!int(g) - 1]++;
    }
    int num = grps[3];
    if (grps[0] > grps[2]) grps[0] -= grps[2];
    else grps[0] = 0;
    if (grps[1] % 2) {
        if (grps[0] <= 2) grps[0] = 0;
        else grps[0] -= 2;
        grps[1] /= 2;
        grps[1]++;
    } else {
        grps[2] /= 2;
    }
    if (grps[0] % 4) grps[0] = grps[0] / 4 + 1;
    else grps[0] /= 4;
    num += grps[2] + grps[1] + grps[0];
    writeln(num);
    return 0;
}

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

void main() {
    readln;
    auto s = readln.chomp.split.map!(to!int).array.sort!("a > b").array;

    int count = 0;

    count += s.count(4);
    s = s.filter!("a != 4").array;

    count += s.count(3);
    for (int i = 0; i < s.count(3); i++) {
        if (s.back == 1) s.popBack;
    }

    count += (s.count(2) / 2.0).ceil;

    count += (s.count(1) / 4.0).ceil;

    count.writeln;
}

import std.c.stdio;
import std.algorithm;
import std.math;

int main()
{
	int n;
	scanf("%d", &n);
	int[] groups = new int[4];
	int temp;
	foreach(i; 0..n)
	{
		scanf("%d", &temp);
		groups[temp-1]++;
	}
	int ansv;
	//4
	ansv += groups[3];
	// 1 and 3
	int temp13 = min(groups[0], groups[2]);
	ansv += temp13;
	groups[0] -= temp13;
	groups[2] -= temp13;
	//2
	ansv += groups[1]/2;
	groups[1] %= 2;
	//1 and 2
	if(groups[1] != 0) {
		ansv++;
		groups[1] = 0;
		if(groups[0] > 2)
			groups[0] -= 2;
		else
			groups[0] = 0;
		if(groups[0] % 4 == 0)
			ansv += groups[0]/4;
		else
			ansv += groups[0]/4 + 1;
	}
	//3
	ansv += groups[2];
	printf("%d", ansv);
	return 0;
}

import std.c.stdio;

int main(string[] argv)
{
	int n;
	scanf("%d", &n);
	int[] arr = [0, 0, 0, 0];
	int temp;
	foreach(i; 0..n)
	{
		scanf("%d", &temp);
		arr[temp-1]++;
	}
	if(arr[0] > arr[2])
		arr[2]=0;
	else
		arr[0] = 0;
	if(arr[1] % 2 == 0)
		arr[1] /= 2;
	else
	{
		arr[1] /= 2;
		if(arr[0] == 0)
			arr[0]++;
	}
	printf("%d", arr[0] + arr[1] + arr[2] + arr[3]);
	return 0;
}

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

void main(string[] args)
{
  inputFile = stdin;
  auto n = next!int;
  auto s = next!int(n);
  int[5] cnt;
  foreach(si; s) cnt[si]++;
  int res = 0;
  res += cnt[4];
  res += cnt[3];
  cnt[1] -= min(cnt[3], cnt[1]);
  auto p21 = min(cnt[2], cnt[1] / 2);
  res += p21;
  cnt[2] -= p21;
  cnt[1] -= 2 * p21;
  auto p21b = min(cnt[2], cnt[1]);
  res += p21b;
  cnt[2] -= p21b;
  cnt[1] -= p21b;
  res += cnt[2] / 2 + cnt[2] % 2;
  res += cnt[1] / 4 + cnt[1] % 4;
  return res.writeln;
}
ulong bitCnt(long x)
{
  ulong cnt = 0;
  while(x) {cnt += x & 1; x>>=1;}
  return cnt;
}
alias Arr(T) = Mat!(T, 1);
struct Mat(T, size_t dimension)
{
  T[] _baseArray;
  T[] _slice;
  size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}
  size_t[dimension] _indexer;
  this(T[] baseArray, size_t[dimension] sizes)
  {
    _baseArray = baseArray;
    _sizes = sizes;
    _indexer[dimension - 1] = 1;
    static foreach_reverse(i; 0 .. dimension - 1)
      _indexer[i] = _indexer[i + 1] * _sizes[i + 1];
    auto requiredSize = _indexer[0] * _sizes[0];
    debug assert(_baseArray.length >= requiredSize);
    _slice = _baseArray[0 .. requiredSize];
  }
  this(size_t[dimension] sizes)
  {
    size_t reqSize = 1;
    static foreach(i; 0 .. dimension)
      reqSize *= sizes[i];
    this(new T[](reqSize), sizes);
  }
  ref auto opIndex()
  {
    pragma(inline, true);
    return _slice[];
  }
  ref auto opIndex(I...)(I i)
  {
    pragma(inline, true);
    debug assert(i.length <= dimension);
    size_t index = mixin(iota(0, i.length).map!(j => text("i[", j, "]*_indexer[", j, "]")).join("+"));
    static if (i.length == dimension)
      {
	return _slice[index];
      }
    else
      {
	enum sliceDimension = dimension - i.length;
	size_t[sliceDimension] remSizes = _sizes[i.length .. $];
	auto basePortion = _slice[index .. index + _indexer[i.length - 1]];
 	return Mat!(T, sliceDimension)(basePortion, remSizes);
      }
  }
  static if (dimension == 2)
    {
      auto identity()
      {
	debug assert(dim(0) == dim(1));
	auto n = dim(0);
	auto id = Mat!(T, 2)([n, n]);
	foreach(k; 0 .. n)
	  id[k, k] = T(1);
	return id;
      }
      bool canMultiply(Mat!(T, 2) b)
      {
	return this.dim(1) == b.dim(0);
      }
      auto opBinary(string op)(Mat!(T, 2) b)
	if (op == "*")
	  {
	    debug assert(canMultiply(b));
	    auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);
	    foreach(i; 0 .. res.dim(0))
	      foreach(k; 0 .. this.dim(1))
		foreach(j; 0 .. res.dim(1))
		  res[i, j] = res[i, j] + this[i, k] * b[k, j];
	    return res;
	  }
      auto opBinary(string op)(ulong exp)
	if (op == "^^")
	  {
	    return this.pow(identity, exp);
	  }
      mixin interiorBinPow;
    }
}

struct Mod(T, ulong mod)
{
  alias This = Mod!(T, mod);
  T _rep; T rep() {return _rep;}
  this(W)(W w)
  {
    _rep = ((cast(T) w)%mod + mod) % mod;
  }
  static auto plainConstruct(T t)
  {
    pragma(inline, true);
    debug assert(t >= 0 && t < mod);
    auto res = Mod!(T, mod).init;
    res._rep = t;
    return res;
  }
  string toString()
  {
    return to!string(rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plainConstruct(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plainConstruct(resrep);
      }
    else static if (op == "*")
      {
	return This(_rep * b._rep);
      }
  }
}

mixin template interiorBinPow()
{
  alias ThisType = typeof(this);
  auto pow(ThisType res, ulong exp)
    {
      if (exp < 0) debug assert(0);
      auto pow = this;
      while(exp)
	{
	  if (exp & 1)
	    res = res * pow;
	  pow = pow * pow;
	  exp >>= 1;
	}
      return res;
    }
}

// INPUT
File inputFile;
DList!string _words;
void _wordsFill()
{
  while (_words.empty) _words.insertBack(inputFile.readln.split);
}
string popWord()
{
  _wordsFill;
  auto word = _words.front;
  _words.removeFront;
  return word;
}
string peekWord()
{
  _wordsFill;
  return _words.front;
}
T next(T)()
{
  return to!T(popWord);
}
T peek(T)()
{
  return to!T(peekWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

void main() {
    import std.algorithm : sort, maxElement;
    import std.stdio : readf, writeln;
    import std.range : enumerate, dropExactly, retro;

    int n;
    readf!"%d"(n);
    int[] s;
    s.length = n;
    foreach (i; 0 .. n) {
        readf!" %d"(s[i]);
    }

    enum maxCapacity = 4;
    int res;
    bool[int] whatever;
    foreach (i; 0 .. n) {
        whatever[i] = false;
    }
    auto r = s.sort.retro;
    foreach (i, g1; r.enumerate) {
        auto available = maxCapacity - g1;
        if (whatever[i]) {
            continue;
        }
        res++;
        whatever[i] = true;

        if (available < r.maxElement) {
            continue;
        }

        foreach (j, g2; r.enumerate.dropExactly(i + 1)) {
            if (!whatever[j] && g2 <= available) {
                whatever[j] = true;
                available -= g2;
            }
            if (available < r.maxElement) {
                break;
            }
        }
    }
    writeln(res);
}

void main() {
    import std.algorithm : sort;
    import std.stdio : readf, writeln;
    import std.range : enumerate, dropExactly, retro;

    int n;
    readf!"%d"(n);
    int[] s;
    s.length = n;
    foreach (i; 0 .. n) {
        readf!" %d"(s[i]);
    }

    enum maxCapacity = 4;
    int res;
    bool[int] whatever;
    foreach (i; 0 .. n) {
        whatever[i] = false;
    }
    auto r = s.sort.retro.enumerate;
    foreach (i, g1; r) {
        auto available = maxCapacity - g1;
        if (whatever[i]) {
            continue;
        }
        if (!available) {
            res++;
            continue;
            whatever[i] = true;
        }
        res++;

        foreach (j, g2; r.dropExactly(i + 1)) {
            if (!whatever[j] && g2 <= available) {
                whatever[j] = true;
                available -= g2;
                break;
            }
        }
    }
    writeln(res);
}


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;
immutable int MX = 5000;

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

    auto arr = [0] ~ readln.chomp.split.map!(to!int).array;

    auto mxle = new int[] (n+1);
    foreach (i; 1 .. n+1) {
        foreach_reverse (j; 1 .. i+1) {
            if (arr[j] == arr[i]) { mxle[i] = j; }
        }
    }

    auto mxr = new int[] (n+1);
    foreach (i; 1 .. n+1) {
        foreach (j; i .. n+1) {
            if (arr[i] == arr[j]) { mxr[i] = j; }
        }
    }

    debug { mxle.writeln; mxr.writeln; }

    auto dp = new int[] (n+1);
    foreach (i; 1 .. n+1) {
        dp[i] = dp[i-1];

        int cxor = 0, borderle = i, borderr = i;
        foreach_reverse (j; 1 .. i+1) {
            borderr = max(borderr, mxr[j]);
            if (borderr > i) { break; }

            if (j == mxr[j]) { cxor ^= arr[j]; }

            borderle = min(borderle, mxle[j]);
            if (borderle < j) { continue; }

            debug { writeln(i, ' ', j, ' ', cxor); }

            dp[i] = max(dp[i], cxor + dp[j-1]);
        }
    }

    debug { dp.writeln; }

    dp[n].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;

void main() {
    immutable int MAX = 5010;

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

    auto L = new int[](MAX);
    auto R = new int[](MAX);
    fill(L, MAX);
    fill(R, -1);

    foreach (i; 0..N) {
        L[A[i]] = min(L[A[i]], i);
        R[A[i]] = max(R[A[i]], i);
    }

    auto mem = new int[](N);
    fill(mem, -1);

    int dp(int i) {
        if (i >= N) return 0;
        if (mem[i] >= 0) return mem[i];

        if (L[A[i]] != i)
            return dp(i + 1);
        int tar = R[A[i]];
        int pos = i + 1;
        int score = A[i];
        while (pos < N && pos <= tar) {
            if (L[A[pos]] < i) {
                score = 0;
                break;
            }
            else if (L[A[pos]] == pos) {
                score ^= A[pos];
            }
            tar = max(tar, R[A[pos]]);
            pos += 1;
        }

        return mem[i] = max(dp(i+1), score + dp(tar+1));
    }

    dp(0).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;
immutable int MX = 5000;

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

    auto arr = [0] ~ readln.chomp.split.map!(to!int).array;

    auto mxle = new int[] (n+1);
    foreach (i; 1 .. n+1) {
        foreach_reverse (j; 1 .. i+1) {
            if (arr[j] == arr[i]) { mxle[i] = j; }
        }
    }

    auto mxr = new int[] (n+1);
    foreach (i; 1 .. n+1) {
        foreach (j; i .. n+1) {
            if (arr[i] == arr[j]) { mxr[i] = j; }
        }
    }

    debug { mxle.writeln; mxr.writeln; }

    auto dp = new int[] (n+1);
    foreach (i; 1 .. n+1) {
        dp[i] = dp[i-1];

        int cxor = 0, mxxor = 0, borderle = i, borderr = i;
        foreach_reverse (j; 1 .. i+1) {
            borderr = max(borderr, mxr[j]);
            if (borderr > i) { break; }

            if (j == mxr[j]) { cxor ^= arr[j]; }

            borderle = min(borderle, mxle[j]);
            if (borderle < j) { continue; }

            debug { writeln(i, ' ', j, ' ', cxor); }

            dp[i] = max(dp[i], cxor + dp[j-1]);
        }
    }

    debug { dp.writeln; }

    dp[n].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;

void main() {
    immutable int MAX = 5010;

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

    auto L = new int[](MAX);
    auto R = new int[](MAX);
    fill(L, MAX);
    fill(R, -1);

    foreach (i; 0..N) {
        L[A[i]] = min(L[A[i]], i);
        R[A[i]] = max(R[A[i]], i);
    }

    auto mem = new int[](N);
    fill(mem, -1);

    int dp(int i) {
        if (i >= N) return 0;
        if (mem[i] >= 0) return mem[i];

        if (L[A[i]] != i)
            return dp(i + 1);
        int tar = R[A[i]];
        int pos = i + 1;
        int score = A[i];
        while (pos < N && pos <= tar) {
            if (L[A[pos]] < i) {
                score = 0;
                break;
            }
            else if (L[A[pos]] == pos) {
                score ^= A[pos];
            }
            tar = max(tar, R[A[pos]]);
            pos += 1;
        }

        writeln(i, " ", tar);
        return mem[i] = max(dp(i+1), score + dp(tar+1));
    }

    dp(0).writeln;
}


// Vicfred
// https://codeforces.com/contest/1405/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 = readln.chomp.to!int;
        long[] a = readln.split.map!(to!long).array;

        long ans = long.max;
        long sum = 0;
        foreach(x; a) {
            sum += x;
            ans = min(ans, sum);
        }

        writefln("%s", -ans);
    }
}

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

alias ll = long;
int inz(long t){ return to!int(t); }
static string[] tempstr;
T rd(T = long)() { while(!tempstr.length) tempstr = readln.chomp.split; string res = tempstr[0]; tempstr.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

void play(){
    int n;
    n = to!int(rd);
    ll[] arr;
    arr = rdarr;
    auto set = redBlackTree!(Tuple!(ll, ll));
    foreach(i; 0..n){
        auto t = tuple(arr[i], to!long(i));
        set.insert(t);
    }
    ll cost = 0;
    ll posmon = 0;
    foreach(i; 0..n){
        auto t = tuple(arr[i], to!long(i));
        set.removeKey(t);
        if(arr[i] < 0 && posmon > 0){
            ll take = min(posmon, - arr[i]);
            posmon -= take;
            arr[i] += take;
        }
        cost -= min(arr[i], 0);
        posmon += max(arr[i], 0);
    }
    writeln(cost);
}

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

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

string FMT_F = "%.10f";

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

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

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

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

		long cnt;
		foreach (i; 0..n)
		{
			cnt += a[i];
			if (cnt < 0)
			{
				ans[ti] += abs(cnt);
				cnt = 0;
			}
		}
	}

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


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()
{
    auto s = readln.chomp;

    auto ones = s.count!(x => x == '1');

    auto left = s.filter!(x => x != '1').array;

    debug { left.writeln; }

    auto parts = left.findSplitBefore("2");

    debug { parts.each!writeln; }

    auto ans = parts[0] ~ (cast(dchar)'1').repeat(ones).array ~ parts[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 S = readln.chomp;
    auto N = S.length.to!int;
    string A = "";
    string B = "";

    foreach (i; 0..N) {
        if (S[i] == '1') A ~= S[i];
        else B ~= S[i];
    }

    if (B.empty) {
        A.writeln;
        return;
    }

    int x = B.length.to!int;
    foreach (i; 0..B.length.to!int) {
        if (B[i] == '2') {
            x = i;
            break;
        }
    }

    writeln(B[0..x] ~ A ~ B[x..$]);
}

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

void main() {
    dchar[] s = readln.chomp.to!(dchar[]);
    int n = s.length.to!int;

    int cnt;
    foreach (i ; 0 .. n) {
        if (s[i] == '1') cnt++;
    }

    foreach (i ; 0 .. n) {
        if (s[i] == '0') {
            write('0');
        }
        else if (s[i] == '1') {
            continue;
        }
        else {
            while (cnt > 0) {
                write('1');
                cnt--;
            }
            write('2');
        }
    }

    while (cnt > 0) {
        write('1');
        cnt--;
    }

    writeln;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

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

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

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

void main() {
    dchar[] s = readln.chomp.to!(dchar[]);
    int n = s.length.to!int;

    int l, r;

    while (l < n) {
        while (r < n && s[r] != '0') {
            r++;
        }
        s[l..r].sort();
        r++;
        l = r;
    }

    debug {
        writeln(s);
    }

    l = r = 0;

    while (l < n) {
        while (r < n && s[r] != '2') {
            r++;
        }
        s[l..r].sort();
        r++;
        l = r;
    }

    writeln(s);
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

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

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


import std.stdio, std.string;

void solve(int[] a, int k, int x)
{
    auto n = cast(int)a.length;
    auto f = new long[n];
    auto b = new long[n];
    f[0] = 0;
    foreach (i; 1 .. n)
    {
        f[i] = f[i - 1] | a[i - 1];
    }
    b[n - 1] = 0;
    for (int i = n - 2; i >= 0; -- i)
    {
        b[i] = b[i + 1] | a[i + 1];
    }
    long ans = 0;
    foreach (i; 0 .. n)
    {
        long val = a[i];
        foreach (j; 0 .. k)
        {
            val *= x;
        }
        val |= f[i];
        val |= b[i];
        if (val > ans)
        {
            ans = val;
        }
    }
    writeln(ans);
}

int main(string[] args)
{
    int n, k, x;
    while (readf("%d %d %d\n", &n, &k, &x) == 3)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a, k, x);
    }
    return 0;
}

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, k, x;
    readf("%s %s %s", &n, &k, &x);
    readln;

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

    auto orr = new int[][] (n, 2);

    foreach (i, e; arr) {
        orr[i][0] = i == 0 ? e : orr[i-1][0] | e;
    }
    foreach_reverse (i, e; arr) {
        orr[i][1] = i == n-1 ? e : orr[i+1][1] | e;
    }

    long m = pow(x, k);
    long ans = 0;
    foreach (i, e; arr) {
        long val = m * e;
        int leor = i == 0 ? 0 : orr[i-1][0];
        int ror = i == n-1 ? 0 : orr[i+1][1];
        ans = max(ans, leor | val | ror);
    }

    ans.writeln;
}


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

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		long start = a[0];
		long [] d;
		foreach (i; 1..n)
		{
			d ~= a[i] - a[i - 1];
		}

		long up = 0;
		foreach (ref y; d)
		{
			up += max (y, 0L);
		}
		writeln ((start + up + 1) >> 1);

		int q;
		readf !(" %s") (q);
		foreach (p; 0..q)
		{
			int l, r, x;
			readf !(" %s %s %s") (l, r, x);
			l -= 1;
			r -= 1;
			if (l == 0)
			{
				start += x;
			}
			if (l > 0)
			{
				up -= max (d[l - 1], 0L);
				d[l - 1] += x;
				up += max (d[l - 1], 0L);
			}
			if (r < n - 1)
			{
				up -= max (d[r], 0L);
				d[r] -= x;
				up += max (d[r], 0L);
			}
			writeln ((start + up + 1) >> 1);
		}
	}
}

import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main () {
	auto n = readln.strip.to !(int), a = readln.split.map !(to !(int)).array, s = a[0] + 1L;
	long [] d;
	foreach (i; 1..n) d ~= a[i] - a[i - 1];
	foreach (ref y; d) s += max (y, 0);
	writeln (s >> 1);
	auto q = readln.strip.to !(int);
	foreach (p; 0..q) {
		int l, r, x;
		readf !(" %s %s %s") (l, r, x);
		if (l > 1) {
			l -= 2;
			s -= max (d[l], 0);
			d[l] += x;
			s += max (d[l], 0);
		}
		else s += x;
		if (r < n) {
			r -= 1;
			s -= max (d[r], 0);
			d[r] -= x;
			s += max (d[r], 0);
		}
		writeln (s >> 1);
	}
}

import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main () {
	auto n = readln.strip.to !(int), a = readln.split.map !(to !(int)).array, s = a[0] + 1L;
	long [] d;
	foreach (i; 1..n) d ~= a[i] - a[i - 1];
	foreach (ref y; d) s += max (y, 0);
	writeln (s >> 1);
	auto q = readln.strip.to !(int);
	foreach (p; 0..q) {
		int l, r, x;
		readf !(" %s %s %s") (l, r, x);
		if (l > 0) {
			l -= 2;
			s -= max (d[l], 0);
			d[l] += x;
			s += max (d[l], 0);
		}
		else s += x;
		if (r < n) {
			r -= 1;
			s -= max (d[r], 0);
			d[r] -= x;
			s += max (d[r], 0);
		}
		writeln (s >> 1);
	}
}


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

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

void main() {
        IO cin;
        int t = 1;
        // t = cin.readInt;
        while (t--) {
                int n = cin.readInt;
                int k = cin.readInt;
                string s = cin.readString;
                int count = 0;
                bool fail = false;
                for (int i = 0; i < n; i++) {
                        count = s[i] == '#' ? count + 1 : 0;
                        if (count >= k) fail = true;
                }
                writeln(fail ? "NO" : "YES");
        }
}

import std.stdio;
import std.exception;
import std.algorithm;
import std.math;
import std.typecons;

void main(){
	int n, m;
	string s;
	readf("%d %d\n%s\n", &n, &m, &s);
	int k=0;
	string ans="YES";
	foreach(i; 0..n){
		if (s[i]=='#') k++;
		else{
			if (k>=m) ans="NO";
			k=0;
		}
	}
	writefln("%s", ans);
}