Recently Vladik discovered a new entertainment — coding bots for social networks. He would like to use machine learning in his bots so now he want to prepare some learning data for them.At first, he need to download t chats. Vladik coded a script which should have downloaded the chats, however, something went wrong. In particular, some of the messages have no information of their sender. It is known that if a person sends several messages in a row, they all are merged into a single message. It means that there could not be two or more messages in a row with the same sender. Moreover, a sender never mention himself in his messages.Vladik wants to recover senders of all the messages so that each two neighboring messages will have different senders and no sender will mention himself in his messages.He has no idea of how to do this, and asks you for help. Help Vladik to recover senders in each of the chats!

The first line contains single integer t (1 ≤ t ≤ 10) — the number of chats. The t chats follow. Each chat is given in the following format. The first line of each chat description contains single integer n (1 ≤ n ≤ 100) — the number of users in the chat. The next line contains n space-separated distinct usernames. Each username consists of lowercase and uppercase English letters and digits. The usernames can't start with a digit. Two usernames are different even if they differ only with letters' case. The length of username is positive and doesn't exceed 10 characters. The next line contains single integer m (1 ≤ m ≤ 100) — the number of messages in the chat. The next m line contain the messages in the following formats, one per line:    <username>:<text> — the format of a message with known sender. The username should appear in the list of usernames of the chat.  <?>:<text> — the format of a message with unknown sender.  The text of a message can consist of lowercase and uppercase English letter, digits, characters '.' (dot), ',' (comma), '!' (exclamation mark), '?' (question mark) and ' ' (space). The text doesn't contain trailing spaces. The length of the text is positive and doesn't exceed 100 characters. We say that a text mention a user if his username appears in the text as a word. In other words, the username appears in a such a position that the two characters before and after its appearance either do not exist or are not English letters or digits. For example, the text "Vasya, masha13 and Kate!" can mention users "Vasya", "masha13", "and" and "Kate", but not "masha". It is guaranteed that in each chat no known sender mention himself in his messages and there are no two neighboring messages with the same known sender.

Print the information about the t chats in the following format: If it is not possible to recover senders, print single line "Impossible" for this chat. Otherwise print m messages in the following format: <username>:<text> If there are multiple answers, print any of them.

1
2
Vladik netman
2
?: Hello, Vladik!
?: Hi

1
2
netman vladik
3
netman:how are you?
?:wrong message
vladik:im fine

2
3
netman vladik Fedosik
2
?: users are netman, vladik, Fedosik
vladik: something wrong with this chat
4
netman tigerrrrr banany2001 klinchuh
4
?: tigerrrrr, banany2001, klinchuh, my favourite team ever, are you ready?
klinchuh: yes, coach!
?: yes, netman
banany2001: yes of course.

Impossible
netman: tigerrrrr, banany2001, klinchuh, my favourite team ever, are you ready?
klinchuh: yes, coach!
tigerrrrr: yes, netman
banany2001: yes of course.

import std.stdio,std.range,std.algorithm,std.regex,std.conv,std.string;
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
void main()
{
	int t;
	while(input(&t))
	{
		foreach(gg;0..t)
		{
			int n;
			input(&n);
			auto aut=arread!string;
			int m;
			input(&m);
			auto a=new int[m], g=new int[][m],mes=new string[m];
			foreach(i;0..m)
			{
				auto s=readln.strip;
				mes[i]=s;
				if(s[0]=='?')
				{
					a[i]=-1;
					auto f=s[2..$].splitter(ctRegex!("[ ?.,:!]+"));
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
				else
				{
					auto f=s.splitter(ctRegex!("[ ?.,:!]+"));;
					a[i]=aut.countUntil(f.front);
					f.popFront;
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
			}
			int[105][105] dp, table;
			foreach(ref i;table)i[]=-1;
			int go(int p,int prev)
			{
				if(p==m)return true;
				int ans=table[p][prev];
				if(ans!=-1)return ans;
				ans=0;
				foreach(i;0..n)
				{
					if((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;
					if(go(p+1,i))
					{
						ans=true;
						dp[p][prev]=i;
						break;
					}
				}
				return table[p][prev]=ans;
			}
			auto o=go(0,0);
			if(!o){writeln("Impossible");continue;}
			int cur=0;
			foreach(i;0..m)
			{
				int x=dp[i][cur];
				a[i]=cur=x;
			}
			foreach(i;0..m)
			{
				if(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);
				else writeln(mes[i]);
			}
		}
	}
}

import std.stdio,std.range,std.algorithm,std.string,std.regex,std.conv;
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
@property auto arread(T)(){return readln.split.map!(to!(T)).array;}
void main()
{
	int t;
	loop:while(input(&t))
	{
		foreach(gg;0..t)
		{
			int n;
			input(&n);
			readln;
			auto aut=arread!string;
			int m;
			input(&m);
			readln;
			auto a=new int[m];
			auto g=new int[][m];
			auto mes=new string[m];
			foreach(i;0..m)
			{
				auto s=readln.strip;
				mes[i]=s;
				if(s[0]=='?')
				{
					a[i]=-1;
					auto f=s[2..$].strip.split(regex("[ ?.,:!]+"));
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
				else
				{
					auto f=s.strip.split(regex("[ ?.,:!]+"));
					a[i]=aut.countUntil(f.front);
					f.popFront;
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
			}
			int[105][105] dp, table;
			foreach(ref i;table)i[]=-1;
			int go(int p,int prev)
			{
				if(p==m)return true;
				int ans=table[p][prev];
				if(ans!=-1)return ans;
				ans=0;
				foreach(i;0..n)
				{
					if((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;
					if(go(p+1,i))
					{
						ans=true;
						dp[p][prev]=i;
						break;
					}
				}
				return table[p][prev]=ans;
			}
			auto o=go(0,0);
			if(!o){writeln("Impossible");continue;}
			int cur=0;
			foreach(i;0..m)
			{
				int x=dp[i][cur];
				a[i]=cur=x;
			}
			foreach(i;0..m)
			{
				if(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);
				else writeln(mes[i]);
			}
		}
	}
}

module main;
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.variant;
import core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
alias mp=make_pair;
alias bins=binary_search;
alias orsq=orient_square;
immutable int mod=1000000007;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	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)))
	{
		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;
	}
	@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))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(g<a[m])r=m;
			else l=m;
		}
		return (g<a[l])?l:r;
	}
	size_t binf(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 (g==a[l])?l: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;
	}
	V foldr(R,V,T)(R range,T arg,V nach)
		if(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))
	{
		for(;!range.empty;range.popFront()) nach=arg(nach,range.front);
		return nach;
	}
	size_t countr(R,T)(R range,T fun)
		if(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))
	{
		size_t nach;
		for(;!range.empty;range.popFront()) nach+=fun(range.front);
		return nach;
	}
	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);
	}
	real square(T)(pair!(T,T)[] figure...)
		if(is(typeof(figure.front*figure.front)==T))
	{
		return abs(orient_square(figure))/2.000000000000000;
	}
}
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,in size_t m)
{
	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;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
	}
	this(this){fi=fi;se=se;}
	this(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))
	{
		fi=p.fi;
		se=p.se;
	}
	pair!(X,Y) opAssign(A,B)(pair!(A,B) val)
	{
		return this=pair!(X,Y)(val);
	}
	int opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe
		if(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.split.map!(to!(T)).array;}
struct Tree(T,alias arg="a+b")
{
	private alias fun=binaryFun!arg;
	private static const size_t n=size_t.max>>1;
	private T[size_t] t;
	this(this){t=t.dup;}
	this(R)(R range) if(isInputRange!R && is(ElementType!(R) : T))
	{
		foreach(pos,i;range) upd(pos,i);
	}
	this(R,alias f)(Tree!(R,f) q) if(is(R:T))
	{
		foreach(i,j;q.t)
		{
			t[i]=j;
		}
	}
	Tree!(T,arg) opAssign(R)(R val)
	{
		return this=Tree!(T,arg)(val);
	}
	private void upd(in size_t v,in size_t vl,in size_t vr,in size_t i,in T x)
	{
		if (vr - vl == 1){t[v] = x;return;}
		size_t vm = (vl + vr) >> 1;
		if(i < vm) upd(2*v, vl, vm, i, x);
		else upd(2*v+1, vm, vr, i, x);
		if(v*2+1 !in t)t[v]=t[v*2];
		else if (v*2 !in t)t[v]=t[v*2+1];
		else t[v]=fun(t[v*2],t[v*2+1]);
	}
	void upd(in size_t i,in T x)
	{
		assert(i>=0 && i<n);
		upd(1,0,n,i,x);
	}
	private T cel(in size_t v,in size_t vl,in size_t vr,in size_t l,in size_t r)
	{
		if(vl==l && r==vr) return t[v];
		size_t vm=(vl+vr) >> 1;
		if(r<=vm) return cel(2*v,vl,vm,l,r);
		else if(l>=vm) return cel(2*v+1,vm,vr,l,r);
		else return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));
	}
	T cel(in size_t l,in size_t r){
		assert(l<=r && l>=0 && r<n);
		return cel(1,0,n,l,r);
	}
};
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	int t;
	loop:while(input(&t))
	{
		foreach(gg;0..t)
		{
			int n;
			input(&n);
			readln;
			auto aut=arread!string;
			int m;
			input(&m);
			readln;
			auto a=new int[m];
			auto g=new int[][m];
			auto mes=new string[m];
			foreach(i;0..m)
			{
				auto s=readln.strip;
				mes[i]=s;
				if(s[0]=='?')
				{
					a[i]=-1;
					auto f=s[2..$].splitter(regex("[ ?.,:!]+"));
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
				else
				{
					auto f=s.splitter(regex("[ ?.,:!]+"));
					a[i]=aut.countUntil(f.front);
					f.popFront;
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
			}
			int dp[105][105];
			int table[105][105];
			foreach(ref i;table)i[]=-1;
			int go(int p,int prev)
			{
				if(p==m)return true;
				int ans=table[p][prev];
				if(ans!=-1)return ans;
				ans=0;
				foreach(i;0..n)
				{
					if((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;
					if(go(p+1,i))
					{
						ans=true;
						dp[p][prev]=i;
						break;
					}
				}
				return table[p][prev]=ans;
			}
			auto o=go(0,0);
			if(!o){writeln("Impossible");continue;}
			int cur=0;
			foreach(i;0..m)
			{
				int x=dp[i][cur];
				a[i]=cur=x;
			}
			foreach(i;0..m)
			{
				if(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);
				else writeln(mes[i]);
			}
		}
	}
}

module main;
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.variant;
import core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
alias mp=make_pair;
alias bins=binary_search;
alias orsq=orient_square;
immutable int mod=1000000007;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	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)))
	{
		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;
	}
	@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))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(g<a[m])r=m;
			else l=m;
		}
		return (g<a[l])?l:r;
	}
	size_t binf(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 (g==a[l])?l: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;
	}
	V foldr(R,V,T)(R range,T arg,V nach)
		if(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))
	{
		for(;!range.empty;range.popFront()) nach=arg(nach,range.front);
		return nach;
	}
	size_t countr(R,T)(R range,T fun)
		if(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))
	{
		size_t nach;
		for(;!range.empty;range.popFront()) nach+=fun(range.front);
		return nach;
	}
	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);
	}
	real square(T)(pair!(T,T)[] figure...)
		if(is(typeof(figure.front*figure.front)==T))
	{
		return abs(orient_square(figure))/2.000000000000000;
	}
}
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,in size_t m)
{
	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;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
	}
	this(this){fi=fi;se=se;}
	this(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))
	{
		fi=p.fi;
		se=p.se;
	}
	pair!(X,Y) opAssign(A,B)(pair!(A,B) val)
	{
		return this=pair!(X,Y)(val);
	}
	int opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe
		if(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.split.map!(to!(T)).array;}
struct Tree(T,alias arg="a+b")
{
	private alias fun=binaryFun!arg;
	private static const size_t n=size_t.max>>1;
	private T[size_t] t;
	this(this){t=t.dup;}
	this(R)(R range) if(isInputRange!R && is(ElementType!(R) : T))
	{
		foreach(pos,i;range) upd(pos,i);
	}
	this(R,alias f)(Tree!(R,f) q) if(is(R:T))
	{
		foreach(i,j;q.t)
		{
			t[i]=j;
		}
	}
	Tree!(T,arg) opAssign(R)(R val)
	{
		return this=Tree!(T,arg)(val);
	}
	private void upd(in size_t v,in size_t vl,in size_t vr,in size_t i,in T x)
	{
		if (vr - vl == 1){t[v] = x;return;}
		size_t vm = (vl + vr) >> 1;
		if(i < vm) upd(2*v, vl, vm, i, x);
		else upd(2*v+1, vm, vr, i, x);
		if(v*2+1 !in t)t[v]=t[v*2];
		else if (v*2 !in t)t[v]=t[v*2+1];
		else t[v]=fun(t[v*2],t[v*2+1]);
	}
	void upd(in size_t i,in T x)
	{
		assert(i>=0 && i<n);
		upd(1,0,n,i,x);
	}
	private T cel(in size_t v,in size_t vl,in size_t vr,in size_t l,in size_t r)
	{
		if(vl==l && r==vr) return t[v];
		size_t vm=(vl+vr) >> 1;
		if(r<=vm) return cel(2*v,vl,vm,l,r);
		else if(l>=vm) return cel(2*v+1,vm,vr,l,r);
		else return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));
	}
	T cel(in size_t l,in size_t r){
		assert(l<=r && l>=0 && r<n);
		return cel(1,0,n,l,r);
	}
};
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	int t;
	loop:while(input(&t))
	{
		foreach(gg;0..t)
		{
			int n;
			input(&n);
			readln;
			auto aut=arread!string;
			int m;
			input(&m);
			readln;
			auto a=new int[m];
			auto g=new int[][m];
			auto mes=new string[m];
			foreach(i;0..m)
			{
				auto s=readln.strip;
				mes[i]=s;
				if(s[0]=='?')
				{
					a[i]=-1;
					auto f=s[2..$].strip.split(regex("[ ?.,:!]+"));
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
				else
				{
					auto f=s.strip.split(regex("[ ?.,:!]+"));
					a[i]=aut.countUntil(f.front);
					f.popFront;
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
			}
			int dp[105][105];
			int table[105][105];
			foreach(ref i;table)i[]=-1;
			int go(int p,int prev)
			{
				if(p==m)return true;
				int ans=table[p][prev];
				if(ans!=-1)return ans;
				ans=0;
				foreach(i;0..n)
				{
					if((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;
					if(go(p+1,i))
					{
						ans=true;
						dp[p][prev]=i;
						break;
					}
				}
				return table[p][prev]=ans;
			}
			auto o=go(0,0);
			if(!o){writeln("Impossible");continue;}
			int cur=0;
			foreach(i;0..m)
			{
				int x=dp[i][cur];
				a[i]=cur=x;
			}
			foreach(i;0..m)
			{
				if(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);
				else writeln(mes[i]);
			}
		}
	}
}

import std.stdio,std.range,std.algorithm,std.string,std.regex,std.conv;
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
@property auto arread(T)(){return readln.split.map!(to!(T)).array;}
void main()
{
	int t;
	while(input(&t))
	{
		foreach(gg;0..t)
		{
			int n;
			input(&n);
			readln;
			auto aut=arread!string;
			int m;
			input(&m);
			readln;
			auto a=new int[m], g=new int[][m],mes=new string[m];
			foreach(i;0..m)
			{
				auto s=readln.strip;
				mes[i]=s;
				if(s[0]=='?')
				{
					a[i]=-1;
					auto f=s[2..$].split(regex("[ ?.,:!]+"));
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
				else
				{
					auto f=s.split(regex("[ ?.,:!]+"));
					a[i]=aut.countUntil(f.front);
					f.popFront;
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
			}
			int[105][105] dp, table;
			foreach(ref i;table)i[]=-1;
			int go(int p,int prev)
			{
				if(p==m)return true;
				int ans=table[p][prev];
				if(ans!=-1)return ans;
				ans=0;
				foreach(i;0..n)
				{
					if((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;
					if(go(p+1,i))
					{
						ans=true;
						dp[p][prev]=i;
						break;
					}
				}
				return table[p][prev]=ans;
			}
			auto o=go(0,0);
			if(!o){writeln("Impossible");continue;}
			int cur=0;
			foreach(i;0..m)
			{
				int x=dp[i][cur];
				a[i]=cur=x;
			}
			foreach(i;0..m)
			{
				if(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);
				else writeln(mes[i]);
			}
		}
	}
}

import std.stdio,std.range,std.algorithm,std.regex,std.conv,std.string;
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
void main()
{
	int t;
	while(input(&t))
	{
		foreach(gg;0..t)
		{
			int n;
			input(&n);
			auto aut=arread!string;
			int m;
			input(&m);
			auto a=new int[m], g=new int[][m],mes=new string[m];
			foreach(i;0..m)
			{
				auto s=readln.strip;
				mes[i]=s;
				if(s[0]=='?')
				{
					a[i]=-1;
					auto f=s[2..$].split(regex("[ ?.,:!]+"));
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
				else
				{
					auto f=s.split(regex("[ ?.,:!]+"));;
					a[i]=aut.countUntil(f.front);
					f.popFront;
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
			}
			int[105][105] dp, table;
			foreach(ref i;table)i[]=-1;
			int go(int p,int prev)
			{
				if(p==m)return true;
				int ans=table[p][prev];
				if(ans!=-1)return ans;
				ans=0;
				foreach(i;0..n)
				{
					if((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;
					if(go(p+1,i))
					{
						ans=true;
						dp[p][prev]=i;
						break;
					}
				}
				return table[p][prev]=ans;
			}
			auto o=go(0,0);
			if(!o){writeln("Impossible");continue;}
			int cur=0;
			foreach(i;0..m)
			{
				int x=dp[i][cur];
				a[i]=cur=x;
			}
			foreach(i;0..m)
			{
				if(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);
				else writeln(mes[i]);
			}
		}
	}
}

import std.stdio,std.range,std.algorithm,std.regex,std.conv;
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
void main()
{
	int t;
	while(input(&t))
	{
		foreach(gg;0..t)
		{
			int n;
			input(&n);
			auto aut=arread!string;
			int m;
			input(&m);
			auto a=new int[m], g=new int[][m],mes=new string[m];
			foreach(i;0..m)
			{
				auto s=readln;
				mes[i]=s;
				if(s[0]=='?')
				{
					a[i]=-1;
					auto f=s[2..$].splitter(ctRegex!("[ ?.,:!\n]+"));
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
				else
				{
					auto f=s.splitter(ctRegex!("[ ?.,:!\n]+"));;
					a[i]=aut.countUntil(f.front);
					f.popFront;
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
			}
			int[105][105] dp, table;
			foreach(ref i;table)i[]=-1;
			int go(int p,int prev)
			{
				if(p==m)return true;
				int ans=table[p][prev];
				if(ans!=-1)return ans;
				ans=0;
				foreach(i;0..n)
				{
					if((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;
					if(go(p+1,i))
					{
						ans=true;
						dp[p][prev]=i;
						break;
					}
				}
				return table[p][prev]=ans;
			}
			auto o=go(0,0);
			if(!o){writeln("Impossible");continue;}
			int cur=0;
			foreach(i;0..m)
			{
				int x=dp[i][cur];
				a[i]=cur=x;
			}
			foreach(i;0..m)
			{
				if(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);
				else writeln(mes[i]);
			}
		}
	}
}

import std.stdio,std.range,std.algorithm,std.regex,std.conv;
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
void main()
{
	int t;
	while(input(&t))
	{
		foreach(gg;0..t)
		{
			int n;
			input(&n);
			auto aut=arread!string;
			int m;
			input(&m);
			auto a=new int[m], g=new int[][m],mes=new string[m];
			foreach(i;0..m)
			{
				auto s=readln;
				mes[i]=s;
				if(s[0]=='?')
				{
					a[i]=-1;
					auto f=s[2..$].splitter(ctRegex!("[ ?.,:!]+"));
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
				else
				{
					auto f=s.split(regex("[ ?.,:!]+"));
					a[i]=aut.countUntil(f.front);
					f.popFront;
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
			}
			int[105][105] dp, table;
			foreach(ref i;table)i[]=-1;
			int go(int p,int prev)
			{
				if(p==m)return true;
				int ans=table[p][prev];
				if(ans!=-1)return ans;
				ans=0;
				foreach(i;0..n)
				{
					if((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;
					if(go(p+1,i))
					{
						ans=true;
						dp[p][prev]=i;
						break;
					}
				}
				return table[p][prev]=ans;
			}
			auto o=go(0,0);
			if(!o){writeln("Impossible");continue;}
			int cur=0;
			foreach(i;0..m)
			{
				int x=dp[i][cur];
				a[i]=cur=x;
			}
			foreach(i;0..m)
			{
				if(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);
				else writeln(mes[i]);
			}
		}
	}
}


Riley is a very bad boy, but at the same time, he is a yo-yo master. So, he decided to use his yo-yo skills to annoy his friend Anton.Anton's room can be represented as a grid with $$$n$$$ rows and $$$m$$$ columns. Let $$$(i, j)$$$ denote the cell in row $$$i$$$ and column $$$j$$$. Anton is currently standing at position $$$(i, j)$$$ in his room. To annoy Anton, Riley decided to throw exactly two yo-yos in cells of the room (they can be in the same cell).Because Anton doesn't like yo-yos thrown on the floor, he has to pick up both of them and return back to the initial position. The distance travelled by Anton is the shortest path that goes through the positions of both yo-yos and returns back to $$$(i, j)$$$ by travelling only to adjacent by side cells. That is, if he is in cell $$$(x, y)$$$ then he can travel to the cells $$$(x + 1, y)$$$, $$$(x - 1, y)$$$, $$$(x, y + 1)$$$ and $$$(x, y - 1)$$$ in one step (if a cell with those coordinates exists).Riley is wondering where he should throw these two yo-yos so that the distance travelled by Anton is maximized. But because he is very busy, he asked you to tell him.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of each test case contains four integers $$$n$$$, $$$m$$$, $$$i$$$, $$$j$$$ ($$$1 \leq n, m \leq 10^9$$$, $$$1\le i\le n$$$, $$$1\le j\le m$$$) — the dimensions of the room, and the cell at which Anton is currently standing.

For each test case, print four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ ($$$1 \leq x_1, x_2 \leq n$$$, $$$1\le y_1, y_2\le m$$$) — the coordinates of where the two yo-yos should be thrown. They will be thrown at coordinates $$$(x_1,y_1)$$$ and $$$(x_2,y_2)$$$. If there are multiple answers, you may print any.

NoteHere is a visualization of the first test case.

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

alias Point = Tuple!(long, long);

long distance(Point a, Point b)
{
  return abs(a[0] - b[0]) + abs(a[1] - b[1]);
}

long distance3(Point start, Point a, Point b)
{
//  writeln(start);
  long tmp1 = distance(start, a) + distance(a, b);
  long tmp2 = distance(start, b) + distance(b, a);
//  long tmp3 = distance(start, a) + distance(start, b);
//  writeln(tmp1);
//  writeln(tmp2);
//  writeln(tmp3);
//  return min(tmp1, tmp2, tmp3);
  return min(tmp1, tmp2);
}

void main()
{
  long t;
  readf!" %d "(t);

  while (t--) {
    long n, m, i, j;
    readf!" %d %d %d %d "(n, m, i, j);
    i -= 1;
    j -= 1;
    auto start = Point(i, j);
    Point c0 = Point(0, 0);
    Point c1 = Point(0, m - 1);
    Point c2 = Point(n - 1, 0);
    Point c3 = Point(n - 1, m - 1);

    Point c4 = Point(i, 0);
    Point c5 = Point(i, m - 1);

//    auto x = [c0, c1, c2, c3];
//    writeln(x.permutations);
    long max = -1;
    Point p1, p2;
    foreach (x ; [c0, c1, c2, c3].permutations) {
      long dist = distance3(start, x[0], x[1]);
      if (dist > max) {
        max = dist;
        p1 = x[0];
        p2 = x[1];
      }
    }
    writefln("%d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);
//    writefln("%d %d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1, max);
  }
//  writeln(distance3(Point(1000000000 - 1, 50 - 1), Point(50 - 1, 1 - 1), Point(1 - 1, 1000000000 - 1)));
//  writeln(distance3(Point(1000000000 - 1, 50 - 1), Point(50 - 1, 1 - 1), Point(1 - 1, 1000000000 - 1)));
}

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

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

while(t--) {
    long n, m, i, j;
    readf("%s %s %s %s\n", &n, &m, &i, &j);
    if(m - j > j - 1) {
        writefln("%s %s %s %s", n, 1, 1, m);
    } else {
        writefln("%s %s %s %s", n, m, 1, 1);
    }
}
}

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

alias Point = Tuple!(long, long);

long distance(Point a, Point b)
{
  return abs(a[0] - b[0]) + abs(a[1] - b[1]);
}

long distance3(Point start, Point a, Point b)
{
//  writeln(start);
  long tmp1 = distance(start, a) + distance(a, b);
  long tmp2 = distance(start, b) + distance(b, a);
  long tmp3 = distance(start, a) + distance(start, b);
//  writeln(tmp1);
//  writeln(tmp2);
//  writeln(tmp3);
  return min(tmp1, tmp2, tmp3);
}

void main()
{
  long t;
  readf!" %d "(t);

  while (t--) {
    long n, m, i, j;
    readf!" %d %d %d %d "(n, m, i, j);
    i -= 1;
    j -= 1;
    auto start = Point(i, j);
    Point c0 = Point(0, 0);
    Point c1 = Point(0, m - 1);
    Point c2 = Point(n - 1, 0);
    Point c3 = Point(n - 1, m - 1);

    Point c4 = Point(i, 0);
    Point c5 = Point(i, m - 1);

//    auto x = [c0, c1, c2, c3];
//    writeln(x.permutations);
    long max = -1;
    Point p1, p2;
    foreach (x ; [c0, c1, c2, c3, c0, c1, c2, c3].permutations) {
      long dist = distance3(start, x[0], x[1]);
      if (dist > max) {
        max = dist;
        p1 = x[0];
        p2 = x[1];
      }
    }
    writefln("%d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);
//    writefln("%d %d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1, max);
  }
//  writeln(distance3(Point(1000000000 - 1, 50 - 1), Point(50 - 1, 1 - 1), Point(1 - 1, 1000000000 - 1)));
}

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

alias Point = Tuple!(long, long);

long distance(Point a, Point b)
{
  return abs(a[0] - b[0]) + abs(a[1] - b[1]);
}

long distance3(Point start, Point a, Point b)
{
  writeln(start);
  long tmp1 = distance(start, a) + distance(a, b);
  long tmp2 = distance(start, b) + distance(b, a);
  long tmp3 = distance(start, a) + distance(start, b);
  writeln(tmp1);
  writeln(tmp2);
  writeln(tmp3);
  return min(tmp1, tmp2, tmp3);
}

void main()
{
  long t;
  readf!" %d "(t);

  while (t--) {
    long n, m, i, j;
    readf!" %d %d %d %d "(n, m, i, j);
    i -= 1;
    j -= 1;
    auto start = Point(i, j);
    Point c0 = Point(0, 0);
    Point c1 = Point(0, m - 1);
    Point c2 = Point(n - 1, 0);
    Point c3 = Point(n - 1, m - 1);

    Point c4 = Point(i, 0);
    Point c5 = Point(i, m - 1);

//    auto x = [c0, c1, c2, c3];
//    writeln(x.permutations);
    long max = -1;
    Point p1, p2;
    foreach (x ; [c0, c1, c2, c3, c0, c1, c2, c3].permutations) {
      long tmp1 = distance(start, x[0]) + distance(x[0], x[1]);
      long tmp2 = distance(start, x[1]) + distance(x[1], x[0]);
      long tmp3 = distance(start, x[0]) + distance(start, x[1]);
      if (min(tmp1, tmp2, tmp3) > max) {
        max = min(tmp1, tmp2, tmp3);
        p1 = x[0];
        p2 = x[1];
      }
    }
    writefln("%d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);
//    writefln("%d %d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1, max);
  }
//  writeln(distance3(Point(1000000000 - 1, 50 - 1), Point(50 - 1, 1 - 1), Point(1 - 1, 1000000000 - 1)));
}

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

alias Point = Tuple!(int, int);

int distance(Point a, Point b)
{
  return abs(a[0] - b[0]) + abs(a[1] - b[1]);
}

void main()
{
  int t;
  readf!" %d "(t);

  while (t--) {
    int n, m, i, j;
    readf!" %d %d %d %d "(n, m, i, j);
    i -= 1;
    j -= 1;
    auto start = Point(i, j);
    Point c0 = Point(0, 0);
    Point c1 = Point(0, m - 1);
    Point c2 = Point(n - 1, 0);
    Point c3 = Point(n - 1, m - 1);
//    auto x = [c0, c1, c2, c3];
//    writeln(x.permutations);
    int max = -1;
    Point p1, p2;
    foreach (x ; [c0, c1, c2, c3, c0, c1, c2, c3].permutations) {
      int tmp1 = distance(start, x[0]) + distance(x[0], x[1]);
      int tmp2 = distance(start, x[1]) + distance(x[1], x[0]);
      int tmp3 = distance(start, x[0]) + distance(start, x[1]);
      if (min(tmp1, tmp2, tmp3) > max) {
        max = min(tmp1, tmp2, tmp3);
        p1 = x[0];
        p2 = x[1];
      }
    }
    writefln("%d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);
  }
}

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

alias Point = Tuple!(int, int);

int distance(Point a, Point b)
{
  return abs(a[0] - b[0]) + abs(a[1] - b[1]);
}

void main()
{
  int t;
  readf!" %d "(t);

  while (t--) {
    int n, m, i, j;
    readf!" %d %d %d %d "(n, m, i, j);
    i -= 1;
    j -= 1;
    auto start = Point(i, j);
    Point c0 = Point(0, 0);
    Point c1 = Point(0, m - 1);
    Point c2 = Point(n - 1, 0);
    Point c3 = Point(n - 1, m - 1);
//    auto x = [c0, c1, c2, c3];
//    writeln(x.permutations);
    int max = -1;
    Point p1, p2;
    foreach (x ; [c0, c1, c2, c3, c0, c1, c2, c3].permutations) {
      int tmp1 = distance(start, x[0]) + distance(x[0], x[1]);
      int tmp2 = distance(start, x[1]) + distance(x[0], x[1]);
      if (min(tmp1, tmp2) > max) {
        max = min(tmp1, tmp2);
        p1 = x[0];
        p2 = x[1];
      }
    }
    writefln("%d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);
  }
}

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

alias Point = Tuple!(int, int);

int distance(Point a, Point b)
{
  return abs(a[0] - b[0]) + abs(a[1] - b[1]);
}

void main()
{
  int t;
  readf!" %d "(t);

  while (t--) {
    int n, m, i, j;
    readf!" %d %d %d %d "(n, m, i, j);
    auto start = Point(i, j);
    Point c0 = Point(0, 0);
    Point c1 = Point(0, m - 1);
    Point c2 = Point(n - 1, 0);
    Point c3 = Point(n - 1, m - 1);
//    auto x = [c0, c1, c2, c3];
//    writeln(x.permutations);
    int max = -1;
    Point p1, p2;
    foreach (x ; [c0, c1, c2, c3].permutations) {
      int tmp1 = distance(start, x[0]) + distance(x[0], x[1]);
      int tmp2 = distance(start, x[1]) + distance(x[0], x[1]);
      if (min(tmp1, tmp2) > max) {
        max = min(tmp1, tmp2);
        p1 = x[0];
        p2 = x[1];
      }
    }
    writefln("%d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);
  }
}

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

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

while(t--) {
    long n, m, i, j;
    readf("%s %s %s %s\n", &n, &m, &i, &j);
    if(n - i < i - 1) {
        writefln("%s %s %s %s", n, n, 1, 1);
    } else {
        writefln("%s %s %s %s", 1, n, n, 1);
    }
}
}


You are given the array $$$a$$$ consisting of $$$n$$$ positive (greater than zero) integers.In one move, you can choose two indices $$$i$$$ and $$$j$$$ ($$$i \ne j$$$) such that the absolute difference between $$$a_i$$$ and $$$a_j$$$ is no more than one ($$$|a_i - a_j| \le 1$$$) and remove the smallest of these two elements. If two elements are equal, you can remove any of them (but exactly one).Your task is to find if it is possible to obtain the array consisting of only one element using several (possibly, zero) such moves or not.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

For each test case, print the answer: "YES" if it is possible to obtain the array consisting of only one element using several (possibly, zero) moves described in the problem statement, or "NO" otherwise.

NoteIn the first test case of the example, we can perform the following sequence of moves:  choose $$$i=1$$$ and $$$j=3$$$ and remove $$$a_i$$$ (so $$$a$$$ becomes $$$[2; 2]$$$);  choose $$$i=1$$$ and $$$j=2$$$ and remove $$$a_j$$$ (so $$$a$$$ becomes $$$[2]$$$). In the second test case of the example, we can choose any possible $$$i$$$ and $$$j$$$ any move and it doesn't matter which element we remove.In the third test case of the example, there is no way to get rid of $$$2$$$ and $$$4$$$.

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

DList!string _words;

void read(T...)(ref T t)
{
  void singleRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  static foreach(i; 0 .. T.length)
    {
      static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))
        {
          foreach(ref element; t[i])
            read(element);
        }
      else static if (isAggregateType!(T[i]))
        {
          static foreach(fieldName; FieldNameTuple!(T[i]))
            {
              static if (hasUDA!(mixin(text(T[i].stringof, ".", fieldName)), string))
                {
                  with(t[i])
                    {
                      mixin(q{t[i].}, fieldName, q{.length}) =
                        cast(size_t) mixin(getUDAs!(mixin(text(T[i].stringof, ".", fieldName)), string)[0]);
                    }
                }
              read(mixin(text(q{t[i].}, fieldName)));
            }
        }
      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)
{
  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;
}

E[] makeSlice(E, S)(S size, lazy E value)
{
  auto a = new E[size.ind];
  foreach(ref ai; a)
    ai = value();
  return a;
}

E[] makeSlice(E, S)(S size = 0)
{
  return new E[size.ind];
}

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()
{
 testCase:foreach(tc; 0 .. next!long)
    next!TestCase.solve(tc);
}

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

alias type = multi;
struct TestCase
{
  long n;
  @("n") long[] a;

  void solve(long i = -1)
  {
    sort(a);
    if (iota(0, n - 1).all!(i => a.at(i + 1) - a.at(i) <= 1))
      writeln("YES");
    else
      writeln("NO");
  }
}

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 t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;
		a.sort();

		bool ok = true;
		foreach (i; 1..n)
		{
			if (a[i] - a[i-1] > 1)
			{
				ok = false;
				break;
			}
		}
		ans[ti] = ok;
	}

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

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

DList!string _words;

void read(T...)(ref T t)
{
  void singleRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  static foreach(i; 0 .. T.length)
    {
      static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))
        {
          foreach(ref element; t[i])
            read(element);
        }
      else static if (isAggregateType!(T[i]))
        {
          static foreach(fieldName; FieldNameTuple!(T[i]))
            {
              static if (hasUDA!(mixin(text(T[i].stringof, ".", fieldName)), string))
                {
                  with(t[i])
                    {
                      mixin(q{t[i].}, fieldName, q{.length}) =
                        cast(size_t) mixin(getUDAs!(mixin(text(T[i].stringof, ".", fieldName)), string)[0]);
                    }
                }
              read(mixin(text(q{t[i].}, fieldName)));
            }
        }
      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)
{
  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;
}

E[] makeSlice(E, S)(S size, lazy E value)
{
  auto a = new E[size.ind];
  foreach(ref ai; a)
    ai = value();
  return a;
}

E[] makeSlice(E, S)(S size = 0)
{
  return new E[size.ind];
}

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()
{
 testCase:foreach(tc; 0 .. next!long)
    next!TestCase.solve(tc);
}

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

alias type = multi;
struct TestCase
{
  long n;
  @("n") long[] a;

  void solve(long i = -1)
  {
    auto m = a.fold!min(long.max);
    if (a.any!(ai => ai != m && ai != m + 1))
      writeln("NO");
    else
      writeln("YES");
  }
}

void main()
{
  type;
}


You are given an infinite periodic array a0, a1, ..., an - 1, ... with the period of length n. Formally, . A periodic subarray (l, s) (0 ≤ l < n, 1 ≤ s < n) of array a is an infinite periodic array with a period of length s that is a subsegment of array a, starting with position l.A periodic subarray (l, s) is superior, if when attaching it to the array a, starting from index l, any element of the subarray is larger than or equal to the corresponding element of array a. An example of attaching is given on the figure (top — infinite array a, bottom — its periodic subarray (l, s)):  Find the number of distinct pairs (l, s), corresponding to the superior periodic arrays.

The first line contains number n (1 ≤ n ≤ 2·105). The second line contains n numbers a0, a1, ..., an - 1 (1 ≤ ai ≤ 106), separated by a space.

Print a single integer — the sought number of pairs.

NoteIn the first sample the superior subarrays are (0, 1) and (3, 2).Subarray (0, 1) is superior, as a0 ≥ a0, a0 ≥ a1, a0 ≥ a2, a0 ≥ a3, a0 ≥ a0, ...Subarray (3, 2) is superior a3 ≥ a3, a0 ≥ a0, a3 ≥ a1, a0 ≥ a2, a3 ≥ a3, ...In the third sample any pair of (l, s) corresponds to a superior subarray as all the elements of an array are distinct.

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

void main ()
{
	int n;
	while (readf (" %s ", &n) > 0)
	{
		auto a = readln.split.map !(to !(int)).array;
		long res = 0;
		auto x = new int [n + 1];
		foreach (i; 0..n + 1)
		{
			x[i] = gcd (i, n);
		}

		foreach (d; 1..n)
		{
			if (n % d != 0)
			{
				continue;
			}

			debug {writeln ("d = ", d);}
			int j;

			auto s = new int [n + 1];
			s[0] = 0;
			foreach (i; 0..n)
			{
				s[i + 1] = s[i] + (x[i + 1] == d);
			}
			debug {writeln (s);}

			auto m = new int [d];
			j = 0;
			foreach (i; 0..n)
			{
				m[j] = max (m[j], a[i]);
				j++;
				if (j >= d)
				{
					j -= d;
				}
			}

			auto b = new bool [n];
			j = 0;
			foreach (i; 0..n)
			{
				b[i] = (a[i] == m[j]);
				j++;
				if (j >= d)
				{
					j -= d;
				}
			}
			debug {writeln (b);}
			b ~= b;

			int start = 0;
			foreach (int i, cur; b)
			{
				if (i + 1 - start >= n)
				{
					start++;
				}
				if (!cur)
				{
					start = i + 1;
				}
				else if (i >= n)
				{
					res += s[(i + 1 - start)];
					debug {writeln (start, " ", i, " ",
					    "+", s[(i + 1 - start)]);}
				}
			}
		}

		writeln (res);
	}
}

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

void main ()
{
	int n;
	while (readf (" %s ", &n) > 0)
	{
		auto a = readln.split.map !(to !(int)).array;
		long res = 0;
		foreach (d; 1..n)
		{
			if (n % d != 0)
			{
				continue;
			}

			debug {writeln ("d = ", d);}
			int j;

			auto m = new int [d];
			j = 0;
			foreach (i; 0..n)
			{
				m[j] = max (m[j], a[i]);
				j++;
				if (j >= d)
				{
					j -= d;
				}
			}

			auto b = new bool [n];
			j = 0;
			foreach (i; 0..n)
			{
				b[i] = (a[i] == m[j]);
				j++;
				if (j >= d)
				{
					j -= d;
				}
			}
			debug {writeln (b);}
			b ~= b;

			int start = 0;
			foreach (i, cur; b)
			{
				if (i + 1 - start >= n)
				{
					start++;
				}
				if (!cur)
				{
					start = i + 1;
				}
				else if (i >= n)
				{
					res += (i + 1 - start) / d;
					debug {writeln (start, " ", i, " ",
					    "+", (i + 1 - start) / d);}
				}
			}
		}

		writeln (res);
	}
}


In the Main Berland Bank n people stand in a queue at the cashier, everyone knows his/her height hi, and the heights of the other people in the queue. Each of them keeps in mind number ai — how many people who are taller than him/her and stand in queue in front of him.After a while the cashier has a lunch break and the people in the queue seat on the chairs in the waiting room in a random order.When the lunch break was over, it turned out that nobody can remember the exact order of the people in the queue, but everyone remembers his number ai.Your task is to restore the order in which the people stood in the queue if it is possible. There may be several acceptable orders, but you need to find any of them. Also, you need to print a possible set of numbers hi — the heights of people in the queue, so that the numbers ai are correct.

The first input line contains integer n — the number of people in the queue (1 ≤ n ≤ 3000). Then n lines contain descriptions of the people as "namei ai" (one description on one line), where namei is a non-empty string consisting of lowercase Latin letters whose length does not exceed 10 characters (the i-th person's name), ai is an integer (0 ≤ ai ≤ n - 1), that represents the number of people who are higher and stand in the queue in front of person i. It is guaranteed that all names are different.

If there's no acceptable order of the people in the queue, print the single line containing "-1" without the quotes. Otherwise, print in n lines the people as "namei hi", where hi is the integer from 1 to 109 (inclusive), the possible height of a man whose name is namei. Print the people in the order in which they stand in the queue, starting from the head of the queue and moving to its tail. Numbers hi are not necessarily unique.

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

immutable int MX = 3000;

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

    auto ps = new string[] (n);
    auto bigger = new int[][] (n+1);
    foreach (i; 0 .. n) {
        int a;
        readf("%s %s", &ps[i], &a);
        readln;

        bigger[a] ~= i;
    }

    debug { bigger[0 .. min(n, 5)].writeln; }

    int[] qord;
    auto hord = make!(SList!int);

    foreach (i; 0 .. n+1) {
        if (bigger[i].empty()) { continue; }

        if (qord.length < i) {
            writeln(-1);
            return;
        }

        foreach (e; bigger[i]) {
            qord ~= e;
            if (i == 0) { hord.insertFront(e); }
            else { hord.insertAfter(take(hord[], i), e); }
        }
    }

    debug { writeln(qord, ' ', hord[]); }

    int ch = MX;
    auto h = new int[] (n+1);
    foreach (e; hord) {
        h[e] = ch;
        ch--;
    }

    foreach (e; qord) {
        writeln(ps[e], ' ', h[e]);
    }
}


You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.

The first line contains a single positive integer n (2 ≤ n ≤ 105). The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.

Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).

NoteIn the first example the second point can be removed.In the second example there is no suitable for the condition point.In the third example any point can be removed.

import std.stdio;

void main() {
    // writeln("hello world!");
    // int[3] A;
    // foreach (i; 0 .. 3) {
    //     readf(" %s", &A[i]);
    // }
    // writeln(A);
    // write(A, "\n");
    // writefln("%(%s %)", A);
    // int t, s, x;
    int n;
    readf(" %s\n", &n);
    int left = 0;
    int right = 0;
    // int middle = 0;
    foreach (idx; 0 .. n) {
        int x, y;
        readf(" %s %s\n", &x, &y);
        if (x > 0) {
            ++right;
        }
        if (x < 0) {
            ++left;
        }
    }
    if (right < 2 || left < 2) {
        writeln("Yes");
    }
    else {
        writeln("No");
    }
    // readf(" %s %s %s\n", &t, &s, &x);
    // writeln(n, x, y);

}

import std.stdio;

void main() {
    // writeln("hello world!");
    // int[3] A;
    // foreach (i; 0 .. 3) {
    //     readf(" %s", &A[i]);
    // }
    // writeln(A);
    // write(A, "\n");
    // writefln("%(%s %)", A);
    // int t, s, x;
    int n;
    readf(" %s\n", &n);
    int left = 0;
    int right = 0;
    // int middle = 0;
    foreach (idx; 0 .. n) {
        int x, y;
        readf(" %s %s\n", &x, &y);
        if (x > 0) {
            ++right;
        }
        if (x < 0) {
            ++left;
        }
    }
    if (right == 1 || left == 1) {
        writeln("Yes");
    }
    else {
        writeln("No");
    }
    // readf(" %s %s %s\n", &t, &s, &x);
    // writeln(n, x, y);

}


It turns out that the meaning of life is a permutation $$$p_1, p_2, \ldots, p_n$$$ of the integers $$$1, 2, \ldots, n$$$ ($$$2 \leq n \leq 100$$$). Omkar, having created all life, knows this permutation, and will allow you to figure it out using some queries.A query consists of an array $$$a_1, a_2, \ldots, a_n$$$ of integers between $$$1$$$ and $$$n$$$. $$$a$$$ is not required to be a permutation. Omkar will first compute the pairwise sum of $$$a$$$ and $$$p$$$, meaning that he will compute an array $$$s$$$ where $$$s_j = p_j + a_j$$$ for all $$$j = 1, 2, \ldots, n$$$. Then, he will find the smallest index $$$k$$$ such that $$$s_k$$$ occurs more than once in $$$s$$$, and answer with $$$k$$$. If there is no such index $$$k$$$, then he will answer with $$$0$$$.You can perform at most $$$2n$$$ queries. Figure out the meaning of life $$$p$$$.

NoteIn the sample, the hidden permutation $$$p$$$ is $$$[3, 2, 1, 5, 4]$$$. Three queries were made.The first query is $$$a = [4, 4, 2, 3, 2]$$$. This yields $$$s = [3 + 4, 2 + 4, 1 + 2, 5 + 3, 4 + 2] = [7, 6, 3, 8, 6]$$$. $$$6$$$ is the only number that appears more than once, and it appears first at index $$$2$$$, making the answer to the query $$$2$$$.The second query is $$$a = [3, 5, 1, 5, 5]$$$. This yields $$$s = [3 + 3, 2 + 5, 1 + 1, 5 + 5, 4 + 5] = [6, 7, 2, 10, 9]$$$. There are no numbers that appear more than once here, so the answer to the query is $$$0$$$.The third query is $$$a = [5, 2, 4, 3, 1]$$$. This yields $$$s = [3 + 5, 2 + 2, 1 + 4, 5 + 3, 4 + 1] = [8, 4, 5, 8, 5]$$$. $$$5$$$ and $$$8$$$ both occur more than once here. $$$5$$$ first appears at index $$$3$$$, while $$$8$$$ first appears at index $$$1$$$, and $$$1 < 3$$$, making the answer to the query $$$1$$$.Note that the sample is only meant to provide an example of how the interaction works; it is not guaranteed that the above queries represent a correct strategy with which to determine the answer.

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

int main(string[] args)
{
    auto n = to!int(readln.strip);
    auto p = new int[n];
    auto q = new int[n];
    auto prev = new int[n];
    fill(prev, -1);
    foreach (i; 0 .. n)
    {
        q[i] = 2;
        foreach (j; 0 .. n) if (j != i) q[j] = 1;
        writeln("? ", join(map!(to!string)(q), " "));
        stdout.flush;
        auto ridx = to!int(readln.strip);
        if (ridx != 0 && ridx != i + 1) prev[ridx - 1] = i;
        q[i] = 1;
        foreach (j; 0 .. n) if (j != i) q[j] = 2;
        writeln("? ", join(map!(to!string)(q), " "));
        stdout.flush;
        ridx = to!int(readln.strip);
        if (ridx != 0 && ridx != i + 1) prev[i] = ridx - 1;
    }
    auto f = new bool[n];
    foreach (i; 0 .. n) if (prev[i] != -1) f[prev[i]] = true;
    auto idx = -1;
    foreach (i; 0 .. n) if (!f[i])
    {
        idx = i;
        break;
    }
    p[idx] = n;
    foreach (i; 0 .. n - 1)
    {
        p[prev[idx]] = p[idx] - 1;
        idx = prev[idx];
    }
    writeln("! ", join(map!(to!string)(p), " "));
    stdout.flush;
    return 0;
}

immutable multi = false;

void solve(int tc)
{
	int n = readInt!int;
	auto next = new int[](n+1);
	auto prev = new int[](n+1);
	int zero = 0;
	void get(int i)
	{
		int answer = void;
		write ("? ");
		foreach(j; 1 .. n+1)
		{
			write (int(i == j)+1, " ");
		}
		writeln;
		stdout.flush;
		answer = readInt!int;
		if (answer == 0)
		{
			next[i] = 0;
		}
		else
		{
			if (answer < i)
			{
				next[i] = answer;
				prev[answer] = i;
			}
			else
			{
				assert(answer == i);
			}
		}

		write ("? ");
		foreach(j; 1 .. n+1)
		{
			write (int(i != j)+1, " ");
		}
		writeln;
		stdout.flush;
		answer = readInt!int;
		if (answer == 0)
		{
			prev[i] = 0;
			zero = i;
		}
		else
		{
			if (answer < i)
			{
				prev[i] = answer;
				next[answer] = i;
			}
			else
			{
				assert(answer == i);
			}
		}
	}
	foreach(i; 1 .. n + 1) get(i);
	assert (zero != 0);
	auto p = new int[](n+1);
	int v = 1;
	int i = zero;
	while (i)
	{
		p[i] = v++;
		i = next[i];
	}
	write("! ");
	foreach(j; 1 .. n + 1) write (p[j], " ");
	writeln;
	stdout.flush;
}

//{{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
//}}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

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

void popChar()
{
	import core.stdc.stdio;
	currChar = getchar();
}

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

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
void writes(T...)(T t)
{
	static foreach(i, ti; t)
	{
		static if (isIterable!(T[i]))
		{
			foreach(e; ti)
			{
				write(e, " ");
			}
		}
	}
}
auto ra(V)()
{
	int n = readInt!int;
	return ma(n, readInt!V);
}
auto rt(V)()
{
	int n = readInt!int;
	int m = readInt!int;
	return ma(n, ma(m, readInt!V));
}
auto rbg()
{
	int n = readInt!int;
	int m = readInt!int;
	auto adj = new int[][](n);
	foreach(i; 0 .. m)
	{
		auto u = readInt!int - 1;
		auto v = readInt!int - 1;
		adj[u] ~= v;
		adj[v] ~= u;
	}
	return adj;
}
auto ma(V)(size_t n, lazy V v)
{
	auto arr = new V[](n);
	foreach(ref ai; arr) ai = v;
	return arr;
}
// }}}
// imports {{{
import std.stdio;
import std.algorithm;
import std.typecons;
import std.math;
import std.numeric;
import std.container;
import std.range;
import std.array;
import std.ascii;
// }}}

immutable multi = false;

void solve(int tc)
{
	int n = readInt!int;
	auto next = new int[](n+1);
	auto prev = new int[](n+1);
	int zero = 0;
	void get(int i)
	{
		int answer = void;
		write ("? ");
		foreach(j; 1 .. n+1)
		{
			write (int(i == j), " ");
		}
		writeln;
		stdout.flush;
		answer = readInt!int;
		if (answer == 0)
		{
			next[i] = 0;
		}
		else
		{
			if (answer < i)
			{
				next[i] = answer;
				prev[answer] = i;
			}
			else
			{
				assert(answer == i);
			}
		}

		write ("? ");
		foreach(j; 1 .. n+1)
		{
			write (int(i != j), " ");
		}
		writeln;
		stdout.flush;
		answer = readInt!int;
		if (answer == 0)
		{
			prev[i] = 0;
			zero = i;
		}
		else
		{
			if (answer < i)
			{
				prev[i] = answer;
				next[answer] = i;
			}
			else
			{
				assert(answer == i);
			}
		}
	}
	foreach(i; 1 .. n + 1) get(i);
	assert (zero != 0);
	auto p = new int[](n+1);
	int v = 1;
	int i = zero;
	while (i)
	{
		p[i] = v++;
		i = next[i];
	}
	write("! ");
	foreach(j; 1 .. n + 1) write (p[j], " ");
	writeln;
	stdout.flush;
}

//{{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
//}}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

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

void popChar()
{
	import core.stdc.stdio;
	currChar = getchar();
}

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

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
void writes(T...)(T t)
{
	static foreach(i, ti; t)
	{
		static if (isIterable!(T[i]))
		{
			foreach(e; ti)
			{
				write(e, " ");
			}
		}
	}
}
auto ra(V)()
{
	int n = readInt!int;
	return ma(n, readInt!V);
}
auto rt(V)()
{
	int n = readInt!int;
	int m = readInt!int;
	return ma(n, ma(m, readInt!V));
}
auto rbg()
{
	int n = readInt!int;
	int m = readInt!int;
	auto adj = new int[][](n);
	foreach(i; 0 .. m)
	{
		auto u = readInt!int - 1;
		auto v = readInt!int - 1;
		adj[u] ~= v;
		adj[v] ~= u;
	}
	return adj;
}
auto ma(V)(size_t n, lazy V v)
{
	auto arr = new V[](n);
	foreach(ref ai; arr) ai = v;
	return arr;
}
// }}}
// imports {{{
import std.stdio;
import std.algorithm;
import std.typecons;
import std.math;
import std.numeric;
import std.container;
import std.range;
import std.array;
import std.ascii;
// }}}

immutable multi = false;

void solve(int tc)
{
	int n = readInt!int;
	auto next = new int[](n+1);
	auto prev = new int[](n+1);
	int zero = 0;
	void get(int i)
	{
		int answer = void;
		write ("? ");
		foreach(j; 1 .. n+1)
		{
			write (int(i == j), " ");
		}
		writeln;
		stdout.flush;
		answer = readInt!int;
		if (answer == 0)
		{
			next[i] = 0;
		}
		else
		{
			if (answer < i)
			{
				next[i] = answer;
				prev[answer] = i;
			}
			else
			{
				assert(answer == i);
			}
		}

		write ("? ");
		foreach(j; 1 .. n+1)
		{
			write (int(i != j), " ");
		}
		writeln;
		stdout.flush;
		answer = readInt!int;
		if (answer == 0)
		{
			prev[i] = 0;
			zero = i;
		}
		else
		{
			if (answer < i)
			{
				prev[i] = answer;
				next[answer] = i;
			}
			else
			{
				assert(answer == i);
			}
		}
	}
	foreach(i; 1 .. n + 1) get(i);
	assert (zero != 0);
	auto p = new int[](n+1);
	int v = 1;
	int i = zero;
	while (i)
	{
		p[i] = v++;
		i = next[i];
	}
	debug writeln(p);
}

//{{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
//}}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

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

void popChar()
{
	import core.stdc.stdio;
	currChar = getchar();
}

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

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
void writes(T...)(T t)
{
	static foreach(i, ti; t)
	{
		static if (isIterable!(T[i]))
		{
			foreach(e; ti)
			{
				write(e, " ");
			}
		}
	}
}
auto ra(V)()
{
	int n = readInt!int;
	return ma(n, readInt!V);
}
auto rt(V)()
{
	int n = readInt!int;
	int m = readInt!int;
	return ma(n, ma(m, readInt!V));
}
auto rbg()
{
	int n = readInt!int;
	int m = readInt!int;
	auto adj = new int[][](n);
	foreach(i; 0 .. m)
	{
		auto u = readInt!int - 1;
		auto v = readInt!int - 1;
		adj[u] ~= v;
		adj[v] ~= u;
	}
	return adj;
}
auto ma(V)(size_t n, lazy V v)
{
	auto arr = new V[](n);
	foreach(ref ai; arr) ai = v;
	return arr;
}
// }}}
// imports {{{
import std.stdio;
import std.algorithm;
import std.typecons;
import std.math;
import std.numeric;
import std.container;
import std.range;
import std.array;
import std.ascii;
// }}}


You are given two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 100$$$). Represent the number $$$n$$$ as the sum of $$$k$$$ positive integers of the same parity (have the same remainder when divided by $$$2$$$).In other words, find $$$a_1, a_2, \ldots, a_k$$$ such that all $$$a_i>0$$$, $$$n = a_1 + a_2 + \ldots + a_k$$$ and either all $$$a_i$$$ are even or all $$$a_i$$$ are odd at the same time.If such a representation does not exist, then report it.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the input. Next, $$$t$$$ test cases are given, one per line. Each test case is two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 100$$$).

For each test case print:   YES and the required values $$$a_i$$$, if the answer exists (if there are several answers, print any of them);  NO if the answer does not exist.  The letters in the words YES and NO can be printed in any case.

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto nk = readln.split.to!(long[]);
        auto N = nk[0];
        auto K = nk[1];

        auto d = N / K;
        auto r = N % K;
        auto x = d+r;

        if (d == 0) {
            writeln("NO");
            continue;
        }

        if (d%2 != x%2) {
            if (d <= 1 || K%2 == 0) {
                writeln("NO");
                continue;
            }
            d -= 1;
            x += K-1;
        }

        long[] as;
        foreach (_k; 0..K-1) as ~= d;
        as ~= x;
        writeln("YES");
        writeln(as.to!(string[]).join(" "));
    }
}

// Author: Ivan Kazmenko (gassa@mail.ru)
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

int [] solve (int n, int k)
{
	foreach (v; [1, 2])
	{
		auto last = n - v * (k - 1);
		if (last > 0 && last % 2 == v % 2)
		{
			return v.repeat (k - 1).array ~ last;
		}
	}
	return null;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		auto res = solve (n, k);
		if (res is null)
		{
			writeln ("NO");
		}
		else
		{
			writeln ("YES");
			writefln !("%(%s %)") (res);
		}
	}
}

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

void calc(int n, int k) {
    int x = n - (k - 1);
    if (x > 0 && x % 2 == 1) {
        writeln("YES");
        auto ans = chain(repeat(1, k - 1), [n - (k - 1)]);
        writeln(ans.map!text.join(' '));
        return;
    }

    int y = n - (k - 1) * 2;
    if (y > 0 && y % 2 == 0) {
        writeln("YES");
        auto ans = chain(repeat(2, k - 1), [n - (k - 1) * 2]);
        writeln(ans.map!text.join(' '));
        return;
    }

    writeln("NO");
}

void main() {
    int t; scan(t);
    foreach (_; 0..t) {
        int n, k; scan(n, k);
        calc(n, k);
    }
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T=string)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readints = reads!int;

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

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto t = readNum!int;

  foreach(i; 0 .. t){
    auto nk = readNums!long;

    long a = nk[0] / nk[1];
    long b = nk[0] % nk[1];

    if(b % 2 == 0 && a > 0){
      writeln("YES");
      foreach(j; 0 .. nk[1] - 1){
        write(a, " ");
      }
      writeln(a+b);
    } else if((b+nk[1]) % 2 == 0 && a-1 > 0){
      writeln("YES");
      foreach(j; 0 .. nk[1] - 1){
        write(a-1, " ");
      }
      writeln(a-1+b+nk[1]);
    } 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; }
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) { x.modm(y.modpow(mod - 2)); }

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

		if (k % 2 == 0)
		{
			if (n % 2) continue;
			if (k > n) continue;
			foreach (i; 0..k-1)
			{
				ans[ti] ~= 1;
			}
			ans[ti] ~= n - (k-1);
		}
		else
		{
			if (n % 2)
			{
				if (k > n) continue;
				foreach (i; 0..k-1)
				{
					ans[ti] ~= 1;
				}
				ans[ti] ~= n - (k-1);
			}
			else
			{
				if (k*2 > n) continue;
				foreach (i; 0..k-1)
				{
					ans[ti] ~= 2;
				}
				ans[ti] ~= n - (k-1)*2;
			}
		}
	}

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

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto nk = readln.split.to!(long[]);
        auto N = nk[0];
        auto K = nk[1];

        auto d = N / K;
        auto r = N % K;
        auto x = d+r;

        if (d%2 != x%2) {
            if (d <= 1 || K%2 == 0) {
                writeln("NO");
                continue;
            }
            d -= 1;
            x += K-1;
        }

        long[] as;
        foreach (_k; 0..K-1) as ~= d;
        as ~= x;
        writeln("YES");
        writeln(as.to!(string[]).join(" "));
    }
}

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto nk = readln.split.to!(long[]);
        auto N = nk[0];
        auto K = nk[1];

        auto d = N / K;
        auto r = N % K;
        auto x = d+r;

        if (d%2 != x%2) {
            if (d == 1 || K%2 == 0) {
                writeln("NO");
                continue;
            }
            d -= 1;
            x += K-1;
        }

        long[] as;
        foreach (_k; 0..K-1) as ~= d;
        as ~= x;
        writeln("YES");
        writeln(as.to!(string[]).join(" "));
    }
}

// Author: Ivan Kazmenko (gassa@mail.ru)
// tries to build with 4 instead of 2
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

int [] solve (int n, int k)
{
	foreach (v; [1, 4])
	{
		auto last = n - v * (k - 1);
		if (last > 0 && last % 2 == v % 2)
		{
			return v.repeat (k - 1).array ~ last;
		}
	}
	return null;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		auto res = solve (n, k);
		if (res is null)
		{
			writeln ("NO");
		}
		else
		{
			writeln ("YES");
			writefln !("%(%s %)") (res);
		}
	}
}


Vasya has the sequence consisting of n integers. Vasya consider the pair of integers x and y k-interesting, if their binary representation differs from each other exactly in k bits. For example, if k = 2, the pair of integers x = 5 and y = 3 is k-interesting, because their binary representation x=101 and y=011 differs exactly in two bits.Vasya wants to know how many pairs of indexes (i, j) are in his sequence so that i < j and the pair of integers ai and aj is k-interesting. Your task is to help Vasya and determine this number.

The first line contains two integers n and k (2 ≤ n ≤ 105, 0 ≤ k ≤ 14) — the number of integers in Vasya's sequence and the number of bits in which integers in k-interesting pair should differ. The second line contains the sequence a1, a2, ..., an (0 ≤ ai ≤ 104), which Vasya has.

Print the number of pairs (i, j) so that i < j and the pair of integers ai and aj is k-interesting.

NoteIn the first test there are 4 k-interesting pairs:  (1, 3),  (1, 4),  (2, 3),  (2, 4). In the second test k = 0. Consequently, integers in any k-interesting pair should be equal to themselves. Thus, for the second test there are 6 k-interesting pairs:  (1, 5),  (1, 6),  (2, 3),  (2, 4),  (3, 4),  (5, 6).

import std.stdio;
import std.string;
import std.format;
import std.algorithm;
import std.math;
import core.bitop;

const int N = 100004;

long ans;
int n, k;
int[N] a;
int[] masks;
int[1 << 14] cnt;

void read() {
	readf(" %s %s", &n, &k);
	foreach (i; 0..n) {
		readf(" %s", &a[i]);
	}
}

void precalc() {
	foreach (mask; 0..1<<14) {
		if (_popcnt(mask) == k) {
			masks ~= mask;
		}
	}
}

void compute() {
	foreach (i; 0..n) {
		foreach (m; masks) {
			ans += cnt[a[i] ^ m];
		}
		cnt[a[i]]++;
	}
}

void solve() {
	read();
	precalc();
	compute();
	writeln(ans);
}

int main() {
	solve();

    return 0;
}

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

immutable int MX = 2 ^^ 14 - 1;

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

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

    auto cnt = new int[] (MX+1);

    arr.each!(x => ++cnt[x]);

    auto ans = 0L;
    foreach (i; 0 .. MX+1) {
        foreach (j; i .. MX+1) {
            if ((i ^ j).popcnt == k) {
                ans += i == j ?
                    cnt[i].to!long * (cnt[i]-1) / 2
                    : cnt[i].to!long * cnt[j];
            }
        }
    }

    ans.writeln;
}

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

immutable int MX = 2 ^^ 14 - 1;

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

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

    auto cnt = new int[] (MX+1);

    arr.each!(x => ++cnt[x]);

    auto ans = 0L;
    foreach (i; 0 .. MX+1) {
        foreach (j; i .. MX+1) {
            if ((i ^ j).popcnt != k) { ans += cnt[i].to!long * cnt[j]; }
        }
    }

    ans.writeln;
}

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

immutable int MX = 2 ^^ 14 - 1;

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

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

    auto cnt = new int[] (MX+1);

    arr.each!(x => ++cnt[x]);

    auto ans = 0L;
    foreach (i; 0 .. MX+1) {
        foreach (j; i .. MX+1) {
            if ((i ^ j).popcnt == k) { ans += cnt[i].to!long * cnt[j]; }
        }
    }

    ans.writeln;
}