Sereja loves integer sequences very much. He especially likes stairs.Sequence a1, a2, ..., a|a| (|a| is the length of the sequence) is stairs if there is such index i (1 ≤ i ≤ |a|), that the following condition is met: a1 < a2 < ... < ai - 1 < ai > ai + 1 > ... > a|a| - 1 > a|a|.For example, sequences [1, 2, 3, 2] and [4, 2] are stairs and sequence [3, 1, 2] isn't.Sereja has m cards with numbers. He wants to put some cards on the table in a row to get a stair sequence. What maximum number of cards can he put on the table?

The first line contains integer m (1 ≤ m ≤ 105) — the number of Sereja's cards. The second line contains m integers bi (1 ≤ bi ≤ 5000) — the numbers on the Sereja's cards.

In the first line print the number of cards you can put on the table. In the second line print the resulting stairs.

#!/bin/perl

my ($n) = split /\s/, <>;
my @in = split /\s/, <>;
my @first, @second;
@in = sort {$a <=> $b} @in;
push @in, @in[-1];
for (my $i = 0; $i < $n; ++$i) {
    my $k = @in[$i];
    push @first, $k;
    if (@in[$i] == @in[$i + 1]) {
        push @second, $k;
        while ($i < $n && @in[$i] == @in[$i + 1]) {
            ++$i;
        }
    }
}
@second = reverse @second;
shift @second if @second && @second[0] == @first[-1];
print @first + @second . "\n" . join(" ", (@first, @second)) . "\n";

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

my $line1 = <>;
my $line2 = <>;
chomp($line1);
chomp($line2);

my $m = $line1;
my @cards = split(/ /, $line2);

my $max_value = 0;
my $res_num = $m;
my @cards_num = ();

foreach (@cards) {
    if (defined($cards_num[$_])) {
        $cards_num[$_]++;
        if ($cards_num[$_] > 2) { $res_num--; }
    } else {
        $cards_num[$_] = 1;
    }
    if ($_ > $max_value) { $max_value = $_; }
}

if ($cards_num[$max_value] > 1) { $res_num--; };
$cards_num[$max_value] = 1;

print "$res_num\n";
$cards_num[$max_value] = 1;
for (my $i = 1; $i <= $max_value; $i++) {
    if (defined($cards_num[$i])) {
        print "$i";
        if ($res_num > 1) {
            print " ";
            $res_num--;
        } else {
            print "\n";
            exit;
        }
        if ($cards_num[$i] == 1) { $cards_num[$i] = (undef); }
    }
}
for (my $i = $max_value; $i >= 1; $i--) {
    if (defined($cards_num[$i])) {
        print "$i";
        if ($res_num > 1) {
            print " ";
            $res_num--;
        } else {
            print "\n";
            exit;
        }
    }
}

#!/usr/bin/perl
use strict;
my $m=<STDIN>;
chomp($m);
my $in=<STDIN>;
chomp($in);
my @arr=split(' ',$in);
@arr=sort {$a<=>$b}@arr;
my @output;
@arr=reverse(@arr);
my $a=$b=$arr[0];
push @output,$arr[0];
for my $i (1..$m-1){
	if($arr[$i]<$a){
	unshift @output,$arr[$i];
	$a=$arr[$i];
	}
	elsif($arr[$i]<$b)
	{
	push @output,$arr[$i];
	$b=$arr[$i];
	}
}
my $sz=scalar(@output);
print "$sz\n";
for my $i (0..$sz-1)
{
print "$output[$i] ";
}
print "\n";
exit;

#!/usr/bin/perl

#方針
#多少処理が遅くてもいいので、
#パッと見てわかるプログラムを目指す。
#perl -e '<>;@d=sort{$b<=>$a}split(" ",<>);@v=($d[0]);map{($_<$v[$#v]&&push(@v,$_))or$_<$v[0]&&unshift(@v,$_)}@d;$n=@v;print $n,"\n","@v","\n"'

use strict;
use warnings;

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

my @vals = split " ", $line;

#降順でソート
@vals = sort{$b <=> $a} @vals;

#初期化。一番大きい値だけを持つ配列を作る。
my $val = shift @vals;
my @answer = ($val);

#値を大きい順に検索し、
#右端より小さければ右端に結合、
#左端より小さければ左端に結合を繰り返す。
foreach $val (@vals){
    if($val < $answer[$#answer]){
        push(@answer, $val);
    }elsif($val < $answer[0]){
        unshift(@answer, $val);
    }
}

$num = @answer;
print $num,"\n";
print "@answer\n";

#!/bin/perl

my ($n) = split / /, <>;
my @in = split / /, <>;
my @first, @second;
@in = sort @in;
push @in, @in[-1];
for (my $i = 0; $i < $n; ++$i) {
    my $k = @in[$i];
    push @first, $k;
    if (@in[$i] == @in[$i + 1]) {
        push @second, $k;
        while ($i < $n && @in[$i] == @in[$i + 1]) {
            ++$i;
        }
    }
}
@second = reverse @second;
shift @second if @second && @second[0] == @first[-1];
print @first + @second . "\n" . join(" ", (@first, @second)) . "\n";

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

my $line1 = <>;
my $line2 = <>;
chomp($line1);
chomp($line2);

my $m = $line1;
my @cards = split(/ /, $line2);

my $max_value = 0;
my $res_num = $m;
my @cards_num = ();

foreach (@cards) {
    if (defined($cards_num[$_])) {
        if ($cards_num[$_] > 2) { $res_num--; }
        else { $cards_num[$_] ++; }
    } else {
        $cards_num[$_] = 1;
    }
    if ($_ > $max_value) { $max_value = $_; }
}
if ($cards_num[$max_value] > 1) {
    $res_num--;
    $cards_num[$max_value] = 1;
}

print "$res_num\n";
for (my $i = 1; $i <= $max_value; $i++) {
    if (defined($cards_num[$i])) {
        print "$i";
        if ($res_num > 1) {
            print " ";
            $res_num--;
        } else {
            print "\n";
            exit;
        }
        if ($cards_num[$i] == 1) { $cards_num[$i] = (undef); }
    }
}
for (my $i = $max_value; $i >= 1; $i--) {
    if (defined($cards_num[$i])) {
        print "$i";
        if ($res_num > 1) {
            print " ";
            $res_num--;
        } else {
            print "\n";
            exit;
        }
    }
}

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

my $line1 = <>;
my $line2 = <>;
chomp($line1);
chomp($line2);

my $m = $line1;
my @cards = split(/ /, $line2);

my $max_value = 0;
my $res_num = $m;
my @cards_num = ();

foreach (@cards) {
    if (defined($cards_num[$_])) {
        $cards_num[$_]++;
    } else {
        $cards_num[$_] = 1;
    }
    if ($_ > $max_value) { $max_value = $_; }
}
$res_num = $#cards_num * 2 - 1;

print "$res_num\n";
$cards_num[$max_value] = 1;
for (my $i = 1; $i <= $max_value; $i++) {
    if (defined($cards_num[$i])) {
        print "$i";
        if ($res_num > 1) {
            print " ";
            $res_num--;
        } else {
            print "\n";
            exit;
        }
        if ($cards_num[$i] == 1) { $cards_num[$i] = (undef); }
    }
}
for (my $i = $max_value; $i >= 1; $i--) {
    if (defined($cards_num[$i])) {
        print "$i";
        if ($res_num > 1) {
            print " ";
            $res_num--;
        } else {
            print "\n";
            exit;
        }
    }
}

#!/usr/bin/perl
use strict;
my $m=<STDIN>;
my @arr;
for my $i (0..$m-1)
{
        $arr[$i]=<STDIN>;
       chomp($arr[$i]);
}
@arr=sort {$a<=>$b}@arr;
my @output;
@arr=reverse(@arr);
my $a=$b=$arr[0];
push @output,$arr[0];
for my $i (1..$m-1){
        if($arr[$i]<$a){
        unshift @output,$arr[$i];
        $a=$arr[$i];
        }
        elsif($arr[$i]<$b)
        {
        push @output,$arr[$i];
        $b=$arr[$i];
        }
}
my $sz=scalar(@output);
print "$sz\n";
for my $i (0..$sz-1)
{
print "$output[$i] ";
}
print "\n";
exit;

#!/usr/bin/perl
use strict;
my $m=<STDIN>;
my @arr;
for my $i (0..$m-1)
{
        $arr[$i]=<STDIN>;
       chomp($arr[$i]);
}
@arr=sort {$a<=>$b}@arr;
my @output;
@arr=reverse(@arr);
my $a=$b=$arr[0];
push @output,$arr[0];
for my $i (1..$m-1){
        if($arr[$i]<$a){
        unshift @output,$arr[$i];
        $a=$arr[$i];
        }
        elsif($arr[$i]<$b)
        {
        push @output,$arr[$i];
        $b=$arr[$i];
        }
}
my $sz=@output;
print "$sz\n";
my $sz=@output;
print "$sz\n";
for my $i (0..$#output)
{
print "$output[$i] ";
}
print "\n";
exit;


Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.

The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.

In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.

NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.

#!/usr/bin/perl -w

use strict;

chomp(my $n = <>);
my @a = (0, 0);
my @b = (0, 0);
for (1 .. $n) {
    chomp($_ = <>);
    my ($server, $succ, $fail) = split;
    $a[$server - 1] += $succ;
    $b[$server - 1] += 10;
}
for my $i (0 .. 1) {
    my $res = $a[$i] * 2 >= $b[$i] ? 'LIVE' : 'DEAD';
    print $res, "\n";
}


Monocarp has forgotten the password to his mobile phone. The password consists of $$$4$$$ digits from $$$0$$$ to $$$9$$$ (note that it can start with the digit $$$0$$$).Monocarp remembers that his password had exactly two different digits, and each of these digits appeared exactly two times in the password. Monocarp also remembers some digits which were definitely not used in the password.You have to calculate the number of different sequences of $$$4$$$ digits that could be the password for Monocarp's mobile phone (i. e. these sequences should meet all constraints on Monocarp's password).

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 8$$$) — the number of digits for which Monocarp remembers that they were not used in the password. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots a_n$$$ ($$$0 \le a_i \le 9$$$) representing the digits that were not used in the password. Note that the digits $$$a_1, a_2, \dots, a_n$$$ are given in ascending order.

For each testcase, print one integer — the number of different $$$4$$$-digit sequences that meet the constraints.

NoteIn the first example, all possible passwords are: "3377", "3737", "3773", "7337", "7373", "7733".


Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.

The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n).

Print m integers — the answers to the queries in the order in which they are given in the input.


You are given an integer $$$n$$$. You have to construct a permutation of size $$$n$$$.A permutation is an array where each integer from $$$1$$$ to $$$s$$$ (where $$$s$$$ is the size of permutation) occurs exactly once. For example, $$$[2, 1, 4, 3]$$$ is a permutation of size $$$4$$$; $$$[1, 2, 4, 5, 3]$$$ is a permutation of size $$$5$$$; $$$[1, 4, 3]$$$ is not a permutation (the integer $$$2$$$ is absent), $$$[2, 1, 3, 1]$$$ is not a permutation (the integer $$$1$$$ appears twice).A subsegment of a permutation is a contiguous subsequence of that permutation. For example, the permutation $$$[2, 1, 4, 3]$$$ has $$$10$$$ subsegments: $$$[2]$$$, $$$[2, 1]$$$, $$$[2, 1, 4]$$$, $$$[2, 1, 4, 3]$$$, $$$[1]$$$, $$$[1, 4]$$$, $$$[1, 4, 3]$$$, $$$[4]$$$, $$$[4, 3]$$$ and $$$[3]$$$.The value of the permutation is the number of its subsegments which are also permutations. For example, the value of $$$[2, 1, 4, 3]$$$ is $$$3$$$ since the subsegments $$$[2, 1]$$$, $$$[1]$$$ and $$$[2, 1, 4, 3]$$$ are permutations.You have to construct a permutation of size $$$n$$$ with minimum possible value among all permutations of size $$$n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. Then, $$$t$$$ lines follow. The $$$i$$$-th of them contains one integer $$$n$$$ ($$$3 \le n \le 50$$$) representing the $$$i$$$-th test case.

For each test case, print $$$n$$$ integers — the permutation of size $$$n$$$ with minimum possible value. If there are multiple such permutations, print any of them.

NoteIn the first example, the permutation $$$[1, 4, 3, 5, 2]$$$ is one of the possible answers; its value is $$$2$$$.In the second example, the permutation $$$[4, 1, 6, 2, 5, 3]$$$ is one of the possible answers; its value is $$$2$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	chomp;

	print join ' ', 1, reverse 2 .. $_;
	}


It has finally been decided to build a roof over the football field in School 179. Its construction will require placing $$$n$$$ consecutive vertical pillars. Furthermore, the headmaster wants the heights of all the pillars to form a permutation $$$p$$$ of integers from $$$0$$$ to $$$n - 1$$$, where $$$p_i$$$ is the height of the $$$i$$$-th pillar from the left $$$(1 \le i \le n)$$$.As the chief, you know that the cost of construction of consecutive pillars is equal to the maximum value of the bitwise XOR of heights of all pairs of adjacent pillars. In other words, the cost of construction is equal to $$$\max\limits_{1 \le i \le n - 1}{p_i \oplus p_{i + 1}}$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.Find any sequence of pillar heights $$$p$$$ of length $$$n$$$ with the smallest construction cost.In this problem, a permutation is an array consisting of $$$n$$$ distinct integers from $$$0$$$ to $$$n - 1$$$ in arbitrary order. For example, $$$[2,3,1,0,4]$$$ is a permutation, but $$$[1,0,1]$$$ is not a permutation ($$$1$$$ appears twice in the array) and $$$[1,0,3]$$$ is also not a permutation ($$$n=3$$$, but $$$3$$$ is in the array).

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line for each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of pillars for the construction of the roof. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_n$$$ — the sequence of pillar heights with the smallest construction cost. If there are multiple answers, print any of them.

NoteFor $$$n = 2$$$ there are $$$2$$$ sequences of pillar heights:   $$$[0, 1]$$$ — cost of construction is $$$0 \oplus 1 = 1$$$.  $$$[1, 0]$$$ — cost of construction is $$$1 \oplus 0 = 1$$$. For $$$n = 3$$$ there are $$$6$$$ sequences of pillar heights:   $$$[0, 1, 2]$$$ — cost of construction is $$$\max(0 \oplus 1, 1 \oplus 2) = \max(1, 3) = 3$$$.  $$$[0, 2, 1]$$$ — cost of construction is $$$\max(0 \oplus 2, 2 \oplus 1) = \max(2, 3) = 3$$$.  $$$[1, 0, 2]$$$ — cost of construction is $$$\max(1 \oplus 0, 0 \oplus 2) = \max(1, 2) = 2$$$.  $$$[1, 2, 0]$$$ — cost of construction is $$$\max(1 \oplus 2, 2 \oplus 0) = \max(3, 2) = 3$$$.  $$$[2, 0, 1]$$$ — cost of construction is $$$\max(2 \oplus 0, 0 \oplus 1) = \max(2, 1) = 2$$$.  $$$[2, 1, 0]$$$ — cost of construction is $$$\max(2 \oplus 1, 1 \oplus 0) = \max(3, 1) = 3$$$.


Given an array $$$a$$$ of $$$n$$$ elements, print any value that appears at least three times or print -1 if there is no such value.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 2\cdot10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq n$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

For each test case, print any value that appears at least three times or print -1 if there is no such value.

NoteIn the first test case there is just a single element, so it can't occur at least three times and the answer is -1.In the second test case, all three elements of the array are equal to $$$2$$$, so $$$2$$$ occurs three times, and so the answer is $$$2$$$.For the third test case, $$$2$$$ occurs four times, so the answer is $$$2$$$.For the fourth test case, $$$4$$$ occurs three times, so the answer is $$$4$$$.For the fifth test case, $$$1$$$, $$$2$$$ and $$$3$$$ all occur at least three times, so they are all valid outputs.For the sixth test case, all elements are distinct, so none of them occurs at least three times and the answer is -1.

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

chomp(my $t = <>);
while($t > 0) {
	chomp(my $n = <>);
	my @a = map { $_ - 0 } split /\s+/, <>;

	my %ca = ();
	my $dr = 1;
	foreach my $el (@a) {
		$ca{$el}++;
		if($ca{$el} >= 3) {
			print "$el\n";
			$dr = 0;
			last;
		}
	}
  print "-1\n" if $dr;
	$t--;
}


Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meets some condition. Let cnt(x) be the number of occurrences of number x in number d as a substring. For example, if d = 747747, then cnt(4) = 2, cnt(7) = 4, cnt(47) = 2, cnt(74) = 2. Petya wants the following condition to fulfil simultaneously: cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. Petya is not interested in the occurrences of other numbers. Help him cope with this task.

The single line contains four integers a1, a2, a3 and a4 (1 ≤ a1, a2, a3, a4 ≤ 106).

On the single line print without leading zeroes the answer to the problem — the minimum lucky number d such, that cnt(4) = a1, cnt(7) = a2, cnt(47) = a3, cnt(74) = a4. If such number does not exist, print the single number "-1" (without the quotes).


For an array $$$a$$$ of integers let's denote its maximal element as $$$\max(a)$$$, and minimal as $$$\min(a)$$$. We will call an array $$$a$$$ of $$$k$$$ integers interesting if $$$\max(a) - \min(a) \ge k$$$. For example, array $$$[1, 3, 4, 3]$$$ isn't interesting as $$$\max(a) - \min(a) = 4 - 1 = 3 < 4$$$ while array $$$[7, 3, 0, 4, 3]$$$ is as $$$\max(a) - \min(a) = 7 - 0 = 7 \ge 5$$$.You are given an array $$$a$$$ of $$$n$$$ integers. Find some interesting nonempty subarray of $$$a$$$, or tell that it doesn't exist.An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.

The first line contains integer number $$$t$$$ ($$$1 \le t \le 10\,000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n \le 2\cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0\le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in $$$a$$$.  Otherwise, output "YES" in a separate line. In the next line, output two integers $$$l$$$ and $$$r$$$ ($$$1\le l \le r \le n$$$) — bounds of the chosen subarray. If there are multiple answers, print any. You can print each letter in any case (upper or lower).

NoteIn the second test case of the example, one of the interesting subarrays is $$$a = [2, 0, 1, 9]$$$: $$$\max(a) - \min(a) = 9 - 0 = 9 \ge 4$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	@_ = split ' ', <>;

	my $ans;

	for my $i ( 0 .. @_ - 2 ){
		if( abs( $_[ $i ] - $_[ $i + 1 ] ) > 1 ){
			$ans = join ' ', $i + 1, $i + 2;
			last;
			}
		}

	print defined $ans ? "YES\n$ans" : "NO"
	}


Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2 × 2 square consisting of black pixels is formed. Pasha has made a plan of k moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers i and j, denoting respectively the row and the column of the pixel to be colored on the current move.Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2 × 2 square consisting of black pixels is formed.

The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.  The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m), representing the row number and column number of the pixel that was painted during a move.

If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed. If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0.


Let us define a magic grid to be a square matrix of integers of size $$$n \times n$$$, satisfying the following conditions.   All integers from $$$0$$$ to $$$(n^2 - 1)$$$ inclusive appear in the matrix exactly once.  Bitwise XOR of all elements in a row or a column must be the same for each row and column. You are given an integer $$$n$$$ which is a multiple of $$$4$$$. Construct a magic grid of size $$$n \times n$$$.

The only line of input contains an integer $$$n$$$ ($$$4 \leq n \leq 1000$$$). It is guaranteed that $$$n$$$ is a multiple of $$$4$$$.

Print a magic grid, i.e. $$$n$$$ lines, the $$$i$$$-th of which contains $$$n$$$ space-separated integers, representing the $$$i$$$-th row of the grid. If there are multiple answers, print any. We can show that an answer always exists.

NoteIn the first example, XOR of each row and each column is $$$13$$$.In the second example, XOR of each row and each column is $$$60$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

while( my $n = <> ){
	$debug and print '-' x 15;
	chomp $n;

	my $s = 0;

	@_ = ();
#	my @xhor = ();
#	my @xver = ();

#	for my $i ( 0 .. $n ** 2 - 1 ){
#		push @{ $_[ $i / $n ] }, sprintf "%0${n}b", $s;
#		$xhor[ $i / $n ] ^= $i;
#		$xver[ $i % $n ] ^= $i;
#		$s ++;
#		}

	for my $i ( 0 .. $n ** 2 - 1 ){
	#	push @{ $_[ 4 * int( $i / ( 4 * $n ) ) + $i % 4 ] }, sprintf "%0${n}b", $s;
		push @{ $_[ 4 * int( $i / ( 4 * $n ) ) + $i % 4 ] }, $s;
	#	$xhor[ $i / $n ] ^= $i;
	#	$xver[ $i % $n ] ^= $i;
		$s ++;
		}

#	$debug and print "@{ $_ }" for @_;

#	$debug and print "@xhor";
#	$debug and print join " ", map { sprintf "%0${n}b", $_ } @xhor;
#	$debug and print "@xver";
#	$debug and print join " ", map { sprintf "%0${n}b", $_ } @xver;

	print "@{ $_ }" for @_;
	}


There was a big bank robbery in Tablecity. In order to catch the thief, the President called none other than Albert – Tablecity’s Chief of Police. Albert does not know where the thief is located, but he does know how he moves.Tablecity can be represented as 1000 × 2 grid, where every cell represents one district. Each district has its own unique name “(X, Y)”, where X and Y are the coordinates of the district in the grid. The thief’s movement is as Every hour the thief will leave the district (X, Y) he is currently hiding in, and move to one of the districts: (X - 1, Y), (X + 1, Y), (X - 1, Y - 1), (X - 1, Y + 1), (X + 1, Y - 1), (X + 1, Y + 1) as long as it exists in Tablecity. Below is an example of thief’s possible movements if he is located in district (7,1):Albert has enough people so that every hour he can pick any two districts in Tablecity and fully investigate them, making sure that if the thief is located in one of them, he will get caught. Albert promised the President that the thief will be caught in no more than 2015 hours and needs your help in order to achieve that.

The first line of output contains integer N – duration of police search in hours. Each of the following N lines contains exactly 4 integers Xi1, Yi1, Xi2, Yi2 separated by spaces, that represent 2 districts (Xi1, Yi1), (Xi2, Yi2) which got investigated during i-th hour. Output is given in chronological order (i-th line contains districts investigated during i-th hour) and should guarantee that the thief is caught in no more than 2015 hours, regardless of thief’s initial position and movement.   N ≤ 2015  1 ≤ X ≤ 1000  1 ≤ Y ≤ 2

В этой задаче нет примеров ввода-вывода.
This problem doesn't have sample input and output.

Смотрите замечание ниже.
See the note below.

NoteLet's consider the following output:25 1 50 28 1 80 2This output is not guaranteed to catch the thief and is not correct. It is given to you only to show the expected output format. There exists a combination of an initial position and a movement strategy such that the police will not catch the thief.Consider the following initial position and thief’s movement:In the first hour, the thief is located in district (1,1). Police officers will search districts (5,1) and (50,2) and will not find him.At the start of the second hour, the thief moves to district (2,2). Police officers will search districts (8,1) and (80,2) and will not find him.Since there is no further investigation by the police, the thief escaped!


Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter. Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva.You are given an encoding s of some word, your task is to decode it.

The first line contains a positive integer n (1 ≤ n ≤ 2000) — the length of the encoded word. The second line contains the string s of length n consisting of lowercase English letters — the encoding.

NoteIn the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva.In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same.In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba.

<>;

$_ = chop( $e = <> );

s/\n\K/chop $e/e, s/(?=\n)/chop $e/e while $e;

print split

<>;

$_ = chop( $e = <> );

s/\n\K/chop $e/e, s/$/chop $e/em while $e;

print split


There is a square painted on a piece of paper, the square's side equals n meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwards, then to the left and so on). Every time he walks (n + 1) meters, he draws a cross (see picture for clarifications).John Doe stops only when the lower left corner of the square has two crosses. How many crosses will John draw?   The figure shows the order in which John draws crosses for a square with side 4. The lower left square has two crosses. Overall John paints 17 crosses.

The first line contains integer t (1 ≤ t ≤ 104) — the number of test cases.  The second line contains t space-separated integers ni (1 ≤ ni ≤ 109) — the sides of the square for each test sample.

For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.


You've got an undirected graph, consisting of n vertices and m edges. We will consider the graph's vertices numbered with integers from 1 to n. Each vertex of the graph has a color. The color of the i-th vertex is an integer ci.Let's consider all vertices of the graph, that are painted some color k. Let's denote a set of such as V(k). Let's denote the value of the neighbouring color diversity for color k as the cardinality of the set Q(k) = {cu :  cu ≠ k and there is vertex v belonging to set V(k) such that nodes v and u are connected by an edge of the graph}.Your task is to find such color k, which makes the cardinality of set Q(k) maximum. In other words, you want to find the color that has the most diverse neighbours. Please note, that you want to find such color k, that the graph has at least one vertex with such color.

The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 105) — the number of vertices end edges of the graph, correspondingly. The second line contains a sequence of integers c1, c2, ..., cn (1 ≤ ci ≤ 105) — the colors of the graph vertices. The numbers on the line are separated by spaces. Next m lines contain the description of the edges: the i-th line contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi) — the numbers of the vertices, connected by the i-th edge.  It is guaranteed that the given graph has no self-loops or multiple edges.

Print the number of the color which has the set of neighbours with the maximum cardinality. It there are multiple optimal colors, print the color with the minimum number. Please note, that you want to find such color, that the graph has at least one vertex with such color.

#!/usr/bin/perl -w

use strict;
use List::Util qw(min);

chomp($_ = <>);
my ($n, $m) = split;
chomp($_ = <>);
my @c = split;
my %edges = ();
my %count = ();

for (1 .. $m) {
    chomp($_ = <>);

    my ($u, $v) = split;
    ($u, $v) = ($c[$u - 1], $c[$v - 1]);
    ($u, $v) = ($v, $u) if $u > $v;

    next if $u == $v;
    next if exists $edges{"$u $v"};

    ++$count{$u};
    ++$count{$v};
    $edges{"$u $v"} = 1;
}

my $res = min @c;
my $cnt = -1;
while (my ($key, $val) = each %count) {
    if ($val > $cnt || ($val == $cnt && $key < $res)) {
        ($res, $cnt) = ($key, $val);
    }
}
print $res, "\n";

#!/usr/bin/perl -w

use strict;

chomp($_ = <>);
my ($n, $m) = split;
chomp($_ = <>);
my @c = split;
my %edges = ();
my %count = ();

for (1 .. $m) {
    chomp($_ = <>);

    my ($u, $v) = split;
    ($u, $v) = ($u - 1, $v - 1);
    my ($cu, $cv) = ($c[$u], $c[$v]);
    ($cu, $cv) = ($cv, $cu) if $cu > $cv;

    next if exists $edges{"$cu $cv"};
    next if $c[$u] == $c[$v];

    ++$count{$cu};
    ++$count{$cv};
    $edges{"$cu $cv"} = 1;
}

my ($res, $cnt) = ($c[0], -1);
while (my ($key, $val) = each %count) {
    if ($val > $cnt || ($val == $cnt && $key < $res)) {
        $cnt = $val;
        $res = $key;
    }
}
print $res, "\n";

#!/usr/bin/perl -w

use strict;

chomp($_ = <>);
my ($n, $m) = split;
chomp($_ = <>);
my @c = split;
my %edges = ();
my %count = ();

for (1 .. $m) {
    chomp($_ = <>);
    my ($u, $v) = split;
    ($u, $v) = ($v, $u) if $u > $v;
    ($u, $v) = ($u - 1, $v - 1);
    next if exists $edges{"$u $v"};
    next if $c[$u] == $c[$v];
    ++$count{$c[$u]};
    ++$count{$c[$v]};
    $edges{"$u $v"} = 1;
}

my ($res, $cnt) = ($c[0], -1);
while (my ($key, $val) = each %count) {
    if ($cnt == -1 || $val > $cnt || ($val == $cnt && $key < $res)) {
        $cnt = $val;
        $res = $key;
    }
}
print $res, "\n";

#!/usr/bin/perl -w

use strict;

chomp($_ = <>);
my ($n, $m) = split;
chomp($_ = <>);
my @c = split;
my %edges = ();
my %count = ();

for (1 .. $m) {
    chomp($_ = <>);

    my ($u, $v) = split;
    ($u, $v) = ($c[$u - 1], $c[$v - 1]);
    ($u, $v) = ($v, $u) if $u > $v;

    next if exists $edges{"$u $v"};
    next if $u == $v;

    ++$count{$u};
    ++$count{$v};
    $edges{"$u $v"} = 1;
}

my ($res, $cnt) = ($c[0], -1);
while (my ($key, $val) = each %count) {
    if ($val > $cnt || ($val == $cnt && $key < $res)) {
        ($res, $cnt) = ($key, $val);
    }
}
print $res, "\n";


Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other.Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (<) and the digit three (3). After applying the code, a test message looks like that: <3word1<3word2<3 ... wordn<3.Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message.Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above.

The first line contains integer n (1 ≤ n ≤ 105) — the number of words in Dima's message. Next n lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105.  The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less.

In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.

7
i
am
not
main
in
the
family
<3i<>3am<3the<3<main<3in<3the<3><3family<3

NotePlease note that Dima got a good old kick in the pants for the second sample from the statement.


Four players participate in the playoff tournament. The tournament is held according to the following scheme: the first player will play with the second, and the third player with the fourth, then the winners of the pairs will play in the finals of the tournament.It is known that in a match between two players, the one whose skill is greater will win. The skill of the $$$i$$$-th player is equal to $$$s_i$$$ and all skill levels are pairwise different (i. e. there are no two identical values in the array $$$s$$$).The tournament is called fair if the two players with the highest skills meet in the finals.Determine whether the given tournament is fair.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. A single line of test case contains four integers $$$s_1, s_2, s_3, s_4$$$ ($$$1 \le s_i \le 100$$$) — skill of the players. It is guaranteed that all the numbers in the array are different.

For each testcase, output YES if the tournament is fair, or NO otherwise.

NoteConsider the example:  in the first test case, players $$$2$$$ and $$$3$$$ with skills $$$7$$$ and $$$9$$$ advance to the finals;  in the second test case, players $$$2$$$ and $$$4$$$ with skills $$$5$$$ and $$$9$$$ advance to the finals. The player with skill $$$6$$$ does not advance, but the player with skill $$$5$$$ advances to the finals, so the tournament is not fair;  in the third test case, players $$$1$$$ and $$$3$$$ with skills $$$5$$$ and $$$8$$$ advance to the finals;  in the fourth test case, players $$$1$$$ and $$$3$$$ with skills $$$6$$$ and $$$3$$$ advance to the finals. The player with skill $$$5$$$ does not advance, but the player with skill $$$3$$$ advances to the finals, so the tournament is not fair.


Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book?

The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$.

Print one integer — the number of days it will take to read the whole book.

NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	@_ = split ' ', <>;

#	print "@_";

	my $i = 0;
	my $max = 0;
	my $days = 0;

	while( @_ ){
		$i ++;
		my $A = shift @_;
		$max < $A and $max = $A;
		if( $max > $i ){
			next;
			}
		$days ++;
		}

	print $days;
	}


You are given a string $$$t$$$ consisting of $$$n$$$ lowercase Latin letters and an integer number $$$k$$$.Let's define a substring of some string $$$s$$$ with indices from $$$l$$$ to $$$r$$$ as $$$s[l \dots r]$$$.Your task is to construct such string $$$s$$$ of minimum possible length that there are exactly $$$k$$$ positions $$$i$$$ such that $$$s[i \dots i + n - 1] = t$$$. In other words, your task is to construct such string $$$s$$$ of minimum possible length that there are exactly $$$k$$$ substrings of $$$s$$$ equal to $$$t$$$.It is guaranteed that the answer is always unique.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 50$$$) — the length of the string $$$t$$$ and the number of substrings. The second line of the input contains the string $$$t$$$ consisting of exactly $$$n$$$ lowercase Latin letters.

Print such string $$$s$$$ of minimum possible length that there are exactly $$$k$$$ substrings of $$$s$$$ equal to $$$t$$$. It is guaranteed that the answer is always unique.


You had $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$ arranged in a circle. For each pair of neighboring numbers ($$$a_1$$$ and $$$a_2$$$, $$$a_2$$$ and $$$a_3$$$, ..., $$$a_{n - 1}$$$ and $$$a_n$$$, and $$$a_n$$$ and $$$a_1$$$), you wrote down: are the numbers in the pair equal or not.Unfortunately, you've lost a piece of paper with the array $$$a$$$. Moreover, you are afraid that even information about equality of neighboring elements may be inconsistent. So, you are wondering: is there any array $$$a$$$ which is consistent with information you have about equality or non-equality of corresponding pairs?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains a non-empty string $$$s$$$ consisting of characters E and/or N. The length of $$$s$$$ is equal to the size of array $$$n$$$ and $$$2 \le n \le 50$$$. For each $$$i$$$ from $$$1$$$ to $$$n$$$:    if $$$s_i =$$$ E then $$$a_i$$$ is equal to $$$a_{i + 1}$$$ ($$$a_n = a_1$$$ for $$$i = n$$$);  if $$$s_i =$$$ N then $$$a_i$$$ is not equal to $$$a_{i + 1}$$$ ($$$a_n \neq a_1$$$ for $$$i = n$$$).

For each test case, print YES if it's possible to choose array $$$a$$$ that are consistent with information from $$$s$$$ you know. Otherwise, print NO. It can be proved, that if there exists some array $$$a$$$, then there exists an array $$$a$$$ of positive integers with values less or equal to $$$10^9$$$.

NoteIn the first test case, you can choose, for example, $$$a_1 = a_2 = a_3 = 5$$$.In the second test case, there is no array $$$a$$$, since, according to $$$s_1$$$, $$$a_1$$$ is equal to $$$a_2$$$, but, according to $$$s_2$$$, $$$a_2$$$ is not equal to $$$a_1$$$.In the third test case, you can, for example, choose array $$$a = [20, 20, 4, 50, 50, 50, 20]$$$.In the fourth test case, you can, for example, choose $$$a = [1, 3, 3, 7]$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	print do {
		if( m/^E+N$/ || m/^NE+$/ || m/^E+NE+$/ ){
			"NO";
			}
		else{
			"YES";
			}
		}
	}


Students of group 199 have written their lectures dismally. Now an exam on Mathematical Analysis is approaching and something has to be done asap (that is, quickly). Let's number the students of the group from 1 to n. Each student i (1 ≤ i ≤ n) has a best friend p[i] (1 ≤ p[i] ≤ n). In fact, each student is a best friend of exactly one student. In other words, all p[i] are different. It is possible that the group also has some really "special individuals" for who i = p[i].Each student wrote exactly one notebook of lecture notes. We know that the students agreed to act by the following algorithm:   on the first day of revising each student studies his own Mathematical Analysis notes,  in the morning of each following day each student gives the notebook to his best friend and takes a notebook from the student who calls him the best friend. Thus, on the second day the student p[i] (1 ≤ i ≤ n) studies the i-th student's notes, on the third day the notes go to student p[p[i]] and so on. Due to some characteristics of the boys' friendship (see paragraph 1), each day each student has exactly one notebook to study.You are given two sequences that describe the situation on the third and fourth days of revising:  a1, a2, ..., an, where ai means the student who gets the i-th student's notebook on the third day of revising;  b1, b2, ..., bn, where bi means the student who gets the i-th student's notebook on the fourth day of revising. You do not know array p, that is you do not know who is the best friend to who. Write a program that finds p by the given sequences a and b.

The first line contains integer n (1 ≤ n ≤ 105) — the number of students in the group. The second line contains sequence of different integers a1, a2, ..., an (1 ≤ ai ≤ n). The third line contains the sequence of different integers b1, b2, ..., bn (1 ≤ bi ≤ n).

Print sequence n of different integers p[1], p[2], ..., p[n] (1 ≤ p[i] ≤ n). It is guaranteed that the solution exists and that it is unique.

#!perl
$num = <STDIN>;
$skeys = <STDIN>;
@keys = split(/\D/,$skeys);
$svalues = <STDIN>;
@values = split(/\D/,$svalues);
@friends{@keys} = @values;
for $i (1..$num) {
	print $friends{$i}, " ";
}


You are given a sequence of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You are also given $$$x$$$ integers $$$1, 2, \dots, x$$$.You are asked to insert each of the extra integers into the sequence $$$a$$$. Each integer can be inserted at the beginning of the sequence, at the end of the sequence, or between any elements of the sequence.The score of the resulting sequence $$$a'$$$ is the sum of absolute differences of adjacent elements in it $$$\left(\sum \limits_{i=1}^{n+x-1} |a'_i - a'_{i+1}|\right)$$$.What is the smallest possible score of the resulting sequence $$$a'$$$?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of each testcase contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n, x \le 2 \cdot 10^5$$$) — the length of the sequence and the number of extra integers. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2 \cdot 10^5$$$). The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print a single integer — the smallest sum of absolute differences of adjacent elements of the sequence after you insert the extra integers into it.

NoteHere are the sequences with the smallest scores for the example. The underlined elements are the extra integers. Note that there exist other sequences with this smallest score.   $$$\underline{1}, \underline{2}, \underline{3}, \underline{4}, \underline{5}, 10$$$  $$$\underline{7}, 7, \underline{6}, \underline{4}, 2, \underline{2}, \underline{1}, \underline{3}, \underline{5}, \underline{8}, 10$$$  $$$6, \underline{1}, 1, \underline{2}, 5, 7, 3, 3, 9, 10, 10, 1$$$  $$$1, 3, \underline{1}, 1, 2, \underline{2}, \underline{3}, \underline{4}, \underline{5}, \underline{6}, \underline{7}, \underline{8}, \underline{9}, \underline{10}$$$


There is an array $$$a$$$ with $$$n-1$$$ integers. Let $$$x$$$ be the bitwise XOR of all elements of the array. The number $$$x$$$ is added to the end of the array $$$a$$$ (now it has length $$$n$$$), and then the elements are shuffled.You are given the newly formed array $$$a$$$. What is $$$x$$$? If there are multiple possible values of $$$x$$$, you can output any of them.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the number of integers in the resulting array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 127$$$) — the elements of the newly formed array $$$a$$$. Additional constraint on the input: the array $$$a$$$ is made by the process described in the statement; that is, some value of $$$x$$$ exists.

For each test case, output a single integer — the value of $$$x$$$, as described in the statement. If there are multiple possible values of $$$x$$$, output any of them.

NoteIn the first test case, one possible array $$$a$$$ is $$$a=[2, 5, 4]$$$. Then $$$x = 2 \oplus 5 \oplus 4 = 3$$$ ($$$\oplus$$$ denotes the bitwise XOR), so the new array is $$$[2, 5, 4, 3]$$$. Afterwards, the array is shuffled to form $$$[4, 3, 2, 5]$$$.In the second test case, one possible array $$$a$$$ is $$$a=[1, 10, 6, 10]$$$. Then $$$x = 1 \oplus 10 \oplus 6 \oplus 10 = 7$$$, so the new array is $$$[1, 10, 6, 10, 7]$$$. Afterwards, the array is shuffled to form $$$[6, 1, 10, 7, 10]$$$.In the third test case, all elements of the array are equal to $$$6$$$, so $$$x=6$$$.In the fourth test case, one possible array $$$a$$$ is $$$a=[100, 100]$$$. Then $$$x = 100 \oplus 100 = 0$$$, so the new array is $$$[100, 100, 0]$$$. Afterwards, the array is shuffled to form $$$[100, 100, 0]$$$. (Note that after the shuffle, the array can remain the same.)


One not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game.He took a checkered white square piece of paper, consisting of n × n cells. After that, he started to paint the white cells black one after the other. In total he painted m different cells on the piece of paper. Since Valera was keen on everything square, he wondered, how many moves (i.e. times the boy paints a square black) he should make till a black square with side 3 can be found on the piece of paper. But Valera does not know the answer to this question, so he asks you to help him.Your task is to find the minimum number of moves, till the checkered piece of paper has at least one black square with side of 3. Otherwise determine that such move does not exist.

The first line contains two integers n and m (1 ≤ n ≤ 1000, 1 ≤ m ≤ min(n·n, 105)) — the size of the squared piece of paper and the number of moves, correspondingly.  Then, m lines contain the description of the moves. The i-th line contains two integers xi, yi (1 ≤ xi, yi ≤ n) — the number of row and column of the square that gets painted on the i-th move.  All numbers on the lines are separated by single spaces. It is guaranteed that all moves are different. The moves are numbered starting from 1 in the order, in which they are given in the input. The columns of the squared piece of paper are numbered starting from 1, from the left to the right. The rows of the squared piece of paper are numbered starting from 1, from top to bottom.

On a single line print the answer to the problem — the minimum number of the move after which the piece of paper has a black square with side 3. If no such move exists, print -1.

#!/bin/perl -w
use strict;
use warnings;
use List::Util qw[min max];

my ($n, $m) = map int, split /\D/, <>;

my @square = ('W' x $n) x $n;

for my $move (1..$m) {
    my ($i, $j) = map int, split /\D/, <>;
    map { $_-- } ($i, $j);
    substr($square[$i], $j, 1) = 'B';
    for (0..2) {
	my $indx = index $square[$i], 'BBB', max($j-$_, 0);
	if ($indx > -1) {
	    my $black_rows = '';
	    for (max($i-2, 0) .. min($i+2, $n-1)) {
		if (substr($square[$_], $indx, 3) eq 'BBB') {
		    $black_rows .= 1;
		} else {
		    $black_rows .= 0;
		}
	    }
	    if ($black_rows =~ /111/) {
		print "$move\n";
		exit;
	    }
	}
    }
}

print "-1\n";

#!/bin/perl -w
use strict;
use warnings;
use List::Util qw[min max];

my ($n, $m) = map int, split /\D/, <>;

my @square = ('W' x $n) x $n;

for my $move (1..$m) {
    my ($i, $j) = map int, split /\D/, <>;
    map { $_-- } ($i, $j);
    substr($square[$i], $j, 1) = 'B';
    for (0..2) {
	my $indx = index $square[$i], 'BBB', min($j-$_, 0);
	if ($indx > -1) {
	    my $black_rows = '';
	    for (max($i-2, 0) .. min($i+2, $n-1)) {
		if (substr($square[$_], $indx, 3) eq 'BBB') {
		    $black_rows .= 1;
		} else {
		    $black_rows .= 0;
		}
	    }
	    if ($black_rows =~ /111/) {
		print "$move\n";
		exit;
	    }
	}
    }
}

print "-1\n";

#!/bin/perl -w
use strict;
use warnings;
use List::Util qw[min max];

my ($n, $m) = map int, split /\D/, <>;

my @square = ('W' x $n) x $n;

for my $move (1..$m) {
    my ($i, $j) = map int, split /\D/, <>;
    map { $_-- } ($i, $j);
    substr($square[$i], $j, 1) = 'B';
    my $indx = index $square[$i], 'BBB', min($j-2, 0);
    if ($indx > -1) {
	my $black_rows = '';
	for (max($i-2, 0) .. min($i+2, $n-1)) {
	    if (substr($square[$_], $indx, 3) eq 'BBB') {
		$black_rows .= 1;
	    } else {
		$black_rows .= 0;
	    }
	}
	if ($black_rows =~ /111/) {
	    print "$move\n";
	    exit;
	}
    }
}

print "-1\n";


A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimum unfortunate sum?

The first line contains number n (1 ≤ n ≤ 1000) — the number of values of the banknotes that used in Geraldion.  The second line contains n distinct space-separated numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the values of the banknotes.

Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print  - 1.

#!/usr/bin/perl
use v5.10;

chomp($n = <>);
$_==1 and say -1 and exit foreach (split / /, <>);
say 1;

#!/usr/bin/perl
use v5.10;

chomp($n = <>);
$==1 and say -1 and exit foreach (split / /, <>);
say 1;


DZY has a sequence a, consisting of n integers.We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.You only need to output the length of the subsegment you find.

The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).

In a single line print the answer to the problem — the maximum length of the required subsegment.

NoteYou can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4.

# http://codeforces.com/problemset/problem/446/A
# http://codeforces.com/blog/entry/13036

my $n = <STDIN>;
my $f = <STDIN>;
chomp ( $n, $f );
my @seq = split m/ /, $f;

my @left, @right;
my $cnt = 1;
$left[0] = 1;

for ( my $i = 1; $i < @seq; $i += 1 ) {
    if ( $seq[ $i-1 ] < $seq[ $i ] ) {
	$cnt += 1;
	$left[ $i ] = $cnt; }
    else {
	$cnt = 1;
	$left[ $i ] = $cnt; }}

$right[ @seq-1 ] = 1;
$cnt = 1;
for ( my $i = @seq-2; $i >= 0; $i -= 1 ) {
    if ( $seq[ $i ] < $seq[ $i+1 ] ) {
	$cnt += 1;
	$right[ $i ] = $cnt; }
    else {
	$cnt = 1;
	$right[ $i ] = $cnt; }}

my $mx = 0;
for ( my $i = 0; $i < @seq-2; $i += 1 ) {
    if ( $seq[ $i ] + 1 < $seq[ $i+2 ] ) {
	if ( $left[ $i ] + 1 + $right[ $i+2 ] > $mx ) {
	    $mx = $left[ $i ] + 1 + $right[ $i+2 ]; }}}

my $ww = 0;
for (@left) {
    if ( $_ > $ww ) {
	$ww = $_; }}
if ( $ww < @left ) {
    $ww += 1; }
if ( $ww > $mx ) { $mx = $ww; }

if ( $n < 3 ) { print "$n\n"; }
else {
print $mx;
print "\n"; }

# http://codeforces.com/problemset/problem/446/A
# http://codeforces.com/blog/entry/13036

my $n = <STDIN>;
my $f = <STDIN>;
chomp ( $n, $f );
my @seq = split m/ /, $f;
my @left, @right;
my $cnt = 1;
$left[0] = 1;

for ( my $i = 1; $i < @seq; $i += 1 ) {
    if ( $seq[ $i-1 ] < $seq[ $i ] ) {
	$cnt += 1;
	$left[ $i ] = $cnt; }
    else {
	$cnt = 1;
	$left[ $i ] = $cnt; }}

$right[ @seq-1 ] = 1;
$cnt = 1;
for ( my $i = @seq-2; $i >= 0; $i -= 1 ) {
    if ( $seq[ $i ] < $seq[ $i+1 ] ) {
	$cnt += 1;
	$right[ $i ] = $cnt; }
    else {
	$cnt = 1;
	$right[ $i ] = $cnt; }}

my $mx = 0;
for ( my $i = 0; $i < @seq-2; $i += 1 ) {
    if ( $seq[ $i ] + 1 < $seq[ $i+2 ] ) {
	if ( $left[ $i ] + 1 + $right[ $i ] > $mx ) {
	    $mx = $left[ $i ] + 1 + $right[ $i ]; }}}

if ( $n < 3 ) { print "$n\n"; }
else {
print $mx;
print "\n"; }


Alice and Bob are playing a game on a matrix, consisting of $$$2$$$ rows and $$$m$$$ columns. The cell in the $$$i$$$-th row in the $$$j$$$-th column contains $$$a_{i, j}$$$ coins in it.Initially, both Alice and Bob are standing in a cell $$$(1, 1)$$$. They are going to perform a sequence of moves to reach a cell $$$(2, m)$$$.The possible moves are:   Move right — from some cell $$$(x, y)$$$ to $$$(x, y + 1)$$$;  Move down — from some cell $$$(x, y)$$$ to $$$(x + 1, y)$$$. First, Alice makes all her moves until she reaches $$$(2, m)$$$. She collects the coins in all cells she visit (including the starting cell).When Alice finishes, Bob starts his journey. He also performs the moves to reach $$$(2, m)$$$ and collects the coins in all cells that he visited, but Alice didn't.The score of the game is the total number of coins Bob collects.Alice wants to minimize the score. Bob wants to maximize the score. What will the score of the game be if both players play optimally?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. Then the descriptions of $$$t$$$ testcases follow. The first line of the testcase contains a single integer $$$m$$$ ($$$1 \le m \le 10^5$$$) — the number of columns of the matrix. The $$$i$$$-th of the next $$$2$$$ lines contain $$$m$$$ integers $$$a_{i,1}, a_{i,2}, \dots, a_{i,m}$$$ ($$$1 \le a_{i,j} \le 10^4$$$) — the number of coins in the cell in the $$$i$$$-th row in the $$$j$$$-th column of the matrix. The sum of $$$m$$$ over all testcases doesn't exceed $$$10^5$$$.

For each testcase print a single integer — the score of the game if both players play optimally.

NoteThe paths for the testcases are shown on the following pictures. Alice's path is depicted in red and Bob's path is depicted in blue.


You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.

First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.

For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.

NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.


You are given two strings $$$s$$$ and $$$t$$$ both of length $$$2$$$ and both consisting only of characters 'a', 'b' and 'c'.Possible examples of strings $$$s$$$ and $$$t$$$: "ab", "ca", "bb".You have to find a string $$$res$$$ consisting of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings.A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".If there are multiple answers, you can print any of them.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of characters 'a', 'b' and 'c' in the resulting string. The second line of the input contains one string $$$s$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'. The third line of the input contains one string $$$t$$$ of length $$$2$$$ consisting of characters 'a', 'b' and 'c'.

If it is impossible to find the suitable string, print "NO" on the first line.  Otherwise print "YES" on the first line and string $$$res$$$ on the second line. $$$res$$$ should consist of $$$3n$$$ characters, $$$n$$$ characters should be 'a', $$$n$$$ characters should be 'b' and $$$n$$$ characters should be 'c' and $$$s$$$ and $$$t$$$ should not occur in $$$res$$$ as substrings. If there are multiple answers, you can print any of them.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

while(<>){
	$debug and print '-' x 15;
	chomp;

	my $n = $_;

	my $length = 2;

	my @re = split ' ', join '', map ~~<>, 1 .. $length;

	$debug and print "\$n: $n, \@re: @re";

	my $letters = join '', 'a' .. 'c';

	my $prependent = ',';

	my $str = join '', map "${prependent}$_", ( $letters ) x $length;

	$debug and print $str;

	my $match_one_letter = "${prependent}.*([^$prependent]).*";

	my $match_letters = $match_one_letter x $length;

	$debug and print "$match_letters";

	my %strings;

	$str =~ /
		$match_letters
		(?{ $strings{ $1 . $2 } ++ })
		(*F)
		/x;

	/(.).*\1/ and delete $strings{ $_ } for sort keys %strings;

	$debug and print join ' ', sort keys %strings;

	my %variants;

	for my $string ( sort keys %strings ){
		my( $third_letter ) = $letters =~ s/[$string]//gr;
		$variants{ join '', map { $_ x $n } $string, $third_letter } ++;
		$variants{ join '', map { $_ x $n } $third_letter, $string } ++;
		$variants{ scalar( $string . $third_letter ) x $n } ++;
		}

	$debug and print for sort keys %variants;

	my $find;

	for my $variant ( sort keys %variants ){
		my $ok = 1;
		for my $re ( @re ){
			$variant =~ /$re/ and $ok = 0;
			}

		last if $ok and $find = $variant;
		}

	print defined $find ? "YES\n$find" : "NO";
	}


On an $$$8 \times 8$$$ grid, some horizontal rows have been painted red, and some vertical columns have been painted blue, in some order. The stripes are drawn sequentially, one after the other. When the stripe is drawn, it repaints all the cells through which it passes.Determine which color was used last.  The red stripe was painted after the blue one, so the answer is R.

The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 4000$$$) — the number of test cases. The description of test cases follows. There is an empty line before each test case. Each test case consists of $$$8$$$ lines, each containing $$$8$$$ characters. Each of these characters is either 'R', 'B', or '.', denoting a red square, a blue square, and an unpainted square, respectively. It is guaranteed that the given field is obtained from a colorless one by drawing horizontal red rows and vertical blue columns. At least one stripe is painted.

For each test case, output 'R' if a red stripe was painted last, and 'B' if a blue stripe was painted last (without quotes).

NoteThe first test case is pictured in the statement.In the second test case, the first blue column is painted first, then the first and last red rows, and finally the last blue column. Since a blue stripe is painted last, the answer is B.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	@_ = map ~~<>, 1 .. 8;

	if( grep m/^R+$/, @_ ){
		print 'R';
		}
	else{
		print 'B';
		}
	}


You're given an array $$$a$$$ of length $$$n$$$. You can perform the following operations on it:  choose an index $$$i$$$ $$$(1 \le i \le n)$$$, an integer $$$x$$$ $$$(0 \le x \le 10^6)$$$, and replace $$$a_j$$$ with $$$a_j+x$$$ for all $$$(1 \le j \le i)$$$, which means add $$$x$$$ to all the elements in the prefix ending at $$$i$$$.  choose an index $$$i$$$ $$$(1 \le i \le n)$$$, an integer $$$x$$$ $$$(1 \le x \le 10^6)$$$, and replace $$$a_j$$$ with $$$a_j \% x$$$ for all $$$(1 \le j \le i)$$$, which means replace every element in the prefix ending at $$$i$$$ with the remainder after dividing it by $$$x$$$. Can you make the array strictly increasing in no more than $$$n+1$$$ operations?

The first line contains an integer $$$n$$$ $$$(1 \le n \le 2000)$$$, the number of elements in the array $$$a$$$. The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\dots$$$, $$$a_n$$$ $$$(0 \le a_i \le 10^5)$$$, the elements of the array $$$a$$$.

On the first line, print the number of operations you wish to perform. On the next lines, you should print the operations. To print an adding operation, use the format "$$$1$$$ $$$i$$$ $$$x$$$"; to print a modding operation, use the format "$$$2$$$ $$$i$$$ $$$x$$$". If $$$i$$$ or $$$x$$$ don't satisfy the limitations above, or you use more than $$$n+1$$$ operations, you'll get wrong answer verdict.

NoteIn the first sample, the array is already increasing so we don't need any operations.In the second sample:In the first step: the array becomes $$$[8,6,3]$$$.In the second step: the array becomes $$$[0,2,3]$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $step = 1e5 + 0;
my $mod = 1e5 + 1;

while(<>){
	@_ = split ' ', <>;

	my @ans;

	my $need = 1e5 + 0;
	my $i = @_ + 1;
	my $sumdiff = 0;

	for( reverse @_ ){
		$i --;
		my $diff = $need - $_ - $sumdiff;
		push @ans, join ' ', 1, $i, $diff;
		$sumdiff += $diff;
		$need += $step;
		}

	push @ans, join ' ', 2, ~~ @_, $mod;

	print for ~~ @ans, @ans;
	}


Bob programmed a robot to navigate through a 2d maze.The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single exit in the maze. Its position is denoted with the character 'E'. This position has no obstacle in it.The robot can only move up, left, right, or down.When Bob programmed the robot, he wrote down a string of digits consisting of the digits 0 to 3, inclusive. He intended for each digit to correspond to a distinct direction, and the robot would follow the directions in order to reach the exit. Unfortunately, he forgot to actually assign the directions to digits.The robot will choose some random mapping of digits to distinct directions. The robot will map distinct digits to distinct directions. The robot will then follow the instructions according to the given string in order and chosen mapping. If an instruction would lead the robot to go off the edge of the maze or hit an obstacle, the robot will crash and break down. If the robot reaches the exit at any point, then the robot will stop following any further instructions.Bob is having trouble debugging his robot, so he would like to determine the number of mappings of digits to directions that would lead the robot to the exit.

The first line of input will contain two integers n and m (2 ≤ n, m ≤ 50), denoting the dimensions of the maze. The next n lines will contain exactly m characters each, denoting the maze. Each character of the maze will be '.', '#', 'S', or 'E'. There will be exactly one 'S' and exactly one 'E' in the maze. The last line will contain a single string s (1 ≤ |s| ≤ 100) — the instructions given to the robot. Each character of s is a digit from 0 to 3.

Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit.

NoteFor the first sample, the only valid mapping is , where D is down, L is left, U is up, R is right.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;
my $debug = 0;

while(<>){
	my( $n, $m ) = split;

	my @A = map { [ split //, <> =~ s/\n//r ] } 1 .. $n;

	$debug and print "@{$_}" for @A;

	my $sx;
	my $sy;

	OUT:
	for my $i ( 0 .. $n - 1 ){
		for my $j ( 0 .. $m - 1 ){
			$A[ $i ][ $j ] eq 'S' and do {
				$sx = $i; $sy = $j;
				$A[ $i ][ $j ] = '.';
				last OUT;
				};
			}
		}

	$debug and print '-' x 5;
	$debug and print "@{$_}" for @A;
	$debug and print "[$sx|$sy]";

	my @dirs = split //, <> =~ s/\n//r;

	$debug and print "[@dirs]";

	my @v = qw( U D L R );
	my $vars = 0;

	for my $i1 ( @v ){
		for my $i2 ( @v ){
			for my $i3 ( @v ){
				for my $i4 ( @v ){
					next if "$i1$i2$i3$i4" =~ /(.).*\1/;
					my @i = split //, "$i1$i2$i3$i4";

					my $ssx = $sx;
					my $ssy = $sy;

					my $fail = 0;

					for my $j ( @dirs ){
						my( $dx, $dy ) = ( 0, 0 );
						$i[ $j ] eq 'D' and $dy += 1;
						$i[ $j ] eq 'U' and $dy -= 1;
						$i[ $j ] eq 'L' and $dx -= 1;
						$i[ $j ] eq 'R' and $dx += 1;

						$ssx += $dx;
						$ssy += $dy;

						if( $ssx < 0 || $ssx >= $n || $ssy < 0 || $ssy >= $m ||
							$A[ $ssx ][ $ssy ] eq '#'
							){
							$fail = 1;
							last;
							}

						if( $A[ $ssx ][ $ssy ] eq 'E' ){
							$vars ++;
							last;
							}
						}
					}
				}
			}
		}

	print $vars;

	$debug and print '-' x 20;
	}


Haiku is a genre of Japanese traditional poetry.A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words.To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u".Three phases from a certain poem are given. Determine whether it is haiku or not.

The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification.

Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).

on  codeforces
beta round is running
   a rustling of keys

how many gallons
of edo s rain did you drink
                                cuckoo

$s.=tr/aeiou// while <>;
print "575" eq $s?"YES":"NO"

#!/usr/bin/env perl

use strict;
use warnings;

my $line1 = <>;
my $line2 = <>;
my $line3 = <>;

$line1 =~ s/[^aeiou]//g;
$line2 =~ s/[^aeiou]//g;
$line3 =~ s/[^aeiou]//g;

printf "%s\n", ((length($line1) == 5 &&
                 length($line2) == 7 &&
                 length($line3) == 5) ? 'YES' : 'NO');

sub occ{
@arr=@_;
@one=grep{$_ eq "a" or $_ eq "i" or $_ eq "u" or $_ eq "o" or $_ eq "e" }@arr;
$size=@one;
return $size;
}
@arr=split('',<>);
@arr1=split('',<>);
@arr2=split('',<>);
if(occ(@arr)==5 and occ(@arr1)==7 and occ(@arr2)==5){
print "YES";
}
else{
print "NO";
}

while(<>) {
  chomp;
  $s.=$_;
}
print $s=~tr/aeiou// == 17?"YES":"NO"


Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.

The first line contains positive integer n (1 ≤ n ≤ 100) — the number of USB flash drives. The second line contains positive integer m (1 ≤ m ≤ 105) — the size of Sean's file. Each of the next n lines contains positive integer ai (1 ≤ ai ≤ 1000) — the sizes of USB flash drives in megabytes. It is guaranteed that the answer exists, i. e. the sum of all ai is not less than m.

Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.

NoteIn the first example Sean needs only two USB flash drives — the first and the third.In the second example Sean needs all three USB flash drives.In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.

use strict;
open STDIN, '<input.txt';
open STDOUT, '>output.txt';
my $n = <>;
my $m = <>;
my @a;
for(my $i = 0; $i < $n; $i++){
   $a[$i] = <>;
}
@a = sort @a;
my $ans = 0;
my $j = $#a;

while($m > 0 && $j >= 0){
  $m -= $a[$j];
  $ans++;
  $j--;
}
print $ans;


A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not.You are given a string $$$s$$$ of length $$$n$$$, consisting of digits.In one operation you can delete any character from string $$$s$$$. For example, it is possible to obtain strings 112, 111 or 121 from string 1121.You need to determine whether there is such a sequence of operations (possibly empty), after which the string $$$s$$$ becomes a telephone number.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the length of string $$$s$$$. The second line of each test case contains the string $$$s$$$ ($$$|s| = n$$$) consisting of digits.

For each test print one line. If there is a sequence of operations, after which $$$s$$$ becomes a telephone number, print YES. Otherwise, print NO.

NoteIn the first test case you need to delete the first and the third digits. Then the string 7818005553535 becomes 88005553535.


Maria participates in a bicycle race.The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west.Let's introduce a system of coordinates, directing the Ox axis from west to east, and the Oy axis from south to north. As a starting position of the race the southernmost point of the track is selected (and if there are several such points, the most western among them). The participants start the race, moving to the north. At all straight sections of the track, the participants travel in one of the four directions (north, south, east or west) and change the direction of movement only in bends between the straight sections. The participants, of course, never turn back, that is, they do not change the direction of movement from north to south or from east to west (or vice versa).Maria is still young, so she does not feel confident at some turns. Namely, Maria feels insecure if at a failed or untimely turn, she gets into the water. In other words, Maria considers the turn dangerous if she immediately gets into the water if it is ignored.Help Maria get ready for the competition — determine the number of dangerous turns on the track.

The first line of the input contains an integer n (4 ≤ n ≤ 1000) — the number of straight sections of the track. The following (n + 1)-th line contains pairs of integers (xi, yi) ( - 10 000 ≤ xi, yi ≤ 10 000). The first of these points is the starting position. The i-th straight section of the track begins at the point (xi, yi) and ends at the point (xi + 1, yi + 1). It is guaranteed that:   the first straight section is directed to the north;  the southernmost (and if there are several, then the most western of among them) point of the track is the first point;  the last point coincides with the first one (i.e., the start position);  any pair of straight sections of the track has no shared points (except for the neighboring ones, they share exactly one point);  no pair of points (except for the first and last one) is the same;  no two adjacent straight sections are directed in the same direction or in opposite directions.

Print a single integer — the number of dangerous turns on the track.

NoteThe first sample corresponds to the picture:  The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1.

chomp (my $n = <STDIN>);

my ($x, $y, $xp, $yp);

chomp (($xp, $yp) = split /\s+/, <STDIN>);
chomp (($xp, $yp) = split /\s+/, <STDIN>);

my $prevDir = 'N';
my $curDir = 'N';

my $ans = 0;
for (my $i = 1; $i < $n; $i++) {
  chomp (($x, $y) = split /\s+/, <STDIN>);

  $curDir = 'N' if ($y > $yp);
  $curDir = 'E' if ($x > $xp);
  $curDir = 'W' if ($x < $xp);
  $curDir = 'S' if ($y < $yp);

  $ans++ if (
    (($prevDir eq 'N') && ($curDir eq 'W')) ||
    (($prevDir eq 'E') && ($curDir eq 'N')) ||
    (($prevDir eq 'W') && ($curDir eq 'S')) ||
    (($prevDir eq 'S') && ($curDir eq 'E'))
  );

  $prevDir = $curDir;
  ($xp, $yp) = ($x, $y);
}

printf "$ans\n";


Given a set of integers (it can contain equal elements).You have to split it into two subsets $$$A$$$ and $$$B$$$ (both of them can contain equal elements or be empty). You have to maximize the value of $$$mex(A)+mex(B)$$$.Here $$$mex$$$ of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:   $$$mex(\{1,4,0,2,2,1\})=3$$$  $$$mex(\{3,3,2,1,3,0,0\})=4$$$  $$$mex(\varnothing)=0$$$ ($$$mex$$$ for empty set) The set is splitted into two subsets $$$A$$$ and $$$B$$$ if for any integer number $$$x$$$ the number of occurrences of $$$x$$$ into this set is equal to the sum of the number of occurrences of $$$x$$$ into $$$A$$$ and the number of occurrences of $$$x$$$ into $$$B$$$.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1\leq t\leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1\leq n\leq 100$$$) — the size of the set. The second line of each testcase contains $$$n$$$ integers $$$a_1,a_2,\dots a_n$$$ ($$$0\leq a_i\leq 100$$$) — the numbers in the set.

For each test case, print the maximum value of $$$mex(A)+mex(B)$$$.

NoteIn the first test case, $$$A=\left\{0,1,2\right\},B=\left\{0,1,5\right\}$$$ is a possible choice.In the second test case, $$$A=\left\{0,1,2\right\},B=\varnothing$$$ is a possible choice.In the third test case, $$$A=\left\{0,1,2\right\},B=\left\{0\right\}$$$ is a possible choice.In the fourth test case, $$$A=\left\{1,3,5\right\},B=\left\{2,4,6\right\}$$$ is a possible choice.


It is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfortunately, he lives far from kindergarten, and his father is too busy to drive him there. The only choice for this poor little boy is to wait for a bus on this rainy day. Under such circumstances, the poor boy will use the first bus he sees no matter where it goes. If several buses come at the same time, he will choose one randomly.Serval will go to the bus station at time $$$t$$$, and there are $$$n$$$ bus routes which stop at this station. For the $$$i$$$-th bus route, the first bus arrives at time $$$s_i$$$ minutes, and each bus of this route comes $$$d_i$$$ minutes later than the previous one.As Serval's best friend, you wonder which bus route will he get on. If several buses arrive at the same time, you can print any of them.

The first line contains two space-separated integers $$$n$$$ and $$$t$$$ ($$$1\leq n\leq 100$$$, $$$1\leq t\leq 10^5$$$) — the number of bus routes and the time Serval goes to the station.  Each of the next $$$n$$$ lines contains two space-separated integers $$$s_i$$$ and $$$d_i$$$ ($$$1\leq s_i,d_i\leq 10^5$$$) — the time when the first bus of this route arrives and the interval between two buses of this route.

Print one number — what bus route Serval will use. If there are several possible answers, you can print any of them.

NoteIn the first example, the first bus of the first route arrives at time $$$6$$$, and the first bus of the second route arrives at time $$$9$$$, so the first route is the answer.In the second example, a bus of the third route arrives at time $$$5$$$, so it is the answer.In the third example, buses of the first route come at times $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$, and so fourth, buses of the second route come at times $$$2$$$, $$$5$$$, $$$8$$$, and so fourth and buses of the third route come at times $$$2$$$, $$$6$$$, $$$10$$$, and so on, so $$$1$$$ and $$$2$$$ are both acceptable answers while $$$3$$$ is not.

#!/usr/bin/env perl

use strict;
use warnings;
use feature qw /say/;

my ($n, $t) = split q{ }, <STDIN>;
my $idx;

my @time_and_gap = ( (undef)x$n );
for ( @time_and_gap ) {
    $_ = [ split q{ }, <STDIN> ];
}

my $time;
my $gap;
my $s;
my $mod;
my $div;
my $min = 1000000;
my $min_i = 101;
my $i = 0;
for ( @time_and_gap ) {
    $i++;
    $time = $_->[0];
    $gap = $_->[1];

    if ( $time < $t ) {
        $s = $t - $time;
        $mod = $s % $gap;
        $div = int ( $s/$gap );
        if ( $mod ) {
            $div++;
        }
        $time += $div * $gap;
    }

    if ( $time < $min ) {
        $min = $time;
        $min_i = $i;
    }

}

say $min_i;

#!/usr/bin/env perl

use strict;
use warnings;
use feature qw /say/;

my ($n, $t) = split q{ }, <STDIN>;
my $idx;

my @time_and_gap = ( (undef)x$n );
for ( @time_and_gap ) {
    $_ = [ split q{ }, <STDIN> ];
}

my $time;
my $gap;
my $s;
my $div;
my $min = 1000000;
my $min_i = 101;
my $i = 0;
for ( @time_and_gap ) {
    $i++;
    $time = $_->[0];
    $gap = $_->[1];

    if ( $time < $t ) {
        $s = $t - $time;
        $div = int ( $s/$gap );
        $time += $div * $gap;
    }
    if ( $time < $t ) {
        $time += $gap;
    }
    if ( $time < $t ) {
        next;
    }

    if ( $time < $min ) {
        $min = $time;
        $min_i = $i;
    }

}

say $min_i;

#!/usr/bin/env perl

use strict;
use warnings;
use feature qw /say/;

my ($n, $t) = split q{ }, <STDIN>;
my $idx;

my @time_and_gap = ( (undef)x$n );
for ( @time_and_gap ) {
    $_ = [ split q{ }, <STDIN> ];
}

my $time;
my $gap;
my $s;
my $div;
my $min = 1000000;
my $min_i = 101;
my $i = 0;
for ( @time_and_gap ) {
    $i++;
    $time = $_->[0];
    $gap = $_->[1];

    while ( $time < $t ) {
        $time += $gap;
    }

    if ( $time < $min ) {
        $min = $time;
        $min_i = $i;
    }

}

say $min_i;

#!/usr/bin/env perl

use strict;
use warnings;
use feature qw /say/;

my ($n, $t) = split q{ }, <STDIN>;

my @time_and_gap = ( (undef)x$n );
for ( @time_and_gap ) {
    $_ = [ split q{ }, <STDIN> ];
}

sub canTake {
    my $t = $_[0];
    my $idx = 1;
    for ( @time_and_gap ) {
        $_->[0] += $_->[1] if $_->[0] < $t;
        if ( $_->[0] == $t ) {
            return $idx;
        }
        $idx++;
    }
    canTake($t+1);
}

say canTake($t);

#!/usr/bin/env perl

use strict;
use warnings;
use feature qw /say/;

my ($n, $t) = split q{ }, <STDIN>;

my @time_and_gap = ( (undef)x$n );
for ( @time_and_gap ) {
    $_ = [ split q{ }, <STDIN> ];
}

sub canTake {
    my $t = $_[0];
    my $idx = 1;
    for ( @time_and_gap ) {
        $_->[0] += $_->[1] if $_->[0] < $t;
        if ( $_->[0] == $t ) {
            say $t;
            say $_->[0];
            return $idx;
        }
        $idx++;
    }
    canTake($t+1);
}

say canTake($t);


We just discovered a new data structure in our research group: a suffix three!It's very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in.It's super simple, 100% accurate, and doesn't involve advanced machine learning algorithms.Let us tell you how it works.  If a sentence ends with "po" the language is Filipino.  If a sentence ends with "desu" or "masu" the language is Japanese.  If a sentence ends with "mnida" the language is Korean. Given this, we need you to implement a suffix three that can differentiate Filipino, Japanese, and Korean.Oh, did I say three suffixes? I meant four.

The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 30$$$) denoting the number of test cases. The next lines contain descriptions of the test cases.  Each test case consists of a single line containing a single string denoting the sentence. Spaces are represented as underscores (the symbol "_") for ease of reading. The sentence has at least $$$1$$$ and at most $$$1000$$$ characters, and consists only of lowercase English letters and underscores. The sentence has no leading or trailing underscores and no two consecutive underscores. It is guaranteed that the sentence ends with one of the four suffixes mentioned above.

For each test case, print a single line containing either "FILIPINO", "JAPANESE", or "KOREAN" (all in uppercase, without quotes), depending on the detected language.

8
kamusta_po
genki_desu
ohayou_gozaimasu
annyeong_hashimnida
hajime_no_ippo
bensamu_no_sentou_houhou_ga_okama_kenpo
ang_halaman_doon_ay_sarisari_singkamasu
si_roy_mustang_ay_namamasu

FILIPINO
JAPANESE
JAPANESE
KOREAN
FILIPINO
FILIPINO
JAPANESE
JAPANESE

NoteThe first sentence ends with "po", so it is written in Filipino.The second and third sentences end with "desu" and "masu", so they are written in Japanese.The fourth sentence ends with "mnida", so it is written in Korean.

#!/usr/bin/env perl

use strict;
use warnings;
use feature qw/ say /;

# essential
my @tokens = ();

my $n = read_token();

for ( 1..$n ) {
    my $line = read_line();
    if ( $line =~ /po$/ ) {
        say "FILIPINO";
    }
    elsif ( $line =~ /desu$/ or $line =~ /masu$/ ) {
        say "JAPANESE";
    }
    else {
        say "KOREAN";
    }
}

sub read_line {
    chomp (my $line = <STDIN>);
    return $line;
}

sub read_token {
    @tokens = split q{ }, read_line() if @tokens == 0;
    return shift @tokens;
}

sub min {
    my @numbers = @_;
    my $min = shift @numbers;
    for ( @numbers ) {
        $min = $min<$_ ? $min : $_;
    }
    return $min;
}

sub max {
    my @numbers = @_;
    my $max = shift @numbers;
    for ( @numbers ) {
        $max = $max > $_ ? $max : $_;
    }
    return $max;
}

sub sum {
    my @numbers = @_;
    my $sum = 0;
    for (@numbers) {
        $sum += $_;
    }
    return $sum;
}


Phoenix has $$$n$$$ coins with weights $$$2^1, 2^2, \dots, 2^n$$$. He knows that $$$n$$$ is even.He wants to split the coins into two piles such that each pile has exactly $$$\frac{n}{2}$$$ coins and the difference of weights between the two piles is minimized. Formally, let $$$a$$$ denote the sum of weights in the first pile, and $$$b$$$ denote the sum of weights in the second pile. Help Phoenix minimize $$$|a-b|$$$, the absolute value of $$$a-b$$$.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 30$$$; $$$n$$$ is even) — the number of coins that Phoenix has.

For each test case, output one integer — the minimum possible difference of weights between the two piles.

NoteIn the first test case, Phoenix has two coins with weights $$$2$$$ and $$$4$$$. No matter how he divides the coins, the difference will be $$$4-2=2$$$.In the second test case, Phoenix has four coins of weight $$$2$$$, $$$4$$$, $$$8$$$, and $$$16$$$. It is optimal for Phoenix to place coins with weights $$$2$$$ and $$$16$$$ in one pile, and coins with weights $$$4$$$ and $$$8$$$ in another pile. The difference is $$$(2+16)-(4+8)=6$$$.

$t = <STDIN>;
chomp $t;
@test = <STDIN>;
chomp @test;

foreach (@test) {
    #print $_;
$loop = $_/2;
@coins = ();
$coins[0] = 2;
for ($i=1;$i<$_;$i = $i + 1) {
    push (@coins, $coins[$i-1]*2);
}
#foreach $coin (@coins) {
#    print "\n $coin";
#}
#print $loop;
$sum1 = 0;
$sum2 = 0;
if ($loop == 1) {
    $ans = $coins[1]-$coins[0];
    print "$ans\n";
}else{
    for ($j=0;$j<=$loop-2;$j=$j+1) {
        $sum1 = $sum1  + $coins[$j];
    }
    $sum1 = $sum1 + $coins[$_-1];
        for ($k=$loop-1;$j<=$_-2;$j=$j+1) {
        $sum2 = $sum2  + $coins[$j];
    }
    $ans = $sum1 - $sum2;
    #print "$sum1 $sum2";
    print "$ans\n";
}
}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	chomp;

	my $left = 0;

	$left += $_ for map { 2 ** $_ } 1 .. $_ / 2 - 1, $_;

	my $right = 0;

	$right += $_ for map { 2 ** $_ } $_ / 2 .. $_ - 1;

	print $left - $right;
	}


Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject in x hours.Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour.You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy.Please be careful that answer might not fit in 32 bit data type.

The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers: c1, c2, ..., cn (1 ≤ ci ≤ 105).

Output a single integer representing the answer to the problem.

NoteLook at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours.Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours.So overall, minimum of both the cases is 11 hours.Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours.

chomp($_ = <STDIN>);
@nums = split / /;
$x = $nums[1];
chomp($_ = <STDIN>);
@nums = split / /;
@nums = sort {$a <=> $b} @nums;
$r = 0;
foreach $n (@nums) {
	$r += $x*$n;
	if ($x > 1) {
		$x--;
	}
}
print $r;


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 ≤ 105; 0 ≤ x ≤ 2·105) — 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 ≤ 105) — the participants' points in the first tour. The third line contains n space-separated integers: b1, b2, ..., bn (0 ≤ bi ≤ 105) — 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.

NoteIn 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.


Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $$$s$$$ and a number $$$k$$$ ($$$0 \le k < |s|$$$).At the beginning of the game, players are given a substring of $$$s$$$ with left border $$$l$$$ and right border $$$r$$$, both equal to $$$k$$$ (i.e. initially $$$l=r=k$$$). Then players start to make moves one by one, according to the following rules: A player chooses $$$l^{\prime}$$$ and $$$r^{\prime}$$$ so that $$$l^{\prime} \le l$$$, $$$r^{\prime} \ge r$$$ and $$$s[l^{\prime}, r^{\prime}]$$$ is lexicographically less than $$$s[l, r]$$$. Then the player changes $$$l$$$ and $$$r$$$ in this way: $$$l := l^{\prime}$$$, $$$r := r^{\prime}$$$. Ann moves first. The player, that can't make a move loses.Recall that a substring $$$s[l, r]$$$ ($$$l \le r$$$) of a string $$$s$$$ is a continuous segment of letters from s that starts at position $$$l$$$ and ends at position $$$r$$$. For example, "ehn" is a substring ($$$s[3, 5]$$$) of "aaaehnsvz" and "ahz" is not.Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $$$s$$$ and $$$k$$$.Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $$$s$$$ and determines the winner for all possible $$$k$$$.

The first line of the input contains a single string $$$s$$$ ($$$1 \leq |s| \leq 5 \cdot 10^5$$$) consisting of lowercase English letters.

Print $$$|s|$$$ lines. In the line $$$i$$$ write the name of the winner (print Mike or Ann) in the game with string $$$s$$$ and $$$k = i$$$, if both play optimally

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

while(<>){
	$debug and print '-' x 15;
	chomp;

	$debug and print;

	my $min = substr $_, 0, 1;

	my @ans = 'Mike';

	for my $i ( 1 .. -1 + length ){
		my $letter = substr $_, $i, 1;

		$debug and print "$min lt $letter";

		if( $min lt $letter ){
			push @ans, 'Ann';
			}
		else{
			push @ans, 'Mike';
			}

		$letter lt $min and $min = $letter;
		}

	print for @ans;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 1;

while(<>){
	$debug and print '-' x 15;
	chomp;

	$debug and print;

	my $min = substr $_, 0, 1;

	my @ans = 'Mike';

	for my $i ( 1 .. -1 + length ){
		my $letter = substr $_, $i, 1;

		$debug and print "$min lt $letter";

		if( $min lt $letter ){
			push @ans, 'Ann';
			}
		else{
			push @ans, 'Mike';
			}

		$letter lt $min and $min = $letter;
		}

	print for @ans;
	}


Suppose you have an integer $$$v$$$. In one operation, you can:   either set $$$v = (v + 1) \bmod 32768$$$  or set $$$v = (2 \cdot v) \bmod 32768$$$. You are given $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of operations you need to make each $$$a_i$$$ equal to $$$0$$$?

The first line contains the single integer $$$n$$$ ($$$1 \le n \le 32768$$$) — the number of integers. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i < 32768$$$).

Print $$$n$$$ integers. The $$$i$$$-th integer should be equal to the minimum number of operations required to make $$$a_i$$$ equal to $$$0$$$.

NoteLet's consider each $$$a_i$$$:   $$$a_1 = 19$$$. You can, firstly, increase it by one to get $$$20$$$ and then multiply it by two $$$13$$$ times. You'll get $$$0$$$ in $$$1 + 13 = 14$$$ steps.  $$$a_2 = 32764$$$. You can increase it by one $$$4$$$ times: $$$32764 \rightarrow 32765 \rightarrow 32766 \rightarrow 32767 \rightarrow 0$$$.  $$$a_3 = 10240$$$. You can multiply it by two $$$4$$$ times: $$$10240 \rightarrow 20480 \rightarrow 8192 \rightarrow 16384 \rightarrow 0$$$.  $$$a_4 = 49$$$. You can multiply it by two $$$15$$$ times.

#!/usr/bin/perl
use Data::Dumper;
use integer;   ### important!
my $mod = 10 ** 9 + 7;
# my $mod = 998244353;

my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @A = map { $_ - 0 } split(/\s+/,<STDIN>);

my @resa = ();
for(my $i=0;$i<$n;$i++){
  my $a = $A[$i];
  my $res = 16;

  for(my $j=0;$j<=16;$j++){
    my $c = $j;
    my $v = ( $a + $c ) % 32768;
    while($v){
      $c++;
      $v = ($v<<1) % 32768;
    }
    $res = &min($res,$c);
  }
  push(@resa,$res);
}
print ( join(' ',@resa) . "\n" );
exit(0);

sub max {
  my $r = undef;
  foreach my $e (@_){  $r = $e if !defined($r) or $e > $r;  }
  return $r;
}
sub min {
  my $r = undef;
  foreach my $e (@_){  $r = $e if !defined($r) or $e < $r;  }
  return $r;
}
sub sum {
  my $r = 0;
  foreach my $e (@_){ $r += $e; }
  return $r;
}
sub ruisum {   # my @rui = (0); &ruisum(\@rui,\@array);
  my $r = shift; my $ar = shift;
  $#{$r} = 1+$#{$ar}; $r->[0] = 0; my $rr = 0;
  for(my $i=0;$i<=$#ar;$i++){
    $rr += $ar->[$i];
    $r->[1+$i] = $rr;
  }
}