Sasha is a very happy guy, that's why he is always on the move. There are $$$n$$$ cities in the country where Sasha lives. They are all located on one straight line, and for convenience, they are numbered from $$$1$$$ to $$$n$$$ in increasing order. The distance between any two adjacent cities is equal to $$$1$$$ kilometer. Since all roads in the country are directed, it's possible to reach the city $$$y$$$ from the city $$$x$$$ only if $$$x < y$$$. Once Sasha decided to go on a trip around the country and to visit all $$$n$$$ cities. He will move with the help of his car, Cheetah-2677. The tank capacity of this model is $$$v$$$ liters, and it spends exactly $$$1$$$ liter of fuel for $$$1$$$ kilometer of the way. At the beginning of the journey, the tank is empty. Sasha is located in the city with the number $$$1$$$ and wants to get to the city with the number $$$n$$$. There is a gas station in each city. In the $$$i$$$-th city, the price of $$$1$$$ liter of fuel is $$$i$$$ dollars. It is obvious that at any moment of time, the tank can contain at most $$$v$$$ liters of fuel.Sasha doesn't like to waste money, that's why he wants to know what is the minimum amount of money is needed to finish the trip if he can buy fuel in any city he wants. Help him to figure it out!

The first line contains two integers $$$n$$$ and $$$v$$$ ($$$2 \le n \le 100$$$, $$$1 \le v \le 100$$$)  — the number of cities in the country and the capacity of the tank.

Print one integer — the minimum amount of money that is needed to finish the trip.

NoteIn the first example, Sasha can buy $$$2$$$ liters for $$$2$$$ dollars ($$$1$$$ dollar per liter) in the first city, drive to the second city, spend $$$1$$$ liter of fuel on it, then buy $$$1$$$ liter for $$$2$$$ dollars in the second city and then drive to the $$$4$$$-th city. Therefore, the answer is $$$1+1+2=4$$$.In the second example, the capacity of the tank allows to fill the tank completely in the first city, and drive to the last city without stops in other cities.

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

immutable long INF = 10L ^^ 18 + 23;

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

    int tank = min(n - 1, v);
    int ans = tank;
    for (int i = 2; i < n; ++i) {
        tank -= 1;
        if (tank < n - i) {
            ++tank;
            ans += i;
        }
    }

    ans.writeln;
}


Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).Find the number on the n-th position of the sequence.

The only line contains integer n (1 ≤ n ≤ 1014) — the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

Print the element in the n-th position of the sequence (the elements are numerated from one).

import std.stdio;

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

	long before = 0;
	int last = 1;

	while (before + last < n) {
		before += last;
		last++;
	}

	int x = 0;
	while (before + x < n) {
		x++;
	}

	writeln(x);
}


Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer a > 1 such that a2 is a divisor of x.  Malek has a number store! In his store, he has only divisors of positive integer n (and he has all of them). As a birthday present, Malek wants to give her a lovely number from his store. He wants this number to be as big as possible.Malek always had issues in math, so he asked for your help. Please tell him what is the biggest lovely number in his store.

The first and only line of input contains one integer, n (1 ≤ n ≤ 1012).

NoteIn first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely.In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 22, so 12 is not lovely, while 6 is indeed lovely.

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

void main() {
    long n = readln.chomp.to!long;
    long[] answer;
    for (long i = 2; i <= sqrt(cast(float)n); i++) {
        if (n % i == 0) {
            answer ~= i;
        }

        while (n % i == 0) {
            n /= i;
        }
    }

    if (answer.empty) {
        writeln(n);
    } else {
        writeln(answer.reduce!("a * b") * n);
    }
}


Let's consider a table consisting of n rows and n columns. The cell located at the intersection of i-th row and j-th column contains number i × j. The rows and columns are numbered starting from 1.You are given a positive integer x. Your task is to count the number of cells in a table that contain number x.

The single line contains numbers n and x (1 ≤ n ≤ 105, 1 ≤ x ≤ 109) — the size of the table and the number that we are looking for in the table.

Print a single number: the number of times x occurs in the table.

NoteA table for the second sample test is given below. The occurrences of number 12 are marked bold.

import std.stdio;
import core.stdc.stdio;

int main(string[] argv)
{
	long n, x;
	scanf("%d %d", &n, &x);
	long count = 0;
	foreach (long i; 1..(n+1))
	{
		if (x % i == 0)
		{
			long a = i;
			long b = x / a;
			if (a <= n && b <= n)
				count += 1;
		}
	}
	printf("%d", count);
	return 0;
}

import std.stdio;
import core.stdc.stdio;

int main(string[] argv)
{
	long n, x;
	scanf("%d %d", &n, &x);
	long count;
	long l = (n / 2) + (n % 2 == 0 ? 1 : 2);
	foreach (long i; 1..l)
	{
		if (x % i == 0)
		{
			long a = i;
			long b = x / a;
			if (a <= n && b <= n)
				count += 1;
		}
	}
	printf("%d", count);
	return 0;
}


Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?

The first and the only line of the input contains two distinct integers n and m (1 ≤ n, m ≤ 104), separated by a space .

Print a single number — the minimum number of times one needs to push the button required to get the number m out of number n.

NoteIn the first example you need to push the blue button once, and then push the red button once.In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.

import std.stdio;

int bfs(short n, short m) {

	if (n >= m)
		return n - m;

	if (!(m & 1))
		return bfs(n, m / 2) + 1;

	if (m & 1)
		return bfs(n, (m + 1) / 2) + 2;

	assert(0);
}

void main() {

	short n, m;

	scanf("%hd%hd", &n, &m);

	writeln(bfs(n, m));
}

import std.stdio;

void main() {

	short n, m;

	scanf("%hd%hd", &n, &m);

	int sum;
	while (m > n) {
		if (!(m & 1))
			m /= 2;
		else
			m++;
		sum++;
	}

	writeln(sum + n - m);
}

import std.stdio;

int bfs(short n, short m) {

	if (n >= m)
		return n - m;

	if (m % 2 == 0)
		return bfs(n, m / 2) + 1;

	if (m % 2 == 1)
		return bfs(n, (m + 1) / 2) + 2;

	assert(0);
}

void main() {

	short n, m;

	scanf("%hd%hd", &n, &m);

	writeln(bfs(n, m));
}

import std.stdio;
import std.container;
import std.array;
import std.conv;
import std.string;
import std.algorithm;

void main()
{
    auto i = readln.chomp.split.map!"a.to!int";
    auto s = DList!int(i[0]);
    auto v = DList!int(0);
    bool [int] visited;

    int a,b;
    while (!s.empty  && s.front!= i[1]) {
        a = s.front;
        b = v.front;
        s.removeFront();
        v.removeFront();
        if (! (a in visited)) {
            visited[a] = true;
            if (a<i[1]) {
                s.insertBack(a*2);
                v.insertBack(b+1);
            }
            if (a>1) {
                    s.insertBack(a-1);
                    v.insertBack(b+1);
            }

        }
        //writeln(array(s));
    }

    writeln(v.front);

}

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

//	Input
class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } 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, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(    const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	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)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(in T[] as, in 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)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

immutable V = 10^^6;

int S, T;

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

		int[] q;
		int[] d = new int[V];
		d[] = -1;
		d[S] = 0;
		q ~= S;
		for (; !q.empty; ) {
			const u = q.front;
			q.popFront;
			foreach (v; [ u * 2, u - 1 ]) if (0 < v && v < V) {
				if (d[v] == -1) {
					d[v] = d[u] + 1;
					q ~= v;
				}
			}
		}

		writeln(d[T]);

	}
	} catch (EOFException) {}
}

import std.stdio;
import std.container;
import std.array;
import std.conv;
import std.string;
import std.algorithm;

void main()
{
    auto i = readln.chomp.split.map!"a.to!int";
    auto s = SList!int(i[0]);
    auto v = SList!int(0);
    bool [int] visited;

    int a,b;
    while (!s.empty  && s.front!= i[1]) {
        a = s.front;
        b = v.front;
        s.removeFront();
        v.removeFront();
        if (! (a in visited)) {
            s.insertFront(a*2);
            v.insertFront(b+1);
            visited[a] = true;
            if (a>0) {
                writeln("here");
                s.insertFront(a-1);
                v.insertFront(b+1);
            }
        }
    }

    writeln(v.front);

}

import std.stdio;
import std.container;
import std.array;
import std.conv;
import std.string;
import std.algorithm;

void main()
{
    auto i = readln.chomp.split.map!"a.to!int";
    auto s = SList!int(i[0]);
    auto v = SList!int(0);
    bool [int] visited;

    int a,b;
    while (!s.empty  && s.front!= i[1]) {
        a = s.front;
        b = v.front;
        s.removeFront();
        v.removeFront();
        if (! (a in visited)) {
            s.insertFront(a*2);
            v.insertFront(b+1);
            visited[a] = true;
            if (a>0) {
                s.insertFront(a-1);
                v.insertFront(b+1);
            }
        }
    }

    writeln(v.front);

}


Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where:  <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes),  <domain> is a non-empty string, consisting of lowercase English letters,  the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context).When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".".Help Vasya to restore the possible address of the recorded Internet resource.

The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only.  It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above.

Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them.

NoteIn the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru".

import std.stdio;
import std.algorithm.comparison;
import std.algorithm.sorting;
import std.algorithm.searching;
import std.algorithm.mutation;
import std.range;
import std.range.primitives;
import std.conv;
import std.string;

int main() {
    debug stdin = File("in.txt", "r");

    string str, outstr;
    readf(" %s\n", &str);
    if (str[0] == 'h') {
        outstr = "http://";
        str = str[4 .. $];
    }
    else {
        outstr = "ftp://";
        str = str[3 .. $];
    }
    int pos = str.indexOf("ru", 1);
    outstr ~= str[0 .. pos] ~ ".ru";
    if (str.length > pos + 2) outstr ~= "/" ~ str[pos + 2 .. $];
    writeln(outstr);

    return 0;
}

import std.stdio;
import std.algorithm.comparison;
import std.algorithm.sorting;
import std.algorithm.searching;
import std.algorithm.mutation;
import std.range;
import std.range.primitives;
import std.conv;
import std.string;

int main() {
    debug stdin = File("in.txt", "r");

    string str, outstr;
    readf(" %s\n", &str);
    if (str[0] == 'h') {
        outstr = "http://";
        str = str[4 .. $];
    }
    else {
        outstr = "ftp://";
        str = str[3 .. $];
    }
    int pos = str.indexOf("ru");
    outstr ~= str[0 .. pos] ~ ".ru";
    if (str.length > pos + 1) outstr ~= "/" ~ str[pos + 2 .. $];
    writeln(outstr);

    return 0;
}

import std.stdio;
import std.algorithm.comparison;
import std.algorithm.sorting;
import std.algorithm.searching;
import std.algorithm.mutation;
import std.range;
import std.range.primitives;
import std.conv;
import std.string;

int main() {
    debug stdin = File("in.txt", "r");

    string str, outstr;
    readf(" %s\n", &str);
    if (str[0] == 'h') {
        outstr = "http://";
        str = str[4 .. $];
    }
    else {
        outstr = "ftp://";
        str = str[3 .. $];
    }
    int pos = str.indexOf("ru", 1);
    outstr ~= str[0 .. pos] ~ ".ru";
    if (str.length > pos + 1) outstr ~= "/" ~ str[pos + 2 .. $];
    writeln(outstr);

    return 0;
}


Petya is having a party soon, and he has decided to invite his $$$n$$$ friends.He wants to make invitations in the form of origami. For each invitation, he needs two red sheets, five green sheets, and eight blue sheets. The store sells an infinite number of notebooks of each color, but each notebook consists of only one color with $$$k$$$ sheets. That is, each notebook contains $$$k$$$ sheets of either red, green, or blue.Find the minimum number of notebooks that Petya needs to buy to invite all $$$n$$$ of his friends.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1\leq n, k\leq 10^8$$$) — the number of Petya's friends and the number of sheets in each notebook respectively.

Print one number — the minimum number of notebooks that Petya needs to buy.

NoteIn the first example, we need $$$2$$$ red notebooks, $$$3$$$ green notebooks, and $$$5$$$ blue notebooks.In the second example, we need $$$5$$$ red notebooks, $$$13$$$ green notebooks, and $$$20$$$ blue notebooks.

import std.stdio;

int f(int a, int b)
{
	if (a%b==0)
	{
		return a/b;
	}
	else
	{
		return a/b+1;
	}
}
int main()
{
	int a=0;
	int b=0;
	readf(" %d", &a);
	readf(" %d", &b);
	writeln(f((a*2),b) + f((a*5),b) + f((a*8),b));
	return 0;
}


You're given a row with $$$n$$$ chairs. We call a seating of people "maximal" if the two following conditions hold:  There are no neighbors adjacent to anyone seated.  It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($$$0$$$ means that the corresponding seat is empty, $$$1$$$ — occupied). The goal is to determine whether this seating is "maximal".Note that the first and last seats are not adjacent (if $$$n \ne 2$$$).

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of chairs. The next line contains a string of $$$n$$$ characters, each of them is either zero or one, describing the seating.

Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No". You are allowed to print letters in whatever case you'd like (uppercase or lowercase).

NoteIn sample case one the given seating is maximal.In sample case two the person at chair three has a neighbour to the right.In sample case three it is possible to seat yet another person into chair three.

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

void main()
{
    readln();
    auto s = readln().strip();

    bool ok = true;
    ok &= !canFind(s, "000");
    ok &= !canFind(s, "11");
    ok &= !s.startsWith("00");
    ok &= !s.endsWith("00");
    ok &= s != "0";

    writeln(ok ? "Yes" : "No");
}

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, std.regex;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.chomp;

    foreach (i; 0..N-1) {
        if (A[i] == '1' && A[i+1] == '1') {
            writeln("No");
            return;
        }
    }

    foreach (i; 0..N) {
        if (A[i] == '1') continue;
        bool ok1  = (i == 0)   || (i > 0   && A[i-1] == '0');
        bool ok2  = (i == N-1) || (i < N-1 && A[i+1] == '0');
        if (ok1 && ok2) {
            writeln("No");
            return;
        }
    }

    writeln("Yes");
}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///int length
		int sz(T)(ref const T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int n;
	read(n);
	string s = readln.strip;
	foreach (i; 0 .. n - 1)
	{
		if (s[i] == '1' && s[i + 1] == '1')
		{
			return writeln("No");
		}
		if (i == 0 && s[i] == '0' && s[i + 1] == '0')
			return writeln("No");
		if (i == n - 2 && s[i] == '0' && s[i + 1] == '0')
			return writeln("No");
		if (i > 0 && s[i] == '0' && s[i - 1] == '0' && s[i + 1] == '0')
		{
			return writeln("No");
		}
	}
	if (n == 1 && s[0] == '0')
		writeln("No");
	else
		writeln("Yes");
}

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

void main()
{
    readln();
    auto s = readln();

    bool ok = true;
    ok &= !canFind(s, "000");
    ok &= !canFind(s, "11");
    ok &= !s.startsWith("00");
    ok &= !s.endsWith("00");

    writeln(ok ? "Yes" : "No");
}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///int length
		int sz(T)(ref const T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int n;
	read(n);
	string s = readln.strip;
	foreach (i; 0 .. n - 1)
	{
		if (s[i] == '1' && s[i + 1] == '1')
		{
			return writeln("No");
		}
		if (i == 0 && s[i] == '0' && s[i + 1] == '0')
			return writeln("No");
		if (i == n - 2 && s[i] == '0' && s[i + 1] == '0')
			return writeln("No");
		if (i > 0 && s[i] == '0' && s[i - 1] == '0' && s[i + 1] == '0')
		{
			return writeln("No");
		}
	}
	writeln("Yes");

}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///int length
		int sz(T)(ref const T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int n;
	read(n);
	string s = readln.strip;
	if (count(s, '1') == (n + 1) / 2)
		writeln("Yes");
	else
		writeln("No");
}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///int length
		int sz(T)(ref const T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int n;
	read(n);
	string s = readln.strip;
	foreach (i; 0 .. n - 1)
	{
		if (s[i] == '1' && s[i + 1] == '1')
		{
			return writeln("No");
		}
		if (i > 0 && s[i] == '0' && s[i - 1] == '0' && s[i + 1] == '0')
		{
			return writeln("No");
		}
	}
	writeln("Yes");

}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///int length
		int sz(T)(ref const T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int n;
	read(n);
	string s = readln.strip;
	if (n == 2)
		n++;
	if (count(s, '1') == (n + 1) / 2)
		writeln("Yes");
	else
		writeln("No");
}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///int length
		int sz(T)(ref const T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int n;
	read(n);
	string s = readln.strip;
	if (n == 2)
	{
		if (s[0] == '1' && s[1] == '1')
			writeln("Yes");
		else
			writeln("No");
		return;
	}
	foreach (i; 0 .. s.length - 1)
	{
		if (s[i] == '1' && s[i + 1] == '1')
		{
			return writeln("No");
		}
	}
	if (count(s, '1') == (n + 1) / 2)
		writeln("Yes");
	else
		writeln("No");
}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///int length
		int sz(T)(ref const T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int n;
	read(n);
	string s = readln.strip;
	foreach (i; 0 .. s.length - 1)
	{
		if (s[i] == '1' && s[i + 1] == '1')
		{
			return writeln("No");
		}
	}
	if (count(s, '1') == (n + 1) / 2)
		writeln("Yes");
	else
		writeln("No");
}


Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?

The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.

In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).

NoteIn the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.

import std.stdio,std.conv,std.array;

void main()
{
	int CountLarge = 0,CountSmall = 0;
	auto n = readln();
	foreach(string s;split(readln()," "))
	{
		uint ui = parse!uint(s);
		if(ui == 200)CountLarge++; else CountSmall++;
	}
	if(CountLarge % 2 == 0) CountLarge = 0;
	else{
		if(CountSmall >= 2){
			CountLarge = 0;
			CountSmall -= 2;
		}else{
			writeln("NO");
			return;
		}
	}
	if(CountSmall % 2 == 0) writeln("YES"); else writeln("NO");
}

import std.stdio,std.conv,std.array;

void main()
{
	int CountLarge = 0,CountSmall = 0;
	auto n = readln();
	foreach(string s;split(readln()," "))
	{
		uint ui = parse!uint(s);
		if(ui == 200)CountLarge++; else CountSmall++;
	}
	writeln(((CountSmall % 2 == 1) || ((CountLarge % 2 == 1)&&(CountSmall <= 1)))?"NO":"YES");
}

import std.stdio,std.conv,std.array;

void main()
{
	int CountLarge = 0,CountSmall = 0;
	auto n = readln();
	foreach(string s;split(readln()," "))
	{
		uint ui = parse!uint(s);
		if(ui == 200)CountLarge++; else CountSmall++;
	}
	// if(CountLarge % 2 == 0) CountLarge = 0;
	// else{
		// if(CountSmall >= 2){
			// CountLarge = 0;
			// CountSmall -= 2;
		// }else{
			// writeln("NO");
			// return;
		// }
	// }
	// if(CountSmall % 2 == 0) writeln("YES"); else writeln("NO");
	writeln(((CountSmall % 2 != 0) || (CountSmall < 2))?"NO":"YES");
}


It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are k such guards in the castle, so if there are more than k opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than k doors were opened.

Two integers are given in the first string: the number of guests n and the number of guards k (1 ≤ n ≤ 106, 1 ≤ k ≤ 26). In the second string, n uppercase English letters s1s2... sn are given, where si is the entrance used by the i-th guest.

Output «YES» if at least one door was unguarded during some time, and «NO» otherwise. You can output each letter in arbitrary case (upper or lower).

NoteIn the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door.

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

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto S = readln.chomp;
    auto F = new int[](26);
    auto L = new int[](26);
    fill(F, 1 << 29);

    foreach (i; 0..N) {
        F[S[i] - 'A'] = min(F[S[i] - 'A'], i);
        L[S[i] - 'A'] = max(L[S[i] - 'A'], i);
    }

    auto imos = new int[](10^^6 + 100);
    foreach (i; 0..26) if (F[i] != 1 << 29) imos[F[i]] += 1, imos[L[i] + 1] -= 1;
    foreach (i; 0..10^^6 + 50) imos[i + 1] += imos[i];

    writeln(imos.reduce!max > K ? "YES" : "NO");
}

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

int n, k;
string s;

void main() {
    scan(n, k);
    s = readln.chomp;

    auto t = new int[](n + 10);

    foreach (char ch ; 'A' .. 'Z' + 1) {
        foreach (i ; 0 .. n) {
            if (s[i] == ch) {
                t[i]++;
                break;
            }
        }

        foreach_reverse (i ; 0 .. n) {
            if (s[i] == ch) {
                t[i + 1]--;
                break;
            }
        }
    }

    foreach (i ; 0 .. n + 1) {
        t[i + 1] += t[i];
    }

    debug {
        writeln(t);
    }

    if (t.reduce!max > k) {
        writeln("YES");
    }
    else {
        writeln("NO");
    }
}

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

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


As you have noticed, there are lovely girls in Arpa’s land.People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi.  Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as follows.The game consists of rounds. Assume person x wants to start a round, he calls crushx and says: "Oww...wwf" (the letter w is repeated t times) and cuts off the phone immediately. If t > 1 then crushx calls crushcrushx and says: "Oww...wwf" (the letter w is repeated t - 1 times) and cuts off the phone immediately. The round continues until some person receives an "Owf" (t = 1). This person is called the Joon-Joon of the round. There can't be two rounds at the same time.Mehrdad has an evil plan to make the game more funny, he wants to find smallest t (t ≥ 1) such that for each person x, if x starts some round and y becomes the Joon-Joon of the round, then by starting from y, x would become the Joon-Joon of the round. Find such t for Mehrdad if it's possible.Some strange fact in Arpa's land is that someone can be himself's crush (i.e. crushi = i).

The first line of input contains integer n (1 ≤ n ≤ 100) — the number of people in Arpa's land. The second line contains n integers, i-th of them is crushi (1 ≤ crushi ≤ n) — the number of i-th person's crush.

If there is no t satisfying the condition, print -1. Otherwise print such smallest t.

NoteIn the first sample suppose t = 3. If the first person starts some round:The first person calls the second person and says "Owwwf", then the second person calls the third person and says "Owwf", then the third person calls the first person and says "Owf", so the first person becomes Joon-Joon of the round. So the condition is satisfied if x is 1.The process is similar for the second and the third person.If the fourth person starts some round:The fourth person calls himself and says "Owwwf", then he calls himself again and says "Owwf", then he calls himself for another time and says "Owf", so the fourth person becomes Joon-Joon of the round. So the condition is satisfied when x is 4.In the last example if the first person starts a round, then the second person becomes the Joon-Joon, and vice versa.

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

long gcd (long a, long b)
{
	if (a == 0)
	{
		return b;
	}
	return gcd (b % a, a);
}

long lcm (long a, long b)
{
	return a / gcd (a, b) * b;
}

long solve (int [] p)
{
	int n = cast (int) (p.length);

	auto q = new int [n];
	q[] = -1;
	foreach (i; 0..n)
	{
		q[p[i]] = i;
	}
	if (q.any !(x => x == -1))
	{
		return -1;
	}

	long res = 1;
	foreach (i; 0..n)
	{
		if (p[i] != -1)
		{
			int len = 0;
			int k = i;
			while (p[k] != -1)
			{
				int r = k;
				k = p[k];
				p[r] = -1;
				len += 1;
			}
			if (len % 2 == 0)
			{
				len /= 2;
			}
			res = lcm (res, len);
		}
	}

	return res;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto p = readln.split.map !(to !(int)).array;
		p[] -= 1;
		writeln (solve (p));
	}
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,std.bitmanip,std.functional,std.math,std.numeric,std.string,std.range,std.uni,std.complex,
std.typecons,std.regex,std.complex,std.random;
import core.stdc.stdio:freopen;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree set;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
immutable int mod=1000000007;
T lcm (T)(T a,T b)
{
	return a/gcd(a,b)*b;
}
pure nothrow X binpow(X,Y)(X base,Y exp)
if(!is(Y==float) && !is(Y==real) && !is(Y==double))
{
	if(exp<0)return X(0);
	X res=X(1);
	while(exp>0)
	{
		if(exp&1)res*=base;
		base*=base;
		exp>>=1;
	}
	return res;
}
pure nothrow auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
if(!is(Y==float) && !is(Y==real) && !is(Y==double))
{
	if(mm==0) return binpow(base,exp);
	if(exp<0)return X(0);
	auto res=X(1)%mm;
	while(exp>0)
	{
		if(exp&1)res=(res*base)%mm;
		base*=base;
		base%=mm;
		exp>>=1;
	}
	return res;
}
@property void putarr(X)(X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(X a,in int n,in int m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
void getarr(X)(X a,in int n){foreach(ref i;a[0..n])input(&i);}
bool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
		}
	this(this){fi=fi;se=se;}
	int opCmp(ref const pair!(X,Y) s_) const pure nothrow
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) mp(X,Y)(X x_,Y y_) pure nothrow
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
X sqr(X)(X a_) pure nothrow @property @nogc {return a_*a_;}
X cub(X)(X a_) pure nothrow @property @nogc {return a_*a_*a_;}
nothrow @nogc @system void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow @nogc @system void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
auto arread(T)(){return readln.split.map!(to!(T)).array;}
nothrow pure size_t lowb(T,X)(T a,X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (!(a[l]<g))?l:r;
}
pure nothrow size_t upb(T,X)(T a,X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(g<a[m])r=m;
		else l=m;
	}
	return (g<a[l])?l:r;
}
pure nothrow size_t binf(T,X)(T a,X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (g==a[l])?l:a.length;
}
pure nothrow bool binary_search(T,X)(T a,X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	return binf(a,g)!=a.length;
}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join
//---------------------------------------------------------------program beginning-----------------------------------------------------------

void main()
{
	int n;
	while(input(&n))
	{
		readln;
		int ans=1;
		auto a=arread!int;
		auto u=new bool[a.length];
		void dfs(int v,int root,int d)
		{
			if(u[v])
			{
				if(v!=root)ans=-1;
				else if(d&1)ans=lcm(ans,d);
				else ans=lcm(ans,d/2);
				return;
			}
			u[v]=1;
			dfs(a[v]-1,root,d+1);
		}
		foreach(i;0..n)
		{
			if(!u[i]) dfs(i,i,0);
			if(ans==-1){writeln(-1); goto loop;}
		}
		writeln(ans);
	loop:;
	}
}

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

int solve (int [] p)
{
	int n = cast (int) (p.length);
	auto q = n.iota.array;
	auto r = new int [n];
	foreach (res; 1..n + 1)
	{
		foreach (i; 0..n)
		{
			r[i] = p[q[i]];
		}
		q[] = r[];
		if (n.iota.all !(x => q[q[x]] == x))
		{
			return res;
		}
	}
	return -1;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto p = readln.split.map !(to !(int)).array;
		p[] -= 1;
		writeln (solve (p));
	}
}


There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.   Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.

The single line of input contains one integer n (0  ≤  n  ≤  109).

Print single integer — the last digit of 1378n.

NoteIn the first example, last digit of 13781 = 1378 is 8.In the second example, last digit of 13782 = 1378·1378 = 1898884 is 4.

import std.bigint,std.container,std.array,std.algorithm,std.conv,std.bitmanip,std.functional,std.math,std.numeric,std.string,std.range,std.uni,std.complex,
std.typecons,std.regex,std.complex,std.random;
import core.stdc.stdio:freopen;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree set;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
immutable int mod=1000000007;
pure nothrow X binpow(X,Y)(X base,Y exp)
if(!is(Y==float) && !is(Y==real) && !is(Y==double))
{
	if(exp<0)return X(0);
	X res=X(1);
	while(exp>0)
	{
		if(exp&1)res*=base;
		base*=base;
		exp>>=1;
	}
	return res;
}
pure nothrow auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
if(!is(Y==float) && !is(Y==real) && !is(Y==double))
{
	if(mm==0) return binpow(base,exp);
	if(exp<0)return X(0);
	auto res=X(1)%mm;
	while(exp>0)
	{
		if(exp&1)res=(res*base)%mm;
		base*=base;
		base%=mm;
		exp>>=1;
	}
	return res;
}
@property void putarr(X)(X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(X a,in int n,in int m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
void getarr(X)(X a,in int n){foreach(ref i;a[0..n])input(&i);}
bool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X fi;
	Y se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
		}
	this(this){fi=fi;se=se;}
	int opCmp(ref const pair!(X,Y) s_) const pure nothrow
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) mp(X,Y)(X x_,Y y_) pure nothrow
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
X sqr(X)(X a_) pure nothrow @property @nogc {return a_*a_;}
X cub(X)(X a_) pure nothrow @property @nogc {return a_*a_*a_;}
nothrow @nogc @system void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow @nogc @system void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
auto arread(T)(){return readln.split.map!(to!(T)).array;}
nothrow pure size_t lowb(T,X)(T a,X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (!(a[l]<g))?l:r;
}
pure nothrow size_t upb(T,X)(T a,X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(g<a[m])r=m;
		else l=m;
	}
	return (g<a[l])?l:r;
}
pure nothrow size_t binf(T,X)(T a,X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (g==a[l])?l:a.length;
}
pure nothrow bool binary_search(T,X)(T a,X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	return binf(a,g)!=a.length;
}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join
//---------------------------------------------------------------program beginning-----------------------------------------------------------

void main()
{
	int n;
	while(input(&n))
	{
		writeln(binpow(1378,n,10));
	}
}

import std.stdio;
import std.bigint;
import std.container;
import std.array;
import std.algorithm;
import std.conv;
import std.bitmanip;
import std.functional;
import std.math;
import std.numeric;
import std.string;
import std.range;
import std.uni;
import std.complex;
import std.typecons;
import core.stdc.stdio:freopen;
import std.regex;
import std.complex;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
immutable int mod=1000000007;
pure nothrow @safe X binpow(X,Y)(X base,Y exp)
if(!is(Y==float) && !is(Y==real) && !is(Y==double))
{
	if(exp<0)return X(0);
	X res=X(1);
	while(exp>0)
	{
		if(exp&1)res*=base;
		base*=base;
		exp>>=1;
	}
	return res;
}
pure nothrow @safe auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
if(!is(Y==float) && !is(Y==real) && !is(Y==double))
{
	if(mm==0) return binpow(base,exp);
	if(exp<0)return X(0);
	auto res=X(1)%mm;
	while(exp>0)
	{
		if(exp&1)res=(res*base)%mm;
		base*=base;
		base%=mm;
		exp>>=1;
	}
	return res;
}
@safe @property void putarr(X)(X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
/*@safe @property void putarr(X)(X[][] a)
{
	foreach(i;0..a.length)
	{
		foreach(j;0..a[i].length)write(a[i][j],' ');
		writeln;
	}
}*/
void getarr(X)(X a,in int n){foreach(ref i;a[0..n])input(&i);}
bool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X fi;
	Y se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
		}
	this(this){fi=fi;se=se;}
	int opCmp(ref const pair!(X,Y) s_) const pure nothrow
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) mp(X,Y)(X x_,Y y_) pure nothrow
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
X sqr(X)(X a_) pure nothrow @safe @property @nogc {return a_*a_;}
X cub(X)(X a_) pure nothrow @safe @property @nogc {return a_*a_*a_;}
nothrow @nogc @system void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow @nogc @system void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
auto arread(T)(){return readln.split.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join
//---------------------------------------------------------------program beginning-----------------------------------------------------------

void main()
{
	int n;
	input(&n);
	writeln(binpow(1378,n,10));
}


Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically  — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $$$4.5$$$ would be rounded up to $$$5$$$ (as in example 3), but $$$4.4$$$ would be rounded down to $$$4$$$.This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $$$5$$$ (maybe even the dreaded $$$2$$$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $$$5$$$ for the course. Of course, Vasya will get $$$5$$$ for the lab works he chooses to redo.Help Vasya — calculate the minimum amount of lab works Vasya has to redo.

The first line contains a single integer $$$n$$$ — the number of Vasya's grades ($$$1 \leq n \leq 100$$$). The second line contains $$$n$$$ integers from $$$2$$$ to $$$5$$$ — Vasya's grades for his lab works.

Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $$$5$$$.

NoteIn the first sample, it is enough to redo two lab works to make two $$$4$$$s into $$$5$$$s.In the second sample, Vasya's average is already $$$4.75$$$ so he doesn't have to redo anything to get a $$$5$$$.In the second sample Vasya has to redo one lab work to get rid of one of the $$$3$$$s, that will make the average exactly $$$4.5$$$ so the final grade would be $$$5$$$.

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

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

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

    int need = 45 * n;

    a.sort();
    int now = a.sum() * 10;
    int ans = 0;

    debug { writeln(need, ' ', now); }

    foreach (e; a) {
        if (now >= need) break;

        now += (5 - e) * 10;
        ++ans;
    }

    ans.writeln;
}


You have n problems. You have estimated the difficulty of the i-th one as integer ci. Now you want to prepare a problemset for a contest, using some of the problems you've made.A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.Find the number of ways to choose a problemset for the contest.

The first line contains four integers n, l, r, x (1 ≤ n ≤ 15, 1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ 106) — the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 106) — the difficulty of each problem.

Print the number of ways to choose a suitable problemset for the contest.

NoteIn the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.In the second example, two sets of problems are suitable — the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable.

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

void main() {
  int n, l, r, x;
  scanf("%d%d%d%d\n", &n, &l, &r, &x);
  auto a = readln().split().map!(to!long);
  int ans = 0;
  for (int S = 1; S < (1 << n); S++) {
    long s = 0, mn = long.max, mx = long.min;
    for (int i = 0; i < n; i++) {
      if (S & (1 << i)) {
        s += a[i];
        mn = min(mn, a[i]);
        mx = max(mx, a[i]);
      }
    }
    if (l <= s && s <= r &&  mx - mn >= x) {
      ans++;
    }
  }
  writeln(ans);
}


There is a building consisting of $$$10~000$$$ apartments numbered from $$$1$$$ to $$$10~000$$$, inclusive.Call an apartment boring, if its number consists of the same digit. Examples of boring apartments are $$$11, 2, 777, 9999$$$ and so on.Our character is a troublemaker, and he calls the intercoms of all boring apartments, till someone answers the call, in the following order:  First he calls all apartments consisting of digit $$$1$$$, in increasing order ($$$1, 11, 111, 1111$$$).  Next he calls all apartments consisting of digit $$$2$$$, in increasing order ($$$2, 22, 222, 2222$$$)  And so on. The resident of the boring apartment $$$x$$$ answers the call, and our character stops calling anyone further.Our character wants to know how many digits he pressed in total and your task is to help him to count the total number of keypresses.For example, if the resident of boring apartment $$$22$$$ answered, then our character called apartments with numbers $$$1, 11, 111, 1111, 2, 22$$$ and the total number of digits he pressed is $$$1 + 2 + 3 + 4 + 1 + 2 = 13$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 36$$$) — the number of test cases. The only line of the test case contains one integer $$$x$$$ ($$$1 \le x \le 9999$$$) — the apartment number of the resident who answered the call. It is guaranteed that $$$x$$$ consists of the same digit.

For each test case, print the answer: how many digits our character pressed in total.

import std.stdio;
import std.conv;
import std.string;

int[string] precalc;

void main()
{
    {
        int strokes = 0;
        for (int i = 1; i <= 9; ++i) {
            string key = "";
            for (int j = 1; j <= 4; ++j) {
                key ~= i.to!string;
                strokes += j;
                precalc[key] = strokes;
            }
        }
    }

    auto t = readln.strip.to!int;
    while (t-- > 0) {
        writeln(precalc[readln.strip]);
    }
}

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

void play(){
    int n;
    n = rd!int;
    int dig = n % 10;
    int tim = 0;
    while(n > 0){
        n /= 10;
        ++tim;
    }
    int res = 10*(dig - 1) + (tim*(tim+1))/2;
    writeln(res);
}

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

/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }
void show(A...)(A a) { debug{ a.each!(w => write(w, "| ")); writeln; } }
alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
T max(T = long)(T a, T b){ return (a > b) ? a : b; }
T min(T = long)(T a, T b){ return (a < b) ? a : b; }

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

void main ()
{
	auto tests = readln.strip.to !(int);
multitest_loop:
	foreach (test; 0..tests)
	{
		auto s = readln.strip;
		int res = 0;
		foreach (d; 1..10)
		{
			foreach (k; 1..5)
			{
				auto t = repeat (cast (char) (d + '0'), k);
				res += k;
				if (equal (s, t))
				{
					writeln (res);
					continue multitest_loop;
				}
			}
		}
		assert (false);
	}
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		auto len = x.length;
		ans[ti] = (cast(long)(x[0]-'0')-1)*10 + (len*(len+1)/2);
	}

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


A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert a grams of sand into b grams of lead, the second one allows you to convert c grams of lead into d grams of gold and third one allows you to convert e grams of gold into f grams of sand. When Harry told his friends about these spells, Ron Weasley was amazed. After all, if they succeed in turning sand into lead, lead into gold, and then turning part of the gold into sand again and so on, then it will be possible to start with a small amount of sand and get huge amounts of gold! Even an infinite amount of gold! Hermione Granger, by contrast, was skeptical about that idea. She argues that according to the law of conservation of matter getting an infinite amount of matter, even using magic, is impossible. On the contrary, the amount of matter may even decrease during transformation, being converted to magical energy. Though Hermione's theory seems convincing, Ron won't believe her. As far as Ron is concerned, Hermione made up her law of conservation of matter to stop Harry and Ron wasting their time with this nonsense, and to make them go and do homework instead. That's why Ron has already collected a certain amount of sand for the experiments. A quarrel between the friends seems unavoidable...Help Harry to determine which one of his friends is right, and avoid the quarrel after all. To do this you have to figure out whether it is possible to get the amount of gold greater than any preassigned number from some finite amount of sand.

The first line contains 6 integers a, b, c, d, e, f (0 ≤ a, b, c, d, e, f ≤ 1000).

Print "Ron", if it is possible to get an infinitely large amount of gold having a certain finite amount of sand (and not having any gold and lead at all), i.e., Ron is right. Otherwise, print "Hermione".

Ron Hermione Hermione Hermione Ron Hermione Ron

NoteConsider the first sample. Let's start with the 500 grams of sand. Apply the first spell 5 times and turn the sand into 1000 grams of lead. Then apply the second spell 4 times to get 600 grams of gold. Let’s take 400 grams from the resulting amount of gold turn them back into sand. We get 500 grams of sand and 200 grams of gold. If we apply the same operations to 500 grams of sand again, we can get extra 200 grams of gold every time. Thus, you can get 200, 400, 600 etc. grams of gold, i.e., starting with a finite amount of sand (500 grams), you can get the amount of gold which is greater than any preassigned number.In the forth sample it is impossible to get sand, or lead, or gold, applying the spells.In the fifth sample an infinitely large amount of gold can be obtained by using only the second spell, which allows you to receive 1 gram of gold out of nothing. Note that if such a second spell is available, then the first and the third one do not affect the answer at all.The seventh sample is more interesting. We can also start with a zero amount of sand there. With the aid of the third spell you can get sand out of nothing. We get 10000 grams of sand in this manner. Let's get 100 grams of lead using the first spell 100 times. Then make 1 gram of gold from them. We managed to receive 1 gram of gold, starting with a zero amount of sand! Clearly, in this manner you can get an infinitely large amount of gold.

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

immutable int INF = 10 ^^ 8;

void main()
{
    int a, b, c, d, e, f;
    readf("%s %s %s %s %s %s", &a, &b, &c, &d, &e, &f);
    readln;

    string solve() {
        auto r = "Ron";
        auto h = "Hermione";

        if (d == 0) { return h; }
        if (c == 0) { return r; }
        if (b == 0) { return h; }
        if (a == 0) { return r; }
        if (f == 0) { return h; }
        if (e == 0) { return r; }

        long lcm1 = b * c / gcd(b, c);
        long aa = a * (lcm1 / b);
        long dd = d * (lcm1 / c);

        long lcm2 = dd * e / gcd(dd, e);
        long fff = f * (lcm2 / e);
        long mult = lcm2 / dd;
        long aaa = aa * mult;

        return aaa < fff ? r : h;
    }

    solve().writeln;
}


There are $$$n$$$ heroes fighting in the arena. Initially, the $$$i$$$-th hero has $$$a_i$$$ health points.The fight in the arena takes place in several rounds. At the beginning of each round, each alive hero deals $$$1$$$ damage to all other heroes. Hits of all heroes occur simultaneously. Heroes whose health is less than $$$1$$$ at the end of the round are considered killed.If exactly $$$1$$$ hero remains alive after a certain round, then he is declared the winner. Otherwise, there is no winner.Your task is to calculate the number of ways to choose the initial health points for each hero $$$a_i$$$, where $$$1 \le a_i \le x$$$, so that there is no winner of the fight. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if at least one hero has a different amount of health. For example, $$$[1, 2, 1]$$$ and $$$[2, 1, 1]$$$ are different.

The only line contains two integers $$$n$$$ and $$$x$$$ ($$$2 \le n \le 500; 1 \le x \le 500$$$).

Print one integer — the number of ways to choose the initial health points for each hero $$$a_i$$$, where $$$1 \le a_i \le x$$$, so that there is no winner of the fight, taken modulo $$$998244353$$$.

immutable multi = false;

int n, x;
immutable long p = 998244353;
alias Zp = Z!p;
Zp[][] ways, prePow;

Zp getWays(int size, int range)
{
	pragma(inline, true);
	assert(size >= 0);
	if (range >= 0) return ways[size][range];
	else return Zp(size == 0);
}

Zp[][] C = new Zp[][](501, 501);
static this()
{
	C[0][0] = Zp(1);
	foreach(size; 1 .. 501)
	{
		C[size][0] = Zp(1);
		foreach(subsize; 1 .. size + 1)
		{
			C[size][subsize] = C[size-1][subsize-1] + C[size-1][subsize];
		}
	}
}

Zp calcWays(int size, int range)
{
	pragma(inline, true);
	if (size == 0) return Zp(1);
	if (size == 1) return Zp(0);
	if (range == 0) return Zp(0);
	Zp ans = Zp(0);
	foreach(noDies; 0 .. size + 1)
	{
		Zp noWaysDies = prePow[min(range, size - 1)][noDies];
		noWaysDies = noWaysDies * C[size][noDies];
		noWaysDies = noWaysDies * getWays(size - noDies, range - (size - 1));
		ans = ans + noWaysDies;
	}
	return ans;
}

void solve(int tc)
{
	n = readInt!int;
	x = readInt!int;
	Zp.makeFactorials(2 * n);
	ways = new Zp[][](n+1, x+1);
	prePow = new Zp[][](501, 501);
	foreach(b; 0 .. 501) prePow[b][0] = Zp(1);
	foreach(b; 0 .. 501)
	{
		foreach(ex; 1 .. 501)
			prePow[b][ex] = prePow[b][ex-1] * Zp(b);
	}
	foreach(size; 0 .. n + 1)
		foreach(range; 0 .. x + 1)
			ways[size][range] = calcWays(size, range);
	debug
	{
		foreach(size; 0 .. n + 1)
			ways[size].writeln;
	}
	ways[n][x].rep.writeln;
}

// modular {{{
struct Z(immutable long m)
{
	long rep;
	static immutable bool primeModulus = isPrime(m);
	static Z!m[] fact;
	static if (primeModulus) { static Z!m[] invFact; }
	static makeFactorials(int n)
	{
		fact = new Z!m[](n + 1);
		fact[0] = Z!m(1);
		foreach(i; 1 .. n + 1) fact[i] = Z!m(i) * fact[i - 1];
		static if (primeModulus)
		{
			invFact = new Z!m[](n + 1);
			invFact[n] = fact[n].inv;
			foreach_reverse(i; 0 .. n) invFact[i] = Z!m(i + 1) * invFact[i + 1];
		}
	}

	this(long num)
	{
		rep = num;
	}

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

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

	static if (primeModulus)
	{
		Z!m inv()
		{
			return this^^(m - 2);
		}
		static Z!m C(int n, int k)
		{
			if (k < 0 || k > n) return Z!m(0);
			return fact[n] * invFact[k] * invFact[n - k];
		}
	}

	invariant
	{
		assert(rep >= 0 && rep < m);
	}
}
bool isPrime(long n)
{
	for(long d = 2; d * d <= n; d++)
		if (n % d == 0) return false;
	return true;
}
unittest
{
	alias Zp = Z!23;
	static assert(Zp.primeModulus);
	foreach(i; 1 .. 23) assert(Zp(i) * Zp(i).inv == Zp(1));
	Zp.makeFactorials(22);
	foreach(i; 0 .. 23) assert(Zp.fact[i] * Zp.invFact[i] == Zp(1));
	assert(Zp.C(3, 2) == Zp(3));
	assert(Zp.C(4, 2) == Zp(6));
}
// }}}

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

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

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

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

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

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

immutable int mod = 998_244_353;
immutable int limit = 504;

void main ()
{
	auto c = new int [] [] (limit, limit);
	foreach (i; 0..limit)
	{
		c[i][0] = 1 % mod;
		foreach (j; 1..i + 1)
		{
			c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
		}
	}

	auto p = new int [] [] (limit, limit);
	foreach (i; 1..limit)
	{
		p[i][0] = 1;
		foreach (j; 1..limit)
		{
			p[i][j] = (p[i][j - 1] * 1L * i) % mod;
		}
	}

	auto f = new int [] [] (limit, limit);
	foreach (x; 0..limit)
	{
		f[0][x] = 1;
	}
	foreach (n; 2..limit)
	{
		foreach (x; 1..limit)
		{
			int delta = min (n - 1, x);
			int y = x - delta;
			foreach (k; 0..n + 1)
			{
				f[n][x] = (f[n][x] + f[k][y] * 1L *
				    (c[n][k] * 1L * p[delta][n - k] %
				    mod)) % mod;
			}
			debug {writefln !("f[%s][%s] = %s") (n, x, f[n][x]);}
		}
	}

	int n, x;
	while (readf !(" %s %s") (n, x) > 0)
	{
		writeln (f[n][x]);
	}
}

immutable multi = true;

void solve(int tc)
{
	auto n = readInt!int;
	auto m = readInt!int;
	auto a = ma(n, ma(m, readInt!int));
	auto minmaxL = new Tuple!(int, int)[][](n);
	auto minmaxR = new Tuple!(int, int)[][](n);
	foreach(i, ref ai; a)
	{
		minmaxL[i] = ai.cumulativeFold!(min, max).array;
		minmaxR[i] = ai.retro.cumulativeFold!(min, max).array.retro.array;
	}
	char[] getConfiguration(int k)
	{
		debug writeln("for k = ", k);
		struct Row
		{
			Tuple!(int, int) left, right;
		}
		Row[] rows = new Row[](n);
		foreach(i, ref rowi; rows)
		{
			rowi = Row(minmaxL[i][k], minmaxR[i][k+1]);
		}
		debug writeln("rows = ", rows);
		auto events = new Tuple!(int, int, int)[](2 * n);
		int evlen = 0;
		foreach(i, row; rows)
		{
			events[evlen++] = tuple(row.left[0], +1, cast(int)i);
			events[evlen++] = tuple(row.left[1] + 1, -1, cast(int)i);
		}
		int pfMinPrev = int.max;
		int sfMaxPrev = int.min;
		auto pfMin = new int[](2 * n);
		auto sfMax = new int[](2 * n);
		sort(events);
		debug writeln("events = ", events);
		debug writeln("evlen = ", evlen);
		foreach(i, evi; events)
		{
			if (evi[1] == +1)
			{
				pfMinPrev = min(pfMinPrev, rows[evi[2]].right[0]);
			}
			pfMin[i] = pfMinPrev;
		}

		foreach_reverse(i, evi; events)
		{
			if (evi[1] == +1)
			{
				sfMaxPrev = max(sfMaxPrev, rows[evi[2]].right[1]);
			}
			sfMax[i] = sfMaxPrev;
		}
		debug writeln("pfMin = ", pfMin);
		debug writeln("sfMax = ", sfMax);
		int open = 0;
		int cut = -1;
		auto color = new char[](n);
		color[] = 'R';
		foreach(i, evi; events)
		{
			open += evi[1];
			if (i+1 < events.length && open == 0)
			{
				debug writeln("found a cut at i = ", i);
				if (pfMin[i] > sfMax[i])
				{
					debug writeln("it's a good cut!");
					foreach(j; 0 .. i)
					{
						if (events[j][1] > 0)
						{
							color[events[j][2]] = 'B';
						}
					}
					return color;
				}
			}
		}
		return null;
	}
	foreach(k; 0 .. m - 1)
	{
		auto config = getConfiguration(k);
		if (config !is null)
		{
			writeln("YES");
			config.write(" ");
			return writeln(k+1);
		}
	}
	return writeln("NO");
}

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

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

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

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

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

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

immutable int mod = 998_244_353;
immutable int limit = 504;

void main ()
{
	auto c = new int [] [] (limit, limit);
	foreach (i; 0..limit)
	{
		c[i][0] = 1 % mod;
		foreach (j; 1..i + 1)
		{
			c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
		}
	}

	auto p = new int [] [] (limit, limit);
	foreach (i; 1..limit)
	{
		p[i][0] = 1;
		foreach (j; 1..limit)
		{
			p[i][j] = (p[i][j - 1] * 1L * i) % mod;
		}
	}

	auto f = new int [] [] (limit, limit);
	foreach (x; 0..limit)
	{
		f[0][x] = 1;
	}
	foreach (n; 2..limit)
	{
		foreach (x; 1..limit)
		{
			int delta = min (n - 1, x);
			int y = x - delta;
			foreach (k; 0..n + 1)
			{
				f[n][x] = (f[n][x] + f[k][y] * 1L *
				    (c[n][k] * 1L * p[delta][n - k]) %
				    mod) % mod;
			}
			debug {writefln !("f[%s][%s] = %s") (n, x, f[n][x]);}
		}
	}

	int n, x;
	while (readf !(" %s %s") (n, x) > 0)
	{
		writeln (f[n][x]);
	}
}


Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him.

The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points.

Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO».

import std.stdio;
import std.format;

class Point
{
    public const int x;
    public const int y;

    this(in int x, in int y)
    {
        this.x = x;
        this.y = y;
    }
}

bool isPresent(Point[] vertexes, int x, int y)
{
    foreach (point; vertexes) {
        if (point is null) {
            return false;
        }
        if (point.x == x && point.y == y) {
            return true;
        }
    }
    return false;
}

void insert(Point[] vertexes, Point p)
{
    for (int i = 0; i < vertexes.length; i++) {
        if (vertexes[i] is null) {
            vertexes[i] = p;
            return;
        }
    }
}

bool processPoint(Point[] vertexes, int x, int y)
{
    if (isPresent(vertexes, x, y)) {
        return true;
    }
    if (vertexes[vertexes.length - 1] !is null) {
        return false;
    }
    insert(vertexes, new Point(x, y));
    return true;
}

class Integer
{
    const int value;
    this(int value) {
        this.value = value;
    }
}

bool checkRectangle()
{
    Point[4] vertexes;
    Integer[2] xLines;
    Integer[2] yLines;

    for (int i = 0; i < 4; i++)
    {
        int x1, y1, x2, y2;
        auto line = stdin.readln();
        formattedRead(line, "%s %s %s %s", &x1, &y1, &x2, &y2);
        if (x1 == x2 && y1 != y2) {
            if (xLines[0] is null) {
                xLines[0] = new Integer(x1);
            } else {
                if (xLines[0].value == x1 || xLines[1] !is null) {
                    return false;
                }
                xLines[1] = new Integer(x1);
            }
        } else if (x1 != x2 && y1 == y2) {
            if (yLines[0] is null) {
                yLines[0] = new Integer(y1);
            } else {
                if (yLines[0].value == y1 || yLines[1] !is null) {
                    return false;
                }
                yLines[1] = new Integer(y1);
            }
        } else {
            return false;
        }

        if (!processPoint(vertexes, x1, y1)) {
            return false;
        }
        if (!processPoint(vertexes, x2, y2)) {
            return false;
        }
    }
    return true;
}

void main()
{
    if (checkRectangle()) {
        stdout.writeln("YES");
    } else {
        stdout.writeln("NO");
    }
}

import std.stdio;
import std.format;

class Point
{
    public const int x;
    public const int y;

    this(in int x, in int y)
    {
        this.x = x;
        this.y = y;
    }
}

bool isPresent(Point[] vertexes, int x, int y)
{
    foreach (point; vertexes) {
        if (point is null) {
            return false;
        }
        if (point.x == x && point.y == y) {
            return true;
        }
    }
    return false;
}

void insert(Point[] vertexes, Point p)
{
    for (int i = 0; i < vertexes.length; i++) {
        if (vertexes[i] is null) {
            vertexes[i] = p;
            return;
        }
    }
}

bool processPoint(Point[] vertexes, int x, int y)
{
    if (isPresent(vertexes, x, y)) {
        return true;
    }
    if (vertexes[vertexes.length - 1] !is null) {
        return false;
    }
    insert(vertexes, new Point(x, y));
    return true;
}

class Integer
{
    const int value;
    this(int value) {
        this.value = value;
    }
}

bool checkRectangle()
{
    Point[4] vertexes;
    Integer[2] xLines;
    Integer[2] yLines;

    for (int i = 0; i < 4; i++)
    {
        int x1, y1, x2, y2;
        auto line = stdin.readln();
        formattedRead(line, "%s %s %s %s", &x1, &y1, &x2, &y2);
        if (x1 == x2 && y1 != y2) {
            if (xLines[0] is null) {
                xLines[0] = new Integer(x1);
            } else {
                if (xLines[0].value == x1 || xLines[1] !is null) {
                    return false;
                }
                xLines[1] = new Integer(x1);
            }
        } else if (x1 != x2 && y1 == y2) {
            if (yLines[0] is null) {
                yLines[0] = new Integer(y1);
            } else {
                if (yLines[0].value == y1 || yLines[1] !is null) {
                    return false;
                }
                yLines[1] = new Integer(y1);
            }
        }
        if (!processPoint(vertexes, x1, y1)) {
            return false;
        }
        if (!processPoint(vertexes, x2, y2)) {
            return false;
        }
    }
    return true;
}

void main()
{
    if (checkRectangle()) {
        stdout.writeln("YES");
    } else {
        stdout.writeln("NO");
    }
}