Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.For example:  the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";  the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo". When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.

The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.

Print the given word without any changes if there are no typos. If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.

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

immutable string vowels = "aeiou";

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		string [] res;
main_loop:
		while (!s.empty)
		{
			foreach (i; 2..s.length)
			{
				if (!vowels.canFind (s[i - 2]) &&
				    !vowels.canFind (s[i - 1]) &&
				    !vowels.canFind (s[i - 0]) &&
				    (s[i - 2] != s[i - 1] ||
				    s[i - 1] != s[i - 0]))
				{
					res ~= s[0..i];
					s = s[i..$];
					continue main_loop;
				}
			}
			res ~= s;
			s = "";
		}
		res.join (" ").writeln;
	}
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.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)); }

bool isCon(char c) {
  return (" aeiou".indexOf(c) == -1);
}

bool isBad(char a, char b, char c) {
  return (isCon(a) && isCon(b) && isCon(c) && !(a == b && a == c));
}

void main() {
  try {
    for (; ; ) {
      const S = readToken();

      string ans;
      foreach (c; S) {
        for (; ans.length >= 2 && isBad(ans[$ - 2], ans[$ - 1], c); ) {
          ans ~= ' ';
        }
        ans ~= c;
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Alice and Bob play the following game. Alice has a set $$$S$$$ of disjoint ranges of integers, initially containing only one range $$$[1, n]$$$. In one turn, Alice picks a range $$$[l, r]$$$ from the set $$$S$$$ and asks Bob to pick a number in the range. Bob chooses a number $$$d$$$ ($$$l \le d \le r$$$). Then Alice removes $$$[l, r]$$$ from $$$S$$$ and puts into the set $$$S$$$ the range $$$[l, d - 1]$$$ (if $$$l \le d - 1$$$) and the range $$$[d + 1, r]$$$ (if $$$d + 1 \le r$$$). The game ends when the set $$$S$$$ is empty. We can show that the number of turns in each game is exactly $$$n$$$.After playing the game, Alice remembers all the ranges $$$[l, r]$$$ she picked from the set $$$S$$$, but Bob does not remember any of the numbers that he picked. But Bob is smart, and he knows he can find out his numbers $$$d$$$ from Alice's ranges, and so he asks you for help with your programming skill.Given the list of ranges that Alice has picked ($$$[l, r]$$$), for each range, help Bob find the number $$$d$$$ that Bob has picked.We can show that there is always a unique way for Bob to choose his number for a list of valid ranges picked by Alice.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). Each of the next $$$n$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$), denoting the range $$$[l, r]$$$ that Alice picked at some point. Note that the ranges are given in no particular order. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$1000$$$, and the ranges for each test case are from a valid game.

For each test case print $$$n$$$ lines. Each line should contain three integers $$$l$$$, $$$r$$$, and $$$d$$$, denoting that for Alice's range $$$[l, r]$$$ Bob picked the number $$$d$$$. You can print the lines in any order. We can show that the answer is unique. It is not required to print a new line after each test case. The new lines in the output of the example are for readability only.

NoteIn the first test case, there is only 1 range $$$[1, 1]$$$. There was only one range $$$[1, 1]$$$ for Alice to pick, and there was only one number $$$1$$$ for Bob to pick.In the second test case, $$$n = 3$$$. Initially, the set contains only one range $$$[1, 3]$$$.   Alice picked the range $$$[1, 3]$$$. Bob picked the number $$$1$$$. Then Alice put the range $$$[2, 3]$$$ back to the set, which after this turn is the only range in the set.  Alice picked the range $$$[2, 3]$$$. Bob picked the number $$$3$$$. Then Alice put the range $$$[2, 2]$$$ back to the set.  Alice picked the range $$$[2, 2]$$$. Bob picked the number $$$2$$$. The game ended. In the fourth test case, the game was played with $$$n = 5$$$. Initially, the set contains only one range $$$[1, 5]$$$. The game's turn is described in the following table.  Game turnAlice's picked rangeBob's picked numberThe range set afterBefore the game start$$$ \{ [1, 5] \} $$$1$$$[1, 5]$$$$$$3$$$$$$ \{ [1, 2], [4, 5] \}$$$2$$$[1, 2]$$$$$$1$$$$$$ \{ [2, 2], [4, 5] \} $$$3$$$[4, 5]$$$$$$5$$$$$$ \{ [2, 2], [4, 4] \} $$$4$$$[2, 2]$$$$$$2$$$$$$ \{ [4, 4] \} $$$5$$$[4, 4]$$$$$$4$$$$$$ \{ \} $$$ (empty set)

import std;

alias range = Tuple!(int, "l", int, "r");

void main () {
    immutable tests = to!int(readln().dropBackOne);

    foreach (test_index; 0 .. tests) {
        immutable n = to!int(readln().dropBackOne);

        immutable x = stdin
            .byLine
            .take(n)
            .map!(l => range(l.split.to!(int[2])))
            .array
            .sort!"a.r - a.l < b.r - b.l"
            .release
            .assumeUnique;

        auto notSeen = redBlackTree(iota(1, n + 1));
        auto viz     = new bool[n + 1];

        foreach (_, t; x) {
            immutable num = (){
                if (!viz[t.l])
                    return t.l;
                if (!viz[t.r])
                    return t.r;
                return notSeen.upperBound(t.l).front;
            }();

            writefln!"%s %s %s"(t.l, t.r, num);
            viz[num] = true;
            notSeen.removeKey(num);
        }

        writeln();
    }
}
// ""

void main() { runSolver(); }

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

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto R = scan!int(N * 2).chunks(2).array;
      string[] ans;

      bool[1001] visited;
      foreach(lr; R.sort!"(a[1] - a[0]).abs < (b[1] - b[0]).abs") {
        int n;
        foreach(m; lr[0]..lr[1] + 1) {
          if (!visited[m]) {
            n = m;
            visited[m] = true;
            break;
          }
        }
        ans ~= [lr[0], lr[1], n].toAnswerString;
      }

      ans.each!writeln;
    }

    foreach(i; 0..QN) {
      if (i > 0) "".writeln;
      subSolve();
    }
  }

  outputForAtCoder(&solve);
}

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

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

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

K binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }
T binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {
  auto ok = l;
  auto ng = r;
  const T TWO = 2;

  bool again() {
    static if (is(T == float) || is(T == double) || is(T == real)) {
      return !ng.approxEqual(ok, 1e-08, 1e-08);
    } else {
      return abs(ng - ok) > 1;
    }
  }

  while(again()) {
    const half = (ng + ok) / TWO;
    const halfValue = fn(half);

    if (cond(halfValue)) {
      ok = half;
    } else {
      ng = half;
    }
  }

  return ok;
}

import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,
       std.container, std.typecons, std.conv, std.random, std.bigint;

void read(S...)(ref S args) {
  auto input = readln.split;
  enforce(input.length == args.length);
  foreach (i, ref arg; args) {
    arg = input[i].to!(S[i]);
  }
}

auto list(T)() { return readln.split.map!(e => e.to!T).array; }

void main() {
  int T;
  read(T);
  while (T--) {
    int n;
    read(n);

    int[][] arr = new int[][n];

    foreach (i; 0 .. n) {
      arr[i] = list!int;
    }

    foreach (range; arr) {
      if (range.front == range.back) {
        writeln(range.front, ' ', range.back, ' ', range.back);
      } else if (arr.canFind([range.front + 1, range.back])) {
        writeln(range.front, ' ', range.back, ' ', range.front);
      } else if (arr.canFind([range.front, range.back - 1])) {
        writeln(range.front, ' ', range.back, ' ', range.back);
      } else {
        foreach (d; range.front + 1 .. range.back) {
          if (arr.canFind([range.front, d - 1]) && arr.canFind([d + 1, range.back])) {
            writeln(range.front, ' ', range.back, ' ', d);
          }
        }
      }
    }
  }
}

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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
double norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }
double dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }

//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 int[][][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto lr = new int[][](n);
		foreach (i; 0..n)
			lr[i] = [RD!int, RD!int];

		lr.sort!("a[0] == b[0] ? a[1] > b[1] : a[0] < b[0]");
		foreach (i; 1..n)
		{
			if (lr[i-1][0] == lr[i-1][1])
				ans[ti] ~= lr[i-1] ~ lr[i-1][0];
			else
			{
				if (lr[i-1][0] != lr[i][0])
					ans[ti] ~= lr[i-1] ~ (lr[i][0]-1);
				else
					ans[ti] ~= lr[i-1] ~ (lr[i][1]+1);
			}
		}
		ans[ti] ~= lr[n-1] ~ lr[n-1][0];
	}

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

// 提出解
void solve(){
	foreach(_; 0 .. scan!int){
		int n = scan!int;
		int[][] us = new int[][](n), vs = new int[][](n);
			// us[a][]: 左端がaである右端、vs[b][]:右端がbである左端
		foreach(i; 0 .. n){
			int l = scan!int - 1, r = scan!int - 1;
			us[l] ~= r, vs[r] ~= l;
		}
		foreach(i; 0 .. n) us[i].sort!"a>b";
		foreach(i; 0 .. n) vs[i].sort!"a<b";
		foreach(i; 0 .. n) foreach(r, j; us[i]){
			if(r == us[i].length - 1) print(i + 1, j + 1, i + 1);
			else print(i + 1, j + 1, us[i][r + 1] + 1 + 1);
		}
	}
}

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
// 愚直解
void jury(){
}

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
// テストケース
void gen(){
}

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
// テンプレ
import std;
bool DEBUG = 0;
void main(string[] args){
	if(args.canFind("-debug")) DEBUG = 1;
	if(args.canFind("-gen")) gen; else if(args.canFind("-jury")) jury; else solve;
}
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){ stdout.write(t, " "), print(a); }
string unsplit(T)(T xs, string d = " "){ return xs.array.to!(string[]).join(d); }
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 mini(T)(ref T x, T y){ if(x > y) x = y; return x; }
T maxi(T)(ref T x, T y){ if(x < y) x = y; return x; }
T mid(T)(T l, T r, bool delegate(T) f){
	T m = (l + r) / 2; (f(m)? l: r) = m; return f(l)? f(r - 1)? r: mid(l, r, f): l;
}

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
// ライブラリ（基本）

class UnionFind{
	this(int n){ foreach(i; 0 .. n) R ~= i, K ~= [i]; } int[] R; int[][] K;
	void unite(int a, int b){
		int ra = R[a], rb = R[b]; if(ra == rb) return;
		if(K[ra].length < K[rb].length) unite(b, a);
		else foreach(k; K[rb]) R[k] = ra, K[ra] ~= k;
	}
	int find(int a){ return R[a]; }
	int getSize(int a){ return K[R[a]].length.to!int; }
}
class Queue(T){
	private T[] xs; private uint i, j;
	this(T[] xs = []){ this.xs = xs; j = xs.length.to!uint; }
	uint length(){ return j - i; }
	bool isEmpty(){ return j == i; }
	void enq(T x){ while(j + 1 >= xs.length) xs.length = xs.length * 2 + 1; xs[j ++] = x; }
	T deq(){ assert(i < j); return xs[i ++]; }
	T peek(){ assert(i < j); return xs[i]; }
	void flush(){ i = j; }
	alias empty = isEmpty, front = peek, popFront = deq, pop = deq, push = enq, top = peek;
	Queue opOpAssign(string op)(T x) if(op == "~"){ enq(x); return this; }
	T opIndex(uint li){ assert(i + li < j); return xs[i + li]; }
	static Queue!T opCall(T[] xs){ return new Queue!T(xs); }
	T[] array(){ return xs[i .. j]; }
	override string toString(){ return array.to!string; }
}
class Stack(T){
	private T[] xs; private uint j;
	this(T[] xs = []){ this.xs = xs; j = xs.length.to!uint; }
	uint length(){ return j; }
	bool isEmpty(){ return j == 0; }
	void push(T x){ while(j + 1 >= xs.length) xs.length = xs.length * 2 + 1; xs[j ++] = x; }
	T pop(){ assert(j > 0); return xs[-- j]; }
	T peek(){ assert(j > 0); return xs[j - 1]; }
	void clear(){ j = 0; }
	alias empty = isEmpty, front = peek, popFront = pop, top = peek;
	Stack opOpAssign(string op)(T x) if(op == "~"){ push(x); return this; }
	T opIndex(uint li){ assert(j > 0 && j - 1 >= li); return xs[j - 1 - li]; }
	static Stack!T opCall(T[] xs = []){ return new Stack!T(xs); }
	T[] array(){ return xs[0 .. j]; }
	override string toString(){ return array.to!string; }
}

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
// ライブラリ（追加）

import std;

alias range = Tuple!(int, "l", int, "r");

void main () {
    immutable tests = to!int(readln().dropBackOne);

    foreach (test_index; 0 .. tests) {
        immutable n = to!int(readln().dropBackOne);

        immutable x = stdin
            .byLine
            .take(n)
            .map!(l => range(l.split.to!(int[2])))
            .array
            .sort!"a.r - a.l < b.r - b.l"
            .release
            .assumeUnique;

        auto notSeen = redBlackTree(iota(1, n + 1));
        auto viz     = new bool[n + 1];

        foreach (_, t; x) {
            assert(t.l == t.r || viz[t.l] || viz[t.r]);

            immutable num = (){
                if (!viz[t.l])
                    return t.l;
                if (!viz[t.r])
                    return t.r;
                return notSeen.upperBound(t.l).back;
            }();

            writefln!"%s %s %s"(t.l, t.r, num);
            viz[num] = true;
            notSeen.removeKey(num);
        }

        writeln();
    }
}
// ""


Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$.

The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively.

For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$.

NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$.

import std.stdio;

void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]))
      foreach(ref e; args[i])
	read(e);
    else
      readf!" %s"(args[i]);
}
alias r = read;
alias w = writeln;

int main()
{
  int n;
  r(n);
  foreach(e; 0 .. n)
    {
      int c, sum;
      r(c, sum);
	{
	  int avg = sum / c;
	  int residue = sum % c;
	  if (residue > 0)
	    {
	      w(avg * avg * (c - residue) + (avg + 1) * (avg + 1) * residue);
	    }
	  else
	    {
	      w(avg * avg * c);
	    }
	}
    }

  return 0;
}

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

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

void solve(){
	int n = rint;
	foreach(i; 0 .. n){
		long c = rlong, s = rlong;
		long x = s / c, d = s % c;
		long ans = (c - d) * x * x + d * (x + 1) * (x + 1);
		ans.writeln;
	}
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto n = RD!int;
	auto ans = new int[](n);
	foreach (i; 0..n)
	{
		auto c = RD!int;
		auto sum = RD!int;
		auto x = sum / c;
		auto y = sum % c;
		ans[i] += ((x+1)^^2) * y;
		ans[i] += (x^^2) * (c - y);
	}

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


The only difference between the two versions is that this version asks the minimal possible answer.Homer likes arrays a lot. Today he is painting an array $$$a_1, a_2, \dots, a_n$$$ with two kinds of colors, white and black. A painting assignment for $$$a_1, a_2, \dots, a_n$$$ is described by an array $$$b_1, b_2, \dots, b_n$$$ that $$$b_i$$$ indicates the color of $$$a_i$$$ ($$$0$$$ for white and $$$1$$$ for black).According to a painting assignment $$$b_1, b_2, \dots, b_n$$$, the array $$$a$$$ is split into two new arrays $$$a^{(0)}$$$ and $$$a^{(1)}$$$, where $$$a^{(0)}$$$ is the sub-sequence of all white elements in $$$a$$$ and $$$a^{(1)}$$$ is the sub-sequence of all black elements in $$$a$$$. For example, if $$$a = [1,2,3,4,5,6]$$$ and $$$b = [0,1,0,1,0,0]$$$, then $$$a^{(0)} = [1,3,5,6]$$$ and $$$a^{(1)} = [2,4]$$$.The number of segments in an array $$$c_1, c_2, \dots, c_k$$$, denoted $$$\mathit{seg}(c)$$$, is the number of elements if we merge all adjacent elements with the same value in $$$c$$$. For example, the number of segments in $$$[1,1,2,2,3,3,3,2]$$$ is $$$4$$$, because the array will become $$$[1,2,3,2]$$$ after merging adjacent elements with the same value. Especially, the number of segments in an empty array is $$$0$$$.Homer wants to find a painting assignment $$$b$$$, according to which the number of segments in both $$$a^{(0)}$$$ and $$$a^{(1)}$$$, i.e. $$$\mathit{seg}(a^{(0)})+\mathit{seg}(a^{(1)})$$$, is as small as possible. Find this number.

The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq n$$$).

Output a single integer, indicating the minimal possible total number of segments.

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

void main(){
    auto n = scan!int;
    auto arr = scanArray!int;
    auto seen = redBlackTree!int;
    int[] seg1, seg2;
    int[] cur;

    seg1 ~= arr[0];
    int i = 1;
    while(i < n && arr[i] == seg1.back){
        seg1 ~= arr[i];
        ++i;
    }
    if(i < n){
        seg2 ~= arr[i]; ++i;
        seen.insert([seg1.back, seg2.back]);
    }

    while(i < n){
        if(cur.length && arr[i] == cur.back){
            cur ~= arr[i];
        }else if(arr[i] in seen){
            if(arr[i] == seg2.back){
                seg2 ~= arr[i];
                foreach(el; cur){
                    if(el == arr[i]){
                        seg2 ~= el;
                    }else{
                        seg1 ~= el;
                    }
                }
            }else{
                seg1 ~= arr[i];
                foreach(el; cur){
                    if(el == arr[i]){
                        seg1 ~= el;
                    }else{
                        seg2 ~= el;
                    }
                }
            }

            // Reset seen & cur
            seen.clear;
            seen.insert([seg1.back, seg2.back]);
            cur = [];
        }else{
            cur ~= arr[i];
            seen.insert(arr[i]);
        }
        ++i;
    }
    // Post while
    seg2 ~= cur;
    cur = []; seen.clear;

    show(seg1, seg2);

    // Calc Answer
    auto res = 1;
    for(int k = 1; k < seg1.length; ++k){
        if(seg1[k] != seg1[k-1]){ ++res; }
    }
    res += (seg2.length > 0);
    for(int k = 1; k < seg2.length; ++k){
        if(seg2[k] != seg2[k-1]){ ++res; }
    }

    writeln(res);
}

/**************    *****    That's All Folks!    *****    **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
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.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 a = readln.splitter.map !(to !(int)).uniq.array;
		a = [-2, -1] ~ a;
		n = a.length;
		int res = 0;
		bool [int] seen;
		foreach (i; 2..n)
		{
			auto cur = a[i];
			if (cur == a[i - 2])
			{
				seen = null;
				seen[a[i - 1]] = true;
				seen[a[i]] = true;
			}
			else if (cur in seen)
			{
				seen = null;
				seen[a[i - 1]] = true;
				seen[a[i]] = true;
			}
			else
			{
				seen[a[i]] = true;
				res += 1;
			}
		}
		writeln (res);
	}
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      int N = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }
      A = A.uniq.array;
      N = cast(int)(A.length);
      debug {
        writeln("A = ", A);
      }

      const lim = A.maxElement + 1;
      auto app = new int[lim];
      app[] = -1;
      auto dp = new int[N + 1];
      foreach (i; 0 .. N) {
        dp[i + 1] = dp[i];
        const j = app[A[i]];
        if (j != -1) {
          chmax(dp[i + 1], dp[j + 2] + 1);
          if (j - 1 >= 0 && A[j - 1] == A[j + 1]) {
            chmax(dp[i + 1], dp[j + 1] + 2);
          }
        }
        app[A[i]] = i;
      }
      writeln(N - dp[N]);

      debug {
        int brt = N;
        foreach (p; 0 .. 1 << N) {
          int cost;
          int[2] bs = [-1, -1];
          foreach (i; 0 .. N) {
            const s = (p >> i) & 1;
            if (bs[s] != A[i]) {
              ++cost;
              bs[s] = A[i];
            }
          }
          chmin(brt, cost);
        }
        writeln("brt = ", brt);
        assert(brt == N - dp[N]);
      }
    }
  } catch (EOFException e) {
  }
}

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

void get(Args...)(ref Args args)
{
    import std.traits, std.meta, std.typecons;

    static if (Args.length == 1) {
        alias Arg = Args[0];

        static if (isArray!Arg) {
          static if (isSomeChar!(ElementType!Arg)) {
            args[0] = readln.chomp.to!Arg;
          } else {
            args[0] = readln.split.to!Arg;
          }
        } else static if (isTuple!Arg) {
            auto input = readln.split;
            static foreach (i; 0..Fields!Arg.length) {
                args[0][i] = input[i].to!(Fields!Arg[i]);
            }
        } else {
            args[0] = readln.chomp.to!Arg;
        }
    } else {
        auto input = readln.split;
        assert(input.length == Args.length);

        static foreach (i; 0..Args.length) {
            args[i] = input[i].to!(Args[i]);
        }
    }
}

void get_lines(Args...)(size_t N, ref Args args)
{
    import std.traits, std.range;

    static foreach (i; 0..Args.length) {
        static assert(isArray!(Args[i]));
        args[i].length = N;
    }

    foreach (i; 0..N) {
        static if (Args.length == 1) {
            get(args[0][i]);
        } else {
            auto input = readln.split;
            static foreach (j; 0..Args.length) {
                args[j][i] = input[j].to!(ElementType!(Args[j]));
            }
        }
    }
}

void main()
{
    int N; get(N);
    int[] aa; get(aa);
    auto nxt = new int[][10^^5 + 1];
    foreach (i, a; aa) nxt[a] ~= i.to!int;

    int x, y, c;
    foreach (a; aa) {
        nxt[a].popFront();
        if (a == x || a == y) continue;
        if (nxt[x].empty) {
            x = a;
        } else if (nxt[y].empty) {
            y = a;
        } else if (nxt[x].front > nxt[y].front) {
            x = a;
        } else {
            y = a;
        }
        ++c;
    }
    writeln(c);
}

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

void main(){
    auto n = scan!int;
    auto arr = scanArray!int;
    auto seen = redBlackTree!int;
    int[] seg1, seg2;
    int[] cur;

    seg1 ~= arr[0];
    int i = 1;
    while(i < n && arr[i] == seg1.back){
        seg1 ~= arr[i];
        ++i;
    }
    if(i < n){
        seg2 ~= arr[i]; ++i;
        seen.insert([seg1.back, seg2.back]);
    }

    while(i < n){
        if(cur.length && arr[i] == cur.back){
            cur ~= arr[i];
        }else if(arr[i] in seen){
            if(arr[i] == seg2.back){
                seg2 ~= arr[i];
                foreach(el; cur){
                    if(el == arr[i]){
                        seg2 ~= el;
                    }else{
                        seg1 ~= el;
                    }
                }
            }else{
                seg1 ~= arr[i];
                foreach(el; cur){
                    if(el == arr[i]){
                        seg1 ~= el;
                    }else{
                        seg2 ~= el;
                    }
                }
            }

            // Reset seen & cur
            seen.clear;
            seen.insert([seg1.back, seg2.back]);
            cur = [];
        }else{
            cur ~= arr[i];
        }
        ++i;
    }
    // Post while
    seg2 ~= cur;
    cur = []; seen.clear;

    show(seg1, seg2);

    // Calc Answer
    auto res = 1;
    for(int k = 1; k < seg1.length; ++k){
        if(seg1[k] != seg1[k-1]){ ++res; }
    }
    res += (seg2.length > 0);
    for(int k = 1; k < seg2.length; ++k){
        if(seg2[k] != seg2[k-1]){ ++res; }
    }

    writeln(res);
}

/**************    *****    That's All Folks!    *****    **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
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");

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

void main(){
    auto n = scan!int;
    auto arr = scanArray!int;
    auto seen = redBlackTree!int;
    int[] seg1, seg2;
    int[] cur;

    seg1 ~= arr[0];
    int i = 1;
    while(i < n && arr[i] == seg1.back){
        seg1 ~= arr[i];
        ++i;
    }
    if(i < n){
        seg2 ~= arr[i]; ++i;
        seen.insert([seg1.back, seg2.back]);
    }

    while(i < n){
        if(arr[i] in seen){
            if(arr[i] == seg2.back){
                seg1 ~= cur;
                seg2 ~= arr[i];
            }else{
                seg1 ~= arr[i];
                foreach(el; cur){
                    if(el == arr[i]){
                        seg1 ~= el;
                    }else{
                        seg2 ~= el;
                    }
                }
            }

            // Reset seen & cur
            seen.clear;
            seen.insert([seg1.back, seg2.back]);
            cur = [];
        }else{
            cur ~= arr[i];
        }
        ++i;
    }
    // Post while
    seg2 ~= cur;
    cur = []; seen.clear;

    show(seg1, seg2);

    // Calc Answer
    auto res = 1;
    for(int k = 1; k < seg1.length; ++k){
        if(seg1[k] != seg1[k-1]){ ++res; }
    }
    res += (seg2.length > 0);
    for(int k = 1; k < seg2.length; ++k){
        if(seg2[k] != seg2[k-1]){ ++res; }
    }

    writeln(res);
}

/**************    *****    That's All Folks!    *****    **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
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.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 a = readln.splitter.map !(to !(int)).array;
		int res = 0;
		int [2] [] p = [[-1, -1]];
		foreach (ref c; a)
		{
			int [2] [] [2] q;
			int next = res;
			foreach (ref prev; p)
			{
				foreach (j; 0..2)
				{
					auto good = (prev[j] != c);
					q[good] ~= [c, prev[!j]];
	                	}
			}
			foreach_reverse (j; 0..2)
			{
				if (!q[j].empty)
				{
					res = next + j;
					p = q[j];
				}
			}
			foreach (ref prev; p)
			{
				sort (prev[]);
			}
			p = p.sort.uniq.take (4).array;
		}
		writeln (res);
	}
}


Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by swiping right from the last photo you reach photo 1. It takes a seconds to swipe from photo to adjacent.For each photo it is known which orientation is intended for it — horizontal or vertical. Phone is in the vertical orientation and can't be rotated. It takes b second to change orientation of the photo.Vasya has T seconds to watch photos. He want to watch as many photos as possible. If Vasya opens the photo for the first time, he spends 1 second to notice all details in it. If photo is in the wrong orientation, he spends b seconds on rotating it before watching it. If Vasya has already opened the photo, he just skips it (so he doesn't spend any time for watching it or for changing its orientation). It is not allowed to skip unseen photos.Help Vasya find the maximum number of photos he is able to watch during T seconds.

The first line of the input contains 4 integers n, a, b, T (1 ≤ n ≤ 5·105, 1 ≤ a, b ≤ 1000, 1 ≤ T ≤ 109) — the number of photos, time to move from a photo to adjacent, time to change orientation of a photo and time Vasya can spend for watching photo. Second line of the input contains a string of length n containing symbols 'w' and 'h'.  If the i-th position of a string contains 'w', then the photo i should be seen in the horizontal orientation. If the i-th position of a string contains 'h', then the photo i should be seen in vertical orientation.

Output the only integer, the maximum number of photos Vasya is able to watch during those T seconds.

NoteIn the first sample test you can rotate the first photo (3 seconds), watch the first photo (1 seconds), move left (2 second), rotate fourth photo (3 seconds), watch fourth photo (1 second). The whole process takes exactly 10 seconds.Note that in the last sample test the time is not enough even to watch the first photo, also you can't skip it.

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

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

    auto s = readln.chomp;
    auto cost = s.map!(x => 1 + (x == 'w' ? b : 0)).array;

    debug { cost.writeln; }

    if (cost[0] > T) {
        writeln(0);
        return;
    }

    T -= cost[0];
    cost = cost.dropOne;

    int go(int[] rightcost, int[] leftcost, int n, int T) {
        auto ans = 0;
        auto leftsum = leftcost.sum + a * n;
        auto leftidx = n;
        auto rightsum = 0;
        auto rightidx = 0;
        while (rightidx < n) {
            rightsum += rightcost[rightidx] + a;
            ++rightidx;
            leftsum += a;

            while (leftsum + rightsum > T && leftidx > 0) {
                leftidx -= 1;
                leftsum -= leftcost[leftidx] + a;
            }

            if (rightsum <= T) {
                ans = max(ans, rightidx);
                if (leftsum + rightsum <= T) {
                    ans = max(ans, min(n, leftidx + rightidx));
                }
            }

            debug { writeln([rightidx, rightsum, leftidx, leftsum, ans].map!(to!string).join(" ")); }
        }

        return ans;
    }

    auto costrev = cost.dup.retro().array;

    int ans = 1 + max(go(cost, costrev, n-1, T), go(costrev, cost, n-1, T));
    ans.writeln;
}

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

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

    auto s = readln.chomp;
    auto cost = s.map!(x => 1 + (x == 'w' ? b : 0)).array;

    debug { cost.writeln; }

    if (cost[0] > T) {
        writeln(0);
        return;
    }

    n -= 1;
    T -= cost[0];
    cost = cost.dropOne;

    int go(int[] rightcost, int[] leftcost, int n, int T) {
        auto ans = 0;
        auto leftsum = leftcost.sum + a * n;
        auto leftidx = n;
        auto rightsum = 0;
        auto rightidx = 0;
        while (rightidx < n) {
            rightsum += rightcost[rightidx] + a;
            ++rightidx;
            leftsum += a;

            while (leftsum + rightsum > T && leftidx > 0) {
                leftidx -= 1;
                leftsum -= leftcost[leftidx] + a;
            }

            if (rightsum <= T) {
                ans = max(ans, rightidx);
                if (leftsum + rightsum <= T) {
                    ans = max(ans, min(n, leftidx + rightidx));
                }
            }

            debug { writeln([rightidx, rightsum, leftidx, leftsum, ans].map!(to!string).join(" ")); }
        }

        return ans;
    }

    auto costrev = cost.dup.retro().array;

    int ans = 1 + max(go(cost, costrev, n, T), go(costrev, cost, n, T));
    ans.writeln;
}

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

void main ()
{
	int n, a, b, t;
	while (readf (" %s %s %s %s", &n, &a, &b, &t) > 0)
	{
		readln;
		auto p = readln.strip.map !(q{a == 'w'}).array;
		auto q = p.dup;
		reverse (q[1..$]);
		t -= p[0] * b;
		t--;

		long [] fun (bool [] r)
		{
			auto res = [0L];
			res.reserve (n);
			foreach (i; 1..n)
			{
				res ~= res.back + a + b * r[i] + 1;
			}
			return res;
		}

		auto gp = fun (p);
		auto gq = fun (q);

		int solve (long [] fp, long [] fq)
		{
			int res = 0;
			int j = 0;
			while (j < n && fq[j] <= t)
			{
				j++;
			}
			j--;
			res = max (res, j);

			foreach (i; 1..n)
			{
				if (t < fp[i])
				{
					break;
				}
				res = max (res, i);
				while (j > 0 && t < fp[i] + fq[j] + i * a)
				{
					j--;
				}
				res = max (res, i + j);
			}
			return res;
		}

		int res = max (solve (gp, gq), solve (gq, gp));
		res = min (res, n - 1);
		if (t >= 0)
		{
			res++;
		}
		writeln (res);
	}
}


This is an interactive problem. In the output section below you will see the information about flushing the output.On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in Vičkopolis. Upon arrival, they left the car in a huge parking lot near the restaurant and hurried inside the building.In the restaurant a polite waiter immediately brought the menu to Leha and Noora, consisting of n dishes. It is interesting that all dishes in the menu are numbered with integers from 1 to n. After a little thought, the girl ordered exactly k different dishes from available in the menu. To pass the waiting time while the chefs prepare ordered dishes, the girl invited the hacker to play a game that will help them get to know each other better.The game itself is very simple: Noora wants Leha to guess any two dishes among all ordered. At the same time, she is ready to answer only one type of questions. Leha can say two numbers x and y (1 ≤ x, y ≤ n). After that Noora chooses some dish a for the number x such that, at first, a is among the dishes Noora ordered (x can be equal to a), and, secondly, the value  is the minimum possible. By the same rules the girl chooses dish b for y. After that Noora says «TAK» to Leha, if , and «NIE» otherwise. However, the restaurant is preparing quickly, so Leha has enough time to ask no more than 60 questions. After that he should name numbers of any two dishes Noora ordered.Help Leha to solve this problem!

There are two numbers n and k (2 ≤ k ≤ n ≤ 105) in the single line of input denoting the number of dishes in the menu and the number of dishes Noora ordered.

If you want to provide an answer, output a string of the form 2 x y (1 ≤ x, y ≤ n, x ≠ y), if you think the dishes x and y was among dishes ordered by Noora. After that, flush the output and terminate your program.

NoteThere are three dishes in sample. Noora ordered dished numberes 2 and 3, which Leha should guess. If Noora receive requests for the first dish (x = 1), then she'll choose the second dish (a = 2) as the dish with the minimum value . For the second (x = 2) and the third (x = 3) dishes themselves will be optimal, because in that case . Let Leha asks Noora about the next couple of dishes:  x = 1, y = 2, then he'll recieve «NIE» answer, because |1 - 2| > |2 - 2|  x = 2, y = 1, then he'll recieve «TAK» answer, because |2 - 2| ≤ |1 - 2|  x = 1, y = 3, then he'll recieve «NIE» answer, because |1 - 2| > |3 - 3|  x = 3, y = 1, then he'll recieve «TAK» answer, because |3 - 3| ≤ |1 - 2|  x = 2, y = 3, then he'll recieve «TAK» answer, because |2 - 2| ≤ |3 - 3|  x = 3, y = 2, then he'll recieve «TAK» answer, because |3 - 3| ≤ |2 - 2| According to the available information, it is possible to say that Nura ordered dishes with numbers 2 and 3.

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

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

    int hi = N - 1;
    int lo = 0;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid + 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }
    int ans1 = hi;

    if (hi >= 2) {
        hi = hi - 1;
        lo = 0;
        while (hi - lo > 1) {
            int mid = (hi + lo) / 2;
            writeln(1, " ", mid, " ", mid + 1);
            stdout.flush;
            if (readln.chomp == "TAK") hi = mid;
            else lo = mid;
        }

        writeln(1, " ", hi, " ", ans1);
        stdout.flush;
        if (readln.chomp == "TAK") {
            writeln(2, " ", hi, " ", ans1);
            return;
        }
    }

    hi = N + 1;
    lo = ans1 + 1;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid - 1);
        stdout.flush;
        if (readln.chomp == "TAK") lo = mid;
        else hi = mid;
    }

    writeln(2, " ", ans1, " ", lo);
}

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

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

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

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

int N, K;
debug {
  int[] A;
}

bool Ask(int x, int y) {
  bool ret;
  debug {
    int xm = N, ym = N;
    foreach (a; A) {
      chmin(xm, abs(x - a));
      chmin(ym, abs(y - a));
    }
    ret = (xm <= ym);
    writefln("Ask %s %s = %s", x, y, ret);
  } else {
    writefln("1 %s %s", x, y);
    stdout.flush;
    const res = readToken();
    ret = (res == "TAK");
  }
  return ret;
}

void Answer(int x, int y) {
  writefln("2 %s %s", x, y);
  stdout.flush;
  debug {
    assert(A.count(x) > 0);
    assert(A.count(y) > 0);
  }
}

void main() {
  N = readInt();
  K = readInt();
  debug {
    A = new int[K];
    foreach (i; 0 .. K) {
      A[i] = readInt();
    }
  }

  int solve(int lo, int hi, int ini = 0) {
    for (; lo + 1 < hi; ) {
      int mid = (lo + hi) / 2;
      if (ini == 1) {
        mid = (lo + lo + hi) / 3;
        ini = 0;
      }
      if (ini == 2) {
        mid = (lo + hi + hi) / 3;
        ini = 0;
      }
      if (Ask(mid, mid + 1)) {
        hi = mid;
      } else {
        lo = mid + 1;
      }
    }
    return Ask(lo, hi) ? lo : hi;
  }

  int ans0, ans1;

  ans0 = solve(1, N);
  if (1 <= ans0 - 1) {
    const res = solve(1, ans0 - 1, 1);
    if (Ask(res, ans0)) {
      ans1 = res;
    }
  }
  if (!ans1) {
    ans1 = solve(ans0 + 1, N, 2);
  }

  Answer(ans0, ans1);
}

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

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

    int hi = N - 1;
    int lo = 0;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid + 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }
    int ans1 = hi;

    if (hi >= 2) {
        hi = hi - 1;
        lo = 0;
        while (hi - lo > 1) {
            int mid = (hi + lo) / 2;
            writeln(1, " ", mid, " ", mid + 1);
            stdout.flush;
            if (readln.chomp == "TAK") hi = mid;
            else lo = mid;
        }

        writeln(1, " ", hi, " ", ans1);
        stdout.flush;
        if (readln.chomp == "TAK") {
            writeln(2, " ", hi, " ", ans1);
            return;
        }
    }

    hi = N;
    lo = ans1;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid - 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }

    writeln(2, " ", ans1, " ", hi);
}

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

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

    int hi = N - 1;
    int lo = 0;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid + 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }
    int ans1 = hi;

    if (hi >= 2) {
        hi = hi - 1;
        lo = 0;
        while (hi - lo > 1) {
            int mid = (hi + lo) / 2;
            writeln(1, " ", mid, " ", mid + 1);
            stdout.flush;
            if (readln.chomp == "TAK") hi = mid;
            else lo = mid;
        }

        writeln(1, " ", hi, " ", ans1);
        stdout.flush;
        if (readln.chomp == "TAK") {
            writeln(2, " ", hi, " ", ans1);
            return;
        }
    }

    hi = N + 1;
    lo = ans1 + 1;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid - 1);
        stdout.flush;
        if (readln.chomp == "TAK") lo = mid;
        else hi = mid;
    }

    writeln(2, " ", ans1, " ", hi);
}

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

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

    int hi = N;
    int lo = 0;
    while (hi - lo > 1) {
        int mid = (hi + lo)/ 2;
        writeln(1, " ", mid, " ", mid + 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }
    int ans1 = hi;

    hi = N + 1;
    lo = 1;
    while (hi - lo > 1) {
        int mid = (hi + lo)/ 2;
        writeln(1, " ", mid, " ", mid - 1);
        stdout.flush;
        if (readln.chomp == "TAK") lo = mid;
        else hi = mid;
    }
    int ans2 = lo;

    writeln(2, " ", ans1, " ", ans2);
}

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

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

    int hi = N - 1;
    int lo = 0;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid + 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }
    int ans1 = hi;

    hi = N + 1;
    lo = 2;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid - 1);
        stdout.flush;
        if (readln.chomp == "TAK") lo = mid;
        else hi = mid;
    }
    int ans2 = lo;

    writeln(2, " ", ans1, " ", ans2);
}

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

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

    int hi = N - 1;
    int lo = 0;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid + 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }
    int ans1 = hi;

    hi = hi - 1;
    lo = 0;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid + 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }

    writeln(1, " ", hi, " ", ans1);
    stdout.flush;
    if (readln.chomp == "TAK") {
        writeln(2, " ", hi, " ", ans1);
        return;
    }

    hi = N;
    lo = ans1;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid - 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }

    writeln(2, " ", ans1, " ", hi);
}

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

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

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

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

int N, K;
debug {
  int[] A;
}

bool Ask(int x, int y) {
  bool ret;
  debug {
    int xm = N, ym = N;
    foreach (a; A) {
      chmin(xm, abs(x - a));
      chmin(ym, abs(y - a));
    }
    ret = (xm <= ym);
    writefln("Ask %s %s = %s", x, y, ret);
  } else {
    writefln("1 %s %s", x, y);
    stdout.flush;
    const res = readToken();
    ret = (res == "TAK");
  }
  return ret;
}

void Answer(int x, int y) {
  writefln("2 %s %s", x, y);
  stdout.flush;
  debug {
    assert(A.count(x) > 0);
    assert(A.count(y) > 0);
  }
}

void main() {
  N = readInt();
  K = readInt();
  debug {
    A = new int[K];
    foreach (i; 0 .. K) {
      A[i] = readInt();
    }
  }

  int ans0, ans1;
  {
    int lo = 1, hi = N;
    for (; lo + 1 < hi; ) {
      const mid = (lo + hi) / 2;
      (Ask(lo, hi) ? hi : lo) = mid;
    }
    ans0 = Ask(lo, hi) ? lo : hi;
  }
  if (1 <= ans0 - 1) {
    int lo = 1, hi = ans0 - 1;
    for (; lo + 1 < hi; ) {
      const mid = (lo + hi) / 2;
      (Ask(lo, hi) ? hi : lo) = mid;
    }
    const x = Ask(lo, hi) ? lo : hi;
    if (Ask(x, ans0)) {
      ans1 = x;
    }
  }
  if (!ans1) {
    int lo = ans0 + 1, hi = N;
    for (; lo + 1 < hi; ) {
      const mid = (lo + hi) / 2;
      (Ask(lo, hi) ? hi : lo) = mid;
    }
    ans1 = Ask(lo, hi) ? lo : hi;
  }

  Answer(ans0, ans1);
}

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

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

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

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

int N, K;
debug {
  int[] A;
}

bool Ask(int x, int y) {
  bool ret;
  debug {
    int xm = N, ym = N;
    foreach (a; A) {
      chmin(xm, abs(x - a));
      chmin(ym, abs(y - a));
    }
    ret = (xm <= ym);
    writefln("Ask %s %s = %s", x, y, ret);
  } else {
    writefln("1 %s %s", x, y);
    stdout.flush;
    const res = readToken();
    ret = (res == "TAK");
  }
  return ret;
}

void Answer(int x, int y) {
  writefln("2 %s %s", x, y);
  stdout.flush;
  debug {
    assert(A.count(x) > 0);
    assert(A.count(y) > 0);
  }
}

void main() {
  N = readInt();
  K = readInt();
  debug {
    A = new int[K];
    foreach (i; 0 .. K) {
      A[i] = readInt();
    }
  }

  int solve(int lo, int hi, int ini = 0) {
    for (; lo + 1 < hi; ) {
      int mid = (lo + hi) / 2;
      if (ini == 1) {
        mid = (lo + lo + hi) / 3;
        ini = 0;
      }
      if (ini == 2) {
        mid = (lo + hi + hi) / 3;
        ini = 0;
      }
      if (Ask(mid, mid + 1)) {
        hi = mid;
      } else {
        lo = mid + 1;
      }
    }
    return Ask(lo, hi) ? lo : hi;
  }

  int ans0, ans1;

  ans0 = solve(1, N);
  if (1 <= ans0 - 1) {
    ans1 = solve(1, ans0 - 1, 1);
  }
  if (!Ask(ans1, ans0)) {
    ans1 = solve(ans0 + 1, N, 2);
  }

  Answer(ans0, ans1);
}

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

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

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

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

int N, K;
debug {
  int[] A;
}

bool Ask(int x, int y) {
  bool ret;
  debug {
    int xm = N, ym = N;
    foreach (a; A) {
      chmin(xm, abs(x - a));
      chmin(ym, abs(y - a));
    }
    ret = (xm <= ym);
    writefln("Ask %s %s = %s", x, y, ret);
  } else {
    writefln("1 %s %s", x, y);
    stdout.flush;
    const res = readToken();
    ret = (res == "TAK");
  }
  return ret;
}

void Answer(int x, int y) {
  writefln("2 %s %s", x, y);
  stdout.flush;
  debug {
    assert(A.count(x) > 0);
    assert(A.count(y) > 0);
  }
}

void main() {
  N = readInt();
  K = readInt();
  debug {
    A = new int[K];
    foreach (i; 0 .. K) {
      A[i] = readInt();
    }
  }

  int solve(int lo, int hi) {
    for (; lo + 1 < hi; ) {
      const mid = (lo + hi) / 2;
      (Ask(lo, hi) ? hi : lo) = mid;
    }
    return Ask(lo, hi) ? lo : hi;
  }

  int ans0, ans1;

  ans0 = solve(1, N);
  for (int e = 0; ans0 + (1 << e) <= N; ++e) {
    if (Ask(ans0 + (1 << e), ans0 + (1 << e) - 1)) {
      ans1 = solve(ans0 + (1 << e) - 1, N);
      goto found;
    }
  }
  for (int e = 0; ans0 + (1 << e) <= N; ++e) {
    if (Ask(ans0 - (1 << e), ans0 - (1 << e) + 1)) {
      ans1 = solve(1, ans0 - (1 << e) + 1);
      goto found;
    }
  }
 found:

  Answer(ans0, ans1);
}


Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally:   There is no road between a and b.  There exists a sequence (path) of n distinct cities v1, v2, ..., vn that v1 = a, vn = b and there is a road between vi and vi + 1 for . On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u1, u2, ..., un that u1 = c, un = d and there is a road between ui and ui + 1 for .Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly.Given n, k and four distinct cities a, b, c, d, can you find possible paths (v1, ..., vn) and (u1, ..., un) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.

The first line of the input contains two integers n and k (4 ≤ n ≤ 1000, n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively. The second line contains four distinct integers a, b, c and d (1 ≤ a, b, c, d ≤ n).

Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d. Two paths generate at most 2n - 2 roads: (v1, v2), (v2, v3), ..., (vn - 1, vn), (u1, u2), (u2, u3), ..., (un - 1, un). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y) and (y, x) are the same road.

NoteIn the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.

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

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(int)).array;
		if (n == 4 || k < n + 1)
		{
			writeln (-1);
		}
		else
		{
			auto b = iota (1, n + 1)
			    .filter !(x => a.find (x).empty).array;
			writefln ("%(%s %)", chain (only (a[0], a[2]),
			    b, only (a[3], a[1])));
			writefln ("%(%s %)", chain (only (a[2], a[0]),
			    b, only (a[1], a[3])));
		}
	}
}

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

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(int)).array;
		if (k < n)
		{
			writeln (-1);
		}
		else
		{
			auto b = iota (1, n + 1)
			    .filter !(x => a.find (x).empty).array;
			auto c = a ~ b;
			writefln ("%(%s %)", c.cycle.drop (1).take (n).retro);
			writefln ("%(%s %)", c.cycle.drop (3).take (n).retro);
		}
	}
}


Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.

In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad. In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.

Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.

NoteIn first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.

import std.stdio;
void main() {
  const int l = 200001;

  int n;
  scanf("%d", &n);

  int [l] a;
  foreach(i; 0..n) {
    scanf("%d", &a[i]);
  }

  bool [l] v;
  int m;
  for(int i = n-1; i >= 0; --i) {
    if (!v[a[i]]) {
      v[a[i]] = true;
      m = a[i];
    }
  }

  printf("%d\n", m);
}


Bessie has way too many friends because she is everyone's favorite cow! Her new friend Rabbit is trying to hop over so they can play! More specifically, he wants to get from $$$(0,0)$$$ to $$$(x,0)$$$ by making multiple hops. He is only willing to hop from one point to another point on the 2D plane if the Euclidean distance between the endpoints of a hop is one of its $$$n$$$ favorite numbers: $$$a_1, a_2, \ldots, a_n$$$. What is the minimum number of hops Rabbit needs to get from $$$(0,0)$$$ to $$$(x,0)$$$? Rabbit may land on points with non-integer coordinates. It can be proved that Rabbit can always reach his destination.Recall that the Euclidean distance between points $$$(x_i, y_i)$$$ and $$$(x_j, y_j)$$$ is $$$\sqrt{(x_i-x_j)^2+(y_i-y_j)^2}$$$.For example, if Rabbit has favorite numbers $$$1$$$ and $$$3$$$ he could hop from $$$(0,0)$$$ to $$$(4,0)$$$ in two hops as shown below. Note that there also exists other valid ways to hop to $$$(4,0)$$$ in $$$2$$$ hops (e.g. $$$(0,0)$$$ $$$\rightarrow$$$ $$$(2,-\sqrt{5})$$$ $$$\rightarrow$$$ $$$(4,0)$$$).    Here is a graphic for the first example. Both hops have distance $$$3$$$, one of Rabbit's favorite numbers. In other words, each time Rabbit chooses some number $$$a_i$$$ and hops with distance equal to $$$a_i$$$ in any direction he wants. The same number can be used multiple times.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Next $$$2t$$$ lines contain test cases — two lines per test case. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le x \le 10^9$$$)  — the number of favorite numbers and the distance Rabbit wants to travel, respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)  — Rabbit's favorite numbers. It is guaranteed that the favorite numbers are distinct. It is guaranteed that the sum of $$$n$$$ over all the test cases will not exceed $$$10^5$$$.

For each test case, print a single integer — the minimum number of hops needed.

NoteThe first test case of the sample is shown in the picture above. Rabbit can hop to $$$(2,\sqrt{5})$$$, then to $$$(4,0)$$$ for a total of two hops. Each hop has a distance of $$$3$$$, which is one of his favorite numbers.In the second test case of the sample, one way for Rabbit to hop $$$3$$$ times is: $$$(0,0)$$$ $$$\rightarrow$$$ $$$(4,0)$$$ $$$\rightarrow$$$ $$$(8,0)$$$ $$$\rightarrow$$$ $$$(12,0)$$$.In the third test case of the sample, Rabbit can hop from $$$(0,0)$$$ to $$$(5,0)$$$.In the fourth test case of the sample, Rabbit can hop: $$$(0,0)$$$ $$$\rightarrow$$$ $$$(5,10\sqrt{2})$$$ $$$\rightarrow$$$ $$$(10,0)$$$.

// https://codeforces.com/problemset/problem/1307/B
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;

void main() {
    int t = readln.chomp.to!int;
    foreach(_; 0..t) {
        int n, x;
        readf("%s %s\n", &n, &x);

        int[] a = readln.split.map!(to!int).array;
        a.sort();

        if(a.count(x) > 0) {
            1.writeln;
            continue;
        }

        long ans = max(2, ceil(real(x)/a[$-1])).to!long;
        writefln("%s", ans);
    }
}

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

final class InputReader {
  private:
  ubyte[] p, buffer;
  bool eof;
  bool rawRead () {
    if (eof) {
      return false;
    }
    p = stdin.rawRead (buffer);
    if (p.empty) {
      eof = true;
      return false;
    }
    return true;
  }
  ubyte nextByte(bool check) () {
    static if (check) {
      if (p.empty) {
        if (!rawRead ()) {
          return 0;
        }
      }
    }
    auto r = p.front;
    p.popFront ();
    return r;
  }
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
  }
  bool seekByte (in ubyte lo) {
    while (true) {
      p = p.find! (c => c >= lo);
      if (!p.empty) {
        return false;
      }
      if (!rawRead ()) {
        return true;
      }
    }
  }
  template next(T) if (isSigned!T) {
    T next ()  {
      if (seekByte (45)) {
        return 0;
      }
      T res;
      ubyte b = nextByte!false ();
      if (b == 45) {
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    T next () {
      if (seekByte (48)) {
        return 0;
      }
      T res = nextByte!false () - 48;
      while (true) {
        ubyte b = nextByte!true ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  T[] nextA(T) (in int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

void main() {
  auto r = new InputReader ();
  immutable nt = r.next!uint ();
  auto ans = new int[nt];
  foreach (tid; 0 .. nt) {
    const uint n = r.next!uint();
    const uint x = r.next!uint();
    auto a = r.nextA!uint (n);
    int res = int.max;
    int check (const int k) {
      if (x < k) {
        return 2;
      }
      int t = x / k;
      if (x % k) ++t;
      return t;
    }
    foreach_reverse (k; a) {
      res = min (res, check (k));
    }
    ans[tid] = res;
  }
  writefln!"%(%s\n%)"(ans);
}

import std.stdio : writeln;

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

    string[] tokens;
}

void main() {
    import std.algorithm : max, maxElement;

    IO io;
    int T = io.readInt;
    while (T--) {
        int n = io.readInt;
        int x = io.readInt;
        int[] a = new int[n];
        bool found = false;
        for (int i = 0; i < n; ++i) {
            a[i] = io.readInt;
            found |= a[i] == x;
        }
        if (found) {
            writeln(1);
        }
        else {
            int maxa = a.maxElement;
            writeln(max(2, (x + maxa - 1) / maxa));
        }
    }
}

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 long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto x = RD;
		auto a = RDA;
		bool isOne;
		long y;
		foreach (i; 0..n)
		{
			if (a[i] == x)
				isOne = true;
			y.chmax(a[i]);
		}
		if (isOne)
			ans[ti] = 1;
		else
			ans[ti] = max(2, (x+y-1) / y);
	}

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

// https://codeforces.com/problemset/problem/1307/B
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;

void main() {
    int t = readln.chomp.to!int;
    foreach(_; 0..t) {
        int n, x;
        readf("%s %s\n", &n, &x);

        int[] a = readln.split.map!(to!int).array;
        a.sort();

        if(a.count(x) > 0) {
            1.writeln;
            continue;
        }

        writefln("%s", max(2, ceil(real(x)/a[$-1])));
    }
}

// https://codeforces.com/problemset/problem/1307/B
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;

void main() {
    int t = readln.chomp.to!int;
    foreach(_; 0..t) {
        int n, x;
        readf("%s %s\n", &n, &x);

        int[] a = readln.split.map!(to!int).array;
        a.sort();

        if(a.count(x) > 0) {
            1.writeln;
            continue;
        }

        writefln("%s", max(2, ceil(real(x/a[$-1]))));
    }
}

// https://codeforces.com/problemset/problem/1307/B
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;

void main() {
    int t = readln.chomp.to!int;
    foreach(_; 0..t) {
        int n, x;
        readf("%s %s\n", &n, &x);

        int[] a = readln.split.map!(to!int).array;
        a.sort();

        if(a.count(x) > 0) {
            1.writeln;
            continue;
        }

        max(2, ceil(real(x)/a[$-1])).writeln;
    }
}

// https://codeforces.com/problemset/problem/1307/B
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;

void main() {
    int t = readln.chomp.to!int;
    foreach(_; 0..t) {
        int n, x;
        readf("%s %s\n", &n, &x);
        int[] a = readln.split.map!(to!int).array;
        a.sort();
        writefln("%s", max(2, x/a[$-1]+1));
    }
}

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

final class InputReader {
  private:
  ubyte[] p, buffer;
  bool eof;
  bool rawRead () {
    if (eof) {
      return false;
    }
    p = stdin.rawRead (buffer);
    if (p.empty) {
      eof = true;
      return false;
    }
    return true;
  }
  ubyte nextByte(bool check) () {
    static if (check) {
      if (p.empty) {
        if (!rawRead ()) {
          return 0;
        }
      }
    }
    auto r = p.front;
    p.popFront ();
    return r;
  }
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
  }
  bool seekByte (in ubyte lo) {
    while (true) {
      p = p.find! (c => c >= lo);
      if (!p.empty) {
        return false;
      }
      if (!rawRead ()) {
        return true;
      }
    }
  }
  template next(T) if (isSigned!T) {
    T next ()  {
      if (seekByte (45)) {
        return 0;
      }
      T res;
      ubyte b = nextByte!false ();
      if (b == 45) {
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    T next () {
      if (seekByte (48)) {
        return 0;
      }
      T res = nextByte!false () - 48;
      while (true) {
        ubyte b = nextByte!true ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  T[] nextA(T) (in int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

void main() {
  auto r = new InputReader ();
  immutable nt = r.next!uint ();
  auto ans = new int[nt];
  foreach (tid; 0 .. nt) {
    const uint n = r.next!uint();
    const uint x = r.next!uint();
    auto a = r.nextA!uint (n);
    bool[int] h;
    foreach (i; a) h[i] = true;
    sort (a);
    int res = int.max;
    int check (const int k) {
      int t = x / k;
      if (t >= res) return t;
      const int z = x % k;
      //debug stderr.writefln ("Case %d: t = %d, x = %d", tid + 1, t, x);
      if (!z) {
      } else if (z in h) ++t;
      else {
        t += 2;
      }
      return t;
    }
    foreach_reverse (k; a) {
      res = min (res, check (k));
    }
    ans[tid] = res;
  }
  writefln!"%(%s\n%)"(ans);
}


Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are n destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The n destinations are described by a non-negative integers sequence a1, a2, ..., an. The number ak represents that the kth destination is at distance ak kilometers from the starting point. No two destinations are located in the same place. Iahub wants to visit each destination only once. Note that, crossing through a destination is not considered visiting, unless Iahub explicitly wants to visit it at that point. Also, after Iahub visits his last destination, he doesn't come back to kilometer 0, as he stops his trip at the last destination. The distance between destination located at kilometer x and next destination, located at kilometer y, is |x - y| kilometers. We call a "route" an order of visiting the destinations. Iahub can visit destinations in any order he wants, as long as he visits all n destinations and he doesn't visit a destination more than once. Iahub starts writing out on a paper all possible routes and for each of them, he notes the total distance he would walk. He's interested in the average number of kilometers he would walk by choosing a route. As he got bored of writing out all the routes, he asks you to help him.

The first line contains integer n (2 ≤ n ≤ 105). Next line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 107).

Output two integers — the numerator and denominator of a fraction which is equal to the wanted average number. The fraction must be irreducible.

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

immutable int MAX_N = 100_005;
immutable int MAX_C = 0x3F3F3F3F;
immutable int NA    = -1;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new int [n + 1];
		a[0] = 0;
		foreach (i; 0..n)
		{
			readf (" %s", &a[i + 1]);
		}
		a.sort !("a < b", SwapStrategy.stable);
		long num = 0;
		auto s = new long [n + 1];
		s[0] = 0;
		foreach (i; 0..n)
		{
			num += a[i + 1];
			s[i + 1] = s[i] + a[i + 1];
		}
//		num *= n - 1;
		debug {writeln (num);}
		foreach (i; 0..n)
		{
			long cur = s[n] - s[i + 1];
			cur -= a[i + 1] * cast (long) (n - i - 1);
//			cur *= (n - 1);
			cur *= 2;
			debug {writefln ("%s: %s", i, cur);}
			num += cur;
		}
		long den = n;
//		den *= n - 1;
		auto d = gcd (num, den);
		num /= d;
		den /= d;
		writeln (num, ' ', den);
	}
}

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

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

void solve(){
    int n;
    n = rd!int;
    ll den = n;
    ll num = 0;
    ll sum = 0, fsum = 0, rsum = 0;
    ll[] arr = rdarr;
    arr.sort;
    foreach(i; 0..arr.length){
        sum += arr[i];
        fsum += i * arr[i];
        rsum += (n - i - 1) * arr[i];
    }
    num = sum + 2 * (fsum - rsum);
    ll gcdd = gcd(num, den);
    num /= gcdd;
    den /= gcdd;
    writeln(num, " ", den);
}

void main(){
    long t = 1;
    /* t = rd; */
    while(t--) solve();
    stdout.flush;
}

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

immutable int MAX_N = 100_005;
immutable int MAX_C = 0x3F3F3F3F;
immutable int NA    = -1;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new int [n + 1];
		a[0] = 0;
		foreach (i; 0..n)
		{
			readf (" %s", &a[i + 1]);
		}
		long num = 0;
		auto s = new long [n + 1];
		s[0] = 0;
		foreach (i; 0..n)
		{
			num += a[i + 1];
			s[i + 1] = s[i] + a[i + 1];
		}
//		num *= n - 1;
		debug {writeln (num);}
		foreach (i; 0..n)
		{
			long cur = s[n] - s[i + 1];
			cur -= a[i + 1] * cast (long) (n - i - 1);
//			cur *= (n - 1);
			cur *= 2;
			debug {writefln ("%s: %s", i, cur);}
			num += cur;
		}
		long den = n;
//		den *= n - 1;
		auto d = gcd (num, den);
		num /= d;
		den /= d;
		writeln (num, ' ', den);
	}
}

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

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

void solve(){
    int n;
    n = rd!int;
    ll den = n;
    ll num = 0;
    ll sum = 0, fsum = 0, rsum = 0;
    ll[] arr = rdarr;
    foreach(i; 0..arr.length){
        sum += arr[i];
        fsum += i * arr[i];
        rsum += (n - i - 1) * arr[i];
    }
    num = sum + (n - 1) * (fsum - rsum);
    ll gcdd = gcd(num, den);
    num /= gcdd;
    den /= gcdd;
    writeln(num, " ", den);
}

void main(){
    long t = 1;
    /* t = rd; */
    while(t--) solve();
    stdout.flush;
}

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

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

void solve(){
    int n;
    n = rd!int;
    ll den = n;
    ll num = 0;
    ll sum = 0, fsum = 0, rsum = 0;
    ll[] arr = rdarr;
    foreach(i; 0..arr.length){
        sum += arr[i];
        fsum += i * arr[i];
        rsum += (n - i - 1) * arr[i];
    }
    num = sum + 2 * (fsum - rsum);
    ll gcdd = gcd(num, den);
    num /= gcdd;
    den /= gcdd;
    writeln(num, " ", den);
}

void main(){
    long t = 1;
    /* t = rd; */
    while(t--) solve();
    stdout.flush;
}