Ivan plays an old action game called Heretic. He's stuck on one of the final levels of this game, so he needs some help with killing the monsters.The main part of the level is a large corridor (so large and narrow that it can be represented as an infinite coordinate line). The corridor is divided into two parts; let's assume that the point $$$x = 0$$$ is where these parts meet.The right part of the corridor is filled with $$$n$$$ monsters — for each monster, its initial coordinate $$$x_i$$$ is given (and since all monsters are in the right part, every $$$x_i$$$ is positive).The left part of the corridor is filled with crusher traps. If some monster enters the left part of the corridor or the origin (so, its current coordinate becomes less than or equal to $$$0$$$), it gets instantly killed by a trap.The main weapon Ivan uses to kill the monsters is the Phoenix Rod. It can launch a missile that explodes upon impact, obliterating every monster caught in the explosion and throwing all other monsters away from the epicenter. Formally, suppose that Ivan launches a missile so that it explodes in the point $$$c$$$. Then every monster is either killed by explosion or pushed away. Let some monster's current coordinate be $$$y$$$, then:  if $$$c = y$$$, then the monster is killed;  if $$$y < c$$$, then the monster is pushed $$$r$$$ units to the left, so its current coordinate becomes $$$y - r$$$;  if $$$y > c$$$, then the monster is pushed $$$r$$$ units to the right, so its current coordinate becomes $$$y + r$$$. Ivan is going to kill the monsters as follows: choose some integer point $$$d$$$ and launch a missile into that point, then wait until it explodes and all the monsters which are pushed to the left part of the corridor are killed by crusher traps, then, if at least one monster is still alive, choose another integer point (probably the one that was already used) and launch a missile there, and so on.What is the minimum number of missiles Ivan has to launch in order to kill all of the monsters? You may assume that every time Ivan fires the Phoenix Rod, he chooses the impact point optimally.You have to answer $$$q$$$ independent queries.

The first line contains one integer $$$q$$$ ($$$1 \le q \le 10^5$$$) — the number of queries. The first line of each query contains two integers $$$n$$$ and $$$r$$$ ($$$1 \le n, r \le 10^5$$$) — the number of enemies and the distance that the enemies are thrown away from the epicenter of the explosion. The second line of each query contains $$$n$$$ integers $$$x_i$$$ ($$$1 \le x_i \le 10^5$$$) — the initial positions of the monsters. It is guaranteed that sum of all $$$n$$$ over all queries does not exceed $$$10^5$$$.

For each query print one integer — the minimum number of shots from the Phoenix Rod required to kill all monsters.

NoteIn the first test case, Ivan acts as follows:   choose the point $$$3$$$, the first monster dies from a crusher trap at the point $$$-1$$$, the second monster dies from the explosion, the third monster is pushed to the point $$$7$$$;  choose the point $$$7$$$, the third monster dies from the explosion. In the second test case, Ivan acts as follows:   choose the point $$$5$$$, the first and fourth monsters die from the explosion, the second monster is pushed to the point $$$1$$$, the third monster is pushed to the point $$$2$$$;  choose the point $$$2$$$, the first monster dies from a crusher trap at the point $$$0$$$, the second monster dies from the explosion.

#!/usr/bin/env perl

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

chomp (my $line = <STDIN>);

my $q = $line;

for (1..$q) {
    chomp ($line = <STDIN>);
    my ($n, $r) = split q{ }, $line;
    chomp ($line = <STDIN>);
    my @monsters = split q{ }, $line;

    my $set = {};
    for (@monsters) {
        $set->{$_} = 1 if !defined $set->{$_};
    }

    @monsters = sort { $a <=> $b } keys %$set;

    my $answer = 0;
    my $i = @monsters-1;
    while ( $i >= 0 ) {
        if ( $monsters[$i] > $answer * $r ) {
            $answer++;
        }
        $i--;
    }

    say $answer;
}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	my( $n, $r ) = split;
	@_ = sort { $a <=> $b } split ' ', <>;

	my $cnt = 0;

	while( @_ ){
		my $last = pop @_;
		if( @_ and $_[ @_ - 1 ] == $last ){
			next;
			}
		if( $last - $cnt * $r > 0 ){
			$cnt ++;
			}
		else{
			last;
			}
		}

	print $cnt;
	}

#!/usr/bin/env perl

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

chomp (my $line = <STDIN>);

my $q = $line;

for (1..$q) {
    chomp ($line = <STDIN>);
    my ($n, $r) = split q{ }, $line;
    chomp ($line = <STDIN>);
    my @monsters = split q{ }, $line;

    my $set = {};
    for (@monsters) {
        $set->{$_} = 1 if !defined $set->{$_};
    }

    @monsters = sort keys %$set;

    my $answer = 0;
    while ( @monsters ) {
        my $last = $monsters[-1];
        while ( @monsters && $monsters[-1] == $last ) {
            pop @monsters;
        }
        @monsters = grep { $_ > 0 } map { $_-1 } @monsters;
        $answer++;
    }
    say $answer;
}

#!/usr/bin/env perl

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

chomp (my $line = <STDIN>);

my $q = $line;

for (1..$q) {
    chomp ($line = <STDIN>);
    my ($n, $r) = split q{ }, $line;
    chomp ($line = <STDIN>);
    my @monsters = split q{ }, $line;

    my $set = {};
    for (@monsters) {
        $set->{$_} = 1 if !defined $set->{$_};
    }

    @monsters = sort keys %$set;

    my $answer = 0;
    while ( @monsters ) {
        my $last = $monsters[-1];
        while ( @monsters && $monsters[-1] == $last ) {
            pop @monsters;
        }
        @monsters = grep { $_ > 0 } map { $_-$r } @monsters;
        $answer++;
    }
    say $answer;
}

#!/usr/bin/env perl

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

chomp (my $line = <STDIN>);

my $q = $line;

for (1..$q) {
    chomp ($line = <STDIN>);
    my ($n, $r) = split q{ }, $line;
    $r++;
    chomp ($line = <STDIN>);
    my @monsters = split q{ }, $line;

    my $set = {};
    for (@monsters) {
        $set->{$_} = 1 if !defined $set->{$_};
    }

    @monsters = sort { $a <=> $b } keys %$set;

    my $answer = 0;
    my $i = 0;
    while ( $i < @monsters ) {
        if ( $r * $answer <= $monsters[$i] ) {
            pop @monsters;
            $answer++;
        }
        $i++;
    }
    say $answer;
}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	my( $n, $r ) = split;
	@_ = split ' ', <>;

	my $cnt = 0;

	while( @_ ){
		my $last = pop @_;
		if( $last - $cnt * $r > 0 ){
			$cnt ++;
			}
		else{
			last;
			}
		}

	print $cnt;
	}


Manao's friends often send him new songs. He never listens to them right away. Instead, he compiles them into a playlist. When he feels that his mind is open to new music, he opens the playlist and starts to listen to the songs.Of course, there are some songs that Manao doesn't particuarly enjoy. To get more pleasure from the received songs, he invented the following procedure of listening to the playlist:  If after listening to some song Manao realizes that he liked it, then he remembers it and starts to listen to the next unlistened song.  If after listening to some song Manao realizes that he did not like it, he listens to all the songs he liked up to this point and then begins to listen to the next unlistened song. For example, if Manao has four songs in the playlist, A, B, C, D (in the corresponding order) and he is going to like songs A and C in the end, then the order of listening is the following:  Manao listens to A, he likes it, he remembers it.  Manao listens to B, he does not like it, so he listens to A, again.  Manao listens to C, he likes the song and he remembers it, too.  Manao listens to D, but does not enjoy it and re-listens to songs A and C. That is, in the end Manao listens to song A three times, to song C twice and songs B and D once. Note that if Manao once liked a song, he will never dislike it on a subsequent listening.Manao has received n songs: the i-th of them is li seconds long and Manao may like it with a probability of pi percents. The songs could get on Manao's playlist in any order, so Manao wants to know the maximum expected value of the number of seconds after which the listening process will be over, for all possible permutations of the songs in the playlist.

The first line contains a single integer n (1 ≤ n ≤ 50000). The i-th of the following n lines contains two integers, separated by a single space — li and pi (15 ≤ li ≤ 1000, 0 ≤ pi ≤ 100) — the length of the i-th song in seconds and the probability that Manao will like the song, in percents.

In a single line print a single real number — the maximum expected listening time over all permutations of songs. The answer will be considered valid if the absolute or relative error does not exceed 10 - 9.

NoteConsider the first test case. If Manao listens to the songs in the order in which they were originally compiled, the mathematical expectation will be equal to 467.5 seconds. The maximum expected value is obtained by putting the first song at the end of the playlist.Consider the second test case. The song which is 360 seconds long should be listened to first. The song 300 seconds long which Manao will dislike for sure should be put in the end.


Theofanis has a riddle for you and if you manage to solve it, he will give you a Cypriot snack halloumi for free (Cypriot cheese).You are given an integer $$$n$$$. You need to find two integers $$$l$$$ and $$$r$$$ such that $$$-10^{18} \le l < r \le 10^{18}$$$ and $$$l + (l + 1) + \ldots + (r - 1) + r = n$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first and only line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^{18}$$$).

For each test case, print the two integers $$$l$$$ and $$$r$$$ such that $$$-10^{18} \le l < r \le 10^{18}$$$ and $$$l + (l + 1) + \ldots + (r - 1) + r = n$$$.  It can be proven that an answer always exists. If there are multiple answers, print any.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	chomp;

	print - $_ + 1, ' ', $_;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	chomp;

	print '-', $_ - 1, ' ', $_;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	chomp;

	print -1, ' ', ++ $_;
	}


A Pythagorean triple is a triple of integer numbers $$$(a, b, c)$$$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $$$a$$$, $$$b$$$ and $$$c$$$, respectively. An example of the Pythagorean triple is $$$(3, 4, 5)$$$.Vasya studies the properties of right triangles, and he uses a formula that determines if some triple of integers is Pythagorean. Unfortunately, he has forgotten the exact formula; he remembers only that the formula was some equation with squares. So, he came up with the following formula: $$$c = a^2 - b$$$.Obviously, this is not the right formula to check if a triple of numbers is Pythagorean. But, to Vasya's surprise, it actually worked on the triple $$$(3, 4, 5)$$$: $$$5 = 3^2 - 4$$$, so, according to Vasya's formula, it is a Pythagorean triple.When Vasya found the right formula (and understood that his formula is wrong), he wondered: how many are there triples of integers $$$(a, b, c)$$$ with $$$1 \le a \le b \le c \le n$$$ such that they are Pythagorean both according to his formula and the real definition? He asked you to count these triples.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing one integer $$$n$$$ ($$$1 \le n \le 10^9$$$).

For each test case, print one integer — the number of triples of integers $$$(a, b, c)$$$ with $$$1 \le a \le b \le c \le n$$$ such that they are Pythagorean according both to the real definition and to the formula Vasya came up with.

NoteThe only Pythagorean triple satisfying $$$c = a^2 - b$$$ with $$$1 \le a \le b \le c \le 9$$$ is $$$(3, 4, 5)$$$; that's why the answer for $$$n = 3$$$ is $$$0$$$, and the answer for $$$n = 6$$$ (and for $$$n = 9$$$) is $$$1$$$.

#!/usr/bin/perl

use warnings;
use strict;

my $debug = 0;

$\ = $/;

<>;

while(<>){
	chomp;

	my $A = sqrt( ( $_ - 1 << 1 ) + 1 );

	$debug and print join ',', $_, int $A, ( int $A ) - 1 >> 1, $A;

	print +( int $A ) - 1 >> 1;
	}


Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 ≤ i ≤ n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.Help Kefa cope with this task!

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

Print a single integer — the length of the maximum non-decreasing subsegment of sequence a.

NoteIn the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.

#!/usr/bin/perl -w
use strict;

<>;
my @a = split ' ', <>;
my $len = 1;
my $maxlen = 1;
for my $i (1..$#a) {
    if ($a[$i - 1] <= $a[$i]) {
        $len++;
        $maxlen = $len if $len > $maxlen;
    } else {
        $len = 1;
    }
}
print "$maxlen\n";

import strict;
import warnings;

$_ = (<>, <>);
map {$me = $_; if($me >= $x){$k ++;}else{$k = 1;} if($k > $s) {$s = $k;} $x = $me; } split;

print "$s\n";

#!/bin/perl

$n = <STDIN>;
$s = <STDIN>;

chomp $s;
@ciong = split / +/, $s;

$pop = 0;
$maks = 0;
$t = 0;

for($i=0;$i<$n;$i++)
{

  if(@ciong[$i] >= $pop)
  {

    $t++;

    if( $t > $maks )
    {

      $maks = $t;

    }

  }
  else
  {

    $t = 1;

  }

  $pop = @ciong[$i];

}

print $maks;

use strict;
use warnings;

my $n = <>;
my @all = split " ", <>;

$n = 2_000_000_000;
my ($len, $mx) = (0, 0);
for my $i (@all){
	if ($i >= $n){
		$n = $i;
		++$len;
	}
	else {
		$len = 1;
		$n = $i;
	}
	$mx = $len if $len > $mx;
}
print "$mx\n";

#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use v5.20;

my $n = <>;
my @numbers = split(' ', <>);

my $result = 1;
my $local_result = 1;

for (my $i = 1; $i < @numbers; $i++)
{
    if ($numbers[$i] >= $numbers[$i-1])
    {
        $local_result++;
    }
    else
    {
        $result = $local_result if $local_result > $result;
        $local_result = 1
    }
}
$result = $local_result if $local_result > $result;

say $result;

my $n = <>;
my @array = split ' ', <>;
my $last = shift @array;
my $c = 1;
my $max_c = 1;
while (my $a = shift @array) {
    if ($a < $last) {
      $max_c = $c if ($max_c < $c);
      $c = 1;
    }
    else {
      ++$c;
    }
    $last = $a;
}
$max_c = $c if ($max_c < $c);
print $max_c;

use strict;
use warnings;

my $n = <>;
my @all = split " ", <>;

$n = 2_000_000_000;
my ($len, $mx) = (0, 0);
for my $i (@all){
	if ($i >= $n){
		$n = $i;
		++$len;
		$mx = $len if $len > $mx;
	}
	else {
		$len = 1;
		$n = $i;
	}
}
print "$mx\n";

use strict;
use warnings;

my $n = <>;
my @all = split " ", <>;

$n = 2_000_000_000;
my ($len, $mx) = (0, 0);
for my $i (@all){
	if ($i >= $n){
		$n = $i;
		++$len;
		$mx = $len if $len > $mx;
	}
	else {
		$mx = $len if $len > $mx;
		$len = 1;
		$n = $i;
	}
}
print "$mx\n";


The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags).

The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.

Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.

6 5
3 5 1 6 8 1
peach
grapefruit
banana
orange
orange

#!/bin/perl -w
use strict;
use warnings;

my ($n, $m) = map int, split /\D/, <>;
my @prices = map int, split /\D/, <>;
my %fruits;
for (1..$m) {
    my $fruit = <>;
    chomp $fruit;
    if (defined $fruits{$fruit}) {
	$fruits{$fruit}++;
    } else {
	$fruits{$fruit} = 1;
    }
}

@prices = sort { $a <=> $b } @prices;
my ($cmin, $cmax, $in, $ix) = (0, 0, 0, $#prices);
for my $key (sort { $fruits{$b} <=> $fruits{$a} } keys %fruits) {
    $cmin += $fruits{$key} * $prices[$in++];
    $cmax += $fruits{$key} * $prices[$ix--];
}

print "$cmin $cmax\n";


Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?

The only line of the input contains single integer n (1 ≤ n ≤ 109) — the length of some side of a right triangle.

Print two integers m and k (1 ≤ m, k ≤ 1018), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.

use bigint;

my $m, $n, $a, $b, $c;
my $i, $j;

my $f = <STDIN>;
chomp ( $f );

my $g = $f;

if ( $f <= 2 ) {
    print "-1\n";}
elsif ( $g % 2 == 0 ) {		# n is even
    $g /= 2;
    $a = $g * $g + 1;
    $b = $g * $g - 1;
    print "$a $b\n";
}
else {				# n is odd
    my $var = ($g * $g + 1) / 2;
    my $uu = sqrt ( ($var * $var) - ($g * $g) );
    print "$var $uu\n";
}

my $m, $n, $a, $b, $c;
my $i, $j;
my $upper = int sqrt ( 10 ** 9 );

my $f = <STDIN>;
chomp ( $f );

my $g = $f;
# every even number is will be the side of a pythagorean triple
if ( $f <= 2 ) {
    print "-1\n"; }
elsif ( $g % 2 == 0 ) {
    $a = $g * $g  + 1;
    $b = $g * $g - 1;
    print "$a $b\n";
}
else {

    for ( $i = 1; $i < $upper and (not $found); $i += 1 ) {
	for ( $j = $i + 1; $j < $upper and (not $found); $j += 1 ) {
	    $a = ($j ** 2) - ($i ** 2);
	    $b = 2 * $j * $i;
	    $c = ($j ** 2) + ($i ** 2);
	    if ( $a == $f or $b == $f or $c == $f ) {
		if ( $a != $f ) { print "$a ";}
		if ( $b != $f ) { print "$b ";}
		if ( $c != $f ) { print "$c ";}
		$found = 1;}
	}
    }

if ( not $found ) { print "-1"; }
print "\n";
}


You are given an array of n integer numbers a0, a1, ..., an - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.

The first line contains positive integer n (2 ≤ n ≤ 105) — size of the given array. The second line contains n integers a0, a1, ..., an - 1 (1 ≤ ai ≤ 109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times.

Print the only number — distance between two nearest minimums in the array.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	$_ = <>;
	@_ = split;

	my $min = ( sort { $a <=> $b } @_ )[ 0 ];
	my $i = 1e5;
	my $MIN = 1e5;

	for( @_ ){
		$_ == $min ? do {
				$MIN > $i and $MIN = $i;
				$i = 1;
			}
			: do {
				$i ++;
			};
		}

	print $MIN;
	}


The Greatest Secret Ever consists of n words, indexed by positive integers from 1 to n. The secret needs dividing between k Keepers (let's index them by positive integers from 1 to k), the i-th Keeper gets a non-empty set of words with numbers from the set Ui = (ui, 1, ui, 2, ..., ui, |Ui|). Here and below we'll presuppose that the set elements are written in the increasing order.We'll say that the secret is safe if the following conditions are hold:  for any two indexes i, j (1 ≤ i < j ≤ k) the intersection of sets Ui and Uj is an empty set;  the union of sets U1, U2, ..., Uk is set (1, 2, ..., n);  in each set Ui, its elements ui, 1, ui, 2, ..., ui, |Ui| do not form an arithmetic progression (in particular, |Ui| ≥ 3 should hold). Let us remind you that the elements of set (u1, u2, ..., us) form an arithmetic progression if there is such number d, that for all i (1 ≤ i < s) fulfills ui + d = ui + 1. For example, the elements of sets (5), (1, 10) and (1, 5, 9) form arithmetic progressions and the elements of sets (1, 2, 4) and (3, 6, 8) don't.Your task is to find any partition of the set of words into subsets U1, U2, ..., Uk so that the secret is safe. Otherwise indicate that there's no such partition.

The input consists of a single line which contains two integers n and k (2 ≤ k ≤ n ≤ 106) — the number of words in the secret and the number of the Keepers. The numbers are separated by a single space.

If there is no way to keep the secret safe, print a single integer "-1" (without the quotes). Otherwise, print n integers, the i-th of them representing the number of the Keeper who's got the i-th word of the secret. If there are multiple solutions, print any of them.


Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai, ai) are the opposite corners of the i-th square.Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary. Help Vasya find a point that would meet the described limits.

The first line contains two space-separated integers n, k (1 ≤ n, k ≤ 50). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109). It is guaranteed that all given squares are distinct.

In a single line print two space-separated integers x and y (0 ≤ x, y ≤ 109) — the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them.  If there is no answer, print "-1" (without the quotes).

#!/usr/bin/perl -w

use strict;

chomp($_ = <>);
my ($n, $k) = split;
chomp($_ = <>);
my @a = split;
@a = sort { -($a <=> $b) } @a;
if ($k - 1 < $n) {
    my $res = $a[$k - 1];
    print "$res $res\n";
} else {
    print "-1\n";
}


Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.

The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105).  The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that means that the second wrestler performed the technique that was awarded with ( - ai) points. The techniques are given in chronological order.

If the first wrestler wins, print string "first", otherwise print "second"

NoteSequence x  =  x1x2... x|x| is lexicographically larger than sequence y  =  y1y2... y|y|, if either |x|  >  |y| and x1  =  y1,  x2  =  y2, ... ,  x|y|  =  y|y|, or there is such number r (r  <  |x|, r  <  |y|), that x1  =  y1,  x2  =  y2,  ... ,  xr  =  yr and xr  +  1  >  yr  +  1.We use notation |a| to denote length of sequence a.


You are given two integers $$$x$$$ and $$$y$$$ (it is guaranteed that $$$x > y$$$). You may choose any prime integer $$$p$$$ and subtract it any number of times from $$$x$$$. Is it possible to make $$$x$$$ equal to $$$y$$$?Recall that a prime number is a positive integer that has exactly two positive divisors: $$$1$$$ and this integer itself. The sequence of prime numbers starts with $$$2$$$, $$$3$$$, $$$5$$$, $$$7$$$, $$$11$$$.Your program should solve $$$t$$$ independent test cases.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ lines follow, each describing a test case. Each line contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le y < x \le 10^{18}$$$).

For each test case, print YES if it is possible to choose a prime number $$$p$$$ and subtract it any number of times from $$$x$$$ so that $$$x$$$ becomes equal to $$$y$$$. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).

NoteIn the first test of the example you may choose $$$p = 2$$$ and subtract it once.In the second test of the example you may choose $$$p = 5$$$ and subtract it twice. Note that you cannot choose $$$p = 7$$$, subtract it, then choose $$$p = 3$$$ and subtract it again.In the third test of the example you may choose $$$p = 3$$$ and subtract it $$$333333333333333333$$$ times.

#!/usr/bin/env perl

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

chomp (my $line = <STDIN>);

my $t = $line;
my @primes = (2, 3, 5, 7, 11);

TESTCASE:
for (1..$t) {
    chomp ($line = <STDIN>);
    my ($x, $y) = split q{ }, $line;

    my $z = $x - $y;

    if ( $z == 1 ) { say "no"; next TESTCASE; }
    else           { say "yes"; next TESTCASE; }
}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	my( $x, $y ) = split;

	print $x == $y + 1 ? "NO" : "YES";
	}


Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.

The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.

Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.

4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis

<>;
s/\B.{9,}\B/length$&/e, print for <>

chomp($num = <STDIN>);
while($num-- > 0) {
	chomp($word = <STDIN>);
	$l = length($word);
	if($l < 11) {
		print $word;
	} else {
		print substr($word, 0, 1).($l-2).substr($word, -1, 1);
	}
	print "\n";
}

use strict;
use warnings;

my $n = <>;
for (1..$n) {
	my $s = <>;
	chomp $s;
	my $len = length $s;
	if ($len > 10) {
		substr($s,1,-1) = $len-2;
	}
	print "$s\n";
}

#!/usr/bin/perl

chomp($n=<STDIN>);
while($n--)
{
chomp ($str=<STDIN>);
my @array = split(//,$str);
$c=$#array;
if ($c<10)
{
print "$str\n";}
else
{
$m=$c-1;
my $e= pop(@array);
$b= shift(@array);
print"$b";
print"$m";
print"$e\n";
}
}

#!/bin/perl
use strict;
use warnings;
my @chars = ();
my $line = '';

chomp (my $line_n = <>);
for (1..$line_n) {
    chomp($line = <>);
    if (length($line) >= 11) {
        @chars = $line =~ /./sg;
        $line = "$chars[0]" . (length($line)-2) . "$chars[-1]";
    }
    print "$line \n";
}

#!/bin/perl
use strict;
use warnings;
my @chars = ();
my $line = '';
my $l = 0;

chomp (my $line_n = <>);
for (1..$line_n) {
    chomp($line = <>);
    $l = length($line);
    if ($l >= 11) {
        @chars = $line =~ /./sg;
        $line = "$chars[0]" . ($l-2) . "$chars[-1]";
    }
    print "$line \n";
}

use strict;
use warnings;
chomp (my $line_n = <>);
my @chars = ();
my $i = 0;
my $line = '';
my @out = ();
my $l = 0;
for ($i=0; $i<$line_n; $i++) {
    chomp($line = <>);
    $l = length($line);
    if ($l < 11) {
        $out[$i] = $line;
    } else {
        @chars = $line =~ /./sg;
        $out[$i] = "$chars[0]" . ($l-2) . "$chars[-1]";
    }
}
foreach (@out) {print "$_ \n";}

<STDIN>; while(<STDIN>){chomp; if((our $len = length $_) <= 10){ print "$_\n"; }else{ print substr($_, 0, 1), $len-2, substr($_, -1, 1), "\n" } }

use strict;
use warnings;
use feature "say";

my $n = <STDIN>;

for ($_ = 0; $_ < $n; $_++)
{
    my $word = <STDIN>;
    chomp $word;
    my $len = length $word;
    if ($len > 10)
    {
        $word = substr($word, 0, 1) . ($len - 2) . substr($word, $len - 1, 1)
    }
    say $word;
}

use v5.20;

use warnings;
use strict;

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

while($n--)
{
	my $s =<>;
	chomp($s);

	if(length $s > 10)
	{
		my $first = substr($s, 0, 1);
		my $last = substr($s, -1);
		my $length = (length $s) - 2;
		say "$first$length$last";
	}
	else
	{
		say "$s";
	}
}

#!/usr/bin/perl
$cases = <>; #number of cases
while($cases--){
    $myname=<>; #get input name
    $lengthofmyname=length($myname); #get its name
    $lengthofmyname = $lengthofmyname+0; #covt to num for being safe
    $maxlen=11; #maxlen permissible
    if($lengthofmyname>$maxlen){
        $first=substr($myname,0,1); #get first letter
        $last=substr($myname,$lengthofmyname-2,1); #get last letter
        $lengthofmyname=$lengthofmyname-3; #decr by 3 as it returns one extra
        print $first;
        print $lengthofmyname;
        print $last;
        print "\n";
    }
    else{
        print "$myname\n";
    }
}

#!/usr/bin/env perl

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

use Carp;

# essential
my @tokens = ();

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

sub say_all {
    my @args = @_;
    say join ' ', @args;
}

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

sub ref_ref_scalar {
    my $ref = shift;
    return 1 if ref($ref) eq 'SCALAR';
}

sub toggle {
    my $ref = shift;
    croak "$ref does not reference to scalar" if !ref_ref_scalar($ref);

    $$ref = !$$ref;
}

sub odd {
    my $num = shift;
    return $num % 2 == 1;
}

sub even {
    my $num = shift;
    return $num % 2 == 0;
}

sub sum_of_digits {
    my $n = shift;
    my @numbers = split q{}, $n;

    my $sum = 0;

    for (@numbers) {
        $sum += $_;
    }

    return $sum;
}

# solution

my $n = read_token;

for (1..$n) {
    my $word = read_token;
    my $len = length $word;
    my $answer;
    if ($len > 10) {
        $answer = substr($word, 0, 1).($len-2).substr($word, $len-1, 1);
    }
    else {
        $answer = $word;
    }
    say $answer;
}

$n = <>;

for ($i = 0; $i < $n; ++$i) {
    $str = <>;
    chomp $str;
    $len = (length $str) - 2;
    $str = substr ($str, 0, 1) . "$len" . chop ($str) if $len > 8;
    print $str . "\n";
}

#!/usr/bin/perl;

$n = <STDIN>;

my @words;

for ($i = 0; $i < $n; $i++) {
	$m = <STDIN>;
	push(@words, $m);
}

for ($i = 0; $i < $n; $i++) {
	if (length(@words[$i]) < 12) {
		print(@words[$i]);
	} else {
		print(substr(@words[$i], 0, 1),(length(@words[$i]) - 3),substr(@words[$i], -2, 1),"\n");
	}
}

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

sub shorten
{ my $s = $_[0]; my $n = length($s) - 3;
  substr $s, 1, $n, $n if $n > 8; $s }

<STDIN>;
print shorten $_ while <STDIN>

#!/usr/bin/perl

$n = <>;

while($n--){
	$word = <>;

	$len = length($word) - 1;
	if($len <11){
		print "$word\n";
	}
	else{
		$mid = $len - 2;
		@chars = split("",$word);
		print "$chars[0]$mid$chars[$len-1]\n";
	}
}

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

<STDIN>;
for (<STDIN>) {
    chomp;
    s/^(.)(.+)(.)$/$1.length($2).$3/e if length > 10;
    say;
}

#!perl

my $num = <STDIN>;
for (1..$num) {
    my $word = <STDIN>;
    chomp $word;
    my @word = split //, $word;
    (@word > 10) ? print $word[0], @word - 2 , $word[-1],"\n" : print $word, "\n";
}

my $len = <STDIN>;

for my $val (1 .. $len) {
	my $word = <STDIN>;
	$word =~ s/\s//g;

	my $word_length = length $word;

	if ($word_length > 10) {
		my $f_let = substr $word, 0, 1;
		my $l_let = substr $word, $word_length - 1, 1;

		print $f_let.($word_length - 2).$l_let."\n";
	} else {
		print $word."\n";
	}
}

#!/usr/bin/env perl

use v5.012;
use warnings;

chomp(my $count = <STDIN>);

while ($count--) {
	chomp(my $word = <STDIN>);
	if (length $word > 10) {
		$word =~ /^(.)(.*)(.)$/;
		$word = $1 . (length $2) . $3;
	}
	say $word;
}

use strict;
use warnings;

my $n = <STDIN>;

while($n-- > 0){
    my $s = <STDIN>;
    chomp($s);
    if(length($s) <= 10){
        print "$s\n";
    }else{
        print substr($s,0,1).(length($s)-2).substr($s,length($s)-1,1)."\n";
    }
}

my $a = <>;
foreach (0 .. $a)
{
    my $str = <>;
    chomp $str;
    if (length $str <= 10) {
        print $str, "\n";
    } else {
        print substr ($str, 0, 1), (length $str) - 2, substr ($str, -1, 1), "\n";
    }
}

chomp($n = <STDIN>);
while($n--)
{
    chomp($word = <STDIN>);
    if (length($word) > 10)
    {
        $len = length($word) - 2;
        $word =~ s/(^.).+?(.$)/$1$len$2/;
        push @words, $word;
    }
    else
    {
        push @words, $word;
    }
}

foreach $word (@words)
{
    print "$word\n";
}

my $n = <>;
my $str;
my @arr;
for(1..$n) {
    $str = <>;
    chomp $str;
    @arr = split "", $str;
    $str =  $arr[0] . (scalar @arr-2) . $arr[-1] if (scalar @arr > 10);
    print $str . "\n";
}

$n = <STDIN>;
while($n != 0) {
	$s = <STDIN>;
	if(length($s) - 1 > 10) {
		print substr($s, 0, 1) . (length($s) - 3) . substr($s, length($s) - 2, 1) . "\n";
	} else {
		print "$s";
	}
	$n--;
}

# 4
# word
# localization
# internationalization
# pneumonoultramicroscopicsilicovolcanoconiosis

# Выходные данные

# word
# l10n
# i18n
# p43s

# Author Badhan Sen
# CSE-14, JUST

# 71A. Way Too Long Words
# Accepted

my $num=<>;

while($num--){
	my $str=<>;

	if(length($str)-1 > 10){
		print substr($str, 0, 1).(length($str)-3).substr($str, length($str)-2, 1);
		print "\n";
	}
	else{
		print $str;
		print "\n";
	}
}

#!/usr/bin/env perl

chomp(my $n = <STDIN>);

for ( 0..$n - 1 )
{
	chomp(my $word = <STDIN>);

	if ( length($word) > 10 )
	{
		$word = substr($word, 0, 1).(length($word) - 2).substr($word, length($word) - 1);

	}

	print("$word\n");

}

#!/usr/bin/env perl

use strict;
use warnings;
use utf8;
use v5.20;

sub main {
    my $lines = int(readline(STDIN)) || 0;

    while ($lines--) {
        my $word = readline(STDIN);
        chomp $word;
        say length $word <= 10
            ? $word
            : substr($word, 0, 1 ) . length(substr($word, 1, -1)) . substr($word,-1);
    }

    return;
}

main();

exit;

#!/usr/bin/env perl

use strict;
use warnings;
use utf8;
use v5.20;

sub main {
    my %args = @_;

    my $lines = int(readline(STDIN)) || 0;

    while ($lines--) {
        my $world = readline(STDIN);
        $world =~ s/(?<=^\w).{9,}(?=\w$)/length $&/e;
        print $world;
    }

    return;
}

main();

exit;

my $n = <STDIN>;
while($n--) {
    my $s = <STDIN>;
    if((length($s) -1) > 10) {
        print substr($s, 0, 1).(length($s) - 3).substr($s, length($s) - 2, 1)."\n";
    }
    else {
        print $s;
    }
}

my $n = <STDIN>;
while($n--) {
    my $s = <STDIN>;
    chomp($s);
    if(length($s) > 10) {
        print substr($s, 0, 1).(length($s) - 2).substr($s, length($s) - 1, 1)."\n";
    }
    else {
        print $s."\n";
    }
}

#!/usr/bin/perl
# your code goes here
use v5.10;

chomp ($n = <>);
while ($n-- > 0) {
	chomp($line = <>);
	$len = length($line)-2;
	$line_ = substr($line, 0, 1) . "$len" . substr($line, $len+1, 1);
	$len<=8 and say $line or say $line_;
}

use strict;
use warnings;

my $input_lines = <>;
my @words;
for (1..$input_lines) {
    my $line = <>;
    chomp $line;
    push @words, $line;
}

my $max_len = 10;

for my $word (@words) {
    my $word_len = length($word);
    if ( $word_len > $max_len ) {
        print substr($word, 0, 1) . ($word_len-2) . substr($word, $word_len-1, 1) . "\n";
    } else {
        print "$word\n";
    }
}

#!/usr/bin/perl -w
use strict;

my $i=<>;
while ($i--){
my $a=<>;
if(($b=length($a)-3)>8) {print substr($a,0,1),$b,substr($a,-2,1),"\n";} else {print "$a\n";}
}

use strict;
use warnings;

sub main
{
    my $input = <STDIN>;
    my @words;
    my $word;
    my $newWord="";
    my $wordLen;
    for(my $i=0;$i<$input;$i++){
        my $inputwords = <STDIN>;
        push @words, $inputwords;
    }
    for(my $i=0;$i<$input;$i++){
        $word = shift @words;
        $wordLen = length($word);
        if($wordLen-1>10){
            $wordLen=$wordLen-3;
            my $headword = substr($word,0,1);
            my $tailword = substr($word,length($word)-2,1);
            $newWord = $headword.$wordLen.$tailword;
            printf("$newWord\n");
        }
        else{
            printf("$word");
        }
    }
}

main();

use strict;
use warnings;

sub main
{
    my $input = <STDIN>;
    my @words;
    my $word;
    my $newWord="";
    my $wordLen;
    for(my $i=0;$i<$input;$i++){
        my $inputwords = <STDIN>;
        push @words, $inputwords;
    }
    for(my $i=0;$i<$input;$i++){
        $word = shift @words;
        $wordLen = length($word);
        if($wordLen>10){
            $wordLen=$wordLen-3;
            my $headword = substr($word,0,1);
            my $tailword = substr($word,length($word)-2,1);
            $newWord = $headword.$wordLen.$tailword;
            printf("$newWord\n");
        }
        else{
            printf("$word");
        }
    }
}

main();

use strict;
use warnings;

my $n = <>;
for (1..$n) {
	my $s = <>;
	chomp $s;
	my $len = length $s;
	if ($len > 10) {
		substr($s,1,-2) = $len-2;
	}
	print "$s\n";
}

#!/usr/bin/perl

chomp($str=<STDIN>);
my @array = split(//,$str);
$c=$#array;
if ($c<=10)
{
print "$str\n";}
else
{
$m=$c-2;
my $e= pop(@array);
$b= shift(@array);
print"$b";
print"$m";
print"$e";
}

#!/usr/bin/perl

chomp($n=<STDIN>);
while($n--)
{
chomp ($str=<STDIN>);
my @array = split(//,$str);
$c=$#array;
if ($c<=10)
{
print "$str\n";}
else
{
$m=$c-2;
my $e= pop(@array);
$b= shift(@array);
print"$b";
print"$m";
print"$e\n";
}
}

#!/usr/bin/perl

chomp($n=<STDIN>);
while($n--)
{
chomp ($str=<STDIN>);
my @array = split(//,$str);
$c=$#array;
if ($c<=10)
{
print "$str\n";}
else
{
$m=$c-1;
my $e= pop(@array);
$b= shift(@array);
print"$b";
print"$m";
print"$e\n";
}
}

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

chomp (my $line_n = <>);
my @chars = ();
my $i = 0;
my $line = '';
my @out = ();
my $l = 0;
for ($i=0; $i<$line_n; $i++) {
    chomp($line = <>);
    $l = length($line);
    if ($l < 10) {
        $out[$i] = $line;
    } else {
        @chars = $line =~ /./sg;
        $out[$i] = "$chars[0]" . ($l-2) . "$chars[-1]";
    }
}
foreach (@out) {
    print "$_ \n";
}

<STDIN>; while(<STDIN>){chomp; if((our $len = length $_) <= 10){ print "$_\n"; }else{ print substr($_, 0, 1), $len, substr($_, -1, 1), "\n" } }

#!/usr/bin/perl
$inputlines=<>;
while($inputlines--){
    $word=<>;
    $len = length $word;
    if($len > 10){
        #then unpack them in array and print abbvr
        $len -=2;
        $first=substr($word,0,1);
        $last=substr($word,$len,1);
        $len=$len-1;
        print $first;
        print $len;
        print $last;
        print "\n";
    }
    else{
        print "$word\n";
    }
}

#!/usr/bin/perl
$inputlines=<>;
while($inputlines--){
    $word=<>;
    $len = length $word;
    if($len > 10){
        #then unpack them in array and print abbvr
        $len -=2;
        $first=substr($word,0,1);
        $last=substr($word,$len,1);
        print $first;
        print $len;
        print $last;
        print "\n";
    }
    else{
        print "$word\n";
    }
}

#!/usr/bin/perl;

$n = <STDIN>;

my @words;

for ($i = 0; $i < $n; $i++) {
	$m = <STDIN>;
	push(@words, $m);
}

for ($i = 0; $i < $n; $i++) {
	if (length(@words[$i]) < 11) {
		print(@words[$i]);
	} else {
		print(substr(@words[$i], 0, 1),(length(@words[$i]) - 3),substr(@words[$i], -2, 1),"\n");
	}
}

@in = <>;
$n = $in;
print $in;
print "\n";
print $n;
print "\n";
for($i = 1; $i < $n; $i++) {
    print $in[$i];
}

<>;
s/\B.{8,}\B/length$&/e, print for <>

#!perl

my $num = <STDIN>;
for (1..$num) {
    my $word = <STDIN>;
    chomp $word;
    my @word = split //, $word;
    (@word > 10) ? print $word[0] , length $word - 2 , $word[-1],"\n" : print $word, "\n";
}

use 5.020;

my $len = <>;
chomp $len;

while(<>) {
   chomp;
   next if length $_ <= $len;
   s/(.)(.+)(.)/$1 . length($2) . $3/e;
   say;
}

$n = <STDIN>;
while($n != 0) {
	$s = <STDIN>;
	if(length($s) > 10) {
		print substr($s, 0, 1) . (length($s) - 3) . substr($s, length($s) - 2, 1) . "\n";
	} else {
		print "$s";
	}
	$n--;
}

# 4
# word
# localization
# internationalization
# pneumonoultramicroscopicsilicovolcanoconiosis

# Выходные данные

# word
# l10n
# i18n
# p43s

#!/usr/bin/env perl

use strict;
use warnings;
use utf8;
use v5.20;

sub main {
    my %args = @_;

    my $lines = int(readline(STDIN)) || 0;

    while ($lines--) {
        my $world = readline(STDIN);
        $world =~ s/(?<=^\w).{6,}(?=\w$)/length $&/e;
        print $world;
    }

    return;
}

main();

exit;

my $n = <STDIN>;
while($n--) {
    my $s = <STDIN>;
    if((length($s) -1) >= 10) {
        print substr($s, 0, 1).(length($s) - 3).substr($s, length($s) - 2, 1);
    }
    else {
        print $s;
    }
}

my $n = <STDIN>;
while($n--) {
    my $s = <STDIN>;
    chomp($s);
    if(length($s) > 10) {
        print substr($s, 0, 1).(length($s) - 2).substr($s, length($s) - 1, 1)."\n";
    }
    else {
        print $s;
    }
}

my $n = <STDIN>;
while($n--) {
    my $s = <STDIN>;
    if((length($s) -1) >= 10) {
        print substr($s, 0, 1).(length($s) - 3).substr($s, length($s) - 2, 1)."\n";
    }
    else {
        print $s;
    }
}

use strict;
use warnings;

my $input_lines = <>;
my @words;
print "\n***\n";
for (1..$input_lines) {
    my $line = <>;
    chomp $line;
    push @words, $line;
}

my $max_len = 10;

for my $word (@words) {
    my $word_len = length($word);
    if ( $word_len > $max_len ) {
        print substr($word, 0, 1) . ($word_len-2) . substr($word, $word_len-1, 1) . "\n";
    } else {
        print "$word\n";
    }
}

#!/usr/bin/perl -w
use strict;

my $i=<>;
while ($i--){
my $a=<>;
if(($b=length($a)-3)>7) {print substr($a,0,1),$b,substr($a,-2,1),"\n";} else {print "$a\n";}
}

#!/usr/bin/perl -w
use strict;
my $i=<>;
while ($i--){
my $a=<>;
if(($b=length($a)-3)>7) {print substr($a,0,1),$b,substr($a,-2,1);} else {print $a;}
}

#!/usr/bin/perl -w
use strict;
my $i=<>;
while ($i--){
my $a=<>;
if(($b=length($a)-2)>8) {print substr($a,0,1),$b,substr($a,-1,1);} else {print $a;}
}


Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer k and a sequence a, consisting of n integers.He wants to know how many subsequences of length three can be selected from a, so that they form a geometric progression with common ratio k.A subsequence of length three is a combination of three such indexes i1, i2, i3, that 1 ≤ i1 < i2 < i3 ≤ n. That is, a subsequence of length three are such groups of three elements that are not necessarily consecutive in the sequence, but their indexes are strictly increasing.A geometric progression with common ratio k is a sequence of numbers of the form b·k0, b·k1, ..., b·kr - 1.Polycarp is only three years old, so he can not calculate this number himself. Help him to do it.

The first line of the input contains two integers, n and k (1 ≤ n, k ≤ 2·105), showing how many numbers Polycarp's sequence has and his favorite number. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — elements of the sequence.

Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio k.

NoteIn the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4.

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

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

my %total = ();
my %curr = ();

for my $i (@arr) {
    if ( not exists $total { $i } ) {
	$total { $i } = 0;
    }
    $total { $i } += 1;
}

my $sum = 0;
for ( my $i = 0; $i < (scalar @arr); $i += 1 ) {

    if ( $i > 0 and $i < (scalar @arr)-1 ) {

	if ( $arr[ $i ] % $k == 0 ) {
	    if ( $k != 1 and $arr[ $i ] != 0 ) {
		$sum += (($curr { $arr[ $i ] / $k }) *
			 ($total { $arr[ $i ] * $k } - $curr { $arr[ $i ] * $k }));
	    }
	    else {
		$sum += (($curr { $arr[ $i ] / $k }) *
			 ($total { $arr[ $i ] * $k } - $curr { $arr[ $i ] * $k } - 1));
	    }
	}
    }

    if ( not exists $curr { $arr [ $i ] } ) {
	$curr { $arr[ $i ] } = 0;
    }
    $curr { $arr[ $i ] } += 1;
}

print "$sum \n";

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

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

my %total = ();
my %curr = ();

for my $i (@arr) {
    if ( not exists $total { $i } ) {
	$total { $i } = 0;
    }
    $total { $i } += 1;
}

my $sum = 0;
for ( my $i = 0; $i < (scalar @arr); $i += 1 ) {

    if ( $i > 0 and $i < (scalar @arr)-1 ) {

	if ( $arr[ $i ] % $k == 0 ) {
	    if ( $k != 1 ) {
		$sum += (($curr { $arr[ $i ] / $k }) *
			 ($total { $arr[ $i ] * $k } - $curr { $arr[ $i ] * $k }));
	    }
	    else {
		$sum += (($curr { $arr[ $i ] / $k }) *
			 ($total { $arr[ $i ] * $k } - $curr { $arr[ $i ] * $k } - 1));
	    }
	}
    }

    if ( not exists $curr { $arr [ $i ] } ) {
	$curr { $arr[ $i ] } = 0;
    }
    $curr { $arr[ $i ] } += 1;
}

print "$sum \n";


Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative integers a1, a2, ..., an. He also wrote a square matrix b of size n × n. The element of matrix b that sits in the i-th row in the j-th column (we'll denote it as bij) equals:  the "bitwise AND" of numbers ai and aj (that is, bij = ai & aj), if i ≠ j;  -1, if i = j. Having written out matrix b, Polycarpus got very happy and wiped a off the blackboard. But the thing is, the teacher will want this sequence to check whether Polycarpus' calculations were correct. Polycarus urgently needs to restore the removed sequence of integers, or else he won't prove that he can count correctly.Help Polycarpus, given matrix b, restore the sequence of numbers a1, a2, ..., an, that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109.

The first line contains a single integer n (1 ≤ n ≤ 100) — the size of square matrix b. Next n lines contain matrix b. The i-th of these lines contains n space-separated integers: the j-th number represents the element of matrix bij. It is guaranteed, that for all i (1 ≤ i ≤ n) the following condition fulfills: bii = -1. It is guaranteed that for all i, j (1 ≤ i, j ≤ n; i ≠ j) the following condition fulfills: 0 ≤ bij ≤ 109, bij = bji.

Print n non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces.  It is guaranteed that there is sequence a that satisfies the problem conditions. If there are multiple such sequences, you are allowed to print any of them.

NoteIf you do not know what is the "bitwise AND" operation please read: http://en.wikipedia.org/wiki/Bitwise_operation.


Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets.Dr. Evil has his favorite evil integer x. He asks Mahmoud and Ehab to find a set of n distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly x. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106.

The only line contains two integers n and x (1 ≤ n ≤ 105, 0 ≤ x ≤ 105) — the number of elements in the set and the desired bitwise-xor, respectively.

If there is no such set, print "NO" (without quotes). Otherwise, on the first line print "YES" (without quotes) and on the second line print n distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them.

NoteYou can read more about the bitwise-xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XORFor the first sample .For the second sample .


Monocarp has been collecting rare magazines for quite a while, and now he has decided to sell them. He distributed the magazines between $$$n$$$ boxes, arranged in a row. The $$$i$$$-th box contains $$$a_i$$$ magazines. Some of the boxes are covered with lids, others are not. Suddenly it started to rain, and now Monocarp has to save as many magazines from the rain as possible. To do this, he can move the lids between boxes as follows: if the $$$i$$$-th box was covered with a lid initially, he can either move the lid from the $$$i$$$-th box to the box $$$(i-1)$$$ (if it exists), or keep the lid on the $$$i$$$-th box. You may assume that Monocarp can move the lids instantly at the same moment, and no lid can be moved more than once. If a box will be covered with a lid after Monocarp moves the lids, the magazines in it will be safe from the rain; otherwise they will soak.You have to calculate the maximum number of magazines Monocarp can save from the rain.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of the testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of boxes. The second line contains a string of $$$n$$$ characters 0 and/or 1. If the $$$i$$$-th character is 1, the $$$i$$$-th box is initially covered with a lid. If the $$$i$$$-th character is 0, the $$$i$$$-th box is initially not covered. The third line contains a sequence of integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^4$$$), where $$$a_i$$$ is the number of magazines in the $$$i$$$-th box. The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print one integer — the maximum number of magazines Monocarp can save from the rain.

NoteIn the first testcase of the example, Monocarp can move the lid from the second box to the first box, so the boxes $$$1$$$, $$$3$$$ and $$$4$$$ are covered, and $$$10 + 8 + 9 = 27$$$ magazines are saved.In the second testcase, Monocarp can move the lid from the second box to the first box, then from the third box to the second box, then from the fifth box to the fourth box, and then from the sixth box to the fifth box. The boxes $$$1$$$, $$$2$$$, $$$4$$$ and $$$5$$$ will be covered, so $$$20 + 10 + 30 + 20 = 80$$$ magazines can be saved.There are no lids in the third testcase, so it's impossible to save even a single magazine.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	my $A = reverse <> =~ y/10/ab/r;
	$_ = <>;

	s/\s/ chop $A /ge;

	my $Z = 0;

	@_ = map y/ab/  /r, map s/^(?=\d+a)/0b/r, m/(?:\d+b)?(?:\d+a)+/g;

	print 0 + eval join '+',
		map { my @A = sort { $b <=> $a } split; pop @A; @A } @_;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	my $A = reverse <> =~ y/10/ab/r;
	$_ = <>;

	s/\s/ chop $A /ge;

	my $Z = 0;

	@_ = map y/ab/  /r, m/(?:\d+b)?(?:\d+a)+/g;

	print 0 + eval join '+',
		map { my @A = sort { $b <=> $a } split; pop @A; @A } @_;
	}


You are given two strings of equal length $$$s$$$ and $$$t$$$ consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.During each operation you choose two adjacent characters in any string and assign the value of the first character to the value of the second or vice versa.For example, if $$$s$$$ is "acbc" you can get the following strings in one operation:   "aabc" (if you perform $$$s_2 = s_1$$$);  "ccbc" (if you perform $$$s_1 = s_2$$$);  "accc" (if you perform $$$s_3 = s_2$$$ or $$$s_3 = s_4$$$);  "abbc" (if you perform $$$s_2 = s_3$$$);  "acbb" (if you perform $$$s_4 = s_3$$$); Note that you can also apply this operation to the string $$$t$$$.Please determine whether it is possible to transform $$$s$$$ into $$$t$$$, applying the operation above any number of times.Note that you have to answer $$$q$$$ independent queries.

The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is represented by two consecutive lines. The first line of each query contains the string $$$s$$$ ($$$1 \le |s| \le 100$$$) consisting of lowercase Latin letters. The second line of each query contains the string $$$t$$$ ($$$1 \le |t| \leq 100$$$, $$$|t| = |s|$$$) consisting of lowercase Latin letters.

For each query, print "YES" if it is possible to make $$$s$$$ equal to $$$t$$$, and "NO" otherwise. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes", and "YES" will all be recognized as positive answer).

NoteIn the first query, you can perform two operations $$$s_1 = s_2$$$ (after it $$$s$$$ turns into "aabb") and $$$t_4 = t_3$$$ (after it $$$t$$$ turns into "aabb"). In the second query, the strings are equal initially, so the answer is "YES".In the third query, you can not make strings $$$s$$$ and $$$t$$$ equal. Therefore, the answer is "NO".

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	chomp;

	my %h;

	map { $h{ $_ } ++ } split //;

	my $ok = 0;

	$_ = <>;

	while( /./g ){
		exists $h{ $& } and $ok = 1;
		}

	print $ok ? "YES" : "NO";
	}


You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$)  — the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$.

If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them.

NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

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

	my( $n, $m ) = split;

	my @ans;

	my $ok = 1;

	for my $i ( 1 .. $n ){
		@_ = split ' ', <>;

		my @A = ( 3, ( 4 ) x ( $m - 2 ), 3 );

		if( $i == 1 || $i == $n ){
			map $_ -= 1, @A;
			}

		for my $j ( 0 .. $m - 1 ){
			$_[ $j ] > $A[ $j ] and $ok = 0;
			last if not $ok;
			}

		push @ans, [ @A ];
		}

	if( $ok ){
		print "YES";
		print "@{ $_ }" for @ans;
		}
	else{
		print "NO";
		}
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

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

	my( $n, $m ) = split;

	my @ans;

	my $ok = 1;

	for my $i ( 1 .. $n ){
		@_ = split ' ', <>;

		my @A = ( 3, ( 4 ) x ( $m - 2 ), 3 );

		if( $i == 1 || $i == $n ){
			map $_ -= 2 , @A;
			}

		for my $j ( 0 .. $m - 1 ){
			$_[ $j ] > $A[ $j ] and $ok = 0;
			last if not $ok;
			}

		last if not $ok;

		push @ans, [ @A ];
		}

	if( $ok ){
		print "YES";
		print "@{ $_ }" for @ans;
		}
	else{
		print "NO";
		}
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

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

	my( $n, $m ) = split;

	my @ans;

	my $ok = 1;

	for my $i ( 1 .. $n ){
		@_ = split ' ', <>;

		my @A = ( 3, ( 4 ) x ( $m - 2 ), 3 );

		if( $i == 1 || $i == $n ){
			map $_ -= 1, @A;
			}

		for my $j ( 0 .. $m - 1 ){
			$_[ $j ] > $A[ $j ] and $ok = 0;
			last if not $ok;
			}

		last if not $ok;

		push @ans, [ @A ];
		}

	if( $ok ){
		print "YES";
		print "@{ $_ }" for @ans;
		}
	else{
		print "NO";
		}
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

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

	my( $n, $m ) = split;

	my @ans;

	my $ok = 1;

	for my $i ( 1 .. $n ){
		@_ = split ' ', <>;

		my $center = ( $i == 1 || $i == $n ) ? 3 : 4;

		my @A = ( 3, ( $center ) x ( $m - 2 ), 3 );

		for my $j ( 0 .. $m - 1 ){
			$_[ $j ] > $A[ $j ] and $ok = 0;
			last if not $ok;
			}

		last if not $ok;

		push @ans, [ @A ];
		}

	if( $ok ){
		print "YES";
		print "@{ $_ }" for @ans;
		}
	else{
		print "NO";
		}
	}


Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.Little Tommy has n lanterns and Big Banban has m lanterns. Tommy's lanterns have brightness a1, a2, ..., an, and Banban's have brightness b1, b2, ..., bm respectively.Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns.Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.You are asked to find the brightness of the chosen pair if both of them choose optimally.

The first line contains two space-separated integers n and m (2 ≤ n, m ≤ 50). The second line contains n space-separated integers a1, a2, ..., an. The third line contains m space-separated integers b1, b2, ..., bm. All the integers range from  - 109 to 109.

Print a single integer — the brightness of the chosen pair.

NoteIn the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself.

#!/usr/bin/perl

use warnings;

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

while(<>){
	my @A = split ' ', <>;
	my @B = split ' ', <>;

	my @M;

	for $i ( @A ){
		$max = -~0;
		for $j ( @B ){
			$max < $j * $i and $max = $j * $i;
			}
		push @M, $max;
		}

	print +( sort { $a <=> $b } @M )[ -2 ]
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	my @A = split ' ', <>;
	my @B = split ' ', <>;

	my $max = -~0;
	my $min = ~0;
	my $M;
	my $MM;

	for my $i ( 0 .. @A - 1 ){
		my $max = -~0;
		my $M;
		for my $j ( @A[ 0 .. $i - 1, $i + 1 .. @A - 1 ] ){
			for my $k ( @B ){
			#	print " $i $j $k";
				$max < $j * $k and do { $max = $j * $k; $M = "$j $k" };
				}
			}
		$min > $max and do { $min = $max; $MM = $M };
		}

	use bigint;
	print 0 + eval join ' * ', split ' ', $MM;
	no bigint;
	}

#!/usr/bin/perl

use warnings;
use strict;

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

while(<>){
	my @A = split ' ', <>;
	my @B = split ' ', <>;

	my $max = -~0;
	my $min = ~0;
	my $M;
	my @M;

	$debug and print "$max|$min";

	for my $i ( @A ){
		my $max = -~0;
		for my $j ( @B ){
			$debug and print " $i $j | ", $j * $i;
			$max < $j * $i and do { $max = $j * $i; $M = "$j $i" };
			}
		push @M, [ $max, $M ];
		}

	use bigint;
	print 0 + eval join ' * ', split ' ', join '', map $_->[ 1 ], ( sort { $a->[ 0 ] <=> $b->[ 0 ] } @M )[ -2 ];
	no bigint;
	}

#!/usr/bin/perl

use warnings;
use strict;

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

while(<>){
	my @A = split ' ', <>;
	my @B = split ' ', <>;

	my $max = -~0;
	my $min = ~0;
	my $M;
	my @M;

	$debug and print "$max|$min";

	for my $i ( @A ){
		my $max = -~0;
		for my $j ( @B ){
			$debug and print " $i $j | ", $j * $i;
			$max < $j * $i and do { $max = $j * $i; $M = "$j $i" };
			}
		push @M, [ $max, $M ];
		}

#	use bigint;
	print 0 + eval join ' * ', split ' ', join '', map $_->[ 1 ], ( sort { $a->[ 0 ] <=> $b->[ 0 ] } @M )[ -2 ];
#	no bigint;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	my @A = split ' ', <>;
	my @B = split ' ', <>;

	my $max = -~0;
	my $min = ~0;
	my $M;
	my $MM;

	for my $i ( 0 .. @A - 1 ){
		my $max = -~0;
		my $M;
		for my $j ( @A[ 0 .. $i - 1, $i + 1 .. @A - 1 ] ){
			for my $k ( @B ){
				print " $i $j $k";
				$max < $j * $k and do { $max = $j * $k; $M = "$j $k" };
				}
			}
		$min > $max and do { $min = $max; $MM = $M };
		}

	use bigint;
	print 0 + eval join ' * ', split ' ', $MM;
	no bigint;
	}


An undirected graph is called k-regular, if the degrees of all its vertices are equal k. An edge of a connected graph is called a bridge, if after removing it the graph is being split into two connected components.Build a connected undirected k-regular graph containing at least one bridge, or else state that such graph doesn't exist.

The single line of the input contains integer k (1 ≤ k ≤ 100) — the required degree of the vertices of the regular graph.

Print "NO" (without quotes), if such graph doesn't exist.  Otherwise, print "YES" in the first line and the description of any suitable graph in the next lines. The description of the made graph must start with numbers n and m — the number of vertices and edges respectively.  Each of the next m lines must contain two integers, a and b (1 ≤ a, b ≤ n, a ≠ b), that mean that there is an edge connecting the vertices a and b. A graph shouldn't contain multiple edges and edges that lead from a vertex to itself. A graph must be connected, the degrees of all vertices of the graph must be equal k. At least one edge of the graph must be a bridge. You can print the edges of the graph in any order. You can print the ends of each edge in any order. The constructed graph must contain at most 106 vertices and 106 edges (it is guaranteed that if at least one graph that meets the requirements exists, then there also exists the graph with at most 106 vertices and at most 106 edges).

NoteIn the sample from the statement there is a suitable graph consisting of two vertices, connected by a single edge.


A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters '+' and '1'. For example, sequences '(())()', '()', and '(()(()))' are balanced, while ')(', '(()', and '(()))(' are not.You are given a binary string $$$s$$$ of length $$$n$$$. Construct two balanced bracket sequences $$$a$$$ and $$$b$$$ of length $$$n$$$ such that for all $$$1\le i\le n$$$:   if $$$s_i=1$$$, then $$$a_i=b_i$$$  if $$$s_i=0$$$, then $$$a_i\ne b_i$$$ If it is impossible, you should report about it.

The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n\le 2\cdot 10^5$$$, $$$n$$$ is even). The next line contains a string $$$s$$$ of length $$$n$$$, consisting of characters 0 and 1. The sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.

If such two balanced bracked sequences exist, output "YES" on the first line, otherwise output "NO". You can print each letter in any case (upper or lower). If the answer is "YES", output the balanced bracket sequences $$$a$$$ and $$$b$$$ satisfying the conditions on the next two lines. If there are multiple solutions, you may print any.

NoteIn the first test case, $$$a=$$$"()()()" and $$$b=$$$"((()))". The characters are equal in positions $$$1$$$, $$$3$$$, $$$4$$$, and $$$6$$$, which are the exact same positions where $$$s_i=1$$$.In the second test case, $$$a=$$$"()()((()))" and $$$b=$$$"(())()()()". The characters are equal in positions $$$1$$$, $$$4$$$, $$$5$$$, $$$7$$$, $$$8$$$, $$$10$$$, which are the exact same positions where $$$s_i=1$$$.In the third test case, there is no solution.


One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.Your task is to write a program that will determine the required number of seconds t.

The first input line contains a single integer n — the number of cupboards in the kitchen (2 ≤ n ≤ 104). Then follow n lines, each containing two integers li and ri (0 ≤ li, ri ≤ 1). Number li equals one, if the left door of the i-th cupboard is opened, otherwise number li equals zero. Similarly, number ri equals one, if the right door of the i-th cupboard is opened, otherwise number ri equals zero. The numbers in the lines are separated by single spaces.

In the only output line print a single integer t — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

$n=<>;
while(<>=~/ /)
{
	$` and $i++;
	$'+0 and $j++;
	}
print (min($i,$n-$i)+min($j,$n-$j));

#***********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+) /;

$n=<>;
while(<>=~/ /)
{
	$` and $i++;
	$' and $j++;
	}
print (min($i,$n-$i)+min($j,$n-$j));

#***********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
}


The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect some of them.The Resistance already has measures in place that will, when the time is right, enable them to control every planet that is not remote. A planet is considered to be remote if it is connected to the rest of the planets only via a single hyperspace tunnel.How much work is there left to be done: that is, how many remote planets are there?

The first line of the input contains an integer N (2 ≤ N ≤ 1000) – the number of planets in the galaxy. The next N - 1 lines describe the hyperspace tunnels between the planets. Each of the N - 1 lines contains two space-separated integers u and v (1 ≤ u, v ≤ N) indicating that there is a bidirectional hyperspace tunnel between the planets u and v. It is guaranteed that every two planets are connected by a path of tunnels, and that each tunnel connects a different pair of planets.

A single integer denoting the number of remote planets.

NoteIn the first example, only planets 2, 3 and 5 are connected by a single tunnel.In the second example, the remote planets are 2 and 3.Note that this problem has only two versions – easy and medium.


You are given a positive integer $$$n$$$.The weight of a permutation $$$p_1, p_2, \ldots, p_n$$$ is the number of indices $$$1\le i\le n$$$ such that $$$i$$$ divides $$$p_i$$$. Find a permutation $$$p_1,p_2,\dots, p_n$$$ with the minimum possible weight (among all permutations of length $$$n$$$).A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 10^4$$$). The description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of permutation. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print a line containing $$$n$$$ integers $$$p_1, p_2,\dots, p_n$$$ so that the permutation $$$p$$$ has the minimum possible weight. If there are several possible answers, you can print any of them.

NoteIn the first test case, the only valid permutation is $$$p=[1]$$$. Its weight is $$$1$$$.In the second test case, one possible answer is the permutation $$$p=[2,1,4,3]$$$. One can check that $$$1$$$ divides $$$p_1$$$ and $$$i$$$ does not divide $$$p_i$$$ for $$$i=2,3,4$$$, so the weight of this permutation is $$$1$$$. It is impossible to find a permutation of length $$$4$$$ with a strictly smaller weight.

#!/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 = ( ($n) , ( 1 .. ($n-1) ));
  print ( join(' ',@a) . "\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;
  }
}


Even if it's a really easy question, she won't be able to answer it— Perfect Memento in Strict SenseCirno's perfect bitmasks classroom has just started!Cirno gave her students a positive integer $$$x$$$. As an assignment, her students need to find the minimum positive integer $$$y$$$, which satisfies the following two conditions:$$$$$$x\ \texttt{and}\ y > 0$$$$$$ $$$$$$x\ \texttt{xor}\ y > 0$$$$$$Where $$$\texttt{and}$$$ is the bitwise AND operation, and $$$\texttt{xor}$$$ is the bitwise XOR operation.Among the students was Mystia, who was truly baffled by all these new operators. Please help her!

The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of input test cases. For each test case, the only line of input contains one integer $$$x$$$ ($$$1 \leq x \leq 2^{30}$$$).

For each test case, print a single integer — the minimum number of $$$y$$$.


It is winter now, and Max decided it's about time he watered the garden.The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5 seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.  The garden from test 1. White colour denotes a garden bed without a tap, red colour — a garden bed with a tap.   The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour — a watered bed. Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!

The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 200). Then t test cases follow. The first line of each test case contains two integers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n) — the number of garden beds and water taps, respectively. Next line contains k integers xi (1 ≤ xi ≤ n) — the location of i-th water tap. It is guaranteed that for each  condition xi - 1 < xi holds. It is guaranteed that the sum of n over all test cases doesn't exceed 200. Note that in hacks you have to set t = 1.

For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.

NoteThe first example consists of 3 tests:  There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.  There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.  There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4.

#!/usr/bin/perl

use warnings;
use strict;

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

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

	my $x = 'x' x $n;

	@_ = split ' ', <>;

	substr $x, $_ - 1, 1, 'o' for @_;

	$debug and print $x;

	my $i = 1;

	while( $x =~ /x/ ){
		$x =~ s/x(?=o)|(?<=o)x/o/g;
		$debug and print " $x";
		$i ++;
		}

	print $i;
	}


There is a grid with $$$n$$$ rows and $$$m$$$ columns. Some cells are colored black, and the rest of the cells are colored white.In one operation, you can select some black cell and do exactly one of the following:   color all cells in its row black, or  color all cells in its column black. You are given two integers $$$r$$$ and $$$c$$$. Find the minimum number of operations required to make the cell in row $$$r$$$ and column $$$c$$$ black, or determine that it is impossible.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains four integers $$$n$$$, $$$m$$$, $$$r$$$, and $$$c$$$ ($$$1 \leq n, m \leq 50$$$; $$$1 \leq r \leq n$$$; $$$1 \leq c \leq m$$$) — the number of rows and the number of columns in the grid, and the row and column of the cell you need to turn black, respectively. Then $$$n$$$ lines follow, each containing $$$m$$$ characters. Each of these characters is either 'B' or 'W' — a black and a white cell, respectively.

For each test case, if it is impossible to make the cell in row $$$r$$$ and column $$$c$$$ black, output $$$-1$$$.  Otherwise, output a single integer — the minimum number of operations required to make the cell in row $$$r$$$ and column $$$c$$$ black.

9

3 5 1 4

WBWWW

BBBWB

WWBBB

4 3 2 1

BWW

BBW

WBB

WWB

2 3 2 2

WWW

WWW

2 2 1 1

WW

WB

5 9 5 9

WWWWWWWWW

WBWBWBBBW

WBBBWWBWW

WBWBWBBBW

WWWWWWWWW

1 1 1 1

B

1 1 1 1

W

1 2 1 1

WB

2 1 1 1

W

B

NoteThe first test case is pictured below.  We can take the black cell in row $$$1$$$ and column $$$2$$$, and make all cells in its row black. Therefore, the cell in row $$$1$$$ and column $$$4$$$ will become black.  In the second test case, the cell in row $$$2$$$ and column $$$1$$$ is already black.In the third test case, it is impossible to make the cell in row $$$2$$$ and column $$$2$$$ black.The fourth test case is pictured below.  We can take the black cell in row $$$2$$$ and column $$$2$$$ and make its column black.   Then, we can take the black cell in row $$$1$$$ and column $$$2$$$ and make its row black.   Therefore, the cell in row $$$1$$$ and column $$$1$$$ will become black.

#!/usr/bin/perl

use warnings;
use strict;

my $debug = 0;

$\ = $/;

<>;

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

	my( $n, $m, $r, $c ) = split;

	$debug and print "[$n, $m, $r, $c]";

	my %row;
	my %col;

	my $ans;

	for my $i ( 0 .. $n - 1 ){
		$_ = <>, chomp;

		next if defined $ans;

		m/B/ and $row{ $i } = 1;

		while( m/B/g ){
			$col{ $-[ 0 ] } = 1;

			if( $r - 1 == $i and $-[ 0 ] == $c - 1 ){
				$ans = 0;
				last;
				}
			}
		}

	if( defined $ans ){
		print $ans;
		}
	elsif( %row or %col ){
		if( $row{ $r - 1 } or $col{ $c - 1 } ){
			print 1;
			}
		else{
			print 2;
			}
		}
	else{
		print -1;
		}
	}


A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the left. Naturally, the semiknight cannot move beyond the limits of the chessboard.Petya put two semiknights on a standard chessboard. Petya simultaneously moves with both semiknights. The squares are rather large, so after some move the semiknights can meet, that is, they can end up in the same square. After the meeting the semiknights can move on, so it is possible that they meet again. Petya wonders if there is such sequence of moves when the semiknights meet. Petya considers some squares bad. That is, they do not suit for the meeting. The semiknights can move through these squares but their meetings in these squares don't count.Petya prepared multiple chess boards. Help Petya find out whether the semiknights can meet on some good square for each board.Please see the test case analysis.

The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed that matrix contains exactly 2 semiknights. The semiknight's squares are considered good for the meeting. The tests are separated by empty line.

For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.

NoteConsider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from square (8, 1) to square (6, 3). Then both semiknights go to (4, 5) but this square is bad, so they move together to square (2, 7).On the second board the semiknights will never meet.


The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north.You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate.

The first line contains single integer n (2 ≤ n ≤ 60 000) — the number of friends. The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 109) — the current coordinates of the friends, in meters. The third line contains n integers v1, v2, ..., vn (1 ≤ vi ≤ 109) — the maximum speeds of the friends, in meters per second.

Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road.  Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if  holds.

NoteIn the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.


Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the і-th row and j-th column that describes the result of the collision of the і-th and the j-th car:    - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix.  0: if no car turned over during the collision.  1: if only the i-th car turned over during the collision.  2: if only the j-th car turned over during the collision.  3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?

The first line contains integer n (1 ≤ n ≤ 100) — the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A.  It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.

Print the number of good cars and in the next line print their space-separated indices in the increasing order.

my $n = int<>;
my @ans;
(scalar(() = <> =~ / 1|3/) == 0) and push @ans, $_ for(1..$n);
print scalar @ans;
print "\n@ans\n";


Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false. Implication is written by using character '', and the arguments and the result of the implication are written as '0' (false) and '1' (true). According to the definition of the implication:   When a logical expression contains multiple implications, then when there are no brackets, it will be calculated from left to fight. For example,. When there are brackets, we first calculate the expression in brackets. For example,.For the given logical expression  determine if it is possible to place there brackets so that the value of a logical expression is false. If it is possible, your task is to find such an arrangement of brackets.

The first line contains integer n (1 ≤ n ≤ 100 000) — the number of arguments in a logical expression. The second line contains n numbers a1, a2, ..., an (), which means the values of arguments in the expression in the order they occur.

Print "NO" (without the quotes), if it is impossible to place brackets in the expression so that its value was equal to 0. Otherwise, print "YES" in the first line and the logical expression with the required arrangement of brackets in the second line. The expression should only contain characters '0', '1', '-' (character with ASCII code 45), '>' (character with ASCII code 62), '(' and ')'. Characters '-' and '>' can occur in an expression only paired like that: ("->") and represent implication. The total number of logical arguments (i.e. digits '0' and '1') in the expression must be equal to n. The order in which the digits follow in the expression from left to right must coincide with a1, a2, ..., an. The expression should be correct. More formally, a correct expression is determined as follows:   Expressions "0", "1" (without the quotes) are correct.  If v1, v2 are correct, then v1->v2 is a correct expression.  If v is a correct expression, then (v) is a correct expression.  The total number of characters in the resulting expression mustn't exceed 106. If there are multiple possible answers, you are allowed to print any of them.


Adilbek was assigned to a special project. For Adilbek it means that he has $$$n$$$ days to run a special program and provide its results. But there is a problem: the program needs to run for $$$d$$$ days to calculate the results.Fortunately, Adilbek can optimize the program. If he spends $$$x$$$ ($$$x$$$ is a non-negative integer) days optimizing the program, he will make the program run in $$$\left\lceil \frac{d}{x + 1} \right\rceil$$$ days ($$$\left\lceil a \right\rceil$$$ is the ceiling function: $$$\left\lceil 2.4 \right\rceil = 3$$$, $$$\left\lceil 2 \right\rceil = 2$$$). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to $$$x + \left\lceil \frac{d}{x + 1} \right\rceil$$$.Will Adilbek be able to provide the generated results in no more than $$$n$$$ days?

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of test cases. The next $$$T$$$ lines contain test cases – one per line. Each line contains two integers $$$n$$$ and $$$d$$$ ($$$1 \le n \le 10^9$$$, $$$1 \le d \le 10^9$$$) — the number of days before the deadline and the number of days the program runs.

Print $$$T$$$ answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in $$$n$$$ days or NO (case insensitive) otherwise.

NoteIn the first test case, Adilbek decides not to optimize the program at all, since $$$d \le n$$$.In the second test case, Adilbek can spend $$$1$$$ day optimizing the program and it will run $$$\left\lceil \frac{5}{2} \right\rceil = 3$$$ days. In total, he will spend $$$4$$$ days and will fit in the limit.In the third test case, it's impossible to fit in the limit. For example, if Adilbek will optimize the program $$$2$$$ days, it'll still work $$$\left\lceil \frac{11}{2+1} \right\rceil = 4$$$ days.


Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim.You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern.

First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters.

Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.

ross rachel
4
ross joey
rachel phoebe
phoebe monica
monica chandler

ross rachel
joey rachel
joey phoebe
joey monica
joey chandler

NoteIn first example, the killer starts with ross and rachel.   After day 1, ross is killed and joey appears.  After day 2, rachel is killed and phoebe appears.  After day 3, phoebe is killed and monica appears.  After day 4, monica is killed and chandler appears.

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

my $line = <>;
chomp($line);
my @init_pot = split (" ", $line);
print "$init_pot[0] $init_pot[1]\n";
my $num = <>;
chomp($num);

for (my $i=0;$i < $num;$i++) {
        my $line = <>;
        chomp($line);
        my @pot = split (" ", $line);
        if ($init_pot [0] eq $pot[0]) {
                $init_pot[0] = $pot[1];
        } elsif ($init_pot [1] eq $pot[0]) {
                $init_pot[1] = $pot[1];
        }

print "$init_pot[0] $init_pot[1]\n";
}

#!/usr/bin/perl

use warnings;
use strict;

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

while(<>){
	chomp;
	print;

	my %h = map { $_ => 1 } split ' ';

	for ( 1 .. <> ){
		@_ = split ' ', <>;
		exists $h{ $_ } ? delete $h{ $_ } : ($h{ $_ } = 1) for @_;

		print join ' ', keys %h;
		}

	$debug and print '-' x 10;
	}


In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this: If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part.  If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part. If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position. Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order?

The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data.

If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes).

$ch=<>;
chomp$ch;
$pos=index($ch,'.');

if(substr($ch,$pos-1,1) eq "9"){
print "GOTO Vasilisa.";
}
elsif(substr($ch,$pos+1,1) lt "5"){
print substr($ch,0,$pos);
}
else{
$car=substr($ch,$pos-1,1)+1;
$res= substr($ch,0,$pos-1).$car;
print $res;

}


Did you know you can download more RAM? There is a shop with $$$n$$$ different pieces of software that increase your RAM. The $$$i$$$-th RAM increasing software takes $$$a_i$$$ GB of memory to run (temporarily, once the program is done running, you get the RAM back), and gives you an additional $$$b_i$$$ GB of RAM (permanently). Each software can only be used once. Your PC currently has $$$k$$$ GB of RAM.Note that you can't use a RAM-increasing software if it takes more GB of RAM to use than what you currently have.Since RAM is the most important thing in the world, you wonder, what is the maximum possible amount of RAM achievable?

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains the integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100$$$, $$$1 \le k \le 1000$$$). Then two lines follow, each containing $$$n$$$ integers describing the arrays $$$a$$$ and $$$b$$$ ($$$1 \le a_i, b_i \le 1000$$$).

For each test case, output a single line containing the largest amount of RAM you can achieve.

NoteIn the first test case, you only have enough RAM to run the third software initially, but that increases your RAM to $$$20$$$ GB, which allows you to use the first software, increasing your RAM to $$$29$$$ GB. The only software left needs $$$30$$$ GB of RAM, so you have to stop here.In the second test case, you can use the first, second, fourth and fifth software that need only $$$1$$$ GB of RAM per software to run to increase your RAM to $$$5$$$ GB, and then use the last remaining one to increase your RAM to $$$6$$$ GB.In the third test case, all the software need more than $$$1$$$ GB of RAM to run, so the amount of RAM you have stays at $$$1$$$ GB.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my @A = split ' ', <>;
	my @B = split ' ', <>;

	my @C;

	while( @A ){
		push @C, [ ( pop @A ), ( pop @B ) ];
		}

	@C = sort { $a->[ 0 ] <=> $b->[ 0 ] } @C;

	while( @C and $C[ 0 ][ 0 ] <= $k ){
		my $c = shift @C;

		$k += $c->[ 1 ];
		}

	print $k;
	}