Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today.  Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner. While watching previous races the organizers have noticed that Willman can perform only steps of length equal to w meters, and Bolt can perform only steps of length equal to b meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes). Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance L.Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to t (both are included). What is the probability that Willman and Bolt tie again today?

The first line of the input contains three integers t, w and b (1 ≤ t, w, b ≤ 5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.

Print the answer to the problem as an irreducible fraction . Follow the format of the samples output. The fraction  (p and q are integers, and both p ≥ 0 and q > 0 holds) is called irreducible, if there is no such integer d > 1, that both p and q are divisible by d.

NoteIn the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack.

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

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

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

void main() {
    string s[] = split(readln());
    BigInt t = s[0];
    BigInt w = s[1];
    BigInt b = s[2];

    BigInt LCM = lcm(w,b);
    BigInt cnt = t / LCM;
    BigInt p, q;
    // なぜこれに気づかなかったのか
    // p = min(w,b)-1;
    p = min(t, min(w,b)-1);
    if(cnt > 0)
        p += (cnt-1) * min(w,b) + min(min(w,b), t % LCM + 1);
    q = t;

    BigInt d = gcd(p, q);
    write(p / d);
    write("/");
    writeln(q / d);
}

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

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

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

void main() {
    string s[] = split(readln());
    BigInt t = s[0];
    BigInt w = s[1];
    BigInt b = s[2];

    BigInt LCM = lcm(w,b);
    BigInt cnt = t / LCM;
    BigInt p, q;
    BigInt one = "1", zero = "0";
    p = max(cnt - 1, zero) * min(w,b) + min(cnt, one) * min(min(w,b), t % LCM + 1);
    q = t;

    BigInt d = gcd(p, q);
    write(p / d);
    write("/");
    writeln(q / d);
}

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

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

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

void main() {
    string s[] = split(readln());
    BigInt t = s[0];
    BigInt w = s[1];
    BigInt b = s[2];

    BigInt LCM = lcm(w,b);
    BigInt cnt = t / LCM;
    BigInt p, q;
    BigInt one = "1", zero = "0";
    p = max(cnt - 1, zero) * w + min(cnt, one) * min(w, t % LCM + 1);
    q = t;

    BigInt d = gcd(p, q);
    write(p / d);
    write("/");
    writeln(q / d);
}

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

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

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

void main() {
    string s[] = split(readln());
    BigInt t = s[0];
    BigInt w = s[1];
    BigInt b = s[2];

    BigInt LCM = lcm(w,b);
    BigInt cnt = t / LCM;
    BigInt p, q;
    p = min(w,b)-1;
    if(cnt > 0)
        p += (cnt-1) * min(w,b) + min(min(w,b), t % LCM + 1);
    q = t;

    BigInt d = gcd(p, q);
    write(p / d);
    write("/");
    writeln(q / d);
}


One Martian boy called Zorg wants to present a string of beads to his friend from the Earth — Masha. He knows that Masha likes two colours: blue and red, — and right in the shop where he has come, there is a variety of adornments with beads of these two colours. All the strings of beads have a small fastener, and if one unfastens it, one might notice that all the strings of beads in the shop are of the same length. Because of the peculiarities of the Martian eyesight, if Zorg sees one blue-and-red string of beads first, and then the other with red beads instead of blue ones, and blue — instead of red, he regards these two strings of beads as identical. In other words, Zorg regards as identical not only those strings of beads that can be derived from each other by the string turnover, but as well those that can be derived from each other by a mutual replacement of colours and/or by the string turnover.It is known that all Martians are very orderly, and if a Martian sees some amount of objects, he tries to put them in good order. Zorg thinks that a red bead is smaller than a blue one. Let's put 0 for a red bead, and 1 — for a blue one. From two strings the Martian puts earlier the string with a red bead in the i-th position, providing that the second string has a blue bead in the i-th position, and the first two beads i - 1 are identical.At first Zorg unfastens all the strings of beads, and puts them into small heaps so, that in each heap strings are identical, in his opinion. Then he sorts out the heaps and chooses the minimum string in each heap, in his opinion. He gives the unnecassary strings back to the shop assistant and says he doesn't need them any more. Then Zorg sorts out the remaining strings of beads and buys the string with index k. All these manupulations will take Zorg a lot of time, that's why he asks you to help and find the string of beads for Masha.

The input file contains two integers n and k (2 ≤ n ≤ 50;1 ≤ k ≤ 1016) —the length of a string of beads, and the index of the string, chosen by Zorg.

Output the k-th string of beads, putting 0 for a red bead, and 1 — for a blue one. If it s impossible to find the required string, output the only number -1.

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

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

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

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

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

int N;
long K;

long solve(int[] head) {
	if (head[0] != 0) {
		return 0;
	}
// writeln("head = ",head);
	const int m = head.length;
	bool fine(int pos, int val) {
		return (pos >= m || head[pos] == val);
	}
	long ret;
	foreach (l0; 0 .. N + 1) foreach (l1; 0 .. N +1) {
		/*
			x[i] = head[i] (0 <= i < m)
			x[i] = (!)x[N - 1 - i] (0 <= i < l)
			x[l] < (!)x[N - 1 - l] (if l < N)
		*/
		long tmp = 1;
		foreach (i; 0 .. N) if (i <= N - 1 - i) {
			long cnt;
			foreach (s; 0 .. 2) foreach (t; 0 .. 2) if (fine(i, s) && fine(N - 1 - i, t)) {
				bool ok = true;
				if (i == N - 1 - i) {
					ok = ok && (s == t);
				}

				if (i < l0) {
					ok = ok && (s == t);
				} else if (i == l0) {
					ok = ok && (s < t);
				}
				if (N - 1 - i < l0) {
					ok = ok && (t == s);
				} else if (N - 1 - i == l0) {
					ok = ok && (t < s);
				}

				if (i < l1) {
					ok = ok && (s == 1 - t);
				} else if (i == l1) {
					ok = ok && (s < 1 - t);
				}
				if (N - 1 - i < l1) {
					ok = ok && (t == 1 - s);
				} else if (N - 1 - i == l1) {
					ok = ok && (t < 1 - s);
				}

				if (ok) {
					++cnt;
				}
			}
			tmp *= cnt;
		}
// writeln("  l0 = ",l0,", l1 = ",l1," : ",tmp);
		ret += tmp;
	}
	return ret;
}

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

		long k = K + 1;

		int[] a = new int[N];
		bool ok = true;
		foreach (i; 0 .. N) {
			for (a[i] = 0; a[i] < 2; ++a[i]) {
				const res = solve(a[0 .. i + 1]);
				if (k > res) {
					k -= res;
				} else {
					break;
				}
			}
			if (a[i] == 2) {
				assert(i == 0);
				writeln(-1);
				ok = false;
				break;
			}
		}
		if (ok) {
			writeln(a.to!string.removechars("[], "));
		}
	}
	} catch (EOFException) {}
}


Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).The University works in such a way that every day it holds exactly n lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks).The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the n pairs she knows if there will be a class at that time or not.Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university.Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home.Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair.

The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of lessons at the university.  The second line contains n numbers ai (0 ≤ ai ≤ 1). Number ai equals 0, if Alena doesn't have the i-th pairs, otherwise it is equal to 1. Numbers a1, a2, ..., an are separated by spaces.

Print a single number — the number of pairs during which Alena stays at the university.

NoteIn the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair. In the last sample Alena doesn't have a single pair, so she spends all the time at home.

import std.stdio;
import std.conv;
import std.array;
import std.algorithm;
void main()
{
	int num;
	readf("%d\n",&num);
	string[]s=split(readln());
	int[]a;
	for(int i=0;i<s.length;i++)a~=to!int(s[i]);
	int ans=0;
	for(int i=1;i<a.length-1;i++)if(a[i-1]==1&&a[i+1]==1)a[i]=1;
	for(int i=0;i<a.length;i++)ans+=a[i];
	writeln(ans);
	readln();
}

module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string[] tk;
        string readString() {
                while (tk.empty)
                        tk = readln.split;
                auto tkt = tk.front;
                tk.popFront;
                return tkt;
        }
        int readInt() {
                return readString.to!int;
        }
        double readDouble() {
                return readString.to!double;
        }
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.readInt;
        while (t--) {
                int n = cin.readInt;
                int[] arr = new int[n];
                foreach (ref i; arr) i = cin.readInt;
                int count = 0;
                for (int i = 0; i < n; i++) {
                        if (arr[i] == 1) count++;
                        if (arr[i] == 0) if (i - 1 >= 0 && i + 1 < n && arr[i - 1] == 1 && arr[i + 1] == 1)
                                count++;
                }
                writeln(count);
        }
}


Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad.The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions $$$a$$$, $$$b$$$ and $$$c$$$ respectively. At the end of the performance, the distance between each pair of ropewalkers was at least $$$d$$$.Ropewalkers can walk on the rope. In one second, only one ropewalker can change his position. Every ropewalker can change his position exactly by $$$1$$$ (i. e. shift by $$$1$$$ to the left or right direction on the rope). Agafon, Boniface and Konrad can not move at the same time (Only one of them can move at each moment). Ropewalkers can be at the same positions at the same time and can "walk past each other".You should find the minimum duration (in seconds) of the performance. In other words, find the minimum number of seconds needed so that the distance between each pair of ropewalkers can be greater or equal to $$$d$$$.Ropewalkers can walk to negative coordinates, due to the rope is infinite to both sides.

The only line of the input contains four integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$1 \le a, b, c, d \le 10^9$$$). It is possible that any two (or all three) ropewalkers are in the same position at the beginning of the performance.

Output one integer — the minimum duration (in seconds) of the performance.

NoteIn the first example: in the first two seconds Konrad moves for 2 positions to the right (to the position $$$8$$$), while Agafon and Boniface stay at their positions. Thus, the distance between Agafon and Boniface will be $$$|5 - 2| = 3$$$, the distance between Boniface and Konrad will be $$$|2 - 8| = 6$$$ and the distance between Agafon and Konrad will be $$$|5 - 8| = 3$$$. Therefore, all three pairwise distances will be at least $$$d=3$$$, so the performance could be finished within 2 seconds.

module main;

import std.stdio;
import std.container.array;
import std.algorithm.sorting;

void main(string[] args){
    int[] arr = [2:0];
    for (int i = 0; i < 3; i++) {
        scanf("%d", &arr[i]);
    }
    arr.sort();
    int d;
    scanf("%d", &d);
    int ans;
    int inc = d - (arr[1] - arr[0]);
    if (inc > 0) {
        ans += inc;
    }
    inc = d - (arr[2] - arr[1]);
    if (inc > 0) {
        ans += inc;
    }
    printf("%d", ans);
}

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

void main ()
{
	long a, b, c, d;
	while (readf !(" %s %s %s %s") (a, b, c, d) > 0)
	{
		auto z = [a, b, c];
		sort (z);
		a = z[0];
		b = z[1];
		c = z[2];
		long res = 0;
		res += d - min (b - a, d);
		res += d - min (c - b, d);
		writeln (res);
	}
}

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

string FMT_F = "%.10f";

static 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; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

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

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

void main()
{
	auto abc = new long[](3);
	foreach (i; 0..3)
	{
		abc[i] = RD;
	}
	auto d = RD;

	abc.sort();
	long ans = max(0, d - (abc[1] - abc[0])) + max(0, d - (abc[2] - abc[1]));

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


Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem.A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will look like following: a game designer will select a rectangular area on the map, and each cell whose center belongs to the selected rectangle will be filled with the enemy unit.More formally, if a game designer selected cells having coordinates (x1, y1) and (x2, y2), where x1 ≤ x2 and y1 ≤ y2, then all cells having center coordinates (x, y) such that x1 ≤ x ≤ x2 and y1 ≤ y ≤ y2 will be filled. Orthogonal coordinates system is set up so that one of cell sides is parallel to OX axis, all hexagon centers have integer coordinates and for each integer x there are cells having center with such x coordinate and for each integer y there are cells having center with such y coordinate. It is guaranteed that difference x2 - x1 is divisible by 2.Working on the problem Petya decided that before painting selected units he wants to output number of units that will be painted on the map.Help him implement counting of these units before painting.

The only line of input contains four integers x1, y1, x2, y2 ( - 109 ≤ x1 ≤ x2 ≤ 109,  - 109 ≤ y1 ≤ y2 ≤ 109) — the coordinates of the centers of two cells.

Output one integer — the number of cells to be filled.

import std.stdio;
import std.algorithm;

void main()
{
	long x1, x2, y1, y2;

	scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);

	long dx = (x2 - x1) / 2;
	long dy = (y2 - y1) / 2;
	printf("%lld\n", (dx + 1) * (dy + 1) + dx * dy);
}


One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It had n grown-ups and m kids..."The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers could have paid for the ride.The bus fare equals one berland ruble in High Bertown. However, not everything is that easy — no more than one child can ride for free with each grown-up passenger. That means that a grown-up passenger who rides with his k (k > 0) children, pays overall k rubles: a ticket for himself and (k - 1) tickets for his children. Also, a grown-up can ride without children, in this case he only pays one ruble.We know that in High Bertown children can't ride in a bus unaccompanied by grown-ups.Help Vasya count the minimum and the maximum sum in Berland rubles, that all passengers of this bus could have paid in total.

The input file consists of a single line containing two space-separated numbers n and m (0 ≤ n, m ≤ 105) — the number of the grown-ups and the number of the children in the bus, correspondingly.

If n grown-ups and m children could have ridden in the bus, then print on a single line two space-separated integers — the minimum and the maximum possible total bus fare, correspondingly.  Otherwise, print "Impossible" (without the quotes).

NoteIn the first sample a grown-up rides with two children and pays two rubles.In the second sample there are only children in the bus, so the situation is impossible. In the third sample there are two cases:  Each of the two grown-ups rides with one children and pays one ruble for the tickets. In this case the passengers pay two rubles in total.  One of the grown-ups ride with two children's and pays two rubles, the another one rides alone and pays one ruble for himself. So, they pay three rubles in total.

//DMD64 D Compiler 2.072.2
import std.stdio;
void main(){
    int a,b,c,d;
    readf("%d %d",&a,&b);
    if(a<1&&b>0){write("Impossible");return;}
    c=a;
    if(b-a>0){c+=b-a;}
    d=a;
    if(b>0){d+=b-1;}
    write(c,' ',d);
}

import std.stdio;void main(){int a,b;readf("%d %d",&a,&b);if(a<1&&b>0){write("Impossible");return;}write(a>b?a:b,' ',b!=0?a+b-1:a);}

//rextester.com:dmd64 2.072.2--codeforces.com:dmd32 2.071.2
import std.stdio;
void main(){
    int a,b;readf("%d %d",&a,&b);
    if(a<1&&b>0){write("Impossible");return;}
    write(a>b?a:b,' ',b!=0?a+b-1:a);
}

//DMD64 2.072.2 | RexTester.Com & DMD32 2.079.0 | CodeForces.Com
import std.stdio;
void main() {
    int grown_ups, children;
    readf("%d %d", &grown_ups, &children);

    if (grown_ups < 1 && children > 0) {
        write("Impossible");
        return;
    }

    write(grown_ups > children ? grown_ups : children, ' ', children != 0 ? grown_ups + children - 1 : grown_ups);
}


Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime. You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l ≤ a < b < c ≤ r. More specifically, you need to find three numbers (a, b, c), such that l ≤ a < b < c ≤ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.

The single line contains two positive space-separated integers l, r (1 ≤ l ≤ r ≤ 1018; r - l ≤ 50).

Print three positive space-separated integers a, b, c — three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.  If the counterexample does not exist, print the single number -1.

NoteIn the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.

import std.stdio;

long GCD(long a, long b) {
	return b ? GCD(b, a % b) : a;
}

void main() {

	long l, r;

	readf(" %s %s", &l, &r);

	foreach (i; l .. r + 1)
		foreach (j; i + 1 .. r + 1)
			foreach (k; j + 1 .. r + 1)
			if (GCD(i, j) == 1 && GCD(j, k) == 1 && GCD(i, k) != 1) {
				writefln("%d %d %d", i, j, k);
				return;
			}

	writeln("-1");
}

import std.stdio;
import std.numeric;

void main() {

	long l, r;

	readf(" %s %s", &l, &r);

	foreach (i; l .. r + 1)
		foreach (j; i + 1 .. r + 1)
			foreach (k; j + 1 .. r + 1)
			if (gcd(i, j) == 1 && gcd(j, k) == 1 && gcd(i, k) != 1) {
				writefln("%d %d %d", i, j, k);
				return;
			}

	writeln("-1");
}

import std.stdio, std.bigint, std.string;

BigInt gcd(BigInt a, BigInt b) {
	return b ? gcd(b, a % b) : a;
}

void main() {

	auto l = BigInt (readln(' ').strip);
	auto r = BigInt (readln.strip);

	foreach (i; l .. r + 1)
		foreach (j; i + 1 .. r + 1)
			foreach (k; j + 1 .. r + 1)
			if (gcd(i, j) == 1 && gcd(j, k) == 1 && gcd(i, k) != 1) {
				writefln("%d %d %d", i, j, k);
				return;
			}

	writeln("-1");
}

import std.stdio;

void main() {

	long l, r;

	readf(" %s %s", &l, &r);

	if (r - l < 2) {
		writeln(-1);
		return;
	}

	if (!(l % 2)) {
		writefln("%s %s %s", l, l + 1, l + 2);
		return;
	}

	if (r - l > 2){
		writefln("%s %s %s", l + 1, l + 2, l + 3);
		return;
	}

	writeln(-1);
}

import std.stdio;

long GCD(long a, long b) {
	return b ? GCD(b, a % b) : a;
}

void main() {

	long l, r;

	readf(" %s %s", &l, &r);

	foreach (i; l .. r + 1) {
		foreach (j; i .. r + 1)
			foreach (k; j .. r + 1)
			if (GCD(i, j) == 1 && GCD(j, k) == 1 && GCD(i, k) != 1) {
					writefln("%d %d %d", i, j, k);
					return;
				}
	}

	writeln("-1");
}

import std.stdio;

void main() {

	long l, r;

	readf(" %s %s", &l, &r);

	if (r - l + 1 < 3) {
		writeln(-1);
		return;
	}

	if (l % 2 == 0) {
		writefln("%s %s %s", l, l + 1, l + 2);
		return;
	}

	if (r - l + 1 > 3){
		writefln("%s %s %s", l + 1, l + 2, l + 3);
		return;
	}

	writeln(-1);
}

//ahmat
import core.stdc.stdio:scanf,printf,puts;
import core.bitop;
import std.stdio;
import std.string;
import std.algorithm;
import std.functional;
import std.array;
import std.container;
import std.conv;
import std.container;
import std.typecons;
import std.math;
import std.numeric;
pragma(inline,true);

void main(){
    ulong l,r;
    readf!"%d %d"(l,r);
    r++;
    readln;
    foreach(a;l..r)
        foreach(b;a+1..r)
            foreach(c;b+1..r)
                if(gcd(a,b)==1 && gcd(b,c)==1 && gcd(a,c)!=1){
                    writefln!"%d %d %d"(a,b,c);
                    return;
                }
    puts("-1");
}

import std.stdio;

long GCD(long a, long b) {
	return b ? GCD(b, a % b) : a;
}

void main() {

	long l, r;

	readf(" %s %s", &l, &r);

	foreach (i; l .. r + 1) {
		foreach (j; i .. r + 1)
			foreach (k; j .. r + 1)
				if (j % i != 0 && k % j != 0 && GCD(i, k) != 1) {
					writefln("%d %d %d", i, j, k);
					return;
				}
	}

	writeln("-1");
}

import std.stdio;

void main() {

	long l, r;

	readf(" %s %s", &l, &r);

	foreach (i; l .. r + 1) {
		foreach (j; i .. r + 1)
			foreach (k; j .. r + 1)
				if (j % i != 0 && k % j != 0) {
					writefln("%d %d %d", i, j, k);
					return;
				}
	}

	writeln("-1");
}


Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid: ABCDEFGHIJKLMNOPQRSTUVWXYZ We say that two tiles are adjacent if they share a side or a corner. In the example grid above, the tile with the letter 'A' is adjacent only to the tiles with letters 'B', 'N', and 'O'. A tile is not adjacent to itself.A sequence of tiles is called a path if each tile in the sequence is adjacent to the tile which follows it (except for the last tile in the sequence, which of course has no successor). In this example, "ABC" is a path, and so is "KXWIHIJK". "MAB" is not a path because 'M' is not adjacent to 'A'. A single tile can be used more than once by a path (though the tile cannot occupy two consecutive places in the path because no tile is adjacent to itself).You’re given a string s which consists of 27 upper-case English letters. Each English letter occurs at least once in s. Find a grid that contains a path whose tiles, viewed in the order that the path visits them, form the string s. If there’s no solution, print "Impossible" (without the quotes).

The only line of the input contains the string s, consisting of 27 upper-case English letters. Each English letter occurs at least once in s.

Output two lines, each consisting of 13 upper-case English characters, representing the rows of the grid. If there are multiple solutions, print any of them. If there is no solution print "Impossible".

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

string solve (string s, int i, int j, int n)
{
	char [13] [2] res;
	int loopLength = (j - i + 1) / 2;
	while (i > 0)
	{
		s = s[1..$] ~ s[0];
		i -= 1;
		j -= 1;
	}
	debug {writeln (s, " ", i, " ", j);}

	int mid = loopLength - 1;
	mid = min (mid, 12);
	int pos = mid;
	res[0][pos] = s[i];
	while (pos > 0)
	{
		pos -= 1;
		i += 1;
		res[0][pos] = s[i];
	}
	i += 1;
	res[1][pos] = s[i];
	while (i < j - 1)
	{
		pos += 1;
		i += 1;
		res[1][pos] = s[i];
	}
	i += 1;
	assert (i == j);
	pos = mid;
	assert (res[0][pos] == s[i]);
	while (pos < 12)
	{
		pos += 1;
		i += 1;
		res[0][pos] = s[i];
	}
	i += 1;
	if (i < n)
	{
		res[1][pos] = s[i];
	}
	while (i + 1 < n)
	{
		pos -= 1;
		i += 1;
		res[1][pos] = s[i];
	}

	return res[].map !(x => x.idup).join ("\n");
}

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		int n = cast (int) (s.length);
		foreach (i; 0..n)
		{
			foreach (j; i + 1..n)
			{
				if (s[i] == s[j])
				{
					if (j - i == 1)
					{
						writeln ("Impossible");
					}
					else
					{
						writeln (solve (s, i, j, n));
					}
				}
			}
		}
	}
}


You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: "BWBW...BW".Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to .In one step you can move one of the pieces one cell to the left or to the right. You cannot move pieces beyond the borders of the board. You also cannot move pieces to the cells that are already occupied.Your task is to place all the pieces in the cells of the same color using the minimum number of moves (all the pieces must occupy only the black cells or only the white cells after all the moves are made).

The first line of the input contains one integer n (2 ≤ n ≤ 100, n is even) — the size of the chessboard.  The second line of the input contains  integer numbers  (1 ≤ pi ≤ n) — initial positions of the pieces. It is guaranteed that all the positions are distinct.

Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color.

NoteIn the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3.In the second example the possible strategy is to move  in 4 moves, then  in 3 moves,  in 2 moves and  in 1 move.

import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;
import std.bigint;

void main()
{
	int n = readln.chomp.to!int;
	int[] p = readln.chomp.split.map!(to!int).array;
	std.algorithm.sort(p);
	int ans = int.max;
	for (int i = 1; i <= 2; ++i) {
		int sum = 0;
		foreach (int j, int t; p) {
			sum += abs(j * 2 + i - t);
		}
		ans = min(ans, sum);
	}
	ans.writeln;
}

void tie(R, Args...)(R arr, ref Args args)
		if (isRandomAccessRange!R || isArray!R)
in
{
	assert (arr.length == args.length);
}
body
{
	foreach (i, ref v; args) {
		alias T = typeof(v);
		v = arr[i].to!T;
	}
}

void verbose(Args...)(in Args args)
{
	stderr.write("[");
	foreach (i, ref v; args) {
		if (i) stderr.write(", ");
		stderr.write(v);
	}
	stderr.writeln("]");
}

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

void main()
{
    int n;
    readf( "%s\n", &n );
    auto a = readln.splitter.map!( to!int ).array;
    a.sort;
    auto ans = n*n;
    foreach ( int shift; 1..3 ) {
        int cur = 0;
        foreach ( int idx, int e; a) {
            cur += abs( e - ( 2*idx + shift ) );
        }
        ans = min( ans, cur );
    }
    writeln(ans);
}

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

void main()
{
    int n;
    readf( "%s\n", &n );
    auto a = readln.splitter.map!( to!int ).array;
    a.sort;
    auto ans = n*n;
    foreach ( int shift; 1..3 ) {
        int cur = 0;
        foreach ( int idx, int e; a ) {
            cur += abs( e - ( 2*idx + shift ) );
        }
        ans = min( ans, cur );
    }
    writeln( ans );
}

import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;
import std.bigint;

void main()
{
	int n = readln.chomp.to!int;
	int[] p = readln.chomp.split.map!(to!int).array;
	int ans = int.max;
	for (int i = 1; i <= 2; ++i) {
		int sum = 0;
		foreach (int j, int t; p) {
			sum += abs(j * 2 + i - t);
		}
		ans = min(ans, sum);
	}
	ans.writeln;
}

void tie(R, Args...)(R arr, ref Args args)
		if (isRandomAccessRange!R || isArray!R)
in
{
	assert (arr.length == args.length);
}
body
{
	foreach (i, ref v; args) {
		alias T = typeof(v);
		v = arr[i].to!T;
	}
}

void verbose(Args...)(in Args args)
{
	stderr.write("[");
	foreach (i, ref v; args) {
		if (i) stderr.write(", ");
		stderr.write(v);
	}
	stderr.writeln("]");
}

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

void main()
{
    int n;
    readf( "%s\n", &n );
    auto a = readln.splitter.map!( to!int ).array;
    auto ans = n*n;
    foreach ( int shift; 1..3 ) {
        int cur = 0;
        foreach ( int idx, int e; a) {
            cur += abs( e - ( 2*idx + shift ) );
        }
        ans = min( ans, cur );
    }
    writeln(ans);
}


Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of k + 1 consecutive ones, and then k consecutive zeroes.Some examples of beautiful numbers:   12 (110);  1102 (610);  11110002 (12010);  1111100002 (49610). More formally, the number is beautiful iff there exists some positive integer k such that the number is equal to (2k - 1) * (2k - 1).Luba has got an integer number n, and she wants to find its greatest beautiful divisor. Help her to find it!

The only line of input contains one number n (1 ≤ n ≤ 105) — the number Luba has got.

Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists.

#!/usr/bin/env dub
/+ dub.sdl:
    name "B"
+/

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

void main()
{
    long[] beauty;
    foreach (i; 1..15) {
        beauty ~= (2^^i - 1) * (2 ^^ (i-1));
    }
    beauty.reverse();

    debug {
        writeln(beauty);
    }

    long N = to!long(readln().strip());

    foreach (b; beauty) {
        if (N % b == 0) {
            writeln(b);
            return;
        }
    }

}

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

immutable inf = 10^^9 + 7;

void main() {
    int n;
    scan(n);

    long ans = 1;

    foreach (k ; 1 .. 30) {
        long bn = 1L * (2L^^k - 1) * (2L^^(k - 1));
        if (k > bn) break;
        if (n % bn == 0) {
            ans = max(ans, bn);
        }
    }

    writeln(ans);
}

struct UnionFind {
    private {
        int N;
        int[] p;
        int[] rank;
    }

    this (int n) {
        N = n;
        p = iota(N).array;
        rank = new int[](N);
    }

    int find_root(int x) {
        if (p[x] != x) {
            p[x] = find_root(p[x]);
        }

        return p[x];
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y) {
        int u = find_root(x), v = find_root(y);

        if (u == v) return;

        if (rank[u] < rank[v]) {
            p[u] = v;
        }
        else {
            p[v] = u;

            if (rank[u] == rank[v]) {
                rank[u]++;
            }
        }
    }
}

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

struct Queue(T) {
    private {
        int N, head, tail;
        T[] data;
    }

    this(int n) {
        N = n + 1;
        data = new T[](N);
    }

    bool empty() {
        return head == tail;
    }

    bool full() {
        return (tail + 1) % N == head;
    }

    T front() {
        return data[head];
    }

    void push(T x) {
        assert(!full);
        data[tail++] = x;
        tail %= N;
    }

    void pop() {
        assert(!empty);
        head = (head + 1) % N;
    }

    void clear() {
        head = tail = 0;
    }
}


Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook.Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight.

The first line contains two integers n and d (1 ≤ n, d ≤ 100). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 100). The third line contains integer m (1 ≤ m ≤ 100).

In a single line print a single integer — the answer to the problem.

NoteIn the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles.In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 =  - 5.

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

alias sum = reduce!"a + b";

void main() {
    int n, d; readf("%d %d\n", &n, &d);
    int[] a = stdin.readln.split.map!(to!int).array;
    int m; readf("%d\n", &m);
    int ans = a.sort[0 .. min(m, $)].sum - d * max(m - n, 0);
    ans.writeln;
}

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

void main() {
  auto input = new int[][2];
  foreach (ref elem; input) {
    elem = readln.chomp.split.map!(to!int).array;
  }
  int n = input[0][0];
  int d = input[0][1];
  int[] a = input[1].sort!("a < b").array;
  int m = readln.chomp.to!int;

  int profit = 0;

  if (a.length >= m) {
    profit += reduce!("a + b")(0, a[0 .. m]);
  } else {
    profit += reduce!("a + b")(0, a);
    profit -= (m - a.length) * d;
  }

  profit.writeln;
}


In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Arkady's choice) by ai. Each extension can't be used more than once, the extensions can be used in any order.Now Arkady's field has size h × w. He wants to enlarge it so that it is possible to place a rectangle of size a × b on it (along the width or along the length, with sides parallel to the field sides). Find the minimum number of extensions needed to reach Arkady's goal.

The first line contains five integers a, b, h, w and n (1 ≤ a, b, h, w, n ≤ 100 000) — the sizes of the rectangle needed to be placed, the initial sizes of the field and the number of available extensions. The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 100 000), where ai equals the integer a side multiplies by when the i-th extension is applied.

Print the minimum number of extensions needed to reach Arkady's goal. If it is not possible to place the rectangle on the field with all extensions, print -1. If the rectangle can be placed on the initial field, print 0.

NoteIn the first example it is enough to use any of the extensions available. For example, we can enlarge h in 5 times using the second extension. Then h becomes equal 10 and it is now possible to place the rectangle on the field.

import core.bitop;
import core.checkedint;
import core.simd;
import core.stdc.stdlib;
import core.stdc.string;
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.bitmanip;
import std.complex;
import std.container;
import std.conv;
import std.datetime;
import std.format;
import std.functional;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.regex;
import std.stdio;
import std.string;
import std.typecons;
import std.variant;

__gshared:

alias BitSet(size_t n) = size_t[(n + size_t.sizeof * 8 - 1) / (size_t.sizeof * 8)];

auto getAddrTuple() {
    return tuple();
}

auto getAddrTuple(T, U...)(ref T head, ref U tail) {
    return tuple(&head, getAddrTuple(tail).expand);
}

bool read(T...)(ref T vars) if (vars.length > 0) {
    return readf(' ' ~ replicate("%s ", vars.length), getAddrTuple(vars).expand) == vars.length;
}

T[ ] allocate(T)(size_t n) {
    return (cast(T*)malloc(n * T.sizeof))[0 .. n];
}

auto pairwise(R)(R range) if (isForwardRange!R) {
    return lockstep(range, dropOne(range));
}

int ih, iw, n;
int[10^^5] _exts;
int[ ] exts;
uint[Tuple!(int, int, int)] dp;

uint dyn(int pos, int curh, int curw) {
    if (curh >= ih && curw >= iw)
        return pos;
    if (pos == n)
        return uint.max;
    if (auto p = tuple(pos, curh, curw) in dp)
        return *p;
    uint result = uint.max;
    bool overflow;
    if (curh < ih) {
        int nexth = muls(curh, exts[pos], overflow);
        if (overflow) {
            nexth = int.max;
            overflow = false;
        }
        result = dyn(pos + 1, nexth, curw);
    }
    if (curw < iw) {
        int nextw = muls(curw, exts[pos], overflow);
        if (overflow)
            nextw = int.max;
        result = min(result, dyn(pos + 1, curh, nextw));
    }
    dp[tuple(pos, curh, curw)] = result;
    return result;
}

uint solve(int oh, int ow) {
    dp = null;
    return dyn(0, oh, ow);
}

void main() {
    int oh, ow;
    while (read(ih, iw, oh, ow, n)) {
        exts = _exts[0 .. n];
        foreach (ref x; exts)
            read(x);
        exts.sort!`a > b`;
        writeln(cast(int)min(solve(oh, ow), solve(ow, oh)));
    }
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,
	std.functional,std.math,std.string,std.range,std.complex,std.bitmanip,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,
	std.meta,core.stdc.stdio : freopen;
import std.numeric: fft,Fft,gcd,inverseFft;alias big=BigInt;alias pair(X,Y)=Tuple!(X,"fi",Y,"se");
alias lint=long;private const int mod=1_000_000_007;
alias pii=pair!(int,int);alias pll=pair!(long,long);alias mp=make_pair;alias gcd=std.numeric.gcd;
private
{
	pure nothrow
	{
		T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
		pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
		big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
		@property X sqr(X)(in X a_) {return a_*a_;}
		@property X cub(X)(in X a_) {return a_*a_*a_;}
		int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
		size_t lowb(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			size_t l=0,r=a.length;
			while(r-l>1)
			{
				auto m=(l+r)>>1;
				if(!(a[m]<g))r=m;
				else l=m;
			}
			return (!(a[l]<g))?l:r;
		}
		size_t upb(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			size_t l=0,r=a.length;
			while(r-l>1)
			{
				auto m=(l+r)>>1;
				if(g<a[m])r=m;
				else l=m;
			}
			return (g<a[l])?l:r;
		}
		size_t binf(T,X)(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;
		}
		bool binary_search(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			return binf(a,g)!=a.length;
		}
	}
	void putarr(X)(in X a,in char ch=' ') if(isInputRange!X && !isInputRange!(ElementEncodingType!X))
	{foreach(const ref i;a)write(i,ch);}
	void putarr(X)(in X a) if(isInputRange!X && isInputRange!(ElementEncodingType!X))
	{
		foreach(ref const i;a)
		{
			foreach(ref const j;i)write(j,' ');
			writeln;
		}
	}
	bool getarr(X)(X a,in size_t n)
	{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
	bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
	{
		size_t s=0;
		foreach(ref e;ptrs)
		{
			if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
			else s+=readf(" %s",&e);
		}
		return s==ptrs.length;
	}
	bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
	{
		size_t s=0;
		foreach(ref e;ptrs)
		{
			if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
			else s+=readf(" %s",&e);
		}
		readln;
		return s==ptrs.length;
	}
	nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
	nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
	@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
	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--------------------------
private
{

}
void main()
{
	version(home)
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	int n,x,y,w,h;
loop:while(read(h,w,x,y,n))
	{
		auto a=arread!int;
		sort(a);
		a=a[max(0,sz(a)-34)..$];
		reverse(a);
		auto dp=new int[10^^5+1],d=new int[10^^5+1];
		dp[x]=d[x]=y;
		foreach(i;0..a.length)
		{
			foreach(j;0..dp.length)
			{
				if((j>=w && dp[j]>=h) || (j>=h && dp[j]>=w))
				{
					writeln(i);
					continue loop;
				}
			}
			//d[]=dp[];
			foreach(j;0..dp.length)
			{
				if(dp[j]!=0)
				{
					if(1L*j*a[i]<=10^^5)d[j*a[i]]=max(d[j*a[i]],dp[j]);
					else d[10^^5]=max(d[10^^5],dp[j]);
					if(1L*dp[j]*a[i]<=10^^5)d[j]=max(dp[j]*a[i],d[j]);
					else d[j]=10^^5;
				}
			}
			dp[]=d[];
		}
		foreach(j;0..dp.length)
		{
			if((j>=w && dp[j]>=h) || (j>=h && dp[j]>=w))
			{
				writeln(a.length);
				continue loop;
			}
		}
		writeln(-1);
	}
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,
	std.functional,std.math,std.string,std.range,std.complex,std.bitmanip,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,
	std.meta,core.stdc.stdio : freopen;
import std.numeric: fft,Fft,gcd,inverseFft;alias big=BigInt;alias pair(X,Y)=Tuple!(X,"fi",Y,"se");
alias lint=long;private const int mod=1_000_000_007;
alias pii=pair!(int,int);alias pll=pair!(long,long);alias mp=make_pair;alias gcd=std.numeric.gcd;
private
{
	pure nothrow
	{
		T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
		pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
		big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
		@property X sqr(X)(in X a_) {return a_*a_;}
		@property X cub(X)(in X a_) {return a_*a_*a_;}
		int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
		size_t lowb(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			size_t l=0,r=a.length;
			while(r-l>1)
			{
				auto m=(l+r)>>1;
				if(!(a[m]<g))r=m;
				else l=m;
			}
			return (!(a[l]<g))?l:r;
		}
		size_t upb(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			size_t l=0,r=a.length;
			while(r-l>1)
			{
				auto m=(l+r)>>1;
				if(g<a[m])r=m;
				else l=m;
			}
			return (g<a[l])?l:r;
		}
		size_t binf(T,X)(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;
		}
		bool binary_search(T,X)(T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
		{
			return binf(a,g)!=a.length;
		}
	}
	void putarr(X)(in X a,in char ch=' ') if(isInputRange!X && !isInputRange!(ElementEncodingType!X))
	{foreach(const ref i;a)write(i,ch);}
	void putarr(X)(in X a) if(isInputRange!X && isInputRange!(ElementEncodingType!X))
	{
		foreach(ref const i;a)
		{
			foreach(ref const j;i)write(j,' ');
			writeln;
		}
	}
	bool getarr(X)(X a,in size_t n)
	{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
	bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
	{
		size_t s=0;
		foreach(ref e;ptrs)
		{
			if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
			else s+=readf(" %s",&e);
		}
		return s==ptrs.length;
	}
	bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
	{
		size_t s=0;
		foreach(ref e;ptrs)
		{
			if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
			else s+=readf(" %s",&e);
		}
		readln;
		return s==ptrs.length;
	}
	nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
	nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
	@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
	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--------------------------
private
{

}
void main()
{
	version(home)
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	int n,x,y,w,h;
loop:while(read(h,w,x,y,n))
	{
		auto a=arread!int;
		sort(a);
		a=a[max(0,sz(a)-34)..$];
		reverse(a);
		auto dp=new lint[10^^5+1],d=new long[10^^5+1];
		dp[x]=d[x]=y;
		foreach(i;0..a.length)
		{
			foreach(j;0..dp.length)
			{
				if((j>=w && dp[j]>=h) || (j>=h && dp[j]>=w))
				{
					writeln(i);
					continue loop;
				}
			}
			//d[]=dp[];
			foreach(j;0..dp.length)
			{
				if(dp[j]!=0)
				{
					if(1L*j*a[i]<=10^^5)d[j*a[i]]=max(d[j*a[i]],dp[j]);
					if(1L*dp[j]*a[i]<=10^^5)d[j]=max(dp[j]*a[i],d[j]);
				}
			}
			dp[]=d[];
		}
		foreach(j;0..dp.length)
		{
			if((j>=w && dp[j]>=h) || (j>=h && dp[j]>=w))
			{
				writeln(a.length);
				continue loop;
			}
		}
		writeln(-1);
	}
}


Soon a school Olympiad in Informatics will be held in Berland, n schoolchildren will participate there.At a meeting of the jury of the Olympiad it was decided that each of the n participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma.They also decided that there must be given at least min1 and at most max1 diplomas of the first degree, at least min2 and at most max2 diplomas of the second degree, and at least min3 and at most max3 diplomas of the third degree.After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree.Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described limitations.It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all n participants of the Olympiad will receive a diploma of some degree.

The first line of the input contains a single integer n (3 ≤ n ≤ 3·106) — the number of schoolchildren who will participate in the Olympiad. The next line of the input contains two integers min1 and max1 (1 ≤ min1 ≤ max1 ≤ 106) — the minimum and maximum limits on the number of diplomas of the first degree that can be distributed. The third line of the input contains two integers min2 and max2 (1 ≤ min2 ≤ max2 ≤ 106) — the minimum and maximum limits on the number of diplomas of the second degree that can be distributed.  The next line of the input contains two integers min3 and max3 (1 ≤ min3 ≤ max3 ≤ 106) — the minimum and maximum limits on the number of diplomas of the third degree that can be distributed.  It is guaranteed that min1 + min2 + min3 ≤ n ≤ max1 + max2 + max3.

In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas. The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree.

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

void main() {
  int n = readln().strip.to!int;
  int x, y, z, u, v, w;
  scanf("%d%d%d%d%d%d", &x, &u, &y, &v, &z, &w);
  n -= x + y + z;
  int d, e, f;
  d = min(n, u - x);
  n -= d;
  x += d;

  e = min(n, v - y);
  n -= e;
  y += e;

  f = min(n, w - z);
  n -= f;
  z += f;

  writeln(x, ' ', y, ' ', z);
}

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

void main() {
    int n = readln.chomp.to!int;
    int[][] diploma;
    for (int i = 0; i < 3; i++) {
        diploma ~= readln.chomp.split.map!(to!int).array;
    }

    int dip_1 = min(diploma[0][1], n - (diploma[1][0] + diploma[2][0]));
    n -= dip_1;
    int dip_2 = min(diploma[1][1], n - diploma[2][0]);
    int dip_3 = n - dip_2;
    writeln(dip_1, " ", dip_2, " ", dip_3);
}


It's been long after the events of the previous problems, and Karen has now moved on from student life and is looking to relocate to a new neighborhood.  The neighborhood consists of n houses in a straight line, labelled 1 to n from left to right, all an equal distance apart.Everyone in this neighborhood loves peace and quiet. Because of this, whenever a new person moves into the neighborhood, he or she always chooses the house whose minimum distance to any occupied house is maximized. If there are multiple houses with the maximum possible minimum distance, he or she chooses the leftmost one.Note that the first person to arrive always moves into house 1.Karen is the k-th person to enter this neighborhood. If everyone, including herself, follows this rule, which house will she move into?

The first and only line of input contains two integers, n and k (1 ≤ k ≤ n ≤ 1018), describing the number of houses in the neighborhood, and that Karen was the k-th person to move in, respectively.

Output a single integer on a line by itself, the label of the house Karen will move into.

NoteIn the first test case, there are 6 houses in the neighborhood, and Karen is the fourth person to move in:  The first person moves into house 1.  The second person moves into house 6.  The third person moves into house 3.  The fourth person moves into house 2. In the second test case, there are 39 houses in the neighborhood, and Karen is the third person to move in:  The first person moves into house 1.  The second person moves into house 39.  The third person moves into house 20.

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

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

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

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

long[long][long] cache;
long calc(long d, long m) {
  long ret;
  if (d !in cache) {
    long[long] tmp;
    cache[d] = tmp;
  }
  cache[d].update(m, {
    if (m > 1) {
      const half = m / 2;
      if (half >= d) {
        ret += 1;
        ret += calc(d, m / 2);
        ret += calc(d, m - m / 2);
      }
    }
    debug {
      writefln("calc %s %s = %s", d, m, ret);
    }
    return ret;
  }, (ref long r) {
    return ret = r;
  });
  return ret;
}

long solve(long d, long a, long b, long k) {
  assert(1 <= k);
  assert(k <= calc(d, b - a));
  long ret;
  const mid = (a + b) / 2;
  if (k == 1) {
    ret = mid;
  } else {
    assert(b - a > 1);
    const resL0 = calc(d, mid - a);
    const resR1 = calc(d + 1, b - mid);
    assert(k > 0);
    if (k <= 1 + resL0 + resR1) {
      ret = solve(d, a, mid, k - 1 - resR1);
    } else {
      ret = solve(d, mid, b, k - 1 - resL0);
    }
  }
  debug {
    writefln("solve %s %s %s %s = %s", d, a, b, k, ret);
  }
  return ret;
}

void main() {
  try {
    for (; ; ) {
      const N = readLong();
      const K = readLong();
      debug {
        writefln("==== N = %s, K = %s ====", N, K);
        cache.clear;
      }

      long ans;
      if (K == 1) {
        ans = 1;
      } else if (K == 2) {
        ans = N;
      } else {
        long lo = 0, hi = N;
        for (; lo + 1 < hi; ) {
          const mid = (lo + hi) / 2;
          ((2 + calc(mid, N - 1) >= K) ? lo : hi) = mid;
        }
        debug {
          writeln("lo = ", lo);
          cache.clear;
        }
        ans = solve(lo, 1, N, K - 2);
      }
      writeln(ans);

      debug {
        if (N <= 300) {
          auto used = new bool[N + 1];
          foreach (k; 1 .. K + 1) {
            long mx;
            long im = -1;
            foreach (i; 1 .. N + 1) {
              if (!used[i]) {
                long score = N;
                foreach (j; 1 .. N + 1) {
                  if (used[j]) {
                    chmin(score, abs(j - i));
                  }
                }
                if (chmax(mx, score)) {
                  im = i;
                }
              }
            }
            used[im] = true;
            if (k == K) {
              writeln("brt = ", im);
              assert(im == ans, format("WA %s %s: %s %s", N, K, im, ans));
            }
          }
        }
      }
    }
  } catch (EOFException e) {
  }
}

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

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

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

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

long[long][long] cache;
long calc(long d, long m) {
  long ret;
  if (d !in cache) {
    long[long] tmp;
    cache[d] = tmp;
  }
  cache[d].update(m, {
    if (m > 1) {
      const half = m / 2;
      if (half >= d) {
        ret += 1;
        ret += calc(d, m / 2);
        ret += calc(d, m - m / 2);
      }
    }
    debug {
      writefln("calc %s %s = %s", d, m, ret);
    }
    return ret;
  }, (ref long r) {
    return ret = r;
  });
  return ret;
}

long solve(long d, long a, long b, long k) {
  assert(1 <= k);
  assert(k <= calc(d, b - a));
  long ret;
  const mid = (a + b) / 2;
  if (k == 1) {
    ret = mid;
  } else {
    assert(b - a > 1);
    const resL0 = calc(d, mid - a);
    const resL1 = calc(d + 1, mid - a);
    const resR1 = calc(d + 1, mid - a);
    assert(k > 0);
    if (k <= 1 + resL0 + resR1) {
      ret = solve(d, a, mid, k - 1 - resR1);
    } else {
      ret = solve(d, mid, b, k - 1 - resL0);
    }
  }
  debug {
    writefln("solve %s %s %s %s = %s", d, a, b, k, ret);
  }
  return ret;
}

void main() {
  try {
    for (; ; ) {
      const N = readLong();
      const K = readLong();
      debug {
        writefln("==== N = %s, K = %s ====", N, K);
        cache.clear;
      }

      long ans;
      if (K == 1) {
        ans = 1;
      } else if (K == 2) {
        ans = N;
      } else {
        long lo = 0, hi = N;
        for (; lo + 1 < hi; ) {
          const mid = (lo + hi) / 2;
          ((2 + calc(mid, N - 1) >= K) ? lo : hi) = mid;
        }
        debug {
          writeln("lo = ", lo);
          cache.clear;
        }
        ans = solve(lo, 1, N, K - 2);
      }
      writeln(ans);

      debug {
        if (N <= 300) {
          auto used = new bool[N + 1];
          foreach (k; 1 .. K + 1) {
            long mx;
            long im = -1;
            foreach (i; 1 .. N + 1) {
              if (!used[i]) {
                long score = N;
                foreach (j; 1 .. N + 1) {
                  if (used[j]) {
                    chmin(score, abs(j - i));
                  }
                }
                if (chmax(mx, score)) {
                  im = i;
                }
              }
            }
            used[im] = true;
            if (k == K) {
              writeln("brt = ", im);
              assert(im == ans, format("WA %s %s: %s %s", N, K, im, ans));
            }
          }
        }
      }
    }
  } catch (EOFException e) {
  }
}


Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky.

The first line contains an even integer n (2 ≤ n ≤ 50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n — the ticket number. The number may contain leading zeros.

On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).

NoteIn the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).In the second sample the ticket number is not the lucky number.

module _template;
import std.stdio;
import std.algorithm;
import std.container;
import std.range;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

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

        int read_int() {
                return read_string.to!int;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // int t = cin.read_int;
        while (t--) {
                int n = cin.read_int;
                string s = cin.read_string;

                for (int i = 0; i < s.length; i++) {
                        if (s[i] == '4' || s[i] == '7') {
                                continue;
                        } else {
                                writeln("NO");
                                return;
                        }
                }

                if (sum(s[0..n / 2]) == sum(s[n / 2..n])) {
                        writeln("YES");
                } else writeln("NO");
        }
}


Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game.

The first line of the input contains one integer n (1 ≤ n ≤ 90) — the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... tn ≤ 90), given in the increasing order.

Print the number of minutes Limak will watch the game.

NoteIn the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.In the second sample, the first 15 minutes are boring.In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.

module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

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

        int read_int() {
                return read_string.to!int;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // int t = cin.read_int;
        while (t--) {
                int n = cin.read_int;
                int[] arr = new int[n];

                int ans = 0;
                for (int i = 0; i < n; i++) {
                        arr[i] = cin.read_int;
                        if (arr[0] > 15) {
                                writeln(15);
                                return;
                        }
                        if (i != 0) {
                                if (arr[i] - arr[i - 1] > 15) {
                                        writeln(arr[i - 1] + 15);
                                        return;
                                }
                        }
                }
                if (arr[n - 1] + 15 >= 90) {
                        writeln(90);
                } else writeln(arr[n - 1] + 15);
        }
}

import std.stdio;
import std.algorithm;

const int BORING = 15;
const int MATCH = 90;

void main()
{
	int n;
	int last = 0;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int x;

		scanf("%d", &x);

		if ((x - 1) - last >= BORING) {
			printf("%d\n", last + BORING);
			return;
		}

		last = x;
	}

	printf("%d\n", min(last + BORING, MATCH));
}

module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

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

        int read_int() {
                return read_string.to!int;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // int t = cin.read_int;
        while (t--) {
                int n = cin.read_int;
                int[] arr = new int[n];

                int ans = 0;
                for (int i = 0; i < n; i++) {
                        arr[i] = cin.read_int;
                        if (arr[0] > 15) {
                                writeln(15);
                                return;
                        }
                        if (i != 0) {
                                if (arr[i] - arr[i - 1] > 15) {
                                        writeln(arr[i - 1] + 15);
                                        return;
                                }
                        }
                }
                writeln(90);
        }
}


In this problem you will meet the simplified model of game King of Thieves.In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.  An interesting feature of the game is that you can design your own levels that will be available to other players. Let's consider the following simple design of a level.A dungeon consists of n segments located at a same vertical level, each segment is either a platform that character can stand on, or a pit with a trap that makes player lose if he falls into it. All segments have the same length, platforms on the scheme of the level are represented as '*' and pits are represented as '.'. One of things that affects speedrun characteristics of the level is a possibility to perform a series of consecutive jumps of the same length. More formally, when the character is on the platform number i1, he can make a sequence of jumps through the platforms i1 < i2 < ... < ik, if i2 - i1 = i3 - i2 = ... = ik - ik - 1. Of course, all segments i1, i2, ... ik should be exactly the platforms, not pits. Let's call a level to be good if you can perform a sequence of four jumps of the same length or in the other words there must be a sequence i1, i2, ..., i5, consisting of five platforms so that the intervals between consecutive platforms are of the same length. Given the scheme of the level, check if it is good.

The first line contains integer n (1 ≤ n ≤ 100) — the number of segments on the level. Next line contains the scheme of the level represented as a string of n characters '*' and '.'.

If the level is good, print the word "yes" (without the quotes), otherwise print the word "no" (without the quotes).

NoteIn the first sample test you may perform a sequence of jumps through platforms 2, 5, 8, 11, 14.

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

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

	if(s.count('*') >= 5) {
		while(true) {
			auto idx = cast(int)s.countUntil('*');
			if(idx < 0) break;

			foreach(k; 1..26) {
				ubyte c;

				for(uint i = idx; i < s.length && s[i] == '*'; c++, i += k) {}

				if(c >= 5) return `yes`.write;
			}

			s = s[idx + 1..$];
		}
	}

	`no`.write;
}

import std.stdio;
import std.range;
import std.array;

T read(T)()
{
    T t;
    readf(" %s", &t);
    return t;
}

int main(string[] args)
{
    auto T = read!int;
    readln;
    auto arr = readln;
    arr = arr[0..T];
    arr ~= repeat('.', T).array;

    for (int i = 0; i < T; i++)
    {
        for (int j = 1; j < T; j++)
        {
            if (
                arr[i + j*0] == '*' &&
                arr[i + j*1] == '*' &&
                arr[i + j*2] == '*' &&
                arr[i + j*3] == '*' &&
                arr[i + j*4] == '*')
            {
                writeln("yes");
                return 0;
            }
        }
    }

    writeln("no");

    return 0;
}

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

void main() {

	int n = readln.strip.to!int;
	string s = readln.strip;

	foreach (from; 0 .. n) {
		if (s[from] != '.')
		foreach (jump; 1 .. n) {
			bool ok;
			foreach (i; 1 .. 5) {
				int pos = from + i * jump;
				if (pos >= n || s[pos] != '*') {
					ok = true;
					break;
				}
			}
			if (!ok)
				return write("yes");
		}
	}

	write("no");
}

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

void main() {

	int n = readln.strip.to!int;
	string s = readln.strip;

	foreach (from; 0 .. n)
	foreach (jump; 1 .. n) {
		bool ok;
		foreach (i; 0 .. 5) {
			int pos = from + i * jump;
			if (pos >= n || s[pos] != '*') {
				ok = true;
				break;
			}
		}
		if (!ok)
			return "yes".write;
	}

	"no".write;
}

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

void main() {

	int n = readln.strip.to!int;
	string s = readln.strip;

	int[] idx;
	foreach (i, e; s)
		if (e == '*')
			idx ~= i;

	foreach (from; idx) {
		foreach (jump; 1 .. n) {
			bool ok;
			foreach (i; 1 .. 5) {
				int pos = from + i * jump;
				if (pos >= n || s[pos] != '*') {
					ok = true;
					break;
				}
			}
			if (!ok)
				return write("yes");
		}
	}

	write("no");
}

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

void main() {

	int n = readln.strip.to!int;
	string s = readln.strip;

	foreach (from; 0 .. n)
		foreach (jump; 1 .. n) {
			bool ok;
			foreach (i; 0 .. 5) {
				int pos = from + i * jump;
				if (pos >= n || s[pos] != '*') {
					ok = true;
					break;
				}
			}
			if (!ok)
				return `yes`.write;
		}

	`no`.write;
}

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

void main() {

	int n = readln.strip.to!int;
	string s = readln.strip;

	foreach (from; 0 .. n) {
		if (s[from] != '.')
		foreach (jump; 1 .. n) {
			bool ok;
			foreach (i; 0 .. 5) {
				int pos = from + i * jump;
				if (pos >= n || s[pos] != '*') {
					ok = true;
					break;
				}
			}
			if (!ok)
				return write("yes");
		}
	}

	write("no");
}

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

void main() {

	int n = readln.strip.to!int;
	string s = readln.strip;

	foreach (from; 0 .. n)
	foreach (jump; 1 .. n) {
		bool ok;
		foreach (i; 0 .. 5) {
			int pos = from + i * jump;
			if (pos >= n || s[pos] != '*') {
				ok = true;
				break;
			}
		}
		if (!ok)
			return write("yes");
	}

	write("no");
}

import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main() {
	auto n = readln.strip.to!int, s = readln.strip;
	writeln (iota (1, n).any !(d => iota (d).any !(p =>
		s.drop (p).stride (d).canFind ("*****"))) ? "yes" : "no");
}

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

void main ()
{
	int n;
	while (readf (" %s ", &n) > 0)
	{
		auto s = readln ().strip ();
		bool ok = false;
		foreach (d; 1..n)
		{
			foreach (p; 0..n)
			{
				if (p + d * 4 < n)
				{
					if (s.drop (p)
					    .stride (d)
					    .takeExactly (5)
					    .all !(q{a == '*'}))
					{
						ok = true;
					}
				}
			}
		}
		writeln (ok ? "yes" : "no");
	}
}

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

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

	if(s.count('*') >= 5) {
		while(true) {
			auto idx = cast(int)s.countUntil('*');
			if(idx < 0) break;

			foreach(k; 1..21) {
				ubyte c;

				for(uint i = idx; i < s.length && s[i] == '*'; c++, i += k) {}

				if(c >= 5) return `yes`.write;
			}

			s = s[idx + 1..$];
		}
	}

	`no`.write;
}

import std.stdio;

void main() {

	writeln(__VERSION__);
}

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

void main() {

	int n = readln.strip.to!int;
	string s = readln.strip;

	foreach (from; 0 .. n) {
		if (s[from] != '.')
		foreach (jump; 1 .. n) {
			bool ok;
			foreach (i; 0 .. 5) {
				int pos = from + i * jump;
				if (pos >= n || s[pos] != '*') {
					writeln("break");
					ok = true;
					break;
				}
			}
			if (!ok)
				return write("yes");
		}
	}

	write("no");
}


Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.The game is played on the following field.  Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field.You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip.A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules.

First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers x and y (1 ≤ x, y ≤ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable.

Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified.

NoteIn the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field.In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell.In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable.

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

void main() {
    auto bd = new char[][](11, 11);
    bd.fillAll(' ');
    foreach (i ; 0 .. 11) {
        auto s = readln.chomp;
        if (i == 3 || i == 7) continue;
        bd[i][] = s.to!(char[]);
    }
    int x, y;
    scan(x, y);
    x--, y--;
    x %= 3;
    y %= 3;

    bool fc = 1;

    foreach (i ; x*4 .. x*4 + 3) {
        foreach (j ; y*4 .. y*4 + 3) {
            if (bd[i][j] == '.') {
                fc = 0;
                bd[i][j] = '!';
            }
        }
    }

    if (fc) {
        foreach (i ; 0 .. 11) {
            foreach (j ; 0 .. 11) {
                if (bd[i][j] == '.') {
                    bd[i][j] = '!';
                }
            }
        }
    }

    writefln("%(%(%c%)\n%)", bd);
}

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


You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).

The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100.

Output one number — length of the longest substring that can be met in the string at least twice.

module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string[] tk;
        string read_string() {
                while (tk.empty)
                        tk = readln.split;
                auto tkt = tk.front;
                tk.popFront;
                return tkt;
        }
        int read_int() {
                return read_string.to!int;
        }
        double read_double() {
                return read_string.to!double;
        }
}

int count_substr(char[] s, char[] sample) {
        int count = 0;
        for (int i = 0; i < s.length - sample.length + 1; i++) {
                if (s[i..i + sample.length] == sample) {
                        count++;
                }
        }
        return count;
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.read_int;
        while (t--) {
                char[] s = cin.read_string.dup;

                int l = s.length;
                int maxx = -999;
                for (int i = l - 1; i >= 1; i--) {
                        for (int j = 0; j < l - i + 1; j++) {
                                int c = count_substr(s, s[j..j + i]);
                                if (c >= 2) {
                                        writeln(s[j..j + i].length);
                                        return;
                                }
                        }
                }
                writeln(0);
        }
}

module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string[] tk;
        string read_string() {
                while (tk.empty)
                        tk = readln.split;
                auto tkt = tk.front;
                tk.popFront;
                return tkt;
        }
        int read_int() {
                return read_string.to!int;
        }
        double read_double() {
                return read_string.to!double;
        }
}

int count_substr(char[] s, char[] sample) {
        int count = 0;
        for (int i = 0; i < s.length - sample.length + 1; i++) {
                if (s[i..i + sample.length] == sample) {
                        count++;
                }
        }
        return count;
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.read_int;
        while (t--) {
                char[] s = cin.read_string.dup;

                int l = s.length;
                int maxx = -999;
                for (int i = l - 1; i >= 1; i--) {
                        for (int j = 0; j < l - i + 1; j++) {
                                int c = count_substr(s, s[j..j + i]);
                                if (c >= 2) {
                                        writeln(i);
                                        return;
                                }
                        }
                }
                writeln(0);
        }
}

import std.string, std.algorithm, std.stdio, std.range, std.array, std.typecons;

void main()
{
    auto s = readln.chomp;
    auto d = s.length.iota.retro.dropOne.map!(
         a => {
            string[] d = s.slide(a+1).map!"a.text".array;
            d.sort;
            return d.group.maxElement!"a[1]"; }()
    ).find!"a[1]>b[1]"(tuple(1,1));
    writeln(d.length>0?d[0][0].length:0);
}