You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.

First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.

For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).

NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

OUTER:
while(<>){

	@_ = split ' ', <>;

	for my $i ( 0 .. @_ - 1 ){
		if( $_[ $i ] < $i ){
			print "NO";
			next OUTER;
			}
		else{
			$_[ $i + 1 ] += $_[ $i ] - $i;
			}
		}

	print "YES";
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

OUTER:
while(<>){

	if( $_ == 1 ){
		print "NO";
		<>;
		next;
		}

	@_ = split ' ', <>;

	for my $i ( 0 .. @_ - 1 ){
		if( $_[ $i ] < $i ){
			print "NO";
			next OUTER;
			}
		else{
			$_[ $i + 1 ] += $_[ $i ] - $i;
			}
		}

	print "YES";
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){

	if( $_ == 1 ){
		print "NO";
		<>;
		next;
		}

	@_ = split ' ', <>;

	my $sum = 0;

	$sum += $_ for @_;

	if( @_ * ( @_ - 1 ) / 2 > $sum ){
		print "NO";
		}
	else{
		print "YES";
		}
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){

	if( $_ == 1 ){
		print "NO";
		next;
		}

	@_ = split ' ', <>;

	my $sum = 0;

	$sum += $_ for @_;

	if( @_ * ( @_ - 1 ) / 2 > $sum ){
		print "NO";
		}
	else{
		print "YES";
		}
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $sum = 0;

	$sum += $_ for @_;

	if( @_ * ( @_ - 1 ) / 2 > $sum ){
		print "NO";
		}
	else{
		print "YES";
		}

	}


You are walking through a parkway near your house. The parkway has $$$n+1$$$ benches in a row numbered from $$$1$$$ to $$$n+1$$$ from left to right. The distance between the bench $$$i$$$ and $$$i+1$$$ is $$$a_i$$$ meters.Initially, you have $$$m$$$ units of energy. To walk $$$1$$$ meter of distance, you spend $$$1$$$ unit of your energy. You can't walk if you have no energy. Also, you can restore your energy by sitting on benches (and this is the only way to restore the energy). When you are sitting, you can restore any integer amount of energy you want (if you sit longer, you restore more energy). Note that the amount of your energy can exceed $$$m$$$.Your task is to find the minimum amount of energy you have to restore (by sitting on benches) to reach the bench $$$n+1$$$ from the bench $$$1$$$ (and end your walk).You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 100$$$; $$$1 \le m \le 10^4$$$). The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the distance between benches $$$i$$$ and $$$i+1$$$.

For each test case, print one integer — the minimum amount of energy you have to restore (by sitting on benches) to reach the bench $$$n+1$$$ from the bench $$$1$$$ (and end your walk) in the corresponding test case.

NoteIn the first test case of the example, you can walk to the bench $$$2$$$, spending $$$1$$$ unit of energy, then restore $$$2$$$ units of energy on the second bench, walk to the bench $$$3$$$, spending $$$2$$$ units of energy, restore $$$1$$$ unit of energy and go to the bench $$$4$$$.In the third test case of the example, you have enough energy to just go to the bench $$$6$$$ without sitting at all.


AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays $$$a$$$ and $$$b$$$, both consist of $$$n$$$ non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero):  She chooses two indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$), then decreases the $$$i$$$-th element of array $$$a$$$ by $$$1$$$, and increases the $$$j$$$-th element of array $$$a$$$ by $$$1$$$. The resulting values at $$$i$$$-th and $$$j$$$-th index of array $$$a$$$ are $$$a_i - 1$$$ and $$$a_j + 1$$$, respectively. Each element of array $$$a$$$ must be non-negative after each operation. If $$$i = j$$$ this operation doesn't change the array $$$a$$$. AquaMoon wants to make some operations to make arrays $$$a$$$ and $$$b$$$ equal. Two arrays $$$a$$$ and $$$b$$$ are considered equal if and only if $$$a_i = b_i$$$ for all $$$1 \leq i \leq n$$$.Help AquaMoon to find a sequence of operations that will solve her problem or find, that it is impossible to make arrays $$$a$$$ and $$$b$$$ equal.Please note, that you don't have to minimize the number of operations.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \leq a_i \leq 100$$$). The sum of all $$$a_i$$$ does not exceed $$$100$$$. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$0 \leq b_i \leq 100$$$). The sum of all $$$b_i$$$ does not exceed $$$100$$$.

For each test case print "-1" on the only line if it is impossible to make two arrays equal with some sequence of operations. Otherwise, print an integer $$$m$$$ ($$$0 \leq m \leq 100$$$) in the first line — the number of operations. Then print $$$m$$$ lines, each line consists of two integers $$$i$$$ and $$$j$$$ — the indices you choose for the operation. It can be proven that if it is possible to make two arrays equal with some sequence of operations, there exists a sequence with $$$m \leq 100$$$. If there are multiple possible solutions, you can print any.

NoteIn the first example, we do the following operations:  $$$i = 2$$$, $$$j = 1$$$: $$$[1, 2, 3, 4] \rightarrow [2, 1, 3, 4]$$$;  $$$i = 3$$$, $$$j = 1$$$: $$$[2, 1, 3, 4] \rightarrow [3, 1, 2, 4]$$$; In the second example, it's impossible to make two arrays equal.


Ever since Kalevitch, a famous Berland abstractionist, heard of fractals, he made them the main topic of his canvases. Every morning the artist takes a piece of graph paper and starts with making a model of his future canvas. He takes a square as big as n × n squares and paints some of them black. Then he takes a clean square piece of paper and paints the fractal using the following algorithm: Step 1. The paper is divided into n2 identical squares and some of them are painted black according to the model.Step 2. Every square that remains white is divided into n2 smaller squares and some of them are painted black according to the model.Every following step repeats step 2.  Unfortunately, this tiresome work demands too much time from the painting genius. Kalevitch has been dreaming of making the process automatic to move to making 3D or even 4D fractals.

The first line contains integers n and k (2 ≤ n ≤ 3, 1 ≤ k ≤ 5), where k is the amount of steps of the algorithm. Each of the following n lines contains n symbols that determine the model. Symbol «.» stands for a white square, whereas «*» stands for a black one. It is guaranteed that the model has at least one white square.

Output a matrix nk × nk which is what a picture should look like after k steps of the algorithm.


Hiking club "Up the hill" just returned from a walk. Now they are trying to remember which hills they've just walked through.It is known that there were N stops, all on different integer heights between 1 and N kilometers (inclusive) above the sea level. On the first day they've traveled from the first stop to the second stop, on the second day they've traveled from the second to the third and so on, and on the last day they've traveled from the stop N - 1 to the stop N and successfully finished their expedition.They are trying to find out which heights were their stops located at. They have an entry in a travel journal specifying how many days did they travel up the hill, and how many days did they walk down the hill.Help them by suggesting some possible stop heights satisfying numbers from the travel journal.

In the first line there is an integer non-negative number A denoting the number of days of climbing up the hill. Second line contains an integer non-negative number B — the number of days of walking down the hill (A + B + 1 = N, 1 ≤ N ≤ 100 000).

Output N space-separated distinct integers from 1 to N inclusive, denoting possible heights of the stops in order of visiting.


Luis has a sequence of $$$n+1$$$ integers $$$a_1, a_2, \ldots, a_{n+1}$$$. For each $$$i = 1, 2, \ldots, n+1$$$ it is guaranteed that $$$0\leq a_i < n$$$, or $$$a_i=n^2$$$. He has calculated the sum of all the elements of the sequence, and called this value $$$s$$$. Luis has lost his sequence, but he remembers the values of $$$n$$$ and $$$s$$$. Can you find the number of elements in the sequence that are equal to $$$n^2$$$?We can show that the answer is unique under the given constraints.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2\cdot 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$n$$$ and $$$s$$$ ($$$1\le n< 10^6$$$, $$$0\le s \le 10^{18}$$$). It is guaranteed that the value of $$$s$$$ is a valid sum for some sequence satisfying the above constraints.

For each test case, print one integer — the number of elements in the sequence which are equal to $$$n^2$$$.

NoteIn the first test case, we have $$$s=0$$$ so all numbers are equal to $$$0$$$ and there isn't any number equal to $$$49$$$.In the second test case, we have $$$s=1$$$. There are two possible sequences: $$$[0, 1]$$$ or $$$[1, 0]$$$. In both cases, the number $$$1$$$ appears just once. In the third test case, we have $$$s=12$$$, which is the maximum possible value of $$$s$$$ for this case. Thus, the number $$$4$$$ appears $$$3$$$ times in the sequence.


Polycarp wants to cook a soup. To do it, he needs to buy exactly $$$n$$$ liters of water.There are only two types of water bottles in the nearby shop — $$$1$$$-liter bottles and $$$2$$$-liter bottles. There are infinitely many bottles of these two types in the shop.The bottle of the first type costs $$$a$$$ burles and the bottle of the second type costs $$$b$$$ burles correspondingly.Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly $$$n$$$ liters of water in the nearby shop if the bottle of the first type costs $$$a$$$ burles and the bottle of the second type costs $$$b$$$ burles. You also have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. The next $$$q$$$ lines contain queries. The $$$i$$$-th query is given as three space-separated integers $$$n_i$$$, $$$a_i$$$ and $$$b_i$$$ ($$$1 \le n_i \le 10^{12}, 1 \le a_i, b_i \le 1000$$$) — how many liters Polycarp needs in the $$$i$$$-th query, the cost (in burles) of the bottle of the first type in the $$$i$$$-th query and the cost (in burles) of the bottle of the second type in the $$$i$$$-th query, respectively.

Print $$$q$$$ integers. The $$$i$$$-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly $$$n_i$$$ liters of water in the nearby shop if the bottle of the first type costs $$$a_i$$$ burles and the bottle of the second type costs $$$b_i$$$ burles.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $sum = 0;

	if( $n % 2 == 1 ){
		$sum += $A;
		$n --;
		}

	if( $A * 2 < $B ){
		print $sum + $n * $A;
		}
	else{
		print $sum + $n * $B / 2;
		}

	}


There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$.

The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat.

Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed.

NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples.


One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):   point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y  point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y  point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y  point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.

The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.

Print the only number — the number of supercentral points of the given set.

NoteIn the first sample the supercentral points are only points (1, 1) and (1, 2).In the second sample there is one supercental point — point (0, 0).

#!/usr/bin/perl
use warnings;
use strict;
chomp(my $n = <STDIN>);
my @pts = ();
while($n-- > 0){
	my @tmp = split(/[\s\/n]/,<STDIN>);
	push(@pts,\@tmp);
}
my @check = (0,0,0,0);
my $count = 0;
foreach my $pt (@pts) {
	@check = (0,0,0,0);
	foreach my $otherpt (@pts) {
		if($$pt[0]==$$otherpt[0]){
			$check[0] = 1 if($$pt[1]>$$otherpt[1]);
			$check[1] = 1 if($$pt[1]<$$otherpt[1]);
		}
		elsif($$pt[1]==$$otherpt[1]){
			$check[2] = 1 if($$pt[0]>$$otherpt[0]);
			$check[3] = 1 if($$pt[0]<$$otherpt[0]);
		}
	}
	my $checksum = 0;
	$checksum += $_ for @check;
	$count++ if($checksum == 4);
}

print $count;

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

chomp (my $n = <>);

my @dots;
push @dots, <> for ($n);

my $count = 0;

foreach my $dot (@dots)
{
    my $index = shift;
    my ($x, $y) = split / /, $dot;
    my $bits;

    foreach (@dots)
    {
        my ($x_, $y_) = split / /, $_;

            if ($x eq $x_)
            {
                $bits |= 1 if ($y_ > $y);
                $bits |= 2 if ($y_ < $y);
            }

            if ($y eq $y_)
            {
                $bits |= 4 if ($x_ < $x);
                $bits |= 8 if ($x_ > $x);
            }

    }

    $count++ if ($bits eq 15);
}

print $count, "\n";

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

my $n = <>;
my @dots;
push @dots, <> for ($n);

my $count = 0;
foreach my $dot (@dots)
{
    my $index = shift;
    my ($x, $y) = split /\s/, $dot;
    my $bits;

    foreach (@dots)
    {
        my ($x_, $y_) = split /\s/;

        $bits |= ($y_ < $y)? 1 : (($y_ > $y) ? 2 : 0) if ($x eq $x_);
        $bits |= ($x_ < $x)? 4 : (($x_ > $x) ? 8 : 0) if ($y eq $y_);
    }

    $count++ if ($bits eq 15);
}

print $count, "\n";

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

chomp (my $n = <>);

my @dots;
push @dots, <> for ($n);

my $count = 0;

sub is_super($)
{
    my $index = shift;
    my ($x, $y) = split / /, $dots[$index];
    chomp ($y);
    my $score = 0;
    my ($left, $right, $up, $down) = (0,0,0,0);

    foreach (@dots)
    {
        chomp($_);
        my ($x_, $y_) = split / /, $_;

            if ($x eq $x_)
            {
                $up = ($y_ > $y) if (!$up);
                $down = ($y_ < $y) if (!$down);
            }

            if ($y eq $y_)
            {
                $left = ($x_ < $x) if (!$left);
                $right = ($x_ > $x) if (!$right);
            }

    }

    $count++ if ($left && $right && $up && $down);
}

is_super($_) for (0..$n-1);

print $count, "\n";

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

chomp (my $n = <>);

my @dots;
push @dots, <> for ($n);

my $count = 0;

sub is_super($)
{
    my $index = shift;
    my ($x, $y) = split / /, $dots[$index];
    chomp ($y);
    my $score = 0;

    foreach (@dots)
    {
        chomp($_);
        my ($x_, $y_) = split / /, $_;

        $score++ if (($x > $x_) and ($y eq $y_));
        $score++ if (($x < $x_) and ($y eq $y_));
        $score++ if (($x eq $x_) and ($y > $y_));
        $score++ if (($x eq $x_) and ($y < $y_));
    }

    $count++ if ($score >= 4);
}

is_super($_) for (0..$n-1);

print $count, "\n";

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

chomp (my $n = <>);

my @dots;
push @dots, <> for ($n);

my $count = 0;

sub is_super($)
{
    my $index = shift;
    my ($x, $y) = split / /, $dots[$index];
    chomp ($y);
    my $score = 0;

    foreach (@dots)
    {
        chomp($_);
        my ($x_, $y_) = split / /, $_;

        if (($x_ ne $x) and ($y_ ne $y))
        {
            $score++ if ($x > $x_ and $y eq $y_);
            $score++ if ($x < $x_ and $y eq $y_);
            $score++ if ($x == $x and $y > $y_);
            $score++ if ($x == $x and $y < $y_);
        }
    }

    $count++ if ($score >= 4);
}

for (0..$n-1)
{
    is_super($_);
}

print $count, "\n";

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

chomp (my $n = <>);

my @dots;
push @dots, <> for ($n);

my $count = 0;

sub is_super($)
{
    my $index = shift;
    my ($x, $y) = split / /, $dots[$index];
    chomp ($y);
    my $score = 0;

    foreach (@dots)
    {
        chomp($_);
        my ($x_, $y_) = split / /, $_;

        if (($x_ ne $x) and ($y_ ne $y))
        {
            $score++ if ($x > $x_ and $y eq $y_);
            $score++ if ($x < $x_ and $y eq $y_);
            $score++ if ($x == $x and $y > $y_);
            $score++ if ($x == $x and $y < $y_);
        }
    }

    $count++ if ($score > 4);
}

for (0..$n-1)
{
    is_super($_);
}

print $count, "\n";


So the Beautiful Regional Contest (BeRC) has come to an end! $$$n$$$ students took part in the contest. The final standings are already known: the participant in the $$$i$$$-th place solved $$$p_i$$$ problems. Since the participants are primarily sorted by the number of solved problems, then $$$p_1 \ge p_2 \ge \dots \ge p_n$$$.Help the jury distribute the gold, silver and bronze medals. Let their numbers be $$$g$$$, $$$s$$$ and $$$b$$$, respectively. Here is a list of requirements from the rules, which all must be satisfied:  for each of the three types of medals, at least one medal must be awarded (that is, $$$g>0$$$, $$$s>0$$$ and $$$b>0$$$);  the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, $$$g<s$$$ and $$$g<b$$$, but there are no requirements between $$$s$$$ and $$$b$$$);  each gold medalist must solve strictly more problems than any awarded with a silver medal;  each silver medalist must solve strictly more problems than any awarded a bronze medal;  each bronze medalist must solve strictly more problems than any participant not awarded a medal;  the total number of medalists $$$g+s+b$$$ should not exceed half of all participants (for example, if $$$n=21$$$, then you can award a maximum of $$$10$$$ participants, and if $$$n=26$$$, then you can award a maximum of $$$13$$$ participants). The jury wants to reward with medals the total maximal number participants (i.e. to maximize $$$g+s+b$$$) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals.

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10000$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. The first line of a test case contains an integer $$$n$$$ ($$$1 \le n \le 4\cdot10^5$$$) — the number of BeRC participants. The second line of a test case contains integers $$$p_1, p_2, \dots, p_n$$$ ($$$0 \le p_i \le 10^6$$$), where $$$p_i$$$ is equal to the number of problems solved by the $$$i$$$-th participant from the final standings. The values $$$p_i$$$ are sorted in non-increasing order, i.e. $$$p_1 \ge p_2 \ge \dots \ge p_n$$$. The sum of $$$n$$$ over all test cases in the input does not exceed $$$4\cdot10^5$$$.

Print $$$t$$$ lines, the $$$j$$$-th line should contain the answer to the $$$j$$$-th test case. The answer consists of three non-negative integers $$$g, s, b$$$.   Print $$$g=s=b=0$$$ if there is no way to reward participants with medals so that all requirements from the statement are satisfied at the same time.  Otherwise, print three positive numbers $$$g, s, b$$$ — the possible number of gold, silver and bronze medals, respectively. The sum of $$$g+s+b$$$ should be the maximum possible. If there are several answers, print any of them.

NoteIn the first test case, it is possible to reward $$$1$$$ gold, $$$2$$$ silver and $$$3$$$ bronze medals. In this case, the participant solved $$$5$$$ tasks will be rewarded with the gold medal, participants solved $$$4$$$ tasks will be rewarded with silver medals, participants solved $$$2$$$ or $$$3$$$ tasks will be rewarded with bronze medals. Participants solved exactly $$$1$$$ task won't be rewarded. It's easy to see, that in this case, all conditions are satisfied and it is possible to reward participants in this way. It is impossible to give more than $$$6$$$ medals because the number of medals should not exceed half of the number of participants. The answer $$$1$$$, $$$3$$$, $$$2$$$ is also correct in this test case.In the second and third test cases, it is impossible to reward medals, because at least one medal of each type should be given, but the number of medals should not exceed half of the number of participants.

my $tests = <>;
chomp ($tests);
foreach my $t (1..$tests) {
 my $n = <>;
 chomp($n);
 my @arr = split(" ",<>);
 my $size = $#arr + 1;
 my $h_size = int($size / 2);
 #print "\$size:$size -- h_size:$h_size\n";
 my $g = 0 ;
 my $s = 0 ;
 my $b = 0 ;
 my $b_flag = 0;
 my $s_flag = 0;
 my $b_block =0 ;
 for (my $i = 0  ; $i <= $size ; $i=$i+1) {
     #if ($n <= 5) {$g=0;$s=0;$b=0;last;}
     my $sum = $g + $s + $b;
     #print "\sum:$sum-($h_size)\n";
     if ($sum > $h_size) {$g=0;$s=0;$b=0;last;}
     if ($b_flag) {
         if ($arr[$i] == $arr[$i+1]) {
             $b_block = $b_block +1;
         } else {
             $b_block = $b_block +1;
             my $sum =  $g + $s + $b + $b_block;
             if ($sum > $h_size) {
              last;
             } else {
              $b = $b + $b_block;
              $b_block =0 ;
             }
         }
     } elsif ($s_flag) {
         if ($arr[$i] == $arr[$i+1]) {
             $s = $s +1;
         } else {
             $s = $s + 1;
             if ($s > $g) {
                 $b_flag = 1;
                 $s_flag = 0;
             }
         }
     } else {
         if ($arr[$i] == $arr[$i+1]) {
             $g = $g +1;
         } else {
             $g = $g +1 ;
             $s_flag = 1;
         }
     }
 }
 if ($b == 0) {$g=0;$s=0;$b=0;}
 print "$g $s $b\n";
}

my $tests = <>;
chomp ($tests);
foreach my $t (1..$tests) {
 my $n = <>;
 chomp($n);
 my @arr = split(" ",<>);
 my $size = $#arr + 1;
 my $h_size = int($size / 2);
 #print "\$size:$size -- h_size:$h_size\n";
 my $g = 0 ;
 my $s = 0 ;
 my $b = 0 ;
 my $b_flag = 0;
 my $s_flag = 0;
 my $b_block =0 ;
 for (my $i = 0  ; $i <= $size ; $i=$i+1) {
     #print "$arr[$i]";
     #if ($n <= 5) {$g=0;$s=0;$b=0;last;}
     my $sum = $g + $s + $b;
     #print "\sum:$sum-($h_size)\n";
     if ($sum > $h_size) {$g=0;$s=0;$b=0;last;}
     if ($b_flag) {
         if ($arr[$i] == $arr[$i+1]) {
             $b_block = $b_block +1;
         } else {
             $b_block = $b_block +1;
             my $sum =  $g + $s + $b + $b_block;
             if ($sum > $h_size) {
              last;
             } else {
              $b = $b + $b_block;
              $b_block =0 ;
             }
         }
     } elsif ($s_flag) {
         if ($arr[$i] == $arr[$i+1]) {
             $s = $s +1;
         } else {
             $s = $s + 1;
             if ($s > $g) {
                 $b_flag = 1;
                 $s_flag = 0;
             }
         }
     } else {
         if ($arr[$i] == $arr[$i+1]) {
             $g = $g +1;
         } else {
             $g = $g +1 ;
             #$s++;
             $s_flag = 1;
         }
     }
 }
 print "$g $s $b\n";
}


You are given a sequence of positive integers a1, a2, ..., an. Find all such indices i, that the i-th element equals the arithmetic mean of all other elements (that is all elements except for this one).

The first line contains the integer n (2 ≤ n ≤ 2·105). The second line contains elements of the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000). All the elements are positive integers.

Print on the first line the number of the sought indices. Print on the second line the sought indices in the increasing order. All indices are integers from 1 to n. If the sought elements do not exist, then the first output line should contain number 0. In this case you may either not print the second line or print an empty line.


After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has n balls and m baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to m, correspondingly. The balls are numbered with numbers from 1 to n.Valeric decided to sort the balls in the order of increasing of their numbers by the following scheme. He will put each new ball in the basket with the least number of balls. And if he's got several variants, he chooses the basket which stands closer to the middle. That means that he chooses the basket for which  is minimum, where i is the number of the basket. If in this case Valeric still has multiple variants, he chooses the basket with the minimum number.For every ball print the number of the basket where it will go according to Valeric's scheme.Note that the balls are sorted into baskets in the order of increasing numbers, that is, the first ball goes first, then goes the second ball and so on.

The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 105) — the number of balls and baskets, correspondingly.

Print n numbers, one per line. The i-th line must contain the number of the basket for the i-th ball.

#!/usr/bin/perl

use 5.006;
use strict;
use warnings;

my $n;
my $m;

sub mcmp {
  my $v1 = abs (($m + 1) / 2 - $a);
  my $v2 = abs (($m + 1) / 2 - $b);
  return -1 if($v1 < $v2);
  return -1 if ($v1 == $v2 && $a < $b);
  return 1;
}

my $num = <>;
my @arr = split(/ /, $num);
$n = $arr[0];
$m = $arr[1];
my @array = ();
for(1..$m) {
    push @array, $_;
}
my @ans= sort mcmp @array;
for(0..($n - 1)) {
  my $t = int($_ % $m);
  print "$ans[$t]\n";
}

#!perl -w
use strict;
use warnings;
use POSIX qw[ceil];

main();

sub main {
    my ($n, $m) = split /\D/, <>;
    my @arr;
    for my $i (0..int($m / 2)-1) {
        unshift @arr, $m - $i;
        unshift @arr, $i + 1;
    }
    if ($m & 1) {
        unshift @arr, int($m / 2) + 1;
    }
    my $c = 0;
    for my $i (1..$n) {
        print $arr[$c % @arr], "\n";
        $c++;
    }
}

__END__


There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X" or "O". Then the player chooses two positive integers a and b (a·b = 12), after that he makes a table of size a × b from the cards he put on the table as follows: the first b cards form the first row of the table, the second b cards form the second row of the table and so on, the last b cards form the last (number a) row of the table. The player wins if some column of the table contain characters "X" on all cards. Otherwise, the player loses.Inna has already put 12 cards on the table in a row. But unfortunately, she doesn't know what numbers a and b to choose. Help her win the game: print to her all the possible ways of numbers a, b that she can choose and win.

The first line of the input contains integer t (1 ≤ t ≤ 100). This value shows the number of sets of test data in the input. Next follows the description of each of the t tests on a separate line. The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The i-th character of the string shows the character that is written on the i-th card from the start.

For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair a, b. Next, print on this line the pairs in the format axb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespaces.

4
OXXXOXOOXOOX
OXOXOXOXOXOX
XXXXXXXXXXXX
OOOOOOOOOOOO

use warnings;
use strict ;
use List::Util qw(first max maxstr min minstr reduce shuffle sum);

my $n = <>;
my @data = (<>);

for my $str (@data)
{
    chomp $str;
    $str or next;
    my @u = split //, $str;

    my @res = ();
    for my $rows (1, 2, 3, 4, 6, 12)
    {
        my $rl = @u / $rows;

        for my $i (0..$rl-1)
        {

            #print $i;
            my $en = join "", map $u[$_* $rl + $i], 0..$rows-1;

            if ($en eq 'X'x $rows )
            {
                #print "ok";
                push @res, $rows . "x" . $rl;
                last;
            }
        }

    }
    print join " ", (scalar(@res),  @res);
    print "\n";

}


You are given an array $$$a$$$ consisting of $$$n$$$ integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from $$$a$$$ to make it a good array. Recall that the prefix of the array $$$a=[a_1, a_2, \dots, a_n]$$$ is a subarray consisting several first elements: the prefix of the array $$$a$$$ of length $$$k$$$ is the array $$$[a_1, a_2, \dots, a_k]$$$ ($$$0 \le k \le n$$$).The array $$$b$$$ of length $$$m$$$ is called good, if you can obtain a non-decreasing array $$$c$$$ ($$$c_1 \le c_2 \le \dots \le c_{m}$$$) from it, repeating the following operation $$$m$$$ times (initially, $$$c$$$ is empty):  select either the first or the last element of $$$b$$$, remove it from $$$b$$$, and append it to the end of the array $$$c$$$. For example, if we do $$$4$$$ operations: take $$$b_1$$$, then $$$b_{m}$$$, then $$$b_{m-1}$$$ and at last $$$b_2$$$, then $$$b$$$ becomes $$$[b_3, b_4, \dots, b_{m-3}]$$$ and $$$c =[b_1, b_{m}, b_{m-1}, b_2]$$$.Consider the following example: $$$b = [1, 2, 3, 4, 4, 2, 1]$$$. This array is good because we can obtain non-decreasing array $$$c$$$ from it by the following sequence of operations:  take the first element of $$$b$$$, so $$$b = [2, 3, 4, 4, 2, 1]$$$, $$$c = [1]$$$;  take the last element of $$$b$$$, so $$$b = [2, 3, 4, 4, 2]$$$, $$$c = [1, 1]$$$;  take the last element of $$$b$$$, so $$$b = [2, 3, 4, 4]$$$, $$$c = [1, 1, 2]$$$;  take the first element of $$$b$$$, so $$$b = [3, 4, 4]$$$, $$$c = [1, 1, 2, 2]$$$;  take the first element of $$$b$$$, so $$$b = [4, 4]$$$, $$$c = [1, 1, 2, 2, 3]$$$;  take the last element of $$$b$$$, so $$$b = [4]$$$, $$$c = [1, 1, 2, 2, 3, 4]$$$;  take the only element of $$$b$$$, so $$$b = []$$$, $$$c = [1, 1, 2, 2, 3, 4, 4]$$$ — $$$c$$$ is non-decreasing. Note that the array consisting of one element is good.Print the length of the shortest prefix of $$$a$$$ to delete (erase), to make $$$a$$$ to be a good array. Note that the required length can be $$$0$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2 \cdot 10^5$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer: the length of the shortest prefix of elements you need to erase from $$$a$$$ to make it a good array.

NoteIn the first test case of the example, the array $$$a$$$ is already good, so we don't need to erase any prefix.In the second test case of the example, the initial array $$$a$$$ is not good. Let's erase first $$$4$$$ elements of $$$a$$$, the result is $$$[4, 5, 2]$$$. The resulting array is good. You can prove that if you erase fewer number of first elements, the result will not be good.


There are $$$n$$$ people participating in some contest, they start participating in $$$x$$$ minutes intervals. That means the first participant starts at time $$$0$$$, the second participant starts at time $$$x$$$, the third — at time $$$2 \cdot x$$$, and so on.Duration of contest is $$$t$$$ minutes for each participant, so the first participant finishes the contest at time $$$t$$$, the second — at time $$$t + x$$$, and so on. When a participant finishes the contest, their dissatisfaction equals to the number of participants that started the contest (or starting it now), but haven't yet finished it.Determine the sum of dissatisfaction of all participants.

The first line contains a single integer $$$k$$$ ($$$1 \le k \le 1000$$$) — the number of test cases. Each of the next $$$k$$$ lines contains three integers $$$n$$$, $$$x$$$, $$$t$$$ ($$$1 \le n, x, t \le 2 \cdot 10^9$$$) — the number of participants, the start interval and the contest duration.

Print $$$k$$$ lines, in the $$$i$$$-th line print the total dissatisfaction of participants in the $$$i$$$-th test case.

NoteIn the first example the first participant starts at $$$0$$$ and finishes at time $$$5$$$. By that time the second and the third participants start, so the dissatisfaction of the first participant is $$$2$$$. The second participant starts at time $$$2$$$ and finishes at time $$$7$$$. By that time the third the fourth participants start, so the dissatisfaction of the second participant is $$$2$$$. The third participant starts at $$$4$$$ and finishes at $$$9$$$. By that time the fourth participant starts, so the dissatisfaction of the third participant is $$$1$$$.The fourth participant starts at $$$6$$$ and finishes at $$$11$$$. By time $$$11$$$ everyone finishes the contest, so the dissatisfaction of the fourth participant is $$$0$$$.In the second example the first participant starts at $$$0$$$ and finishes at time $$$2$$$. By that time the second participants starts, and the third starts at exactly time $$$2$$$. So the dissatisfaction of the first participant is $$$2$$$. The second participant starts at time $$$1$$$ and finishes at time $$$3$$$. At that time the third participant is solving the contest.

use bigint;

chomp(my $k = <STDIN>);
for (; $k > 0; $k--) {
    my $s = <STDIN>;
    my @arr = split(" ", $s);
    my $n = int($arr[0]);
    my $x = int($arr[1]);
    my $t = int($arr[2]);
    my $sum = $x + $t;
    if ($t < $x) {
        print "0\n";
    } else {
        $other_max = int($t / $x);
        $result = $n * ($n - 1) / 2;
        if ($other_max <= $n) {
            $result = ($other_max) * ($other_max + 1) / 2;
            $result += $other_max * ($n - $other_max - 1);
        }
        print "$result\n";
    }
}

chomp(my $k = <STDIN>);
for (; $k > 0; $k--) {
    my $s = <STDIN>;
    my @arr = split(" ", $s);
    my $n = int($arr[0]);
    my $x = int($arr[1]);
    my $t = int($arr[2]);
    my $sum = $x + $t;
    if ($t < $x) {
        print "0\n";
    } else {
        $other_max = int(($t + $x - 1) / $x) - 1;
        $result = $n * ($n - 1) / 2;
        if ($other_max <= $n) {
            $result = ($other_max) * ($other_max + 1) / 2;
            $result += $other_max * ($n - $other_max - 1);
        }
        print "$result\n";
    }
}


You are given an array $$$a$$$ consisting of $$$n$$$ positive integers.You are allowed to perform this operation any number of times (possibly, zero):   choose an index $$$i$$$ ($$$2 \le i \le n$$$), and change $$$a_i$$$ to $$$a_i - a_{i-1}$$$. Is it possible to make $$$a_i=0$$$ for all $$$2\le i\le n$$$?

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$)  — the number of test cases. The description of the test cases follows. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$).

For each test case, print "YES" (without quotes), if it is possible to change $$$a_i$$$ to $$$0$$$ for all $$$2 \le i \le n$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower).

NoteIn the first test case, the initial array is $$$[5,10]$$$. You can perform $$$2$$$ operations to reach the goal:  Choose $$$i=2$$$, and the array becomes $$$[5,5]$$$.  Choose $$$i=2$$$, and the array becomes $$$[5,0]$$$. In the second test case, the initial array is $$$[1,2,3]$$$. You can perform $$$4$$$ operations to reach the goal:   Choose $$$i=3$$$, and the array becomes $$$[1,2,1]$$$.  Choose $$$i=2$$$, and the array becomes $$$[1,1,1]$$$.  Choose $$$i=3$$$, and the array becomes $$$[1,1,0]$$$.  Choose $$$i=2$$$, and the array becomes $$$[1,0,0]$$$. In the third test case, you can choose indices in the order $$$4$$$, $$$3$$$, $$$2$$$.

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

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

while( $testcase -- > 0 ){

  my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
  my @A = map { $_ - 0 } split(/\s+/,<STDIN>);
  my $a0 = $A[0];
  my $res = 'YES';
  for(my $i=1;$i<$n;$i++){
      if( $A[$i] % $a0 != 0 ){
	  $res = 'NO'; last;
      }
  }
  print "$res\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;
  }
}


Martians are actively engaged in interplanetary trade. Olymp City, the Martian city known for its spaceport, has become a place where goods from all the corners of our Galaxy come. To deliver even more freight from faraway planets, Martians need fast spaceships.A group of scientists conducts experiments to build a fast engine for the new spaceship. In the current experiment, there are $$$n$$$ elementary particles, the $$$i$$$-th of them has type $$$a_i$$$.Denote a subsegment of the particle sequence ($$$a_1, a_2, \dots, a_n$$$) as a sequence ($$$a_l, a_{l+1}, \dots, a_r$$$) for some left bound $$$l$$$ and right bound $$$r$$$ ($$$1 \le l \le r \le n$$$). For instance, the sequence $$$(1\ 4\ 2\ 8\ 5\ 7)$$$ for $$$l=2$$$ and $$$r=4$$$ has the sequence $$$(4\ 2\ 8)$$$ as a subsegment. Two subsegments are considered different if at least one bound of those subsegments differs.Note that the subsegments can be equal as sequences but still considered different. For example, consider the sequence $$$(1\ 1\ 1\ 1\ 1)$$$ and two of its subsegments: one with $$$l=1$$$ and $$$r=3$$$ and another with $$$l=2$$$ and $$$r=4$$$. Both subsegments are equal to $$$(1\ 1\ 1)$$$, but still considered different, as their left and right bounds differ.The scientists want to conduct a reaction to get two different subsegments of the same length. Denote this length $$$k$$$. The resulting pair of subsegments must be harmonious, i. e. for some $$$i$$$ ($$$1 \le i \le k$$$) it must be true that the types of particles on the $$$i$$$-th position are the same for these two subsegments. For example, the pair $$$(1\ 7\ 3)$$$ and $$$(4\ 7\ 8)$$$ is harmonious, as both subsegments have $$$7$$$ on the second position. The pair $$$(1\ 2\ 3)$$$ and $$$(3\ 1\ 2)$$$ is not harmonious.The longer are harmonious subsegments, the more chances for the scientists to design a fast engine. So, they asked you to calculate the maximal possible length of harmonious pair made of different subsegments.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The following are descriptions of the test cases. The first line contains an integer $$$n$$$ ($$$2 \le n \le 150\,000$$$) — the amount of elementary particles in the sequence. The second line contains $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 150\,000$$$) — types of elementary particles. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3\cdot10^5$$$.

For each test, print a single integer, maximal possible length of harmonious pair made of different subsegments. If such pair does not exist, print $$$-1$$$ instead.

NoteThe first test case is shown on the picture below:  As you can see from it, you may choose the subsegments $$$(2\ 1\ 3\ 4)$$$ and $$$(3\ 1\ 5\ 2)$$$, which are a harmonious pair. Their length is equal to $$$4$$$, so the answer is $$$4$$$.In the second test case, you need to take two subsegments: one with $$$l=1$$$ and $$$r=5$$$, and one with $$$l=2$$$ and $$$r=6$$$. It's not hard to observe that these segments are a harmonious pair and considered different even though they are both equal to $$$(1\ 1\ 1\ 1\ 1)$$$.In the third test case, you cannot make a harmonious pair, so the answer is $$$-1$$$.

#!/usr/bin/perl

use warnings;
use strict;

my $debug = 0;

$\ = $/;

<>;

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

	@_ = split ' ', <>;

	$debug and print "[@_]";

	my @cand;

	my %h;

	for my $i ( 0 .. @_ - 1 ){
		exists $h{ $_[ $i ] } and push @cand, @_ - $i + $h{ $_[ $i ] };

		$h{ $_[ $i ] } = $i;
		}

	print !@cand ? -1 : 0 + ( sort { $b <=> $a } @cand )[ 0 ];
	}

#!/usr/bin/perl

use warnings;
use strict;

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

<>;

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

	@_ = split ' ', <>;

	$debug and print "[@_]";

	my @cand;

	leftmost_two( \@cand, \@_ );

	@_ = reverse @_;

	leftmost_two( \@cand, \@_ );

	print !@cand ? -1 : 0 + ( sort { $b <=> $a } @cand )[ 0 ];
	}

sub leftmost_two {
	my( $ref_cand, $ref_array ) = @_;

	my %h;

	for my $i ( 0 .. @{ $ref_array } - 1 ){
		if( not exists $h{ $$ref_array[ $i ] } ){
			$h{ $$ref_array[ $i ] } = $i;
			}
		elsif( $h{ $$ref_array[ $i ] } == @{ $ref_array } ){
			next;
			}
		else{
			push @{ $ref_cand }, @{ $ref_array } - $i + $h{ $$ref_array[ $i ] };

			$h{ $$ref_array[ $i ] } = @{ $ref_array };
			}
		}
	}


Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases.  The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).

For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.


Given an integer $$$n$$$, find the maximum value of integer $$$k$$$ such that the following condition holds:  $$$n$$$ & ($$$n-1$$$) & ($$$n-2$$$) & ($$$n-3$$$) & ... ($$$k$$$) = $$$0$$$  where & denotes the bitwise AND operation.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3 \cdot 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^9$$$).

For each test case, output a single integer — the required integer $$$k$$$.

NoteIn the first testcase, the maximum value for which the continuous & operation gives 0 value, is 1.In the second testcase, the maximum value for which the continuous & operation gives 0 value, is 3. No value greater then 3, say for example 4, will give the & sum 0.   $$$5 \, \& \, 4 \neq 0$$$,  $$$5 \, \& \, 4 \, \& \, 3 = 0$$$. Hence, 3 is the answer.

use integer;
chomp($t = <STDIN>);
foreach (1..$t)
{
    chomp($n = <STDIN>);
    $res = 0;
    while ($n > 0)
    {
        $n /= 2;
        $res++;
    }
    print((1 << ($res - 1)) - 1, "\n");
}

use integer;
chomp($t = <STDIN>);
foreach (1..$t)
{
    chomp($n = <STDIN>);
    while ($n > 0)
    {
        $n /= 2;
        $res++;
    }
    print((1 << ($res - 1)) - 1, "\n");
}


One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.

The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.

Print a single integer — the number of problems the friends will implement on the contest.

NoteIn the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.

#!/usr/bin/perl -w

use strict;

my $res = 0;
chomp(my $n = <>);
for (1 .. $n) {
	my $cur = 0;
	chomp($_ = <>);
	map { $cur += $_ } split;
	++$res if $cur >= 2;
}
print "$res\n";

#!/usr/bin/env perl

use v5.012;
use warnings;

my $cnt = <STDIN>;
my $ret = 0;
while ($cnt--) {
	my $ones = (<STDIN> =~ tr/1/1/);
	$ret++ if $ones >= 2;
}
print $ret;

use strict;
use warnings;

my $n = <>;
my $ans = 0;
my $count;
while($n-- > 0){
    $count = 0;
    my @a = split(/ /,<>);
    $count++ if $a[0]==1;
    $count++ if $a[1]==1;
    $count++ if $a[2]==1;
    $ans++ if $count > 1;
}
print "$ans\n";

my $n = <STDIN>;
my $count = 0;
while($n--) {
    my($a, $b, $c) = split(' ', <STDIN>);
    if(($a + $b + $c) > 1) {
        $count++;
    }
}
print $count;

#!/usr/bin/perl
# your code goes here

chomp($n = <>);
$ans = 0;
while ($n-- > 0) {
	$c = 0;
	$c += $_ foreach (split / /,<>);
	$c>=2 and $ans++;
}
print $ans;

#use strict;
#use warnings;
#use diagnostics;

my $lines = <STDIN>;
my $solutions = 0;
for (my $i=0; $i<$lines; $i++) {
	my $sum = 0;
	$line = <STDIN>;
	@inputs = split (/ /,$line);
	foreach (@inputs) {
		$sum += $_;
	}

	if ($sum >= 2) {
		$solutions++;
	}
}

print $solutions;

my $n = <>;
my $solutions = 0;
while (<>) {
    my ($x,$y,$z) = $_ =~ /^(\d) (\d) (\d)$/;

    $solutions++ if $x+$y+$z > 1;
}
print $solutions;

use strict;
use warnings;

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

my $solutions = 0;
for (my $i=0; $i < $n; $i++) {
    my $in = <>;
    chomp($in);

    my @verdicts = split(' ', $in);
    my $p = scalar grep { $_ } @verdicts;
    $solutions += ($p >= 2) ? 1 : 0;
}

print $solutions;

use strict;
use warnings;

my $n = <>;
my $res = 0;
for (1..$n) {
	my @sols = split ' ', <>;
	my $b = 0;
	for (@sols) { $b += $_ };
	$res++ if $b > 1;
}
print $res."\n";

#!/usr/bin/perl
use strict;
my $n = <STDIN>;
my $sum = 0;
while (my $row = <STDIN>)
{
    my $sum_w = 0;
    chomp $row;
    my @inputs_p = split (' ', $row);
    foreach my $item (@inputs_p)
    {
        if ($item == 1) { $sum_w++; }
    }
    if ($sum_w >= 2) { $sum++;}
}
print $sum;

chomp(my $testCase=<STDIN>);
my $count = 0;
while($testCase){
	my $a=<STDIN>;
	my $sum;
	my @arr = split / /,$a;
	foreach (@arr){
		$sum += $_;
	}
	if($sum >= 2 ){
	 $count++;
	}
	$testCase--;
}
print "$count";

my $len=0; my $count = <STDIN>; for(1..$count){ @_ = split " ", <STDIN>; my $sym = 0; for(@_){ $sym += $_; } if($sym > 1){ $len += 1; } }; print "$len\n";

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

my $n = 0; <STDIN>;
while (<STDIN>)
{ my ($a, $b, $c) = split ' ', $_; ++$n if $a + $b + $c > 1 }
print $n . "\n"

use strict;
use warnings;
use diagnostics;

my $lines = <STDIN>;
my $solutions = 0;
for (my $i=0; $i<$lines; $i++) {
	my $sum = 0;
	$sum += <STDIN>;
	$sum += <STDIN>;
	$sum += <STDIN>;

	if ($sum >= 2) {
		$solutions++;
	}
}

print $solutions."\n";

#use strict;
#use warnings;
#use diagnostics;

my $lines = <STDIN>;
my $solutions = 0;
for (my $i=0; $i<$lines; $i++) {
	my $sum = 0;
	$sum += <STDIN>;
	$sum += <STDIN>;
	$sum += <STDIN>;

	if ($sum >= 2) {
		$solutions++;
	}
}

print $solutions;

#use strict;
#use warnings;
#use diagnostics;

my $lines = <STDIN>;
my $solutions = 0;
for (my $i=0; $i<$lines; $i++) {
	my $sum = 0;
	$sum += <STDIN>;
	$sum += <STDIN>;
	$sum += <STDIN>;

	if ($sum >= 2) {
		$solutions++;
	}
}

print "2";
#print $solutions."\n";

chomp(my $testCase=<STDIN>);
my $count;
while($testCase){
	my $a=<STDIN>;
	my $sum;
	my @arr = split / /,$a;
	foreach (@arr){
		$sum += $_;
	}
	if($sum >= 2 ){
	 $count++;
	}
	$testCase--;
}
print $count;


Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are indexed but the glasses are not.First Petya puts a marble under the glass in position s. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position p1, the glass from the second position to position p2 and so on. That is, a glass goes from position i to position pi. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in.After all shuffling operations Petya shows Vasya that the ball has moved to position t. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position s to position t.

The first line contains three integers: n, s, t (1 ≤ n ≤ 105; 1 ≤ s, t ≤ n) — the number of glasses, the ball's initial and final position. The second line contains n space-separated integers: p1, p2, ..., pn (1 ≤ pi ≤ n) — the shuffling operation parameters. It is guaranteed that all pi's are distinct. Note that s can equal t.

If the marble can move from position s to position t, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position t. If it is impossible, print number -1.


Vasya has found a piece of paper with an array written on it. The array consists of n integers a1, a2, ..., an. Vasya noticed that the following condition holds for the array ai ≤ ai + 1 ≤ 2·ai for any positive integer i (i < n).Vasya wants to add either a "+" or a "-" before each number of array. Thus, Vasya will get an expression consisting of n summands. The value of the resulting expression is the sum of all its elements. The task is to add signs "+" and "-" before each number so that the value of expression s meets the limits 0 ≤ s ≤ a1. Print a sequence of signs "+" and "-", satisfying the given limits. It is guaranteed that the solution for the problem exists.

The first line contains integer n (1 ≤ n ≤ 105) — the size of the array. The second line contains space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the original array.  It is guaranteed that the condition ai ≤ ai + 1 ≤ 2·ai fulfills for any positive integer i (i < n).

In a single line print the sequence of n characters "+" and "-", where the i-th character is the sign that is placed in front of number ai. The value of the resulting expression s must fit into the limits 0 ≤ s ≤ a1. If there are multiple solutions, you are allowed to print any of them.


Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and k.

The only line of the input contains a single integer n (2 ≤ n ≤ 100 000).

The first line of the output contains a single integer k — maximum possible number of primes in representation. The second line should contain k primes with their sum equal to n. You can print them in any order. If there are several optimal solution, print any of them.

#!/usr/bin/env perl

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

# send argument as array, not reference, to function requiring list

# essential
my @tokens = ();

sub ceil {
    my $n = shift;
    my $in = int($n);
    return $n if $in == $n;
    return $in + 1;
}

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

# solve

my $n = read_token;

my $count = 0;
my $answer = '';

if ($n % 2 == 1) {
    $n -= 3;
    while ($n > 0) {
        $count++;
        $n -= 2;
        $answer .= '2 ';
    }
    $count++;
    $answer .= '3';
}
else {
    while ($n > 0) {
        $count++;
        $n -= 2;
        $answer .= '2 ';
    }
}

say $count;
say $answer;


You are given a matrix with $$$n$$$ rows (numbered from $$$1$$$ to $$$n$$$) and $$$m$$$ columns (numbered from $$$1$$$ to $$$m$$$). A number $$$a_{i, j}$$$ is written in the cell belonging to the $$$i$$$-th row and the $$$j$$$-th column, each number is either $$$0$$$ or $$$1$$$.A chip is initially in the cell $$$(1, 1)$$$, and it will be moved to the cell $$$(n, m)$$$. During each move, it either moves to the next cell in the current row, or in the current column (if the current cell is $$$(x, y)$$$, then after the move it can be either $$$(x + 1, y)$$$ or $$$(x, y + 1)$$$). The chip cannot leave the matrix.Consider each path of the chip from $$$(1, 1)$$$ to $$$(n, m)$$$. A path is called palindromic if the number in the first cell is equal to the number in the last cell, the number in the second cell is equal to the number in the second-to-last cell, and so on.Your goal is to change the values in the minimum number of cells so that every path is palindromic.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 30$$$) — the dimensions of the matrix. Then $$$n$$$ lines follow, the $$$i$$$-th line contains $$$m$$$ integers $$$a_{i, 1}$$$, $$$a_{i, 2}$$$, ..., $$$a_{i, m}$$$ ($$$0 \le a_{i, j} \le 1$$$).

For each test case, print one integer — the minimum number of cells you have to change so that every path in the matrix is palindromic.

NoteThe resulting matrices in the first three test cases: $$$\begin{pmatrix} 1 & 1\\ 0 & 1 \end{pmatrix}$$$  $$$\begin{pmatrix} 0 & 0 & 0\\ 0 & 0 & 0 \end{pmatrix}$$$  $$$\begin{pmatrix} 1 & 0 & 1 & 1 & 1 & 1 & 1\\ 0 & 1 & 1 & 0 & 1 & 1 & 0\\ 1 & 1 & 1 & 1 & 1 & 0 & 1 \end{pmatrix}$$$


Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. The cost of the i-th stone is vi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:  She will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her .  Let ui be the cost of the i-th cheapest stone (the cost that will be on the i-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her . For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.

The first line contains an integer n (1 ≤ n ≤ 105). The second line contains n integers: v1, v2, ..., vn (1 ≤ vi ≤ 109) — costs of the stones.  The third line contains an integer m (1 ≤ m ≤ 105) — the number of Kuriyama Mirai's questions. Then follow m lines, each line contains three integers type, l and r (1 ≤ l ≤ r ≤ n; 1 ≤ type ≤ 2), describing a question. If type equal to 1, then you should output the answer for the first question, else you should output the answer for the second one.

Print m lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.

NotePlease note that the answers to the questions may overflow 32-bit integer type.

#!perl -w

use strict;

chomp ( my $n = <STDIN> ) ;
my @stones = split /\s+/s , <STDIN>;
chomp ( my $questions = <STDIN> ) ;
my @sort_stones = sort{$a <=> $b} @stones;

my $temp = 0 ;
my @accstones = map{$temp += $_ } @stones ;
unshift @accstones , 0 ;
$temp = 0 ;
my @accsortstones = map{$temp += $_ } @sort_stones ;
unshift @accsortstones , 0 ;

while( $questions-- ){
    my ($type,$low,$high) = split /\s+/s , <STDIN> ;
    my $summ=0 ;
    if($type==1){
        $summ = $accstones[$high]-$accstones[$low-1];
    }else{
        $summ = $accsortstones[$high]-$accsortstones[$low-1];
    }

    print "$summ\n";
}


Let's call a positive integer composite if it has at least one divisor other than $$$1$$$ and itself. For example:  the following numbers are composite: $$$1024$$$, $$$4$$$, $$$6$$$, $$$9$$$;  the following numbers are not composite: $$$13$$$, $$$1$$$, $$$2$$$, $$$3$$$, $$$37$$$. You are given a positive integer $$$n$$$. Find two composite integers $$$a,b$$$ such that $$$a-b=n$$$.It can be proven that solution always exists.

The input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^7$$$): the given integer.

Print two composite integers $$$a,b$$$ ($$$2 \leq a, b \leq 10^9, a-b=n$$$). It can be proven, that solution always exists. If there are several possible solutions, you can print any.

use strict;
use warnings FATAL => 'all';

my $n = <STDIN>;
chomp $n;
$n = int($n);

my $a = 9 * $n;
my $b = 8 * $n;

print $a, ' ', $b

#!/usr/bin/env perl
package Codeforces::Task::A;
use v5.10;
use strict;
use warnings;

sub min {
    my ($a, $b) = @_;
    if ($a < $b) {
		return $a;
	} else {
        return $b;
    }
}
sub max {
    my ($a, $b) = @_;
    if ($a > $b) {
        return $a;
    } else {
        return $b;
    }
}

sub solve {
    my $n = int(<>);
    if ($n % 2 == 0) {
        print $n + 4, " 4";
    } else {
        print $n + 9, " 9";
    }
    print "\n";
}

sub main {
    my $t = 1;
#    $t = int(<>);
    while ($t--) {
        solve();
    }
    return 0;
}

exit(main(@ARGV));

#Perl v5.18.2
$n = <STDIN>;

print 9*$n;
print " ";
print 8*$n;

use strict;
use warnings FATAL => 'all';

my $n = <STDIN>;
chomp $n;
$n = int($n);

my $a = 3 * $n;
my $b = 2 * $n;

print $a, ' ', $b


Let's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array $$$a=[1, 3, 3, 7]$$$ is good because there is the element $$$a_4=7$$$ which equals to the sum $$$1 + 3 + 3$$$.You are given an array $$$a$$$ consisting of $$$n$$$ integers. Your task is to print all indices $$$j$$$ of this array such that after removing the $$$j$$$-th element from the array it will be good (let's call such indices nice).For example, if $$$a=[8, 3, 5, 2]$$$, the nice indices are $$$1$$$ and $$$4$$$:   if you remove $$$a_1$$$, the array will look like $$$[3, 5, 2]$$$ and it is good;  if you remove $$$a_4$$$, the array will look like $$$[8, 3, 5]$$$ and it is good. You have to consider all removals independently, i. e. remove the element, check if the resulting array is good, and return the element into the array.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — elements of the array $$$a$$$.

In the first line print one integer $$$k$$$ — the number of indices $$$j$$$ of the array $$$a$$$ such that after removing the $$$j$$$-th element from the array it will be good (i.e. print the number of the nice indices). In the second line print $$$k$$$ distinct integers $$$j_1, j_2, \dots, j_k$$$ in any order — nice indices of the array $$$a$$$. If there are no such indices in the array $$$a$$$, just print $$$0$$$ in the first line and leave the second line empty or do not print it at all.

NoteIn the first example you can remove any element with the value $$$2$$$ so the array will look like $$$[5, 1, 2, 2]$$$. The sum of this array is $$$10$$$ and there is an element equals to the sum of remaining elements ($$$5 = 1 + 2 + 2$$$).In the second example you can remove $$$8$$$ so the array will look like $$$[3, 5, 2]$$$. The sum of this array is $$$10$$$ and there is an element equals to the sum of remaining elements ($$$5 = 3 + 2$$$). You can also remove $$$2$$$ so the array will look like $$$[8, 3, 5]$$$. The sum of this array is $$$16$$$ and there is an element equals to the sum of remaining elements ($$$8 = 3 + 5$$$).In the third example you cannot make the given array good by removing exactly one element.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $sum = 0;

	$sum += $_ for @_;

	my( $max1, $max2 ) = sort { $b <=> $a } @_;

	my @ans;

	my $i = 0;

	for( @_ ){
		$i ++;
		if( $_ == $max1 ){
			if( $sum - $_ == 2 * $max2 ){
				push @ans, $i;
				}
			}
		else{
			if( $sum - $_ == 2 * $max1 ){
				push @ans, $i;
				}
			}
		}

	print for ~~ @ans, "@ans";
	}


There is a toy building consisting of $$$n$$$ towers. Each tower consists of several cubes standing on each other. The $$$i$$$-th tower consists of $$$h_i$$$ cubes, so it has height $$$h_i$$$.Let's define operation slice on some height $$$H$$$ as following: for each tower $$$i$$$, if its height is greater than $$$H$$$, then remove some top cubes to make tower's height equal to $$$H$$$. Cost of one "slice" equals to the total number of removed cubes from all towers.Let's name slice as good one if its cost is lower or equal to $$$k$$$ ($$$k \ge n$$$).  Calculate the minimum number of good slices you have to do to make all towers have the same height. Of course, it is always possible to make it so.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$n \le k \le 10^9$$$) — the number of towers and the restriction on slices, respectively. The second line contains $$$n$$$ space separated integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 2 \cdot 10^5$$$) — the initial heights of towers.

Print one integer — the minimum number of good slices you have to do to make all towers have the same heigth.

NoteIn the first example it's optimal to make $$$2$$$ slices. The first slice is on height $$$2$$$ (its cost is $$$3$$$), and the second one is on height $$$1$$$ (its cost is $$$4$$$).

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

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

	@_ = sort { $b <=> $a } split ' ', <>;

	my $min = $_[ @_ - 1 ];

	$_ -= $min - 1 for @_;

	$debug and print '-' x 20;
	$debug and print "[@_]";

	my $wide = 1;
	my $cnt = 0;

	if( $_[ 0 ] == $_[ @_ - 1 ] ){
		print 0;
		next;
		}

	OUTER:
	while( @_ > 1 ){
		$cnt ++;
		$debug and print " cnt: $cnt";
		my $to_cut = $k;
		while( $to_cut > 0 ){
			$debug and print "  to_cut: $to_cut";
			if( @_ < 2 ){
				last OUTER;
				}
			my $diff = $_[ 0 ] - $_[ 1 ];
			if( $diff * $wide <= $to_cut ){
				$to_cut -= $diff * $wide;
				$wide ++;
				shift @_;
				}
			else{
				while( $diff * $wide > $to_cut ){
					$diff >>= 1;
					}
				if( $diff == 0 ){
					next OUTER;
					}
				$to_cut -= $diff * $wide;
				$_[ 0 ] -= $diff;
				}
			}
		}

	print $cnt - 0;
	}


A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and engineering. Vasya liked the idea of the method very much, and he decided to try it in practice.Applying the simplest variant of median smoothing to the sequence of numbers a1, a2, ..., an will result a new sequence b1, b2, ..., bn obtained by the following algorithm:  b1 = a1, bn = an, that is, the first and the last number of the new sequence match the corresponding numbers of the original sequence.  For i = 2, ..., n - 1 value bi is equal to the median of three values ai - 1, ai and ai + 1. The median of a set of three numbers is the number that goes on the second place, when these three numbers are written in the non-decreasing order. For example, the median of the set 5, 1, 2 is number 2, and the median of set 1, 0, 1 is equal to 1.In order to make the task easier, Vasya decided to apply the method to sequences consisting of zeros and ones only.Having made the procedure once, Vasya looked at the resulting sequence and thought: what if I apply the algorithm to it once again, and then apply it to the next result, and so on? Vasya tried a couple of examples and found out that after some number of median smoothing algorithm applications the sequence can stop changing. We say that the sequence is stable, if it does not change when the median smoothing is applied to it.Now Vasya wonders, whether the sequence always eventually becomes stable. He asks you to write a program that, given a sequence of zeros and ones, will determine whether it ever becomes stable. Moreover, if it ever becomes stable, then you should determine what will it look like and how many times one needs to apply the median smoothing algorithm to initial sequence in order to obtain a stable one.

The first input line of the input contains a single integer n (3 ≤ n ≤ 500 000) — the length of the initial sequence. The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 1), giving the initial sequence itself.

If the sequence will never become stable, print a single number  - 1. Otherwise, first print a single integer — the minimum number of times one needs to apply the median smoothing algorithm to the initial sequence before it becomes is stable. In the second line print n numbers separated by a space  — the resulting sequence itself.

NoteIn the second sample the stabilization occurs in two steps: , and the sequence 00000 is obviously stable.


Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).Implement this feature to help Polycarp test his editor.

The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.

Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.

#!/usr/bin/env perl

my @result = ();
my $line = readline(*STDIN);
my ($w, $h) = split(' ', $line);

for (my $n=0; $n<$h; $n++) {
    $line = readline(*STDIN);
    chomp($line);
    my $currentw = $n*2;
    my $currenth = 0;
    while ( $line =~ m/(.)/g) {
     	my $nexth = $currenth + 1;
     	my $nextw = $currentw + 1;
        $result[$currenth][$currentw] = $result[$nexth][$currentw] = $result[$currenth][$nextw]= $result[$nexth][$nextw] = $1;
        $currenth += 2;
    }
}

for (my $W = 0; $W<$w*2; $W++)
{
	for (my $H = 0; $H<$h*2; $H++)
	{
		print $result[$W][$H];
	}
	print "\n";
}

#!/usr/bin/env perl

use 5.011;
use strict;
use warnings;

my ($w, $h) = split /\s/, <>;
my @a;
push @a, [split ""] while <>;

my @b;
for (my $i = 0; $i < $w; $i++) {
    my @x;
    for (my $j = 0; $j < $h; $j++) {
        push @x, $a[$h - $j - 1][$i];
    }
    push @b, \@x;
}

my @c;
for (my $i = 0; $i < $w; $i++) {
    my @x;
    for (my $j = $h - 1; $j >= 0; $j--) {
        push @x, $b[$i][$j];
        push @x, $b[$i][$j];
    }
    push @c, \@x;
    push @c, \@x;
}

say @$_ for @c;


There is a string $$$s$$$ of length $$$3$$$, consisting of uppercase and lowercase English letters. Check if it is equal to "YES" (without quotes), where each letter can be in any case. For example, "yES", "Yes", "yes" are all allowable.

The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of testcases. The description of each test consists of one line containing one string $$$s$$$ consisting of three characters. Each character of $$$s$$$ is either an uppercase or lowercase English letter.

For each test case, output "YES" (without quotes) if $$$s$$$ satisfies the condition, and "NO" (without quotes) otherwise. You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).

10

YES

yES

yes

Yes

YeS

Noo

orZ

yEz

Yas

XES

NoteThe first five test cases contain the strings "YES", "yES", "yes", "Yes", "YeS". All of these are equal to "YES", where each character is either uppercase or lowercase.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	print m/^yes$/i ? "YES" : "NO";
	}


Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a number k and an array a containing n numbers. Find out how many k-good numbers are in a (count each number every time it occurs in array a).

The first line contains integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 9). The i-th of the following n lines contains integer ai without leading zeroes (1 ≤ ai ≤ 109).

Print a single integer — the number of k-good numbers in a.

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

    <>=~/ /;
#   <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

chomp($a=$');
$t=0;
while (<>){
	chomp;
	for $i(0..$a){
		/$i/ or $k++;

		}

	$k or $t++;
	$k=0;

	}
print $t;

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

my ($n, $k) = split ' ', <>;
$count = 0;
Label:
for (1..$n) {
    my $num = <>;
    for (0..$k) {
        next Label if $num !~ /$_/;
    }
    $count++;
}
print $count;

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

    <>=~/ /;
#   <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

chomp($a=$'+1);
$t=0;
while (<>){
	chomp;
	@a=split//;
	@a=sort @a;
#	print " @a\n";
	for $i(@a){
		($i==$j++) or ($k++)
		}
	$j=0;
	@a==$a or $k++;

	$k or $t++;
	$k=0;

	}
print $t;

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

    <>=~/ /;
#   <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

chomp($a=$'+1);
$t=0;
while (<>){
	chomp;
	@a=split//;
	@a=sort @a;
#	print " @a\n";
	for $i(@a){
		($i==$j++) or ($k++)
		}
	$j=0;
	@a<1 and push @a,1;
	@a==$a or $k++;

	$k or $t++;
	$k=0;

	}
print $t;

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}


You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z'  'y'  'x'  'b'  'a'  'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?

The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.

Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.

NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.

# cf708a # solution courtesy 20147365 s_p
use strict;
$_=<>;
s% [b-z]+ % $& =~ tr/b-z/a-y/r %xe || s/a$/z/;
print $_;

# cf708a
use strict;
my $c=getc();
my $s=0;
while(defined($c)) {
  if($s==0) {
    if($c ne 'a') { $s=1; }
  }
  if($s==1) {
    if($c ne 'a') { $c=chr(ord($c)-1); }
    else { $s=2; }
  }
  my $nextC=getc();
  if($nextC eq "\n") { $nextC=undef }
  print defined($nextC) || $s!=0 ? $c : 'z';
  $c=$nextC;
}

# cf708a
use strict;
my $c;
my $s=0;
while(defined($c=getc())) {
  if($s==0) {
    if($c ne 'a') { $s=1; }
  }
  if($s==1) {
    if($c ne 'a') { $c=chr(ord($c)-1); }
    else { $s=2; }
  }
  print $c;
}

# cf708a
use strict;
my $c=getc();
my $s=0;
while(defined($c)) {
  if($s==0) {
    if($c ne 'a') { $s=1; }
  }
  if($s==1) {
    if($c ne 'a') { $c=chr(ord($c)-1); }
    else { $s=2; }
  }
  my $nextC=getc();
  print defined($nextC) || $s!=0 ? $c : 'z';
  $c=$nextC;
}


You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence — so plain and boring, that you'd like to repaint it.  You have a fence consisting of $$$n$$$ planks, where the $$$i$$$-th plank has the color $$$a_i$$$. You want to repaint the fence in such a way that the $$$i$$$-th plank has the color $$$b_i$$$.You've invited $$$m$$$ painters for this purpose. The $$$j$$$-th painter will arrive at the moment $$$j$$$ and will recolor exactly one plank to color $$$c_j$$$. For each painter you can choose which plank to recolor, but you can't turn them down, i. e. each painter has to color exactly one plank.Can you get the coloring $$$b$$$ you want? If it's possible, print for each painter which plank he must paint.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of planks in the fence and the number of painters. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the initial colors of the fence. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le n$$$) — the desired colors of the fence. The fourth line of each test case contains $$$m$$$ integers $$$c_1, c_2, \dots, c_m$$$ ($$$1 \le c_j \le n$$$) — the colors painters have. It's guaranteed that the sum of $$$n$$$ doesn't exceed $$$10^5$$$ and the sum of $$$m$$$ doesn't exceed $$$10^5$$$ over all test cases.

For each test case, output "NO" if it is impossible to achieve the coloring $$$b$$$. Otherwise, print "YES" and $$$m$$$ integers $$$x_1, x_2, \dots, x_m$$$, where $$$x_j$$$ is the index of plank the $$$j$$$-th painter should paint. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" are all recognized as positive answer).

YES
1
YES
2 2
YES
1 1 1
YES
2 1 9 5 9
NO
NO

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

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

	my( $n, $m ) = split;
	my @A = split ' ', <>;
	my @B = split ' ', <>;
	my @C = split ' ', <>;

	$debug and print "\@A:[@A]";
	$debug and print "\@B:[@B]";
	$debug and print "\@C:[@C]";

	my %h;
	my %g;

	undef $h{ $_ } for @B;

	for my $i ( 0 .. @A - 1 ){
		$A[ $i ] != $B[ $i ] and $h{ $B[ $i ] }{ $i + 1 } = 1;
		$g{ $B[ $i ] } = $i + 1;
		}

	$debug and print map "keys %h:[$_]", join " ", sort keys %h;

	my @D;

	for( @C ){
		if( exists $h{ $_ } ){
			if( 0 < keys %{ $h{ $_ } } ){
				my( $key ) = keys %{ $h{ $_ } };
				delete $h{ $_ }{ $key };
				push @D, $key;
				}
			else{
				push @D, $g{ $_ };
				}
			}
		else{
			push @D, -1;
			}
		}

	$debug and print "\@D:[@D]";

	if( $D[ @D - 1 ] == -1 ){
		print 'NO';
		}
	elsif( 0 < map { keys %{ $h{ $_ } } } keys %h ){
		print 'NO';
		}
	else{
		map { $_ == -1 and $_ = $D[ @D - 1 ] } @D;
		print 'YES';
		print "@D";
		}
	}

#!/usr/bin/perl
use Data::Dumper;

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

while( $test_case -- > 0 ){
  my ($n,$m) = map { $_ - 0 } split(/\s+/,<STDIN>);
  my @aa = map { $_ - 0 } split(/\s+/,<STDIN>);
  my @bb = map { $_ - 0 } split(/\s+/,<STDIN>);
  my @cc = map { $_ - 0 } split(/\s+/,<STDIN>);

  my @need_col = (); $#need_col = $n + 10;
  my @need_col_i = (); $#need_col_i = $n + 10;

  my $total_need = 0;

  my @btype = (); $#btype = $n + 10;

  for(my $i=0;$i<$n;$i++){
    if( $aa[$i] != $bb[$i] ){
      $need_col[$bb[$i]]++;
      push(@{$need_col_i[$bb[$i]]},$i);
      $total_need ++;
    }
    push(@{$btype[$bb[$i]]},$i);
  }

  my @tr = (); $#tr = $m - 1;
  my $init = 1;
  my $prev = -1;
  my $init_pass = 0;
  for(my $i=$m-1;$i>=0;$i--){
    my $c1 = $cc[$i];
    if( $need_col[$c1] - 0 > 0 ){
      $need_col[$c1] --;
      $tr[$i] = $need_col_i[$c1]->[$need_col[$c1]];
      $prev = $tr[$i];
      $total_need --;
      $init = 0;
    } else {
      if( $init==1 and !ref($btype[$c1]) and $prev < 0 ){
        $init = -1; last;
      }
      if( $prev >= 0 ){
        $tr[$i] = $prev;
      } else {
        $tr[$i] = $btype[$c1]->[0];
        $prev = $tr[$i];
      }
    }
  }
  if( $init < 0 or $total_need > 0 ){
    print "NO\n"; next;
  }
  print "YES\n";
  for(my $i=0;$i<$m;$i++){
    my $v = $tr[$i]+1;
    print " " if $i > 0;
    print "$v";
  }
  print "\n";

}

exit(0);

#!/usr/bin/perl
my ($n,$m) = map {$_ - 0} split(/\s+/o,<STDIN>);

my @tr = ();
$#tr = $n-1;
my @par = ();
$#par = $n-1;

for(my $i=0;$i<$n;$i++){
  $par[$i] = $i;
}

for(my $i=0;$i<$m;$i++){
  my ($x,$y,$z) = map {$_ - 0} split(/\s+/o,<STDIN>);
  unite($x-1,$y-1);
}

my %dum = ();
for(my $i=0;$i<$n;$i++){
  $dum{&root($i)} = 1;
}
my @d2 = keys %dum;
my $res = 1 + $#d2;
print "$res\n";

exit(0);

###

#!/usr/bin/perl
use Data::Dumper;
my ($n) = map {$_ - 0} split(/\s+/o,<STDIN>);

my $f = &factr($n);

my @facts = keys %$f;

my %f0 = ();

my %oki = ();

while(1){
  my $gosei = 1;
  foreach my $f1 (@facts){
    $gosei *= ( $f1 ** ( $f0{$f1} - 0 ) );
  }
  if( $gosei >= 3 ){
#    print "gosei = $gosei\n";
    my $syo = $n / $gosei;
    if( $syo <= $gosei - 2 ){
      my $g1 = $gosei - 1;
      $oki{$g1} = 1;
    }
  }
  my $cu = 0;
  my $carry = 1;
  while($carry > 0){
    $f0{$facts[$cu]} += 1;
    $carry = 0;
    if( $f0{$facts[$cu]} > $f->{$facts[$cu]} ){
      $f0{$facts[$cu]} = 0;
      $carry = 1;
      $cu++;
    }
    last if( $cu > $#facts );
  }
  last if $cu > $#facts;
}
my $res = 0;
foreach my $o1 (keys %oki){
  $res += ( $o1 - 0);
}
#print &Dumper(\%oki);
print "$res\n";
exit(0);

sub factr {
  my $v = shift;
  my %f = ();
  if( $v<4 ){
    $f{$v}++;
    return \%f;
  }
  for(my $i=1;$i*$i<=$v;$i+=2){
    my $ii = ($i == 1 ? 2 : $i);
    while($v % $ii == 0){
      $f{$ii}++;
      $v /= $ii;
    }
  }
  $f{$v}++ if $v>1;
  return \%f;
}

####  mod_int + nCr nPr set

#!/usr/bin/perl

my $mod = 10 ** 9 + 7;
# my $mod = 998244353;

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

&mk_fact($n+10);

### write here

exit(0);

sub mod_pow {     # ( x ** n ) % mod
  my ($x,$n) = @_;
  my $r = 1;
  while( $n ){
    $r = ( $r * $x ) % $mod if 1 & $n;
    $n >>= 1;
    $x = ( $x * $x ) % $mod;
  }
  return $r;
}

sub mk_fact {     # make {global} n-size variable  fact[]  factinv[]
  my $n_max = shift;
  our @fact    = (1); $#fact = $n_max;
  our @factinv = (1); $#factinv = $n_max;
  for(my $i=1;$i<=$n_max;$i++){
    $fact[$i] = ( $fact[$i-1] * $i ) % $mod;
    $factinv[$i] = &mod_pow($fact[$i],$mod-2);
  }
}

sub nCr {         # calc nCr % mod
  my $n = shift; my $r = shift;
  return (( $fact[$n] * ( ( $factinv[$r] * $factinv[$n-$r] ) % $mod ) ) % $mod);
}

sub nPr {         # calc nPr % mod
  my $n = shift; my $r = shift;
  return (( $fact[$n] * $factinv[$n-$r] ) % $mod );
}

#### union find set

#!/usr/bin/perl

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

#### write here

exit(0);

sub mk_uf {
  my $n = shift;
  our @uf = (); $#uf = $n - 1;
  for(my $i=0;$i<$n;$i++){
    $uf[$i] = $i;
  }
}

sub root {
  my $x = shift;
  while( $uf[$x] != $x ){  $x = $uf[$x] = $uf[$uf[$x]];  }
  return $x;
}

sub unite {
  my $x = &root(scalar(shift)); my $y = &root(scalar(shift));
  $uf[$y] = $x;
}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

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

	my( $n, $m ) = split;
	my @A = split ' ', <>;
	my @B = split ' ', <>;
	my @C = split ' ', <>;

	$debug and print "\@A:[@A]";
	$debug and print "\@B:[@B]";
	$debug and print "\@C:[@C]";

	my %h;
	my %g;

	undef $h{ $_ } for @B;

	for my $i ( 0 .. @A - 1 ){
		$A[ $i ] != $B[ $i ] and $h{ $B[ $i ] }{ $i + 1 } = 1;
		$g{ $B[ $i ] } = $i + 1;
		}

	$debug and print map "keys %h:[$_]", join " ", sort keys %h;

	my @D;

	for( @C ){
		if( exists $h{ $_ } ){
			if( 0 < keys %{ $h{ $_ } } ){
				my( $key ) = keys %{ $h{ $_ } };
				delete $h{ $_ }{ $key };
				push @D, $key;

				}
			else{
				push @D, $g{ $_ };
				}
			}
		else{
			push @D, -1;
			}
		}

	$debug and print "\@D:[@D]";

	if( $D[ @D - 1 ] == -1 ){
		print 'NO';
		}
	else{
		map { $_ == -1 and $_ = $D[ @D - 1 ] } @D;
		print 'YES';
		print "@D";
		}
	}


You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that:   $$$1 \le i < j < k \le n$$$;  $$$p_i < p_j$$$ and $$$p_j > p_k$$$.  Or say that there are no such indices.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$.

For each test case:    if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves;  if there are no such indices, print NO (case insensitive).  If there are multiple valid triples of indices, print any of them.


Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder.Let's denote a flip operation of an integer as follows: number is considered in decimal notation and then reverted. If there are any leading zeroes afterwards, they are thrown away. For example, if we flip 123 the result is the integer 321, but flipping 130 we obtain 31, and by flipping 31 we come to 13.Oksana Fillipovna picked some number a without leading zeroes, and flipped it to get number ar. Then she summed a and ar, and told Vitya the resulting value n. His goal is to find any valid a.As Oksana Fillipovna picked some small integers as a and ar, Vitya managed to find the answer pretty fast and became interested in finding some general algorithm to deal with this problem. Now, he wants you to write the program that for given n finds any a without leading zeroes, such that a + ar = n or determine that such a doesn't exist.

The first line of the input contains a single integer n (1 ≤ n ≤ 10100 000).

If there is no such positive integer a without leading zeroes that a + ar = n then print 0. Otherwise, print any valid a. If there are many possible answers, you are allowed to pick any.

NoteIn the first sample 4 = 2 + 2, a = 2 is the only possibility.In the second sample 11 = 10 + 1, a = 10 — the only valid solution. Note, that a = 01 is incorrect, because a can't have leading zeroes.It's easy to check that there is no suitable a in the third sample.In the fourth sample 33 = 30 + 3 = 12 + 21, so there are three possibilities for a: a = 30, a = 12, a = 21. Any of these is considered to be correct answer.


Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number ai written on it.They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all cards having a number strictly lesser than the number on the chosen card. Formally, if the player chooses the i-th card, he removes that card and removes the j-th card for all j such that aj < ai.A player loses if he cannot make a move on his turn, that is, he loses if there are no cards left. Predict the outcome of the game, assuming both players play optimally.

The first line contains an integer n (1 ≤ n ≤ 105) — the number of cards Conan has.  The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105), where ai is the number on the i-th card.

If Conan wins, print "Conan" (without quotes), otherwise print "Agasa" (without quotes).

NoteIn the first example, Conan can just choose the card having number 7 on it and hence remove all the cards. After that, there are no cards left on Agasa's turn.In the second example, no matter which card Conan chooses, there will be one one card left, which Agasa can choose. After that, there are no cards left when it becomes Conan's turn again.

my %hash = ();
my $n = <STDIN>;
chomp ( $n );
my $f = <STDIN>;
chomp ( $f );
my @arr = split m/ /, $f;
for my $i (@arr) {
    if ( not exists $hash { $i } ) {
	$hash { $i } = 0;
    }
    $hash { $i } += 1;
}

my $winner = 1;
for my $i ( keys %hash ) {
    if ( $hash { $i } % 2 == 1 ) {
	$winner = 0;
    }
}
if ( $winner == 0 ) {
    print "Conan\n";
}
else {
    print "Agasa\n";
}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	my %h;

	map $h{ $_ } ++, split ' ', <>;

	print qw( Conan Agasa )[ ! grep $_ % 2, values %h ];
	}

<>;

$h{ $_ } ++ for split ' ', <>;

print qw( Conan Agasa )[ ! grep $_ % 2, values %h ]


There is one apple tree in Arkady's garden. It can be represented as a set of junctions connected with branches so that there is only one way to reach any junctions from any other one using branches. The junctions are enumerated from $$$1$$$ to $$$n$$$, the junction $$$1$$$ is called the root.A subtree of a junction $$$v$$$ is a set of junctions $$$u$$$ such that the path from $$$u$$$ to the root must pass through $$$v$$$. Note that $$$v$$$ itself is included in a subtree of $$$v$$$.A leaf is such a junction that its subtree contains exactly one junction.The New Year is coming, so Arkady wants to decorate the tree. He will put a light bulb of some color on each leaf junction and then count the number happy junctions. A happy junction is such a junction $$$t$$$ that all light bulbs in the subtree of $$$t$$$ have different colors.Arkady is interested in the following question: for each $$$k$$$ from $$$1$$$ to $$$n$$$, what is the minimum number of different colors needed to make the number of happy junctions be greater than or equal to $$$k$$$?

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of junctions in the tree. The second line contains $$$n - 1$$$ integers $$$p_2$$$, $$$p_3$$$, ..., $$$p_n$$$ ($$$1 \le p_i < i$$$), where $$$p_i$$$ means there is a branch between junctions $$$i$$$ and $$$p_i$$$. It is guaranteed that this set of branches forms a tree.

Output $$$n$$$ integers. The $$$i$$$-th of them should be the minimum number of colors needed to make the number of happy junctions be at least $$$i$$$.

NoteIn the first example for $$$k = 1$$$ and $$$k = 2$$$ we can use only one color: the junctions $$$2$$$ and $$$3$$$ will be happy. For $$$k = 3$$$ you have to put the bulbs of different colors to make all the junctions happy.In the second example for $$$k = 4$$$ you can, for example, put the bulbs of color $$$1$$$ in junctions $$$2$$$ and $$$4$$$, and a bulb of color $$$2$$$ into junction $$$5$$$. The happy junctions are the ones with indices $$$2$$$, $$$3$$$, $$$4$$$ and $$$5$$$ then.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

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

	chomp;
	my $n = $_;

	my $i = 2;

	my %h;

	map {
		$h{ $i }{ $_ } = 1;
		$h{ $_ }{ $i } = 1;
		$i ++;
		} split ' ', <>;

	my @try = ( 1 );
	my @seq = @try;

	while( @try ){
		my $try = shift @try;
		my @arr =
		map {
			$h{ $_ }{ $try } = 0;
			$_
			} grep $h{ $try }{ $_ }, keys %{ $h{ $try } };
		unshift @seq, @arr;
		push @try, @arr;
		}

	my %nums;

	while( @seq ){
		my $leaflikes = shift @seq;

		my @keys = grep { defined $nums{ $_ } } keys %{ $h{ $leaflikes } };
		my $sum = 0;
		if( @keys ){
			$sum += $_ for map { $nums{ $_ } } @keys;
			}
		$nums{ $leaflikes } = $sum || 1;
		}

	print join ' ', sort { $a <=> $b } grep $_, values %nums;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

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

	chomp;
	my $n = $_;

	my $i = 2;

	my %h;

	map {
		$h{ $i }{ $_ } = 1;
		$h{ $_ }{ $i } = 1;
		$i ++;
		} split ' ', <>;

	my @try = ( 1 );
	my @seq = ( [ @try ] );

	while( @try ){
		my @allkeys;
		for my $try ( @try ){
			push @allkeys,
			map {
				$h{ $_ }{ $try } = 0;
			#	$h{ $try }{ $_ } = 0;
				$_
				} grep $h{ $try }{ $_ }, keys %{ $h{ $try } };
			}
		push @seq, [ @allkeys ];
		@try = @allkeys;
		}

	pop @seq;
	@seq = reverse @seq;

	$debug and print " seq : => @{ $_ }" for @seq;

	my %nums;

	map { $nums{ $_ } = 1 } @{ shift @seq };

	while( @seq ){

		my @leaflikes = @{ shift @seq };

		for my $leaflikes ( @leaflikes ){
			my @keys = keys %{ $h{ $leaflikes } };
			@keys = grep { defined $nums{ $_ } } @keys;
			my $sum = 0;
			if( @keys ){
				$sum += eval join ' + ', map { $nums{ $_ } } @keys;
				}
			$sum ||= 1;
			$nums{ $leaflikes } = $sum;
			}

		}

	print join ' ', sort { $a <=> $b } grep $_, values %nums;
	}