Alicia has an array, $$$a_1, a_2, \ldots, a_n$$$, of non-negative integers. For each $$$1 \leq i \leq n$$$, she has found a non-negative integer $$$x_i = max(0, a_1, \ldots, a_{i-1})$$$. Note that for $$$i=1$$$, $$$x_i = 0$$$.For example, if Alicia had the array $$$a = \{0, 1, 2, 0, 3\}$$$, then $$$x = \{0, 0, 1, 2, 2\}$$$.Then, she calculated an array, $$$b_1, b_2, \ldots, b_n$$$: $$$b_i = a_i - x_i$$$.For example, if Alicia had the array $$$a = \{0, 1, 2, 0, 3\}$$$, $$$b = \{0-0, 1-0, 2-1, 0-2, 3-2\} = \{0, 1, 1, -2, 1\}$$$.Alicia gives you the values $$$b_1, b_2, \ldots, b_n$$$ and asks you to restore the values $$$a_1, a_2, \ldots, a_n$$$. Can you help her solve the problem?

The first line contains one integer $$$n$$$ ($$$3 \leq n \leq 200\,000$$$) – the number of elements in Alicia's array. The next line contains $$$n$$$ integers, $$$b_1, b_2, \ldots, b_n$$$ ($$$-10^9 \leq b_i \leq 10^9$$$). It is guaranteed that for the given array $$$b$$$ there is a solution $$$a_1, a_2, \ldots, a_n$$$, for all elements of which the following is true: $$$0 \leq a_i \leq 10^9$$$.

Print $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 10^9$$$), such that if you calculate $$$x$$$ according to the statement, $$$b_1$$$ will be equal to $$$a_1 - x_1$$$, $$$b_2$$$ will be equal to $$$a_2 - x_2$$$, ..., and $$$b_n$$$ will be equal to $$$a_n - x_n$$$. It is guaranteed that there exists at least one solution for the given tests. It can be shown that the solution is unique.

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

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto b = readln.splitter.map !(to !(long)).array;
		long m = 0;
		long [] a;
		foreach (ref c; b)
		{
			a ~= c + m;
			m = max (m, a.back);
		}
		writefln !("%(%s %)") (a);
	}
}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
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)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
    int n = scan!int;
    long[] bs = scan!long(n);

    long x = 0;
    long[] as;
    foreach(i; 0 .. n){
        as ~= x + bs[i];
        x.raiseTo(as[i]);
    }
    as.unsplit.print;
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      auto B = new long[N];
      foreach (i; 0 .. N) {
        B[i] = readLong();
      }

      auto as = new long[N];
      auto xs = new long[N + 1];
      xs[0] = 0;
      foreach (i; 0 .. N) {
        // b = a - x
        as[i] = B[i] + xs[i];
        xs[i + 1] = max(xs[i], as[i]);
      }
      foreach (i; 0 .. N) {
        if (i > 0) write(" ");
        write(as[i]);
      }
      writeln();
    }
  } catch (EOFException e) {
  }
}

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

string FMT_F = "%.10f";

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

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

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

long mod = 10^^9 + 7;
//long mod = 998244353;
//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 n = RD!int;
	auto b = RDA;
	auto a = new long[](n);
	auto c = new long[](n);
	long last;
	foreach (i; 0..n)
	{
		a[i] = b[i] + last;
		last.chmax(a[i]);
		if (a[i] < 0)
		{
			c[i] = abs(a[i]);
			last += c[i];
		}
	}
	long add;
	foreach_reverse (i; 0..n)
	{
		a[i] += add;
		if (c[i] > 0)
		{
			add = c[i];
		}
	}

	a.map!(to!string).join(" ").writeln;
	stdout.flush;
	debug readln;
}


Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the problem before the contest. Because he wants to make sure Iahub will be the one qualified, he tells Iahub the following task.You're given an (1-based) array a with n elements. Let's define function f(i, j) (1 ≤ i, j ≤ n) as (i - j)2 + g(i, j)2. Function g is calculated by the following pseudo-code:int g(int i, int j) {    int sum = 0;    for (int k = min(i, j) + 1; k <= max(i, j); k = k + 1)        sum = sum + a[k];    return sum;}Find a value mini ≠ j  f(i, j).Probably by now Iahub already figured out the solution to this problem. Can you?

The first line of input contains a single integer n (2 ≤ n ≤ 100000). Next line contains n integers a[1], a[2], ..., a[n] ( - 104 ≤ a[i] ≤ 104).

Output a single integer — the value of mini ≠ j  f(i, j).

import std.algorithm, std.math, std.stdio;
void main () {
	int n;
	readf (" %s", &n);
	auto a = new int [n];
	foreach (ref x; a) readf (" %s", &x);
	long r = long.max;
	foreach (i; 1..1111) {
		long c = 0;
		foreach (j; 1..n) {
			c += a[j];
			if (j > i) c -= a[j - i];
			r = min (r, c * c + i * i);
		}
	}
	writeln (r);
}

import std.algorithm;
import std.stdio;

immutable int MAX_C = 10_005;

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

		int res = MAX_C * MAX_C;
		foreach (i; 1..min (MAX_C, n))
		{
			int add = i;
			add *= add;
			int cur = 0;
			foreach (j; 1..n)
			{
				cur += a[j];
				if (j > i)
				{
					cur -= a[j - i];
				}
				if (-MAX_C <= cur && cur <= MAX_C)
				{
					res = min (res, cur * cur + add);
				}
			}
		}

		writeln (res);
	}
}

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

int MAX_C = 10_005;

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

		int res = MAX_C;
		foreach (i; 1..min (MAX_C, n))
		{
			int add = i;
			add *= add;
			int cur = 0;
			foreach (j; 1..n)
			{
				cur += a[j];
				if (j > i)
				{
					cur -= a[j - i];
				}
				if (cur <= MAX_C)
				{
					res = min (res, cur * cur + add);
				}
			}
		}

		writeln (res);
	}
}


Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent.One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the n drinks and mixed them. Then he wondered, how much orange juice the cocktail has.Find the volume fraction of orange juice in the final drink.

The first input line contains a single integer n (1 ≤ n ≤ 100) — the number of orange-containing drinks in Vasya's fridge. The second line contains n integers pi (0 ≤ pi ≤ 100) — the volume fraction of orange juice in the i-th drink, in percent. The numbers are separated by a space.

Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10  - 4.

NoteNote to the first sample: let's assume that Vasya takes x milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal  milliliters. The total cocktail's volume equals 3·x milliliters, so the volume fraction of the juice in the cocktail equals , that is, 66.(6) percent.

import std.stdio;
import std.string;
import std.conv;
import std.regex;
import std.algorithm.iteration;
import  std.array;

void main()
{
  stdin.readln;
  auto ps = stdin.readln.strip.split(regex(` +`)).map!(to!double)
    .map!"a/100".array;
  writef("%.9f",ps.sum/ps.length*100);
}

import std.stdio;
import core.stdc.stdio;
import std.algorithm;
import std.math;

int main(string[] argv)
{
	int n;
	int[] oj;
	scanf("%d", &n); oj.length = n;
	long sum;
	foreach (int i; 0..n)
	{
		scanf("%d", &oj[i]);
		sum += oj[i];
	}
	printf("%.10f", cast(float)sum / cast(float)n);
	return 0;
}

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

void main() {
	readln();
	auto arr = readln().chomp.split(" ").map!(to!int).array;
	writeln(arr.reduce!((a, b) => a + b) / cast(double) arr.length);
}

import std.stdio;
int main()
{
	float a=0;
	readf(" %f", &a);
	float sum=0;
	for (int i=0; i<a; i++)
	{
		float b=0;
		readf(" %f", &b);
		sum=sum+b;
	}
	writeln(sum/a);
	return 0;
}


All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi — a coordinate on the Ox axis. No two cities are located at a single point.Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.For each city calculate two values mini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city

The first line of the input contains integer n (2 ≤ n ≤ 105) — the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.

Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.

import std.stdio;
import std.c.stdio;
import std.math;
import std.algorithm;
import std.conv;
import std.string;
import std.array;
import std.typecons;

void main() {
  int n = readln().strip().to!int;
  int[] a = readln().split().map!(to!int).array;
  writeln(a[1] - a[0], ' ', a[n - 1] - a[0]);
  foreach (i; 1..n-1) {
    writeln(min(a[i] - a[i - 1], a[i + 1] - a[i]), ' ',
            max(a[i] - a[0], a[n - 1] - a[i]));
  }
  writeln(a[n - 1] - a[n - 2], ' ', a[n - 1] - a[0]);
}

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

void main() {
  int n = readln.strip.to!int;
  int[] a = readln.strip.split.map!(to!int).array;
  writeln(abs(a[0]-a[1]), " ", abs(a[0]-a[n-1]));
  foreach (i; 1..n-1) {
    auto mn = min(abs(a[i]-a[i-1]), abs(a[i]-a[i+1]));
    auto mx = max(abs(a[i]-a[0]), abs(a[i]-a[n-1]));
    writeln(mn, " ", mx);
  }
  writeln(abs(a[n-1]-a[n-2]), " ", abs(a[0]-a[n-1]));
}


You are given a tree consisting exactly of $$$n$$$ vertices. Tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a value $$$a_v$$$ assigned to it.Let $$$dist(x, y)$$$ be the distance between the vertices $$$x$$$ and $$$y$$$. The distance between the vertices is the number of edges on the simple path between them.Let's define the cost of the tree as the following value: firstly, let's fix some vertex of the tree. Let it be $$$v$$$. Then the cost of the tree is $$$\sum\limits_{i = 1}^{n} dist(i, v) \cdot a_i$$$.Your task is to calculate the maximum possible cost of the tree if you can choose $$$v$$$ arbitrarily.

The first line contains one integer $$$n$$$, the number of vertices in the tree ($$$1 \le n \le 2 \cdot 10^5$$$). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2 \cdot 10^5$$$), where $$$a_i$$$ is the value of the vertex $$$i$$$. Each of the next $$$n - 1$$$ lines describes an edge of the tree. Edge $$$i$$$ is denoted by two integers $$$u_i$$$ and $$$v_i$$$, the labels of vertices it connects ($$$1 \le u_i, v_i \le n$$$, $$$u_i \ne v_i$$$). It is guaranteed that the given edges form a tree.

Print one integer — the maximum possible cost of the tree if you can choose any vertex as $$$v$$$.

NotePicture corresponding to the first example: You can choose the vertex $$$3$$$ as a root, then the answer will be $$$2 \cdot 9 + 1 \cdot 4 + 0 \cdot 1 + 3 \cdot 7 + 3 \cdot 10 + 4 \cdot 1 + 4 \cdot 6 + 4 \cdot 5 = 18 + 4 + 0 + 21 + 30 + 4 + 24 + 20 = 121$$$.In the second example tree consists only of one vertex so the answer is always $$$0$$$.

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

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    auto G = new int[][](N);
    foreach (_; 0..N-1) {
        auto s = readln.split.map!(to!int);
        G[s[0]-1] ~= s[1]-1;
        G[s[1]-1] ~= s[0]-1;
    }

    auto f = new long[](N);
    auto g = new long[](N);
    auto h = new long[](N);
    auto k = new long[](N);

    void dfs1(int n, int p) {
        foreach (m; G[n]) {
            if (m == p) continue;
            dfs1(m, n);
            g[n] += g[m] + A[m];
            f[n] += f[m] + g[m] + A[m];
        }
    }

    void dfs2(int n, int p) {
        if (p == -1) {
            h[n] = f[n];
            k[n] = g[n];
        } else {
            /*
            long fp = h[p] - f[n] - g[n] - A[n];
            long gp = k[p] - g[n] - A[n];
            h[n] = fp + gp + A[p];
            k[n] = gp + A[p];
            */
            h[n] = h[p] + k[p] + A[p] - (A[n] + g[n]) * 2;
            k[n] = k[p] + A[p] - A[n];
        }
        foreach (m; G[n]) if (m != p) dfs2(m, n);
    }

    dfs1(0, -1);
    dfs2(0, -1);
    h.reduce!max.writeln;
}

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;

void main(string[] args)
{
  auto n = next!int;
  auto a = next!long(n);
  auto adjlist = new int[][](n);
  foreach(i; 0 .. n - 1)
    {
      auto u = next!int - 1;
      auto v = next!int - 1;
      adjlist[u] ~= v;
      adjlist[v] ~= u;
    }
  auto aSum = new long[](n);
  auto treeCost = new long[](n);
  void dfs1(int v, int p)
  {
    aSum[v] = a[v];
    treeCost[v] = 0;
    foreach(w; adjlist[v])
      if (w != p)
	{
	  dfs1(w, v);
	  treeCost[v] += treeCost[w] + aSum[w];
	  aSum[v] += aSum[w];
	}
  }
  dfs1(0, -1);
  long maxCost = long.min;
  void dfs2(int v, int p, long parentCost)
  {
    auto cost = treeCost[v] + parentCost;
    maxCost = max(maxCost, cost);
    foreach(w; adjlist[v])
      if (w != p)
	{
	  dfs2(w, v, cost - treeCost[w] - aSum[w] + aSum[0] - aSum[w]);
	}
  }
  dfs2(0, -1, 0);
  maxCost.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;
	}
    }
}


Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:   climb one area up;  climb one area down;  jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall. If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon.The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.The level is considered completed if the ninja manages to get out of the canyon.After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.

The first line contains two integers n and k (1 ≤ n, k ≤ 105) — the height of the canyon and the height of ninja's jump, correspondingly. The second line contains the description of the left wall — a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area. The third line describes the right wall in the same format. It is guaranteed that the first area of the left wall is not dangerous.

Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).

NoteIn the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon. In the second sample there's no way the ninja can get out of the canyon.

import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

const INF = 1<<28;

void main() {
    int N, K; scanf("%d %d\n", &N, &K);
    auto F = [readln.chomp, readln.chomp];

    auto dp = new int[][](2, N + K);
    foreach (i; 0 .. 2) dp[i][] = INF;

    dp[0][0] = 0;
    struct P {
        int w, h;
    }
    DList!P Q;
    Q.insert(P(0, 0));
    while (!Q.empty) {
        auto c = Q.front; Q.removeFront;
        int i = c.w, j = c.h;
        if (j < N && F[i][j] == 'X') {
            dp[i][j] = INF;
            continue;
        }
        int n = dp[i][j] + 1;
        if (j < dp[i][j]) {
            dp[i][j] = INF;
            continue;
        }
        void f(int a, int b, int n) {
            if (b >= N + K) return;
            if (dp[a][b] > n) {
                dp[a][b] = n;
                Q.insert(P(a, b));
            }
        }
        f(!i, j + K, n);
        f(i, j + 1, n);
        if (j - 1 >= 0) f(i, j - 1, n);
    }
    //foreach (i; 0 .. 2) writefln("%(%5d %)", dp[i].map!((a) => (a == INF ? -1 : a)));

    foreach (i; 0 .. 2) {
        foreach (j; N .. N + K) {
            if (dp[i][j] <= N) {
                writeln("YES"); return;
            }
        }
    }
    writeln("NO");

}


Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store. Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the greatest common divisor of numbers of the apples in each group must be greater than 1. Of course, each apple can be part of at most one group.Jzzhu wonders how to get the maximum possible number of groups. Can you help him?

A single integer n (1 ≤ n ≤ 105), the number of the apples.

The first line must contain a single integer m, representing the maximum number of groups he can get. Each of the next m lines must contain two integers — the numbers of apples in the current group. If there are several optimal answers you can print any of them.

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

immutable int NA = -1;

__gshared int [] [] a;
__gshared int [] p;
__gshared bool [] b;
__gshared int n;

bool find_pair (int c)
{
	if (b[c])
	{
		return false;
	}
	b[c] = true;
	foreach_reverse (d; a[c])
	{
		if (!b[d])
		{
			if (p[d] == NA || find_pair (p[d]))
			{
				debug {writeln (c, '-', d);}
				p[d] = c;
				p[c] = d;
				return true;
			}
		}
	}
	return false;
}

bool find_pair2 (int c)
{
// /*
	if (c < n / 2)
	{
		return find_pair (c);
	}
// */
	if (b[c])
	{
		return false;
	}
	b[c] = true;
	if (a[c].length == 0)
	{
		return false;
	}
/*
	foreach_reverse (d; a[c])
	{
		if (!b[d])
		{
			if (p[d] == NA || find_pair2 (p[d]))
			{
				debug {writeln (c, '-', d);}
				p[d] = c;
				p[c] = d;
				return true;
			}
		}
	}
*/
	foreach_reverse (d; a[a[c][$ - 1]])
	{
		if (!b[d])
		{
			if (p[d] == NA || find_pair2 (p[d]))
			{
				debug {writeln (c, '-', d);}
				p[d] = c;
				p[c] = d;
				return true;
			}
		}
	}

	if (a[c].length <= 1)
	{
		return false;
	}
	foreach_reverse (d; a[a[c][0]])
	{
		if (!b[d])
		{
			if (p[d] == NA || find_pair2 (p[d]))
			{
				debug {writeln (c, '-', d);}
				p[d] = c;
				p[c] = d;
				return true;
			}
		}
	}

	return false;
}

void main ()
{
	while (readf (" %s", &n) > 0)
	{
		n++;
		a = new int [] [n];
		foreach (c; 2..n)
		{
			for (int d = c * 2; d < n; d += c)
			{
				a[c] ~= d;
				a[d] ~= c;
			}
		}

		long res = 0;
		p = new int [n];
		p[] = NA;
		b = new bool [n];
		foreach_reverse (c; 2..n)
		{
			if (p[c] == NA)
			{
				if (find_pair (c))
				{
					res++;
				}
				else
				{
					b[] = false;
					if (find_pair (c))
					{
						res++;
					}
				}
				debug {writeln (p);}
			}
		}

		version (DEBUG)
		{
			int num = 0;
			foreach (c; 2..n)
			{
				if (a[c].length > 0 && p[c] == NA)
				{
					num++;
				}
			}
			writeln ("!", num);
		}

		b[] = false;
		foreach_reverse (c; 2..n)
		{
			if (p[c] == NA)
			{
				if (find_pair2 (c))
				{
					res++;
				}
				else
				{
/*
					b[] = false;
					if (find_pair2 (c))
					{
						res++;
					}
*/
				}
				debug {writeln (p);}
			}
		}

		version (DEBUG)
		{
			num = 0;
			foreach (c; 2..n)
			{
				if (a[c].length > 0 && p[c] == NA)
				{
					num++;
				}
			}
			writeln ("!", num);
		}

		foreach_reverse (c; 2..n)
		{
			if (p[c] == NA)
			{
				b[] = false;
				if (find_pair2 (c))
				{
					res++;
				}
				debug {writeln (p);}
			}
		}

		version (DEBUG)
		{
			num = 0;
			foreach (c; 2..n)
			{
				if (a[c].length > 0 && p[c] == NA)
				{
					num++;
				}
			}
			writeln ("!", num);
		}

		writeln (res);
		foreach (c; 2..n)
		{
			if (p[c] > c)
			{
				writeln (c, ' ', p[c]);
			}
		}
	}
}

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

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

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

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

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

immutable LIM = 100005;

int N;

void main(string[] args) {
	bool[] isnp = new bool[LIM];
	for (int i = 2; i * i < LIM; ++i) if (!isnp[i]) for (int j = i * i; j < LIM; j += i) isnp[j] = true;

	try {
	for (; ; ) {
		N = readInt;

		Pair!(int, int)[] ans;
		bool[] used = new bool[N + 1];
		for (int d = N; d >= 2; --d) if (!isnp[d]) {
			int[] xs;
			for (int x = d; x <= N; x += d) if (!used[x]) {
				xs ~= x;
			}
			if (xs.length >= 2 && xs[1] == d * 2) {
				swap(xs[0], xs[1]);
			}
			for (int j = xs.length % 2; j < xs.length; j += 2) {
				ans ~= pair(xs[j], xs[j + 1]);
				used[xs[j]] = true;
				used[xs[j + 1]] = true;
			}
		}

		writeln(ans.length);
		foreach (p; ans) {
			writeln(p.x, " ", p.y);
		}

	}
	} catch (EOFException) {}
}

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

immutable int NA = -1;

__gshared int [] [] a;
__gshared int [] p;
__gshared bool [] b;
__gshared int n;

bool find_pair (int c)
{
	if (b[c])
	{
		return false;
	}
	b[c] = true;
	foreach_reverse (d; a[c])
	{
		if (!b[d])
		{
			if (p[d] == NA || find_pair (p[d]))
			{
				debug {writeln (c, '-', d);}
				p[d] = c;
				p[c] = d;
				return true;
			}
		}
	}
	return false;
}

void main ()
{
	while (readf (" %s", &n) > 0)
	{
		n++;
		a = new int [] [n];
		foreach (c; 2..n)
		{
			for (int d = c * 2; d < n; d += c)
			{
				a[c] ~= d;
				a[d] ~= c;
			}
		}

		long res = 0;
		p = new int [n];
		p[] = NA;
		b = new bool [n];
		foreach_reverse (c; 2..n)
		{
			if (p[c] == NA)
			{
				if (find_pair (c))
				{
					res++;
				}
				else
				{
					b[] = false;
					if (find_pair (c))
					{
						res++;
					}
				}
				debug {writeln (p);}
			}
		}

		writeln (res);
		foreach (c; 2..n)
		{
			if (p[c] > c)
			{
				writeln (c, ' ', p[c]);
			}
		}
	}
}

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

immutable int NA = -1;

__gshared int [] [] a;
__gshared int [] p;
__gshared bool [] b;
__gshared int n;

bool find_pair (int c)
{
	if (b[c])
	{
		return false;
	}
	b[c] = true;
	foreach_reverse (d; a[c])
	{
		if (!b[d])
		{
			if (p[d] == NA || find_pair (p[d]))
			{
				debug {writeln (c, '-', d);}
				p[d] = c;
				p[c] = d;
				return true;
			}
		}
	}
	return false;
}

void main ()
{
	while (readf (" %s", &n) > 0)
	{
		n++;
		a = new int [] [n];
		foreach (c; 2..n)
		{
			for (int d = c * 2; d < n; d += c)
			{
				a[c] ~= d;
				a[d] ~= c;
			}
		}

		long res = 0;
		p = new int [n];
		p[] = NA;
		b = new bool [n];
		foreach_reverse (c; 2..n / 2 + 1)
		{
			if (p[c] == NA)
			{
				if (find_pair (c))
				{
					res++;
				}
				else
				{
					b[] = false;
					if (find_pair (c))
					{
						res++;
					}
				}
				debug {writeln (p);}
			}
		}

		writeln (res);
		foreach (c; 2..n)
		{
			if (p[c] > c)
			{
				writeln (c, ' ', p[c]);
			}
		}
	}
}

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

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

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

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

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

int N;

void main(string[] args) {
	try {
	for (; ; ) {
		N = readInt;

		Pair!(int, int)[] ans;
		bool[] used = new bool[N + 1];
		for (int d = N; d >= 2; --d) {
			int[] xs;
			for (int i = d; i <= N; i += d) if (!used[i]) {
				xs ~= i;
			}
			if (xs.length > 1 && xs.length % 2 != 0) {
				swap(xs[0], xs[1]);
			}
			for (int j = xs.length % 2; j < xs.length; j += 2) {
				ans ~= pair(xs[j], xs[j + 1]);
				used[xs[j]] = true;
				used[xs[j + 1]] = true;
			}
		}

		writeln(ans.length);
		foreach (p; ans) {
			writeln(p.x, " ", p.y);
		}

	}
	} catch (EOFException) {}
}

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

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

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

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

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

int N;

void main(string[] args) {
	try {
	for (; ; ) {
		N = readInt;

		Pair!(int, int)[] ans;
		bool[] used = new bool[N + 1];
		for (int d = N; d >= 2; --d) {
			int[] xs;
			for (int i = d; i <= N; i += d) if (!used[i]) {
				xs ~= i;
			}
			if (xs.length >= 2 && xs[1] == d * 2) {
				swap(xs[0], xs[1]);
			}
			for (int j = xs.length % 2; j < xs.length; j += 2) {
				ans ~= pair(xs[j], xs[j + 1]);
				used[xs[j]] = true;
				used[xs[j + 1]] = true;
			}
		}

		writeln(ans.length);
		foreach (p; ans) {
			writeln(p.x, " ", p.y);
		}

	}
	} catch (EOFException) {}
}


During the quarantine, Sicromoft has more free time to create the new functions in "Celex-2021". The developers made a new function GAZ-GIZ, which infinitely fills an infinite table to the right and down from the upper left corner as follows:   The cell with coordinates $$$(x, y)$$$ is at the intersection of $$$x$$$-th row and $$$y$$$-th column. Upper left cell $$$(1,1)$$$ contains an integer $$$1$$$.The developers of the SUM function don't sleep either. Because of the boredom, they teamed up with the developers of the RAND function, so they added the ability to calculate the sum on an arbitrary path from one cell to another, moving down or right. Formally, from the cell $$$(x,y)$$$ in one step you can move to the cell $$$(x+1, y)$$$ or $$$(x, y+1)$$$. After another Dinwows update, Levian started to study "Celex-2021" (because he wants to be an accountant!). After filling in the table with the GAZ-GIZ function, he asked you to calculate the quantity of possible different amounts on the path from a given cell $$$(x_1, y_1)$$$ to another given cell $$$(x_2, y_2$$$), if you can only move one cell down or right.Formally, consider all the paths from the cell $$$(x_1, y_1)$$$ to cell $$$(x_2, y_2)$$$ such that each next cell in the path is located either to the down or to the right of the previous one. Calculate the number of different sums of elements for all such paths.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 57179$$$) — the number of test cases. Each of the following $$$t$$$ lines contains four natural numbers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ ($$$1 \le x_1 \le x_2 \le 10^9$$$, $$$1 \le y_1 \le y_2 \le 10^9$$$) — coordinates of the start and the end cells.

For each test case, in a separate line, print the number of possible different sums on the way from the start cell to the end cell.

NoteIn the first test case there are two possible sums: $$$1+2+5=8$$$ and $$$1+3+5=9$$$.

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

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

    while (t--) {
        int x1, y1, x2, y2;
        readf("%s %s %s %s", &x1, &y1, &x2, &y2);
        readln;

        auto n = x2 - x1;
        auto m = y2 - y1;

        if (n > m) { swap(n, m); }

        long sm (int k) {
            return (1 + k).to!long * k / 2;
        }

        long ans = 1 + sm(n) * 2 + n.to!long * (m - 1 - n);

        ans.writeln;
    }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int row1, col1, row2, col2;
		readf !(" %s %s %s %s") (row1, col1, row2, col2);
		writeln ((row2 - row1) * 1L * (col2 - col1) + 1);
	}
}


Ramesses came to university to algorithms practice, and his professor, who is a fairly known programmer, gave him the following task.You are given two matrices $$$A$$$ and $$$B$$$ of size $$$n \times m$$$, each of which consists of $$$0$$$ and $$$1$$$ only. You can apply the following operation to the matrix $$$A$$$ arbitrary number of times: take any submatrix of the matrix $$$A$$$ that has at least two rows and two columns, and invert the values in its corners (i.e. all corners of the submatrix that contain $$$0$$$, will be replaced by $$$1$$$, and all corners of the submatrix that contain $$$1$$$, will be replaced by $$$0$$$). You have to answer whether you can obtain the matrix $$$B$$$ from the matrix $$$A$$$.  An example of the operation. The chosen submatrix is shown in blue and yellow, its corners are shown in yellow. Ramesses don't want to perform these operations by himself, so he asks you to answer this question.A submatrix of matrix $$$M$$$ is a matrix which consist of all elements which come from one of the rows with indices $$$x_1, x_1+1, \ldots, x_2$$$ of matrix $$$M$$$ and one of the columns with indices $$$y_1, y_1+1, \ldots, y_2$$$ of matrix $$$M$$$, where $$$x_1, x_2, y_1, y_2$$$ are the edge rows and columns of the submatrix. In other words, a submatrix is a set of elements of source matrix which form a solid rectangle (i.e. without holes) with sides parallel to the sides of the original matrix. The corners of the submatrix are cells $$$(x_1, y_1)$$$, $$$(x_1, y_2)$$$, $$$(x_2, y_1)$$$, $$$(x_2, y_2)$$$, where the cell $$$(i,j)$$$ denotes the cell on the intersection of the $$$i$$$-th row and the $$$j$$$-th column.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 500$$$) — the number of rows and the number of columns in matrices $$$A$$$ and $$$B$$$. Each of the next $$$n$$$ lines contain $$$m$$$ integers: the $$$j$$$-th integer in the $$$i$$$-th line is the $$$j$$$-th element of the $$$i$$$-th row of the matrix $$$A$$$ ($$$0 \leq A_{ij} \leq 1$$$).  Each of the next $$$n$$$ lines contain $$$m$$$ integers: the $$$j$$$-th integer in the $$$i$$$-th line is the $$$j$$$-th element of the $$$i$$$-th row of the matrix $$$B$$$ ($$$0 \leq B_{ij} \leq 1$$$).

Print "Yes" (without quotes) if it is possible to transform the matrix $$$A$$$ to the matrix $$$B$$$ using the operations described above, and "No" (without quotes), if it is not possible. You can print each letter in any case (upper or lower).

NoteThe examples are explained below.  Example 1.   Example 2.   Example 3.

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

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		readln;

		int [] [] a;
		foreach (i; 0..n)
		{
			a ~= readln.splitter.map !(to !(int)).array;
		}

		int [] [] b;
		foreach (i; 0..n)
		{
			b ~= readln.splitter.map !(to !(int)).array;
		}

		foreach (i; 0..n)
		{
			a[i][] ^= b[i][];
		}

		auto u = new int [n];
		auto v = new int [m];
		foreach (i; 0..n)
		{
			foreach (j; 0..m)
			{
				u[i] += a[i][j];
				v[j] += a[i][j];
			}
		}

		bool ok = true;
		ok &= u.all !(x => x % 2 == 0);
		ok &= v.all !(x => x % 2 == 0);
		writeln (ok ? "Yes" : "No");
	}
}

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

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

  template next(T) if (isSigned!T) {
    final T next ()  {
      T res;
      ubyte b = skipByte (45);
      if (b == 45) {
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    final T next () {
      T res = skipByte (48) - 48;
      while (true) {
        ubyte b = nextByte ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
}

bool check (int[][] a, int[][] b, int h, int w) {
  auto r = new int[h];
  foreach (i; 0 .. h) {
    int t;
    foreach (j; 0 .. w) {
      t += a[i][j] ^ b[i][j];
    }
    if (t & 1) return false;
  }
  foreach (j; 0 .. w) {
    int t;
    foreach (i; 0 .. h) {
      t += a[i][j] ^ b[i][j];
    }
    if (t & 1) return false;
  }
  return true;
}

void main() {
  auto r = new InputReader;
  immutable h = r.next!uint;
  immutable w = r.next!uint;
  auto a = uninitializedArray!(int[][]) (h, w);
  auto b = uninitializedArray!(int[][]) (h, w);
  foreach (i; 0 .. h) foreach (j; 0 .. w) a[i][j] = r.next!uint;
  foreach (i; 0 .. h) foreach (j; 0 .. w) b[i][j] = r.next!uint;
  writeln (check (a, b, h, w) ? "Yes" : "No");
}

void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, m;
  rd(n, m);
  auto a = new int[][](n, m);
  foreach (i; 0 .. n) {
    a[i] = readln.split.to!(int[]);
  }
  auto b = new int[][](n, m);
  foreach (i; 0 .. n) {
    b[i] = readln.split.to!(int[]);
  }

  if (n < 2 || m < 2) {
    bool all = true;
    foreach (i; 0 .. n) {
      foreach (j; 0 .. m) {
        all &= a[i][j] == b[i][j];
      }
    }
    writeln(all ? "Yes" : "No");
    return;
  }
  foreach (i; 0 .. (n - 1)) {
    foreach (j; 0 .. (m - 1)) {
      if (a[i][j] != b[i][j]) {
        a[i][j] ^= 1;
        a[i + 1][j] ^= 1;
        a[i][j + 1] ^= 1;
        a[i + 1][j + 1] ^= 1;
      }
    }
  }
  bool all = true;
  foreach (i; 0 .. n) {
    foreach (j; 0 .. m) {
      all &= a[i][j] == b[i][j];
    }
  }
  writeln(all ? "Yes" : "No");
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}

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

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

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

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

int M, N;
int[][] A, B;

void main() {
  try {
    for (; ; ) {
      M = readInt();
      N = readInt();
      A = new int[][](M, N);
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        A[x][y] = readInt();
      }
      B = new int[][](M, N);
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        B[x][y] = readInt();
      }

      auto a = new int[][](M, N);
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        a[x][y] = A[x][y];
      }
      foreach (x; 0 .. M - 1) foreach (y; 0 .. N - 1) {
        if (a[x][y] != B[x][y]) {
          a[x][y] ^= 1;
          a[x][y + 1] ^= 1;
          a[x + 1][y] ^= 1;
          a[x + 1][y + 1] ^= 1;
        }
      }
      bool ans = true;
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        ans = ans && (a[x][y] == B[x][y]);
      }
      writeln(ans ? "Yes" : "No");
    }
  } catch (EOFException e) {
  }
}


Grigory has $$$n$$$ magic stones, conveniently numbered from $$$1$$$ to $$$n$$$. The charge of the $$$i$$$-th stone is equal to $$$c_i$$$.Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $$$i$$$, where $$$2 \le i \le n - 1$$$), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge $$$c_i$$$ changes to $$$c_i' = c_{i + 1} + c_{i - 1} - c_i$$$.Andrew, Grigory's friend, also has $$$n$$$ stones with charges $$$t_i$$$. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes $$$c_i$$$ into $$$t_i$$$ for all $$$i$$$?

The first line contains one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of magic stones. The second line contains integers $$$c_1, c_2, \ldots, c_n$$$ ($$$0 \le c_i \le 2 \cdot 10^9$$$) — the charges of Grigory's stones. The second line contains integers $$$t_1, t_2, \ldots, t_n$$$ ($$$0 \le t_i \le 2 \cdot 10^9$$$) — the charges of Andrew's stones.

If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes". Otherwise, print "No".

NoteIn the first example, we can perform the following synchronizations ($$$1$$$-indexed):  First, synchronize the third stone $$$[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$$$.  Then synchronize the second stone: $$$[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$$$. In the second example, any operation with the second stone will not change its charge.

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto d = iota (n - 1).map !(i => a[i + 1] - a[i]).array;
		auto b = readln.splitter.map !(to !(int)).array;
		auto e = iota (n - 1).map !(i => b[i + 1] - b[i]).array;
		sort (d);
		sort (e);
		writeln ((a[0] == b[0] && d == e) ? "Yes" : "No");
	}
}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto d = iota (n - 1).map !(i => a[i + 1] - a[i]).array;
		auto b = readln.splitter.map !(to !(int)).array;
		auto e = iota (n - 1).map !(i => b[i + 1] - b[i]).array;
		sort (d);
		sort (e);
		writeln (d == e ? "Yes" : "No");
	}
}


You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example:  The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened;  The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise.

NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened.

import std.algorithm : max, maxElement;
import std.container : Array;
import std.stdio : stdin, write, writeln;
import std.typecons : Tuple, tuple;

struct IO {
    string readToken() {
        import std.range : empty, front, popFront, split;
        import std.stdio : readln;

        while (tokens.empty) {
            tokens = readln.split;
        }
        auto token = tokens.front;
        tokens.popFront;
        return token;
    }

    int readInt() {
        import std.conv : to;

        return readToken.to!int;
    }

    long readLong() {
        import std.conv : to;

        return readToken.to!long;
    }

    string[] tokens;
}

bool solve(int n, int[] a) {
    bool ok = true;
    bool[] prefixOK = new bool[n];

    for (int i = 0; i < n; ++i) {
        ok &= a[i] >= i;
        prefixOK[i] = ok;
    }
    ok = true;
    for (int i = n; i--;) {
        ok &= a[i] >= n - 1 - i;
        if (prefixOK[i] && ok) {
            return true;
        }
    }
    return false;
}

void main() {
    IO io;
    int T = io.readInt;
    while (T--) {
        int n = io.readInt;
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = io.readInt();
        }
        writeln(solve(n, a) ? "Yes" : "No");
    }
}

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

DList!string _words;

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

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

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

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

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

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

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

    }
}

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

void main()
{
  auto t = next!long;
  foreach(tc; 0 .. t)
    {
      auto n = next!long;
      auto a = new long[n.ind];
      read(a);
      auto inc = long(0);
      for(inc = 0; inc < n && a.at(inc) >= inc; inc++)
        {}
      if (inc == n)
        {
          writeln("Yes");
          continue;
        }
      auto dec = long(0);
      for(dec = n - 1; dec >= 0 && a.at(dec) >= (n - 1 - dec); dec--)
        {}
      if (dec == -1)
        {
          writeln("Yes");
          continue;
        }
      if (tc == 6)
        logSym!(n, a, inc, dec);
      if (dec >= inc)
        {
          writeln("No");
        }
      else
        {
          if (inc == dec + 1 && inc == n - 1 - dec)
            {
              writeln("No");
            }
          else
            {
              writeln("Yes");
            }
        }
    }
}

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 = 998244353;
//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 main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;
		bool mode;
		ans[ti] = true;
		foreach (i; 0..n)
		{
			if (!mode)
			{
				if (a[i] < i)
					mode = true;
			}
			if (mode)
			{
				a[i].chmin(a[i-1]-1);
				if (a[i] < 0)
					ans[ti] = false;
			}
		}
	}

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


There are two infinite sources of water:  hot water of temperature $$$h$$$;  cold water of temperature $$$c$$$ ($$$c < h$$$). You perform the following procedure of alternating moves:  take one cup of the hot water and pour it into an infinitely deep barrel;  take one cup of the cold water and pour it into an infinitely deep barrel;  take one cup of the hot water $$$\dots$$$  and so on $$$\dots$$$ Note that you always start with the cup of hot water.The barrel is initially empty. You have to pour at least one cup into the barrel. The water temperature in the barrel is an average of the temperatures of the poured cups.You want to achieve a temperature as close as possible to $$$t$$$. So if the temperature in the barrel is $$$t_b$$$, then the absolute difference of $$$t_b$$$ and $$$t$$$ ($$$|t_b - t|$$$) should be as small as possible.How many cups should you pour into the barrel, so that the temperature in it is as close as possible to $$$t$$$? If there are multiple answers with the minimum absolute difference, then print the smallest of them.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 3 \cdot 10^4$$$) — the number of testcases. Each of the next $$$T$$$ lines contains three integers $$$h$$$, $$$c$$$ and $$$t$$$ ($$$1 \le c < h \le 10^6$$$; $$$c \le t \le h$$$) — the temperature of the hot water, the temperature of the cold water and the desired temperature in the barrel.

For each testcase print a single positive integer — the minimum number of cups required to be poured into the barrel to achieve the closest temperature to $$$t$$$.

NoteIn the first testcase the temperature after $$$2$$$ poured cups: $$$1$$$ hot and $$$1$$$ cold is exactly $$$20$$$. So that is the closest we can achieve.In the second testcase the temperature after $$$7$$$ poured cups: $$$4$$$ hot and $$$3$$$ cold is about $$$29.857$$$. Pouring more water won't get us closer to $$$t$$$ than that.In the third testcase the temperature after $$$1$$$ poured cup: $$$1$$$ hot is $$$18$$$. That's exactly equal to $$$t$$$.

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

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

double dist(ll treq, ll cups, ll c, ll h){
    ll haf = (cups - 1) / 2;
    double val = c*haf + h*(haf + 1);
    val /= cups;
    return abs(val - treq);
}

void play(){
    ll h, c, treq;
    h = rd; c = rd; treq = rd;
    /* double mid = (h + c) / 2.0; */

    if(treq >= h || h == c){
        writeln(1); return;
    }if(2*treq <= h + c){
        writeln(2); return;
    }

    // Multiple of (H - C)
    /* double temptake = (treq - c) / (h - c); */
    /*
    */
    ll num = (h - c);
    ll den = (2*treq - h - c);

    ll res = num / den;
    if(res % 2 == 0) ++res;
    if(dist(treq, res, c, h) > dist(treq, res - 2, c, h)){
        res -= 2;
    }else if (dist(treq, res, c, h) > dist(treq, res+2, c, h)){
        res += 2;
    }
    writeln(res);
}

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

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

immutable int logLimit = 21;
immutable int limit = 1 << logLimit;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int h, c, t;
		readf !(" %s %s %s") (h, c, t);
		int res = 1;

		long fun (int x)
		{
			auto y = x / 2;
			auto z = x - y;
			auto num = c * 1L * y + h * 1L * z;
			return num;
		}

		void go (int x)
		{
			auto prev = fun (res);
			auto next = fun (x);
			if (abs (prev - t * 1L * res) * x >
			    abs (next - t * 1L * x) * res)
			{
				res = x;
			}
		}

		go (2);

		int lo = 2;
		int hi = limit;
		foreach (step; 0..logLimit)
		{
			auto me = (lo + hi) / 2;
			auto cur = me * 2 + 1;
			if (fun (cur) > t * 1L * cur)
			{
				lo = me + 1;
			}
			else
			{
				hi = me;
			}
		}

		foreach (i; lo - 1..lo + 2)
		{
			go (2 * i + 1);
		}

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

T binarySearch(alias pred, T)(T ok, T ng)
{
	while (abs(ok-ng) > 1)
	{
		auto mid = (ok+ng)/2;
		if (unaryFun!pred(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

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

		bool f(long x)
		{
			return h*x + c*(x-1) > tt*(x*2-1);
		}
		auto r = binarySearch!(f)(0L, int.max);

		if (r == 0)
		{
			if (abs((tt - h)*2) < abs(tt*2 - (h+c)))
				ans[ti] = 1;
			else
				ans[ti] = 2;
		}
		else if (r == int.max-1)
		{
			ans[ti] = 2;
		}
		else
		{
			auto d1 = cast(double)(h*r + c*(r-1))/(r*2-1) - tt;
			auto d2 = cast(double)(h*(r+1) + c*r)/(r*2+1) - tt;
			debug writeln("r:", r, " h*(r+1):", h*(r+1), " c*r:", c*r, " d1:", d1, " d2:", d2);
			if (abs(d1) <= abs(d2))
				ans[ti] = r*2 - 1;
			else
				ans[ti] = r*2 + 1;
		}
	}

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

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

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

double[] ratios;
void preprocess(){
    foreach(i; 0..100000){
        ratios ~= (i + 1) / (2*i + 1);
    }
}

void play(){
    ll h, c, treq;
    h = rd; c = rd; treq = rd;
    double mid = (h + c) / 2.0;

    if(treq == h || h == c){
        writeln(1); return;
    }if(treq <= mid){
        writeln(2); return;
    }

    // Multiple of (H - C)
    /* double temptake = (treq - c) / (h - c); */
    /*
    ll lo = 0; ll hi = 100_000;
    while(hi - lo > 1){
        ll midd = (lo + hi)/2;
        if(ratios[midd] < temptake){
            hi = midd;
        }else{
            lo = midd;
        }
    }
    if(abs(ratios[lo] - temptake) < abs(ratios[hi] - temptake)){
        lo = hi;
    }
    */
    double num = (h - c);
    double den = (2*treq - h - c);
    debug writeln(num , " ", den);
    double margin = num / den;
    debug writeln(margin);
    ll res = to!ll(margin);
    if(res % 2 == 0) ++res;
    if(abs(margin - res - 2) < abs(margin - res)){
        res -= 2;
    }
    writeln(res);
}

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

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

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

double[] ratios;
void preprocess(){
    foreach(i; 0..100000){
        ratios ~= (i + 1) / (2*i + 1);
    }
}

void play(){
    ll h, c, treq;
    h = rd; c = rd; treq = rd;
    double mid = (h + c) / 2.0;

    if(treq == h || h == c){
        writeln(1); return;
    }if(treq <= mid){
        writeln(2); return;
    }

    // Multiple of (H - C)
    /* double temptake = (treq - c) / (h - c); */
    /*
    ll lo = 0; ll hi = 100_000;
    while(hi - lo > 1){
        ll midd = (lo + hi)/2;
        if(ratios[midd] < temptake){
            hi = midd;
        }else{
            lo = midd;
        }
    }
    if(abs(ratios[lo] - temptake) < abs(ratios[hi] - temptake)){
        lo = hi;
    }
    */
    double num = (h - c);
    double den = (treq - mid);
    debug writeln(num , " ", den);
    double margin = num / (2.0 * den);
    debug writeln(margin);
    ll res = to!ll(margin);
    if(res % 2 == 0) ++res;
    writeln(res);
}

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

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

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

double[] ratios;
void preprocess(){
    foreach(i; 0..100000){
        ratios ~= (i + 1) / (2*i + 1);
    }
}

void play(){
    ll h, c, treq;
    h = rd; c = rd; treq = rd;
    double mid = (h + c) / 2.0;

    if(treq >= h || h == c){
        writeln(1); return;
    }if(treq <= mid){
        writeln(2); return;
    }

    // Multiple of (H - C)
    /* double temptake = (treq - c) / (h - c); */
    /*
    */
    ll num = (h - c);
    ll den = (2*treq - h - c);
    debug writeln(num , " ", den);

    ll lo = 0; ll hi = 100_000;
    while(hi - lo > 1){
        ll midd = (lo + hi)/2;
        ll midval = 2*midd + 1;
        if(den * midval > num){
            hi = midd;
        }else{
            lo = midd;
        }
    }
    ll midval = 2 * lo + 1;
    debug writeln(midval);
    if(abs(den * midval - num) > abs(den * (midval + 2) - num)){
        midval += 2;
    }

    /* double margin = num / den; */
    /* debug writeln(margin); */
    /* ll res = to!ll(margin); */
    /* if(res % 2 == 0) ++res; */
    /* if(abs(margin - res + 2) < abs(margin - res)){ */
    /*     res -= 2; */
    /* }else if (abs(margin - res - 2) < abs(margin - res)){ */
    /*     res += 2; */
    /* } */
    /* writeln(res); */
    writeln(midval);
}

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

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

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

double[] ratios;
void preprocess(){
    foreach(i; 0..100000){
        ratios ~= (i + 1) / (2*i + 1);
    }
}

void play(){
    ll h, c, treq;
    h = rd; c = rd; treq = rd;
    double mid = (h + c) / 2.0;

    if(treq == h || h == c){
        writeln(1); return;
    }if(treq <= mid){
        writeln(2); return;
    }

    // Multiple of (H - C)
    /* double temptake = (treq - c) / (h - c); */
    /*
    ll lo = 0; ll hi = 100_000;
    while(hi - lo > 1){
        ll midd = (lo + hi)/2;
        if(ratios[midd] < temptake){
            hi = midd;
        }else{
            lo = midd;
        }
    }
    if(abs(ratios[lo] - temptake) < abs(ratios[hi] - temptake)){
        lo = hi;
    }
    */
    double num = (h - c);
    double den = (2*treq - h - c);
    debug writeln(num , " ", den);
    double margin = num / den;
    debug writeln(margin);
    ll res = to!ll(margin);
    if(res % 2 == 0) ++res;
    if(abs(margin - res + 2) < abs(margin - res)){
        res -= 2;
    }else if (abs(margin - res - 2) < abs(margin - res)){
        res += 2;
    }
    writeln(res);
}

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

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

string FMT_F = "%.10f";

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

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

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

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

T binarySearch(alias pred, T)(T ok, T ng)
{
	while (abs(ok-ng) > 1)
	{
		auto mid = (ok+ng)/2;
		if (unaryFun!pred(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

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

		bool f(long x)
		{
			return h*x + c*(x-1) > tt*(x*2-1);
		}
		auto r = binarySearch!(f)(0L, int.max);

		if (r == 0)
		{
			ans[ti] = 1;
		}
		else if (r == int.max-1)
		{
			ans[ti] = 2;
		}
		else
		{
			auto d1 = h*r + c*(r-1) - tt*2;
			auto d2 = (h+1)*r + c*r - tt*2;
			if (d1 <= d2)
				ans[ti] = r*2 + 1;
			else
				ans[ti] = (r+1)*2 + 1;
		}
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

T binarySearch(alias pred, T)(T ok, T ng)
{
	while (abs(ok-ng) > 1)
	{
		auto mid = (ok+ng)/2;
		if (unaryFun!pred(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

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

		bool f(long x)
		{
			return h*x + c*(x-1) > tt*(x*2-1);
		}
		auto r = binarySearch!(f)(0L, int.max);

		if (r == 0)
		{
			ans[ti] = 1;
		}
		else if (r == int.max-1)
		{
			ans[ti] = 2;
		}
		else
		{
			auto d1 = h*r + c*(r-1) - tt*2;
			auto d2 = h*(r+1) + c*r - tt*2;
			if (d1 <= d2)
				ans[ti] = r*2 + 1;
			else
				ans[ti] = (r+1)*2 + 1;
		}
	}

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


You have a list of numbers from $$$1$$$ to $$$n$$$ written from left to right on the blackboard.You perform an algorithm consisting of several steps (steps are $$$1$$$-indexed). On the $$$i$$$-th step you wipe the $$$i$$$-th number (considering only remaining numbers). You wipe the whole number (not one digit).  When there are less than $$$i$$$ numbers remaining, you stop your algorithm. Now you wonder: what is the value of the $$$x$$$-th remaining number after the algorithm is stopped?

The first line contains one integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. The next $$$T$$$ lines contain queries — one per line. All queries are independent. Each line contains two space-separated integers $$$n$$$ and $$$x$$$ ($$$1 \le x < n \le 10^{9}$$$) — the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least $$$x$$$ numbers.

Print $$$T$$$ integers (one per query) — the values of the $$$x$$$-th number after performing the algorithm for the corresponding queries.

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

immutable long MOD = 10^^9 + 7;
long[] F;

void solve() {
    auto s = readln.split.map!(to!long);
    auto N = s[0];
    auto X = s[1];
    writeln(X * 2);
}

void main() {

    auto T = readln.chomp.to!int;
    while(T--) solve;
}


$$$n$$$ distinct integers $$$x_1,x_2,\ldots,x_n$$$ are written on the board. Nezzar can perform the following operation multiple times.  Select two integers $$$x,y$$$ (not necessarily distinct) on the board, and write down $$$2x-y$$$. Note that you don't remove selected numbers. Now, Nezzar wonders if it is possible to have his favorite number $$$k$$$ on the board after applying above operation multiple times.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases.  The first line of each test case contains two integers $$$n,k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$-10^{18} \le k \le 10^{18}$$$). The second line of each test case contains $$$n$$$ distinct integers $$$x_1,x_2,\ldots,x_n$$$ ($$$-10^{18} \le x_i \le 10^{18}$$$). It is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print "YES" on a single line if it is possible to have $$$k$$$ on the board. Otherwise, print "NO". You can print each letter in any case (upper or lower).

NoteIn the first test case, the number $$$1$$$ is already on the board.In the second test case, Nezzar could perform the following operations to write down $$$k=0$$$ on the board:   Select $$$x=3$$$ and $$$y=2$$$ and write down $$$4$$$ on the board.  Select $$$x=4$$$ and $$$y=7$$$ and write down $$$1$$$ on the board.  Select $$$x=1$$$ and $$$y=2$$$ and write down $$$0$$$ on the board. In the third test case, it is impossible to have the number $$$k = -1$$$ on the board.

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

long gcd (long a, long b)
{
	while (a && b)
	{
		a %= b;
		if (a)
		{
			b %= a;
		}
	}
	return a + b;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n;
		long k;
		readf !(" %s %s") (n, k);
		readln;
		auto a = readln.splitter.map !(to !(long)).array;
		long g = 0;
		foreach (i; 1..n)
		{
			g = gcd (g, a[i] - a[0]);
		}
		bool good;
		if (g == 0)
		{
			good = (a[0] == k);
		}
		else
		{
			auto one = ((a[0] % g) + g) % g;
			auto two = ((k % g) + g) % g;
			good = (one == two);
		}
		writeln (good ? "YES" : "NO");
	}
}


Kawashiro Nitori is a girl who loves competitive programming.One day she found a string and an integer. As an advanced problem setter, she quickly thought of a problem.Given a string $$$s$$$ and a parameter $$$k$$$, you need to check if there exist $$$k+1$$$ non-empty strings $$$a_1,a_2...,a_{k+1}$$$, such that $$$$$$s=a_1+a_2+\ldots +a_k+a_{k+1}+R(a_k)+R(a_{k-1})+\ldots+R(a_{1}).$$$$$$ Here $$$+$$$ represents concatenation. We define $$$R(x)$$$ as a reversed string $$$x$$$. For example $$$R(abcd) = dcba$$$. Note that in the formula above the part $$$R(a_{k+1})$$$ is intentionally skipped.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case description contains two integers $$$n$$$, $$$k$$$ ($$$1\le n\le 100$$$, $$$0\le k\le \lfloor \frac{n}{2} \rfloor$$$)  — the length of the string $$$s$$$ and the parameter $$$k$$$. The second line of each test case description contains a single string $$$s$$$ of length $$$n$$$, consisting of lowercase English letters.

For each test case, print "YES" (without quotes), if it is possible to find $$$a_1,a_2,\ldots,a_{k+1}$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower).

7
5 1
qwqwq
2 1
ab
3 1
ioi
4 2
icpc
22 0
dokidokiliteratureclub
19 8
imteamshanghaialice
6 3
aaaaaa

NoteIn the first test case, one possible solution is $$$a_1=qw$$$ and $$$a_2=q$$$.In the third test case, one possible solution is $$$a_1=i$$$ and $$$a_2=o$$$.In the fifth test case, one possible solution is $$$a_1=dokidokiliteratureclub$$$.

// Vicfred
// https://codeforces.com/contest/1496/problem/A
// string manipulation
import std.algorithm;
import std.stdio;
import std.conv;
import std.string;

void main() {
  long t;
  readf("%s\n", &t);

  uint n, k;
  string s;
  while(t--) {
    readf("%s %s\n", &n, &k);
    readf("%s\n", &s);

    string S = s[0..k];

    if(k > (n-1)/2)
      writeln("NO");
    else if(k == 0 || s[0..k] == s[$-k..$].dup.reverse) {
      "YES".writeln;
    } else {
      "NO".writeln;
    }
  }
}

// Vicfred
// https://codeforces.com/contest/1496/problem/A
// string manipulation
import std.algorithm;
import std.stdio;
import std.conv;
import std.string;
import core.stdc.string : strlen;

void main() {
    long t;
    readf("%s\n", &t);

    uint n, k;
    string s;
while(t--) {
    readf("%s %s\n", &n, &k);
    readf("%s\n", &s);

    if(k == 0) {
        "YES".writeln;
        continue;
    }

    if(2*k == n) {
        "NO".writeln;
        continue;
    }

    if(s[0..k] == s[$-k..$].dup.reverse) {
        "YES".writeln;
    } else {
        "NO".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(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 bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto k = RD!int;
		auto s = RD!string;

		if (k == 0)
			ans[ti] = true;
		else if (n <= k*2)
			continue;
		else
		{
			int l, r = n-1;
			int cnt;
			while (l < r)
			{
				if (s[l] != s[r])
					break;
				++l; --r;
				++cnt;
			}
			ans[ti] = cnt >= k;
		}
	}

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

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

void theCode(){
    int n;
    n = scan!int;
    int k = scan!int;
    dchar[] arr = scan!(dchar[]);
    bool f = 1;
    for(int i = 0; i < k; ++i){
        if(arr[i] != arr[n - i - 1]){
            f = 0; break;
        }
    }
    if((n % 2 == 0 && k == n/2) || !f){
        writeln("NO");
    }else{
        writeln("YES");
    }
}

void main(){
    long tests = 1;
    tests = scan;        // Toggle!
    while(tests--) theCode();
}

/*********  That's All Folks!  *********/
import std.stdio, std.random, std.functional, std.container, std.algorithm;
import std.numeric, std.range, std.typecons, std.string, std.math, std.conv;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");

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

		if (k == 0)
			ans[ti] = true;
		else if (n <= k*2)
			continue;
		else
		{
			int l, r = n-1;
			bool ok = true;
			while (l < r)
			{
				if (s[l] != s[r])
				{
					ok = false;
					break;
				}
				++l; --r;
			}
			ans[ti] = ok;
		}
	}

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