You are given an undirected unweighted graph consisting of $$$n$$$ vertices and $$$m$$$ edges (which represents the map of Bertown) and the array of prices $$$p$$$ of length $$$m$$$. It is guaranteed that there is a path between each pair of vertices (districts).Mike has planned a trip from the vertex (district) $$$a$$$ to the vertex (district) $$$b$$$ and then from the vertex (district) $$$b$$$ to the vertex (district) $$$c$$$. He can visit the same district twice or more. But there is one issue: authorities of the city want to set a price for using the road so if someone goes along the road then he should pay the price corresponding to this road (he pays each time he goes along the road). The list of prices that will be used $$$p$$$ is ready and they just want to distribute it between all roads in the town in such a way that each price from the array corresponds to exactly one road.You are a good friend of Mike (and suddenly a mayor of Bertown) and want to help him to make his trip as cheap as possible. So, your task is to distribute prices between roads in such a way that if Mike chooses the optimal path then the price of the trip is the minimum possible. Note that you cannot rearrange prices after the start of the trip.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains five integers $$$n, m, a, b$$$ and $$$c$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$n-1 \le m \le min(\frac{n(n-1)}{2}, 2 \cdot 10^5)$$$, $$$1 \le a, b, c \le n$$$) — the number of vertices, the number of edges and districts in Mike's trip. The second line of the test case contains $$$m$$$ integers $$$p_1, p_2, \dots, p_m$$$ ($$$1 \le p_i \le 10^9$$$), where $$$p_i$$$ is the $$$i$$$-th price from the array. The following $$$m$$$ lines of the test case denote edges: edge $$$i$$$ is represented by a pair of integers $$$v_i$$$, $$$u_i$$$ ($$$1 \le v_i, u_i \le n$$$, $$$u_i \ne v_i$$$), which are the indices of vertices connected by the edge. There are no loops or multiple edges in the given graph, i. e. for each pair ($$$v_i, u_i$$$) there are no other pairs ($$$v_i, u_i$$$) or ($$$u_i, v_i$$$) in the array of edges, and for each pair $$$(v_i, u_i)$$$ the condition $$$v_i \ne u_i$$$ is satisfied. It is guaranteed that the given graph is connected. It is guaranteed that the sum of $$$n$$$ (as well as the sum of $$$m$$$) does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$, $$$\sum m \le 2 \cdot 10^5$$$).

For each test case, print the answer — the minimum possible price of Mike's trip if you distribute prices between edges optimally.

NoteOne of the possible solution to the first test case of the example:One of the possible solution to the second test case of the example:

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

void main ()
{
	readln;
	int n, m, a, b, c;
	while (readf !(" %s %s %s %s %s") (n, m, a, b, c) > 0)
	{
		a -= 1;
		b -= 1;
		c -= 1;
		readln;

		auto p = readln.splitter.map !(to !(int)).array;
		sort (p);
		auto s = [0L] ~ cumulativeFold !(q{a + b}) (p, 0L).array;

		auto adj = new int [] [n];
		foreach (j; 0..m)
		{
			int u, v;
			readf !(" %s %s") (u, v);
			u -= 1;
			v -= 1;
			adj[u] ~= v;
			adj[v] ~= u;
		}

		int [] bfs (int start)
		{
			auto d = new int [n];
			d[] = int.max;
			d[start] = 0;
			int [] q;
			q ~= start;
			foreach (i; 0..n)
			{
				auto v = q.front;
				q.popFront ();
				q.assumeSafeAppend ();
				foreach (u; adj[v])
				{
					if (d[u] == int.max)
					{
						d[u] = d[v] + 1;
						q ~= u;
					}
				}
			}
			return d;
		}

		auto da = bfs (a);
		auto db = bfs (b);
		auto dc = bfs (c);

		long res = long.max;
		foreach (u; 0..n)
		{
			auto common = db[u];
			auto total = da[u] + db[u] + dc[u];
			debug {writeln (u + 1, ": ", common, ", ", total);}
			if (total <= m)
			{
				res = min (res, s[common] + s[total]);
			}
		}
		writeln (res);
	}
}

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!int;
		auto m = RD!int;
		auto a = RD!int-1;
		auto b = RD!int-1;
		auto c = RD!int-1;
		auto p = RDA;

		auto edges = new int[][](n);
		foreach (i; 0..m)
		{
			auto u = RD!int-1;
			auto v = RD!int-1;
			edges[u] ~= v;
			edges[v] ~= u;
		}

		long[] search(int s)
		{
			int[] open = [s];
			auto dist = new long[](n);
			dist[] = long.max;
			dist[s] = 0;
			while (!open.empty)
			{
				auto from = open.front; open.popFront;
				auto d = dist[from]+1;
				foreach (to; edges[from])
				{
					if (d < dist[to])
					{
						open ~= to;
						dist[to] = d;
					}
				}
			}
			return dist;
		}
		auto dist_a = search(a);
		auto dist_b = search(b);
		auto dist_c = search(c);

		p.sort();
		auto pp = new long[](p.length+1);
		foreach (i; 0..p.length)
		{
			pp[i+1] = pp[i] + p[i];
		}

		ans[ti] = long.max;
		foreach (i; 0..n)
		{
			if (dist_b[i]+dist_a[i]+dist_c[i] > p.length) continue;
			auto c1 = pp[cast(int)dist_b[i]];
			auto c2 = pp[cast(int)(dist_b[i]+dist_a[i])] - c1;
			auto c3 = pp[cast(int)(dist_b[i]+dist_a[i]+dist_c[i])] - (c1+c2);
			ans[ti].chmin(c1*2+c2+c3);
		}
	}

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


As their story unravels, a timeless tale is told once again...Shirahime, a friend of Mocha's, is keen on playing the music game Arcaea and sharing Mocha interesting puzzles to solve. This day, Shirahime comes up with a new simple puzzle and wants Mocha to solve them. However, these puzzles are too easy for Mocha to solve, so she wants you to solve them and tell her the answers. The puzzles are described as follow.There are $$$n$$$ squares arranged in a row, and each of them can be painted either red or blue.Among these squares, some of them have been painted already, and the others are blank. You can decide which color to paint on each blank square.Some pairs of adjacent squares may have the same color, which is imperfect. We define the imperfectness as the number of pairs of adjacent squares that share the same color.For example, the imperfectness of "BRRRBBR" is $$$3$$$, with "BB" occurred once and "RR" occurred twice.Your goal is to minimize the imperfectness and print out the colors of the squares after painting.

Each test contains multiple test cases.  The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains an integer $$$n$$$ ($$$1\leq n\leq 100$$$) — the length of the squares row. The second line of each test case contains a string $$$s$$$ with length $$$n$$$, containing characters 'B', 'R' and '?'. Here 'B' stands for a blue square, 'R' for a red square, and '?' for a blank square.

For each test case, print a line with a string only containing 'B' and 'R', the colors of the squares after painting, which imperfectness is minimized. If there are multiple solutions, print any of them.

NoteIn the first test case, if the squares are painted "BRRBRBR", the imperfectness is $$$1$$$ (since squares $$$2$$$ and $$$3$$$ have the same color), which is the minimum possible imperfectness.

immutable multi = true;

void solve(int tc)
{
	auto n = readInt!int;
	auto s = readString;
	int prev = -1;
	char[] ans = new char[](n);
	foreach(i; 0 .. n)
	{
		if (s[i] != '?')
		{
			foreach_reverse(j; prev+1 .. i+1)
			{
				if (j%2 == i%2)
					ans[j] = s[i];
				else
					ans[j] = s[i] == 'R'? 'B' : 'R';
			}
			prev = i;
		}
		else
		{
		}
	}
	foreach(j; prev+1 .. n)
	{
		if ((prev+2)%2 == j%2)
		{
			ans[j] = prev == -1? 'R' : s[prev];
		}
		else
		{
			ans[j] = prev == -1? 'B' : (s[prev] == 'R'? 'B' : 'R');
		}
	}
	ans.writeln;
}

// main {{{
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;
}
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;
// }}}

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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

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

void main()
{
	auto T = RD!int;
	auto ans = new char[][](T);
	foreach (ti; 0..T)
	{
		auto n = RD!int;
		auto s = RD!string;

		ans[ti].length = n;

		int pos;
		foreach (i; 0..n)
		{
			if (s[i] == '?') continue;
			pos = i;
			break;
		}
		foreach (i; pos..n)
		{
			if (s[i] != '?')
				ans[ti][i] = s[i];
			else if (i == 0)
			{
				ans[ti][i] = 'R';
			}
			else
			{
				if (ans[ti][i-1] == 'R')
					ans[ti][i] = 'B';
				else
					ans[ti][i] = 'R';
			}
		}
		foreach_reverse (i; 0..pos)
		{
			if (s[i] != '?')
				ans[ti][i] = s[i];
			else
			{
				if (ans[ti][i+1] == 'R')
					ans[ti][i] = 'B';
				else
					ans[ti][i] = 'R';
			}
		}
	}

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

immutable multi = true;

void solve(int tc)
{
	auto n = readInt!int;
	auto s = readString;
	int prev = -1;
	char[] ans = new char[](n);
	foreach(i; 0 .. n)
	{
		if (s[i] != '?')
		{
			foreach_reverse(j; prev+1 .. i+1)
			{
				if (j%2 == i%2)
					ans[j] = s[i];
				else
					ans[j] = s[i] == 'R'? 'B' : 'R';
			}
			prev = i;
		}
		else
		{
		}
	}
	foreach(j; prev+1 .. n)
	{
		if (prev%2 == j%2)
		{
			ans[j] = prev == -1? 'R' : s[prev];
		}
		else
		{
			ans[j] = prev == -1? 'B' : (s[prev] == 'R'? 'B' : 'R');
		}
	}
	ans.writeln;
}

// main {{{
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;
}
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;
// }}}


Sometimes it is not easy to come to an agreement in a bargain. Right now Sasha and Vova can't come to an agreement: Sasha names a price as high as possible, then Vova wants to remove as many digits from the price as possible. In more details, Sasha names some integer price $$$n$$$, Vova removes a non-empty substring of (consecutive) digits from the price, the remaining digits close the gap, and the resulting integer is the price.For example, is Sasha names $$$1213121$$$, Vova can remove the substring $$$1312$$$, and the result is $$$121$$$.It is allowed for result to contain leading zeros. If Vova removes all digits, the price is considered to be $$$0$$$.Sasha wants to come up with some constraints so that Vova can't just remove all digits, but he needs some arguments supporting the constraints. To start with, he wants to compute the sum of all possible resulting prices after Vova's move.Help Sasha to compute this sum. Since the answer can be very large, print it modulo $$$10^9 + 7$$$.

The first and only line contains a single integer $$$n$$$ ($$$1 \le n < 10^{10^5}$$$).

In the only line print the required sum modulo $$$10^9 + 7$$$.

// Cheese-Cracker: cheese-cracker.github.io

const ll PRIME = 10L^^9 + 7;

void play(){
    dchar[] nummer;
    nummer = rd!(dchar[]);
    ll[] arr;
    foreach(c; nummer){
        arr ~= c-'0';
    }
    int n = arr.length.to!int;
    ll res = 0;
    // Ten-> Power of Ten, RevNN -> Reverse Natural Numbers
    ll tim = 0, ten = 1, revnn = 0;
    foreach_reverse(i; 0..n){
        // Add Before
        ll mul = ( ( 1L * i * (i + 1))/2L ) % PRIME;
        mul *= ten;
        mul %= PRIME;
        res += mul*arr[i];
        res %= PRIME;

        // Add After
        res += revnn * arr[i];
        res %= PRIME;

        // Remove Number Value

        show(ten, tim, mul*ten*arr[i], revnn);

        // Update Tim & Ten
        tim *= 10; tim += 1; tim %= PRIME;
        revnn *= 10; revnn += tim; revnn %= PRIME;
        ten *= 10; ten %= PRIME;

    }
    writeln(res);
}

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

/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
alias ll = long;
alias rbt = RedBlackTree;
alias sr = SortedRange;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
void show(A...)(A a) { debug{ foreach(t; a){ write(t, "| "); } writeln; } }

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

immutable int mod  = 1_000_000_007;
immutable int base =            10;

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		auto n = s.length.to !(int);
		long res = 0;
		long cur = 1;
		long add = 0;
		foreach (k; 0..n)
		{
			auto mult = ((n - k) * (n - k - 1L) / 2) % mod;
			mult = (mult * cur + add) % mod;
			res = (res + mult * (s[n - k - 1] - '0')) % mod;
			add = (add + cur * (k + 1L)) % mod;
			cur = (cur * base) % mod;
		}
		writeln (res);
	}
}

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

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

void main(string[] args)
{
  enum p = 1_000_000_000 + 7;
  auto n = next!string;
  auto tenpow = new long[](n.length);
  tenpow[n.length - 1] = 1;
  foreach_reverse(i; 0 .. n.length - 1)
    tenpow[i] = (tenpow[i + 1] * 10) % p;
  long rightNum = 0;
  foreach(d; n) rightNum = ((rightNum * 10) % p + long(d - '0')) % p;
  long leftSum = 0;
  long leftNum = 0;
  long res = 0;
  foreach(i; 0 .. n.length)
    {
      long li = cast(long)i;
      long dig = n[i] - '0';
      rightNum = pmod(rightNum - (dig * tenpow[i]) % p, p);

      res = (res%p + (rightNum * (li + 1))%p + (leftSum * tenpow[i])%p)%p;

      leftNum = ((leftNum * 10) % p + dig)%p;
      leftSum = (leftSum + leftNum) % p;
    }
  res.writeln;
}

static this()
{
  popChar;
}

struct Any(T)
{
  static auto read()
  {
    static if (is(T == char))
      {
	auto res = frontChar;
	popChar;
	return res;
      }
  }
}

struct Unsigned(T)
{
  auto read()
  {
    auto res = T(0);
    while(!frontChar.isDigit) popChar;
    do
      {
	res = res * T(10) + T(frontChar - '0');
	popChar;
      }
    while(frontChar.isDigit);
    return res;
  }
}

struct Matrix(T, alias rows, alias cols)
{
  T[][] _cell;
  alias _cell this;
  // Ring constructor
  this(int n)
  {
    final switch(n)
      {
      case 0:
	_cell = new T[][](rows, cols);
	break;
      case 1:
	debug assert(rows == cols);
	_cell = new T[][](rows, cols);
	foreach(i; 0 .. rows)
	  _cell[i][i] = T(1);
	break;
      }
  }
  // Copy constructor
  this(Matrix!(T, rows, cols) other)
  {
    _cell = new T[][](rows, cols);
    foreach(i; 0 .. rows)
      _cell[i][] = other[i][];
  }
  auto opBinary(string op)(Matrix!(T, rows, cols) other)
       if (op == "+" || op == "-")
	 {
	   auto res = Matrix!(T, rows, cols)(0);
	   foreach(i; 0 .. rows)
	     foreach(j; 0 .. cols)
	       res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});
	   return res;
	 }
  auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)
       if (op == "*")
	 {
	   debug assert(cols == otherRows);
	   auto res = Matrix!(T, rows, otherCols)(0);
	   foreach(i; 0 .. rows)
	     foreach(k; 0 .. cols)
	       foreach(j; 0 .. otherCols)
		 res[i][j] += this[i][k] * other[k][j];
	   return res;
	 }
  ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)
  {
    static if (op == "*")
      {
	debug assert(rows == cols);
	alias n = rows;
	auto res = Matrix!(T, n, n)(0);
	T factor;
	foreach(i; 0 .. n)
	  foreach(k; 0 .. n)
	    foreach(j; 0 .. n)
	      res[i][j] += this[i][k] * other[k][j];
	foreach(i; 0 .. n)
	  this[i][] = res[i][];
      }
    else
      {
	foreach(i; 0 .. rows)
	  foreach(j; 0 .. cols)
	    mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});
      }
    return this;
  }
  mixin powMethod;
}

struct Mod(T, alias mod)
{
  alias This = Mod!(T, mod);
  T _rep;
  this(T t)
  {
    _rep = t % mod;
    if (_rep < 0) _rep += mod;
  }
  static auto plain(T t)
  {
    auto res = Mod!(T, mod)();
    res._rep = t;
    return res;
  }
  static auto fromPositive(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod);
  }
  static auto fromNegative(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod + mod);
  }
  string toString()
  {
    return to!string(_rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plain(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plain(resrep);
      }
    else static if (op == "*")
      {
	return This.fromPositive(_rep * b._rep);
      }
  }
  auto opOpAssign(string op)(This b)
  {
    mixin(q{_rep }, text(op, "="), q{b._rep;});
    static if (op == "+")
      {
	if (_rep >= mod) _rep -= mod;
      }
    else static if (op == "-")
      {
	if (_rep < 0) _rep += mod;
      }
    else static if (op == "*")
      {
	_rep %= mod;
      }
    return this;
  }

  auto opBinary(string op)(long exp)
       if (op == "^^")
	 {
	   return pow(exp);
	 }
  mixin powMethod;
}

mixin template powMethod()
{
  auto pow(this ThisType)(long exp)
    {
      auto res = ThisType(1);
      auto pow = ThisType(this);
      while(exp)
	{
	  if (exp & 1) res *= pow;
	  pow *= pow;
	  exp >>= 1;
	}
      return res;
    }
}
// INPUT
char frontChar;
void popChar()
{
  import core.stdc.stdio;
  frontChar = cast(char) getchar;
  if (feof(stdin)) frontChar = ' ';
}
auto makeArray(T, S...)(S s)
{
  enum brackets = () {
    string res;
    foreach(i; 0 .. s.length)
      res ~= "[]";
    return res;
  } ();
  mixin(q{alias Type = T}, brackets, q{;});
  return new Type(s);
}
template isNumberLike(T)
{
  enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));
}
void popWhite()
{
  import std.ascii;
  while (frontChar.isWhite) popChar;
}
void print(T...)(T t)
{
  static foreach(ti; t)
    {
      static if (is(typeof(ti) == string))
	{
	  write(ti, " ");
	}
      else static if (isArray!(typeof(ti)))
	{
	  foreach(e; ti) print(e);
	}
      else static if (isTuple!(typeof(ti)))
	{
	  static foreach(i; ti.length) writesp(ti[i]);
	}
      else
	{
	  write(ti, " ");
	}
    }
}
void println(T...)(T t)
{
  static if (t.length == 0)
    writeln;
  static foreach(ti; t)
    {
      print(ti);
      writeln;
    }
}
auto next(alias T, S...)(S s)
{
  pragma(inline, true);
  static if (s.length > 0)
    {
      auto res = makeArray!(typeof(next!T()))(s);
      S t;
      enum loops = () {
	string res;
	foreach(i; 0 .. s.length)
	  {
	    auto ti = text(q{t[}, i, q{]});
	    res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});
	  }
	return res;
      } ();
      enum indexing = () {
	string res = "res";
	foreach(i; 0 .. s.length)
	  res ~= text(q{[t[}, i, q{]]});
	return res;
      } ();
      mixin(loops, indexing, q{ = next!T;});
      return res;
    }
  else
    {
      static if (isNumberLike!T)
	{
	  import std.ascii: isDigit;
	  T res;
	  while(frontChar.isWhite) popChar;
	  T multiplier = T(1);
	  if (frontChar == '-')
	    {
	      multiplier = T(-1);
	      popChar;
	    }
	  else if (frontChar == '+')
	    {
	      popChar;
	    }
	  debug assert(frontChar.isDigit);
	  do
	    {
	      res = res * T(10) + T(frontChar - '0');
	      popChar;
	    }
	  while(frontChar.isDigit);
	  return multiplier * res;
	}
      else static if (is(T == string))
	{
	  import std.ascii: isWhite;
	  string res;
	  while(frontChar.isWhite)
	    popChar;
	  while(!frontChar.isWhite)
	    {
	      res ~= frontChar;
	      popChar;
	    }
	  return res;
	}
      else static if (is(T == char))
	{
	  while(frontChar.isWhite) popChar;
	  auto res = frontChar;
	  popChar;
	  return res;
	}
      else
	{
	  return T.read;
	}
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto n = RD!string;

	auto pat = new long[](n.length+1);
	foreach (i; 0..n.length)
	{
		pat[i+1] = pat[i];
		long tmp = 10;
		tmp.modpow(i);
		tmp.modm(i+1);
		pat[i+1].moda(tmp);
	}

	long ans;
	foreach (i; 0..n.length)
	{
		{
			long num = n[i]-'0';
			long left = i;
			left *= (i+1);
			left /= 2;
			left %= mod;
			long digit = 10;
			digit.modpow(n.length-i-1);
			num.modm(digit);
			left.modm(num);
			ans.moda(left);
			debug writeln("i:", i, " ans:", ans);
		}
		{
			long num = n[i]-'0';
			num.modm(pat[n.length-i-1]);
			ans.moda(num);
			debug writeln("i:", i, " ans:", ans);
		}
	}

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

// Cheese-Cracker: cheese-cracker.github.io

const ll PRIME = 10L^^9 + 7;

void play(){
    dchar[] nummer;
    nummer = rd!(dchar[]);
    ll[] arr;
    foreach(c; nummer){
        arr ~= c-'0';
    }
    int n = arr.length.to!int;
    ll res = 0;
    // Ten-> Power of Ten, RevNN -> Reverse Natural Numbers
    ll tim = 0, ten = 1, revnn = 0;
    foreach_reverse(i; 0..n){
        // Add Before
        ll mul = (i*(i+1))/2;
        mul %= PRIME;
        res += (mul*ten % PRIME)*arr[i];
        res %= PRIME;

        // Add After
        res += revnn * arr[i];
        res %= PRIME;

        // Remove Number Value

        show(ten, tim, mul*ten*arr[i], revnn);

        // Update Tim & Ten
        tim *= 10; tim += 1; tim %= PRIME;
        revnn *= 10; revnn += tim; revnn %= PRIME;
        ten *= 10; ten %= PRIME;

    }
    writeln(res);
}

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

/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
alias ll = long;
alias rbt = RedBlackTree;
alias sr = SortedRange;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
void show(A...)(A a) { debug{ foreach(t; a){ write(t, "| "); } writeln; } }

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto n = RD!string;

	auto pat = new long[](n.length+1);
	foreach (i; 0..n.length)
	{
		pat[i+1] = pat[i];
		long tmp = 10;
		tmp.modpow(i);
		tmp.modm(i+1);
		pat[i+1].moda(tmp);
	}

	long ans;
	foreach (i; 0..n.length)
	{
		{
			long num = n[i]-'0';
			long left = i*(i+1)/2;
			long digit = 10;
			digit.modpow(n.length-i-1);
			num.modm(digit);
			left.modm(num);
			ans.moda(left);
			debug writeln("i:", i, " ans:", ans);
		}
		{
			long num = n[i]-'0';
			num.modm(pat[n.length-i-1]);
			ans.moda(num);
			debug writeln("i:", i, " ans:", ans);
		}
	}

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


Orac is studying number theory, and he is interested in the properties of divisors.For two positive integers $$$a$$$ and $$$b$$$, $$$a$$$ is a divisor of $$$b$$$ if and only if there exists an integer $$$c$$$, such that $$$a\cdot c=b$$$.For $$$n \ge 2$$$, we will denote as $$$f(n)$$$ the smallest positive divisor of $$$n$$$, except $$$1$$$.For example, $$$f(7)=7,f(10)=2,f(35)=5$$$.For the fixed integer $$$n$$$, Orac decided to add $$$f(n)$$$ to $$$n$$$. For example, if he had an integer $$$n=5$$$, the new value of $$$n$$$ will be equal to $$$10$$$. And if he had an integer $$$n=6$$$, $$$n$$$ will be changed to $$$8$$$.Orac loved it so much, so he decided to repeat this operation several times.Now, for two positive integers $$$n$$$ and $$$k$$$, Orac asked you to add $$$f(n)$$$ to $$$n$$$ exactly $$$k$$$ times (note that $$$n$$$ will change after each operation, so $$$f(n)$$$ may change too) and tell him the final value of $$$n$$$.For example, if Orac gives you $$$n=5$$$ and $$$k=2$$$, at first you should add $$$f(5)=5$$$ to $$$n=5$$$, so your new value of $$$n$$$ will be equal to $$$n=10$$$, after that, you should add $$$f(10)=2$$$ to $$$10$$$, so your new (and the final!) value of $$$n$$$ will be equal to $$$12$$$.Orac may ask you these queries many times.

The first line of the input is a single integer $$$t\ (1\le t\le 100)$$$: the number of times that Orac will ask you. Each of the next $$$t$$$ lines contains two positive integers $$$n,k\ (2\le n\le 10^6, 1\le k\le 10^9)$$$, corresponding to a query by Orac. It is guaranteed that the total sum of $$$n$$$ is at most $$$10^6$$$.

Print $$$t$$$ lines, the $$$i$$$-th of them should contain the final value of $$$n$$$ in the $$$i$$$-th query by Orac.

NoteIn the first query, $$$n=5$$$ and $$$k=1$$$. The divisors of $$$5$$$ are $$$1$$$ and $$$5$$$, the smallest one except $$$1$$$ is $$$5$$$. Therefore, the only operation adds $$$f(5)=5$$$ to $$$5$$$, and the result is $$$10$$$.In the second query, $$$n=8$$$ and $$$k=2$$$. The divisors of $$$8$$$ are $$$1,2,4,8$$$, where the smallest one except $$$1$$$ is $$$2$$$, then after one operation $$$8$$$ turns into $$$8+(f(8)=2)=10$$$. The divisors of $$$10$$$ are $$$1,2,5,10$$$, where the smallest one except $$$1$$$ is $$$2$$$, therefore the answer is $$$10+(f(10)=2)=12$$$.In the third query, $$$n$$$ is changed as follows: $$$3 \to 6 \to 8 \to 10 \to 12$$$.

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

void main()
{
    auto arr = iota(1100000).array;
    foreach (e, i; arr) {
        if (e != i || i < 2) continue;
        for (int j = i + i; j < arr.length; j += i) {
            arr[j] = min(arr[j], i);
        }
    }

    uint t, n, k;
    scanf("%d", &t);
    while (t--) {
        scanf("%d%d", &n, &k);
        if (k > 0 && n % 2 == 1) {
          k--;
          n += arr[n];
        }
        n += 2 * k;
        writef!"%d\n"(n);
    }
}

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;
    auto ps = new long[](10^^6+1);
    foreach (i; 2..10^^6+1) if (ps[i] == 0) {
        ps[i] = i;
        auto x = i;
        while (x <= 10^^6) {
            if (ps[x] == 0) ps[x] = i;
            x += i;
        }
    }
    foreach (_t; 0..T) {
        auto nk = readln.split.to!(long[]);
        auto N = nk[0];
        auto K = nk[1];
        writeln(N + ps[N.to!size_t] + 2*(K-1));
    }
}

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!int;
		auto k = RD!int;

		long x = n;
		for (long i = 2; i*i <= n; ++i)
		{
			if (n % i == 0)
			{
				x = i;
				break;
			}
		}
		ans[ti] = n + x + 2 * (k-1);
	}

	foreach (e; ans)
		writeln(e);
	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;
    auto ps = new long[](10^^6+1);
    foreach (i; 2..10^^6+1) if (ps[i] == 0) {
        ps[i] = i;
        auto x = i;
        while (x <= 10^^6) {
            ps[x] = i;
            x += i;
        }
    }
    foreach (_t; 0..T) {
        auto nk = readln.split.to!(long[]);
        auto N = nk[0];
        auto K = nk[1];
        writeln(N + ps[N.to!size_t] + 2*(K-1));
    }
}


The only difference between this problem and D1 is that you don't have to provide the way to construct the answer in D1, but you have to do it in this problem.There's a table of $$$n \times m$$$ cells ($$$n$$$ rows and $$$m$$$ columns). The value of $$$n \cdot m$$$ is even.A domino is a figure that consists of two cells having a common side. It may be horizontal (one of the cells is to the right of the other) or vertical (one of the cells is above the other).You need to place $$$\frac{nm}{2}$$$ dominoes on the table so that exactly $$$k$$$ of them are horizontal and all the other dominoes are vertical. The dominoes cannot overlap and must fill the whole table.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of a single line. The line contains three integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$1 \le n,m \le 100$$$, $$$0 \le k \le \frac{nm}{2}$$$, $$$n \cdot m$$$ is even) — the count of rows, columns and horizontal dominoes, respectively.

For each test case:   print "NO" if it's not possible to place the dominoes on the table in the described way;  otherwise, print "YES" on a separate line, then print $$$n$$$ lines so that each of them contains $$$m$$$ lowercase letters of the Latin alphabet — the layout of the dominoes on the table. Each cell of the table must be marked by the letter so that for every two cells having a common side, they are marked by the same letters if and only if they are occupied by the same domino. I.e. both cells of the same domino must be marked with the same letter, but two dominoes that share a side must be marked with different letters. If there are multiple solutions, print any of them.

YES
accx
aegx
bega
bdda
YES
aha
aha
YES
zz
aa
zz
NO
YES
aaza
bbza
NO
YES
bbaabbaabbaabbaay
ddccddccddccddccy
NO

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

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

void printSolOdd(int n, int m, int k)
{
	k -= m/2;
	assert(k >= 0);
	foreach(i; 0 .. m)
	{
		int d = i/2;
		write(cast(char)('a' + (d&1)));
	}
	writeln;
	printSolEven(n - 1, m, k);
}
void printSolEven(int n, int m, int k)
{
	char[][] solution = new char[][](n, m);
	foreach(j; 0 .. m/2)
	{
		foreach(i; 0 .. n/2)
		{
			if (k > 0)
			{
				int num = (j)&1;
				solution[2*i][2*j] = solution[2*i][2*j+1] = cast(char)('c' + num);
				solution[2*i+1][2*j] = solution[2*i+1][2*j+1] = cast(char)('c' + (num^1));
				k -= 2;
			}
		}
	}
	foreach(i; 0 .. n/2)
	{
		foreach(j; 0 .. m)
		{
			if (solution[2*i][j] == char.init)
			{
				assert(solution[2*i+1][j] == char.init);
				solution[2*i][j] = solution[2*i+1][j] = cast(char)('f'+((i+j)&1));
			}
		}
	}
	foreach(row; solution)
	{
		writeln(row);
	}
}

void solve()
{
	int n = readInt!int;
	int m = readInt!int;
	int k = readInt!int;
	if (n&1)
	{
		int g = m/2;
		int parity = g&1;
		if ((k&1) != parity)
		{
			return writeln("NO");
		}
		int mx = g * n;
		if (k > mx || k < g) return writeln("NO");
		writeln("YES");
		printSolOdd(n, m, k);
	}
	else
	{
		if (k&1) return writeln("NO");
		int g = m/2;
		int mx = g * n;
		if (k > mx) return writeln("NO");
		writeln("YES");
		printSolEven(n, m, k);
	}
}

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

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

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

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

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

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

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

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

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

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

void printSolOdd(int n, int m, int k)
{
	k -= m/2;
	assert(k >= 0);
	foreach(i; 0 .. m)
	{
		int d = i/2;
		write(cast(char)('a' + (d&1)));
	}
	writeln;
	printSolEven(n - 1, m, k);
}
void printSolEven(int n, int m, int k)
{
	char[][] solution = new char[][](n, m);
	foreach(j; 0 .. m/2)
	{
		foreach(i; 0 .. n/2)
		{
			if (k > 0)
			{
				int num = (j)&1;
				solution[2*i][2*j] = solution[2*i][2*j+1] = cast(char)('c' + num);
				solution[2*i+1][2*j] = solution[2*i+1][2*j+1] = cast(char)('c' + (num^1));
				k -= 2;
			}
		}
	}
	foreach(i; 0 .. n/2)
	{
		foreach(j; 0 .. m)
		{
			if (solution[2*i][j] == char.init)
			{
				assert(solution[2*i+1][j] == char.init);
				solution[2*i][j] = solution[2*i+1][j] = cast(char)('f'+((i+j)&1));
			}
		}
	}
	foreach(row; solution)
	{
		writeln(row);
	}
}

void solve()
{
	int n = readInt!int;
	int m = readInt!int;
	int k = readInt!int;
	if (n&1)
	{
		int g = m/2;
		int parity = g&1;
		if ((k&1) != parity)
		{
			return writeln("no");
		}
		int mx = g * n;
		if (k > mx || k < g) return writeln("no");
		writeln("yes");
		printSolOdd(n, m, k);
	}
	else
	{
		if (k&1) return writeln("no");
		int g = m/2;
		int mx = g * n;
		if (k > mx) return writeln("no");
		writeln("yes");
		printSolEven(n, m, k);
	}
}

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

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

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

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

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

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

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

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


Vova again tries to play some computer card game.The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number ai is written on the i-th card in the deck.After receiving the deck and the magic number, Vova removes x (possibly x = 0) cards from the top of the deck, y (possibly y = 0) cards from the bottom of the deck, and the rest of the deck is his new deck (Vova has to leave at least one card in the deck after removing cards). So Vova's new deck actually contains cards x + 1, x + 2, ... n - y - 1, n - y from the original deck.Vova's new deck is considered valid iff the product of all numbers written on the cards in his new deck is divisible by k. So Vova received a deck (possibly not a valid one) and a number k, and now he wonders, how many ways are there to choose x and y so the deck he will get after removing x cards from the top and y cards from the bottom is valid?

The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers written on the cards.

Print the number of ways to choose x and y so the resulting deck is valid.

NoteIn the first example the possible values of x and y are:  x = 0, y = 0;  x = 1, y = 0;  x = 2, y = 0;  x = 0, y = 1.

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

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

    int p;
    int[] primes;
    int[] primes_n;
    foreach (i; 2..10^^5) {
        if (K % i == 0) {
            p += 1;
            primes ~= i;
            primes_n ~= 0;
        }
        while (K % i == 0) {
            K /= i;
            primes_n[p-1] += 1;
        }
    }
    if (K > 1) {
        p += 1;
        primes ~= K;
        primes_n ~= 1;
    }

    auto cumsum = new int[][](N+1, p);
    foreach (i; 0..N) {
        auto k = A[i];
        foreach (j; 0..p) {
            while (k % primes[j] == 0) {
                cumsum[i+1][j] += 1;
                k /= primes[j];
            }
        }
    }

    foreach (i; 0..N) {
        cumsum[i+1][] += cumsum[i][];
    }

    long ans = 0;
    auto cs = new int[](p);

    foreach (i; 0..N) {
        int hi = N;
        int lo = i - 1;
        while (hi - lo > 1) {
            int mid = (hi + lo) / 2;
            cs[] = cumsum[mid + 1][] - cumsum[i][];
            if (p.iota.map!(i => cs[i] >= primes_n[i]).all) hi = mid;
            else lo = mid;
        }
        ans += max(N - lo - 1, 0);
    }

    ans.writeln;
}

// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

int n, k;
int[] a;

void main() {
    scan(n, k);
    a = readln.split.to!(int[]);

    if (k == 1) {
        writeln(1L * n * (n + 1) / 2L);
        return;
    }

    auto p = new int[](0);
    auto q = new int[](0);

    for (int d = 2; d*d <= k; d++) {
        if (k % d == 0) {
            p ~= d;
            int cnt = 0;

            while (k % d == 0) {
                cnt++;
                k /= d;
            }

            q ~= cnt;
        }
    }

    if (k > 1) {
        p ~= k;
        q ~= 1;
    }

    debug {
        writeln("p:", p);
        writeln("q:", q);
    }

    int m = p.length.to!int;

    auto div = new int[][](n, m);

    foreach (i ; 0 .. n) {
        foreach (j ; 0 .. m) {
            while (a[i] % p[j] == 0) {
                div[i][j]++;
                a[i] /= p[j];
            }
        }
    }

    debug {
        writefln("%(%(%s %)\n%)", div);
    }

    auto cnt = new int[](m);
    long ans;

    for (int l, r; r < n + 1; l++) {
        for (; r < n + 1; r++) {
            if (iota(m).all!(i => cnt[i] >= q[i])) {
                ans += n + 1 - r;
                break;
            }
            else {
                if (r == n) {
                    writeln(ans);
                    return;
                }

                cnt[] += div[r][];
            }
        }

        cnt[] -= div[l][];
    }

    writeln(ans);
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

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

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

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);
  auto n = next!int;
  auto k = next!int;
  auto a = next!long(n);
  foreach(ref ai; a) ai %= k;
  long mul(long a1, long a2)
  {
    return (a1 * a2) % k;
  }
  auto st = SegmentTree!(long, mul, "mul")(a);
  debug st.mul(0, 0).writeln;
  long ways = 0;
  foreach(i; 0 .. n)
    {
      bool divides(int j) {return st.mul(i, j) == 0;}
      auto end = firstThat!divides(i, n - 1);
      debug writeln("for ", i, " is ", end);
      ways += n - end;
    }
  ways.writeln;
}

// BIN SEARCH
auto firstThat(alias pred, T)(T i, T j)
{
  T first = j + 1;
  while(i <= j)
    {
      debug writeln(i, " ", j);
      auto mid = (i + j) / 2;
      if (pred(mid))
	{
	  first = mid;
	  j = mid - 1;
	}
      else
	{
	  i = mid + 1;
	}
    }
  return first;
}

// Segment Tree
struct SegmentTree(T, alias f, string getMethodName = "get")
{
  static assert(is(typeof((){T x, y; return f(x, y);}()) == T));
  class Node
  {
    size_t low, high;
    size_t length() {return high - low + 1;}
    this(size_t l, size_t h)
    {
      low = l;
      high = h;
    }
    T fValue;
    Node firstHalf, secondHalf;
    bool contains(size_t i, size_t j)
    {
      return max(low, i) <= min(high, j);
    }
    bool inside(size_t i, size_t j)
    {
      return i <= low && high <= j;
    }
  }
  Node _root;
  this(T[] arr)
  {
    _root = new Node(0, arr.length - 1);
    void fill(Node node)
    {
      if (node.length == 1) {node.fValue = arr[node.low]; return;}
      size_t mid = (node.low + node.high) / 2;
      node.firstHalf = new Node(node.low, mid);
      fill(node.firstHalf);
      node.secondHalf = new Node(mid + 1, node.high);
      fill(node.secondHalf);
      node.fValue = f(node.firstHalf.fValue, node.secondHalf.fValue);
    }
    fill(_root);
  }
  mixin(q{alias }, getMethodName, q{ = fRange;});
  T fRange(size_t i, size_t j, Node node = null)
  {
    if (node is null) node = _root;
    debug assert(node !is null);
    debug assert(node.contains(i, j), text(node.low, " ", node.high, " ", i, " ", j));
    if (node.inside(i, j)) return node.fValue;

    debug assert((node.firstHalf !is null && node.firstHalf.contains(i, j))
		 || (node.secondHalf !is null && node.secondHalf.contains(i, j)));

    if (node.firstHalf !is null && node.firstHalf.contains(i, j))
      {
	if (node.secondHalf !is null && node.secondHalf.contains(i, j))
	  return f(fRange(i, j, node.firstHalf), fRange(i, j, node.secondHalf));
	return fRange(i, j, node.firstHalf);
      }
    else
      {
	debug assert(node.secondHalf !is null && node.secondHalf.contains(i, j));
	return fRange(i, j, node.secondHalf);
      }
  }
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

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

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);
  auto n = next!int;
  auto k = next!long;
  auto a = next!long(n);
  foreach(ref ai; a) ai %= k;
  auto st = SegmentTree!(long, (x, y) => (x * y) % k, "mul")(a);
  iota(0, n)
    .map!(i => cast(long)n - firstThat!(j => st.mul(i, j) == 0)(i, n - 1))
    .sum
    .writeln;
}

// BIN SEARCH
auto firstThat(alias pred, T)(T i, T j)
{
  T first = j + 1;
  while(i <= j)
    {
      auto mid = (i + j) / 2;
      if (pred(mid))
	{
	  first = mid;
	  j = mid - 1;
	}
      else
	{
	  i = mid + 1;
	}
    }
  return first;
}

// Segment Tree
struct SegmentTree(T, alias f, string getMethodName = "get")
{
  static assert(is(typeof((){T x, y; return f(x, y);}()) == T));
  class Node
  {
    size_t low, high;
    size_t length() {return high - low + 1;}
    this(size_t l, size_t h)
    {
      low = l;
      high = h;
    }
    T fValue;
    Node firstHalf, secondHalf;
    bool contains(size_t i, size_t j)
    {
      return max(low, i) <= min(high, j);
    }
    bool inside(size_t i, size_t j)
    {
      return i <= low && high <= j;
    }
  }
  Node _root;
  this(T[] arr)
  {
    _root = new Node(0, arr.length - 1);
    void fill(Node node)
    {
      if (node.length == 1) {node.fValue = arr[node.low]; return;}
      size_t mid = (node.low + node.high) / 2;
      node.firstHalf = new Node(node.low, mid);
      fill(node.firstHalf);
      node.secondHalf = new Node(mid + 1, node.high);
      fill(node.secondHalf);
      node.fValue = f(node.firstHalf.fValue, node.secondHalf.fValue);
    }
    fill(_root);
  }
  mixin(q{alias }, getMethodName, q{ = fRange;});
  T fRange(size_t i, size_t j, Node node = null)
  {
    if (node is null) node = _root;
    debug assert(node !is null);
    debug assert(node.contains(i, j), text(node.low, " ", node.high, " ", i, " ", j));
    if (node.inside(i, j)) return node.fValue;

    debug assert((node.firstHalf !is null && node.firstHalf.contains(i, j))
		 || (node.secondHalf !is null && node.secondHalf.contains(i, j)));

    if (node.firstHalf !is null && node.firstHalf.contains(i, j))
      {
	if (node.secondHalf !is null && node.secondHalf.contains(i, j))
	  return f(fRange(i, j, node.firstHalf), fRange(i, j, node.secondHalf));
	return fRange(i, j, node.firstHalf);
      }
    else
      {
	debug assert(node.secondHalf !is null && node.secondHalf.contains(i, j));
	return fRange(i, j, node.secondHalf);
      }
  }
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

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

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

    int p;
    int[] primes;
    int[] primes_n;
    foreach (i; 2..10^^5) {
        if (K % i == 0) {
            p += 1;
            primes ~= i;
            primes_n ~= 0;
        }
        while (K % i == 0) {
            K /= i;
            primes_n[p-1] += 1;
        }
    }

    auto cumsum = new int[][](N+1, p);
    foreach (i; 0..N) {
        auto k = A[i];
        foreach (j; 0..p) {
            while (k % primes[j] == 0) {
                cumsum[i+1][j] += 1;
                k /= primes[j];
            }
        }
    }

    foreach (i; 0..N) {
        cumsum[i+1][] += cumsum[i][];
    }

    long ans = 0;
    auto cs = new int[](p);

    foreach (i; 0..N) {
        int hi = N;
        int lo = i - 1;
        while (hi - lo > 1) {
            int mid = (hi + lo) / 2;
            cs[] = cumsum[mid + 1][] - cumsum[i][];
            if (p.iota.map!(i => cs[i] >= primes_n[i]).all) hi = mid;
            else lo = mid;
        }
        ans += max(N - lo - 1, 0);
    }

    ans.writeln;
}

// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

int n, k;
long[] a;

void main() {
    scan(n, k);

    if (k == 1) {
        writeln(1L * n * (n + 1) / 2L);
        return;
    }

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

    auto sg = new SegTree!(long)(a, k);

    long ans;

    foreach (i ; 0 .. n) {
        if (sg.find(i, n, 0, 0, 2^^sg.depth) != 0) break;
        int btm = i, top = n, mid;

        while (top - btm > 1) {
            mid = (top + btm) / 2;

            if (sg.find(i, mid, 0, 0, 2^^sg.depth) == 0) {
                top = mid;
            }
            else {
                btm = mid;
            }
        }

        ans += n + 1 - top;
    }

    writeln(ans);
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

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

class SegTree(T){
private:
    T[] data;
    int N;
    long mod;
    int depth;

public:
    //int depth;

    this(T[] a, long k){
        N = a.length.to!int;
        mod = k;

        while(2^^depth < N){
            depth++;
        }

        data = new T[](2^^(depth + 1) - 1);

        data[] = 1L;
        data[2^^depth - 1 .. 2^^depth - 1 + N] = a[];

        foreach_reverse (i ; 0 .. 2^^depth - 1) {
            data[i] = 1L * data[2*i + 1] * data[2*i + 2] % mod;
        }
    }

    void update(int i, T x){
        i += 2^^depth - 1;
        data[i] = x;

        while(i > 0){
            i = (i - 1) / 2;
            data[i] = 1L * data[2*i + 1] * data[2*i + 2] % mod;
        }
    }

    T find(int s, int t, int k, int l, int r){
        if (r <= s || t <= l) {
            return 1L;
        }

        if (s <= l && r <= t) {
            return data[k];
        }

        auto vl = find(s, t, 2*k + 1, l, (l + r) / 2);
        auto vr = find(s, t, 2*k + 2, (l + r) / 2, r);

        return 1L * vl * vr % mod;
    }

    void print(){
        stderr.writefln("%(%s %)", data);
    }
}

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

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);
  auto n = next!int;
  auto k = next!int;
  auto a = next!long(n);
  foreach(ref ai; a) ai %= k;
  auto st = SegmentTree!(long, (x, y) => (x * y) % k, "mul")(a);
  iota(0, n)
    .map!(i => n - firstThat!(j => st.mul(i, j) == 0)(i, n - 1))
    .sum
    .writeln;
}

// BIN SEARCH
auto firstThat(alias pred, T)(T i, T j)
{
  T first = j + 1;
  while(i <= j)
    {
      auto mid = (i + j) / 2;
      if (pred(mid))
	{
	  first = mid;
	  j = mid - 1;
	}
      else
	{
	  i = mid + 1;
	}
    }
  return first;
}

// Segment Tree
struct SegmentTree(T, alias f, string getMethodName = "get")
{
  static assert(is(typeof((){T x, y; return f(x, y);}()) == T));
  class Node
  {
    size_t low, high;
    size_t length() {return high - low + 1;}
    this(size_t l, size_t h)
    {
      low = l;
      high = h;
    }
    T fValue;
    Node firstHalf, secondHalf;
    bool contains(size_t i, size_t j)
    {
      return max(low, i) <= min(high, j);
    }
    bool inside(size_t i, size_t j)
    {
      return i <= low && high <= j;
    }
  }
  Node _root;
  this(T[] arr)
  {
    _root = new Node(0, arr.length - 1);
    void fill(Node node)
    {
      if (node.length == 1) {node.fValue = arr[node.low]; return;}
      size_t mid = (node.low + node.high) / 2;
      node.firstHalf = new Node(node.low, mid);
      fill(node.firstHalf);
      node.secondHalf = new Node(mid + 1, node.high);
      fill(node.secondHalf);
      node.fValue = f(node.firstHalf.fValue, node.secondHalf.fValue);
    }
    fill(_root);
  }
  mixin(q{alias }, getMethodName, q{ = fRange;});
  T fRange(size_t i, size_t j, Node node = null)
  {
    if (node is null) node = _root;
    debug assert(node !is null);
    debug assert(node.contains(i, j), text(node.low, " ", node.high, " ", i, " ", j));
    if (node.inside(i, j)) return node.fValue;

    debug assert((node.firstHalf !is null && node.firstHalf.contains(i, j))
		 || (node.secondHalf !is null && node.secondHalf.contains(i, j)));

    if (node.firstHalf !is null && node.firstHalf.contains(i, j))
      {
	if (node.secondHalf !is null && node.secondHalf.contains(i, j))
	  return f(fRange(i, j, node.firstHalf), fRange(i, j, node.secondHalf));
	return fRange(i, j, node.firstHalf);
      }
    else
      {
	debug assert(node.secondHalf !is null && node.secondHalf.contains(i, j));
	return fRange(i, j, node.secondHalf);
      }
  }
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

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

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);
  auto n = next!int;
  auto k = next!long;
  auto a = next!long(n);
  foreach(ref ai; a) ai %= k;
  auto st = SegmentTree!(long, (x, y) => (x * y) % k, "mul")(a);
  iota(0, n)
    .map!(i => n - firstThat!(j => st.mul(i, j) == 0)(i, n - 1))
    .sum
    .writeln;
}

// BIN SEARCH
auto firstThat(alias pred, T)(T i, T j)
{
  T first = j + 1;
  while(i <= j)
    {
      auto mid = (i + j) / 2;
      if (pred(mid))
	{
	  first = mid;
	  j = mid - 1;
	}
      else
	{
	  i = mid + 1;
	}
    }
  return first;
}

// Segment Tree
struct SegmentTree(T, alias f, string getMethodName = "get")
{
  static assert(is(typeof((){T x, y; return f(x, y);}()) == T));
  class Node
  {
    size_t low, high;
    size_t length() {return high - low + 1;}
    this(size_t l, size_t h)
    {
      low = l;
      high = h;
    }
    T fValue;
    Node firstHalf, secondHalf;
    bool contains(size_t i, size_t j)
    {
      return max(low, i) <= min(high, j);
    }
    bool inside(size_t i, size_t j)
    {
      return i <= low && high <= j;
    }
  }
  Node _root;
  this(T[] arr)
  {
    _root = new Node(0, arr.length - 1);
    void fill(Node node)
    {
      if (node.length == 1) {node.fValue = arr[node.low]; return;}
      size_t mid = (node.low + node.high) / 2;
      node.firstHalf = new Node(node.low, mid);
      fill(node.firstHalf);
      node.secondHalf = new Node(mid + 1, node.high);
      fill(node.secondHalf);
      node.fValue = f(node.firstHalf.fValue, node.secondHalf.fValue);
    }
    fill(_root);
  }
  mixin(q{alias }, getMethodName, q{ = fRange;});
  T fRange(size_t i, size_t j, Node node = null)
  {
    if (node is null) node = _root;
    debug assert(node !is null);
    debug assert(node.contains(i, j), text(node.low, " ", node.high, " ", i, " ", j));
    if (node.inside(i, j)) return node.fValue;

    debug assert((node.firstHalf !is null && node.firstHalf.contains(i, j))
		 || (node.secondHalf !is null && node.secondHalf.contains(i, j)));

    if (node.firstHalf !is null && node.firstHalf.contains(i, j))
      {
	if (node.secondHalf !is null && node.secondHalf.contains(i, j))
	  return f(fRange(i, j, node.firstHalf), fRange(i, j, node.secondHalf));
	return fRange(i, j, node.firstHalf);
      }
    else
      {
	debug assert(node.secondHalf !is null && node.secondHalf.contains(i, j));
	return fRange(i, j, node.secondHalf);
      }
  }
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

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

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);
  auto n = next!int;
  auto k = next!int;
  auto a = next!int(n);
  foreach(ref ai; a) ai %= k;
  int mul(int a1, int a2)
  {
    return (a1 * a2) % k;
  }
  auto st = SegmentTree!(int, mul, "mul")(a);
  debug st.mul(0, 0).writeln;
  long ways = 0;
  foreach(i; 0 .. n)
    {
      bool divides(int j) {return st.mul(i, j) == 0;}
      auto end = firstThat!divides(i, n - 1);
      debug writeln("for ", i, " is ", end);
      ways += n - end;
    }
  ways.writeln;
}

// BIN SEARCH
auto firstThat(alias pred, T)(T i, T j)
{
  T first = j + 1;
  while(i <= j)
    {
      debug writeln(i, " ", j);
      auto mid = (i + j) / 2;
      if (pred(mid))
	{
	  first = mid;
	  j = mid - 1;
	}
      else
	{
	  i = mid + 1;
	}
    }
  return first;
}

// Segment Tree
struct SegmentTree(T, alias f, string getMethodName = "get")
{
  static assert(is(typeof((){T x, y; return f(x, y);}()) == T));
  class Node
  {
    size_t low, high;
    size_t length() {return high - low + 1;}
    this(size_t l, size_t h)
    {
      low = l;
      high = h;
    }
    T fValue;
    Node firstHalf, secondHalf;
    bool contains(size_t i, size_t j)
    {
      return max(low, i) <= min(high, j);
    }
    bool inside(size_t i, size_t j)
    {
      return i <= low && high <= j;
    }
  }
  Node _root;
  this(T[] arr)
  {
    _root = new Node(0, arr.length - 1);
    void fill(Node node)
    {
      if (node.length == 1) {node.fValue = arr[node.low]; return;}
      size_t mid = (node.low + node.high) / 2;
      node.firstHalf = new Node(node.low, mid);
      fill(node.firstHalf);
      node.secondHalf = new Node(mid + 1, node.high);
      fill(node.secondHalf);
      node.fValue = f(node.firstHalf.fValue, node.secondHalf.fValue);
    }
    fill(_root);
  }
  mixin(q{alias }, getMethodName, q{ = fRange;});
  T fRange(size_t i, size_t j, Node node = null)
  {
    if (node is null) node = _root;
    debug assert(node !is null);
    debug assert(node.contains(i, j), text(node.low, " ", node.high, " ", i, " ", j));
    if (node.inside(i, j)) return node.fValue;

    debug assert((node.firstHalf !is null && node.firstHalf.contains(i, j))
		 || (node.secondHalf !is null && node.secondHalf.contains(i, j)));

    if (node.firstHalf !is null && node.firstHalf.contains(i, j))
      {
	if (node.secondHalf !is null && node.secondHalf.contains(i, j))
	  return f(fRange(i, j, node.firstHalf), fRange(i, j, node.secondHalf));
	return fRange(i, j, node.firstHalf);
      }
    else
      {
	debug assert(node.secondHalf !is null && node.secondHalf.contains(i, j));
	return fRange(i, j, node.secondHalf);
      }
  }
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}


You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?Let's assume that the rows of matrix a are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. A matrix cell on the intersection of the i-th row and the j-th column can be represented as (i, j). Formally, a submatrix of matrix a is a group of four integers d, u, l, r (1 ≤ d ≤ u ≤ n; 1 ≤ l ≤ r ≤ m). We will assume that the submatrix contains cells (i, j) (d ≤ i ≤ u; l ≤ j ≤ r). The area of the submatrix is the number of cells it contains.

The first line contains two integers n and m (1 ≤ n, m ≤ 5000). Next n lines contain m characters each — matrix a. Matrix a only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines.

Print a single integer — the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0.

import std.stdio, std.string;

void solve(int n, int m, char[][] mat)
{
    auto cnt = new int[m + 1];
    auto len = new int[n];
    auto prelen = new int[n];
    int ans = 0;
    foreach (i; 0 .. m)
    {
        int[] modify;
        foreach (j; 0 .. n)
        {
            len[j] = 0;
            if (mat[j][i] == '1')
            {
                if (prelen[j])
                {
                    len[j] = prelen[j] + 1;
                }
                else
                {
                    len[j] = 1;
                }
            }
            if (!cnt[len[j]]) modify ~= len[j];
            ++ cnt[len[j]];
        }
        int count = 0;
        for (int j = i + 1; j > 0; -- j)
        {
            if (cnt[j])
            {
                count += cnt[j];
                if (j * count > ans) ans = j * count;
            }
        }
        foreach (val; modify) cnt[val] = 0;
        foreach (j; 0 .. n) prelen[j] = len[j];
    }
    writeln(ans);
}

void main(string[] args)
{
    int n, m;
    while (scanf("%d%d", &n, &m) == 2)
    {
        auto mat = new char[][n];
        stdin.readln(mat[0]);
        foreach (i; 0 .. n) stdin.readln(mat[i]);
        solve(n, m, mat);
    }
}

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

void solve(int n, int m, char[][] mat)
{
    auto cnt = new int[m + 1];
    auto len = new int[n];
    auto prelen = new int[n];
    int ans = 0;
    foreach (i; 0 .. m)
    {
        //int[] modify;
        foreach (j; 0 .. n)
        {
            len[j] = 0;
            if (mat[j][i] == '1')
            {
                if (prelen[j])
                {
                    len[j] = prelen[j] + 1;
                }
                else
                {
                    len[j] = 1;
                }
            }
            //if (!cnt[len[j]]) modify ~= len[j];
            ++ cnt[len[j]];
        }
        int count = 0;
        for (int j = i + 1; j > 0; -- j)
        {
            if (cnt[j])
            {
                count += cnt[j];
                if (j * count > ans) ans = j * count;
            }
        }
        fill(cnt, 0);
        //foreach (val; modify) cnt[val] = 0;
        foreach (j; 0 .. n) prelen[j] = len[j];
    }
    writeln(ans);
}

void main(string[] args)
{
    int n, m;
    while (scanf("%d%d", &n, &m) == 2)
    {
        auto mat = new char[][n];
        stdin.readln(mat[0]);
        foreach (i; 0 .. n) stdin.readln(mat[i]);
        solve(n, m, mat);
    }
}

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

void solve(int n, int m, char[][] mat)
{
    auto cnt = new int[m + 1];
    auto len = new int[n];
    auto prelen = new int[n];
    auto modify = new int[m + 1];
    int ans = 0;
    foreach (i; 0 .. m)
    {
        //int[] modify;
        int midx = 0;
        foreach (j; 0 .. n)
        {
            len[j] = 0;
            if (mat[j][i] == '1')
            {
                len[j] = 1;
                if (prelen[j])
                {
                    len[j] += prelen[j];
                }
            }
            if (!cnt[len[j]]) modify[midx ++] = len[j];
            ++ cnt[len[j]];
        }
        int count = 0;
        for (int j = i + 1; j > 0; -- j)
        {
            if (cnt[j])
            {
                count += cnt[j];
                if (j * count > ans) ans = j * count;
            }
        }
        //fill(cnt, 0);
        for (int j = 0; j < midx; ++ j) cnt[modify[j]] = 0;
        //foreach (val; modify) cnt[val] = 0;
        foreach (j; 0 .. n) prelen[j] = len[j];
    }
    writeln(ans);
}

void main(string[] args)
{
    int n, m;
    while (scanf("%d%d", &n, &m) == 2)
    {
        auto mat = new char[][n];
        stdin.readln(mat[0]);
        foreach (i; 0 .. n) stdin.readln(mat[i]);
        solve(n, m, mat);
    }
}

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

void main ()
{
	int n, m;
	while (readf (" %s %s ", &n, &m) > 0)
	{
		auto a = new string [n];
		foreach (i; 0..n)
		{
			a[i] = readln ().strip ();
		}

		auto b = new int [] [] (m, n);
		foreach (j; 0..m)
		{
			foreach (i; 0..n)
			{
				b[j][i] = a[i][j] - '0';
			}
		}

		int res = 0;
		auto c = new int [m + 1];
		foreach (j; 0..m)
		{
			foreach (i; 0..n)
			{
				if (b[j][i] != 0)
				{
					if (j > 0)
					{
						b[j][i] = b[j - 1][i] + 1;
					}
				}
			}

			c[] = 0;
			foreach (i; 0..n)
			{
				c[b[j][i]]++;
			}

			int w;
			int h = 0;
			foreach_reverse (k; 0..m + 1)
			{
				foreach (q; 0..c[k])
				{
					w = k;
					h++;
					debug {writeln (w, ' ', h);}
					res = max (res, w * h);
				}
			}
		}

		writeln (res);
	}
}


Polycarp got an array of integers $$$a[1 \dots n]$$$ as a gift. Now he wants to perform a certain number of operations (possibly zero) so that all elements of the array become the same (that is, to become $$$a_1=a_2=\dots=a_n$$$). In one operation, he can take some indices in the array and increase the elements of the array at those indices by $$$1$$$.For example, let $$$a=[4,2,1,6,2]$$$. He can perform the following operation: select indices 1, 2, and 4 and increase elements of the array in those indices by $$$1$$$. As a result, in one operation, he can get a new state of the array $$$a=[5,3,1,7,2]$$$.What is the minimum number of operations it can take so that all elements of the array become equal to each other (that is, to become $$$a_1=a_2=\dots=a_n$$$)?

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)  — the number of test cases in the test. The following are descriptions of the input test cases. The first line of the description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$)  — the array $$$a$$$. The second line of the description of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)  — elements of the array $$$a$$$.

For each test case, print one integer  — the minimum number of operations to make all elements of the array $$$a$$$ equal.

NoteFirst test case:   $$$a=[3,4,2,4,1,2]$$$ take $$$a_3, a_5$$$ and perform an operation plus one on them, as a result we get $$$a=[3,4,3,4,2,2]$$$.  $$$a=[3,4,3,4,2,2]$$$ we take $$$a_1, a_5, a_6$$$ and perform an operation on them plus one, as a result we get $$$a=[4,4,3,4,3,3]$$$.  $$$a=[4,4,3,4,3,3]$$$ we take $$$a_3, a_5, a_6$$$ and perform an operation on them plus one, as a result we get $$$a=[4,4,4,4,4,4]$$$. There are other sequences of $$$3$$$ operations, after the application of which all elements become equal.Second test case:   $$$a=[1000,1002,998]$$$ 2 times we take $$$a_1, a_3$$$ and perform an operation plus one on them, as a result we get $$$a=[1002,1002,1000]$$$.  $$$a=[1002,1002,1000]$$$ also take $$$a_3$$$ 2 times and perform an operation plus one on it, as a result we get $$$a=[1002,1002,1002]$$$. Third test case:   $$$a=[12,11]$$$ take $$$a_2$$$ and perform an operation plus one on it, as a result we get $$$a=[12,12]$$$.

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

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    long n;
    readf!" %d "(n);
    auto a = readln.splitter.map!(to!long).array;
    writeln(a.maxElement - a.minElement);
  }
}

import std;

void main () {
    immutable tests = (){ uint t; readf!"%s\n"(t); return t; }();

    foreach (test_index; 0 .. tests) {
        readln();
        const pair =
            readln.chomp
            .split(' ')
            .map!(str => to!int(str))
            .fold!(min, max);

        writeln(pair[1] - pair[0]);
    }
}
// ""

void main() { runSolver(); }

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

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

      (A.maxElement - A.minElement).writeln;
    }
  }

  outputForAtCoder(&solve);
}

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

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

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


There is a city that can be represented as a square grid with corner points in $$$(0, 0)$$$ and $$$(10^6, 10^6)$$$.The city has $$$n$$$ vertical and $$$m$$$ horizontal streets that goes across the whole city, i. e. the $$$i$$$-th vertical streets goes from $$$(x_i, 0)$$$ to $$$(x_i, 10^6)$$$ and the $$$j$$$-th horizontal street goes from $$$(0, y_j)$$$ to $$$(10^6, y_j)$$$. All streets are bidirectional. Borders of the city are streets as well.There are $$$k$$$ persons staying on the streets: the $$$p$$$-th person at point $$$(x_p, y_p)$$$ (so either $$$x_p$$$ equal to some $$$x_i$$$ or $$$y_p$$$ equal to some $$$y_j$$$, or both).Let's say that a pair of persons form an inconvenient pair if the shortest path from one person to another going only by streets is strictly greater than the Manhattan distance between them.Calculate the number of inconvenient pairs of persons (pairs $$$(x, y)$$$ and $$$(y, x)$$$ are the same pair).Let's recall that Manhattan distance between points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 \le n, m \le 2 \cdot 10^5$$$; $$$2 \le k \le 3 \cdot 10^5$$$) — the number of vertical and horizontal streets and the number of persons. The second line of each test case contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$0 = x_1 < x_2 < \dots < x_{n - 1} < x_n = 10^6$$$) — the $$$x$$$-coordinates of vertical streets. The third line contains $$$m$$$ integers $$$y_1, y_2, \dots, y_m$$$ ($$$0 = y_1 < y_2 < \dots < y_{m - 1} < y_m = 10^6$$$) — the $$$y$$$-coordinates of horizontal streets. Next $$$k$$$ lines contains description of people. The $$$p$$$-th line contains two integers $$$x_p$$$ and $$$y_p$$$ ($$$0 \le x_p, y_p \le 10^6$$$; $$$x_p \in \{x_1, \dots, x_n\}$$$ or $$$y_p \in \{y_1, \dots, y_m\}$$$) — the coordinates of the $$$p$$$-th person. All points are distinct. It guaranteed that sum of $$$n$$$ doesn't exceed $$$2 \cdot 10^5$$$, sum of $$$m$$$ doesn't exceed $$$2 \cdot 10^5$$$ and sum of $$$k$$$ doesn't exceed $$$3 \cdot 10^5$$$.

For each test case, print the number of inconvenient pairs.

NoteThe second test case is pictured below:   For example, points $$$3$$$ and $$$4$$$ form an inconvenient pair, since the shortest path between them (shown red and equal to $$$7$$$) is greater than its Manhattan distance (equal to $$$5$$$).Points $$$3$$$ and $$$5$$$ also form an inconvenient pair: the shortest path equal to $$$1000001$$$ (shown green) is greater than the Manhattan distance equal to $$$999999$$$.But points $$$5$$$ and $$$9$$$ don't form an inconvenient pair, since the shortest path (shown purple) is equal to its Manhattan distance.

immutable multi = true;

int[1_000_000+1] visX, visY;

void solve(int tc)
{
	tc++;
	auto n = readInt!int;
	auto m = readInt!int;
	auto k = readInt!int;
	auto x = ma(n, readInt!int);
	foreach(xi; x) visX[xi] = tc;
	auto y = ma(m, readInt!int);
	foreach(yi; y) visY[yi] = tc;
	int[][] xgroups = new int[][](n);
	int[][] ygroups = new int[][](m);
	foreach(i; 0 .. k)
	{
		auto xp = readInt!int;
		auto yp = readInt!int;
		debug writeln("read person ", xp, " ", yp);
		auto onX = visX[xp] == tc;
		auto onY = visY[yp] == tc;
		if (onX && onY) continue;
		debug writeln("putting on group");
		assert(onX || onY);
		if (onX)
		{
			auto posY = assumeSorted(y).lowerBound(yp).length;
			assert(posY >= 1);
			ygroups[posY] ~= xp;
		}
		else
		{
			auto posX = assumeSorted(x).lowerBound(xp).length;
			assert(posX >= 1);
			xgroups[posX] ~= yp;
		}
	}
	foreach(ref seq; xgroups) sort(seq);
	foreach(ref seq; ygroups) sort(seq);
	long ans = 0;
	foreach(seq; xgroups)
	{
		debug writeln("current seq ", seq);
		int i = 0;
		int total = cast(int)seq.length;
		for (;i < seq.length; i++)
		{
			auto currY = seq[i];
			assert(visY[currY] == tc);
			int blk = 1;
			while (i+1 < seq.length && seq[i+1] == currY)
			{ i++; blk++; }
			int nonblk = total - blk;
			assert(nonblk >= 0);
			ans += cast(long)blk * cast(long)nonblk;
		}
	}
	foreach(seq; ygroups)
	{
		int i = 0;
		int total = cast(int)seq.length;
		for (;i < seq.length; i++)
		{
			auto currX = seq[i];
			assert(visX[currX] == tc);
			int blk = 1;
			while (i+1 < seq.length && seq[i+1] == currX)
			{ i++; blk++; }
			int nonblk = total - blk;
			assert(nonblk >= 0);
			ans += cast(long)blk * cast(long)nonblk;
		}
	}
	assert(ans % 2 == 0);
	writeln(ans/2);
}

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