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

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

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

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

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const A = readLong();
        const B = readLong();
        const N = readLong();

        long ans;
        long a = A, b = B;
        for (; a <= N && b <= N; ) {
          if (a > b) {
            swap(a, b);
          }
          a += b;
          ++ans;
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint;
import std.bitmanip, std.complex, std.container;
import std.math, std.mathspecial,std.numeric;
import std.regex, std.typecons;
import core.bitop;
class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }
bool chmin(T)(ref T t, in T f)
{ if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f)
{ if (t < f) { t = f; return true; } else { return false; } }
int binarySearch(alias pred, T)(in T[] as)
{int lo = -1, hi = cast(int)(as.length);
for(;lo + 1 < hi;){const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid;}
return hi;}
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }
void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const A = readLong();
        const B = readLong();
        const N = readLong();

        long ans;
        long a = A, b = B;
        for (; a <= N && b <= N; ) {
          if (a > b) {
            swap(a, b);
          }
          a += b;
          ++ans;
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}

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

void main ()
{
	foreach (t; 0..readln.strip.to !(int))
	{
		int a, b, n;
		readf !(" %s %s %s") (a, b, n);
		int res = 0;
		while (!(a > n || b > n))
		{
			if (a > b)
			{
				swap (a, b);
			}
			res += 1;
			a += b;
		}
		writeln (res);
	}
}

// Code By H~$~C

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

void _Main() {
  int a, b, n;
  readf!" %d %d %d"(a, b, n);
  if (a > b) swap(a, b);
  int cnt = 0;
  while (b <= n) {
    a += b;
    swap(a, b);
    cnt++;
  }
  writefln!"%s"(cnt);
}

void main(string[] args) {
  int tests = 1;
  readf!" %d"(tests);
  foreach (test; 0 .. tests) _Main();
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		while (max(a, b) <= n)
		{
			if (a < b)
				a += b;
			else
				b += a;
			++ans[ti];
		}
	}

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


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		int i = 0;
		int j = n - 1;
		int res = 0;
		while (true)
		{
			while (i < n && a[i] == 0)
			{
				i += 1;
			}
			while (j >= 0 && a[j] == 1)
			{
				j -= 1;
			}
			if (i >= j)
			{
				break;
			}
			res += 1;
			i += 1;
			j -= 1;
		}
		writeln (res);
	}
}

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

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

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

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

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

        auto ASum = new int[N + 1];
        foreach (i; 0 .. N) {
          ASum[i + 1] = ASum[i] + A[i];
        }

        int ans = N;
        foreach (k; 0 .. N + 1) {
          const l = ASum[k];
          const r = (N - k) - (ASum[N] - ASum[k]);
          const cost = max(l, r);
          chmin(ans, cost);
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}


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

void solve() {
    long N, K; readf("%d %d\n", &N, &K);
    auto A = readln.chomp.split(" ").map!(to!long).array;
    long C = A.reduce!"a+b" - K * N;
    long ans = C;
    long[] rs;
    for (int i = cast(int)(N-1); i >= 0; i--) {
        long[] nrs;
        long rd = 0;
        rs ~= A[i];
        foreach (ref r; rs) {
            rd += (r - r / 2);
            r /= 2;
            if (r > 0) {
                nrs ~= r;
            }
        }
        C = C - rd + K;
        ans = max(ans, C);
        rs = nrs;
    }
    writeln(ans);
}

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

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

immutable int limit = 32;

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;

		auto f = new long [n + 1];
		f[] = long.min / 2;
		f[0] = 0;
		long res = 0;
		foreach (d; 0..limit)
		{
			foreach (i; 0..n)
			{
				f[i + 1] = max (f[i + 1], f[i] + a[i] - k);
			}
			res = max (res, f[n]);
			a[] /= 2;
			foreach_reverse (i; 0..n)
			{
				f[i + 1] = max (f[i + 1], f[i] + a[i]);
			}
		}
		res = max (res, f.maxElement);
		writeln (res);
	}
}


import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
//import core.stdc.stdio;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;alias pair(X,Y)=Tuple!(X,"fi",Y,"se");
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;alias long lint;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;immutable int mod=1000000007;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
bool read(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~"\n", ptrs)==ptrs.length;}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter
//---------------------------------------------------------------program beginning-----------------------------------------------------------

void main()
{
	int n,k;
loop:while(read(&n,&k))
	{
		auto w=arread!int;
		sort(w);
		int ans=0;
		foreach(x;w)
		{
			ans+=(x+k-1)/k;
		}
		writeln((ans+1)/2);
	}
	//debug system("pause");
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
//import core.stdc.stdio;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;alias pair(X,Y)=Tuple!(X,"fi",Y,"se");
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;alias long lint;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;immutable int mod=1000000007;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter
//---------------------------------------------------------------program beginning-----------------------------------------------------------
T orient_square(T)(pair!(T,T)[] figure...)if(is(typeof(figure.front*figure.front)==T))
{
	auto n=figure.front,t=figure.front;
	figure.popFront();
	T ans=0;
	for(;!figure.empty;figure.popFront())
	{
		ans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);
		t=figure.front;
	}
	return ans+(n.fi-t.fi)*(n.se+t.se);
}

X binpow(X,Y)(X base,Y exp)if(is(typeof(exp>>1)))
{
	if(exp<0)return X(0);
	X res=X(1);
	while(exp>0)
	{
		if(exp&1)res*=base;
		base*=base;
		exp>>=1;
	}
	return res;
}
auto binpow(X,Y,Z)(X base,Y exp,in Z mm)if(is(typeof(exp>>1)) && is(typeof(base%mm)))
{
	if(mm==0) return binpow(base,exp);
	if(exp<0)return X(0);
	auto res=X(1)%mm;
	while(exp>0)
	{
		if(exp&1)res=(res*base)%mm;
		base*=base;
		base%=mm;
		exp>>=1;
	}
	return res;
}
real square(T)(pair!(T,T)[] figure...)if(is(typeof(figure.front*figure.front)==T))
{
	return abs(orient_square(figure))/2.000000000000000;
}
alias orient_square orsq;
class vertex(X,alias f="a+b",X n=0,size_t lg=0,size_t rg=size_t.max/2)
{
	protected
	{
		class node
		{
			X val;
			node l,r;
			this(){}
		};
		node root;
	}
	public
	{
		size_t lb=lg,rb=rg;
		X neutral=0;
		size_t length;
		alias fun=binaryFun!f;
		this()
		{
			root=new node();
			length=0;
		}

	}
	protected
	{
		bool insert(node t,size_t tl,size_t tr,size_t pos,X x)
		{
			bool mark=false;
			if(!t)
			{
				t=new node();
				mark=true;
			}
			if(tl==tr)
			{
				t.val=x;
			}
			else
			{
				size_t tm=(tl+tr)>>1;
				if(pos<=tm)
				{
					mark=insert(t.l,tl,tm,pos,x);
				}
				else
				{
					mark=insert(t.r,tm+1,tr,pos,x);
				}
				if(!t.l)t.val=t.r.val;
				else if(!t.r)t.val=t.l.val;
				else t.val=fun(t.l.val,t.r.val);
			}
			return mark;
		}
		bool erase(node t,size_t tl,size_t tr,size_t pos)
		{
			if(!t)return false;
			if(tl==tr)
			{
				t=null;
				return true;
			}
			else
			{
				size_t tm=(tl+tr)>>1;
				if(pos<=tm)
				{
					return erase(t.l,tl,tm,pos);
				}
				else
				{
					return erase(t.r,tm+1,tr,pos);
				}
				if(!t.l)t.val=t.r.val;
				else if(!t.r)t.val=t.l.val;
				else t.val=fun(t.l.val,t.r.val);
			}
		}
		X cel(node t,size_t tl,size_t tr,size_t l,size_t r)
		{
			if(!t)return neutral;
			if(tl==l && tr==r)return t.val;
			else
			{
				size_t tm=(tl+tr)>>1;
				if(r<=tm)return cel(t.l,tl,tm,l,r);
				else if(l>tm)return cel(t.r,tm+1,tr,l,r);
				else return fun(cel(t.l,tl,tm,l,tm),cel(t.r,tm+1,tr,tm+1,r));
			}
		}
	}
	public
	{
		void insert(size_t pos,X x)
			in
		{
			assert(pos>=lb && pos<=rb);
		}
		body
		{
			length+=insert(root,lb,rb,pos,x);
		}
		void erase(size_t pos)
			in
		{
			assert(pos>=lb && pos<=rb);
		}
		body
		{
			length-=erase(root,lb,rb,pos);
		}
		X cel(size_t l,size_t r)
			in
		{
			assert(l<=r && l>=lb && r<=rb);
		}
		body
		{
			return cel(root,lb,rb,l,r);
		}
	}
};
class item
{
	size_t cnt,prior;
	int key;
	item l,r;
	this(){}
	this(int val,int rnd)
	{
		key=val;
		cnt=1;
		prior=rnd;
	}
};
int cnt(item t)
{
	return t?t.cnt:0;
}
void upd_cnt(item t)
{
	t.cnt=cnt(t.l)+cnt(t.r)+1;
}
void merge(ref item t,item l,item r)
{
	if(!l || !r)
	{
		t=(l?l:r);
	}
	else
	{
		if(l.prior>r.prior)
		{
			merge(l.r,l.r,r);
			t=l;
		}
		else
		{
			merge(r.l,l,r.l);
			t=r;
		}
	}
	upd_cnt(t);
}
void split(item t,int key,ref item l,ref item r)
{
	if(!t)l=r=null;
	else if(key<t.key)
	{
		split(t.l,key,l,t.l);
		r=t;
	}
	else
	{
		split(t.r,key,t.r,r);
		l=t;
	}
	upd_cnt(t);
}
void insert(ref item t,item it)
{
	if(!t) t=it;
	else
	{
		if(it.prior>t.prior)
		{
			split(t,it.key,it.l,it.r);
			t=it;
		}
		else insert(it.key<t.key?t.l:t.r,it);
	}
	upd_cnt(t);
}
void erase(ref item t,int key)
{
	if(t.key==key)merge(t,t.l,t.r);
	else erase(key<t.key?t.l:t.r,key);
}
size_t order(item t,int key,size_t add=0)
{
	if(!t)return add+1;
	else if(key<=t.key)return order(t.l,key,add);
	else return order(t.r,key,cnt(t.l)+add+1);
}
class nitem
{
	size_t cnt,prior;
	int key;
	nitem l,r;
	this(){}
	this(int val,int rnd)
	{
		key=val;
		cnt=1;
		prior=rnd;
	}
};
int cnt(nitem t)
{
	return t?t.cnt:0;
}
void upd_cnt(nitem t)
{
	t.cnt=cnt(t.l)+cnt(t.r)+1;
}
void merge(ref nitem t,nitem l,nitem r)
{
	if(!l || !r)t=(l?l:r);
	else
	{
		if(l.prior>r.prior)
		{
			merge(l.r,l.r,r);
			t=l;
		}
		else
		{
			merge(r.l,l,r.l);
			t=r;
		}
	}
	upd_cnt(t);
}
void split(nitem t,int key,ref nitem l,ref nitem r,int add=0)
{
	if(!t){l=r=null;return;}
	int cur=add=cnt(t.l);
	if(key<=cur)
	{
		split(t.l,key,l,t.l,add);
		r=t;
	}
	else
	{
		split(t.r,key,t.r,r,add+1+cnt(t.l));
		l=t;
	}
	upd_cnt(t);
}
void insert(ref nitem t,nitem it)
{
	nitem l,r;
	split(t,it.key,l,r);
	merge(l,l,it);
	merge(t,l,r);
	upd_cnt(t);
}

void erase(ref nitem t,int key)
{
	if(t.key==key)merge(t,t.l,t.r);
	else erase(key<t.key?t.l:t.r,key);
}

void main()
{
	int n,k;
loop:while(read(n,k))
	{
		auto w=arread!int;
		sort(w);
		int ans=0;
		foreach(x;w)
		{
			ans+=(x+k-1)/k;
		}
		writeln((ans+1)/2);
	}
	//debug system("pause");
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
//import core.stdc.stdio;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;alias pair(X,Y)=Tuple!(X,"fi",Y,"se");
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;alias long lint;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;immutable int mod=1000000007;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter
//---------------------------------------------------------------program beginning-----------------------------------------------------------

void main()
{
	int n,k;
loop:while(read(n,k))
	{
		auto w=arread!int;
		sort(w);
		int ans=0;
		foreach(x;w)
		{
			ans+=(x+k-1)/k;
		}
		writeln((ans+1)/2);
	}
	//debug system("pause");
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
//import core.stdc.stdio;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;alias pair(X,Y)=Tuple!(X,"fi",Y,"se");
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;alias long lint;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;immutable int mod=1000000007;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
bool read(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~"\n", ptrs)==ptrs.length;}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter
//---------------------------------------------------------------program beginning-----------------------------------------------------------

void main()
{
	int n,k;
loop:while(read(&n,&k))
	{
		auto w=arread!int;
		sort(w);
		int ans=0;
		foreach(p;0..n-1)
		{
			ans+=w[p]/(2*k);
			w[p]%=2*k;
			if(w[p]==0)continue;
			ans++;
			if(w[p]<=k)w[p+1]-=k;
			w[p]=0;
		}
		if(w[n-1]>0)
		{
			ans+=w[n-1]/(2*k);
			w[n-1]%=2*k;
			if(w[n-1])ans++;
		}
		writeln(ans);
	}
	//debug system("pause");
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
//import core.stdc.stdio;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;alias pair(X,Y)=Tuple!(X,"fi",Y,"se");
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;alias long lint;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;immutable int mod=1000000007;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
bool read(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~"\n", ptrs)==ptrs.length;}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter
//---------------------------------------------------------------program beginning-----------------------------------------------------------

void main()
{
	int n,k;
loop:while(read(&n,&k))
	{
		auto w=arread!int;
		sort(w);
		int ans=0;
		foreach(x;w)
		{
			ans+=(x+k-1)/k;
		}
		writeln(ans);
	}
	//debug system("pause");
}


import std.stdio, std.string, std.conv, std.algorithm;
immutable int MN = 100010;
immutable int MK = 105;
immutable int MD = cast(int)(1e9+7.1);

int main() {
    long[MK][] b = new long[MK][](MN);
    long[MK][] c = new long[MK][](MN+MK);

    c[0][0] = 1;
    foreach (i; 1..MN+MK) {
        c[i][0] = 1;
        c[i][1..MK] = (c[i-1][0..MK-1] + c[i-1][1..MK]) % MD;
    }

    int n, m;
    readf("%d %d\n", &n, &m);
    string[] input = split(readln());
    long[] a = new long[](n);
    foreach (i; 0..n) {
        a[i] = to!int(input[i]);
    }
    foreach (i; 0..m) {
        int l, r, k;
        readf("%d %d %d\n", &l, &r, &k); l--;
        int f = 1;
        foreach_reverse (j; 0..k+1) {
            b[l][j] += c[l][k-j]*f; b[l][j] %= MD;
            b[r][j] -= c[l][k-j]*f; b[r][j] %= MD;
            f = -f;
        }
    }
    long[] b1 = new long[](MK);
    foreach (i; 0..n) {
        b1[] += b[i][];
        b1[] %= MD;
        for (int k = 0; k < MK; k++) {
            a[i] += b1[k]*c[i+k][k]%MD; a[i] %= MD;
        }
        a[i] = (a[i]+MD)%MD;
    }
    writeln(join(map!(to!string)(a[0..n]), " "));
    return 0;
}

import std.stdio, std.string, std.conv, std.algorithm;
immutable int MN = 100010;
immutable int MK = 105;
immutable int MD = cast(int)(1e9+7.1);

int main() {
    long[MK][] b = new long[MK][](MN);
    long[MK][] c = new long[MK][](MN+MK);

    c[0][0] = 1;
    foreach (i; 1..MN+MK) {
        c[i][0] = 1;
        c[i][1..MK] = (c[i-1][0..MK-1] + c[i-1][1..MK]) % MD;
    }

    int n, m;
    readf("%d %d\n", &n, &m);
    string[] input = split(readln());
    long[] a = new long[](n);
    for (int i = 0; i < n; i++) {
        a[i] = to!int(input[i]);
    }
    for (int i = 0; i < m; i++) {
        int l, r, k;
        readf("%d %d %d\n", &l, &r, &k); l--;
        int f = 1;
        foreach_reverse (j; 0..k+1) {
            b[l][j] += c[l][k-j]*f; b[l][j] %= MD;
            b[r][j] -= c[l][k-j]*f; b[r][j] %= MD;
            f = -f;
        }
    }
    long[] b1 = new long[](MK);
    foreach (i; 0..n) {
        b1[] += b[i][];
        b1[] %= MD;
        for (int k = 0; k < MK; k++) {
            a[i] += b1[k]*c[i+k][k]%MD; a[i] %= MD;
        }
        a[i] = (a[i]+MD)%MD;
    }
    writeln(join(map!(to!string)(a[0..n]), " "));
    return 0;
}

import std.stdio, std.string, std.conv, std.algorithm;
immutable int MN = 100010;
immutable int MK = 105;
immutable int MD = cast(int)(1e9+7.1);

int main() {
    long[MK][] b = new long[MK][](MN);
    long[MK][] c = new long[MK][](MN+MK);
    c[0][0] = 1;
    for (int i = 1; i < MN+MK; i++) {
        c[i][0] = 1;
        c[i][1..MK] = (c[i-1][0..MK-1] + c[i-1][1..MK]) % MD;
    }
    int n, m;
    readf("%d %d\n", &n, &m);
    string[] input = split(readln());
    long[] a = new long[](n);
    foreach (i, s; input) {
        a[i] = to!int(s);
    }
    for (int i = 0; i < m; i++) {
        int l, r, k;
        readf("%d %d %d\n", &l, &r, &k); l--;
        int f = 1;
        for (int j = 0; j <= k; j++) {
            b[l][k-j] += c[l][j]*f; b[l][k-j] %= MD;
            b[r][k-j] -= c[l][j]*f; b[r][k-j] %= MD;
            f = -f;
        }
    }
    long b1[MK];
    for (int i = 0; i < n; i++) {
        long r = a[i];
        b1[] += b[i][];
        b1[] %= MD;
        for (int k = 0; k < MK; k++) {
            r += b1[k]*c[i+k][k]%MD; r %= MD;
        }
        r = (r+MD)%MD;
        write(cast(int)r);
        if (i == n-1) {
            write("\n");
        } else {
            write(" ");
        }
    }
    return 0;
}

import std.stdio, std.string, std.conv, std.algorithm;
immutable int MN = 100010;
immutable int MK = 105;
immutable int MD = cast(int)(1e9+7.1);

int main() {
    long[][] b = new long[][](MN, MK);
    long[][] c = new long[][](MN+MK, MK);
    c[0][0] = 1;
    for (int i = 1; i < MN+MK; i++) {
        c[i][0] = 1;
        c[i][1..MK] = (c[i-1][0..MK-1] + c[i-1][1..MK]) % MD;
    }
    int n, m;
    readf("%d %d\n", &n, &m);
    string[] input = split(readln());
    auto a = map!(to!int)(input[]);
    for (int i = 0; i < m; i++) {
        int l, r, k;
        readf("%d %d %d\n", &l, &r, &k); l--;
        int f = 1;
        for (int j = 0; j <= k; j++) {
            b[l][k-j] += c[l][j]*f; b[l][k-j] %= MD;
            b[r][k-j] -= c[l][j]*f; b[r][k-j] %= MD;
            f = -f;
        }
    }
    long b1[MK];
    for (int i = 0; i < n; i++) {
        long r = a[i];
        b1[] += b[i][];
        b1[] %= MD;
        for (int k = 0; k < MK; k++) {
            r += b1[k]*c[i+k][k]%MD; r %= MD;
        }
        r = (r+MD)%MD;
        write(cast(int)r);
        if (i == n-1) {
            write("\n");
        } else {
            write(" ");
        }
    }
    return 0;
}

import std.stdio, std.string, std.conv, std.algorithm;
immutable int MN = 100010;
immutable int MK = 105;
immutable int MD = cast(int)(1e9+7.1);

int main() {
    long[MK][] b = new long[MK][MN];
    long[MK][] c = new long[MK][MN+MK];
    c[0][0] = 1;
    for (int i = 1; i < MN+MK; i++) {
        c[i][0] = 1;
        c[i][1..MK] = (c[i-1][0..MK-1] + c[i-1][1..MK]) % MD;
    }
    int n, m;
    readf("%d %d\n", &n, &m);
    string[] input = split(readln());
    auto a = map!(to!int)(input[]);
    for (int i = 0; i < m; i++) {
        int l, r, k;
        readf("%d %d %d\n", &l, &r, &k); l--;
        int f = 1;
        for (int j = 0; j <= k; j++) {
            b[l][k-j] += c[l][j]*f; b[l][k-j] %= MD;
            b[r][k-j] -= c[l][j]*f; b[r][k-j] %= MD;
            f = -f;
        }
    }
    long b1[MK];
    for (int i = 0; i < n; i++) {
        long r = a[i];
        b1[] += b[i][];
        b1[] %= MD;
        for (int k = 0; k < MK; k++) {
            r += b1[k]*c[i+k][k]%MD; r %= MD;
        }
        r = (r+MD)%MD;
        write(cast(int)r);
        if (i == n-1) {
            write("\n");
        } else {
            write(" ");
        }
    }
    return 0;
}

import std.stdio, std.string, std.conv, std.algorithm;
immutable int MN = 100010;
immutable int MK = 105;
immutable int MD = cast(int)(1e9+7.1);

int main() {
    long[MK][] b = new long[MK][](MN);
    long[MK][] c = new long[MK][](MN+MK);

    c[0][0] = 1;
    foreach (i; 1..MN+MK) {
        c[i][0] = 1;
        c[i][1..MK] = (c[i-1][0..MK-1] + c[i-1][1..MK]) % MD;
    }

    int n, m;
    readf("%d %d\n", &n, &m);
    string[] input = split(readln());
    long[] a = new long[](n);
    for (int i = 0; i < n; i++) {
        a[i] = to!int(input[i]);
    }
    for (int i = 0; i < m; i++) {
        int l, r, k;
        readf("%d %d %d\n", &l, &r, &k); l--;
        int f = 1;
        foreach_reverse (j; 0..k+1) {
            b[l][j] += c[l][k-j]*f; b[l][j] %= MD;
            b[r][j] -= c[l][k-j]*f; b[r][j] %= MD;
            f = -f;
        }
    }
    long[] b1 = new long[](MK);
    long[] r = new long[](n);
    foreach (i; 0..n) {
        b1[] += b[i][];
        b1[] %= MD;
        for (int k = 0; k < MK; k++) {
            r[i] += b1[k]*c[i+k][k]%MD; r[i] %= MD;
        }
        r[i] = (r[i]+MD)%MD;
    }
    writeln(join(map!(to!string)(r), " "));
    return 0;
}


import std.stdio;

void main() {
    int n, k;
    int[1005] count;

    readf(" %s %s", n, k);
    foreach(i; 0..n) {
        int a;
        readf(" %s", a);
        count[a]++;
    }

    int odds = 0;
    foreach(c; count) {
        if (c % 2 == 1) {
            odds++;
        }
    }

    int result = n - odds / 2;
    writeln(result);
}

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

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

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

void main()
{
	auto n = RD!int;
	auto k = RD!int;
	auto cnt = new long[](k);
	foreach (i; 0..n)
	{
		auto a = RD!int-1;
		++cnt[a];
	}
	long ans;
	long used;
	foreach (i; 0..k)
	{
		auto c = cnt[i] / 2;
		ans += c * 2;
		used += c;
		cnt[i] -= c * 2;
	}
	auto remain = n - used * 2 + n % 2;
	ans += remain / 2;

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

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

void solve(){
	int n = read.to!int;
	int k = read.to!int;

	int[] as;
	foreach(i; 0 .. n) as ~= read.to!int;

	int[int] ac;
	foreach(a; as){
		if(a !in ac) ac[a] = 0;
		ac[a] += 1;
	}

	int ans;
	int ocnt = n % 2;
	int[] ks = ac.keys;
	foreach(a; ks){
		int c = ac[a];
		if(c % 2 == 0) ans += c;
		else{
			if(ocnt >= 1) ans += c, ocnt = 0;
			else ans += c - 1, ocnt = 1;
		}
		log("a:", a, "cnt:", c, "ocnt:", ocnt, "ans:", ans);
	}

	ans.writeln;
}


import std;
void main(){
	auto t=readln.strip.to!int;
	foreach(_;0..t){
		auto n=readln.strip.to!int;
		auto a=readln.strip.split.to!(int[]);
		if(a.length==1){ writeln(0); continue; }
		int u=iota(n).maxElement!(i=>a[i]);
		int v=iota(n).minElement!(i=>a[i]);
		if(v<u) swap(u,v);
		int solve(R)(R x){
			if(x.length<=1) return 0;
			int mini=0,maxi=1,r=1;
			if(x[mini]>x[maxi]) swap(mini,maxi);
			for(int i=2;i<x.length;i++){
				if(x[i]<x[mini]){
					r+=mini<maxi;
					mini=i;
				}
				if(x[i]>x[maxi]){
					r+=maxi<mini;
					maxi=i;
				}
			}
			return r;
		}
		writeln(solve(a[0..u+1])+1+solve(a[v..$].retro));
	}
}

import std;
void main(){
	auto t=readln.strip.to!int;
	foreach(_;0..t){
		auto n=readln.strip.to!int;
		auto a=readln.strip.split.to!(int[]);
		if(a.length==1){ writeln(0); continue; }
		int u=iota(n).maxElement!(i=>a[i]);
		int v=iota(n).minElement!(i=>a[i]);
		if(v<u) swap(u,v);
		int solve(R)(R x){
			if(x.length<=1) return 0;
			int mini=0,maxi=1,r=1;
			if(x[mini]>x[maxi]) swap(mini,maxi);
			for(int i=2;i<x.length;i++){
				if(x[i]<x[mini]){
					if(maxi<mini){
						mini=i;
					}else{
						mini=i;
						r++;
					}
				}
				if(x[i]>x[maxi]){
					if(mini<maxi){
						maxi=i;
					}else{
						maxi=i;
						r++;
					}
				}
			}
			return r;
		}
		writeln(solve(a[0..u+1])+1+solve(a[v..$].retro));
	}
}

import std;

struct S(alias op,alias ε){
	alias T=typeof(ε);
	int n;
	T[] b;
	this(R)(R a){
		n=to!int(a.length);
		b=ε.repeat(4*n).array;
		T build(int l,int r,int i){
			if(l+1==r) return b[i]=a[l];
			int m=(l+r)/2;
			return b[i]=op(build(l,m,2*i),build(m,r,2*i+1));
		}
		build(0,n,1);
	}
	auto query(int ql,int qr){
		auto query_rec(int l,int r,int i){
			if(qr<=l||r<=ql) return ε;
			if(ql<=l&&r<=qr) return b[i];
			int m=(l+r)/2;
			return op(query_rec(l,m,2*i),query_rec(m,r,2*i+1));
		}
		return query_rec(0,n,1);
	}
	void opIndexAssign(T value,int k){
		T update_rec(int l,int r,int i){
			if(k<l||r<=k) return ε;
			if(l+1==r) return b[i]=value;
			int m=(l+r)/2;
			return b[i]=op(update_rec(l,m,2*i),update_rec(m,r,2*i+1));
		}
		update_rec(0,n,1);
	}
}

enum inf=to!int(3e5);

void main(){
	auto t=readln.strip.to!int;
	foreach(_;0..t){
		auto n=readln.strip.to!int;
		auto a=readln.strip.split.to!(int[]).map!(x=>x-1).array;
		auto maxtree=S!(max,tuple(0,-1))(a.zip(iota(n)));
		auto mintree=S!(min,tuple(inf,-1))(a.zip(iota(n)));
		auto ip=0.repeat(n).array;
		foreach(i,x;a) ip[x]=to!int(i);
		auto indextree=S!(min,n)(n.repeat(n));
		auto next_smaller=n.repeat(n).array;
		auto next_larger=n.repeat(n).array;
		foreach_reverse(i;0..n){
			next_smaller[i]=indextree.query(0,a[i]);
			next_larger[i]=indextree.query(a[i],n);
			indextree[a[i]]=i;
		}
		auto dist=chain(only(0),inf.repeat(n)).array;
		foreach(i;0..n-1){
			int[2] u=[
				maxtree.query(i+1,min(n,next_smaller[i]+1))[1],
				mintree.query(i+1,min(n,next_larger[i]+1))[1],
			];
			foreach(j;u) dist[j]=min(dist[j],dist[i]+1);
		}
		writeln(dist[n-1]);
	}
}

import std;
void main(){
	auto t=readln.strip.to!int;
	foreach(_;0..t){
		auto n=readln.strip.to!int;
		auto a=readln.strip.split.to!(int[]);
		int mini=0,maxi=0,r=0;
		for(int i=1;i<n;i++){
			r+=a[i]<a[mini]&&mini<=maxi;
			r+=a[i]>a[maxi]&&maxi<=mini;
			if(a[i]<a[mini]){
				if(mini<maxi) maxi=i;
				mini=i;
			}
			if(a[i]>a[maxi]){
				if(maxi<mini) mini=i;
				maxi=i;
			}
		}
		r+=(mini!=n-1&&maxi!=n-1);
		writeln(r);
	}
}

import std;
void main(){
	auto t=readln.strip.to!int;
	foreach(_;0..t){
		auto n=readln.strip.to!int;
		auto a=readln.strip.split.to!(int[]);
		int mini=0,maxi=0,r=0;
		for(int i=1;i<n;i++){
			r+=a[i]<a[mini]&&mini<=maxi;
			r+=a[i]>a[maxi]&&maxi<=mini;
			if(a[i]<a[mini]) mini=i;
			if(a[i]>a[maxi]) maxi=i;
		}
		r+=(mini!=n-1&&mini!=0)+(maxi!=n-1&&maxi!=0);
		writeln(r);
	}
}


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;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto uf = new UnionFind(N);
    foreach (_; 0..N-1) {
        s = readln.split.map!(to!int);
        if (s[2] == 0) {
            uf.unite(s[0]-1, s[1]-1);
        }
    }

    long ans = powmod(N, K, MOD);

    foreach (i; 0..N) {
        if (uf.find(i) != i) continue;
        long x = -uf.table[i];
        ans -= powmod(x, K, MOD);
        ans %= MOD;
    }

    ans = (ans + MOD) % MOD;
    ans.writeln;
}

class UnionFind {
    int N;
    int[] table;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (table[x] > table[y]) swap(x, y);
        table[x] += table[y];
        table[y] = x;
    }
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}

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

class DisjointSet {
  private:
    int [] p, h, s;
    int n;
  public:
  this (int _n) {
    n = _n;
    p = iota (0, n).array;
    h = new int[n];
    s = uninitializedArray!(int[])(n);
    s[] = 1;
  }
  int findSet (int x) pure nothrow @nogc {
    if (p[x] == x) {
      return x;
    }
    return p[x] = findSet (p[x]);
  }
  void merge (int i, int j) pure nothrow @nogc {
    i = findSet (i);
    j = findSet (j);
    if (i != j) {
      if (h[i] < h[j]) {
        p[i] = j;
        s[j] = s[i] + s[j];
      } else if (h[i] > h[j]) {
        p[j] = i;
        s[i] = s[i] + s[j];
      } else {
        p[i] = j;
        ++h[j];
        s[j] = s[i] + s[j];
      }
    }
  }
}

class InputReader {
  private:
  ubyte[] p;
  ubyte[] buffer;
  size_t cur;
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
    p = stdin.rawRead (buffer);
  }
  final ubyte skipByte (ubyte lo) {
    while (true) {
      auto a = p[cur .. $];
      auto r = a.find! (c => c >= lo);
      if (!r.empty) {
        cur += a.length - r.length;
        return p[cur++];
      }
      p = stdin.rawRead (buffer);
      cur = 0;
      if (p.empty) return 0;
    }
  }
  final ubyte nextByte () {
    if (cur < p.length) {
       return p[cur++];
    }
    p = stdin.rawRead (buffer);
    if (p.empty) return 0;
    cur = 1;
    return p[0];
  }
  template next(T) if (isUnsigned!T) {
    final T next () {
      T res = skipByte (48) - 48;
      while (true) {
        ubyte b = nextByte ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
}

struct IntM {
  enum q = 1_000_000_007;
  int v;
  this (int m) pure nothrow @nogc {
    v = m % q;
    if (v < 0) {
      v += q;
    }
  }
  IntM opAssign (int m) pure nothrow @nogc {
    v = m % q;
    if (v < 0) {
      v += q;
    }
    return this;
  }
  IntM opUnary (string op : "-")() const pure nothrow @nogc {
    return IntM ((q - v) % q);
  }
  ref IntM opOpAssign (string op : "+")(in IntM rhs) pure nothrow @nogc {
    v += rhs.v;
    v %= q;
    return this;
  }
  ref IntM opOpAssign (string op : "-")(in IntM rhs) pure nothrow @nogc {
    v -= rhs.v;
    v %= q;
    return this;
  }
  ref IntM opOpAssign (string op : "*")(in IntM rhs) pure nothrow @nogc {
    v = ((v.to!(long)) * rhs.v.to!(long)) % q;
    return this;
  }
  IntM opBinary (string op : "+")(in IntM rhs) const pure nothrow @nogc {
    return IntM ( (v + rhs.v) % q);
  }
  IntM opBinary (string op : "-")(in IntM rhs) const pure nothrow @nogc {
    return IntM ( (v - rhs.v) % q);
  }
  IntM opBinary (string op : "*")(in IntM rhs) const pure nothrow @nogc {
    return IntM (((v.to!(long)) * rhs.v.to!(long)) % q);
  }
  IntM opBinary (string op : "^^")(in int rhs) const pure nothrow @nogc {
    IntM a = 1, b = this;
    int p = rhs;
    while (p > 0) {
      //a * (b ^ p) == x ^ rhs
      if (p & 1) {
        a *= b;
      }
      b *= b;
      p >>>= 1;
    }
    return a;
  }
  IntM opBinary (string op)(in int v) const pure nothrow @nogc if (op == "+" || op == "-" || op == "*") {
    mixin ("return this " ~ op ~ " IntM(v);");
  }
  string toString() const pure nothrow { return ((v < 0) ? v + q : v).text; }
}

void main() {
  auto r = new InputReader;
  immutable n = r.next!uint;
  immutable k = r.next!uint;
  auto ds = new DisjointSet (n);
  foreach (edge; 1 .. n) {
    immutable i = r.next!uint - 1;
    immutable j = r.next!uint - 1;
    immutable c = r.next!uint;
    if (c == 0) {
      ds.merge (i, j);
    }
  }
  int[] x;
  foreach (i; 0 .. n) {
    if (ds.findSet (i) == i) {
      x ~= ds.s[i];
    }
  }
  immutable m = x.length.to!int;
  IntM s;
  foreach (i; x) {
    auto c = IntM (i);
    s += c ^^ k;
  }
  IntM res = IntM (n) ^^ k;
  res -= s;
  write (res);
}


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

class InputReader {
  private:
  ubyte[] p;
  ubyte[] buffer;
  size_t cur;
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
    p = stdin.rawRead (buffer);
  }
  final ubyte skipByte (ubyte lo) {
    while (true) {
      auto a = p[cur .. $];
      auto r = a.find! (c => c >= lo);
      if (!r.empty) {
        cur += a.length - r.length;
        return p[cur++];
      }
      p = stdin.rawRead (buffer);
      cur = 0;
      if (p.empty) return 0;
    }
  }
  final ubyte nextByte () {
    if (cur < p.length) {
       return p[cur++];
    }
    p = stdin.rawRead (buffer);
    if (p.empty) return 0;
    cur = 1;
    return p[0];
  }

  template next(T) if (isSigned!T) {
    final T next ()  {
      T res;
      ubyte b = skipByte (45);
      if (b == 45) {
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    final T next () {
      T res = skipByte (48) - 48;
      while (true) {
        ubyte b = nextByte ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  final T[] nextA(T) (int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

void main() {
  auto r = new InputReader;
  auto nt = r.next!uint;
  foreach (tid; 0 .. nt) {
    auto a = r.nextA!ulong(3);
    sort (a);
    auto s = sum (a);
    long m = (s + 1) / 2;
    if (a[2] > m) {
      writeln ("No");
    } else {
      writeln ("Yes");
    }
  }
}

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

void main() {
    auto T = readln.chomp.to!int;
    while (T--) {
        auto s = readln.split.map!(to!int).array;
        s.sort();
        auto a = s[0];
        auto b = s[1];
        auto c = s[2];
        if (c <= a + b + 1) {
            writeln("Yes");
        } else {
            writeln("No");
        }
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto r = RD!int;
		auto g = RD!int;
		auto b = RD!int;
		long[] arr = [r, g, b];
		arr.sort();
		ans[ti] = arr[2] <= (arr.sum+1)/2;
	}

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

void main() {
	auto t = ri;
	foreach(i; 0..t) {
		auto ip = readAs!(long[]).sort.array;
		if(ip[2] > ip[0] + ip[1] + 1) writeln("No");
		else writeln("Yes");
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

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

void solve(){
	foreach(_; 0 .. rint){
		long a = rlong, b = rlong, c = rlong;
		long n = a + b + c;
		long m = (n + 1) / 2;
		if(a > m || b > m || c > m) "No".writeln;
		else "Yes".writeln;
	}
}

void main() {
	auto t = ri;
	foreach(i; 0..t) {
		auto ip = readAs!(int[]), r = ip[0], g = ip[1], b = ip[2];
		if(r > (g + b) || g > (r + b) || b > (r + g)) writeln("No");
		else writeln("Yes");
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

void main() {
	auto t = ri;
	foreach(i; 0..t) {
		auto ip = readAs!(int[]), r = ip[0], g = ip[1], b = ip[2];
		if(r > (g + b) && g > (r + b) && b > (r + g)) writeln("No");
		else writeln("Yes");
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

void main() {
	auto t = ri;
	foreach(i; 0..t) {
		auto ip = readAs!(int[]).sort.uniq.array;
		if(ip[2] > ip[0] + ip[1] + 1) writeln("No");
		else writeln("Yes");
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

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

void solve(){
	foreach(_; 0 .. rint){
		long a = rlong, b = rlong, c = rlong;
		long n = a + b + c;
		long m = n / 2;
		if(a > m || b > m || c > m) "No".writeln;
		else "Yes".writeln;
	}
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto r = RD!int;
		auto g = RD!int;
		auto b = RD!int;
		auto arr = [r, g, b];
		arr.sort();
		ans[ti] = arr[2] <= (arr.sum+1)/2;
	}

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


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;

immutable int N = 15_000_000 + 10;

void main()
{
    auto dvs = new int[N];
    auto cnt = new int[N];

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

    foreach (i; 2 .. N) {
        if (dvs[i] != 0) continue;

        dvs[i] = i;
        for (int j = i+i; j < N; j += i) dvs[j] = i;
    }

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

    auto gcdnow = arr.fold!gcd;
    arr[] /= gcdnow;

    debug { gcdnow.writeln; }

    foreach (e; arr) {
        while (e > 1) {
            auto now = dvs[e];
            ++cnt[now];
            while (dvs[e] == now) e /= now;
        }
    }

    auto left = cnt[2 .. $].maxElement;

    if (left == 0) {
        writeln(-1);
        return;
    }

    writeln(n - left);
}

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;

immutable int N = 15_000_000 + 10;

void main()
{
    auto pr = new bool[N];
    auto cnt = new int[N];

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

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

    auto gcdnow = arr.fold!gcd;
    debug { gcdnow.writeln; }

    arr.each!(e => ++cnt[e / gcdnow]);

    auto ans = 0;
    pr[] = true;
    foreach (i; 2 .. N) {
        if (!pr[i]) continue;

        auto cur = 0;
        for (int j = i; j < N; j += i) {
            cur += cnt[j];
            pr[j] = false;
        }

        ans = max(ans, cur);
    }

    ans = ans > 0 ? n - ans : -1;
    writeln(ans);
}

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;

immutable int N = 15_000_000 + 10;

void main()
{
    auto dvs = new int[N];
    auto cnt = new int[N];

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

    foreach (i; 2 .. N) {
        if (dvs[i] != 0) continue;

        dvs[i] = i;
        for (int j = i+i; j < N; j += i) dvs[j] = i;
    }

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

    auto gcdnow = arr.fold!gcd;

    debug { gcdnow.writeln; }

    foreach (e; arr) {
        while (e > 1) {
            auto now = dvs[e];
            ++cnt[now];
            while (dvs[e] == now) e /= now;
        }
    }

    auto left = cnt[gcdnow+1 .. $].maxElement;

    if (left == 0) {
        writeln(-1);
        return;
    }

    writeln(n - left);
}


import std.algorithm : max, maxElement, sort, swap;
import std.conv : to;
import std.numeric : gcd;
import std.range;
import std.stdio;
import std.typecons : Tuple, tuple;
import std.algorithm.mutation;

// import std.container.array;

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

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

void main()
{
    int n = readInt;
    auto a = new int[n];
    for (int i = 0; i < n; ++i)
        a[i] = readInt;
    int m = a.maxElement;
    auto cnt = new int[m + 1];
    auto mu = new int[m + 1];
    mu[1] = 1;
    for (int d = 1; d <= m; ++d)
    {
        cnt[d]++;
        for (int i = d * 2; i <= m; i += d)
            cnt[i]++, mu[i] -= mu[d];
    }
    auto divs = new int[][m + 1];
    for (int i = 1; i <= m; ++i)
        divs[i] = new int[cnt[i]];
    fill(cnt, 0);
    for (int d = 1; d <= m; ++d)
        for (int i = d; i <= m; i += d)
            divs[i][cnt[i]++] = d;
    fill(cnt, 0);
    for (int i = 0; i < n; ++i)
        cnt[a[i]]++;
    long result = m;
    int[] stack = new int[m], subcnt = new int[m + 1];
    for (int g = 1; g <= m; ++g)
    {
        int m1 = m / g;
        int top = 0;
        for (int x = m1; x >= 1; --x)
            if (cnt[g * x])
            {
                int coprimes = 0;
                foreach (d; divs[x])
                    coprimes += mu[d] * subcnt[d];
                while (coprimes)
                {
                    int y = stack[--top];
                    if (gcd(x, y) == 1)
                        coprimes--, result = max(result, cast(long) g * x * y);
                    foreach (d; divs[y])
                        subcnt[d]--;
                }
                foreach (d; divs[x])
                    subcnt[d]++;
                stack[top++] = x;
            }
        while (top--)
            foreach (d; divs[stack[top]])
                subcnt[d]--;
    }
    writeln(result);
}

import std.algorithm;
import std.conv : to;
import std.numeric : gcd;
import std.range;
import std.stdio;
import std.typecons : Tuple, tuple;

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

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

void main()
{
    int n = readInt;
    auto a = new int[n];
    for (int i = 0; i < n; ++i)
        a[i] = readInt;
    int m = a.maxElement;
    auto cnt = new int[m + 1];
    auto mu = new int[m + 1];
    mu[1] = 1;
    for (int d = 1; d <= m; ++d)
    {
        if (!mu[d])
            continue;
        cnt[d]++;
        for (int i = d * 2; i <= m; i += d)
            cnt[i]++, mu[i] -= mu[d];
    }
    auto divs = new int[][m + 1];
    for (int i = 1; i <= m; ++i)
        divs[i] = new int[cnt[i]];
    fill(cnt, 0);
    for (int d = 1; d <= m; ++d)
        if (mu[d])
            for (int i = d; i <= m; i += d)
                divs[i][cnt[i]++] = d;
    fill(cnt, 0);
    for (int i = 0; i < n; ++i)
        cnt[a[i]]++;
    long result = m;
    int[] stack = new int[m], subcnt = new int[m + 1];
    for (int g = 1; g <= m; ++g)
    {
        int m1 = m / g;
        int top = 0;
        for (int x = m1; x >= 1; --x)
            if (cnt[g * x])
            {
                int coprimes = 0;
                foreach (d; divs[x])
                    coprimes += mu[d] * subcnt[d];
                while (coprimes)
                {
                    int y = stack[--top];
                    if (gcd(x, y) == 1)
                        coprimes--, result = max(result, cast(long) g * x * y);
                    foreach (d; divs[y])
                        subcnt[d]--;
                }
                foreach (d; divs[x])
                    subcnt[d]++;
                stack[top++] = x;
            }
        while (top--)
            foreach (d; divs[stack[top]])
                subcnt[d]--;
    }
    writeln(result);
}


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

DList!string _words;

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

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

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

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

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

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

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

    }
}

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

void main()
{
  int t;
  read(t);
  while(t--)
    {
      int n;
      read(n);
      string s;
      read(s);
      string rs = s.dup.reverse;
      auto prefix = cast(long) s.countUntil('1');
      if (prefix == -1)
        prefix = n;
      auto suffix = cast(long) rs.countUntil('0');
      if (suffix == -1)
        suffix = n;
      string middle = "";
      if (suffix + prefix < n)
        middle = "0";
      string res = s[0 .. cast(size_t)prefix] ~ middle ~ s[$ - cast(size_t)suffix .. $];
      writeln(res);
    }
}

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;
		string res1, res2, res3;
		while (!s.empty && s.front == '0')
		{
			res1 ~= s.front;
			s.popFront ();
		}
		while (!s.empty && s.back == '1')
		{
			res3 ~= s.back;
			s.popBack ();
		}
		if (!s.empty)
		{
			res2 = "0";
		}
		writeln (res1 ~ res2 ~ res3);
	}
}

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 string[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto s = RD!string;

		int l = n, r = -1;
		foreach (int i; 0..n)
		{
			if (s[i] == '1')
			{
				l = i;
				break;
			}
		}
		foreach_reverse (int i; 0..n)
		{
			if (s[i] == '0')
			{
				r = i;
				break;
			}
		}
		if (l < r)
			ans[ti] = s[0..l] ~ '0' ~ s[r+1..s.length];
		else
			ans[ti] = s[0..l] ~ s[r+1..s.length];
	}

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


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

    Tuple!(int, int)[] ans;
    foreach (i; 2 .. n+1) {
        int prev = i-k < 1 ? 1 : i-k;
        ans ~= tuple(prev, i);
    }

    int longerCnt = (n-1)%k;
    int longerVal = (n-1 + k-1)/k;
    int shorterVal = (n-1)/k;
    int dst = longerCnt == 0 ? shorterVal * 2
        : longerCnt == 1 ? shorterVal + longerVal : longerVal * 2;
    writeln(dst);
    ans.each!(t => writeln(t[0], ' ', t[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[][] graph;

alias Result = Tuple!(int, "d", int, "u");

Result dfs(int u, int p) {
  auto ret = Result(0, u);
  foreach (v; graph[u]) {
    if (v != p) {
      const res = dfs(v, u);
      chmax(ret, Result(1 + res.d, res.u));
    }
  }
  return ret;
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      const K = readInt();

      int[][] ans;
      int n = 1 + (N - 1) % K;
      foreach (u; 1 .. n) {
        ans ~= [0, u];
      }
      int a, b;
      if (n == 1) {
        a = 0;
        b = 1;
      } else if (n == 2) {
        a = 0;
        b = 2;
      } else {
        a = 1;
        b = n;
      }
      debug {
        writefln("N = %s, K = %s", N, K);
        writefln("n = %s, a = %s, b = %s", n, a, b);
      }
      for (; n < N; n += K) {
        foreach (k; 0 .. K) {
          ans ~= [a + k % (b - a), n + k];
        }
        a = n;
        b = n + K;
      }

      graph = new int[][N];
      foreach (edge; ans) {
        graph[edge[0]] ~= edge[1];
        graph[edge[1]] ~= edge[0];
      }
      const res0 = dfs(0, -1);
      const res1 = dfs(res0.u, -1);
      writeln(res1.d);
      foreach (edge; ans) {
        writeln(edge[0] + 1, " ", edge[1] + 1);
      }
    }
  } catch (EOFException e) {
  }
}

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

    Tuple!(int, int)[] ans;
    foreach (i; 2 .. n+1) {
        int prev = i-k < 1 ? 1 : i-k;
        ans ~= tuple(prev, i);
    }

    int longerCnt = (n-1)%k;
    int longerVal = (n-1 + k-1)/k;
    int shorterVal = (n-1)/k;
    int dst = longerCnt == 0 ? shorterVal * 2
        : longerCnt == 1 ? shorterVal + longerVal : 2 * longerVal;
    writeln(dst);
    ans.each!(t => writeln(t[0], ' ', t[1]));
}

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

    Tuple!(int, int)[] ans;

    void star(int sz) {
        foreach (i; 2 .. sz+1) {
            ans ~= tuple(1, i);
        }
    }

    if (k == n-1) {
        star(n);
        writeln(2);
        ans.each!(t => writeln(t[0], ' ', t[1]));
    } else {
        star(k+1);
        foreach (i; k+1 .. n) {
            ans ~= tuple(i, i+1);
        }

        writeln(n - (k-1));
        ans.each!(t => writeln(t[0], ' ', t[1]));
    }
}

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

    Tuple!(int, int)[] ans;

    void star(int sz) {
        foreach (i; 2 .. sz+1) {
            ans ~= tuple(1, i);
        }
    }

    if (k == n-1) {
        star(n);
        writeln(2);
        ans.each!(t => writeln(t[0], ' ', t[1]));
    } else {
        star(k+1);
        foreach (i; k+2 .. n) {
            ans ~= tuple(i, i+1);
        }

        writeln(n - (k-1));
        ans.each!(t => writeln(t[0], ' ', t[1]));
    }
}

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

    Tuple!(int, int)[] ans;
    foreach (i; 2 .. n+1) {
        int prev = i-k < 1 ? 1 : i-k;
        ans ~= tuple(prev, i);
    }

    writeln((n-1)/k + (n-1 + k-1)/k);
    ans.each!(t => writeln(t[0], ' ', t[1]));
}

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

    Tuple!(int, int)[] ans;

    void star(int sz) {
        foreach (i; 2 .. sz+1) {
            ans ~= tuple(1, i);
        }
    }

    if (k == n-1) {
        star(n);
    } else if (k == n-2) {
        star(n-2);
        ans ~= tuple(1, n-1);
        ans ~= tuple(n-1, n);
    } else {
        star(k+1);
        foreach (i; k+2 .. n) {
            ans ~= tuple(i, i+1);
        }
        ans ~= tuple(n, 1);
    }

    ans.length.writeln;
    foreach (t; ans) {
        writeln(t[0], ' ', t[1]);
    }
}

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

    Tuple!(int, int)[] ans;

    void star(int sz) {
        foreach (i; 2 .. sz+1) {
            ans ~= tuple(1, i);
        }
    }

    if (k == n-1) {
        star(n);
        writeln(2);
        ans.each!(t => writeln(t[0], ' ', t[1]));
    } else {
        star(k);
        foreach (i; k .. n) {
            ans ~= tuple(i, i+1);
        }

        writeln(n - (k-1));
        ans.each!(t => writeln(t[0], ' ', t[1]));
    }
}


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

void main ()
{
	int rows, cols, sRow, sCol;
	while (readf !(" %s %s %s %s") (rows, cols, sRow, sCol) > 0)
	{
		auto r = rows.iota.array;
		swap (r[0], r[sRow - 1]);
		r[] += 1;
		auto c = cols.iota.array;
		swap (c[0], c[sCol - 1]);
		c[] += 1;
		foreach (row; 0..rows)
		{
			if (row & 1)
			{
				foreach_reverse (col; 0..cols)
				{
					writeln (r[row], " ", c[col]);
				}
			}
			else
			{
				foreach (col; 0..cols)
				{
					writeln (r[row], " ", c[col]);
				}
			}
		}
	}
}

// Vicfred
// https://codeforces.com/contest/1395/problem/B
// implementation
import std.stdio;

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

    writefln("%s %s", sx, sy);

    for(int i = 1; i <= n; i++)
        if(i != sx)
            writefln("%s %s", i, sy);

    for(int i =1; i <= m; i++) {
        if(i == sy)
            continue;
        int direction = i&1;
        if(i > sy)
            direction ^= 1;
        if(direction == 1)
            for(int j = n; j > 0; j--)
                writefln("%s %s", j, i);
        else
            for(int j = 1; j <= n; j++)
                writefln("%s %s", j, i);
    }
}

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

alias type = single;
struct TestCase
{
  mixin prettyPrinting;

  long n, m, sx, sy;

  void solve(long tc = -1)
  {
    foreach(y; sy .. m + 1)
      {
        writeln(sx, " ", y);
      }
    foreach_reverse(y; 1 .. sy)
      {
        writeln(sx, " ", y);
      }
    bool bottom = true;
    foreach(col; 1 .. n + 1)
      if (col != sx)
      {
        if (bottom)
          {
            foreach(y; 1 .. m + 1)
              {
                writeln(col, " ", y);
              }
          }
        else
          {
            foreach_reverse(y; 1 .. m + 1)
              {
                writeln(col, " ", y);
              }
          }
        bottom = !bottom;
      }
  }
}

struct Interval
{
  long l, h;

  bool empty()
  {
    return l > h;
  }
}

Interval intersect(Interval a, Interval b)
{
  return Interval(max(a.l, b.l), min(a.h, b.h));
}

struct If
{
  string condition;
}
enum ignore = If("false");
struct Dim
{
  string dimensions;
  int levels;
  this(string dimensions)
  {
    this.dimensions = dimensions;
    levels = cast(int)dimensions.count(",") + 1;
  }
}

template getArrayLevel(W)
{
  static if (isDynamicArray!W && !is(W == string))
    enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));
  else
    enum getArrayLevel = 0;
}

static foreach(fieldName; 'a' .. cast(char)('z' + 1))
  {
    static if (fieldName != 'o')
      mixin("enum d", fieldName, " = Dim(\"", fieldName, "\");");
  }

mixin template prettyPrinting()
{
  string toString()
  {
    alias structType = typeof(this);
    auto res = appender!(string)();
    res.put(structType.stringof);
    res.put("(");
    static foreach(fieldName; FieldNameTuple!structType)
      {
        res.put(text(" ", fieldName, ": ", mixin(fieldName)));
      }
    res.put(" )");
    res.put("\n");
    return res[];
  }
}

struct Graph(N)
{
  size_t size;
  this(S)(S size)
  {
    adjacencyList.length = cast(size_t) size;
    this.size = cast(size_t) size;
    this.visited = makeSlice!bool(size);
  }
  N[][] adjacencyList;
  alias ne = neighbours;
  N[] neighbours(N n)
  {
    return adjacencyList.at(n);
  }
  alias bcon = biconnect;
  void biconnect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
    adjacencyList.at(b) ~= a;
  }
  alias con = connect;
  void connect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
  }
  void connect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        connect(edge[0], edge[1]);
      }
  }
  void biconnect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        biconnect(edge[0], edge[1]);
      }
  }
  alias deg = degree!long;
  auto degree(T)(N a)
  {
    return cast(T) adjacencyList.at(a).length;
  }

  auto visited = new bool[0];
  void dfs(Visitor)(long startNode)
  {
    auto visitor = Visitor.init;
    void internalDfs(long node)
    {
      visited.set(node, true);
      static if (is(typeof({visitor.n = node;})))
        visitor.n = node;
      static if (is(typeof({visitor.pre;})))
        visitor.pre;
      foreach(w; ne(node))
        if (!visited.at(w))
          {
            static if (is(typeof({visitor.w = w;})))
              visitor.w = w;
            static if (is(typeof(visitor.pren)))
              visitor.pren;
            internalDfs(w);
            static if (is(typeof(visitor.postn)))
              visitor.postn;
          }
      static if (is(typeof(visitor.post)))
        visitor.post;
    }
    internalDfs(startNode);
  }
  void dfs(long startNode)
  {
    struct DefVisitor {}
    dfs!DefVisitor(startNode);
  }
}

DList!string _words;

template removeArray(W, int times)
{
  static if (times == 0)
    alias removeArray = W;
  else static if (times == 1)
    alias removeArray = typeof(function(){W w; return w[0];}());
  else
    {
      static assert(isDynamicArray!W);
      alias removeArray = removeArray!(removeArray!(W, 1), times - 1);
    }
}

template baseType(W)
{
  static if (isDynamicArray!W && !is(W == string))
    alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));
  else
    alias baseType = W;
}

auto makeSlice(E, W, T...)(W size, T otherSizes)
{
  static if (T.length == 0)
    {
      E[] res;
      res.length = cast(size_t) size;
      return res;
    }
  else
    {
      typeof(makeSlice!E(otherSizes))[] res;
      res.length = cast(size_t) size;
      foreach(ref row; res)
        row = makeSlice!E(otherSizes);
      return res;
    }
}

void read(T...)(ref T t)
{
  void basicTypeRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  void iterableRead(W)(ref W w)
  {
    foreach(ref element; w)
      read(element);
  }
  void tupleRead(W)(ref W w)
  {
    static foreach(j; 0 .. W.length)
      read(w[j]);
  }
  void structRead(W)(ref W readStruct)
  {
    static foreach(fieldName; FieldNameTuple!W)
      {
        with(readStruct)
          {
            alias fieldSymbol = mixin(W.stringof, ".", fieldName);
            alias typeOfField = typeof(mixin(fieldName));
            static if (hasUDA!(fieldSymbol, If))
              enum condition = getUDAs!(fieldSymbol, If)[0].condition;
            else
              enum condition = "true";

            if (mixin(condition))
              {
                static if (hasUDA!(fieldSymbol, Dim))
                  {
                    static assert(isDynamicArray!(typeOfField)
                                  , text(W.stringof, ".", fieldName, " has Dim UDA but isn't a Dynamic Array."));
                    enum uda = getUDAs!(fieldSymbol, Dim)[0];
                    static assert(getArrayLevel!(typeOfField) == uda.levels,
                                  text(W.stringof, ".", fieldName, " has a Dim UDA with different number of dimensions than it's type."));
                    mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});
                  }
                else static if (isDynamicArray!typeOfField && !is(typeOfField == string))
                  {
                    pragma(msg, "Warning: You probably want to add dimension to input ", W.stringof, ".", fieldName);
                  }
                read(mixin(fieldName));
              }
          }
      }
  }
  static foreach(i; 0 .. T.length)
    {
      static if (isBasicType!(T[i]) || is(T[i] == string))
        basicTypeRead(t[i]);
      else static if (is(typeof({foreach(ref e; t[i]){}})))
        iterableRead(t[i]);
      else static if (isTuple!(T[i]))
        tupleRead(t[i]);
      else static if (isAggregateType!(T[i]))
        structRead(t[i]);
    }
}

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

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

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

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

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

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

    }
}

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

template mem(alias F)
{
  ReturnType!F[Tuple!(Parameters!F)] table;
  ReturnType!F mem(Parameters!F args)
  {
    return table.require(tuple(args), F(args));
  }
}

string input(string names, string type = "long")
{
  return text(type, " ", names, "; read(", names, ");");
}

auto pmod(T, W)(T t, W w)
{
  return (t%w + w) % w;
}

void rep(S, F)(F f, S times)
{
  static if (is(typeof(f(i))))
    foreach(i; 0 .. times)
      f(i);
  else
    foreach(i; 0 .. times)
      f();
}

void multi()
{
  foreach(tc; 0 .. next!long)
    next!TestCase.solve(tc);
}

void single()
{
  auto tc = next!TestCase;
  tc.solve;
}

void main()
{
  type;
}

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 n = RD!int;
	auto m = RD!int;
	auto sx = RD!int;
	auto sy = RD!int;

	int[][] ans;
	foreach_reverse (y; 1..sy+1)
	{
		ans ~= [sx, y];
	}
	foreach (y; sy+1..m+1)
	{
		ans ~= [sx, y];
	}
	auto x = sx-1;
	auto y = m;
	ans ~= [x, y];
	int dir = -1;
	while (true)
	{
		//debug writeln(x, " ", y);
		y += dir;
		if (y == 0 || y == m+1)
		{
			dir = -dir;
			y += dir;
			--x;
			if (x == 0) break;
		}
		ans ~= [x, y];
	}

	x = sx+1;
	ans ~= [x, y];
	while (true)
	{
		//debug writeln(x, " ", y);
		y += dir;
		if (y == 0 || y == m+1)
		{
			dir = -dir;
			y += dir;
			++x;
			if (x == n+1) break;
		}
		ans ~= [x, y];
	}

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

// Vicfred
// https://codeforces.com/contest/1395/problem/B
// implementation
import std.stdio;

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

    writefln("%s %s", sx, sy);

    for(int i = 1; i <= n; i++)
        if(i != sx)
            writefln("%s %s", i, sx);

    for(int i =1; i <= m; i++) {
        if(i == sy)
            continue;
        int direction = i&1;
        if(i > sy)
            direction ^= 1;
        if(direction == 1)
            for(int j = n; j > 0; j--)
                writefln("%s %s", j, i);
        else
            for(int j = 1; j <= n; j++)
                writefln("%s %s", j, i);
    }
}