Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. Limak knows it will take him 5·i minutes to solve the i-th problem.Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs k minutes to get there from his house, where he will participate in the contest first.How many problems can Limak solve if he wants to make it to the party?

The only line of the input contains two integers n and k (1≤n≤10, 1≤k≤240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.

Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.

In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5+10=15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.
In the second sample, Limak can solve all 4 problems in 5+10+15+20=50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems.


Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle... Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll. Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.You can only rotate the hands forward, that is, as is shown in the picture:  As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.

The only line of input contains current time according to the digital clock, formatted as HH:MM (00≤HH≤23, 00≤MM≤59). The mantel clock initially shows 12:00.
Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.

Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0≤x,y<360). The absolute or relative error in the answer should not exceed 10^-9.

A note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.


#!/usr/bin/perl
use bigint;
chomp($n=<>);
my @array=qw (Sheldon Leonard Penny Rajesh Howard);
$i=1;
$c=$i*5;
while ($c<$n){
$n-=$i*5;
$i=$i*2;
}
$n = $n%($i*5);
$n -=1;
$n=($n-($n%$i)/$i);
print ($array[$n]);

Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.Write a program that will print the name of a man who will drink the n-th can.Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.

The input data consist of a single integer n (1≤n≤10^9).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.

Print the single line — the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.

use strict;
use warnings;

my @names = qw (Sheldon Leonard Penny Rajesh Howard);
my $n = <>;
my $curr = 5;
my $sum = 5;
while ($sum < $n) {
    $curr *= 2;
    $sum += $curr;
}

my $cnt = 4;
while ($sum >= $n) {
    $cnt--;
    $sum -= $curr / 5;
}

print $names[$cnt+1]."\n";


Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical.Valera absolutely accidentally got a piece of ancient parchment on which an array of numbers was written. He immediately thought that the numbers in this array were not random. As a result of extensive research Valera worked out a wonderful property that a magical array should have: an array is defined as magic if its minimum and maximum coincide.He decided to share this outstanding discovery with you, but he asks you for help in return. Despite the tremendous intelligence and wit, Valera counts very badly and so you will have to complete his work. All you have to do is count the number of magical subarrays of the original array of numbers, written on the parchment. Subarray is defined as non-empty sequence of consecutive elements.

The first line of the input data contains an integer n (1≤n≤10^5). The second line contains an array of original integers a1,a2,...,an (-10^9≤ai≤10^9).

Print on the single line the answer to the problem: the amount of subarrays, which are magical.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator).

Notes to sample tests:
Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end.
In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3].
In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3].


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $y = join ' ',
	map {
		join ' ', 31, $_,
			qq{
			... Ð² Ð¼Ð°ÑÑÐµ 31 Ð´ÐµÐ½Ñ, Ð² Ð°Ð¿ÑÐµÐ»Ðµ 30 Ð´Ð½ÐµÐ¹,
			Ð² Ð¼Ð°Ðµ 31 Ð´ÐµÐ½Ñ, Ð² Ð¸ÑÐ½Ðµ 30 Ð´Ð½ÐµÐ¹, Ð² Ð¸ÑÐ»Ðµ 31 Ð´ÐµÐ½Ñ,
			Ð² Ð°Ð²Ð³ÑÑÑÐµ 31 Ð´ÐµÐ½Ñ, Ð² ÑÐµÐ½ÑÑÐ±ÑÐµ 30 Ð´Ð½ÐµÐ¹, Ð² Ð¾ÐºÑÑÐ±ÑÐµ 31 Ð´ÐµÐ½Ñ,
			Ð² Ð½Ð¾ÑÐ±ÑÐµ 30 Ð´Ð½ÐµÐ¹, Ð² Ð´ÐµÐºÐ°Ð±ÑÐµ 31 Ð´ÐµÐ½Ñ.
			} =~ /\d+/g
	} 28, 28, 29, 28;

while(<>){
	$_ = <>, chomp;

	print $y =~ /$_/ ? "Yes" : "No";
	}

Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.A year is leap in one of two cases: either its number is divisible by 4, but not divisible by 100, or is divisible by 400. For example, the following years are leap: 2000, 2004, but years 1900 and 2018 are not leap.In this problem you are given n (1≤n≤24) integers a1,a2,...,an, and you have to check if these integers could be durations in days of n consecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there is a month in some year, such that its duration is a1 days, duration of the next month is a2 days, and so on.

The first line contains single integer n (1≤n≤24) — the number of integers.
The second line contains n integers a1,a2,...,an (28≤ai≤31) — the numbers you are to check.

If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in arbitrary case (small or large).

In the first example the integers can denote months July, August, September and October.
In the second example the answer is no, because there are no two consecutive months each having 30 days.
In the third example the months are: February (leap year) — March — April – May — June.
In the fourth example the number of days in the second month is 28, so this is February. March follows February and has 31 days, but not 30, so the answer is NO.
In the fifth example the months are: December — January — February (non-leap year).

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $y = join ' ',
	map {
		join ' ', 31, $_,
			qq{
			... Ð² Ð¼Ð°ÑÑÐµ 31 Ð´ÐµÐ½Ñ, Ð² Ð°Ð¿ÑÐµÐ»Ðµ 30 Ð´Ð½ÐµÐ¹,
			Ð² Ð¼Ð°Ðµ 31 Ð´ÐµÐ½Ñ, Ð² Ð¸ÑÐ½Ðµ 30 Ð´Ð½ÐµÐ¹, Ð² Ð¸ÑÐ»Ðµ 31 Ð´ÐµÐ½Ñ,
			Ð² Ð°Ð²Ð³ÑÑÑÐµ 31 Ð´ÐµÐ½Ñ, Ð² ÑÐµÐ½ÑÑÐ±ÑÐµ 30 Ð´Ð½ÐµÐ¹, Ð² Ð¾ÐºÑÑÐ±ÑÐµ 31 Ð´ÐµÐ½Ñ,
			Ð² Ð½Ð¾ÑÐ±ÑÐµ 30 Ð´Ð½ÐµÐ¹, Ð² Ð´ÐµÐºÐ°Ð±ÑÐµ 31 Ð´ÐµÐ½Ñ.
			} =~ /\d+/g
	} 28, 28, 28, 29, 28, 28;

while(<>){
	$_ = <>, chomp;

	print $y =~ /$_/ ? "Yes" : "No";
	}


# Read input\nmy ($n, $m) = split(' ', <STDIN>);\nchomp(my $vertex_values = <STDIN>);\nmy @a = split(' ', $vertex_values);\nmy @special_offers;\n\n# Read special offers\nfor (my $i = 0; $i < $m; $i++) {\n    chomp(my $offer = <STDIN>);\n    my ($x, $y, $w) = split(' ', $offer);\n    push @special_offers, [$x, $y, $w];\n}\n\n# Sort special offers by cost in ascending order\n@special_offers = sort { $a->[2] <=> $b->[2] } @special_offers;\n\n# Initialize disjoint set data structure\nmy @parent = (0..$n);\nmy @rank = (0..$n);\n\n# Find operation for disjoint set data structure\nsub find {\n    my ($x) = @_;\n    if ($parent[$x] != $x) {\n        $parent[$x] = find($parent[$x]);\n    }\n    return $parent[$x];\n}\n\n# Union operation for disjoint set data structure\nsub union {\n    my ($x, $y) = @_;\n    my $x_root = find($x);\n    my $y_root = find($y);\n    if ($x_root == $y_root) {\n        return;\n    }\n    if ($rank[$x_root] < $rank[$y_root]) {\n        ($x_root, $y_root) = ($y_root, $x_root);\n    }\n    $parent[$y_root] = $x_root;\n    if ($rank[$x_root] == $rank[$y_root]) {\n        $rank[$x_root]++;\n    }\n}\n\n# Kruskal's algorithm to find minimum spanning tree\nmy $total_cost = 0;\nforeach my $offer (@special_offers) {\n    my ($x, $y, $w) = @$offer;\n    if (find($x) != find($y)) {\n        union($x, $y);\n        $total_cost += $w;\n    }\n}\n\n# Add remaining edges with their costs\nfor (my $i = 1; $i <= $n; $i++) {\n    for (my $j = $i + 1; $j <= $n; $j++) {\n        if (find($i) != find($j)) {\n            my $cost = $a[$i - 1] + $a[$j - 1];\n            $total_cost += $cost;\n            union($i, $j);\n        }\n    }\n}\n\n# Print the minimum number of coins required\nprint $total_cost;" }]

You are given an undirected graph consisting of $$$n$$$ vertices. A number is written on each vertex; the number on vertex $$$i$$$ is $$$a_i$$$. Initially there are no edges in the graph.You may add some edges to this graph, but you have to pay for them. The cost of adding an edge between vertices $$$x$$$ and $$$y$$$ is $$$a_x + a_y$$$ coins. There are also $$$m$$$ special offers, each of them is denoted by three numbers $$$x$$$, $$$y$$$ and $$$w$$$, and means that you can add an edge connecting vertices $$$x$$$ and $$$y$$$ and pay $$$w$$$ coins for it. You don't have to use special offers: if there is a pair of vertices $$$x$$$ and $$$y$$$ that has a special offer associated with it, you still may connect these two vertices paying $$$a_x + a_y$$$ coins for it.What is the minimum number of coins you have to spend to make the graph connected? Recall that a graph is connected if it's possible to get from any vertex to any other vertex using only the edges belonging to this graph.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$, $$$0 \\le m \\le 2 \\cdot 10^5$$$) — the number of vertices in the graph and the number of special offers, respectively.
The second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 10^{12}$$$) — the numbers written on the vertices.
Then $$$m$$$ lines follow, each containing three integers $$$x$$$, $$$y$$$ and $$$w$$$ ($$$1 \\le x, y \\le n$$$, $$$1 \\le w \\le 10^{12}$$$, $$$x \\ne y$$$) denoting a special offer: you may add an edge connecting vertex $$$x$$$ and vertex $$$y$$$, and this edge will cost $$$w$$$ coins.

Print one integer — the minimum number of coins you have to pay to make the graph connected.

#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(min);

sub find {
    my ($x, $parent) = @_;
    if ($parent->[$x] != $x) {
        $parent->[$x] = find($parent->[$x], $parent);
    }
    return $parent->[$x];
}

sub union {
    my ($x, $y, $parent, $rank) = @_;
    my $px = find($x, $parent);
    my $py = find($y, $parent);
    if ($px != $py) {
        if ($rank->[$px] > $rank->[$py]) {
            $parent->[$py] = $px;
        } else {
            $parent->[$px] = $py;
            if ($rank->[$px] == $rank->[$py]) {
                $rank->[$py]++;
            }
        }
    }
}

my ($n, $m) = split / /, <>;
my @a = split / /, <>;
my @parent = (0..$n);
my @rank = (0) x ($n+1);
my @edges;
my $min_a = min @a;
my $min_i = 0;
for my $i (0..$#a) {
    if ($a[$i] == $min_a) {
        $min_i = $i;
        last;
    }
}
for my $i (0..$#a) {
    if ($i != $min_i) {
        push @edges, [$min_i+1, $i+1, $min_a + $a[$i]];
    }
}
for my $i (0..$m-1) {
    my ($x, $y, $w) = split / /, <>;
    push @edges, [$x, $y, $w];
}
@edges = sort {$a->[2] <=> $b->[2]} @edges;
my $res = 0;
for my $edge (@edges) {
    my ($x, $y, $w) = @$edge;
    if (find($x, \@parent) != find($y, \@parent)) {
        union($x, $y, \@parent, \@rank);
        $res += $w;
    }
}
print "$res\n";


use strict;\nuse warnings;\n\n# Read input\nmy $n = <STDIN>;\nchomp $n;\n\nmy @poles;\nfor (my $i = 0; $i < $n; $i++) {\n    my $line = <STDIN>;\n    chomp $line;\n    my ($x, $y) = split ' ', $line;\n    push @poles, { x => $x, y => $y };\n}\n\n# Count intersecting pairs\nmy $count = 0;\nfor (my $i = 0; $i < $n; $i++) {\n    for (my $j = $i + 1; $j < $n; $j++) {\n        for (my $k = $j + 1; $k < $n; $k++) {\n            my $x1 = $poles[$i]->{x};\n            my $y1 = $poles[$i]->{y};\n            my $x2 = $poles[$j]->{x};\n            my $y2 = $poles[$j]->{y};\n            my $x3 = $poles[$k]->{x};\n            my $y3 = $poles[$k]->{y};\n\n            if ((($x2 - $x1) * ($y3 - $y1)) == (($x3 - $x1) * ($y2 - $y1))) {\n                $count++;\n            }\n        }\n    }\n}\n\n# Print the result\nprint $count;\n

This problem is same as the next one, but has smaller constraints.It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic.At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $$$(x_i, y_i)$$$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire.Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem?

The first line contains a single integer $$$n$$$ ($$$2 \\le n \\le 50$$$) — the number of electric poles.
Each of the following $$$n$$$ lines contains two integers $$$x_i$$$, $$$y_i$$$ ($$$-10^4 \\le x_i, y_i \\le 10^4$$$) — the coordinates of the poles.
It is guaranteed that all of these $$$n$$$ points are distinct.

Print a single integer — the number of pairs of wires that are intersecting.

#!/usr/bin/perl

use strict;
use warnings;

sub gcd {
    my ($a, $b) = @_;
    return $b == 0 ? $a : gcd($b, $a % $b);
}

my $n = <>;
chomp $n;
my @points;
my %lines;

for (1..$n) {
    my $line = <>;
    chomp $line;
    my ($x, $y) = split / /, $line;
    push @points, [$x, $y];
}

for my $i (0..$#points) {
    for my $j ($i+1..$#points) {
        my $dx = $points[$i][0] - $points[$j][0];
        my $dy = $points[$i][1] - $points[$j][1];
        my $g = gcd($dx, $dy);
        $dx /= $g; $dy /= $g;
        if ($dx < 0 || $dx == 0 && $dy < 0) {
            $dx = -$dx;
            $dy = -$dy;
        }
        my $c = $dx * $points[$i][1] - $dy * $points[$i][0];
        $lines{"$dx $dy"}{$c}++;
    }
}

my $total = 0;
my $pairs = 0;

for my $slope (keys %lines) {
    my $lines_on_slope = scalar keys %{$lines{$slope}};
    $total += $lines_on_slope;
    $pairs += $lines_on_slope * ($lines_on_slope - 1) / 2;
}

print $total * ($total - 1) / 2 - $pairs;


\nuse strict;\nuse warnings;\n\nsub count_threats {\n    my ($n, $m, @queens) = @_;\n    \n    my @threats = (0) x 9;\n    \n    for (my $i = 0; $i < $m; $i++) {\n        my ($row, $col) = split(' ', $queens[$i]);\n        \n        # Count threats in horizontal and vertical directions\n        for (my $j = 1; $j <= $n; $j++) {\n            if ($j != $row) {\n                $threats[1]++ if ($queens[$i] =~ /^$j $col$/);\n            }\n            if ($j != $col) {\n                $threats[1]++ if ($queens[$i] =~ /^$row $j$/);\n            }\n        }\n        \n        # Count threats in diagonal directions\n        for (my $j = 1; $j <= $n; $j++) {\n            if ($j != $row && $j != $col) {\n                $threats[1]++ if ($queens[$i] =~ /^$j $j$/);\n                $threats[1]++ if ($queens[$i] =~ /^$j @{[ $col - $row + $j ]}$/);\n                $threats[1]++ if ($queens[$i] =~ /^$j @{[ $col + $row - $j ]}$/);\n            }\n        }\n    }\n    \n    foreach my $threat (@threats) {\n        print "$threat ";\n    }\n}\n\nmy $input = <>;\nchomp($input);\nmy ($n, $m) = split(' ', $input);\nmy @queens;\nfor (my $i = 0; $i < $m; $i++) {\n    my $queen = <>;\n    chomp($queen);\n    push @queens, $queen;\n}\n\ncount_threats($n, $m, @queens);\n

A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and the bishop.There are m queens on a square n×n chessboard. You know each queen's positions, the i-th queen is positioned in the square (ri,ci), where ri is the board row number (numbered from the top to the bottom from 1 to n), and ci is the board's column number (numbered from the left to the right from 1 to n). No two queens share the same position.For each queen one can count w — the number of other queens that the given queen threatens (attacks). For a fixed attack direction only the first queen in this direction is under attack if there are many queens are on the ray of the attack. Obviously, for any queen w is between 0 and 8, inclusive.Print the sequence t0,t1,...,t8, where ti is the number of queens that threaten exactly i other queens, i.e. the number of queens that their w equals i.

The first line of the input contains a pair of integers n,m (1≤n,m≤10^5), where n is the size of the board and m is the number of queens on the board. Then m following lines contain positions of the queens, one per line. Each line contains a pair of integers ri,ci (1≤ri,ci≤n) — the queen's position. No two queens stand on the same square.

Print the required sequence t0,t1,...,t8, separating the numbers with spaces.

#!/usr/bin/perl

use strict;
use warnings;

sub check_queen {
    my ($x, $y, $dx, $dy, $n, $board) = @_;
    $x += $dx;
    $y += $dy;
    while ($x >= 0 && $y >= 0 && $x < $n && $y < $n) {
        if ($board->[$x][$y]) {
            return 1;
        }
        $x += $dx;
        $y += $dy;
    }
    return 0;
}

sub count_threats {
    my ($x, $y, $n, $board) = @_;
    my $threats = 0;
    for my $dx (-1..1) {
        for my $dy (-1..1) {
            if ($dx != 0 || $dy != 0) {
                $threats += check_queen($x, $y, $dx, $dy, $n, $board);
            }
        }
    }
    return $threats;
}

my $input = <>;
chomp($input);
my ($n, $m) = split(' ', $input);
my @board = map { [(0) x $n] } (1..$n);
my @threats = (0) x 9;
for my $i (1..$m) {
    my $input = <>;
    chomp($input);
    my ($x, $y) = split(' ', $input);
    $x--;
    $y--;
    $board[$x][$y] = 1;
}
for my $x (0..$n-1) {
    for my $y (0..$n-1) {
        if ($board[$x][$y]) {
            my $threats = count_threats($x, $y, $n, \@board);
            $threats[$threats]++;
        }
    }
}
print join(' ', @threats), "\n";


\nuse strict;\nuse warnings;\n\nsub count_triangles {\n    my ($n, $m, $red_points, $blue_points) = @_;\n\n    my $count = 0;\n\n    for (my $i = 0; $i < $n - 2; $i++) {\n        for (my $j = $i + 1; $j < $n - 1; $j++) {\n            for (my $k = $j + 1; $k < $n; $k++) {\n                my ($x1, $y1) = @{$red_points->[$i]};\n                my ($x2, $y2) = @{$red_points->[$j]};\n                my ($x3, $y3) = @{$red_points->[$k]};\n\n                my $is_triangle = 1;\n\n                for (my $l = 0; $l < $m; $l++) {\n                    my ($bx, $by) = @{$blue_points->[$l]};\n\n                    my $cross_product = ($x2 - $x1) * ($by - $y1) - ($y2 - $y1) * ($bx - $x1);\n\n                    if ($cross_product > 0 && ($x3 - $x1) * ($by - $y1) - ($y3 - $y1) * ($bx - $x1) > 0 && ($x1 - $x2) * ($by - $y2) - ($y1 - $y2) * ($bx - $x2) > 0) {\n                        $is_triangle = 0;\n                        last;\n                    }\n                }\n\n                $count += $is_triangle;\n            }\n        }\n    }\n\n    return $count;\n}\n\nmy $input = <STDIN>;\nchomp $input;\nmy ($n, $m) = split ' ', $input;\n\nmy @red_points;\nfor (my $i = 0; $i < $n; $i++) {\n    my $point = <STDIN>;\n    chomp $point;\n    my ($x, $y) = split ' ', $point;\n    push @red_points, [$x, $y];\n}\n\nmy @blue_points;\nfor (my $i = 0; $i < $m; $i++) {\n    my $point = <STDIN>;\n    chomp $point;\n    my ($x, $y) = split ' ', $point;\n    push @blue_points, [$x, $y];\n}\n\nmy $result = count_triangles($n, $m, \@red_points, \@blue_points);\nprint $result;\n

Little Petya likes to draw. He drew N red and M blue points on the plane in such a way that no three points lie on the same line. Now he wonders what is the number of distinct triangles with vertices in red points which do not contain any blue point inside.

The first line contains two non-negative integer numbers N and M (0≤N≤500, 0≤M≤500) — the number of red and blue points respectively. The following N lines contain two integer numbers each — coordinates of red points. The following M lines contain two integer numbers each — coordinates of blue points. All coordinates do not exceed 10^9 by absolute value.

Output one integer — the number of distinct triangles with vertices in red points which do not contain any blue point inside.

# Read input
my $input = <STDIN>;
chomp $input;
my ($N, $M) = split ' ', $input;

# Read red points
my @red_points;
for (1..$N) {
    my $point = <STDIN>;
    chomp $point;
    my ($x, $y) = split ' ', $point;
    push @red_points, [$x, $y];
}

# Read blue points
my @blue_points;
for (1..$M) {
    my $point = <STDIN>;
    chomp $point;
    my ($x, $y) = split ' ', $point;
    push @blue_points, [$x, $y];
}

# Function to check if a point is inside a triangle
sub is_inside_triangle {
    my ($p, $p1, $p2, $p3) = @_;
    my $d1 = ($p1->[0] - $p->[0]) * ($p2->[1] - $p1->[1]) - ($p2->[0] - $p1->[0]) * ($p1->[1] - $p->[1]);
    my $d2 = ($p2->[0] - $p->[0]) * ($p3->[1] - $p2->[1]) - ($p3->[0] - $p2->[0]) * ($p2->[1] - $p->[1]);
    my $d3 = ($p3->[0] - $p->[0]) * ($p1->[1] - $p3->[1]) - ($p1->[0] - $p3->[0]) * ($p3->[1] - $p->[1]);
    return ($d1 >= 0 && $d2 >= 0 && $d3 >= 0) || ($d1 <= 0 && $d2 <= 0 && $d3 <= 0);
}

# Count the number of distinct triangles
my $count = 0;
for my $i (0..$N-1) {
    for my $j ($i+1..$N-1) {
        for my $k ($j+1..$N-1) {
            my $triangle = [$red_points[$i], $red_points[$j], $red_points[$k]];
            my $is_valid = 1;
            for my $blue_point (@blue_points) {
                if (is_inside_triangle($blue_point, @$triangle)) {
                    $is_valid = 0;
                    last;
                }
            }
            $count++ if $is_valid;
        }
    }
}

# Print the result
print $count;


Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything. At last, after some thought, he thought of something. Let's say there is a word s, consisting of |s| lowercase Latin letters. Then for one operation you can choose a certain position p (1≤p<|s|) and perform one of the following actions:   either replace letter sp with the one that alphabetically follows it and replace letter sp+1 with the one that alphabetically precedes it;  or replace letter sp with the one that alphabetically precedes it and replace letter sp+1 with the one that alphabetically follows it. Let us note that letter "z" doesn't have a defined following letter and letter "a" doesn't have a defined preceding letter. That's why the corresponding changes are not acceptable. If the operation requires performing at least one unacceptable change, then such operation cannot be performed.Two words coincide in their meaning iff one of them can be transformed into the other one as a result of zero or more operations.Sherlock Holmes needs to learn to quickly determine the following for each word: how many words can exist that coincide in their meaning with the given word, but differs from the given word in at least one character? Count this number for him modulo 1000000007 (10^9+7).

The input data contains several tests. The first line contains the only integer t (1≤t≤10^4) — the number of tests.
Next t lines contain the words, one per line. Each word consists of lowercase Latin letters and has length from 1 to 100, inclusive. Lengths of words can differ.

For each word you should print the number of different other words that coincide with it in their meaning — not from the words listed in the input data, but from all possible words. As the sought number can be very large, print its value modulo 1000000007 (10^9+7).

Some explanations about the operation:
  Note that for each letter, we can clearly define the letter that follows it. Letter "b" alphabetically follows letter "a", letter "c" follows letter "b", ..., "z" follows letter "y".  Preceding letters are defined in the similar manner: letter "y" precedes letter "z", ..., "a" precedes letter "b".  Note that the operation never changes a word's length. In the first sample you can obtain the only other word "ba". In the second sample you cannot obtain any other word, so the correct answer is 0.
Consider the third sample. One operation can transform word "klmbfxzb" into word "klmcexzb": we should choose p=4, and replace the fourth letter with the following one ("b" → "c"), and the fifth one — with the preceding one ("f" → "e"). Also, we can obtain many other words from this one. An operation can transform word "ya" only into one other word "xb".
Word "ya" coincides in its meaning with words "xb", "wc", "vd", ..., "ay" (overall there are 24 other words). The word "klmbfxzb has many more variants — there are 3320092814 other words that coincide with in the meaning. So the answer for the first word equals 24 and for the second one equals 320092793 — the number 3320092814 modulo 10^9+7

use strict;
use warnings;

my $MOD = 1000000007;

sub count_coinciding_words {
    my ($word) = @_;
    my $length = length($word);
    my $count = 0;

    # Calculate the number of words that coincide with the given word
    # by considering each possible position for the operation
    for (my $p = 0; $p < $length - 1; $p++) {
        my $letter_p = substr($word, $p, 1);
        my $letter_p_next = substr($word, $p + 1, 1);

        # Calculate the number of words that can be formed by replacing
        # letter p with the letter that follows it and letter p+1 with the
        # letter that precedes it
        my $count_follows = ord('z') - ord($letter_p) + ord($letter_p_next) - ord('a') + 1;

        # Calculate the number of words that can be formed by replacing
        # letter p with the letter that precedes it and letter p+1 with the
        # letter that follows it
        my $count_precedes = ord($letter_p) - ord('a') + ord('z') - ord($letter_p_next) + 1;

        # Add the counts modulo $MOD
        $count = ($count + $count_follows + $count_precedes) % $MOD;
    }

    return $count;
}

# Read the number of tests
my $t = <STDIN>;
chomp($t);

# Process each test case
for (my $i = 0; $i < $t; $i++) {
    # Read the word
    my $word = <STDIN>;
    chomp($word);

    # Calculate the number of coinciding words
    my $coinciding_words = count_coinciding_words($word);

    # Print the result modulo $MOD
    print($coinciding_words % $MOD . "\n");
}


In some country live wizards. They love to ride trolleybuses.A city in this country has a trolleybus depot with n trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final station is at a distance of d meters from the depot. We know for the i-th trolleybus that it leaves at the moment of time ti seconds, can go at a speed of no greater than vi meters per second, and accelerate with an acceleration no greater than a meters per second squared. A trolleybus can decelerate as quickly as you want (magic!). It can change its acceleration as fast as you want, as well. Note that the maximum acceleration is the same for all trolleys.Despite the magic the trolleys are still powered by an electric circuit and cannot overtake each other (the wires are to blame, of course). If a trolleybus catches up with another one, they go together one right after the other until they arrive at the final station. Also, the drivers are driving so as to arrive at the final station as quickly as possible.You, as head of the trolleybuses' fans' club, are to determine for each trolley the minimum time by which it can reach the final station. At the time of arrival at the destination station the trolleybus does not necessarily have zero speed. When a trolley is leaving the depot, its speed is considered equal to zero. From the point of view of physics, the trolleybuses can be considered as material points, and also we should ignore the impact on the speed of a trolley bus by everything, except for the acceleration and deceleration provided by the engine.

The first input line contains three space-separated integers n, a, d (1≤n≤10^5, 1≤a,d≤10^6) — the number of trolleybuses, their maximum acceleration and the distance from the depot to the final station, correspondingly.
Next n lines contain pairs of integers ti vi (0≤t1<t2...<tn-1<tn≤10^6, 1≤vi≤10^6) — the time when the i-th trolleybus leaves the depot and its maximum speed, correspondingly. The numbers in the lines are separated by spaces.

For each trolleybus print a single line the time it arrives to the final station. Print the times for the trolleybuses in the order in which the trolleybuses are given in the input. The answer will be accepted if the absolute or relative error doesn't exceed 10^-4.

In the first sample the second trolleybus will catch up with the first one, that will happen at distance 510.5 meters from the depot. The trolleybuses will go the remaining 9489.5 meters together at speed 10 meters per second. As a result, both trolleybuses will arrive to the final station by the moment of time 1000.5 seconds. The third trolleybus will not catch up with them. It will arrive to the final station by the moment of time 11000.05 seconds.

#!/usr/bin/perl

use strict;
use warnings;
use List::Util qw[max];

sub trolley_time {
    my ($n, $a, $d, @trolley_info) = @_;
    my @arrival_times;
    my $prev_time = 0;
    for my $i (0 .. $n-1) {
        my ($t, $v) = @{$trolley_info[$i]};
        my $time_to_reach_v = $v / $a;
        my $dist_to_reach_v = 0.5 * $a * $time_to_reach_v**2;
        my $total_time;
        if ($dist_to_reach_v <= $d) {
            my $remaining_dist = $d - $dist_to_reach_v;
            my $remaining_time = $remaining_dist / $v;
            $total_time = $t + $time_to_reach_v + $remaining_time;
        } else {
            $total_time = $t + sqrt(2*$d/$a);
        }
        $prev_time = max($prev_time, $total_time);
        push @arrival_times, $prev_time;
    }
    return @arrival_times;
}

my $input_line = <STDIN>;
chomp $input_line;
my ($n, $a, $d) = split ' ', $input_line;
my @trolley_info;
for my $i (0 .. $n-1) {
    my $trolley_line = <STDIN>;
    chomp $trolley_line;
    push @trolley_info, [split ' ', $trolley_line];
}
my @arrival_times = trolley_time($n, $a, $d, @trolley_info);
for my $time (@arrival_times) {
    printf("%.10f\n", $time);
}


use strict;\nuse warnings;\n\nsub fibonacci_strings {\n    my ($k, $m, @queries) = @_;\n    my @fibonacci = ('a', 'b');\n    for (my $i = 2; $i < $k; $i++) {\n        $fibonacci[$i] = $fibonacci[$i-1] . $fibonacci[$i-2];\n    }\n    my @results;\n    foreach my $query (@queries) {\n        my $count = 0;\n        foreach my $fib_str (@fibonacci) {\n            while ($fib_str =~ /$query/g) {\n                $count++;\n            }\n        }\n        push @results, $count;\n    }\n    return \@results;\n}\n\nmy $input = <STDIN>;\nchomp $input;\nmy ($k, $m) = split ' ', $input;\nmy @queries;\nfor (my $i = 0; $i < $m; $i++) {\n    my $query = <STDIN>;\n    chomp $query;\n    push @queries, $query;\n}\n\nmy $output = fibonacci_strings($k, $m, @queries);\nforeach my $result (@$output) {\n    print $result % 1000000007 . \"\\n\";\n}

Fibonacci strings are defined as follows:   f1 = «a»  f2 = «b»  fn = fn-1 fn-2, n>2 Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba".You are given a Fibonacci string and m strings si. For each string si, find the number of times it occurs in the given Fibonacci string as a substring.

The first line contains two space-separated integers k and m — the number of a Fibonacci string and the number of queries, correspondingly.
Next m lines contain strings si that correspond to the queries. It is guaranteed that strings si aren't empty and consist only of characters "a" and "b".
The input limitations for getting 30 points are:
  1≤k≤3000  1≤m≤3000  The total length of strings si doesn't exceed 3000  The input limitations for getting 100 points are:
  1≤k≤10^18  1≤m≤10^4  The total length of strings si doesn't exceed 10^5  Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

For each string si print the number of times it occurs in the given Fibonacci string as a substring. Since the numbers can be large enough, print them modulo 1000000007 (10^9+7). Print the answers for the strings in the order in which they are given in the input.

use strict;
use warnings;

sub fibonacci_strings {
    my ($k, $m, @queries) = @_;
    my @fibonacci = ('a', 'b');

    for (my $i = 2; $i < $k; $i++) {
        $fibonacci[$i] = $fibonacci[$i-1] . $fibonacci[$i-2];
    }

    my @results;
    foreach my $query (@queries) {
        my $count = 0;
        my $pos = 0;
        while (($pos = index($fibonacci[$k-1], $query, $pos)) != -1) {
            $count++;
            $pos++;
        }
        push @results, $count;
    }

    return @results;
}

# Read input
my $input = <STDIN>;
chomp $input;
my ($k, $m) = split ' ', $input;
my @queries;
for (my $i = 0; $i < $m; $i++) {
    my $query = <STDIN>;
    chomp $query;
    push @queries, $query;
}

# Call the function and print the results
my @output = fibonacci_strings($k, $m, @queries);
foreach my $result (@output) {
    print "$result\n";
}


#!/usr/local/bin/perl
$n              = <>;
$openBlocks     = 0;
$needlessBlocks =
  0;    #ÑÑÐ¾ Ð±Ð»Ð¾ÐºÐ¸, Ð¾ÑÐºÑÑÑÑÐµ Ð¿Ð¾ÑÐ»Ðµ ÑÐºÑÐµÐ¿ÑÐµÐ½Ð° TODO
$wasThrow = 0;
$eType;
for ( 1 .. $n ) {
    my $line = <>;

    if ( $line =~ /\s*try\s*/ ) {
        if ( $wasThrow == 0 ) {
            $openBlocks++;
        }
        else {
            $needlessBlocks++;
        }
        next;
    }
    if ( $line =~ /\s*throw\s*\(\s*(\w+)\s*\)/ ) {
        $wasThrow = 1;
        $eType    = $1;
        maybeError();
        next;
    }
    if ( $line =~ /\s*catch\s*\(\s*(\w+)\s*,\s*"(.+)"\s*\)/ ) {
        if ( $needlessBlocks > 0 ) {
            $needlessBlocks--;
            next;
        }
        $openBlocks--;
        if ( $wasThrow != 0 && $eType eq $1 ) {
            print $2. "\n";
            exit;
        }
        if ($wasThrow != 0){
        maybeError();
        }

    }
}
print "Unhandled Exception\n";

sub maybeError {
    if ( $openBlocks == 0 ) {
        print "Unhandled Exception\n";
        exit;
    }
}

Vasya is developing his own programming language VPL (Vasya Programming Language). Right now he is busy making the system of exceptions. He thinks that the system of exceptions must function like that.The exceptions are processed by try-catch-blocks. There are two operators that work with the blocks: The try operator. It opens a new try-catch-block.  The catch(<exception_type>, <message>) operator. It closes the try-catch-block that was started last and haven't yet been closed. This block can be activated only via exception of type <exception_type>. When we activate this block, the screen displays the <message>. If at the given moment there is no open try-catch-block, then we can't use the catch operator.The exceptions can occur in the program in only one case: when we use the throw operator. The throw(<exception_type>) operator creates the exception of the given type.Let's suggest that as a result of using some throw operator the program created an exception of type a. In this case a try-catch-block is activated, such that this block's try operator was described in the program earlier than the used throw operator. Also, this block's catch operator was given an exception type a as a parameter and this block's catch operator is described later that the used throw operator. If there are several such try-catch-blocks, then the system activates the block whose catch operator occurs earlier than others. If no try-catch-block was activated, then the screen displays message "Unhandled Exception".To test the system, Vasya wrote a program that contains only try, catch and throw operators, one line contains no more than one operator, the whole program contains exactly one throw operator.Your task is: given a program in VPL, determine, what message will be displayed on the screen.

The first line contains a single integer: n (1≤n≤10^5) the number of lines in the program. Next n lines contain the program in language VPL. Each line contains no more than one operator. It means that input file can contain empty lines and lines, consisting only of spaces.
The program contains only operators try, catch and throw. It is guaranteed that the program is correct. It means that each started try-catch-block was closed, the catch operators aren't used unless there is an open try-catch-block. The program has exactly one throw operator. The program may have spaces at the beginning of a line, at the end of a line, before and after a bracket, a comma or a quote mark.
The exception type is a nonempty string, that consists only of upper and lower case english letters. The length of the string does not exceed 20 symbols. Message is a nonempty string, that consists only of upper and lower case english letters, digits and spaces. Message is surrounded with quote marks. Quote marks shouldn't be printed. The length of the string does not exceed 20 symbols.
Length of any line in the input file does not exceed 50 symbols.

Print the message the screen will show after the given program is executed.

In the first sample there are 2 try-catch-blocks such that try operator is described earlier than throw operator and catch operator is described later than throw operator: try-catch(BE,"BE in line 3") and try-catch(AE,"AE somewhere"). Exception type is AE, so the second block will be activated, because operator catch(AE,"AE somewhere") has exception type AE as parameter and operator catch(BE,"BE in line 3") has exception type BE.
In the second sample there are 2 try-catch-blocks such that try operator is described earlier than throw operator and catch operator is described later than throw operator: try-catch(AE,"AE in line 3") and try-catch(AE,"AE somewhere"). Exception type is AE, so both blocks can be activated, but only the first one will be activated, because operator catch(AE,"AE in line 3") is described earlier than catch(AE,"AE somewhere")
In the third sample there is no blocks that can be activated by an exception of type CE.

8
try
    try
        throw ( AE )
    catch ( BE, "BE in line 3")

    try
    catch(AE, "AE in line 5")
catch(AE,"AE somewhere")

8
try
    try
        throw ( AE )
    catch ( AE, "AE in line 3")

    try
    catch(BE, "BE in line 5")
catch(AE,"AE somewhere")

8
try
    try
        throw ( CE )
    catch ( BE, "BE in line 3")

    try
    catch(AE, "AE in line 5")
catch(AE,"AE somewhere")

AE somewhere
AE in line 3
Unhandled Exception

#!/usr/bin/perl

use 5.006;
use strict;
use warnings;

sub getMessage {
    my $t = shift;
    my $s = $t;
    $s =~ s/^[\w (,]+\"//g;
    $s =~ s/\"[\w) ]+$//g;
    $s =~ s/^[\s]+//g;
    $s =~ s/[\s]+$//g;
    return $s;
}

sub getException {
    my $t = shift;
    my $s = $t;
    $s =~ s/^[\w ]+\(//g;
    $s =~ s/,[\w )\"]+$//g;
    $s =~ s/^[\s]+//g;
    $s =~ s/[\s]+$//g;
    return $s;
}

sub startsWith {
    my $t = shift;
    my $tok = shift;
    my $s = $t;
    $s =~ s/^[\s]+//g;
    return 1 if ($s =~ /^$tok/);
    return 0;
}

sub getThrowExc {
    my $t = shift;
    my $s = $t;
    $s =~ s/^[\w ]+\(//g;
    $s =~ s/[)]//g;
    $s =~ s/^[\s]+//g;
    $s =~ s/[\s]+$//g;
    return $s;
}

sub blank {
    my $t = shift;
    my $s = $t;
    $s =~ s/[\s]+//g;
    return length($s) == 0;
}

my $n = <>;
my $line;
my $level = 0;
my $throwLevel = -1;
my $left = 0;
my $haveAnswer = 0;
my $exc;
while ($line = <>) {
    next if (blank($line));
    if ($throwLevel == -1) {
        if (startsWith($line, "try")) {
            $level++;
            next;
        }
        if (startsWith($line, "catch")) {
            $level--;
            next;
        }
        $exc = getThrowExc($line);
        $throwLevel = $level;
    } else {
        if (startsWith($line, "try")) {
            $left++;
            next;
        }
        my $e = getException($line);
        if ($left == 0 && $exc eq $e) {
            $haveAnswer = 1;
            print getMessage($line);
            last;
        }
        if ($left > 0) {
            $left--;
        }

    }
}

if ($haveAnswer != 1) {
    print "Unhandled Exception";
}

[{'input': ['8\r\ntry\r\n    try\r\n        throw ( AE ) \r\n    catch ( BE, "BE in line 3")\r\n\r\n    try\r\n    catch(AE, "AE in line 5") \r\ncatch(AE,"AE somewhere")\r\n'], 'output': ['AE somewhere\r\n']}, {'input': ['8\r\ntry\r\n    try\r\n        throw ( AE ) \r\n    catch ( AE, "AE in line 3")\r\n\r\n    try\r\n    catch(BE, "BE in line 5") \r\ncatch(AE,"AE somewhere")\r\n'], 'output': ['AE in line 3\r\n']}, {'input': ['8\r\ntry\r\n    try\r\n        throw ( CE ) \r\n    catch ( BE, "BE in line 3")\r\n\r\n    try\r\n    catch(AE, "AE in line 5") \r\ncatch(AE,"AE somewhere")\r\n'], 'output': ['Unhandled Exception\r\n']}, {'input': ['3\r\ntry\r\nthrow(A)\r\ncatch(A, "A cought")\r\n'], 'output': ['A cought\r\n']}, {'input': ['5\r\n try  \r\n try \r\n  catch ( gnAEZNTt,  "i5 tAC8ktUdeX")  \r\n  throw(   gnAEZNTt    ) \r\ncatch  ( gnAEZNTt, "g1cN" )  \r\n'], 'output': ['g1cN\r\n']}, {'input': ['5\r\n try    \r\n catch(UqWpIpGKiMqFnKox ,  "bp9h8dfeNLhk9Wea"  ) \r\nthrow   (   uaBRmgAAQyWTCzaaQMlZ ) \r\n    try    \r\ncatch(  UqWpIpGKiMqFnKox,"0OvVhsVWzDyqwo"  )\r\n'], 'output': ['Unhandled Exception\r\n']}, {'input': ['5\r\n    throw  (    ouB    )    \r\n  try   \r\ncatch(ouB, "bTJZV" )\r\n try    \r\ncatch(  ouB , "DUniE dDhpiN")  \r\n'], 'output': ['Unhandled Exception\r\n']}, {'input': ['5\r\ntry    \r\n throw(    egdCZzrKRLBcqDl   )\r\n catch (  egdCZzrKRLBcqDl  ,"o" )\r\n    try    \r\n  catch (egdCZzrKRLBcqDl  , "oM62EJIirV D0"  ) \r\n'], 'output': ['o\r\n']}, {'input': ['10\r\n  \r\n\r\n \r\n\r\nthrow (ProgramException)\r\n \r\n  \r\n\r\n\r\n \r\n'], 'output': ['Unhandled Exception\r\n']}, {'input': ['21\r\n  try  \r\n  try  \r\n  try  \r\n  try  \r\n  try  \r\n  try  \r\n  try  \r\n  try  \r\n  try  \r\n  try  \r\n  throw(  qtSMze)   \r\ncatch(LY,"x3 j")\r\ncatch(hgSAFgbMGx,"moByu")\r\ncatch(LmydVQgv,"hbZl")\r\ncatch(oK,"B6OZx qy")\r\ncatch(rrtnRQB,"7VFkQMv")\r\ncatch(CASqQXaz,"d9oci1Kx")\r\ncatch(CTCzsdD,"u")\r\ncatch(xqqMxbEs,"Mdu")\r\ncatch(sOWgTPbRp,"fVH6")\r\ncatch(qtSMze,"ZRnNzz")\r\n'], 'output': ['ZRnNzz\r\n']}, {'input': ['3\r\ntry\r\nthrow ( X )\r\ncatch ( X, "try again")\r\n'], 'output': ['try again\r\n']}, {'input': ['3\r\ntry\r\nthrow ( try )\r\ncatch ( try, "try again")\r\n'], 'output': ['try again\r\n']}, {'input': ['3\r\ntry\r\nthrow(tryC)\r\ncatch(tryC, "bad boy")\r\n'], 'output': ['bad boy\r\n']}, {'input': ['7\r\ntry\r\ncatch(A,"try A")\r\ntry\r\n throw(A)\r\ncatch(A,"try B")\r\ntry\r\ncatch(A,"try C")\r\n'], 'output': ['try B\r\n']}, {'input': ['3\r\ntry\r\n throw(try)\r\ncatch(try,"haha")\r\n'], 'output': ['haha\r\n']}, {'input': ['3\r\ntry\r\n throw(try)\r\ncatch(try,"asd")\r\n'], 'output': ['asd\r\n']}, {'input': ['11\r\ntry\r\n  try\r\n  catch (B, "b")\r\n  \r\n  try\r\n    throw ( U )\r\n  catch (U, "try")\r\n  \r\n  try\r\n  catch (C, "c")\r\ncatch (A, "a")\r\n'], 'output': ['try\r\n']}]


#!/usr/bin/perl

use 5.006;
use strict;
use warnings;

my %hash;

sub gcd {
  my $a = shift;
  my $b = shift;
  while ($b > 0) {
    $b ^= $a ^= $b ^= $a %= $b;
  }
  return $a;
}

my $n = <>;
for(1..$n) {
  my $line = <>;
  my @arr = split(/ /, $line);
  my $k = $arr[0];
  my $b = $arr[1];
  next if (0 == $k);
  my $g = gcd($k, $b);
  $k /= $g;
  $b /= $g;
  if ($k < 0) {
    $k = -$k;
    $b = -$b;
  }
  $hash{($k, $b)} = 1;
}
print "".keys( %hash )."\n";

As Valeric and Valerko were watching one of the last Euro Championship games in a sports bar, they broke a mug. Of course, the guys paid for it but the barman said that he will let them watch football in his bar only if they help his son complete a programming task. The task goes like that.Let's consider a set of functions of the following form:  Let's define a sum of n functions y1(x),...,yn(x) of the given type as function s(x)=y1(x)+...+yn(x) for any x. It's easy to show that in this case the graph s(x) is a polyline. You are given n functions of the given type, your task is to find the number of angles that do not equal 180 degrees, in the graph s(x), that is the sum of the given functions.Valeric and Valerko really want to watch the next Euro Championship game, so they asked you to help them.

The first line contains integer n (1≤n≤10^5) — the number of functions. Each of the following n lines contains two space-separated integer numbers ki,bi (-10^9≤ki,bi≤10^9) that determine the i-th function.

Print a single number — the number of angles that do not equal 180 degrees in the graph of the polyline that equals the sum of the given functions.

#!/usr/bin/perl

use 5.006;
use strict;
use warnings;

my %hash;

sub gcd {
  my $a = abs (shift);
  my $b = abs (shift);
  while ($b > 0) {
    $b ^= $a ^= $b ^= $a %= $b;
  }
  return $a;
}

my $n = <>;
for(1..$n) {
  my $line = <>;
  my @arr = split(/ /, $line);
  my $k = $arr[0];
  my $b = $arr[1];
  next if (0 == $k);
  my $g = gcd($k, $b);
  $k /= $g;
  $b /= $g;
  if ($k < 0) {
    $k = -$k;
    $b = -$b;
  }
  $hash{($k, $b)} = 1;
}
print "".keys( %hash )."\n";


#!/usr/bin/perl

use List::Util qw[min max];

$a = <>;
$b = <>;
$r = <>;

if (min($a, $b) < 2*$r) {
  print ("Second");
}
else {
  print ("First");
}

You've got a rectangular table with length a and width b and the infinite number of plates of radius r. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can touch each other), and so that any point on any plate is located within the table's border. During the game one cannot move the plates that already lie on the table. The player who cannot make another move loses. Determine which player wins, the one who moves first or the one who moves second, provided that both players play optimally well.

A single line contains three space-separated integers a, b, r (1≤a,b,r≤100) — the table sides and the plates' radius, correspondingly.

If wins the player who moves first, print "First" (without the quotes). Otherwise print "Second" (without the quotes).

In the first sample the table has place for only one plate. The first player puts a plate on the table, the second player can't do that and loses.

In the second sample the table is so small that it doesn't have enough place even for one plate. So the first player loses without making a single move.

$xx = <STDIN> ; @xx = split(" ",$xx) ;
if ($xx[0] < $xx[2] * 2 or $xx[1] < $xx[2] * 2) { print "Second"; }
else { print "First"; }


Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai,j.Let's call matrix A clear if no two cells containing ones have a common side.Let's call matrix A symmetrical if it matches the matrices formed from it by a horizontal and/or a vertical reflection. Formally, for each pair (i,j) (1≤i,j≤n) both of the following conditions must be met: Ai,j=An-i+1,j and Ai,j=Ai,n-j+1.Let's define the sharpness of matrix A as the number of ones in it.Given integer x, your task is to find the smallest positive integer n such that there exists a clear symmetrical matrix A with side n and sharpness x.

The only line contains a single integer x (1≤x≤100) — the required sharpness of the matrix.

Print a single number — the sought value of n.

The figure below shows the matrices that correspond to the samples:


The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'.A path called normalized if it contains the smallest possible number of characters '/'.Your task is to transform a given path to the normalized form.

The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.

chomp($line = <>);
$line =~ s/\/+/\//g;
$line =~ s/\/+$//g if (length $line) > 1;
print "$line\n";

[{'input': ['//usr///local//nginx/sbin\r\n'], 'output': ['/usr/local/nginx/sbin\r\n']}, {'input': ['////a//b/////g\r\n'], 'output': ['/a/b/g\r\n']}, {'input': ['/a/b/c\r\n'], 'output': ['/a/b/c\r\n']}, {'input': ['/\r\n'], 'output': ['/\r\n']}, {'input': ['////\r\n'], 'output': ['/\r\n']}, {'input': ['/a//aa/a//\r\n'], 'output': ['/a/aa/a\r\n']}, {'input': ['/aa//b/aa\r\n'], 'output': ['/aa/b/aa\r\n']}, {'input': ['////////////////////////////////////////////////////////////////////////////////////////////////////\r\n'], 'output': ['/\r\n']}, {'input': ['/opt///pokerband///srvb/opt///pokerband///srvb////pokerband///srvb/\r\n'], 'output': ['/opt/pokerband/srvb/opt/pokerband/srvb/pokerband/srvb\r\n']}, {'input': ['/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/\r\n'], 'output': ['/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game\r\n']}, {'input': ['/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//\r\n'], 'output': ['/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game\r\n']}, {'input': ['/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//test/\r\n'], 'output': ['/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/test\r\n']}, {'input': ['/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//testt\r\n'], 'output': ['/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/testt\r\n']}, {'input': ['///a//a////a/a//a//a//a/////\r\n'], 'output': ['/a/a/a/a/a/a/a\r\n']}, {'input': ['/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n'], 'output': ['/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n']}, {'input': ['/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz/\r\n'], 'output': ['/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n']}, {'input': ['/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a\r\n'], 'output': ['/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a\r\n']}, {'input': ['///////////////////////////////////////////////////////////////////////////////////////////////////z\r\n'], 'output': ['/z\r\n']}, {'input': ['/z//////////////////////////////////////////////////////////////////////////////////////////////////\r\n'], 'output': ['/z\r\n']}]


Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.Each digit is allowed to occur in the number the same number of times it occurs in the set.

A single line contains a single integer n (1≤n≤100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.

On a single line print the answer to the problem. If such number does not exist, then you should print -1.

In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number.

#!/usr/bin/perl

use strict;
use warnings;

my $n = <>;
chomp($n);
my $line = <>;
chomp($line);

my @nums = split(/\s/, $line);
my $data = +{};
for my $num (@nums) {
    $data->{$num}++;
}

if (!$data->{0}) {
    print "-1";
    exit;
}

my $sum = get_sum($data);

my $rest = $sum % 3;
my $cnt = 0;
while ($rest != 0 && $cnt < 2) {
    func($data, $rest);
    $rest = get_sum($data) % 3;
    $cnt++;
}

if ($rest == 0) {
    my $ans = '';
    for (my $i=9; $i >= 0; $i--) {
        if ($data->{$i}) {
             $ans .= $i x $data->{$i};
        }
    }

    if (substr($ans, 0, 1) eq '0') {
        print 0;
    }
    else {
        print $ans;
    }
}
else {
    print "-1";
}

sub get_sum {
    $data = shift;
    my $sum = 0;
    for my $key (keys(%{$data})) {
        if ($data->{$key}) {
            $sum += $key * $data->{$key};
        }
    }

    return $sum;
}

sub func {
    my ($data, $rest) = @_;
    if ($rest == 1) {
        for my $i (1, 4, 7) {
            if ($data->{$i}) {
                $data->{$i}--;
                return;
            }
        }
        for my $i (2, 5, 8) {
            if ($data->{$i}) {
                $data->{$i}--;
                return;
            }
        }
    }
    if ($rest == 2) {
        for my $i (2, 5, 8) {
            if ($data->{$i}) {
                $data->{$i}--;
                return;
            }
        }
        for my $i (1, 4, 7) {
            if ($data->{$i}) {
                $data->{$i}--;
                return;
            }
        }
    }
}


Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where   <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <username> is between 1 and 16, inclusive.  <hostname> — is a sequence of word separated by periods (characters «.»), where each word should contain only characters allowed for <username>, the length of each word is between 1 and 16, inclusive. The length of <hostname> is between 1 and 32, inclusive.  <resource> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <resource> is between 1 and 16, inclusive. The content of square brackets is optional — it can be present or can be absent.There are the samples of correct Jabber IDs: [email protected], [email protected]/contest.Your task is to write program which checks if given string is a correct Jabber ID.

The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive.

[{'input': ['mike@codeforces.com\r\n'], 'output': ['YES\r\n']}, {'input': ['john.smith@codeforces.ru/contest.icpc/12\r\n'], 'output': ['NO\r\n']}, {'input': ['test@test.ri/abacaba\r\n'], 'output': ['YES\r\n']}, {'input': ['@ops\r\n'], 'output': ['NO\r\n']}, {'input': ['this-is-the-test\r\n'], 'output': ['NO\r\n']}, {'input': ['mike@codeforces.commike@codeforces.com\r\n'], 'output': ['NO\r\n']}, {'input': ['oooop/oooop\r\n'], 'output': ['NO\r\n']}, {'input': ['w@S8/XU.5._R7fHq.@../e.WP!54Ey1L\x7f.9jv\r\n'], 'output': ['NO\r\n']}, {'input': ['lNC9D1L5U@.L!_!CcAOEEx.0z.aiW/S430sbQT\r\n'], 'output': ['NO\r\n']}, {'input': ['@/YTd.K1@lD\r\n'], 'output': ['NO\r\n']}, {'input': ['Fyi!d1l@.OesGopTnRn.81xdSb8q\x7f./MzuI\r\n'], 'output': ['NO\r\n']}, {'input': ['_TlPy65\x7fw/@.Vl@.8k\r\n'], 'output': ['NO\r\n']}, {'input': ['xpS@._s8.e0l\x7fJci/.LdiT\r\n'], 'output': ['NO\r\n']}, {'input': ['lGwo\x7f8.D2@.3\r\n'], 'output': ['NO\r\n']}, {'input': ['Ccz9T5rKZQuEerGo@6l.\r\n'], 'output': ['NO\r\n']}, {'input': ['Y@5nh@8.9P.Bx5AaY.1g.Tc_MK7.g_..0.\r\n'], 'output': ['NO\r\n']}, {'input': ['Q2/6y!SP9s\x7fG@7zIGr.Du_nR8.\r\n'], 'output': ['NO\r\n']}, {'input': ['eWfLL@gW!BEJUxF\x7fh@dghf.d4.FiYp/2.Pr7a/5O6zXdAkikjCEDrb\r\n'], 'output': ['NO\r\n']}, {'input': ['8oI/\x7fa@Q\r\n'], 'output': ['NO\r\n']}, {'input': ['J@Y9Gz550l@\x7fPqVZdQ!u\r\n'], 'output': ['NO\r\n']}, {'input': ['VTE6aTTta@DHe4xeG@6.c2R.J.O7sndWEEW.9j@.l..3Bs\r\n'], 'output': ['NO\r\n']}, {'input': ['aeo2XkK@UX.nQJN!Tg..wGN5YOi68U.oP2Yl3/\r\n'], 'output': ['NO\r\n']}, {'input': ['m13zREg8LbPr@T2.Z9@g.9u.v.A..XNH/1/tloIceXydZf3\r\n'], 'output': ['NO\r\n']}, {'input': ['4@@..f3ZT./oUGZ@\r\n'], 'output': ['NO\r\n']}, {'input': ['G.rVAxwDx@a.PVSe!KtpX4tzs/0yQGzZCPJPJoda\r\n'], 'output': ['NO\r\n']}, {'input': ['SV9T5RR425Sl0b@kzj.XT.PFWc..ho/VE7gjf\r\n'], 'output': ['NO\r\n']}, {'input': ['bgko@1../xwSj_\x7fJ\r\n'], 'output': ['NO\r\n']}, {'input': ['n5ymLC.bE@ukio.im2../.\r\n'], 'output': ['NO\r\n']}, {'input': ['zr.KB_6ZMSwI2GA5@R/4iP1ZKHpszW!YN/\r\n'], 'output': ['NO\r\n']}, {'input': ['@alK@pR\r\n'], 'output': ['NO\r\n']}, {'input': ['al_Y2I4IKp@A_N.\x7fruCw0VL/hRzJtx.S7sp/r!c.n9ffh\r\n'], 'output': ['NO\r\n']}, {'input': ['C1rE26_rTAVzLm@6@X5OGX.ibJ9./kkBEVlcU\r\n'], 'output': ['NO\r\n']}, {'input': ['feGSXP@eyUfr\x7f8.x4Re.JL.6B.r/fX_\r\n'], 'output': ['NO\r\n']}, {'input': ['Ht15T@50eo.E@.\r\n'], 'output': ['NO\r\n']}, {'input': ['k9MITs_Ar.JL2RRs4@VRq.wCuJ.6..amF.fE4.5I.6fJ7gz7\r\n'], 'output': ['NO\r\n']}, {'input': ['Mi\x7fWPE8@fc./IViqq4T4PSUuMdhH\r\n'], 'output': ['NO\r\n']}, {'input': ['pxSCmv!NbMvz2@pTQ.t!.Ntz/QEh_sl\r\n'], 'output': ['NO\r\n']}, {'input': ['s@mH@RO\x7f_/iWD\r\n'], 'output': ['NO\r\n']}, {'input': ['UP51i49wX@pvx@2LWm8w/G4M3J./9L6Szy\r\n'], 'output': ['NO\r\n']}, {'input': ['xC_5Vx8NgF..\x7fln@X1.drRTX..1vx.Xb3of@/PQYPeq@_y8!h_iF\r\n'], 'output': ['NO\r\n']}, {'input': ['qG3@LKp\r\n'], 'output': ['YES\r\n']}, {'input': ['flTq1knyb@2!Mtfss\r\n'], 'output': ['NO\r\n']}, {'input': ['/pqi7WXQPJFM4q1@hxUyUy\x7f/_pWo0n\r\n'], 'output': ['NO\r\n']}, {'input': ['zXme@.Dq.TWBs.fB.M\r\n'], 'output': ['NO\r\n']}, {'input': ['o3EaAnc3K6@h\r\n'], 'output': ['YES\r\n']}, {'input': ['G/AZdVMTzRLV4Ucm@eQ!..pq!..tRTi5.Ejkqa/HGpFYk\r\n'], 'output': ['NO\r\n']}, {'input': ['.c_V@L.1v!AFAEk7glM\x7fq.ag8Sy8@0.Qm/OLKoJpZlac\r\n'], 'output': ['NO\r\n']}, {'input': ['WKxNIM79u\x7f@I.RM\r\n'], 'output': ['NO\r\n']}, {'input': ['POTjlYcxAZsbyZPDh@sPm.z6aVaO.H1wEUhD9YvROQFUk/M_jTHS_6!\r\n'], 'output': ['NO\r\n']}, {'input': ['pbRIiuA@KZ2hVed2fMikA.@ebd.tE2Y\r\n'], 'output': ['NO\r\n']}, {'input': ['OlS_OwxYhH@im.0A7o/juNlxB\r\n'], 'output': ['YES\r\n']}, {'input': ['xkjHHDRBEFwgNP@G9TGStEs2Lu.BJge3EBXw3c9EfE\r\n'], 'output': ['YES\r\n']}, {'input': ['bK@8X7tQO.pXBHJpDewD\r\n'], 'output': ['YES\r\n']}, {'input': ['kKUXy6@0WefbXz39ywP.Q3r7uF\r\n'], 'output': ['YES\r\n']}, {'input': ['SllbRLdZ6@.T.E3x.BE2nIv.5db_.38./zgVGNjpldr\r\n'], 'output': ['NO\r\n']}, {'input': ['4lBJkY8c097oa@ZYmVbtiyyYN.gbj\r\n'], 'output': ['YES\r\n']}, {'input': ['F@JX4.SI1/0EY3XmYatfY\r\n'], 'output': ['YES\r\n']}, {'input': ['oLo01@B77Pu.9R.vtAZG0.HQSunv0J.\r\n'], 'output': ['NO\r\n']}, {'input': ['xLEctap0T@22U9W_fA/7iQeJGFu1lSgMZ\r\n'], 'output': ['YES\r\n']}, {'input': ['WYh@yUWfOQiF.gOK9k8aEa\r\n'], 'output': ['YES\r\n']}, {'input': ['BPxNVANhtEh@Oh_go.\r\n'], 'output': ['NO\r\n']}, {'input': ['mGIY@cHRNC8GlJ/2pcl3LYxpi3PaKGs\r\n'], 'output': ['YES\r\n']}, {'input': ['x6yfn7BGwqWd@.N/UXC\r\n'], 'output': ['NO\r\n']}, {'input': ['cUIr@cP.eGQC2xJXvI1X7\r\n'], 'output': ['YES\r\n']}, {'input': ['MLZ6e1vgZ4hOI@ktWk.Ro.o6C4/i8cnKHT\r\n'], 'output': ['YES\r\n']}, {'input': ['XCJIa@jFaP.Eu28YaoT9Z.Epk.Z/4TBzLWf724zE1r\r\n'], 'output': ['YES\r\n']}, {'input': ['Cz1U1xjg6iW0U@.97HoVA.YG.Qd.eI.DCXxtibi6HG.GV/0sN\r\n'], 'output': ['NO\r\n']}, {'input': ['nrKbWV@P0irxQoRxDsNvG/69WxCwCsfB\r\n'], 'output': ['YES\r\n']}, {'input': ['yI1nRv3FbuhgaI@.Y9vKe.8oc.BLi.6JfYT/tT5d36\r\n'], 'output': ['NO\r\n']}, {'input': ['IGsma3L6YTJRrXS@1g.yR3mC.c.xoCns7Wo1.9C.Oe.5ebkR/_97Ltj3\r\n'], 'output': ['YES\r\n']}, {'input': ['Uu538LDu9Bye@Gu0W0P5a.b9zA9nSaNhzB_TQ2.z/qfi5CZrH\r\n'], 'output': ['YES\r\n']}, {'input': ['bdHl525me@XzR_iO23v.YFXbnHUybbgw.i/WVEhm\r\n'], 'output': ['YES\r\n']}, {'input': ['NQsZ0K@eE8VMB.w2nYtKImB.4nUF\r\n'], 'output': ['YES\r\n']}, {'input': ['186@E.MmBaKLj.WYpt4wPZkzv93\r\n'], 'output': ['YES\r\n']}, {'input': ['hmhYxkGtWYRJFtBU@Drg3L7WKujE.lU61Ljqxv./FJ4X\r\n'], 'output': ['NO\r\n']}, {'input': ['t1RIUz9l3FA15@tOL9.rv.NjhouD.\r\n'], 'output': ['NO\r\n']}, {'input': ['_I4ytjyccT@q.WIc.Cqn\r\n'], 'output': ['YES\r\n']}, {'input': ['LwHHRYq@whOoq.e9b6i0xnoWBl7z.SGJiJe/iUij1x7\r\n'], 'output': ['YES\r\n']}, {'input': ['Yesx@9_KiJq2cBI6.\r\n'], 'output': ['NO\r\n']}, {'input': ['Zu5VFUtSbIw@ner5e\r\n'], 'output': ['YES\r\n']}, {'input': ['test@test.\r\n'], 'output': ['NO\r\n']}, {'input': ['test@.test\r\n'], 'output': ['NO\r\n']}, {'input': ['est.@test\r\n'], 'output': ['NO\r\n']}, {'input': ['test@test.ru/\r\n'], 'output': ['NO\r\n']}, {'input': ['asd@asd@\r\n'], 'output': ['NO\r\n']}, {'input': ['@\r\n'], 'output': ['NO\r\n']}, {'input': ['/\r\n'], 'output': ['NO\r\n']}, {'input': ['.\r\n'], 'output': ['NO\r\n']}, {'input': ['mike@\r\n'], 'output': ['NO\r\n']}, {'input': ['@mike\r\n'], 'output': ['NO\r\n']}, {'input': ['@mail.ru\r\n'], 'output': ['NO\r\n']}, {'input': ['test.me\r\n'], 'output': ['NO\r\n']}, {'input': ['$@ru\r\n'], 'output': ['NO\r\n']}, {'input': ['testme@o.o.o.o.o/ooooo\r\n'], 'output': ['YES\r\n']}, {'input': ['oooop/oooop\r\n'], 'output': ['NO\r\n']}, {'input': ['mail.ru/a\r\n'], 'output': ['NO\r\n']}, {'input': ['mike@mail.ru/aaa\r\n'], 'output': ['YES\r\n']}, {'input': ['mike@mike.mike\r\n'], 'output': ['YES\r\n']}]


A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.Help Vasya's teacher, find two numbers — the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.

The first line contains two space-separated integers n,x (1≤n≤10^5; 0≤x≤2·10^5) — the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains n space-separated integers: a1,a2,...,an (0≤ai≤10^5) — the participants' points in the first tour.
The third line contains n space-separated integers: b1,b2,...,bn (0≤bi≤10^5) — the participants' points in the second tour.
The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad — there are two integers i,j (1≤i,j≤n) such, that ai+bj≥x.

Print two space-separated integers — the best and the worst place Vasya could have got on the Olympiad.

In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that — {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.
In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.
In the worst case scenario Vasya can get the fifth place if the table looks like that — {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly.


One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point (0,0,0), and the opposite one is at point (x1,y1,z1). The six faces of the box contain some numbers a1,a2,...,a6, exactly one number right in the center of each face. The numbers are located on the box like that:   number a1 is written on the face that lies on the ZOX plane;  a2 is written on the face, parallel to the plane from the previous point;  a3 is written on the face that lies on the XOY plane;  a4 is written on the face, parallel to the plane from the previous point;  a5 is written on the face that lies on the YOZ plane;  a6 is written on the face, parallel to the plane from the previous point. At the moment Vasya is looking at the box from point (x,y,z). Find the sum of numbers that Vasya sees. Note that all faces of the box are not transparent and Vasya can't see the numbers through the box. The picture contains transparent faces just to make it easier to perceive. You can consider that if Vasya is looking from point, lying on the plane of some face, than he can not see the number that is written on this face. It is enough to see the center of a face to see the corresponding number for Vasya. Also note that Vasya always reads correctly the ai numbers that he sees, independently of their rotation, angle and other factors (that is, for example, if Vasya sees some ai=6, then he can't mistake this number for 9 and so on).

The fist input line contains three space-separated integers x, y and z (|x|,|y|,|z|≤10^6) — the coordinates of Vasya's position in space. The second line contains three space-separated integers x1, y1, z1 (1≤x1,y1,z1≤10^6) — the coordinates of the box's vertex that is opposite to the vertex at point (0,0,0). The third line contains six space-separated integers a1,a2,...,a6 (1≤ai≤10^6) — the numbers that are written on the box faces.
It is guaranteed that point (x,y,z) is located strictly outside the box.

Print a single integer — the sum of all numbers on the box faces that Vasya sees.

The first sample corresponds to perspective, depicted on the picture. Vasya sees numbers a2 (on the top face that is the darkest), a6 (on the right face that is the lightest) and a4 (on the left visible face).
In the second sample Vasya can only see number a4.


Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an n×m chessboard, a very tasty candy and two numbers a and b.Dima put the chessboard in front of Inna and placed the candy in position (i,j) on the board. The boy said he would give the candy if it reaches one of the corner cells of the board. He's got one more condition. There can only be actions of the following types:  move the candy from position (x,y) on the board to position (x-a,y-b);  move the candy from position (x,y) on the board to position (x+a,y-b);  move the candy from position (x,y) on the board to position (x-a,y+b);  move the candy from position (x,y) on the board to position (x+a,y+b). Naturally, Dima doesn't allow to move the candy beyond the chessboard borders.Inna and the pony started shifting the candy around the board. They wonder what is the minimum number of allowed actions that they need to perform to move the candy from the initial position (i,j) to one of the chessboard corners. Help them cope with the task!

The first line of the input contains six integers n,m,i,j,a,b (1≤n,m≤10^6; 1≤i≤n; 1≤j≤m; 1≤a,b≤10^6).
You can assume that the chessboard rows are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. Position (i,j) in the statement is a chessboard cell on the intersection of the i-th row and the j-th column. You can consider that the corners are: (1,m), (n,1), (n,m), (1,1).

In a single line print a single integer — the minimum number of moves needed to get the candy.
If Inna and the pony cannot get the candy playing by Dima's rules, print on a single line "Poor Inna and pony!" without the quotes.

Note to sample 1:
Inna and the pony can move the candy to position (1+2,3+2)=(3,5), from there they can move it to positions (3-2,5+2)=(1,7) and (3+2,5+2)=(5,7). These positions correspond to the corner squares of the chess board. Thus, the answer to the test sample equals two.


#!usr/bin/perl
use warnings;
use strict;

sub win($){
    my $bard=shift;
    if(($bard=~/[X]{3}/)||($bard=~/[0]{3}/)){
	return 1;
    }
    elsif(($bard=~/[X].{3}[X].{3}[X]/)||($bard=~/[0].{3}[0].{3}[0]/)){
	return 1;
    }
    elsif(($bard=~/[X].{4}[X].{4}[X]/)||($bard=~/[0].{4}[0].{4}[0]/)){
	return 1;
    }
    elsif(($bard=~/..[X].{2}[X].{2}[X]/)||($bard=~/..[0].{2}[0].{2}[0]/)){
	return 1;
    }
    else{
	return 0;
    }
}

my $fl=<STDIN>;chomp($fl);my $sl=<STDIN>;chomp($sl);my $tl=<STDIN>;chomp($tl);
my $board=$fl.' '.$sl.' '.$tl;
my $boz=$board=~s/[X]//rg;my $box=$board=~s/[0]//rg;my $bod=$board=~s/[\.]//rg;
my $k=length($box)<length($boz);
if($k||(length($box)-length($boz)>1)){
    print "illegal\n";
}
else{
    if(win($board)){
	my $blz=$board=~s/[X]/P/rg;my $blx=$board=~s/[0]/P/rg;
	if(win($blz)||win($blx)){
	    print "illegal\n";
	}
	else{
	    if(length($bod)%2==0){
		print "the second player won\n";
	    }
	    else{
		print "the first player won\n";
	    }
	}
    }
    elsif(length($bod)==11){
	print "draw\n";
    }
    else{
	if(length($bod)%2==0){
	    print "first\n";
	}
	else{
	    print "second\n";
	}
    }
}

Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3×3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is announced.You are given a 3×3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below:   illegal — if the given board layout can't appear during a valid game;  the first player won — if in the given board layout the first player has just won;  the second player won — if in the given board layout the second player has just won;  draw — if the given board layout has just let to a draw.

The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero).

Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw.

#!usr/bin/perl
use warnings;
use strict;

sub win($){
    my $bard=shift;
    if(($bard=~/[X]{3}/)||($bard=~/[0]{3}/)){
	return 1;
    }
    elsif(($bard=~/[X].{3}[X].{3}[X]/)||($bard=~/[0].{3}[0].{3}[0]/)){
	return 1;
    }
    elsif(($bard=~/[X].{4}[X].{4}[X]/)||($bard=~/[0].{4}[0].{4}[0]/)){
	return 1;
    }
    elsif(($bard=~/..[X].{2}[X].{2}[X]/)||($bard=~/..[0].{2}[0].{2}[0]/)){
	return 1;
    }
    else{
	return 0;
    }
}

my $fl=<STDIN>;chomp($fl);my $sl=<STDIN>;chomp($sl);my $tl=<STDIN>;chomp($tl);
my $board=$fl.' '.$sl.' '.$tl;
my $boz=$board=~s/[X]//rg;my $box=$board=~s/[0]//rg;my $bod=$board=~s/[\.]//rg;
my $k=length($box)<length($boz);
if($k||(length($box)-length($boz)>1)){
    print "illegal\n";
}
else{
    if(win($board)){
	my $blz=$board=~s/[X]/P/rg;my $blx=$board=~s/[0]/P/rg;
	if(length($bod)%2==0){
	    if(win($blx)){
		print "illegal\n";
	    }
	    else{
		print "the second player won\n";
	    }
	}
	else{
	    if(win($blz)){
		print "illegal\n";
	    }
	    else{
		print "the first player won\n";
	    }
	}
    }
    elsif(length($bod)==11){
	print "draw\n";
    }
    else{
	if(length($bod)%2==0){
	    print "first\n";
	}
	else{
	    print "second\n";
	}
    }
}


sub compare { $a <=> $b }
sub max { my ($a, $b) = @_; $a > $b? $a: $b }

(undef, @input) = <STDIN>;
for (@input) { push @p, (split)[0] }
@p = sort compare @p;

for $p (@p) {
	$d = max $p, $d;
	push @r, $d;
	$d++;
}

print "@r";

On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li,ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.

The first line contains one integer n (1≤n≤100) — the number of known events. Then follow n lines containing two integers li and ri each (1≤li≤ri≤10^7) — the earliest acceptable date and the latest acceptable date of the i-th event.

Print n numbers — the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.

sub max { my ($a, $b) = @_; $a > $b? $a: $b }
sub priority { max($a->{start}, $current) <=> max($b->{start}, $current) || $a->{end} <=> $b->{end} }

(undef, @input) = <STDIN>;
for (@input) {
	@val = split;
	push @p, {start => $val[0], end => $val[1], index => $i++ }
}

while (@p) {
	($p, @p) = sort priority @p;
	$current = max $p->{start}, $current;
	$r[ $p->{index} ] = $current++;
}

print "@r";


Stepan has n pens. Every day he uses them, and on the i-th day he uses the pen number i. On the (n+1)-th day again he uses the pen number 1, on the (n+2)-th — he uses the pen number 2 and so on.On every working day (from Monday to Saturday, inclusive) Stepan spends exactly 1 milliliter of ink of the pen he uses that day. On Sunday Stepan has a day of rest, he does not stend the ink of the pen he uses that day. Stepan knows the current volume of ink in each of his pens. Now it's the Monday morning and Stepan is going to use the pen number 1 today. Your task is to determine which pen will run out of ink before all the rest (that is, there will be no ink left in it), if Stepan will use the pens according to the conditions described above.

The first line contains the integer n (1≤n≤50000) — the number of pens Stepan has.
The second line contains the sequence of integers a1,a2,...,an (1≤ai≤10^9), where ai is equal to the number of milliliters of ink which the pen number i currently has.

Print the index of the pen which will run out of ink before all (it means that there will be no ink left in it), if Stepan will use pens according to the conditions described above.
Pens are numbered in the order they are given in input data. The numeration begins from one.
Note that the answer is always unambiguous, since several pens can not end at the same time.

In the first test Stepan uses ink of pens as follows:
  on the day number 1 (Monday) Stepan will use the pen number 1, after that there will be 2 milliliters of ink in it;  on the day number 2 (Tuesday) Stepan will use the pen number 2, after that there will be 2 milliliters of ink in it;  on the day number 3 (Wednesday) Stepan will use the pen number 3, after that there will be 2 milliliters of ink in it;  on the day number 4 (Thursday) Stepan will use the pen number 1, after that there will be 1 milliliters of ink in it;  on the day number 5 (Friday) Stepan will use the pen number 2, after that there will be 1 milliliters of ink in it;  on the day number 6 (Saturday) Stepan will use the pen number 3, after that there will be 1 milliliters of ink in it;  on the day number 7 (Sunday) Stepan will use the pen number 1, but it is a day of rest so he will not waste ink of this pen in it;  on the day number 8 (Monday) Stepan will use the pen number 2, after that this pen will run out of ink. So, the first pen which will not have ink is the pen number 2.


program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,math;

var
  a:array[0..101,0..101] of boolean;
  b:array[0..101] of longint;
  i,j,n,m,x,y,k,ans:longint;

begin
  read(n,m);
  for i:=1 to n do
    read(b[i]);
  for i:=1 to m do
    begin
      read(x,y);
      a[x][y]:=true;
      a[y][x]:=true;
    end;
  ans:=maxlongint;
  for i:=1 to n do
    for j:=1 to n do
      for k:=1 to n do
        if (a[i][j]) and (a[i][k]) and (a[k][j]) then
           ans:=min(ans,b[i]+b[j]+b[k]);
  writeln(ans);
end.

A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap.Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend.

The first input file line contains integers n and m — the total number of clothing items in the shop and the total number of matching pairs of clothing items ().
Next line contains n integers ai (1≤ai≤10^6) — the prices of the clothing items in rubles.
Next m lines each contain a pair of space-separated integers ui and vi (1≤ui,vi≤n,ui≠vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui,vi) are different.

Print the only number — the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes).

In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way — to buy the 3 pieces of clothing; in this case he spends 6 roubles.
The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1.
In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.

{$R+ Q+ I+}
{$APPTYPE CONSOLE}
uses
  Sysutils;
var
   c : array[1..100,1..100] of boolean;
   a : array[1..100] of integer;
   s,min,m,n,i,j,k,x,y : integer;
begin
    read(n,m);
    for i := 1 to n do read(a[i]);
    for i := 1 to m do begin
        read(x,y);
        c[x][y] := true;
        c[y][x] := true;
    end;
    min := high(min);
    for i := 1 to n - 2 do begin
        s := a[i];
        for j := i + 1 to n - 1 do
            if (c[i][j] = true) then begin
                s := s + a[j];
                for k := j + 1 to n do
                    if (c[j][k] = true) and (c[i][k] = true) then begin
                        s := s + a[k];
                        if s < min then min := s;
                        s := s - a[k];
                    end;
                s := s - a[j];
            end;
    end;
    if min = high(min) then min := -1;
    write(min);

end.


program passwordick;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
    a: array [1..100]of integer;
    n, m, i, max, s: integer;
begin
    readln (n);
    readln (m);
    max := -1;
    for i := 1 to n do
    begin
        readln (a[i]);
        if a[i] > max then
            max := a[i];
    end;

    s := 0;
    for i := 1 to n do
        s := s + max - a[i];

    i := (m - s)div n + max;
    //writeln (n,' ',m,' ',s,' ',max,' ',i );
    if ((m - s) mod n > 0) then
        inc(i);
    writeln (i, ' ', max + m);
    readln;
end.

There are $$$n$$$ benches in the Berland Central park. It is known that $$$a_i$$$ people are currently sitting on the $$$i$$$-th bench. Another $$$m$$$ people are coming to the park and each of them is going to have a seat on some bench out of $$$n$$$ available.Let $$$k$$$ be the maximum number of people sitting on one bench after additional $$$m$$$ people came to the park. Calculate the minimum possible $$$k$$$ and the maximum possible $$$k$$$.Nobody leaves the taken seat during the whole process.

The first line contains a single integer $$$n$$$ $$$(1 \\le n \\le 100)$$$ — the number of benches in the park.
The second line contains a single integer $$$m$$$ $$$(1 \\le m \\le 10\\,000)$$$ — the number of people additionally coming to the park.
Each of the next $$$n$$$ lines contains a single integer $$$a_i$$$ $$$(1 \\le a_i \\le 100)$$$ — the initial number of people on the $$$i$$$-th bench.

Print the minimum possible $$$k$$$ and the maximum possible $$$k$$$, where $$$k$$$ is the maximum number of people sitting on one bench after additional $$$m$$$ people came to the park.

In the first example, each of four benches is occupied by a single person. The minimum $$$k$$$ is $$$3$$$. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining — the fourth bench. The maximum $$$k$$$ is $$$7$$$. That requires all six new people to occupy the same bench.
The second example has its minimum $$$k$$$ equal to $$$15$$$ and maximum $$$k$$$ equal to $$$15$$$, as there is just a single bench in the park and all $$$10$$$ people will occupy it.

                   const eps=0.000000001;  besk1=200000008;  nn=2600000;
             { modul=1000000007;  }
   besk=8000000000000000000;
   label 22,1,2,3,4;
    type    real=extended;   double=extended;
    mas=array [-100000..nn] of int64;   point=record x,y,z:real;end;
    zap=record p1,p2,p3 :int64;end; zap1=^zap;
    mass=array[0..nn] of longint;mass1=^mass;
    var kol,sq,sum,h,pmin,pmax,limit,posi,posj,diam,modul,oldt,ot1,time,pos,prod,ll,rr,posx,posy,gr,n,dloch,newdl,oldn,oldm,ost,ot,aa,bb,cc,p1,p2,p3,p4,kk,znamzz,kolperiod,znam,tperiod,start,finish,kol1,kol2,lavel,x0,p0,t2,t1,jj,w,ii,ogr,q,p,pp,tt,oldtt,qq,qq1,qq2,q1,q2,imax,t,nm,m,smin,cen:int64;
   pp0,mask,k,i1,j1,step1, step, i,j:longint;
   y:mas;
    ppp,prob1,prob2,prob3,pr1new,pr2new,pr3new,pr1,pr2,pr3:zap;
    oldpos,finot,vv,znak:int64;
    aold:mas;
    sumkonfig,konfig:array[-1000..200000,-1..10] of int64;
    xleft,xright,xplus,xminus,px,py,xc,yc,xxc,yyc:extended;
    del:array[-1..100001,-1..150] of longint;
    x1,y1,z1,z2,kolnul,a,fact,next,prev,x,xx,yy,str,s,name,d,dnew, voltay,l,r,c,z,day,b:mas;
    zz:array[0..125000000] of byte;
    ppole:array[-10..1002,-10..1005] of char;
    pole,ddd,dd2,dd3,dd4,dd:array[-10..4201,-10..4220] of int64;
    dd1,ddsum:array[-1..4200,-1..100] of int64;
   newzan,marked,zanx,zany:array[-1000000..2000000] of boolean;
    sss1,sss2:string;
    def,left,right,udal,stepen,koled,dl,och,newoch,place,newnabor,stoim,nabor:array[-10..200005] of int64;
     zanleft,zanright,zan,fl:array[-100000..10000000] of boolean;
    ss1,ss2,ss:string;ch,ch1,ch2:char;
    pr,hesh,numright,dr: array [-10..1060,-10..1060] of extended;
    s3,s2,s1:array[-100..500000] of string;

    grr :array [-10..2010,-10..2010] of boolean;
    maxpr:array[0..nn] of string;
    sss:array[-10..nn] of string;
     tx,ty,vel,ott,v0,v1,s0,t0:int64;
     zv:point;
     ugol,rot,temp,sumtemp,vol,newx,newy:array[-1000..400000] of int64;
     mash,sqx,sqy,ottt,aaa,bbb,ccc:extended;
     xxx,yyy,yot:double;
       flag2,flag,flag1:boolean;

  function max(a,b:int64):int64;
begin max:=a; if b>a then max:=b;   end;

  function min(a,b:int64):int64;
begin min:=a; if b<a then min:=b;   end;

      function nod(x,y:int64):int64; var z:int64;
begin   repeat  z:=x mod y;x:=y;y:=z;   until  z=0 ;  nod:=x;end;

     function summ(xx,yy:zap):zap1;
var t1,t2,tt:int64; ott:zap;
 begin
    t1:=(xx.p1*yy.p2+xx.p2*yy.p1) mod modul;
    t2:=(xx.p2*yy.p2) mod modul;
    tt:=nod(t1,t2);
    t1:=t1 div tt mod modul;
    t2:=t2 div tt mod modul;
    ott.p1:=t1; ott.p2:=t2;

   summ:=@ott;
 end;

{     function prod(xx,yy:zap):zap1;
var t1,t2,tt:int64; ott:zap;
 begin
    t1:=(xx.p1*yy.p1) mod modul;
    t2:=(xx.p2*yy.p2) mod modul;
    tt:=nod(t1,t2);
    t1:=(t1 div tt) mod modul;
    t2:=(t2 div tt) mod modul;
    ott.p1:=t1; ott.p2:=t2;

   prod:=@ott;
 end;
 }

    function al(x,y:real):real; var t0,t1,p,s0,s1:real;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     al:=p{/pi*180};
 end;

function degg(a,k:int64):int64; var p:int64;
begin
 if k<=0 then degg:=1 else if odd(k) then degg:=degg(a,k-1)*a mod modul else
   begin  p:=degg(a,k shr 1); degg:=p*p mod modul;   end;

end;

{function prost(tt:longint):boolean;
var aa:extended; i,p,t:longint;  fl:boolean;
 begin
   fl:=true;
   aa:=tt;
   aa:=sqrt(aa);
   t:=round(aa);
   for i:=2 to t do if tt mod i=0 then fl:=false;

   prost:=fl;
 end;
 }
function arcsin(pp:extended):extended;
var tt:extended;
begin
   if (abs(pp)<=1+eps)and (abs(pp)>=1-eps)
   then if pp>0 then arcsin:=pi/2 else arcsin:=-pi/2;
   tt:=1-pp*pp;
   if abs(tt)>=0 then
     begin
        arcsin:=arctan(pp/sqrt(tt));

     end;

end;

function gl(ch:char):boolean;
begin
 if (ch='o')or (ch='a')or(ch='e')or(ch='u')or(ch='i') then gl:=true else gl:=false;

end;

function zaprmax(left,right:longint):int64;
begin
   if left>=right then zaprmax:=y[left] else
     begin
        if not odd(left) and odd(right) then zaprmax:=zaprmax(left shr 1,right shr 1) else
         begin
          if odd(left) then zaprmax:=max(zaprmax(left+1,right),y[left]);
          if not odd(right) then zaprmax:=max(zaprmax(left,right-1),y[right]);

         end;

     end;

end;

 function ff(gr:int64):boolean;

var ot,aa,bb,cc:int64; fl:boolean;
begin
  aa:=1; bb:=m;  cc:=aa; fl:=false;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if y[cc]<gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,m+1);
   repeat dec(cc) until y[cc]<=gr;
   if y[cc]=gr then fl:=true else fl:=false;
  ff:=fl;
end;

begin
   { assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
    }
      read(n,k);
      for i:=1 to n do read(a[i]);
      pmax:=0; for i:=1 to n do pmax:=max(pmax,a[i]);
      sum:=0;      for i:=1 to n do sum:=sum+a[i];
        p1:=max((sum+k+n-1) div n,pmax);
        p2:=pmax+k;

       write(p1,' ',p2);

   1:          close(output);
end.


program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils, Math;

var
  list, head, next, mark: array[1..2000] of integer;
  i, ct, pos, s, ans, n: integer;

procedure add (a, b: integer);
begin
  inc(pos);
  list[pos] := b;
  next[pos] := head[a];
  head[a] := pos;
end;

procedure dfs(v: integer);
var
  i: integer;
begin
  mark[v] := 1;
  inc(ct);
  ans := max(ans, ct);
  i := head[v];
  while (i <> 0) do begin
    if (mark[list[i]] <> 1) then
      dfs(list[i]);
    i := next[i];
  end;
  dec(ct);
end;

begin
  //s
  readln(n);
  pos := 0;
  ans := 0;
  for i := 1 to n do begin
    readln(s);
    if (s <> -1) then
      add(i, s);
  end;
  for i := 1 to n do
    if (mark[i] <> 1) then begin
      ct := 0;
      dfs(i);
    end;

  writeln(ans);
  readln;
  readln;
end.

A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B if at least one of the following is true:  Employee A is the immediate manager of employee B  Employee B has an immediate manager employee C such that employee A is the superior of employee C. The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.Today the company is going to arrange a party. This involves dividing all n employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees A and B such that A is the superior of B.What is the minimum number of groups that must be formed?

The first line contains integer n (1≤n≤2000) — the number of employees.
The next n lines contain the integers pi (1≤pi≤n or pi=-1). Every pi denotes the immediate manager for the i-th employee. If pi is -1, that means that the i-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (pi≠i). Also, there will be no managerial cycles.

Print a single integer denoting the minimum number of groups that will be formed in the party.

For the first example, three groups are sufficient, for example:
  Employee 1  Employees 2 and 4  Employees 3 and 5

var a:array[1..2000]of Integer;
    b:array[1..2000]of Boolean;
i,n,r,t:Integer;
function max(x:integer):Integer;
begin
  if a[x]=-1
  then max:=1
  else max:=max(a[x])+1;
end;
begin
  //reset(input,'input.txt');
  //rewrite(output,'output.txt');
  Readln(n);
  for i:=1 to n do
  Readln(a[i]);
  r:=-1;
  for i:=1 to n do
    begin
      t:=max(i);
      if t>r
      then r:=t;
    end;
    Writeln(r);
end.


program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const
  Divisors: array[1..5] of Integer
    = (4, 7, 44, 47, 74);

var
  I, n: Integer;
  isDivisible: Boolean;

begin
  readln(n);

  isDivisible := false;

  for I := Low(Divisors) to High(Divisors) do
  begin
    isDivisible := (n mod Divisors[I]) = 0;
    if isDivisible then
      break;
  end;

  if isDivisible then
    writeln('YES')
  else
    writeln('NO');

  readln;
end.

Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number n is almost lucky.

The single line contains an integer n (1≤n≤1000) — the number that needs to be checked.

In the only line print "YES" (without the quotes), if number n is almost lucky. Otherwise, print "NO" (without the quotes).

Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const
  Divisors: array[1..12] of Integer
    = (4, 7, 44, 47, 74, 444, 447, 474, 477, 744, 747, 777);

var
  I, n: Integer;
  isDivisible: Boolean;

begin
  readln(n);

  isDivisible := false;

  for I := Low(Divisors) to High(Divisors) do
  begin
    isDivisible := (n mod Divisors[I]) = 0;
    if isDivisible then
      break;
  end;

  if isDivisible then
    writeln('YES')
  else
    writeln('NO');

  readln;
end.


program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
        var n,s,i,z:integer;
    a: array of integer;
    q:boolean;
begin
  { TODO -oUser -cConsole Main : Insert code here }

 readln(n);
 setlength(a,n);
 s:=0;
 z:=0;
 for i:=0 to n-1 do
   begin
   read(a[i]);
   s:=a[i]+s;
   end;
    // if s=1 then z:=1;
   if s mod 2 <> 0 then q:=false
   else q:=true;

   if q then begin
   for i:=0 to n-1 do
   if a[i] mod 2=0 then z:=z+1;
          end;
   if not q then begin
   for i:=0 to n-1 do
    if s-a[i] mod 2=0 then z:=z+1;
    end;
    writeln(z);
    readln;
    readln;
end.

Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?

The first line contains the only integer n (1≤n≤100) — the number of cookie bags Anna and Maria have. The second line contains n integers ai (1≤ai≤100) — the number of cookies in the i-th bag.

Print in the only line the only number — the sought number of ways. If there are no such ways print 0.

In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5+3=8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2*9+99=117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies.

{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O-,P+,Q-,R+,S+,T-,U-,V+,W-,X+,Y+,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE CONSOLE}

const filename='x';
      oo=maxlongint div 2;
      eps=1e-6;
      eee=1e-21;

var qq,cc,a,aa:array[0..1000000]of longint;
    qc:array[0..2000,0..2000]of int64;
    ss:array[0..1000]of string;
    s,s0,s1,s2,s3:string;
    x,y,z,xx,yy,zz,x0,y0,z0,x1,x2,x3,y1,y2,y3,z1,z2,z3:extended;
    res,cur:int64;
    u,v,nt,ii,jj,kk,nn,mm,n,m,q,c,q0,c0,q1,c1,q2,c2,q3,c3,max,min:longint;
    test,ll,t,tt:longint;
    b,bb,bbb,b0,b1,b2,b3:boolean;

procedure init;
  begin
  assign(input,filename+'.in');
  assign(output,filename+'.out');
  reset(input);
  rewrite(output);
  end;

procedure fin;
  begin
  close(input);
  close(output);
  end;

procedure clear;
var i,j,k:longint;
  begin
  fillchar(qc,sizeof(qc),0);
  end;

procedure load;
var i,j,k:longint;
  begin
  end;

procedure save;
var i,j,k:longint;
  begin
  end;

procedure run;
var i,j,z:longint;
    k,m:int64;
  begin
  //init;
  read(n);
  for i:=1 to n do
    begin
    read(qq[i]);
    inc(cur,qq[i]);
    end;
  res:=0;
  for i:=1 to n do
    if ((cur-qq[i]) mod 2 = 0) then inc(res);
  writeln(res);
  end;

begin
nt:=1;
//readln(nt);
for test:=1 to nt do
  begin
  clear;
  load;
  run;
  save;
  end;
end.