The only difference between the easy and the hard version is the limit to the number of queries.This is an interactive problem.There is an array $$$a$$$ of $$$n$$$ different numbers. In one query you can ask the position of the second maximum element in a subsegment $$$a[l..r]$$$. Find the position of the maximum element in the array in no more than 20 queries.A subsegment $$$a[l..r]$$$ is all the elements $$$a_l, a_{l + 1}, ..., a_r$$$. After asking this subsegment you will be given the position of the second maximum from this subsegment in the whole array.

The first line contains a single integer $$$n$$$ $$$(2 \leq n \leq 10^5)$$$ — the number of elements in the array.

NoteIn the sample suppose $$$a$$$ is $$$[5, 1, 4, 2, 3]$$$. So after asking the $$$[1..5]$$$ subsegment $$$4$$$ is second to max value, and it's position is $$$3$$$. After asking the $$$[4..5]$$$ subsegment $$$2$$$ is second to max value and it's position in the whole array is $$$4$$$.Note that there are other arrays $$$a$$$ that would produce the same interaction, and the answer for them might be different. Example output is given in purpose of understanding the interaction.

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

string FMT_F = "%.10f";

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

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

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

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

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

	int l = 1, r = n;
	writeln("? ", l, " ", r);
	stdout.flush;
	auto m = RD!int;
	while (r - l > 1)
	{
		auto m2 = (l+r)/2;
		if (m <= m2)
		{
			auto ll = min(m, l);
			auto rr = m2;
			writeln("? ", ll, " ", rr);
			stdout.flush;
			auto a = RD!int;
			if (a == m)
				r = m2;
			else
				l = m2;
		}
		else
		{
			auto ll = m2;
			auto rr = max(m, r);
			writeln("? ", ll, " ", rr);
			stdout.flush;
			auto a = RD!int;
			if (a == m)
				l = m2;
			else
				r = m2;
		}
	}

	writeln("? ", l, " ", r);
	stdout.flush;
	m = RD!int;
	if (m == l)
		writeln("! ", r);
	else
		writeln("! ", l);
	stdout.flush;
	debug readln;
}

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

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

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

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

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

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

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

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

void main()
{
    int N; get(N);
    writefln!"? %d %d"(1, N); stdout.flush();
    int p; get(p);
    int q;
    if (p == 1) {
        q = -1;
    } else if (p == N) {
        q = N;
    } else {
        writefln!"? %d %d"(1, p); stdout.flush();
        get(q);
    }
    if (p == q) {
        int l = 1, r = p;
        while (l + 1 < r) {
            auto m = (l + r) / 2;
            writefln!"? %d %d"(m, p); stdout.flush();
            get(q);
            if (p == q) {
                l = m;
            } else {
                r = m;
            }
        }
        writeln("! ", l); stdout.flush();
    } else {
        int l = p, r = N;
        while (l + 1 < r) {
            auto m = (l + r) / 2;
            writefln!"? %d %d"(p, m); stdout.flush();
            get(q);
            if (p == q) {
                r = m;
            } else {
                l = m;
            }
        }
        writeln("! ", r); stdout.flush();
    }
}

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

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

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

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

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

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

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

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

void main()
{
    int N; get(N);
    writefln!"? %d %d"(1, N); stdout.flush();
    int p; get(p);
    writefln!"? %d %d"(1, p); stdout.flush();
    int q; get(q);
    if (p == q) {
        int l = 1, r = p;
        while (l + 1 < r) {
            auto m = (l + r) / 2;
            writefln!"? %d %d"(m, p); stdout.flush();
            get(q);
            if (p == q) {
                l = m;
            } else {
                r = m;
            }
        }
        writeln("! ", l); stdout.flush();
    } else {
        int l = p, r = N;
        while (l + 1 < r) {
            auto m = (l + r) / 2;
            writefln!"? %d %d"(p, m); stdout.flush();
            get(q);
            if (p == q) {
                r = m;
            } else {
                l = m;
            }
        }
        writeln("! ", r); stdout.flush();
    }
}


You have decided to watch the best moments of some movie. There are two buttons on your player:   Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie.  Skip exactly x minutes of the movie (x is some fixed positive integer). If the player is now at the t-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (t + x). Initially the movie is turned on in the player on the first minute, and you want to watch exactly n best moments of the movie, the i-th best moment starts at the li-th minute and ends at the ri-th minute (more formally, the i-th best moment consists of minutes: li, li + 1, ..., ri). Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments?

The first line contains two space-separated integers n, x (1 ≤ n ≤ 50, 1 ≤ x ≤ 105) — the number of the best moments of the movie and the value of x for the second button. The following n lines contain the descriptions of the best moments of the movie, the i-th line of the description contains two integers separated by a space li, ri (1 ≤ li ≤ ri ≤ 105). It is guaranteed that for all integers i from 2 to n the following condition holds: ri - 1 < li.

Output a single number — the answer to the problem.

NoteIn the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 4-th to the 6-th minute, after that the current time is 7. Similarly, we again skip 3 minutes and then watch from the 10-th to the 12-th minute of the movie. In total, we watch 6 minutes of the movie.In the second sample, the movie is very interesting, so you'll have to watch all 100000 minutes of the movie.

import std.stdio;

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

int main(string[] args)
{
    int n = read!int;
    int x = read!int;

    int curr = 1;
    int ans = 0;
    foreach (i; 0..n)
    {
        int l = read!int;
        int r = read!int;

        while (curr + x <= l)
        {
            curr += x;
        }

        ans += r - curr + 1;
        curr = r + 1;
    }

    writeln(ans);

    return 0;
}

import std.stdio;

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

int main(string[] args)
{
    int n = read!int;
    int x = read!int;

    int curr = 1;
    int ans = 0;
    foreach (i; 0..n)
    {
        int l = read!int;
        int r = read!int;

        while (curr + x <= l)
            curr += x;

        ans += r - curr + 1;
    }

    writeln(ans);

    return 0;
}


There are $$$n$$$ traps numbered from $$$1$$$ to $$$n$$$. You will go through them one by one in order. The $$$i$$$-th trap deals $$$a_i$$$ base damage to you.Instead of going through a trap, you can jump it over. You can jump over no more than $$$k$$$ traps. If you jump over a trap, it does not deal any damage to you. But there is an additional rule: if you jump over a trap, all next traps damages increase by $$$1$$$ (this is a bonus damage).Note that if you jump over a trap, you don't get any damage (neither base damage nor bonus damage). Also, the bonus damage stacks so, for example, if you go through a trap $$$i$$$ with base damage $$$a_i$$$, and you have already jumped over $$$3$$$ traps, you get $$$(a_i + 3)$$$ damage.You have to find the minimal damage that it is possible to get if you are allowed to jump over no more than $$$k$$$ traps.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le k \le n$$$) — the number of traps and the number of jump overs that you are allowed to make. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — base damage values of all traps. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case output a single integer — the minimal total damage that it is possible to get if you are allowed to jump over no more than $$$k$$$ traps.

NoteIn the first test case it is allowed to jump over all traps and take $$$0$$$ damage.In the second test case there are $$$5$$$ ways to jump over some traps:  Do not jump over any trap.Total damage: $$$5 + 10 + 11 + 5 = 31$$$. Jump over the $$$1$$$-st trap.Total damage: $$$\underline{0} + (10 + 1) + (11 + 1) + (5 + 1) = 29$$$. Jump over the $$$2$$$-nd trap.Total damage: $$$5 + \underline{0} + (11 + 1) + (5 + 1) = 23$$$. Jump over the $$$3$$$-rd trap.Total damage: $$$5 + 10 + \underline{0} + (5 + 1) = 21$$$. Jump over the $$$4$$$-th trap.Total damage: $$$5 + 10 + 11 + \underline{0} = 26$$$.To get minimal damage it is needed to jump over the $$$3$$$-rd trap, so the answer is $$$21$$$.In the third test case it is optimal to jump over the traps $$$1$$$, $$$3$$$, $$$4$$$, $$$5$$$, $$$7$$$:Total damage: $$$0 + (2 + 1) + 0 + 0 + 0 + (2 + 4) + 0 = 9$$$.

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto res = a.sum (0L);
		auto b = n.iota.map !(i => n - 1 - i - a[i]).array;
		sort (b);
		res += b[0..k].sum (0L);
		res -= k * (k - 1L) / 2;
		writeln (res);
	}
}


Leslie and Leon entered a labyrinth. The labyrinth consists of $$$n$$$ halls and $$$m$$$ one-way passages between them. The halls are numbered from $$$1$$$ to $$$n$$$.Leslie and Leon start their journey in the hall $$$s$$$. Right away, they quarrel and decide to explore the labyrinth separately. However, they want to meet again at the end of their journey.To help Leslie and Leon, your task is to find two different paths from the given hall $$$s$$$ to some other hall $$$t$$$, such that these two paths do not share halls other than the staring hall $$$s$$$ and the ending hall $$$t$$$. The hall $$$t$$$ has not been determined yet, so you can choose any of the labyrinth's halls as $$$t$$$ except $$$s$$$.Leslie's and Leon's paths do not have to be the shortest ones, but their paths must be simple, visiting any hall at most once. Also, they cannot visit any common halls except $$$s$$$ and $$$t$$$ during their journey, even at different times.

The first line contains three integers $$$n$$$, $$$m$$$, and $$$s$$$, where $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) is the number of vertices, $$$m$$$ ($$$0 \le m \le 2 \cdot 10^5$$$) is the number of edges in the labyrinth, and $$$s$$$ ($$$1 \le s \le n$$$) is the starting hall. Then $$$m$$$ lines with descriptions of passages follow. Each description contains two integers $$$u_i$$$, $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$; $$$u_i \neq v_i$$$), denoting a passage from the hall $$$u_i$$$ to the hall $$$v_i$$$. The passages are one-way. Each tuple $$$(u_i, v_i)$$$ is present in the input at most once. The labyrinth can contain cycles and is not necessarily connected in any way.

If it is possible to find the desired two paths, output "Possible", otherwise output "Impossible". If the answer exists, output two path descriptions. Each description occupies two lines. The first line of the description contains an integer $$$h$$$ ($$$2 \le h \le n$$$) — the number of halls in a path, and the second line contains distinct integers $$$w_1, w_2, \dots, w_h$$$ ($$$w_1 = s$$$; $$$1 \le w_j \le n$$$; $$$w_h = t$$$) — the halls in the path in the order of passing. Both paths must end at the same vertex $$$t$$$. The paths must be different, and all intermediate halls in these paths must be distinct.

import std.stdio;
import std.container;
import std.typecons;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    int N, M, S; readf("%d %d %d\n", &N, &M, &S);
    S--;
    auto G = new int[][N];
    foreach (i; 0 .. M) {
        int U, V; readf("%d %d\n", &U, &V);
        U--; V--;
        G[U] ~= V;
    }

    int K = cast(int)(G[S].length);
    auto vis = new int[N]; vis[] = -1;
    int[] svs;
    int T;
    bool dfs(int v, int k) {
        if (v == S) return false;
        if (vis[v] >= 0 && vis[v] != k) {
            svs = [G[S][k], G[S][vis[v]]];
            T = v;
            return true;
        }
        vis[v] = k;
        foreach (nv; G[v]) {
            if (vis[nv] == k) continue;
            if ( dfs(nv, k) ) return true;
        }
        return false;
    }

    void show_path() {
        bool dfs(int v, ref int[] path, ref bool[] used) {
            if (v == S) return false;
            used[v] = true;
            if (v == T) {
                return true;
            }
            foreach (nv; G[v]) {
                if (used[nv]) continue;
                if (dfs(nv, path, used)) {
                    path ~= nv;
                    return true;
                }
            }
            return false;
        }
        int[] path_a, path_b;
        bool[] used_a = new bool[N];
        bool[] used_b = new bool[N];
        dfs(svs[0], path_a, used_a); path_a ~= svs[0]; path_a ~= S;
        dfs(svs[1], path_b, used_b); path_b ~= svs[1]; path_b ~= S;
        foreach (ref x; path_a) x++;
        foreach (ref x; path_b) x++;
        reverse(path_a);
        reverse(path_b);
        writeln(path_a.length);
        writefln("%(%s %)", path_a);
        writeln(path_b.length);
        writefln("%(%s %)", path_b);
    }

    for (int k = 0; k < K; k++) {
        int v = G[S][k];
        if (dfs(v, k)) {
            writeln("Possible");
            show_path();
            return;
        }
    }
    writeln("Impossible");
}

import std.stdio;
import std.container;
import std.typecons;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

void main() {
    int N, M, S; readf("%d %d %d\n", &N, &M, &S);
    S--;
    auto G = new int[][N];
    foreach (i; 0 .. M) {
        int U, V; readf("%d %d\n", &U, &V);
        U--; V--;
        G[U] ~= V;
    }

    int K = cast(int)(G[S].length);
    auto vis = new int[N]; vis[] = -1;
    int[] svs;
    int T;
    bool dfs(int v, int k) {
        if (vis[v] >= 0 && vis[v] != k) {
            svs = [G[S][k], G[S][vis[v]]];
            T = v;
            return true;
        }
        vis[v] = k;
        foreach (nv; G[v]) {
            if (vis[nv] == k) continue;
            if ( dfs(nv, k) ) return true;
        }
        return false;
    }

    void show_path() {
        bool dfs(int v, ref int[] path, ref bool[] used) {
            used[v] = true;
            if (v == T) {
                return true;
            }
            foreach (nv; G[v]) {
                if (used[nv]) continue;
                if (dfs(nv, path, used)) {
                    path ~= nv;
                    return true;
                }
            }
            return false;
        }
        int[] path_a, path_b;
        bool[] used_a = new bool[N];
        bool[] used_b = new bool[N];
        dfs(svs[0], path_a, used_a); path_a ~= svs[0]; path_a ~= S;
        dfs(svs[1], path_b, used_b); path_b ~= svs[1]; path_b ~= S;
        foreach (ref x; path_a) x++;
        foreach (ref x; path_b) x++;
        reverse(path_a);
        reverse(path_b);
        writeln(path_a.length);
        writefln("%(%s %)", path_a);
        writeln(path_b.length);
        writefln("%(%s %)", path_b);
    }

    for (int k = 0; k < K; k++) {
        int v = G[S][k];
        if (dfs(v, k)) {
            writeln("Possible");
            show_path();
            return;
        }
    }
    writeln("Impossible");
}


Shubham has an array $$$a$$$ of size $$$n$$$, and wants to select exactly $$$x$$$ elements from it, such that their sum is odd. These elements do not have to be consecutive. The elements of the array are not guaranteed to be distinct.Tell him whether he can do so.

The first line of the input contains a single integer $$$t$$$ $$$(1\le t \le 100)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ $$$(1 \le x \le n \le 1000)$$$ — the length of the array and the number of elements you need to choose. The next line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 1000)$$$ — elements of the array.

For each test case, print "Yes" or "No" depending on whether it is possible to choose $$$x$$$ elements such that their sum is odd. You may print every letter in any case you want.

NoteFor $$$1$$$st case: We must select element $$$999$$$, and the sum is odd.For $$$2$$$nd case: We must select element $$$1000$$$, so overall sum is not odd.For $$$3$$$rd case: We can select element $$$51$$$.For $$$4$$$th case: We must select both elements $$$50$$$ and $$$51$$$  — so overall sum is odd.For $$$5$$$th case: We must select all elements  — but overall sum is not odd.

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, x;
		readf !(" %s %s") (n, x);
		readln;
		auto s = readln.splitter.map !(to !(int)).array;
		auto odds = s.count !(q{a % 2 != 0}).to !(int);
		auto evens = s.length.to !(int) - odds;
		bool ok = false;
		foreach (i; 0..x + 1)
		{
			auto j = x - i;
			if (i <= odds && j <= evens)
			{
				if (i % 2 != 0)
				{
					ok = true;
				}
			}
		}
		writeln (ok ? "YES" : "NO");
	}
}

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

		long e, o;
		foreach (i; 0..n)
		{
			if (a[i] % 2)
				++o;
			else
				++e;
		}

		if (o == 0) continue;

		auto y = min(o, x);
		if (y % 2 == 0)
		{
			--y;
		}
		x -= y;
		ans[ti] = e >= x;
	}

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


You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones.Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$. You can apply the following operations any number of times:  Choose some substring of string $$$a$$$ (for example, you can choose entire string) and reverse it, paying $$$x$$$ coins for it (for example, «0101101» $$$\to$$$ «0111001»);  Choose some substring of string $$$a$$$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $$$y$$$ coins for it (for example, «0101101» $$$\to$$$ «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.What is the minimum number of coins you need to spend to get a string consisting only of ones?

The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $$$a$$$ of length $$$n$$$, consisting of zeros and ones.

Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations.

NoteIn the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$. Then the string was changed as follows:«01000» $$$\to$$$ «10000» $$$\to$$$ «11111».The total cost of operations is $$$1 + 10 = 11$$$.In the second sample, at first you need to invert substring $$$[1 \dots 1]$$$, and then you need to invert substring $$$[3 \dots 5]$$$. Then the string was changed as follows:«01000» $$$\to$$$ «11000» $$$\to$$$ «11111».The overall cost is $$$1 + 1 = 2$$$.In the third example, string already consists only of ones, so the answer is $$$0$$$.

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

void main ()
{
	int n, x, y;
	while (readf (" %s %s %s", &n, &x, &y) > 0)
	{
		readln;
		auto s = readln.strip ~ '1';
		auto k = n.iota.map !(i => s[i..i + 2] == "01").sum;
		long res = 0;
		if (k > 0)
		{
			res += y;
			k -= 1;
		}
		res += k * 1L * min (x, y);
		writeln (res);
	}
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const X = readLong();
      const Y = readLong();
      const A = readToken();

      long cnt;
      for (int i = 0, j; i < N; i = j) {
        for (j = i; j < N && A[i] == A[j]; ++j) {}
        if (A[i] == '0') {
          ++cnt;
        }
      }
      long ans;
      if (cnt >= 1) {
        ans += (cnt - 1) * min(X, Y);
        ans += Y;
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

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, x, y;
    readf("%s %s %s", &n, &x, &y);
    readln;

    auto s = readln.chomp;

    auto seg = cast(int)(s[0] == '0');
    foreach (a, b; lockstep(s, s.dropOne)) {
        if (a == '1' && b == '0') ++seg;
    }

    if (seg == 0) {
        writeln(0);
        return;
    }

    auto ans = min(cast(long)seg * y, cast(long)(seg - 1) * x + y);

    ans.writeln;
}

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, x, y;
    readf("%s %s %s", &n, &x, &y);
    readln;

    auto s = readln.chomp;

    auto seg = cast(int)(s[0] == '0');
    foreach (a, b; lockstep(s, s.dropOne)) {
        if (a == '1' && b == '0') ++seg;
    }

    auto ans = min(cast(long)seg * y, cast(long)(seg - 1) * x + y);

    ans.writeln;
}

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, x, y;
    readf("%s %s %s", &n, &x, &y);
    readln;

    auto s = readln.chomp;

    if (n == 1) {
        writeln(s[0] == '1' ? 0 : y);
        return;
    }

    auto seg = cast(int)(s[0] == '0');
    foreach (a, b; lockstep(s, s.dropOne)) {
        if (a == '1' && b == '0') ++seg;
    }

    auto ans = min(cast(long)seg * y, cast(long)(seg - 1) * x + y);

    ans.writeln;
}


You are given an integer array of length $$$n$$$.You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to $$$[x, x + 1, \dots, x + k - 1]$$$ for some value $$$x$$$ and length $$$k$$$.Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array $$$[5, 3, 1, 2, 4]$$$ the following arrays are subsequences: $$$[3]$$$, $$$[5, 3, 1, 2, 4]$$$, $$$[5, 1, 4]$$$, but the array $$$[1, 3]$$$ is not.

The first line of the input containing integer number $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the array. The second line of the input containing $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the array itself.

On the first line print $$$k$$$ — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.

NoteAll valid answers for the first example (as sequences of indices):   $$$[1, 3, 5, 6]$$$  $$$[2, 3, 5, 6]$$$ All valid answers for the second example:   $$$[1, 4]$$$  $$$[2, 5]$$$  $$$[3, 6]$$$ All valid answers for the third example:   $$$[1]$$$  $$$[2]$$$  $$$[3]$$$  $$$[4]$$$ All valid answers for the fourth example:   $$$[1, 2, 3, 7, 8, 9]$$$

import std.stdio, std.string;

void solve(int[] a, int n)
{
    auto dp = new int[n];
    auto prev = new int[n];
    int[int] pos;
    foreach (i; 0 .. n)
    {
        dp[i] = 1;
        prev[i] = -1;
        auto val = a[i] - 1;
        if (val in pos)
        {
            prev[i] = pos[val];
            dp[i] = dp[prev[i]] + 1;
        }
        pos[a[i]] = i;
    }
    auto best = 0, idx = -1;
    foreach (i; 0 .. n)
    {
        if (dp[i] > best)
        {
            best = dp[i];
            idx = i;
        }
    }
    writeln(best);
    auto ans = new int[best];
    foreach (i; 0 .. best)
    {
        ans[best - i - 1] = idx + 1;
        idx = prev[idx];
    }
    foreach (i; 0 .. best - 1)
    {
        write(ans[i], " ");
    }
    writeln(ans[best - 1]);
}

int main(string[] args)
{
    int n;
    while (readf("%d\n", &n) == 1)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a, n);
    }
    return 0;
}

import std.stdio, std.string;

void solve(int[] a, int n)
{
    auto dp = new int[n];
    auto prev = new int[n];
    int[int] pos;
    foreach (i; 0 .. n)
    {
        dp[i] = 1;
        prev[i] = -1;
        auto val = a[i] - 1;
        if (val in pos)
        {
            prev[i] = pos[val];
            dp[i] = dp[prev[i]] + 1;
        }
        pos[a[i]] = i;
    }
    auto best = 0, idx = -1;
    foreach (i; 0 .. n)
    {
        if (dp[i] > best)
        {
            best = dp[i];
            idx = i;
        }
    }
    auto ans = new int[best];
    foreach (i; 0 .. best)
    {
        ans[best - i - 1] = idx + 1;
        idx = prev[idx];
    }
    writeln(best);
    foreach (i; 0 .. best - 1)
    {
        write(ans[i], " ");
    }
    writeln(ans[best - 1]);
}

int main(string[] args)
{
    int n;
    while (readf("%d\n", &n) == 1)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a, n);
    }
    return 0;
}

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

void main()
{
    readln;

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

    int [int] v;
    a.each!(e => v[e] = max(v.get(e, 0), v.get(e-1, 0) + 1));

    debug { writeln(v); }

    auto p = v.byKeyValue().maxElement!(q{ a.value });
    auto st = p.key - p.value + 1;

    debug { writeln(st); }

    int [] ans;
    foreach (i, e; a.enumerate(1)) {
        if (e == st) {
            ++st;
            ans ~= i;
        }
    }

    writeln(ans.length);
    writefln("%(%s %)", ans);
}

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

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);

  int[int] b;
  foreach (i; 0..n) {
    if (a[i]-1 in b) b[a[i]] = b[a[i]-1]+1;
    else             b[a[i]] = 1;
  }

  auto c = -1, m = 0;
  foreach (k, v; b)
    if (v > m) {
      m = v;
      c = k;
    }

  writeln(m);

  auto d = c-m+1;
  foreach (i; 0..n)
    if (a[i] == d) {
      write(i+1, " ");
      ++d;
    }
  writeln;
}


Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path.Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine.Peter decided to tie his car to point P and now he is wondering what is the area of the region that will be cleared from snow. Help him.

The first line of the input contains three integers — the number of vertices of the polygon n (), and coordinates of point P. Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line. All the numbers in the input are integers that do not exceed 1 000 000 in their absolute value.

Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.  Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

NoteIn the first sample snow will be removed from that area:

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;

alias Point = Tuple !(real, q{x}, real, q{y});

real sp (Point a, Point b, Point c)
{
	return (b.x - a.x) * (c.x - a.x) + (b.y - a.y) * (c.y - a.y);
}

void main ()
{
	int n;
	Point p;
	while (readf (" %s %s %s", &n, &p.x, &p.y) > 0)
	{
		auto a = new Point [n];
		foreach (ref s; a)
		{
			readf (" %s %s", &s.x, &s.y);
		}
		auto d = a.map !(s => hypot (s.y - p.y, s.x - p.x)).array;
		real r1 = d.minPos.front;
		foreach (i; 0..n)
		{
			auto u = a[i];
			auto v = a[(i + 1) % n];
			auto ta = u.y - v.y;
			auto tb = v.x - u.x;
			auto tc = -(u.x * ta + u.y * tb);
			auto td = -(p.x * ta + p.y * tb);
			auto dis = ta ^^ 2 + tb ^^ 2;
			auto delta = (td - tc) / dis;
			auto w = Point (p.x + ta * delta, p.y + tb * delta);
			debug {writeln (u, " ", v, " ", w);}
			if (sp (w, u, v) < 0)
			{
				r1 = min (r1, hypot (w.y - p.y, w.x - p.x));
			}
		}
		real r2 = d.minPos !(q{a > b}).front;
		real res = PI * (r2 ^^ 2 - r1 ^^ 2);
		writefln ("%.20f", res);
	}
}

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

void main(string[] args)
{
  string input;
  readf!"%s"(input);
  auto words = input.split;
  debug writeln("words are = ", words);
  auto n = words[0].to!int;
  real[2] p;
  p[] = [words[1].to!real, words[2].to!real];
  auto polygon =  new real[2][](n);
  foreach(i, ref pi; polygon)
    pi = [words[3 + 2 * i].to!real, words[3 + 2 * i + 1].to!real];
  debug writeln("n = ", n, " p = ", p, " polygon = ", polygon);
  auto distances = polygon.map!(point => euclideanDistance([point[0], point[1]],
							   [p[0], p[1]])).array;
  auto minDistance = distances.fold!min;
  auto maxDistance = distances.fold!max;
  foreach(i, pi; polygon)
    {
      auto np = i + 1 >= polygon.length? polygon[0] : polygon[i + 1];
      real[2] d = [np[0] - pi[0], np[1] - pi[1]];
      auto t = (dotProduct(p, d) - dotProduct(pi, d)) / dotProduct(d, d);
      if (0 <= t && t <= 1)
	{
	  real[2] lp = [pi[0] + t * d[0], pi[1] + t * d[1]];
	  minDistance = min(minDistance, euclideanDistance(lp[], p[]));
	}
    }
  auto outerCircle = maxDistance * maxDistance * PI;
  auto innerCircle = minDistance * minDistance * PI;
  auto res = outerCircle - innerCircle;
  stdout.writefln!"%.20s"(res);
}

static this()
{
}

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

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

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

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

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

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

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

void main(string[] args)
{
  string input;
  readf!"%s"(input);
  auto words = input.split;
  auto n = words[0].to!int;
  real[2] p;
  p[] = [words[1].to!real, words[2].to!real];
  auto polygon =  new real[2][](n);
  foreach(i, ref pi; polygon) pi = [words[3 + 2 * i].to!real, words[3 + 2 * i + 1].to!real];

  auto minDistance = iota(0, n)
    .map!(i => segmentPointDistance(p, polygon[i], polygon[(i + 1)%n]))
    .fold!min;
  auto maxDistance = polygon
    .map!(point => euclideanDistance(point[], p[]))
    .fold!max;
  auto outerCircle = maxDistance * maxDistance * PI;
  auto innerCircle = minDistance * minDistance * PI;
  stdout.writefln!"%.20s"(outerCircle - innerCircle);
}

auto segmentPointDistance(T)(T p, T a, T b)
{
  real[2] d = [b[0] - a[0], b[1] - a[1]];
  auto t = (dotProduct(p, d) - dotProduct(a, d)) / dotProduct(d, d);
  if (0 <= t && t <= 1)
    {
      real[2] lp = [a[0] + t * d[0], a[1] + t * d[1]];
      return euclideanDistance(lp[], p[]);
    }
  else
    {
      return min(euclideanDistance(a[], p[]), euclideanDistance(b[], p[]));
    }
}

static this()
{
}

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

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

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

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

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

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

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

void main(string[] args)
{
  string input;
  readf!"%s"(input);
  auto words = input.split;
  auto n = words[0].to!int;
  real[2] p; p[] = [words[1].to!real, words[2].to!real];
  auto polygon =  new real[2][](n);
  foreach(i, ref pi; polygon) pi = [words[3 + 2 * i].to!real, words[3 + 2 * i + 1].to!real];
  auto minMax = iota(0, n)
    .map!(i => segmentPointDistance(p, polygon[i], polygon[(i + 1)%n]),
	  i => euclideanDistance(p[], polygon[i][]))
    .fold!((minmax, x) => tuple(min(minmax[0], x[0]), max(minmax[1], x[1])));
  auto minDistance = minMax[0];
  auto maxDistance = minMax[1];
  auto outerCircle = maxDistance * maxDistance * PI;
  auto innerCircle = minDistance * minDistance * PI;
  stdout.writefln!"%.20s"(outerCircle - innerCircle);
}

auto segmentPointDistance(T)(T p, T a, T b)
{
  real[2] d = [b[0] - a[0], b[1] - a[1]];
  auto t = (dotProduct(p, d) - dotProduct(a, d)) / dotProduct(d, d);
  if (0 <= t && t <= 1)
    {
      real[2] lp = [a[0] + t * d[0], a[1] + t * d[1]];
      return euclideanDistance(lp[], p[]);
    }
  else
    {
      return min(euclideanDistance(a[], p[]), euclideanDistance(b[], p[]));
    }
}

static this()
{
}

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

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

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

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

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

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

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;

alias Point = Tuple !(real, q{x}, real, q{y});

void main ()
{
	int n;
	Point p;
	while (readf (" %s %s %s", &n, &p.x, &p.y) > 0)
	{
		auto a = new Point [n];
		foreach (ref s; a)
		{
			readf (" %s %s", &s.x, &s.y);
		}
		auto d = a.map !(s => hypot (s.y - p.y, s.x - p.x)).array;
		real r1 = d.minPos.front;
		real r2 = d.minPos !(q{a > b}).front;
		real res = PI * (r2 ^^ 2 - r1 ^^ 2);
		writefln ("%.20f", res);
	}
}

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

alias Point = Tuple !(real, q{x}, real, q{y});

real sp (Point a, Point b, Point c)
{
	return (b.x - a.x) * (c.x - a.x) + (b.y - a.y) * (c.y - a.y);
}

void main ()
{
	int n;
	Point p;
	while (readf (" %s %s %s", &n, &p.x, &p.y) > 0)
	{
		auto a = new Point [n];
		foreach (ref s; a)
		{
			readf (" %s %s", &s.x, &s.y);
		}
		auto d = a.map !(s => hypot (s.y - p.y, s.x - p.x)).array;
		real r1 = d.minPos.front;
		foreach (i; 0..n)
		{
			auto u = a[i];
			auto v = a[(i + 1) % n];
			auto ta = u.y - v.y;
			auto tb = v.x - u.x;
			auto tc = -(u.x * ta + u.y * tb);
			auto td = -(p.x * ta + p.y * tb);
			auto dis = ta ^^ 2 + tb ^^ 2;
			auto delta = (td - tc) / dis;
			auto w = Point (p.x + ta * delta, p.y + tb * delta);
			debug {writeln (u, " ", v, " ", w);}
			if (sp (w, u, v) < 0)
			{
				r1 = min (r1, delta);
			}
		}
		real r2 = d.minPos !(q{a > b}).front;
		real res = PI * (r2 ^^ 2 - r1 ^^ 2);
		writefln ("%.20f", res);
	}
}

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

void main(string[] args)
{
  string input;
  readf!"%s"(input);
  auto words = input.split;
  debug writeln("words are = ", words);
  auto n = words[0].to!int;
  real[2] p;
  p[] = [words[1].to!real, words[2].to!real];
  auto polygon =  new real[2][](n);
  foreach(i, ref pi; polygon)
    pi = [words[3 + 2 * i].to!real, words[3 + 2 * i + 1].to!real];
  debug writeln("n = ", n, " p = ", p, " polygon = ", polygon);
  auto distances = polygon.map!(point => euclideanDistance([point[0], point[1]],
							   [p[0], p[1]])).array;
  auto minDistance = distances.fold!min;
  auto maxDistance = distances.fold!max;
  auto outerCircle = maxDistance * maxDistance * PI;
  auto innerCircle = minDistance * minDistance * PI;
  println(outerCircle - innerCircle);
}

static this()
{
}

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

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

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

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

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

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

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

void main(string[] args)
{
  string input;
  readf!"%s"(input);
  auto words = input.split;
  debug writeln("words are = ", words);
  auto n = words[0].to!int;
  real[2] p;
  p[] = [words[1].to!real, words[2].to!real];
  auto polygon =  new real[2][](n);
  foreach(i, ref pi; polygon)
    pi = [words[3 + 2 * i].to!real, words[3 + 2 * i + 1].to!real];
  debug writeln("n = ", n, " p = ", p, " polygon = ", polygon);
  auto distances = polygon.map!(point => euclideanDistance([point[0], point[1]],
							   [p[0], p[1]])).array;
  auto minDistance = distances.fold!min;
  auto maxDistance = distances.fold!max;
  auto outerCircle = maxDistance * maxDistance * PI;
  auto innerCircle = minDistance * minDistance * PI;
  auto res = outerCircle - innerCircle;
  stdout.writefln!"%.20s"(res);
}

static this()
{
}

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

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

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

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

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

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


You are given a binary matrix $$$a$$$ of size $$$n \times m$$$. A binary matrix is a matrix where each element is either $$$0$$$ or $$$1$$$.You may perform some (possibly zero) operations with this matrix. During each operation you can inverse the row of this matrix or a column of this matrix. Formally, inverting a row is changing all values in this row to the opposite ($$$0$$$ to $$$1$$$, $$$1$$$ to $$$0$$$). Inverting a column is changing all values in this column to the opposite.Your task is to sort the initial matrix by some sequence of such operations. The matrix is considered sorted if the array $$$[a_{1, 1}, a_{1, 2}, \dots, a_{1, m}, a_{2, 1}, a_{2, 2}, \dots, a_{2, m}, \dots, a_{n, m - 1}, a_{n, m}]$$$ is sorted in non-descending order.

The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 200$$$) — the number of rows and the number of columns in the matrix. The next $$$n$$$ lines contain $$$m$$$ integers each. The $$$j$$$-th element in the $$$i$$$-th line is $$$a_{i, j}$$$ ($$$0 \le a_{i, j} \le 1$$$) — the element of $$$a$$$ at position $$$(i, j)$$$.

If it is impossible to obtain a sorted matrix, print "NO" in the first line. Otherwise print "YES" in the first line. In the second line print a string $$$r$$$ of length $$$n$$$. The $$$i$$$-th character $$$r_i$$$ of this string should be '1' if the $$$i$$$-th row of the matrix is inverted and '0' otherwise. In the third line print a string $$$c$$$ of length $$$m$$$. The $$$j$$$-th character $$$c_j$$$ of this string should be '1' if the $$$j$$$-th column of the matrix is inverted and '0' otherwise. If there are multiple answers, you can print any.

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

string [] solve (int rows, int cols, bool [] [] a)
{
	auto ir = new bool [rows];
	auto ic = new bool [cols];

	bool elem (int row, int col)
	{
		return a[row][col] ^ ir[row] ^ ic[col];
	}

	foreach (t; 0..2)
	{
		foreach (z; 0..cols + 1)
		{
			foreach (col; 0..cols)
			{
				if (elem (0, col) != (col >= z))
				{
					ic[col] ^= true;
				}
			}

			bool already = elem (0, cols - 1);
			foreach (row; 1..rows)
			{
				if (!already && elem (row, 0))
				{
					ir[row] ^= true;
				}
				if (!isSorted (cols.iota.map !(col =>
				    elem (row, col))))
				{
					ir[row] ^= true;
				}
				if (already && !elem (row, 0))
				{
					ir[row] ^= true;
				}
				already |= elem (row, cols - 1);
			}
			debug {writefln ("%-(%(%d%)\n%)\n", rows.iota.map
			    !(row => cols.iota.map
			    !(col => elem (row, col))));}

			bool prev = false;
			bool ok = true;
checkLoop:
			foreach (row; 0..rows)
			{
				foreach (col; 0..cols)
				{
					if (prev > elem (row, col))
					{
						ok = false;
						break checkLoop;
					}
					prev = elem (row, col);
				}
			}
			if (ok)
			{
				string [] res;
				res ~= "YES";
				res ~= ir.map !(x => "01"[x]).array.text;
				res ~= ic.map !(x => "01"[x]).array.text;
				return res;
			}
		}
		ir[0] ^= true;
	}
	return ["NO"];
}

void main ()
{
	int rows, cols;
	while (readf (" %s %s", &rows, &cols) > 0)
	{
		readln;
		bool [] [] a;
		foreach (row; 0..rows)
		{
			a ~= readln.splitter.map !(x => x == "1").array;
		}
		writefln ("%-(%s\n%)", solve (rows, cols, a));
	}
}


A root tree is a directed acyclic graph that contains one node (root), from which there is exactly one path to any other node.A root tree is binary if each node has at most two outgoing arcs.When a binary tree is painted on the plane, all arcs should be directed from top to bottom. That is, each arc going from u to v must meet the condition yu > yv.You've been given the coordinates of all tree nodes. Your task is to connect these nodes by arcs so as to get the binary root tree and make the total length of the arcs minimum. All arcs of the built tree must be directed from top to bottom.

The first line contains a single integer n (2 ≤ n ≤ 400) — the number of nodes in the tree. Then follow n lines, two integers per line: xi, yi (|xi|, |yi| ≤ 103) — coordinates of the nodes. It is guaranteed that all points are distinct.

If it is impossible to build a binary root tree on the given points, print "-1". Otherwise, print a single real number — the total length of the arcs in the minimum binary tree. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.

import std.algorithm;
import std.container;
import std.math;
import std.stdio;
import std.typecons;

immutable int MAX_V = 805;
immutable double MAX_L = 1E20;

alias Tuple !(int, "x", int, "y") Point;

int [MAX_V] [MAX_V] f;
int [MAX_V] [MAX_V] h;
double [MAX_V] [MAX_V] g;
int m, n, s, t;

double rho (Point a, Point b)
{
	return sqrt (cast (double) ((a.x - b.x) ^^ 2 + (a.y - b.y) ^^ 2));
}

double flow ()
{
	auto b = new bool [m];
	auto d = new double [m];
	d[] = MAX_L;
	auto p = new int [m];
	auto q = [s];
	b[s] = true;
	d[s] = 0.0;
	while (q.length > 0)
	{
		auto i = q[0];
		q = q[1..$];
		b[i] = false;
		debug {writefln ("%s %s", i, d[i]);}
		debug {writefln ("%s", f[i]);}
		debug {writefln ("%s", h[i]);}
		debug {writefln ("%s", g[i]);}
		foreach (j; 0..m)
		{
			if (f[i][j] < h[i][j])
			{
				if (d[j] > d[i] + g[i][j])
				{
					d[j] = d[i] + g[i][j];
					p[j] = i;
					if (!b[j])
					{
						debug {writefln ("->%s", j);}
						q ~= j;
						b[j] = true;
					}
				}
			}
		}
		foreach (j; 0..m)
		{
			if (f[j][i] > 0)
			{
				if (d[j] > d[i] + g[i][j])
				{
					d[j] = d[i] + g[i][j];
					p[j] = i;
					if (!b[j])
					{
						debug {writefln ("->%s", j);}
						q ~= j;
						b[j] = true;
					}
				}
			}
		}
	}
	if (d[t] == MAX_L)
	{
		return -1;
	}
	double res = 0;
	int i = t;
	do
	{
		debug {writefln ("%s %s %s %s", i, p[i],
		                 f[p[i]][i], g[p[i]][i]);}
		if (h[p[i]][i] > 0)
		{
			f[p[i]][i]++;
		}
		else
		{
			f[i][p[i]]--;
		}
		res += g[p[i]][i];
		i = p[i];
	}
	while (i != s);
	return res;
}

void main ()
{
	while (readf (" %s", &n) > 0)
	{
		auto p = new Point [n];
		foreach (i; 0..n)
		{
			readf (" %s %s", &p[i].x, &p[i].y);
		}
		s = n + n;
		t = s + 1;
		m = t + 1;
		foreach (i; 0..m)
		{
			foreach (j; 0..m)
			{
				f[i][j] = 0;
				h[i][j] = 0;
				g[i][j] = 0.0;
			}
		}
		foreach (i; 0..n)
		{
			int u = i * 2 + 0;
			foreach (j; 0..n)
			{
				int v = j * 2 + 1;
				if (p[i].y > p[j].y)
				{
					g[u][v] = rho (p[i], p[j]);
					g[v][u] = -g[u][v];
					h[u][v] = 1;
				}
			}
		}
		foreach (i; 0..n)
		{
			int u = i * 2;
			h[s][u + 0] = 2;
			h[u + 1][t] = 1;
		}
		double res = 0;
		foreach (i; 0..n - 1)
		{
			double cur = flow ();
			if (cur == -1)
			{
				res = -1;
				break;
			}
			res += cur;
		}
		writefln ("%.10f", res);
	}
}

import std.algorithm;
import std.container;
import std.math;
import std.stdio;
import std.typecons;

immutable int MAX_V = 805;
immutable double MAX_L = 1E20;

alias Tuple !(int, "x", int, "y") Point;

int [MAX_V] [MAX_V] f;
int [MAX_V] [MAX_V] h;
double [MAX_V] [MAX_V] g;
int m, n, s, t;

double rho (Point a, Point b)
{
	return sqrt (cast (double) ((a.x - b.x) ^^ 2 + (a.y - b.y) ^^ 2));
}

double flow ()
{
	auto b = new bool [m];
	auto d = new double [m];
	d[] = MAX_L;
	auto p = new int [m];
	auto q = [s];
	b[s] = true;
	d[s] = 0.0;
	while (q.length > 0)
	{
		auto i = q[0];
		q = q[1..$];
		b[i] = false;
		debug {writefln ("%s %s", i, d[i]);}
		debug {writefln ("%s", f[i]);}
		debug {writefln ("%s", h[i]);}
		debug {writefln ("%s", g[i]);}
		foreach (j; 0..m)
		{
			if (f[i][j] < h[i][j])
			{
				if (d[j] > d[i] + g[i][j])
				{
					d[j] = d[i] + g[i][j];
					p[j] = i;
					if (!b[j])
					{
						debug {writefln ("->%s", j);}
						q ~= j;
						b[j] = true;
					}
				}
			}
		}
		foreach (j; 0..m)
		{
			if (f[j][i] > 0)
			{
				if (d[j] > d[i] + g[i][j])
				{
					d[j] = d[i] + g[i][j];
					p[j] = i;
					if (!b[j])
					{
						debug {writefln ("->%s", j);}
						q ~= j;
						b[j] = true;
					}
				}
			}
		}
	}
	if (d[t] == MAX_L)
	{
		return -1;
	}
	double res = 0;
	int i = t;
	do
	{
		debug {writefln ("%s %s %s %s", i, p[i],
		                 f[p[i]][i], g[p[i]][i]);}
		f[p[i]][i]++;
		res += g[p[i]][i];
		i = p[i];
	}
	while (i != s);
	return res;
}

void main ()
{
	while (readf (" %s", &n) > 0)
	{
		auto p = new Point [n];
		foreach (i; 0..n)
		{
			readf (" %s %s", &p[i].x, &p[i].y);
		}
		s = n + n;
		t = s + 1;
		m = t + 1;
		foreach (i; 0..m)
		{
			foreach (j; 0..m)
			{
				f[i][j] = 0;
				h[i][j] = 0;
				g[i][j] = 0.0;
			}
		}
		foreach (i; 0..n)
		{
			int u = i * 2 + 0;
			foreach (j; 0..n)
			{
				int v = j * 2 + 1;
				if (p[i].y > p[j].y)
				{
					g[u][v] = rho (p[i], p[j]);
					g[v][u] = -g[u][v];
					h[u][v] = 1;
				}
			}
		}
		foreach (i; 0..n)
		{
			int u = i * 2;
			h[s][u + 0] = 2;
			h[u + 1][t] = 1;
		}
		double res = 0;
		foreach (i; 0..n - 1)
		{
			double cur = flow ();
			if (cur == -1)
			{
				res = -1;
				break;
			}
			res += cur;
		}
		writefln ("%.10f", res);
	}
}

import std.algorithm;
import std.container;
import std.math;
import std.stdio;
import std.typecons;

immutable int MAX_V = 805;
immutable double MAX_L = 1E20;

alias Tuple !(int, "x", int, "y") Point;

int [MAX_V] [MAX_V] f;
int [MAX_V] [MAX_V] h;
double [MAX_V] [MAX_V] g;
int m, n, s, t;

double rho (Point a, Point b)
{
	return sqrt (cast (double) ((a.x - b.x) ^^ 2 + (a.y - b.y) ^^ 2));
}

double flow ()
{
	auto b = new bool [m];
	auto d = new double [m];
	d[] = MAX_L;
	auto p = new int [m];
	auto q = [s];
	b[s] = true;
	d[s] = 0.0;
	while (q.length > 0)
	{
		auto i = q[0];
		q = q[1..$];
		b[i] = false;
		debug {writefln ("%s %s", i, d[i]);}
		debug {writefln ("%s", f[i]);}
		debug {writefln ("%s", h[i]);}
		debug {writefln ("%s", g[i]);}
		foreach (j; 0..m)
		{
			if (f[i][j] < h[i][j])
			{
				if (d[j] > d[i] + g[i][j])
				{
					d[j] = d[i] + g[i][j];
					p[j] = i;
					if (!b[j])
					{
						debug {writefln ("->%s", j);}
						q ~= j;
						b[j] = true;
					}
				}
			}
		}
		foreach (j; 0..m)
		{
			if (f[j][i] > 0)
			{
				if (d[j] > d[i] + g[i][j])
				{
					d[j] = d[i] + g[i][j];
					p[j] = i;
					if (!b[j])
					{
						debug {writefln ("->%s", j);}
						q ~= j;
						b[j] = true;
					}
				}
			}
		}
	}
	if (d[t] == MAX_L)
	{
		return -1;
	}
	double res = 0;
	int i = t;
	do
	{
		debug {writefln ("%s %s %s %s", i, p[i],
		                 f[p[i]][i], g[p[i]][i]);}
		f[p[i]][i]++;
		res += g[p[i]][i];
		i = p[i];
	}
	while (i != s);
	return res;
}

void main ()
{
	while (readf (" %s", &n) > 0)
	{
		auto p = new Point [n];
		foreach (i; 0..n)
		{
			readf (" %s %s", &p[i].x, &p[i].y);
		}
		s = n + n;
		t = s + 1;
		m = t + 1;
		foreach (i; 0..m)
		{
			foreach (j; 0..m)
			{
				f[i][j] = 0;
				h[i][j] = 0;
				g[i][j] = 0.0;
			}
		}
		foreach (i; 0..n)
		{
			int u = i * 2 + 0;
			foreach (j; 0..n)
			{
				int v = j * 2 + 1;
				if (p[i].y > p[j].y)
				{
					g[u][v] = rho (p[i], p[j]);
					g[v][u] = -f[u][v];
					h[u][v] = 1;
				}
			}
		}
		foreach (i; 0..n)
		{
			int u = i * 2;
			h[s][u + 0] = 2;
			h[u + 1][t] = 1;
		}
		double res = 0;
		foreach (i; 0..n - 1)
		{
			double cur = flow ();
			if (cur == -1)
			{
				res = -1;
				break;
			}
			res += cur;
		}
		writefln ("%.10f", res);
	}
}


Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?

Output one integer  — the maximum number of breaks.

NoteIn the first sample Vasya can take $$$3$$$ breaks starting after $$$2$$$, $$$5$$$ and $$$8$$$ minutes after the beginning of the day.In the second sample Vasya can take $$$2$$$ breaks starting after $$$0$$$ and $$$2$$$ minutes after the beginning of the day.In the third sample Vasya can't take any breaks.

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

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split;
    auto N = s[0].to!int;
    auto L = s[1].to!long;
    auto A = s[2].to!long;
    long[] T, X;
    foreach (i; 0..N) {
        s = readln.split;
        T ~= s[0].to!long;
        X ~= s[1].to!long;
    }
    T ~= L;
    X ~= 0;

    long t = 0;
    long ans = 0;

    foreach (i; 0..N+1) {
        long interaval = T[i] - t;
        ans += interaval / A;
        t = T[i] + X[i];
    }

    ans.writeln;
}

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

  int n, l, a;
  rd(n, l, a);
  auto s = new int[](n), t = new int[](n);
  foreach (i; 0 .. n)
    rd(s[i], t[i]);

  long cnt = 0;
  foreach (i; 1 .. n) {
    cnt += (s[i] - (s[i - 1] + t[i - 1])) / a;
  }
  if (n > 0) {
    cnt += (s[0]) / a;
    cnt += (l - (s[$ - 1] + t[$ - 1])) / a;
  } else {
    cnt += l / a;
  }
  writeln(cnt);
}

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

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