Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described).This priority factor will be affected by three types of actions:   1. "X posted on Y's wall" (15 points),  2. "X commented on Y's post" (10 points),  3. "X likes Y's post" (5 points). X and Y will be two distinct names. And each action will increase the priority factor between X and Y (and vice versa) by the above value of points (the priority factor between X and Y is the same as the priority factor between Y and X).You will be given n actions with the above format (without the action number and the number of points), and you have to print all the distinct names in these actions sorted according to the priority factor with you.

The first line contains your name. The second line contains an integer n, which is the number of actions (1 ≤ n ≤ 100). Then n lines follow, it is guaranteed that each one contains exactly 1 action in the format given above. There is exactly one space between each two words in a line, and there are no extra spaces. All the letters are lowercase. All names in the input will consist of at least 1 letter and at most 10 small Latin letters.

Print m lines, where m is the number of distinct names in the input (excluding yourself). Each line should contain just 1 name. The names should be sorted according to the priority factor with you in the descending order (the highest priority factor should come first). If two or more names have the same priority factor, print them in the alphabetical (lexicographical) order. Note, that you should output all the names that are present in the input data (excluding yourself), even if that person has a zero priority factor. The lexicographical comparison is performed by the standard "<" operator in modern programming languages. The line a is lexicographically smaller than the line b, if either a is the prefix of b, or if exists such an i (1 ≤ i ≤ min(|a|, |b|)), that ai < bi, and for any j (1 ≤ j < i) aj = bj, where |a| and |b| stand for the lengths of strings a and b correspondently.

ahmed
3
ahmed posted on fatma's wall
fatma commented on ahmed's post
mona likes ahmed's post

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,
	std.stdio,std.bitmanip;
import core.stdc.stdio : freopen;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias boyerMooreFinder strfind;
alias make_pair mp;
alias binary_search bins;
alias pair(X,Y)=Tuple!(X,q{fi},Y,q{se});
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
immutable int mod=10^^9+7;
immutable long hashmod=10L^^18+3;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	@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;
	}
}
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) if(isRandomAccessRange!X)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n) if(hasSlicing!X)
{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 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.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------
void main()
{
	/*int n;
	loop:while(read(&n))
	{

	}*/
	string name=readln.strip;
	int n;
	read(&n);
	auto r1=ctRegex!(`(\w+) posted on (\w+)\'s wall`),
		r2=ctRegex!(`(\w+) commented on (\w+)\'s post`),
		r3=ctRegex!(`(\w+) likes (\w+)\'s post`);
	int[string] q;
	foreach(i;0..n)
	{
		auto s=readln.strip;
		if(auto c=matchFirst(s,r1))
		{
			if(c[1]==name)
			{
				q[c[2]]+=15;
			}
			else if(c[2]==name)
			{
				q[c[1]]+=15;
			}
			else
			{
				q[c[1]]+=0;
				q[c[2]]+=0;
			}
		}
		else if(auto c=matchFirst(s,r2))
		{
			if(c[1]==name)
			{
				q[c[2]]+=10;
			}
			else if(c[2]==name)
			{
				q[c[1]]+=10;
			}
			else
			{
				q[c[1]]+=0;
				q[c[2]]+=0;
			}
		}
		else if(auto c=matchFirst(s,r3))
		{
			if(c[1]==name)
			{
				q[c[2]]+=5;
			}
			else if(c[2]==name)
			{
				q[c[1]]+=5;
			}
			else
			{
				q[c[1]]+=0;
				q[c[2]]+=0;
			}
		}
	}
	pair!(int,string) a[];
	foreach(i,j;q)a~=mp(j,i);
	bool cmp(ref const pair!(int,string) x,ref const pair!(int,string) y)
	{
		return x.fi>y.fi || (x.fi==y.fi && x.se<y.se);
	}
	sort!cmp(a);
	foreach(i;a)writeln(i.se);
}

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,
	std.stdio,std.bitmanip;
import core.stdc.stdio : freopen;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias boyerMooreFinder strfind;
alias make_pair mp;
alias binary_search bins;
alias pair(X,Y)=Tuple!(X,q{fi},Y,q{se});
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
immutable int mod=10^^9+7;
immutable long hashmod=10L^^18+3;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	@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;
	}
}
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) if(isRandomAccessRange!X)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n) if(hasSlicing!X)
{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 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.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------
void main()
{
	/*int n;
	loop:while(read(&n))
	{

	}*/
	string name=readln.strip;
	int n;
	read(&n);
	auto r1=regex(`(\w+) posted on (\w+)\'s wall`),
		r2=regex(`(\w+) commented on (\w+)\'s post`),
		r3=regex(`(\w+) likes (\w+)\'s post`);
	int[string] q;
	foreach(i;0..n)
	{
		auto s=readln.strip;
		if(auto c=matchFirst(s,r1))
		{
			if(c[1]==name)
			{
				q[c[2]]+=15;
			}
			else if(c[2]==name)
			{
				q[c[1]]+=15;
			}
			else
			{
				q[c[1]]+=0;
				q[c[2]]+=0;
			}
		}
		else if(auto c=matchFirst(s,r2))
		{
			if(c[1]==name)
			{
				q[c[2]]+=10;
			}
			else if(c[2]==name)
			{
				q[c[1]]+=10;
			}
			else
			{
				q[c[1]]+=0;
				q[c[2]]+=0;
			}
		}
		else if(auto c=matchFirst(s,r3))
		{
			if(c[1]==name)
			{
				q[c[2]]+=5;
			}
			else if(c[2]==name)
			{
				q[c[1]]+=5;
			}
			else
			{
				q[c[1]]+=0;
				q[c[2]]+=0;
			}
		}
	}
	pair!(int,string) a[];
	foreach(i,j;q)a~=mp(j,i);
	bool cmp(ref const pair!(int,string) x,ref const pair!(int,string) y)
	{
		return x.fi>y.fi || (x.fi==y.fi && x.se<y.se);
	}
	sort!cmp(a);
	foreach(i;a)writeln(i.se);
}


In one one-dimensional world there are n platforms. Platform with index k (platforms are numbered from 1) is a segment with coordinates [(k - 1)m, (k - 1)m + l], and l < m. Grasshopper Bob starts to jump along the platforms from point 0, with each jump he moves exactly d units right. Find out the coordinate of the point, where Bob will fall down. The grasshopper falls down, if he finds himself not on the platform, but if he finds himself on the edge of the platform, he doesn't fall down.

The first input line contains 4 integer numbers n, d, m, l (1 ≤ n, d, m, l ≤ 106, l < m) — respectively: amount of platforms, length of the grasshopper Bob's jump, and numbers m and l needed to find coordinates of the k-th platform: [(k - 1)m, (k - 1)m + l].

Output the coordinates of the point, where the grosshopper will fall down. Don't forget that if Bob finds himself on the platform edge, he doesn't fall down.

import core.thread;
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;

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

//	chmin/chmax
void chmin(T)(ref T t, const T f) { if (t > f) t = f; }
void chmax(T)(ref T t, const T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; }
}
auto pair(S, T)(S x, T y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(T[] as, bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

//	min x >= 0 s.t. l <= ((a x) mod m) <= r
//	m > 0, a >= 0
/*
	take k s.t. a (k - 1) < l <= a k
	if a (k - 1) < l <= r < a k:
		l <= a x - m y <= r
		==> 0 < a k - r <= m y - a (x - k) <= a k - l < a
		x >= k ==> y >= (a x - r) / m >= (a k - r) / m > 0
		y >= 0 ==> x >= (m y + l) / a >= 0
*/
long modRange(long m, long a, long l, long r) {
	chmax(l, 0L);
	chmin(r, m - 1);
	if (l > r) return -1;
	a %= m;
	if (a == 0) return (l > 0) ? -1 : 0;
	const k = (l + a - 1) / a;
	if (a * k <= r) return k;
	const y = modRange(a, m, a * k - r, a * k - l);
	return (y == -1) ? -1 : ((m * y + r) / a);
}
long N, D, M, L;

void main(string[] args) {
	try {
	for (; ; ) {
		N = readLong;
		D = readLong;
		M = readLong;
		L = readLong;

		const rightEnd = (N - 1) * M + L;
		long ans = D * (rightEnd / D + 1);

		const res = modRange(M, D, L + 1, M - 1);
		if (res != -1) {
			chmin(ans, D * res);
		}

		writeln(ans);

	}
	} catch (EOFException) {}
}


After defeating a Blacklist Rival, you get a chance to draw $$$1$$$ reward slip out of $$$x$$$ hidden valid slips. Initially, $$$x=3$$$ and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are $$$c$$$, $$$m$$$, and $$$p$$$, respectively. There is also a volatility factor $$$v$$$. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the $$$x$$$ valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was $$$a$$$. Then,  If the item was a Pink Slip, the quest is over, and you will not play any more races.  Otherwise,   If $$$a\leq v$$$, the probability of the item drawn becomes $$$0$$$ and the item is no longer a valid item for all the further draws, reducing $$$x$$$ by $$$1$$$. Moreover, the reduced probability $$$a$$$ is distributed equally among the other remaining valid items.  If $$$a > v$$$, the probability of the item drawn reduces by $$$v$$$ and the reduced probability is distributed equally among the other valid items.  For example,  If $$$(c,m,p)=(0.2,0.1,0.7)$$$ and $$$v=0.1$$$, after drawing Cash, the new probabilities will be $$$(0.1,0.15,0.75)$$$.  If $$$(c,m,p)=(0.1,0.2,0.7)$$$ and $$$v=0.2$$$, after drawing Cash, the new probabilities will be $$$(Invalid,0.25,0.75)$$$.  If $$$(c,m,p)=(0.2,Invalid,0.8)$$$ and $$$v=0.1$$$, after drawing Cash, the new probabilities will be $$$(0.1,Invalid,0.9)$$$.  If $$$(c,m,p)=(0.1,Invalid,0.9)$$$ and $$$v=0.2$$$, after drawing Cash, the new probabilities will be $$$(Invalid,Invalid,1.0)$$$. You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.

The first line of input contains a single integer $$$t$$$ ($$$1\leq t\leq 10$$$)  — the number of test cases. The first and the only line of each test case contains four real numbers $$$c$$$, $$$m$$$, $$$p$$$ and $$$v$$$ ($$$0 < c,m,p < 1$$$, $$$c+m+p=1$$$, $$$0.1\leq v\leq 0.9$$$). Additionally, it is guaranteed that each of $$$c$$$, $$$m$$$, $$$p$$$ and $$$v$$$ have at most $$$4$$$ decimal places.

For each test case, output a single line containing a single real number — the expected number of races that you must play in order to draw a Pink Slip. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$$$.

NoteFor the first test case, the possible drawing sequences are:   P with a probability of $$$0.6$$$;  CP with a probability of $$$0.2\cdot 0.7 = 0.14$$$;  CMP with a probability of $$$0.2\cdot 0.3\cdot 0.9 = 0.054$$$;  CMMP with a probability of $$$0.2\cdot 0.3\cdot 0.1\cdot 1 = 0.006$$$;  MP with a probability of $$$0.2\cdot 0.7 = 0.14$$$;  MCP with a probability of $$$0.2\cdot 0.3\cdot 0.9 = 0.054$$$;  MCCP with a probability of $$$0.2\cdot 0.3\cdot 0.1\cdot 1 = 0.006$$$.  So, the expected number of races is equal to $$$1\cdot 0.6 + 2\cdot 0.14 + 3\cdot 0.054 + 4\cdot 0.006 + 2\cdot 0.14 + 3\cdot 0.054 + 4\cdot 0.006 = 1.532$$$.For the second test case, the possible drawing sequences are:   P with a probability of $$$0.4$$$;  CP with a probability of $$$0.4\cdot 0.6 = 0.24$$$;  CMP with a probability of $$$0.4\cdot 0.4\cdot 1 = 0.16$$$;  MP with a probability of $$$0.2\cdot 0.5 = 0.1$$$;  MCP with a probability of $$$0.2\cdot 0.5\cdot 1 = 0.1$$$. So, the expected number of races is equal to $$$1\cdot 0.4 + 2\cdot 0.24 + 3\cdot 0.16 + 2\cdot 0.1 + 3\cdot 0.1 = 1.86$$$.

// code by cutx64

module main;

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

void main() {

  immutable(int) S = 4 * 10 ^^ 4;
  real calc(int a, int p, int v) {
    if (a > v) {
      return 1 + calc(a - v, p + v, v) * a / S;
    }
    else {
      return 1 + cast(real)(a) / S;
    }
  }
  real calc2(int a, int b, int p, int v) {
    real aa, bb;
    if (a > v) {
      aa = calc2(a - v, b + v / 2, p + v / 2, v);
    }
    else {
      aa = calc(b + a / 2, p + a / 2, v);
    }
    if (b > v) {
      bb = calc2(a + v / 2, b - v, p + v / 2, v);
    }
    else {
      bb = calc(a + b / 2, p + b / 2, v);
    }
    aa = aa * a / S;
    bb = bb * b / S;
    return 1 + aa + bb;
  }

  int tests; readf!"%s\n"(tests);
  while(tests--) {
    real a, b, p, v;
    readf!"%s %s %s %s\n"(a, b, p, v);
    writefln!"%.12f"(calc2(round(a * S).to!int, round(b * S).to!int, round(p * S).to!int, round(v * S).to!int));
  }

} // main


You are given three sequences: $$$a_1, a_2, \ldots, a_n$$$; $$$b_1, b_2, \ldots, b_n$$$; $$$c_1, c_2, \ldots, c_n$$$.For each $$$i$$$, $$$a_i \neq b_i$$$, $$$a_i \neq c_i$$$, $$$b_i \neq c_i$$$.Find a sequence $$$p_1, p_2, \ldots, p_n$$$, that satisfy the following conditions: $$$p_i \in \{a_i, b_i, c_i\}$$$ $$$p_i \neq p_{(i \mod n) + 1}$$$.In other words, for each element, you need to choose one of the three possible values, such that no two adjacent elements (where we consider elements $$$i,i+1$$$ adjacent for $$$i<n$$$ and also elements $$$1$$$ and $$$n$$$) will have equal value.It can be proved that in the given constraints solution always exists. You don't need to minimize/maximize anything, you need to find any proper sequence.

The first line of input contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$): the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$3 \leq n \leq 100$$$): the number of elements in the given sequences. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$). The third line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \leq b_i \leq 100$$$). The fourth line contains $$$n$$$ integers $$$c_1, c_2, \ldots, c_n$$$ ($$$1 \leq c_i \leq 100$$$). It is guaranteed that $$$a_i \neq b_i$$$, $$$a_i \neq c_i$$$, $$$b_i \neq c_i$$$ for all $$$i$$$.

For each test case, print $$$n$$$ integers: $$$p_1, p_2, \ldots, p_n$$$ ($$$p_i \in \{a_i, b_i, c_i\}$$$, $$$p_i \neq p_{i \mod n + 1}$$$). If there are several solutions, you can print any.

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, 3);
        foreach (j; 0 .. 3) {
          foreach (i; 0 .. N) {
            A[i][j] = readInt();
          }
        }

        auto ans = new int[N];
        foreach (i; 0 .. N) {
          foreach (j; 0 .. 3) {
            bool ok = true;
            if (i >= 1) {
              ok = ok && (ans[i - 1] != A[i][j]);
            }
            if (i == N - 1) {
              ok = ok && (ans[0] != A[i][j]);
            }
            if (ok) {
              ans[i] = A[i][j];
              break;
            }
          }
        }
        foreach (i; 0 .. N) {
          if (i > 0) write(" ");
          write(ans[i]);
        }
        writeln;
      }
    }
  } catch (EOFException e) {
  }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new int[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto abc = new int[][](3);
		abc[0] = RDA!int;
		abc[1] = RDA!int;
		abc[2] = RDA!int;

		int pos;
		int last = -1;
		foreach (i; 0..n)
		{
			if (last == abc[pos][i])
				pos = (pos+1) % 3;

			ans[ti] ~= abc[pos][i];
			last = ans[ti][$-1];
		}
		if (ans[ti][0] == ans[ti][$-1])
		{
			pos = (pos+1) % 3;
			ans[ti][$-1] = abc[pos][$-1];
		}
		if (ans[ti][$-2] == ans[ti][$-1])
		{
			pos = (pos+1) % 3;
			ans[ti][$-1] = abc[pos][$-1];
		}
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new int[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto abc = new int[][](3);
		abc[0] = RDA!int;
		abc[1] = RDA!int;
		abc[2] = RDA!int;

		int pos;
		int last = -1;
		foreach (i; 0..n)
		{
			if (last == abc[pos][i])
				pos = (pos+1) % 3;

			ans[ti] ~= abc[pos][i];
			last = ans[ti][$-1];
		}
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new int[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto abc = new int[][](3);
		abc[0] = RDA!int;
		abc[1] = RDA!int;
		abc[2] = RDA!int;

		int pos;
		int last = -1;
		foreach (i; 0..n)
		{
			if (last == abc[pos][i])
				pos = (pos+1) % 3;

			ans[ti] ~= abc[pos][i];
			last = ans[ti][$-1];
		}
		if (ans[ti][0] == ans[ti][$-1])
		{
			pos = (pos+1) % 3;
			ans[ti][$-1] = abc[pos][$-1];
		}
	}

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


Alice and Bob play a game. They have a binary string $$$s$$$ (a string such that each character in it is either $$$0$$$ or $$$1$$$). Alice moves first, then Bob, then Alice again, and so on.During their move, the player can choose any number (not less than one) of consecutive equal characters in $$$s$$$ and delete them.For example, if the string is $$$10110$$$, there are $$$6$$$ possible moves (deleted characters are bold):  $$$\textbf{1}0110 \to 0110$$$;  $$$1\textbf{0}110 \to 1110$$$;  $$$10\textbf{1}10 \to 1010$$$;  $$$101\textbf{1}0 \to 1010$$$;  $$$10\textbf{11}0 \to 100$$$;  $$$1011\textbf{0} \to 1011$$$. After the characters are removed, the characters to the left and to the right of the removed block become adjacent. I. e. the following sequence of moves is valid: $$$10\textbf{11}0 \to 1\textbf{00} \to 1$$$.The game ends when the string becomes empty, and the score of each player is the number of $$$1$$$-characters deleted by them.Each player wants to maximize their score. Calculate the resulting score of Alice.

The first line contains one integer $$$T$$$ ($$$1 \le T \le 500$$$) — the number of test cases. Each test case contains exactly one line containing a binary string $$$s$$$ ($$$1 \le |s| \le 100$$$).

For each test case, print one integer — the resulting score of Alice (the number of $$$1$$$-characters deleted by her).

NoteQuestions about the optimal strategy will be ignored.

// Vicfred
// https://codeforces.com/contest/1398/problem/B
// greedy
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--) {
        string s = readln.strip;

        int[] moves;
        for(int i = 0; i < s.length; ++i) {
            if(s[i] == '1') {
                int j = i;
                while(j + 1 < s.length && s[j + 1] == '1')
                    ++j;
                moves ~= j - i + 1;
                i = j;
            }
        }

        moves.sort!("a > b");

        int ans = 0;
        for(int i = 0; i < moves.length; i += 2)
            ans += moves[i];
        ans.writeln;
    }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip;
		auto g = s.group.array;
		auto sizes = g.filter !(q{a[0] == '1'}).map !(q{a[1]}).array;
		sort !(q{a > b}) (sizes);
		writeln (sizes.stride (2).sum);
	}
}

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 s = RD!string;
		int cnt;
		int[] list;
		foreach (i; 0..s.length)
		{
			if (s[i] == '1')
			{
				++cnt;
			}
			else
			{
				if (cnt != 0)
					list ~= cnt;
				cnt = 0;
			}
		}
		if (cnt != 0)
			list ~= cnt;
		list.sort!"a > b";
		int i;
		while (!list.empty)
		{
			if (i % 2 == 0)
				ans[ti] += list.front;
			list.popFront;
			++i;
		}
	}

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


Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC. For that, he asked to give him the statistics of the performance of the SMSC for some period of time. In the end, Polycarpus got a list of n tasks that went to the SMSC of the corporation. Each task was described by the time it was received by the SMSC and the number of text messages to send. More formally, the i-th task was described by two integers ti and ci — the receiving time (the second) and the number of the text messages, correspondingly.Polycarpus knows that the SMSC cannot send more than one text message per second. The SMSC uses a queue to organize its work. Consider a time moment x, the SMSC work at that moment as follows:  If at the time moment x the queue is not empty, then SMSC sends one message from the queue (SMSC gets the message from the head of the queue). Otherwise it doesn't send messages at the time moment x.  If at the time moment x SMSC receives a task, then it adds to the queue all the messages from this task (SMSC adds messages to the tail of the queue). Note, that the messages from the task cannot be send at time moment x. That's because the decision about sending message or not is made at point 1 before adding these messages to the queue. Given the information about all n tasks, Polycarpus wants to count two values: the time when the last text message was sent and the maximum size of the queue at some time. Help him count these two characteristics he needs to evaluate the efficiency of the SMSC.

The first line contains a single integer n (1 ≤ n ≤ 103) — the number of tasks of the SMSC. Next n lines contain the tasks' descriptions: the i-th line contains two space-separated integers ti and ci (1 ≤ ti, ci ≤ 106) — the time (the second) when the i-th task was received and the number of messages to send, correspondingly. It is guaranteed that all tasks were received at different moments of time. It is guaranteed that the tasks are sorted in the chronological order, that is, ti < ti + 1 for all integer i (1 ≤ i < n).

In a single line print two space-separated integers — the time when the last text message was sent and the maximum queue size at a certain moment of time.

NoteIn the first test sample:   second 1: the first message has appeared in the queue, the queue's size is 1;  second 2: the first message is sent, the second message has been received, the queue's size is 1;  second 3: the second message is sent, the queue's size is 0, Thus, the maximum size of the queue is 1, the last message was sent at the second 3.

import std.stdio;

void main()
{
    uint numTasks;
    readf("%d\n", &numTasks);

    uint time, numMessages;
    uint queue, maxQueue = 0;
    uint lastTime;

    foreach(i;0..numTasks)
    {
        readf("%d %d\n", &time, &numMessages);
        if (queue > 0)
        {
            uint timeDiff = time - lastTime;
            if (queue > timeDiff)
            {
                queue -= timeDiff;
            }
            else
            {
                queue = 0;
            }
        }
        lastTime = time;
        queue += numMessages;
        if (queue > maxQueue) maxQueue = queue;
    }
    writeln(lastTime + queue, " ", maxQueue);
}

import std.algorithm;
import std.container;
import std.exception;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		int m = 0, c = 0, t = 0;
		foreach (i; 0..n)
		{
			int r, k;
			readf (" %s %s", &r, &k);
			c = max (0, c - (r - t));
			c += k;
			m = max (m, c);
			t = r;
		}
		writefln ("%s %s", t + c, m);
	}
}

module sigod.codeforces.p292A;

import std.stdio;

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

	int[] t = new int[n];
	int[] c = new int[n];

	foreach (i; 0 .. n) {
		stdin.readf(" %s %s", &t[i], &c[i]);
	}

	int x, y;
	solve(t, c, x, y);

	stdout.writeln(x, " ", y);
}

void solve(int[] time, int[] count, out int last_send_time, out int max_queue_size)
{
	max_queue_size = int.min;

	int queue_size = 0;
	int current_time = 0;

	foreach (i; 0 .. time.length) {
		queue_size = max(queue_size - (time[i] - current_time), 0) + count[i];

		current_time = time[i];

		if (max_queue_size < queue_size) max_queue_size = queue_size;

		version (unittest) {
			stdout.writeln("queue_size: ", queue_size,
				"; current_time: ", current_time);
		}
	}

	last_send_time = current_time + queue_size;

	if (max_queue_size < queue_size) max_queue_size = queue_size;
}

unittest {
	import std.string;

	int x, y;

	solve([1, 2], [1, 1], x, y);
	assert(x == 3 && y == 1, format("x: %s, y: %s", x, y));

	solve([1000000], [10], x, y);
	assert(x == 1000010 && y == 10, format("x: %s, y: %s", x, y));

	solve([3, 4, 5], [3, 3, 3], x, y);
	assert(x == 12 && y == 7, format("x: %s, y: %s", x, y));
}

private pure
int max(int a, int b)
{
	if (a > b) return a;
	else return b;
}


Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.His farm is presented by a rectangle grid with $$$r$$$ rows and $$$c$$$ columns. Some of these cells contain rice, others are empty. $$$k$$$ chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:  Each cell of the farm is assigned to exactly one chicken.  Each chicken is assigned at least one cell.  The set of cells assigned to every chicken forms a connected area. More precisely, if two cells $$$(x, y)$$$ and $$$(u, v)$$$ are assigned to the same chicken, this chicken is able to walk from $$$(x, y)$$$ to $$$(u, v)$$$ by passing only its cells and moving from each cell to another cell sharing a side. Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.

Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 2 \cdot 10^4$$$). Description of the test cases follows. The first line of each test case contains three integers $$$r$$$, $$$c$$$ and $$$k$$$ ($$$1 \leq r, c \leq 100, 1 \leq k \leq 62$$$), representing the size of Long's farm and the number of chickens Long has.  Each of the next $$$r$$$ lines contains $$$c$$$ characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm. It is guaranteed that the sum of $$$r \cdot c$$$ over all test cases does not exceed $$$2 \cdot 10^4$$$.

For each test case, print $$$r$$$ lines with $$$c$$$ characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens. If there are multiple optimal answers, print any.

4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR

11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789

NoteThese pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is $$$0$$$.In the second test case, there are $$$4$$$ chickens with $$$3$$$ cells of rice, and $$$2$$$ chickens with $$$2$$$ cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is $$$3 - 2 = 1$$$.In the third test case, each chicken has $$$3$$$ cells with rice. In the last test case, since there are $$$62$$$ chicken with exactly $$$62$$$ cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way.

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

void main ()
{
	string names;
	foreach (c; 'a'..'z' + 1)
	{
		names ~= cast (char) (c);
	}
	foreach (c; 'A'..'Z' + 1)
	{
		names ~= cast (char) (c);
	}
	foreach (c; '0'..'9' + 1)
	{
		names ~= cast (char) (c);
	}
	debug {writeln (names);}

	int tests;
	readf !(" %s") (tests);
	foreach (test; 0..tests)
	{
		int r, c, k;
		readf !(" %s %s %s") (r, c, k);
		readln;

		auto board = new string [r];
		int num = 0;
		foreach (row; 0..r)
		{
			board[row] = readln.strip;
			num += board[row].count ('R');
		}
		int part = num / k;
		auto give = new int [k];
		foreach (i; 0..num)
		{
			give[i % k] += 1;
		}

		auto ans = new char [] [] (r, c);
		int cur = 0;
		int team = 0;
		foreach (row; 0..r)
		{
			foreach (col0; 0..c)
			{
				auto col = (row & 1) ? col0 : c - col0 - 1;
				ans[row][col] = names[team];
				debug {writeln (row, " ", col, " ", team);}
				cur += (board[row][col] == 'R');
				if (cur >= give[team])
				{
					cur = 0;
					team = min (team + 1, k - 1);
				}
			}
		}
		writefln !("%-(%s\n%)") (ans);
	}
}

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;

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

void solve(){
	int t = rint;
	foreach(_; 0 .. t){
		int r = rint, c = rint, k = rint;
		bool[][] uf;
		char[][] ansf = new char[][](r, c);
		foreach(i; 0 .. r) uf ~= readln.chomp.to!(char[]).map!(c => c == 'R').array;

		int sum;
		foreach(i; 0 .. r) foreach(j; 0 .. c) if(uf[i][j]) sum += 1;

		int h = 0;
		char[] symbols = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" ~
		"abcdefghijklmnopqrstuvwxyz" ~ "0123456789").to!(char[]);
		int cnt;
		int[] quota;
		foreach(x; 0 .. k){
			if(x < sum % k) quota ~= sum / k + 1;
			else quota ~= sum / k;
		}
		log("quota:", quota);
		foreach(i; 0 .. r){
			if(i % 2 == 0) foreach(j; 0 .. c){
				if(uf[i][j]) cnt += 1;
				if(cnt > quota[h]) cnt = 1, h += 1;
				ansf[i][j] = symbols[h];
			}
			else foreach_reverse(j; 0 .. c){
				if(uf[i][j]) cnt += 1;
				if(cnt > quota[h]) cnt = 1, h += 1;
				ansf[i][j] = symbols[h];
			}
		}
		foreach(i; 0 .. r) ansf[i].writeln;
	}

}

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

char tr(int x) {
  if (x < 10) return cast(char)('0' + x);
  if (x < 36) return cast(char)('A' + (x - 10));
  if (x < 62) return cast(char)('a' + (x - 36));
  assert(false);
}

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const M = readInt();
        const N = readInt();
        const K = readInt();
        auto A = new string[M];
        foreach (x; 0 .. M) {
          A[x] = readToken();
        }

        int rice;
        foreach (x; 0 .. M) {
          rice += A[x].count('R');
        }
        const q = rice / K, r = rice % K;

        alias Pt = Tuple!(int, "x", int, "y");
        Pt[] ps;
        foreach (x; 0 .. M) {
          if (x % 2 == 0) {
            foreach (y; 0 .. N) {
              ps ~= Pt(x, y);
            }
          } else {
            foreach_reverse (y; 0 .. N) {
              ps ~= Pt(x, y);
            }
          }
        }
        const psLen = cast(int)(ps.length);

        auto ans = new int[][](M, N);
        int pos;
        foreach (k; 0 .. K) {
          int need = q + ((k < r) ? 1 : 0);
          int cnt;
          for (; cnt < need; ++pos) {
            const x = ps[pos].x, y = ps[pos].y;
            ans[x][y] = k;
            if (A[x][y] == 'R') {
              ++cnt;
            }
          }
        }
        for (; pos < psLen; ++pos) {
          const x = ps[pos].x, y = ps[pos].y;
          ans[x][y] = K - 1;
        }

        foreach (x; 0 .. M) {
          foreach (y; 0 .. N) {
            write(tr(ans[x][y]));
          }
          writeln();
        }
      }
    }
  } catch (EOFException e) {
  }
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.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; }

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 str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	auto T = RD!int;
	auto ans = new char[][][](T);
	foreach (i; 0..T)
	{
		auto r = RD!int;
		auto c = RD!int;
		auto k = RD!int;
		auto s = new string[](r);
		foreach (j; 0..r)
			s[j] = RD!string;
		ans[i] = new char[][](r, c);

		int rice;
		foreach (y; 0..r)
		{
			foreach (x; 0..c)
			{
				if (s[y][x] == 'R')
					++rice;
			}
		}
		auto cnt1 = rice / k;
		auto cnt2 = rice % k;
		int cnt;
		int num;
		foreach (y; 0..r)
		{
			if (y % 2 == 0)
			{
				foreach (x; 0..c)
				{
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt > cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 1;
						}
					}
					ans[i][y][x] = str[num];
				}
			}
			else
			{
				foreach_reverse (x; 0..c)
				{
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt > cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 1;
						}
					}
					ans[i][y][x] = str[num];
				}
			}
		}
	}

	foreach (e; ans)
	{
		foreach (y; 0..e.length)
		{
			writeln(e[y]);
		}
	}

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

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

void solve(){
	int t = rint;
	foreach(_; 0 .. t){
		int r = rint, c = rint, k = rint;
		bool[][] uf;
		char[][] ansf = new char[][](r, c);
		foreach(i; 0 .. r) uf ~= readln.chomp.to!(char[]).map!(c => c == 'R').array;

		int sum;
		foreach(i; 0 .. r) foreach(j; 0 .. c) if(uf[i][j]) sum += 1;

		int h = 0;
		char[] symbols = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" ~
		"abcdefghijklmnopqrstuvwxyz" ~ "0123456789").to!(char[]);
		int cnt;
		int[] quota;
		foreach(x; 0 .. k){
			if(x < sum % k) quota ~= sum / k + 1;
			else quota ~= sum / k;
		}
		foreach(i; 0 .. r){
			if(i % 2 == 0) foreach(j; 0 .. c){
				if(uf[i][j]) cnt += 1;
				ansf[i][j] = symbols[h];
				if(cnt >= quota[h]) cnt = 0, h += 1;
			}
			else foreach_reverse(j; 0 .. c){
				if(uf[i][j]) cnt += 1;
				ansf[i][j] = symbols[h];
				if(cnt >= quota[h]) cnt = 0, h += 1;
			}
		}
		foreach(i; 0 .. r) ansf[i].writeln;
	}

}

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

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 str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	auto T = RD!int;
	auto ans = new char[][][](T);
	foreach (i; 0..T)
	{
		auto r = RD!int;
		auto c = RD!int;
		auto k = RD!int;
		auto s = new string[](r);
		foreach (j; 0..r)
			s[j] = RD!string;
		ans[i] = new char[][](r, c);

		int rice;
		foreach (y; 0..r)
		{
			foreach (x; 0..c)
			{
				if (s[y][x] == 'R')
					++rice;
			}
		}
		auto cnt1 = rice / k;
		auto cnt2 = rice % k;
		int cnt;
		int num;
		foreach (y; 0..r)
		{
			if (y % 2 == 0)
			{
				foreach (x; 0..c)
				{
					ans[i][y][x] = str[num];
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
				}
			}
			else
			{
				foreach_reverse (x; 0..c)
				{
					ans[i][y][x] = str[num];
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
				}
			}
		}
	}

	foreach (e; ans)
	{
		foreach (y; 0..e.length)
		{
			writeln(e[y]);
		}
	}

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

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.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; }

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 char[][][](T);
	foreach (i; 0..T)
	{
		auto r = RD!int;
		auto c = RD!int;
		auto k = RD!int;
		auto s = new string[](r);
		foreach (j; 0..r)
			s[j] = RD!string;
		ans[i] = new char[][](r, c);

		int rice;
		foreach (y; 0..r)
		{
			foreach (x; 0..c)
			{
				if (s[y][x] == 'R')
					++rice;
			}
		}
		auto cnt1 = rice / k;
		auto cnt2 = rice % k;
		int cnt;
		int num;
		foreach (y; 0..r)
		{
			if (y % 2 == 0)
			{
				foreach (x; 0..c)
				{
					ans[i][y][x] = cast(char)(('0'+num)%256);
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
				}
			}
			else
			{
				foreach_reverse (x; 0..c)
				{
					ans[i][y][x] = cast(char)(('0'+num)%256);
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
				}
			}
		}
	}

	foreach (e; ans)
	{
		foreach (y; 0..e.length)
		{
			writeln(e[y]);
		}
	}

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

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.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; }

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 str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	auto T = RD!int;
	auto ans = new char[][][](T);
	foreach (i; 0..T)
	{
		auto r = RD!int;
		auto c = RD!int;
		auto k = RD!int;
		auto s = new string[](r);
		foreach (j; 0..r)
			s[j] = RD!string;
		ans[i] = new char[][](r, c);

		int rice;
		foreach (y; 0..r)
		{
			foreach (x; 0..c)
			{
				if (s[y][x] == 'R')
					++rice;
			}
		}
		auto cnt1 = rice / k;
		auto cnt2 = rice % k;
		int cnt;
		int num;
		foreach (y; 0..r)
		{
			if (y % 2 == 0)
			{
				foreach (x; 0..c)
				{
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt > cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
					ans[i][y][x] = str[num];
				}
			}
			else
			{
				foreach_reverse (x; 0..c)
				{
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt > cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
					ans[i][y][x] = str[num];
				}
			}
		}
	}

	foreach (e; ans)
	{
		foreach (y; 0..e.length)
		{
			writeln(e[y]);
		}
	}

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

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.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; }

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 char[][][](T);
	foreach (i; 0..T)
	{
		auto r = RD!int;
		auto c = RD!int;
		auto k = RD!int;
		auto s = new string[](r);
		foreach (j; 0..r)
			s[j] = RD!string;
		ans[i] = new char[][](r, c);

		int rice;
		foreach (y; 0..r)
		{
			foreach (x; 0..c)
			{
				if (s[y][x] == 'R')
					++rice;
			}
		}
		auto cnt1 = rice / k;
		auto cnt2 = rice % k;
		int cnt;
		int num;
		foreach (y; 0..r)
		{
			if (y % 2 == 0)
			{
				foreach (x; 0..c)
				{
					ans[i][y][x] = num.to!string[0];
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
				}
			}
			else
			{
				foreach_reverse (x; 0..c)
				{
					ans[i][y][x] = num.to!string[0];
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
				}
			}
		}
	}

	foreach (e; ans)
	{
		foreach (y; 0..e.length)
		{
			writeln(e[y]);
		}
	}

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

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.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; }

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 str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	auto T = RD!int;
	auto ans = new char[][][](T);
	foreach (i; 0..T)
	{
		auto r = RD!int;
		auto c = RD!int;
		auto k = RD!int;
		auto s = new string[](r);
		foreach (j; 0..r)
			s[j] = RD!string;
		ans[i] = new char[][](r, c);

		int rice;
		foreach (y; 0..r)
		{
			foreach (x; 0..c)
			{
				if (s[y][x] == 'R')
					++rice;
			}
		}
		auto cnt1 = rice / k;
		auto cnt2 = rice % k;
		int cnt;
		int num;
		foreach (y; 0..r)
		{
			if (y % 2 == 0)
			{
				foreach (x; 0..c)
				{
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
					ans[i][y][x] = str[num];
				}
			}
			else
			{
				foreach_reverse (x; 0..c)
				{
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
					ans[i][y][x] = str[num];
				}
			}
		}
	}

	foreach (e; ans)
	{
		foreach (y; 0..e.length)
		{
			writeln(e[y]);
		}
	}

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

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.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; }

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 char[][][](T);
	foreach (i; 0..T)
	{
		auto r = RD!int;
		auto c = RD!int;
		auto k = RD!int;
		auto s = new string[](r);
		foreach (j; 0..r)
			s[j] = RD!string;
		ans[i] = new char[][](r, c);

		int rice;
		foreach (y; 0..r)
		{
			foreach (x; 0..c)
			{
				if (s[y][x] == 'R')
					++rice;
			}
		}
		auto cnt1 = rice / k;
		auto cnt2 = rice % k;
		int cnt;
		int num;
		foreach (y; 0..r)
		{
			if (y % 2 == 0)
			{
				foreach (x; 0..c)
				{
					ans[i][y][x] = cast(char)(('a'+num)%256);
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
				}
			}
			else
			{
				foreach_reverse (x; 0..c)
				{
					ans[i][y][x] = cast(char)(('a'+num)%256);
					if (s[y][x] == 'R')
					{
						++cnt;
						if (cnt >= cnt1+(num < cnt2 ? 1 : 0))
						{
							++num;
							cnt = 0;
						}
					}
				}
			}
		}
	}

	foreach (e; ans)
	{
		foreach (y; 0..e.length)
		{
			writeln(e[y]);
		}
	}

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


Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si.In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two numbers l and r (1 ≤ l ≤ r ≤ n) and each pair of ants with indices between l and r (inclusively) will fight. When two ants i and j fight, ant i gets one battle point only if si divides sj (also, ant j gets one battle point only if sj divides si). After all fights have been finished, Mole makes the ranking. An ant i, with vi battle points obtained, is going to be freed only if vi = r - l, or in other words only if it took a point in every fight it participated. After that, Mole eats the rest of the ants. Note that there can be many ants freed or even none.In order to choose the best sequence, Mole gives you t segments [li, ri] and asks for each of them how many ants is he going to eat if those ants fight.

The first line contains one integer n (1 ≤ n ≤ 105), the size of the ant colony.  The second line contains n integers s1, s2, ..., sn (1 ≤ si ≤ 109), the strengths of the ants.  The third line contains one integer t (1 ≤ t ≤ 105), the number of test cases.  Each of the next t lines contains two integers li and ri (1 ≤ li ≤ ri ≤ n), describing one query.

Print to the standard output t lines. The i-th line contains number of ants that Mole eats from the segment [li, ri].

NoteIn the first test battle points for each ant are v = [4, 0, 2, 0, 2], so ant number 1 is freed. Mole eats the ants 2, 3, 4, 5.In the second test case battle points are v = [0, 2, 0, 2], so no ant is freed and all of them are eaten by Mole.In the third test case battle points are v = [2, 0, 2], so ants number 3 and 5 are freed. Mole eats only the ant 4.In the fourth test case battle points are v = [0, 1], so ant number 5 is freed. Mole eats the ant 4.

import std.stdio;
import std.conv;

immutable N = 100001;

int[N] a;
int[4*N] tree;
int[][int] mapper;

int gcd(int a, int b) {
  while (b != 0) {
    int t = a % b;
    a = b;
    b = t;
  }
  return a;
}

void build(int x, int l, int r) {
  if (l == r) {
    tree[x] = a[l];
  } else {
    int mid = (l + r) >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    tree[x] = gcd(tree[x << 1], tree[x << 1 | 1]);
  }
}

int query(int x, int l, int r, int ql, int qr) {
  if (l > qr || r < ql) {
    return 0;
  } else if (l >= ql && r <= qr) {
    return tree[x];
  } else {
    int mid = (l + r) >> 1;
    return gcd(query(x << 1, l, mid, ql, qr), query(x << 1 | 1, mid + 1, r, ql, qr));
  }
}

void main() {
  int n; readf(" %s", &n);
  for (int i = 0; i < n; i++) {
    readf(" %s", &a[i]);
    mapper[a[i]] ~= i;
  }
  build(1, 0, n - 1);
  int t; readf(" %s", &t);
  while (t--) {
    int l, r; readf(" %s %s", &l, &r); l--; r--;
    int g = query(1, 0, n - 1, l, r);
    if (g in mapper) {
      int ll, rr;
      int lo = -1, hi = to!(int)(mapper[g].length);
      while (lo + 1 < hi) {
        int mid = (lo + hi) >> 1;
        if (mapper[g][mid] < l) lo = mid;
        else hi = mid;
      }
      ll = hi;
      lo = -1; hi = to!(int)(mapper[g].length);
      while (lo + 1 < hi) {
        int mid = (lo + hi) >> 1;
        if (mapper[g][mid] > r) hi = mid;
        else lo = mid;
      }
      rr = lo;
      writeln((r - l + 1) - (rr - ll + 1));
    } else {
      writeln(r - l + 1);
    }
  }
}

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

int gcd(int a, int b) { return a == 0 ? b : gcd(b % a, a); }

void main() { while (solve()) {} }

enum N = 100500;

struct node {
	int g;
	int mn, cntmn;
	int len;
	this(int val) {
		this.g = val;
		this.mn = val;
		this.cntmn = 1;
		this.len = 1;
	}
	int ans() {
		if (mn != g) return len;
		return len - cntmn;
	}
}

node merge(node a, node b) {
	node res;
	res.len = a.len + b.len;
	res.g = gcd(a.g, b.g);
	res.mn = min(a.mn, b.mn);
	res.cntmn = 0;
	if (res.mn == a.mn) res.cntmn += a.cntmn;
	if (res.mn == b.mn) res.cntmn += b.cntmn;
	return res;
}

node[4 * N] t;
int[N] a;

void build(size_t v, size_t lf, size_t rg) {
	if (lf + 1 == rg) {
		t[v] = node(a[lf]);
		return;
	}
	size_t mid = (lf + rg) / 2;
	build(v * 2 + 1, lf, mid);
	build(v * 2 + 2, mid, rg);
	t[v] = merge(t[v * 2 + 1], t[v * 2 + 2]);
}

node get(size_t from, size_t to, size_t v, size_t lf, size_t rg) {
	if (from == lf && to == rg) return t[v];
	size_t mid = (lf + rg) / 2;
	if (to <= mid) return get(from, to, v * 2 + 1, lf, mid);
	if (from >= mid) return get(from, to, v * 2 + 2, mid, rg);
	return merge(get(from, mid, v * 2 + 1, lf, mid),
		get(mid, to, v * 2 + 2, mid, rg));
}

size_t n;

bool solve() {
	if (!readf(" %s", &n)) return false;
	foreach (i; 0..n)
		enforce(readf(" %s", &a[i]));
	build(0, 0, n);
	size_t m;
	enforce(readf(" %s", &m));
	foreach (i; 0..m) {
		size_t lf, rg;
		enforce(readf(" %s %s", &lf, &rg));
		lf--;
		node res = get(lf, rg, 0, 0, n);
		writeln(res.ans);
	}
	return true;
}

import std.stdio;
import std.conv;

immutable N = 100001;

int[N] a;
int[4*N] tree;
int[][int] mapper;

int gcd(int a, int b) {
  while (b != 0) {
    int t = a % b;
    a = b;
    b = t;
  }
  return a;
}

void build(int x, int l, int r) {
  if (l == r) {
    tree[x] = a[l];
  } else {
    int mid = (l + r) >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    tree[x] = gcd(tree[x << 1], tree[x << 1 | 1]);
  }
}

int query(int x, int l, int r, int ql, int qr) {
  if (l > qr || r < ql) {
    return 0;
  } else if (l >= ql && r <= qr) {
    return tree[x];
  } else {
    int mid = (l + r) >> 1;
    return gcd(query(x << 1, l, mid, ql, qr), query(x << 1 | 1, mid + 1, r, ql, qr));
  }
}

void main() {
  int n; readf(" %s", &n);
  for (int i = 0; i < n; i++) {
    readf(" %s", &a[i]);
    mapper[a[i]] ~= i;
  }
  build(1, 0, n - 1);
  int t; readf(" %s", &t);
  while (t--) {
    int l, r; readf(" %s %s", &l, &r); l--; r--;
    int g = query(1, 0, n - 1, l, r);
    if (g in mapper) {
      int ll, rr;
      int lo = -1, hi = to!(int)(mapper[g].length);
      while (lo + 1 < hi) {
        int mid = (lo + hi) >> 1;
        if (mapper[g][mid] < l) lo = mid;
        else hi = mid;
      }
      ll = hi;
      lo = -1; hi = to!(int)(mapper[g].length);
      while (lo + 1 < hi) {
        int mid = (lo + hi) >> 1;
        if (mapper[g][mid] > r) hi = mid;
        else lo = mid;
      }
      rr = lo;
      writeln((r - l + 1) - (rr - ll + 1));
    } else {
      writeln(0);
    }
  }
}


$$$n$$$ people live on the coordinate line, the $$$i$$$-th one lives at the point $$$x_i$$$ ($$$1 \le i \le n$$$). They want to choose a position $$$x_0$$$ to meet. The $$$i$$$-th person will spend $$$|x_i - x_0|$$$ minutes to get to the meeting place. Also, the $$$i$$$-th person needs $$$t_i$$$ minutes to get dressed, so in total he or she needs $$$t_i + |x_i - x_0|$$$ minutes. Here $$$|y|$$$ denotes the absolute value of $$$y$$$.These people ask you to find a position $$$x_0$$$ that minimizes the time in which all $$$n$$$ people can gather at the meeting place.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases. Then the test cases follow. Each test case consists of three lines. The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of people.  The second line contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$0 \le x_i \le 10^{8}$$$) — the positions of the people. The third line contains $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$ ($$$0 \le t_i \le 10^{8}$$$), where $$$t_i$$$ is the time $$$i$$$-th person needs to get dressed. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print a single real number — the optimum position $$$x_0$$$. It can be shown that the optimal position $$$x_0$$$ is unique. Your answer will be considered correct if its absolute or relative error does not exceed $$$10^{−6}$$$. Formally, let your answer be $$$a$$$, the jury's answer be $$$b$$$. Your answer will be considered correct if $$$\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$$$.

Note  In the $$$1$$$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $$$3$$$ minutes, that he or she need to get dressed.  In the $$$2$$$-nd test case there are $$$2$$$ people who don't need time to get dressed. Each of them needs one minute to get to position $$$2$$$.  In the $$$5$$$-th test case the $$$1$$$-st person needs $$$4$$$ minutes to get to position $$$1$$$ ($$$4$$$ minutes to get dressed and $$$0$$$ minutes on the way); the $$$2$$$-nd person needs $$$2$$$ minutes to get to position $$$1$$$ ($$$1$$$ minute to get dressed and $$$1$$$ minute on the way); the $$$3$$$-rd person needs $$$4$$$ minutes to get to position $$$1$$$ ($$$2$$$ minutes to get dressed and $$$2$$$ minutes on the way).

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

void solve() {
    int N; readf("%d\n", &N);
    double[] X = readln.chomp.split(" ").map!(to!double).array;
    double[] T = readln.chomp.split(" ").map!(to!double).array;

    double C(double x0) {
        double r = 0;
        foreach (i; 0 .. N) {
            auto x = X[i], t = T[i];
            r = max(r, t + abs(x - x0));
        }
        return r;
    }

    int L = 200;
    double lb = 0, ub = 1e8 + 10;
    foreach (_; 0 .. L) {
        double d = ub - lb;
        double m0 = lb + d / 3,
               m1 = lb + d / 3 * 2;
        if (C(m0) < C(m1)) {
            ub = m1;
        } else {
            lb = m0;
        }
    }
    writefln("%.12f", lb);
}

void main() {
    int T; readf("%d\n", &T);
    foreach (t; 0 .. T) {
        solve();
    }
}