Two players decided to play one interesting card game.There is a deck of $$$n$$$ cards, with values from $$$1$$$ to $$$n$$$. The values of cards are pairwise different (this means that no two different cards have equal values). At the beginning of the game, the deck is completely distributed between players such that each player has at least one card. The game goes as follows: on each turn, each player chooses one of their cards (whichever they want) and puts on the table, so that the other player doesn't see which card they chose. After that, both cards are revealed, and the player, value of whose card was larger, takes both cards in his hand. Note that as all cards have different values, one of the cards will be strictly larger than the other one. Every card may be played any amount of times. The player loses if he doesn't have any cards.For example, suppose that $$$n = 5$$$, the first player has cards with values $$$2$$$ and $$$3$$$, and the second player has cards with values $$$1$$$, $$$4$$$, $$$5$$$. Then one possible flow of the game is:The first player chooses the card $$$3$$$. The second player chooses the card $$$1$$$. As $$$3>1$$$, the first player gets both cards. Now the first player has cards $$$1$$$, $$$2$$$, $$$3$$$, the second player has cards $$$4$$$, $$$5$$$.The first player chooses the card $$$3$$$. The second player chooses the card $$$4$$$. As $$$3<4$$$, the second player gets both cards. Now the first player has cards $$$1$$$, $$$2$$$. The second player has cards $$$3$$$, $$$4$$$, $$$5$$$.The first player chooses the card $$$1$$$. The second player chooses the card $$$3$$$. As $$$1<3$$$, the second player gets both cards. Now the first player has only the card $$$2$$$. The second player has cards $$$1$$$, $$$3$$$, $$$4$$$, $$$5$$$.The first player chooses the card $$$2$$$. The second player chooses the card $$$4$$$. As $$$2<4$$$, the second player gets both cards. Now the first player is out of cards and loses. Therefore, the second player wins.Who will win if both players are playing optimally? It can be shown that one of the players has a winning strategy.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The description of the test cases follows. The first line of each test case contains three integers $$$n$$$, $$$k_1$$$, $$$k_2$$$ ($$$2 \le n \le 100, 1 \le k_1 \le n - 1, 1 \le k_2 \le n - 1, k_1 + k_2 = n$$$) — the number of cards, number of cards owned by the first player and second player correspondingly. The second line of each test case contains $$$k_1$$$ integers $$$a_1, \dots, a_{k_1}$$$ ($$$1 \le a_i \le n$$$) — the values of cards of the first player. The third line of each test case contains $$$k_2$$$ integers $$$b_1, \dots, b_{k_2}$$$ ($$$1 \le b_i \le n$$$) — the values of cards of the second player. It is guaranteed that the values of all cards are different.

For each test case, output "YES" in a separate line, if the first player wins. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower).

NoteIn the first test case of the example, there is only one possible move for every player: the first player will put $$$2$$$, the second player will put $$$1$$$. $$$2>1$$$, so the first player will get both cards and will win.In the second test case of the example, it can be shown that it is the second player who has a winning strategy. One possible flow of the game is illustrated in the statement.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	chomp( my $s1 = <> );
	chomp( my $s2 = <> );

	print $s1 =~ /\b$n\b/ ? "YES" : "NO";
	}


Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.For each opponent Arya knows his schedule — whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.

The first line of the input contains two integers n and d (1 ≤ n, d ≤ 100) — the number of opponents and the number of days, respectively. The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.

Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents.

NoteIn the first and the second samples, Arya will beat all present opponents each of the d days.In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.

($n, $d) = split ' ', <>;
$d1 = '1' x $n;
for (<>) {
	chomp;
	$period .= ($_ eq $d1? '1': '0');
}
$maxlen = 0;
while ($period =~ /0+/g) {
	$len = length($&);
	$maxlen = $len > $maxlen? $len: $maxlen;
}
print $maxlen, "\n";


Try guessing the statement from this picture:   You are given a non-negative integer $$$d$$$. You have to find two non-negative real numbers $$$a$$$ and $$$b$$$ such that $$$a + b = d$$$ and $$$a \cdot b = d$$$.

The first line contains $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases. Each test case contains one integer $$$d$$$ $$$(0 \le d \le 10^3)$$$.

For each test print one line. If there is an answer for the $$$i$$$-th test, print "Y", and then the numbers $$$a$$$ and $$$b$$$. If there is no answer for the $$$i$$$-th test, print "N". Your answer will be considered correct if $$$|(a + b) - a \cdot b| \le 10^{-6}$$$ and $$$|(a + b) - d| \le 10^{-6}$$$.


One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles.At the end of the day there were n castles built by friends. Castles are numbered from 1 to n, and the height of the i-th castle is equal to hi. When friends were about to leave, Squidward noticed, that castles are not ordered by their height, and this looks ugly. Now friends are going to reorder the castles in a way to obtain that condition hi ≤ hi + 1 holds for all i from 1 to n - 1.Squidward suggested the following process of sorting castles:   Castles are split into blocks — groups of consecutive castles. Therefore the block from i to j will include castles i, i + 1, ..., j. A block may consist of a single castle.  The partitioning is chosen in such a way that every castle is a part of exactly one block.  Each block is sorted independently from other blocks, that is the sequence hi, hi + 1, ..., hj becomes sorted.  The partitioning should satisfy the condition that after each block is sorted, the sequence hi becomes sorted too. This may always be achieved by saying that the whole sequence is a single block. Even Patrick understands that increasing the number of blocks in partitioning will ease the sorting process. Now friends ask you to count the maximum possible number of blocks in a partitioning that satisfies all the above requirements.

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of castles Spongebob, Patrick and Squidward made from sand during the day. The next line contains n integers hi (1 ≤ hi ≤ 109). The i-th of these integers corresponds to the height of the i-th castle.

Print the maximum possible number of blocks in a valid partitioning.

NoteIn the first sample the partitioning looks like that: [1][2][3].  In the second sample the partitioning is: [2, 1][3, 2]


You have two binary strings $$$a$$$ and $$$b$$$ of length $$$n$$$. You would like to make all the elements of both strings equal to $$$0$$$. Unfortunately, you can modify the contents of these strings using only the following operation:  You choose two indices $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$);  For every $$$i$$$ that respects $$$l \le i \le r$$$, change $$$a_i$$$ to the opposite. That is, $$$a_i := 1 - a_i$$$;  For every $$$i$$$ that respects either $$$1 \le i < l$$$ or $$$r < i \le n$$$, change $$$b_i$$$ to the opposite. That is, $$$b_i := 1 - b_i$$$. Your task is to determine if this is possible, and if it is, to find such an appropriate chain of operations. The number of operations should not exceed $$$n + 5$$$. It can be proven that if such chain of operations exists, one exists with at most $$$n + 5$$$ operations.

Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of the strings. The second line of each test case contains a binary string $$$a$$$, consisting only of characters 0 and 1, of length $$$n$$$. The third line of each test case contains a binary string $$$b$$$, consisting only of characters 0 and 1, of length $$$n$$$. It is guaranteed that sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print first "YES" if it's possible to make all the elements of both strings equal to $$$0$$$. Otherwise, print "NO". If the answer is "YES", on the next line print a single integer $$$k$$$ ($$$0 \le k \le n + 5$$$) — the number of operations. Then $$$k$$$ lines follows, each contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$) — the description of the operation. If there are several correct answers, print any of them.

YES
1
2 2
NO
NO
YES
2
1 2
2 2
YES
2
1 1
2 3

NoteIn the first test case, we can perform one operation with $$$l = 2$$$ and $$$r = 2$$$. So $$$a_2 := 1 - 1 = 0$$$ and string $$$a$$$ became equal to 000. $$$b_1 := 1 - 1 = 0$$$, $$$b_3 := 1 - 1 = 0$$$ and string $$$b$$$ became equal to 000.In the second and in the third test cases, it can be proven that it's impossible to make all elements of both strings equal to $$$0$$$.In the fourth test case, we can perform an operation with $$$l = 1$$$ and $$$r = 2$$$, then string $$$a$$$ became equal to 01, and string $$$b$$$ doesn't change. Then we perform an operation with $$$l = 2$$$ and $$$r = 2$$$, then $$$a_2 := 1 - 1 = 0$$$ and $$$b_1 = 1 - 1 = 0$$$. So both of string $$$a$$$ and $$$b$$$ became equal to 00.In the fifth test case, we can perform an operation with $$$l = 1$$$ and $$$r = 1$$$. Then string $$$a$$$ became equal to 011 and string $$$b$$$ became equal to 100. Then we can perform an operation with $$$l = 2$$$ and $$$r = 3$$$, so both of string $$$a$$$ and $$$b$$$ became equal to 000.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	chomp;
	my $A = <>;
	chomp $A;
	my $B = <>;
	chomp $B;

	my $invA = $A =~ y/10/01/r;

	if( $A ne $B and $invA ne $B ){
		print 'NO';
		next;
		}

	print 'YES';

	my $cA = () = $A =~ m/1/g;

	my @ans;

	while( $A =~ m/1/g ){
		push @ans, join ' ', map $_ + 1, $-[0], $+[0] - 1;
		}

	if( $A eq $B ){
		if( $cA % 2 == 1 ){
			push @ans, "1 $_", "1 1", "2 $_";
			}
		else{
			;
			}
		}
	else{
		if( $cA % 2 == 1 ){
			;
			}
		else{
			push @ans, "1 $_", "1 1", "2 $_";
			}
		}

	print for @ans;
	}


Find the minimum area of a square land on which you can place two identical rectangular $$$a \times b$$$ houses. The sides of the houses should be parallel to the sides of the desired square land.Formally,   You are given two identical rectangles with side lengths $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 100$$$) — positive integers (you are given just the sizes, but not their positions).  Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square. Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding.    The picture shows a square that contains red and green rectangles.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) —the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$a$$$, $$$b$$$ ($$$1 \le a, b \le 100$$$) — side lengths of the rectangles.

Print $$$t$$$ answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions $$$a \times b$$$.

NoteBelow are the answers for the first two test cases:

my $t=readline STDIN;
chomp $t;
while ($t) {
    my $line= readline STDIN; chomp $line;
    my ($a,$b)=split / /,$line;

    if ($a<$b) { ($b,$a)=($a,$b); }
    if ($a==$b) { print (($a<<1)**2)}
    elsif ($b==1) { print (($a)**2); }
    elsif (($a/2) >= $b) {  print ($a**2); }
    else {
        print (($b<<1)**2);
    }
    print "\n";
    $t--;
}

#perl 5.26.1

$n = <STDIN>;
chomp $n;
@ip = <STDIN>;
chomp @ip;
foreach (@ip) {
    @test = split(' ', $_);
    if ($test[0] > $test[1]) {
        $dummy = 2*$test[1];
        if ($dummy > $test[0] || $dummy == $test[0]) {
            $ans = $dummy*$dummy;
            print "$ans\n";
        }else {
            $ans = $test[0]*$test[0];
            print "$ans\n";
        }
    }elsif ($test[0] < $test[1]) {
        $dummy = 2*$test[0];
        if ($dummy > $test[1] || $dummy == $test[1]) {
            $ans = $dummy*$dummy;
            print "$ans\n";
        }else {
            $ans = $test[1]*$test[1];
            print "$ans \n";
        }
    }else {
        $ans = (2*$test[0])*(2*$test[0]);
        print "$ans \n";
    }
}


At many competitions that have a word «cup» in its official name the winner is presented with an actual cup. This time the organizers of one unusual programming competition have decided to please the winner even more and to add a nameplate to the cup with the handle of the winner.The nameplate is to be rectangular and the text on it will be printed as a table of several rows and columns. Having some measurements done, the organizers have found out that the number $$$a$$$ of rows cannot be greater than $$$5$$$ while the number $$$b$$$ of columns cannot exceed $$$20$$$. Every cell of the table will contain either an asterisk («*») or a letter of user's handle.Furthermore, the organizers want the rows of the table to be uniform, which means that the number of asterisks used in different rows should differ by at most one (i.e. you can't have two asterisks in the first row and none in the second). The main goal, however, is to obtain the winner's handle precisely when reading the table from top to bottom and from left to right in every row (skipping asterisks).The organizers want for the nameplate to have as few rows as possible and among all valid tables with the minimum number of rows they want to choose the one that has the minimum number of columns.The winner is not yet determined so your task is to write a program that, given a certain handle, generates the necessary table.

The only line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$), comprised of uppercase and lowercase Latin letters,  — the handle of the winner.

In the first line output the minimum number $$$a$$$ of rows in the table and the minimum number $$$b$$$ of columns in an optimal table with rows. The following $$$a$$$ lines should contain $$$b$$$ characters each  — any valid table.

3 15
MyNameIsLifeIAm
ForeverByYourSi
deMyNameIsL*ife

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

while(<>){
	chomp;

	my $len = length;

	$debug and print $len;

	my $part = 1;

	while( $len / $part > 20 ){
		$part ++;
		}

	$debug and print $part;

	my $chunk = $len / $part;
	$debug and print $chunk;

	if( $chunk !~ /\./ ){
		;
		}
	else{
		my $plus = ( 1 + int $chunk ) * $part - $len;

		$debug and print $plus;

		my $int = int $chunk;

		s/.{$int}\K/ $plus -- > 0 ? '*' : '' /eg;
		$chunk = 1 + int $chunk;
		}

	$debug and print;

	@_ = /.{$chunk}/g;

	print join ' ', ~~ @_, $chunk;

	print for @_;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

while(<>){
	chomp;

	my $len = length;

	$debug and print $len;

	my $part = 1;

	while( $len / $part > 20 ){
		$part ++;
		}

	$debug and print $part;

	my $chunk = $len / $part;
	$debug and print $chunk;

	if( $chunk !~ /\./ ){
		;
		}
	else{
		my $plus = ( 1 + int $chunk ) * $part - $len;

		$debug and print $plus;

		my $int = int $chunk;

		$plus --, s/.{$int}\K/\*/ while $plus;
		$chunk = 1 + int $chunk;
		}

	$debug and print;

	@_ = /.{$chunk}/g;

	print join ' ', ~~ @_, $chunk;

	print for @_;
	}


Vasya has his favourite number $$$n$$$. He wants to split it to some non-zero digits. It means, that he wants to choose some digits $$$d_1, d_2, \ldots, d_k$$$, such that $$$1 \leq d_i \leq 9$$$ for all $$$i$$$ and $$$d_1 + d_2 + \ldots + d_k = n$$$.Vasya likes beauty in everything, so he wants to find any solution with the minimal possible number of different digits among $$$d_1, d_2, \ldots, d_k$$$. Help him!

The first line contains a single integer $$$n$$$ — the number that Vasya wants to split ($$$1 \leq n \leq 1000$$$).

In the first line print one integer $$$k$$$ — the number of digits in the partition. Note that $$$k$$$ must satisfy the inequality $$$1 \leq k \leq n$$$. In the next line print $$$k$$$ digits $$$d_1, d_2, \ldots, d_k$$$ separated by spaces. All digits must satisfy the inequalities $$$1 \leq d_i \leq 9$$$. You should find a partition of $$$n$$$ in which the number of different digits among $$$d_1, d_2, \ldots, d_k$$$ will be minimal possible among all partitions of $$$n$$$ into non-zero digits. Among such partitions, it is allowed to find any. It is guaranteed that there exists at least one partition of the number $$$n$$$ into digits.

NoteIn the first test, the number $$$1$$$ can be divided into $$$1$$$ digit equal to $$$1$$$.In the second test, there are $$$3$$$ partitions of the number $$$4$$$ into digits in which the number of different digits is $$$1$$$. This partitions are $$$[1, 1, 1, 1]$$$, $$$[2, 2]$$$ and $$$[4]$$$. Any of these partitions can be found. And, for example, dividing the number $$$4$$$ to the digits $$$[1, 1, 2]$$$ isn't an answer, because it has $$$2$$$ different digits, that isn't the minimum possible number.

use 5.20.1;
use strict;
my $n = <STDIN>;
say $n;
say "1" until ($n-- < 1);

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	chomp;
	print for $_, join ' ', ( 1 ) x $_;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my @cand;

	for my $cand ( 1 .. 100 ){
		my $sum = 0;
		for( @_ ){
			my $x = abs( $cand - $_ ) - 1;
			$x < 0 and $x = 0;
			$sum += $x;
			}
		push @cand, [ $cand, $sum ];
		}

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


Polycarp must pay exactly $$$n$$$ burles at the checkout. He has coins of two nominal values: $$$1$$$ burle and $$$2$$$ burles. Polycarp likes both kinds of coins equally. So he doesn't want to pay with more coins of one type than with the other.Thus, Polycarp wants to minimize the difference between the count of coins of $$$1$$$ burle and $$$2$$$ burles being used. Help him by determining two non-negative integer values $$$c_1$$$ and $$$c_2$$$ which are the number of coins of $$$1$$$ burle and $$$2$$$ burles, respectively, so that the total value of that number of coins is exactly $$$n$$$ (i. e. $$$c_1 + 2 \cdot c_2 = n$$$), and the absolute value of the difference between $$$c_1$$$ and $$$c_2$$$ is as little as possible (i. e. you must minimize $$$|c_1-c_2|$$$).

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line. This line contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the number of burles to be paid by Polycarp.

For each test case, output a separate line containing two integers $$$c_1$$$ and $$$c_2$$$ ($$$c_1, c_2 \ge 0$$$) separated by a space where $$$c_1$$$ is the number of coins of $$$1$$$ burle and $$$c_2$$$ is the number of coins of $$$2$$$ burles. If there are multiple optimal solutions, print any one.

NoteThe answer for the first test case is "334 333". The sum of the nominal values of all coins is $$$334 \cdot 1 + 333 \cdot 2 = 1000$$$, whereas $$$|334 - 333| = 1$$$. One can't get the better value because if $$$|c_1 - c_2| = 0$$$, then $$$c_1 = c_2$$$ and $$$c_1 \cdot 1 + c_1 \cdot 2 = 1000$$$, but then the value of $$$c_1$$$ isn't an integer.The answer for the second test case is "10 10". The sum of the nominal values is $$$10 \cdot 1 + 10 \cdot 2 = 30$$$ and $$$|10 - 10| = 0$$$, whereas there's no number having an absolute value less than $$$0$$$.


A and B are preparing themselves for programming contests.B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.Can you help B find out exactly what two errors he corrected?

The first line of the input contains integer n (3 ≤ n ≤ 105) — the initial number of compilation errors. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the errors the compiler displayed for the first time.  The third line contains n - 1 space-separated integers b1, b2, ..., bn - 1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.  The fourth line contains n - 2 space-separated integers с1, с2, ..., сn - 2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.

Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.

NoteIn the first test sample B first corrects the error number 8, then the error number 123.In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.

#!/usr/bin/env perl

use strict;
use warnings;
no warnings 'uninitialized';

my $N = <>+0;

my $line = <>;
chomp $line;
my @A = split ' ', $line;
my %S = ();
foreach my $x (@A) {
   ++$S{ int($x) };
}

$line = <>;
chomp $line;
my @B = split ' ', $line;
foreach my $x (@B) {
   --$S{ int($x) };
   delete $S{ int($x) } unless $S{ int($x) }
}
foreach my $k (keys(%S)) {
   print $k, "\n"
}

%S = ();
foreach my $x (@B) {
   ++$S{ int($x) };
}

$line = <>;
chomp $line;
my @C = split ' ', $line;
foreach my $x (@C) {
   --$S{ int($x) };
   delete $S{ int($x) } unless $S{ int($x) }
}
foreach my $k (keys(%S)) {
   print $k, "\n"
}

<>;
my %hash;
my %hash2;
$hash{int$_}++ for(split / /, <>);
$hash2{int$_}++, $hash{int$_}-- for(split / /, <>);
$hash2{int$_}-- for(split / /, <>);
print grep{$hash{$_} == 1} keys %hash;
print "\n";
print grep{$hash2{$_} == 1} keys %hash2;

chomp (my @s = split /\s+/, <STDIN>);
chomp (my @i = sort {$a <=> $b} split /\s+/, <STDIN>);
chomp (my @j = sort {$a <=> $b} split /\s+/, <STDIN>);
chomp (my @k = sort {$a <=> $b} split /\s+/, <STDIN>);

my $x;
for ($x = 0; $x < @j; $x++) {
  if ($i[$x] != $j[$x]) {
    printf "$i[$x]\n";
    last;
  }
}
printf "$i[$x]\n" if ($x == @j);
for ($x = 0; $x < @k; $x++) {
  if ($j[$x] != $k[$x]) {
    printf "$j[$x]\n";
    last;
  }
}
printf "$j[$x]\n" if ($x == @k);

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

sub get_missing{
    my ($total, $cur) = ($_[0], $_[1]);
    my %hash1; my %hash2;
    foreach(@{$total}){
        $hash1{$_} = 0 unless exists $hash1{$_};
        $hash2{$_} = 0 unless exists $hash2{$_};
        $hash1{$_}++;
    }
    foreach(@{$cur}){
        $hash2{$_}++;
    }
    foreach(keys %hash1){
        return $_ if $hash2{$_} < $hash1{$_};
    }
    return -1;
}
###############################

my $n = <>;
my @total = split ' ',<>;
my @cur = split ' ' , <>;
my $res1 = get_missing(\@total,\@cur);

@total = @cur;
@cur = split ' ' , <>;
my $res2 = get_missing(\@total,\@cur);

print "$res1\n$res2";

<>;
print join $/, map eval, (join '-', map {eval join '+', split} <>) =~ /(?=(\d+-\d+))/g

<>;
my $n = <>;
my %hash;
$hash{int$_}++ for(split / /, <>);
$hash{int$_}++ for(split / /, <>);
$hash{int$_}++ for(split / /, <>);
print grep{$hash{$_} == 1} keys %hash;
print "\n";
print grep{$hash{$_} == 2} keys %hash;


Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly k empty cells into walls so that all the remaining cells still formed a connected area. Help him.

The first line contains three integers n, m, k (1 ≤ n, m ≤ 500, 0 ≤ k < s), where n and m are the maze's height and width, correspondingly, k is the number of walls Pavel wants to add and letter s represents the number of empty cells in the original maze. Each of the next n lines contains m characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.

Print n lines containing m characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.

use strict;
#use warnings;
use 5.010;

my ($n, $m, $k) = split " ", <>;
my @board;
my ($s, $visited) = (0, 0);
my ($bi, $bj);

sub DFS {
    my ($i, $j) = @_;
    #say "in func ", $i, " ", $j;
    #say $visited, $s, $k;
    if($visited == $s - $k){
        return;
    }
    $board[$i][$j] = '0';
    $visited++;
    if($i > 0 && $board[$i-1][$j] eq '.') {
        DFS($i-1, $j);
    }
    if($i < $n - 1 && $board[$i+1][$j] eq '.') {
        DFS($i+1, $j);
    }
    if($j > 0 && $board[$i][$j-1] eq '.') {
        DFS($i, $j-1);
    }
    if($j < $m - 1 && $board[$i][$j+1] eq '.') {
        DFS($i, $j+1);
    }
    return;
}

for (<>) {
    chomp;
    push @board, [split //];
}

for my $row (@board) {
    for my $cell (@$row) {
        if($cell eq '.') {
            $s++;
        }
    }
}

for my $i (0..$n) {
    for my $j (0..$m) {
        if($board[$i][$j] eq '.') {
            ($bi, $bj) = ($i, $j);
        }
    }
}

#say $s, " ", $k;
#print_board();
DFS($bi, $bj);
#print_board();

for my $row (@board) {
    for my $cell (@$row) {
        if($cell eq '0') {
            $cell = '.';
        }
        elsif($cell eq '.') {
            $cell = 'X';
        }
    }
}

print_board();

sub print_board {
    for (@board) {
        say @$_;
    }
}

use strict;
#use warnings;
use 5.010;

my ($n, $m, $k) = split " ", <>;
my @board;
my ($s, $visited) = (0, 0);
my ($bi, $bj);

sub DFS {
    my ($i, $j) = @_;
    #say "in func ", $i, " ", $j;
    #say $visited, $s, $k;
    if($visited == $s - $k){
        return;
    }
    $board[$i][$j] = '0';
    $visited++;
    if($i > 0 && $board[$i-1][$j] eq '.') {
        DFS($i-1, $j);
    }
    if($i < $n - 1 && $board[$i+1][$j] eq '.') {
        DFS($i+1, $j);
    }
    if($j > 0 && $board[$i][$j-1] eq '.') {
        DFS($i, $j-1);
    }
    if($j < $m - 1 && $board[$i][$j+1] eq '.') {
        DFS($i, $j+1);
    }
    return;
}

for (<>) {
    chomp;
    push @board, [split //];
}

for my $row (@board) {
    for my $cell (@$row) {
        if($cell eq '.') {
            $s++;
        }
    }
}

for my $i (0..$n) {
    for my $j (0..$m) {
        if($board[$i][$j] eq '.') {
            ($bi, $bj) = ($i, $j);
        }
    }
}

#say $s, " ", $k;
#print_board();
DFS($bi, $bj);
#print_board();

for my $row (@board) {
    for my $cell (@$row) {
        if($cell ne '0') {
            $cell = '#';
        }
        else {
            $cell = '.';
        }
    }
}

print_board();

sub print_board {
    for (@board) {
        say @$_;
    }
}


Vasya has the square chessboard of size n × n and m rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there is a rook located in the cell, this cell is also under attack.You are given the positions of the board where Vasya will put rooks. For each rook you have to determine the number of cells which are not under attack after Vasya puts it on the board.

The first line of the input contains two integers n and m (1 ≤ n ≤ 100 000, 1 ≤ m ≤ min(100 000, n2)) — the size of the board and the number of rooks.  Each of the next m lines contains integers xi and yi (1 ≤ xi, yi ≤ n) — the number of the row and the number of the column where Vasya will put the i-th rook. Vasya puts rooks on the board in the order they appear in the input. It is guaranteed that any cell will contain no more than one rook.

Print m integer, the i-th of them should be equal to the number of cells that are not under attack after first i rooks are put.

NoteOn the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack.

#!/usr/bin/perl

use strict;

my ($n, $m) = split (" ",<STDIN>);
my (%rows,%cols,@result);
for (my $i=0;$i<$m;$i++){
    my ($row, $col) = split(" ",<STDIN>);
    $rows{$row} = 1;
    $cols{$col} = 1;
    push @result,(($n - keys(%rows))*($n - keys(%cols)));
}
print join " ", @result;


Tomorrow is a difficult day for Polycarp: he has to attend $$$a$$$ lectures and $$$b$$$ practical classes at the university! Since Polycarp is a diligent student, he is going to attend all of them.While preparing for the university, Polycarp wonders whether he can take enough writing implements to write all of the lectures and draw everything he has to during all of the practical classes. Polycarp writes lectures using a pen (he can't use a pencil to write lectures!); he can write down $$$c$$$ lectures using one pen, and after that it runs out of ink. During practical classes Polycarp draws blueprints with a pencil (he can't use a pen to draw blueprints!); one pencil is enough to draw all blueprints during $$$d$$$ practical classes, after which it is unusable.Polycarp's pencilcase can hold no more than $$$k$$$ writing implements, so if Polycarp wants to take $$$x$$$ pens and $$$y$$$ pencils, they will fit in the pencilcase if and only if $$$x + y \le k$$$.Now Polycarp wants to know how many pens and pencils should he take. Help him to determine it, or tell that his pencilcase doesn't have enough room for all the implements he needs tomorrow!Note that you don't have to minimize the number of writing implements (though their total number must not exceed $$$k$$$).

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow. Each test case is described by one line containing five integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ and $$$k$$$, separated by spaces ($$$1 \le a, b, c, d, k \le 100$$$) — the number of lectures Polycarp has to attend, the number of practical classes Polycarp has to attend, the number of lectures which can be written down using one pen, the number of practical classes for which one pencil is enough, and the number of writing implements that can fit into Polycarp's pencilcase, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.

For each test case, print the answer as follows: If the pencilcase can't hold enough writing implements to use them during all lectures and practical classes, print one integer $$$-1$$$. Otherwise, print two non-negative integers $$$x$$$ and $$$y$$$ — the number of pens and pencils Polycarp should put in his pencilcase. If there are multiple answers, print any of them. Note that you don't have to minimize the number of writing implements (though their total number must not exceed $$$k$$$).

NoteThere are many different answers for the first test case; $$$x = 7$$$, $$$y = 1$$$ is only one of them. For example, $$$x = 3$$$, $$$y = 1$$$ is also correct.$$$x = 1$$$, $$$y = 3$$$ is the only correct answer for the third test case.


Madoka is a very strange girl, and therefore she suddenly wondered how many pairs of integers $$$(a, b)$$$ exist, where $$$1 \leq a, b \leq n$$$, for which $$$\frac{\operatorname{lcm}(a, b)}{\operatorname{gcd}(a, b)} \leq 3$$$.In this problem, $$$\operatorname{gcd}(a, b)$$$ denotes the greatest common divisor of the numbers $$$a$$$ and $$$b$$$, and $$$\operatorname{lcm}(a, b)$$$ denotes the smallest common multiple of the numbers $$$a$$$ and $$$b$$$.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Description of the test cases follows. The first and the only line of each test case contains the integer $$$n$$$ ($$$1 \le n \le 10^8$$$).

For each test case output a single integer — the number of pairs of integers satisfying the condition.

NoteFor $$$n = 1$$$ there is exactly one pair of numbers — $$$(1, 1)$$$ and it fits.For $$$n = 2$$$, there are only $$$4$$$ pairs — $$$(1, 1)$$$, $$$(1, 2)$$$, $$$(2, 1)$$$, $$$(2, 2)$$$ and they all fit.For $$$n = 3$$$, all $$$9$$$ pair are suitable, except $$$(2, 3)$$$ and $$$(3, 2)$$$, since their $$$\operatorname{lcm}$$$ is $$$6$$$, and $$$\operatorname{gcd}$$$ is $$$1$$$, which doesn't fit the condition.


You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.

Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).

NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).

#!/bin/perl

use strict;

my $cases = +<>;

while ($cases--) {
  my $line = <>;

  my ($a, $b, $found1) = (0, 0, 0);
  for (my $i = 0; $i < length($line) - 1; $i++) {
    if (substr($line, $i, 1) eq '1') {
      $found1 = 1;
      $b = $a;
    } elsif ($found1) {
      $a++;
    }
  }
  print "$b\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 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

sub count_zero {
    my $str = shift;
    my @chars = split q{}, $str;
    my $count = 0;
    for (@chars) {
        $count++ if $_ eq '0';
    }
    return $count;
}

my $n = read_token;

for (1..$n) {
    my $s = read_line;
    while ($s and substr($s, 0, 1) eq '0') {
        $s = substr($s, 1);
    }
    if (!$s) {
        say 0;
        next;
    }

    while ($s and substr($s, length($s)-1, 1) eq '0') {
        $s = substr($s, 0, length($s)-1);
    }

    say count_zero($s);
}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	chomp;

	s/^0+//;
	s/0+$//;

	print length y/1//dr;
	}


Nastia has $$$2$$$ positive integers $$$A$$$ and $$$B$$$. She defines that:  The integer is good if it is divisible by $$$A \cdot B$$$;  Otherwise, the integer is nearly good, if it is divisible by $$$A$$$. For example, if $$$A = 6$$$ and $$$B = 4$$$, the integers $$$24$$$ and $$$72$$$ are good, the integers $$$6$$$, $$$660$$$ and $$$12$$$ are nearly good, the integers $$$16$$$, $$$7$$$ are neither good nor nearly good.Find $$$3$$$ different positive integers $$$x$$$, $$$y$$$, and $$$z$$$ such that exactly one of them is good and the other $$$2$$$ are nearly good, and $$$x + y = z$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) — the number of test cases. The first line of each test case contains two integers $$$A$$$ and $$$B$$$ ($$$1 \le A \le 10^6$$$, $$$1 \le B \le 10^6$$$) — numbers that Nastia has.

For each test case print:    "YES" and $$$3$$$ different positive integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^{18}$$$) such that exactly one of them is good and the other $$$2$$$ are nearly good, and $$$x + y = z$$$.  "NO" if no answer exists.  YES NO If there are multiple answers, print any.

NoteIn the first test case: $$$60$$$ — good number; $$$10$$$ and $$$50$$$ — nearly good numbers.In the second test case: $$$208$$$ — good number; $$$169$$$ and $$$39$$$ — nearly good numbers.In the third test case: $$$154$$$ — good number; $$$28$$$ and $$$182$$$ — nearly good numbers.

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

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

while( $test_case -- > 0 ){
  my ($A,$B) = map { $_ - 0 } split(/\s+/,<STDIN>);
  if( $B == 1 ){
    print "NO\n"; next;
  }
  #my $g = &gcd($A,$B);
  my $z = $B * $A;
  my $x = 1 * $A;
  my $y = ($B - 1) * $A;
  if( $B == 2 ){
    $z = 4 * $A;
    $x = $A;
    $y = 3 * $A;
  }
  print "YES\n";
  print "$x $y $z\n";
}

exit(0);

sub gcd { # gcd
  my ($x,$y) = @_;
  return $x if $y == 0;
  return &gcd($y, $x % $y);
}

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

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

while( $test_case -- > 0 ){
  my ($A,$B) = map { $_ - 0 } split(/\s+/,<STDIN>);
  if( $A % $B == 0 ){
    print "NO\n"; next;
  }
  my $z = $B * $A;
  my $x = 1 * $A;
  my $y = ($B - 1) * $A;
  if( $B == 2 ){
    $z = 4 * $A;
    $x = $A;
    $y = 3 * $A;
  }
  print "YES\n";
  print "$x $y $z\n";
}

exit(0);

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

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

while( $test_case -- > 0 ){
  my ($A,$B) = map { $_ - 0 } split(/\s+/,<STDIN>);
  if( $B == 1 ){
    print "NO\n"; next;
  }
  my $z = $B * $A;
  my $x = 1 * $A;
  my $y = ($B - 1) * $A;
  print "YES\n";
  print "$x $y $z\n";
}

exit(0);


You are given an array of integers $$$a$$$ of length $$$n$$$. The elements of the array can be either different or the same. Each element of the array is colored either blue or red. There are no unpainted elements in the array. One of the two operations described below can be applied to an array in a single step:  either you can select any blue element and decrease its value by $$$1$$$;  or you can select any red element and increase its value by $$$1$$$. Situations in which there are no elements of some color at all are also possible. For example, if the whole array is colored blue or red, one of the operations becomes unavailable.Determine whether it is possible to make $$$0$$$ or more steps such that the resulting array is a permutation of numbers from $$$1$$$ to $$$n$$$?In other words, check whether there exists a sequence of steps (possibly empty) such that after applying it, the array $$$a$$$ contains in some order all numbers from $$$1$$$ to $$$n$$$ (inclusive), each exactly once.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of input data sets in the test. The description of each set of input data consists of three lines. The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the length of the original array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — the array elements themselves. The third line has length $$$n$$$ and consists exclusively of the letters 'B' and/or 'R': $$$i$$$th character is 'B' if $$$a_i$$$ is colored blue, and is 'R' if colored red. It is guaranteed that the sum of $$$n$$$ over all input sets does not exceed $$$2 \cdot 10^5$$$.

Print $$$t$$$ lines, each of which contains the answer to the corresponding test case of the input. Print YES as an answer if the corresponding array can be transformed into a permutation, and NO otherwise. You can print the answer in any case (for example, the strings yEs, yes, Yes, and YES will be recognized as a positive answer).

NoteIn the first test case of the example, the following sequence of moves can be performed:  choose $$$i=3$$$, element $$$a_3=5$$$ is blue, so we decrease it, we get $$$a=[1,2,4,2]$$$;  choose $$$i=2$$$, element $$$a_2=2$$$ is red, so we increase it, we get $$$a=[1,3,4,2]$$$;  choose $$$i=3$$$, element $$$a_3=4$$$ is blue, so we decrease it, we get $$$a=[1,3,3,2]$$$;  choose $$$i=2$$$, element $$$a_2=2$$$ is red, so we increase it, we get $$$a=[1,4,3,2]$$$. We got that $$$a$$$ is a permutation. Hence the answer is YES.

my $line;
my @input1; my @input2;

$line = <STDIN>;
chomp($line);

my $line2; my $line3; my $len; my @data;
for(1..$line) {

        $len = <STDIN>;
        chomp($len);

        $line2 = <STDIN>;
        chomp($line2);
        $line3 = <STDIN>;
        chomp($line3);
        @input1 = (); @input2 = (); @data = ();

        @input1 = split / /, $line2;
        @input2 = split //, $line3;
        my $flag = 0;

        for (0..$len-1) {
                if( @input2[$_] eq "B") {
                        if (@input1[$_] < 1) {
                                $flag = 1; last;
                        }
                        if (@input1[$_] > $len){
                               @input1[$_] = $len;
                       }
                        $data[0][@input1[$_]]++;
                }
                if(@input2[$_] eq "R") {
                       if (@input1[$_] > $len){
                               $flag = 1; last;
                       }
                        if (@input1[$_] < 1) {
                               @input1[$_] = 1;
                       }
                        $data[1][@input1[$_]]++;
                }
        }
        my $s1 = 0; my $s2 = 0;
        for (my $i = 1; $i <= $len; $i++) {
                $s1 += $data[0][$i];
                if ($s1 > $i) {
                        $flag = 1; last;
                }
                $s2 += $data[1][$len - $i + 1];
                if ($s2 > $i) {
                        $flag = 1; last;
                }

        }
        if (!$flag) {print "YES", "\n";} else { print "NO", "\n"; }
}

my $line;
my @input1; my @input2;
my $key1 = 0; my $key2 = 0; my $key3 = 0; my $key4 = 0;
my $s = 0; my $c; my $result; my $i; my %h;

$line = <STDIN>;
chomp($line);
@input1 = split(' ', $line);
my $x;

for(1..@input1[0]) {
        $line = <STDIN>;
        chomp($line);
        my $len = $line;
        $line = <STDIN>;
        chomp($line);
        my @input1 = split(' ', $line);
        $line = <STDIN>;
        chomp($line);
        my @input2 = split('', $line);
        my @range;
        my $i = 0;
        my @test;
        my $flag = 0;
        foreach (@input2) {
                if ($_ eq "B") {
                        if (@input1[$i] < 1) {$flag = 1;last;}
                        if (@input1[$i] > $len) {@input1[$i] = $len;}
                        $range[$i][1] = @input1[$i];
                        $range[$i][0] = 1;
                        for (my $j = $range[$i][1]; $j <= $len; $j++) {
                                $test[$range[$i][0]][$j]++;
                        }
                } else {
                        if (@input1[$i] > $len) {$flag = 1;last;}
                        if (@input1[$i] < 1) {@input1[$i] = 1;}
                        $range[$i][0] = @input1[$i];
                        $range[$i][1] = $len;
                        for (my $j = 1; $j <= $range[$i][0]; $j++) {
                                $test[$j][$range[$i][1]]++;
                        }
                }
                $range[$i][2] = $range[$i][1] - $range[$i][0];
                if ($test[$range[$i][0]][$range[$i][1]] > $range[$i][2] + 1) { $flag = 1; last;}
                $i++;
        }

        if (!$flag) { print "YES", "\n";} else { print "NO", "\n"; }
}

my $line;
my @input1; my @input2;
my $key1 = 0; my $key2 = 0; my $key3 = 0; my $key4 = 0;
my $s = 0; my $c; my $result; my $i; my %h;

$line = <STDIN>;
chomp($line);
@input1 = split(' ', $line);
my $x;

for(1..@input1[0]) {
        $line = <STDIN>;
        chomp($line);
        my $len = $line;
        $line = <STDIN>;
        chomp($line);
        my @input1 = split(' ', $line);
        $line = <STDIN>;
        chomp($line);
        my @input2 = split('', $line);
        my @range;
        my $i = 0;
        my @test;
        my $flag = 0;
        foreach (@input2) {
                if ($_ eq "B") {
                        if (@input1[$i] < 1) {$flag = 1;last;}
                        if (@input1[$i] > $len) {@input1[$i] = $len;}
                        $range[$i][1] = @input1[$i];
                        $range[$i][0] = 1;
                        for (my $j = 1; $j <= $range[$i][1]; $j++) {
                                $test[$range[$i][0]][$j]++;
                        }
                } else {
                        if (@input1[$i] > $len) {$flag = 1;last;}
                        if (@input1[$i] < 1) {@input1[$i] = 1;}
                        $range[$i][0] = @input1[$i];
                        $range[$i][1] = $len;
                        for (my $j = 1; $j <= $range[$i][0]; $j++) {
                                $test[$j][$range[$i][1]]++;
                        }
                }
                $range[$i][2] = $range[$i][1] - $range[$i][0];
                if ($test[$range[$i][0]][$range[$i][1]] > $range[$i][2] + 1) { $flag = 1; last;}
                $i++;
        }

        if (!$flag) { print "YES", "\n";} else { print "NO", "\n"; }
}

my $line;
my @input1; my @input2;
my $key1 = 0; my $key2 = 0; my $key3 = 0; my $key4 = 0;
my $s = 0; my $c; my $result; my $i; my %h;

$line = <STDIN>;
chomp($line);
@input1 = split(' ', $line);
my $x;

for(1..@input1[0]) {
        $line = <STDIN>;
        chomp($line);
        my $len = $line;
        $line = <STDIN>;
        chomp($line);
        my @input1 = split(' ', $line);
        $line = <STDIN>;
        chomp($line);
        my @input2 = split('', $line);
        my @range;
        my $i = 0;
        my @test;
        my $flag = 0;
        foreach (@input2) {
                if ($_ eq "B") {
                        if (@input1[$i] < 1) {$flag = 1;last;}
                        if (@input1[$i] > $len) {@input1[$i] = $len;}
                        $range[$i][1] = @input1[$i];
                        $range[$i][0] = 1;
                        for (my $j = 0; $j <= $range[$i][1]; $j++) {
                                $test[$range[$i][0]][$j]++;
                        }
                } else {
                        if (@input1[$i] > $len) {$flag = 1;last;}
                        if (@input1[$i] < 1) {@input1[$i] = 1;}
                        $range[$i][0] = @input1[$i];
                        $range[$i][1] = $len;
                        for (my $j = $range[$i][0]; $j <= $len; $j++) {
                                $test[$j][$range[$i][1]]++;
                        }
                }
                $range[$i][2] = $range[$i][1] - $range[$i][0];
                if ($test[$range[$i][0]][$range[$i][1]] > $range[$i][2] + 1) { $flag = 1; last;}
                $i++;
        }

        if (!$flag) { print "YES", "\n";} else { print "NO", "\n"; }
}

my $line;
my @input1; my @input2;
my $key1 = 0; my $key2 = 0; my $key3 = 0; my $key4 = 0;
my $s = 0; my $c; my $result; my $i; my %h;

$line = <STDIN>;
chomp($line);
@input1 = split(' ', $line);
my $x;

for(1..@input1[0]) {
        $line = <STDIN>;
        chomp($line);
        my $len = $line;
        $line = <STDIN>;
        chomp($line);
        my @input1 = split(' ', $line);
        $line = <STDIN>;
        chomp($line);
        my @input2 = split('', $line);
        my @range;
        my $i = 0;
        my @test;
        my $flag = 0;
        foreach (@input2) {
                if ($_ eq "B") {
                        if (@input1[$i] < 1) {$flag = 1;last;}
                        if (@input1[$i] > $len) {@input1[$i] = $len;}
                        $range[$i][1] = @input1[$i];
                        $range[$i][0] = 1;
                        for (my $j = 0; $j <= $range[$i][1]; $j++) {
                                $test[$range[$i][0]][$j]++;
                        }
                } else {
                        if (@input1[$i] > $len) {$flag = 1;last;}
                        if (@input1[$i] < 1) {@input1[$i] = 1;}
                        $range[$i][0] = @input1[$i];
                        $range[$i][1] = $len;
                        for (my $j = $range[$i][0]; $j <= $len; $j++) {
                                $test[$j][$range[$i][1]];
                        }
                }
                $range[$i][2] = $range[$i][1] - $range[$i][0];
                if ($test[$range[$i][0]][$range[$i][1]] > $range[$i][2] + 1) { $flag = 1; last;}
                $i++;
        }

        if (!$flag) { print "YES", "\n";} else { print "NO", "\n"; }
}

use POSIX;
my $line;
my @input1; my @input2;
my $key1 = 0; my $key2 = 0; my $key3 = 0; my $key4 = 0;
my $s = 0; my $c; my $result; my $i; my %h;

$line = <STDIN>;
chomp($line);
@input1 = split(' ', $line);

for(1..@input1[0]) {
        $line = <STDIN>;
        chomp($line);
        my $len = $line;
        $line = <STDIN>;
        chomp($line);
        my @input1 = split(' ', $line);
        $line = <STDIN>;
        chomp($line);
        my @input2 = split('', $line);
        my @range = ();
        my $i = 0;
        my @test = ();
        my $flag = 0;
        foreach (@input2) {
                if ($_ eq "B") {
                        if (@input1[$i] < 1) {$flag = 1;last;}
                        if (@input1[$i] > $len) {@input1[$i] = $len;}
                        $range[$i][1] = @input1[$i];
                        $range[$i][0] = 1;
                } else {
                        if (@input1[$i] > $len) {$flag = 1;last;}
                        if (@input1[$i] < 1) {@input1[$i] = 1;}
                        $range[$i][0] = @input1[$i];
                        $range[$i][1] = $len;
                }
                $range[$i][2] = $range[$i][1] - $range[$i][0];
                $test[$range[$i][0]][$range[$i][1]]++;
                if ($test[$range[$i][0]][$range[$i][1]] > $range[$i][2] + 1) { $flag = 1; last;}
                $i++;
        }

        if (!$flag) { print "YES", "\n";} else { print "NO", "\n"; }
}
exit;

use POSIX;
my $line;
my @input1; my @input2;
my $key1 = 0; my $key2 = 0; my $key3 = 0; my $key4 = 0;
my $s = 0; my $c; my $result; my $i; my %h;

$line = <STDIN>;
chomp($line);
@input1 = split(' ', $line);

for(1..@input1[0]) {
        $line = <STDIN>;
        chomp($line);
        my $len = $line;
        $line = <STDIN>;
        chomp($line);
        my @input1 = split(' ', $line);
        $line = <STDIN>;
        chomp($line);
        my @input2 = split('', $line);
        my @range;
        my $i = 0;
        my @test;
        my $flag = 0;
        foreach (@input2) {
                if ($_ eq "B") {
                        if (@input1[$i] < 1) {$flag = 1;last;}
                        if (@input1[$i] > $len) {@input1[$i] = $len;}
                        $range[$i][1] = @input1[$i];
                        $range[$i][0] = 1;
                } else {
                        if (@input1[$i] > $len) {$flag = 1;last;}
                        if (@input1[$i] < 1) {@input1[$i] = 1;}
                        $range[$i][0] = @input1[$i];
                        $range[$i][1] = $len;
                }
                $range[$i][2] = $range[$i][1] - $range[$i][0];
                $test[$range[$i][0]][$range[$i][1]]++;
                if ($test[$range[$i][0]][$range[$i][1]] > $range[$i][2] + 1) { $flag = 1; last;}
                $i++;
        }

        if (!$flag) { print "YES", "\n";} else { print "NO", "\n"; }
}
exit;

use Class::Struct;
use List::Util qw(first);
use List::Util qw(min);
use List::Util qw(max);
use POSIX;
my $line;
my @input1; my @input2;
my $key1 = 0; my $key2 = 0; my $key3 = 0; my $key4 = 0;
my $s = 0; my $c; my $result; my $i; my %h;

$line = <STDIN>;
chomp($line);
@input1 = split(' ', $line);

for(1..@input1[0]) {
        $line = <STDIN>;
        chomp($line);
        my $len = $line;
        $line = <STDIN>;
        chomp($line);
        my @input1 = split(' ', $line);
        $line = <STDIN>;
        chomp($line);
        my @input2 = split('', $line);
        my @range;
        my $i = 0;
        foreach (@input2) {
                if ($_ eq "B") {
                        if (@input1[$i] < 1) {last;}
                        if (@input1[$i] > $len) {@input1[$i] = $len;}
                        $range[$i][1] = @input1[$i];
                        $range[$i][0] = 1;
                } else {
                        if (@input1[$i] > $len) {last;}
                        if (@input1[$i] < 1) {@input1[$i] = 1;}
                        $range[$i][0] = @input1[$i];
                        $range[$i][1] = $len;
                }
                $range[$i][2] = $range[$i][1] - $range[$i][0];
                $i++;
        }
        @range = sort {$a->[2] <=> $b->[2]} @range;
        @range = sort {$a->[0] <=> $b->[0]} @range;
        #for (my $i = 0; $i < $len; $i++) { print $range[$i][0], "-";print $range[$i][1], ": ";print $range[$i][2], "\n";}
        #each number should exist in the range o
        for (my $i = 0; $i < $len; $i++) {
                if ($i + 1 < $range[$i][0] || $i + 1 > $range[$i][1]) {
                        print "NO", "\n";
                        last;
                }
        }
        print "YES", "\n";
}

use Class::Struct;
use List::Util qw(first);
use List::Util qw(min);
use List::Util qw(max);
use POSIX;
my $line;
my @input1; my @input2;
my $key1 = 0; my $key2 = 0; my $key3 = 0; my $key4 = 0;
my $s = 0; my $c; my $result; my $i; my %h;

$line = <STDIN>;
chomp($line);
@input1 = split(' ', $line);

for(1..@input1[0]) {
        $line = <STDIN>;
        chomp($line);
        my $len = $line;
        $line = <STDIN>;
        chomp($line);
        my @input1 = split(' ', $line);
        $line = <STDIN>;
        chomp($line);
        my @input2 = split('', $line);
        my @range;
        my $i = 0;
        foreach (@input2) {
                if ($_ eq "B") {
                        if (@input1[$i] < 1) {last;}
                        if (@input1[$i] > $len) {@input1[$i] = $len;}
                        $range[$i][1] = @input1[$i];
                        $range[$i][0] = 1;
                } else {
                        if (@input1[$i] > $len) {last;}
                        if (@input1[$i] < 1) {@input1[$i] = 1;}
                        $range[$i][0] = @input1[$i];
                        $range[$i][1] = $len;
                }
                $range[$i][2] = $range[$i][1] - $range[$i][0];
                $i++;
        }
        @range = sort {$a->[2] <=> $b->[2]} @range;
        @range = sort {$a->[1] <=> $b->[1]} @range;
        @range = sort {$a->[0] <=> $b->[0]} @range;
        #for (my $i = 0; $i < $len; $i++) { print $range[$i][0], "-";print $range[$i][1], ": ";print $range[$i][2], "\n";}
        #each number should exist in the range o
        for (my $i = 0; $i < $len; $i++) {
                if ($i + 1 < $range[$i][0] || $i + 1 > $range[$i][1]) {
                        print "NO", "\n";
                        exit;
                }
        }
        print "YES", "\n";
}

use Class::Struct;
use List::Util qw(first);
use List::Util qw(min);
use List::Util qw(max);
use POSIX;
my $line;
my @input1; my @input2;
my $key1 = 0; my $key2 = 0; my $key3 = 0; my $key4 = 0;
my $s = 0; my $c; my $result; my $i; my %h;

$line = <STDIN>;
chomp($line);
@input1 = split(' ', $line);

for(1..@input1[0]) {
        $line = <STDIN>;
        chomp($line);
        my $len = $line;
        $line = <STDIN>;
        chomp($line);
        my @input1 = split(' ', $line);
        $line = <STDIN>;
        chomp($line);
        my @input2 = split('', $line);
        my @range;
        my $i = 0;
        foreach (@input2) {
                if ($_ eq "B") {
                        if (@input1[$i] < 1) {last;}
                        if (@input1[$i] > $len) {@input1[$i] = $len;}
                        $range[$i][1] = @input1[$i];
                        $range[$i][0] = 1;
                } else {
                        if (@input1[$i] > $len) {last;}
                        if (@input1[$i] < 1) {@input1[$i] = 1;}
                        $range[$i][0] = @input1[$i];
                        $range[$i][1] = $len;
                }
                $range[$i][2] = $range[$i][1] - $range[$i][0];
                $i++;
        }
        @range = sort {$a->[2] <=> $b->[2]} @range;
        @range = sort {$a->[1] <=> $b->[1]} @range;
        @range = sort {$a->[0] <=> $b->[0]} @range;
        for (my $i = 0; $i < $len; $i++) { print $range[$i][0], "-";print $range[$i][1], ": ";print $range[$i][2], "\n";}
        #each number should exist in the range o
        for (my $i = 0; $i < $len; $i++) {
                if ($i + 1 < $range[$i][0] || $i + 1 > $range[$i][1]) {
                        print "NO", "\n";
                        exit;
                }
        }
        print "YES", "\n";
}

        use Class::Struct;
        use List::Util qw(first);
        use List::Util qw(min);
        use List::Util qw(max);
        use POSIX;
        my $line;
        my @input1; my @input2;
        my $key1 = 0; my $key2 = 0; my $key3 = 0; my $key4 = 0;
        my $s = 0; my $c; my $result; my $i; my %h;

        $line = <STDIN>;
        chomp($line);
        @input1 = split(' ', $line);

        for(1..@input1[0]) {
                $line = <STDIN>;
                chomp($line);
                my $len = $line;
                $line = <STDIN>;
                chomp($line);
                my @input1 = split(' ', $line);
                $line = <STDIN>;
                chomp($line);
                my @input2 = split('', $line);
                my @range;
                my $i = 0;
                foreach (@input2) {
                        if ($_ eq "B") {
                                $range[$i][1] = @input1[$i];
                                $range[$i][0] = 1;
                        } else {
                                $range[$i][0] = @input1[$i];
                                $range[$i][1] = $len;
                        }
                        $range[$i][2] = $range[$i][1] - $range[$i][0];
                        $i++;
                }
                @range = sort {$a->[2] <=> $b->[2]} @range;
                @range = sort {$a->[0] <=> $b->[0]} @range;
                #for (my $i = 0; $i < $len; $i++) { print $range[$i][0], "-";print $range[$i][1], ": ";print $range[$i][2], "\n";}
                #each number should exist in the range o
                my $flag = 0;
                for (my $i = 0; $i < $len; $i++) {
                        if ($i + 1 < $range[$i][0] || $i + 1 > $range[$i][1]) {
                                print "NO", "\n";
                                $flag = 1;
                                last;
                        }
                }
                if (!$flag) {print "YES", "\n"};
        }

use Class::Struct;
use List::Util qw(first);
use List::Util qw(min);
use List::Util qw(max);
use POSIX;
my $line;
my @input1; my @input2;
my $key1 = 0; my $key2 = 0; my $key3 = 0; my $key4 = 0;
my $s = 0; my $c; my $result; my $i; my %h;

$line = <STDIN>;
chomp($line);
@input1 = split(' ', $line);

for(1..@input1[0]) {
        $line = <STDIN>;
        chomp($line);
        my $len = $line;
        $line = <STDIN>;
        chomp($line);
        my @input1 = split(' ', $line);
        $line = <STDIN>;
        chomp($line);
        my @input2 = split('', $line);
        my @range;
        my $i = 0;
        foreach (@input2) {
                if ($_ eq "B") {
                        $range[$i][1] = @input1[$i];
                        $range[$i][0] = 1;
                } else {
                        $range[$i][0] = @input1[$i];
                        $range[$i][1] = $len;
                }
                $range[$i][2] = $range[$i][1] - $range[$i][0];
                $i++;
        }
        @range = sort {$a->[2] <=> $b->[2]} @range;
        @range = sort {$a->[0] <=> $b->[0]} @range;
        #for (my $i = 0; $i < $len; $i++) { print $range[$i][0], "-";print $range[$i][1], ": ";print $range[$i][2], "\n";}
        #each number should exist in the range o
        for (my $i = 0; $i < $len; $i++) {
                if ($i + 1 < $range[$i][0] || $i + 1 > $range[$i][1]) {
                        print "NO", "\n";
                        exit;
                }
        }
        print "YES", "\n";
}

use Class::Struct;
use List::Util qw(first);
use List::Util qw(min);
use List::Util qw(max);
use POSIX;
my $line;
my @input1; my @input2;
my $key1 = 0; my $key2 = 0; my $key3 = 0; my $key4 = 0;
my $s = 0; my $c; my $result; my $i; my %h;

$line = <STDIN>;
chomp($line);
@input1 = split(' ', $line);

for(1..@input1[0]) {
        $line = <STDIN>;
        chomp($line);
        my $len = $line;
        $line = <STDIN>;
        chomp($line);
        my @input1 = split(' ', $line);
        $line = <STDIN>;
        chomp($line);
        my @input2 = split('', $line);
        my @range;
        my $i = 0;
        foreach (@input2) {
                if ($_ eq "B") {
                        $range[$i][1] = @input1[$i];
                        $range[$i][0] = 1;
                } else {
                        $range[$i][0] = @input1[$i];
                        $range[$i][1] = $len;
                }
                $range[$i][2] = $range[$i][1] - $range[$i][0];
                $i++;
        }
        @range = sort {$a->[2] <=> $b->[2]} @range;
        @range = sort {$a->[0] <=> $b->[0]} @range;
        #for (my $i = 0; $i < $len; $i++) { print $range[$i][0], "-";print $range[$i][1], ": ";print $range[$i][2], "\n";}
        #each number should exist in the range o
        for (my $i = 0; $i < $len; $i++) {
                if ($i + 1 < $range[$i][0] || $i + 1 > $range[$i][1]) {
                        print "NO";
                        exit;
                }
        }
        print "YES";
}


Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows:   $$$f(0) = a$$$;  $$$f(1) = b$$$;  $$$f(n) = f(n-1) \oplus f(n-2)$$$ when $$$n > 1$$$, where $$$\oplus$$$ denotes the bitwise XOR operation. You are given three integers $$$a$$$, $$$b$$$, and $$$n$$$, calculate $$$f(n)$$$.You have to answer for $$$T$$$ independent test cases.

The input contains one or more independent test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases. Each of the $$$T$$$ following lines contains three space-separated integers $$$a$$$, $$$b$$$, and $$$n$$$ ($$$0 \le a, b, n \le 10^9$$$) respectively.

NoteIn the first example, $$$f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$$$.

#!/usr/bin/env perl

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

chomp (my $line = <STDIN>);
my $t = $line;

for ( 1..$t ) {
    chomp ($line = <STDIN>);
    my ($a, $b, $n) = split q{ }, $line;
    my $c = int($a) ^ int($b);
    my $mod = $n % 3;
    if ( $mod == 0 ) {
        say $a;
    }
    elsif ( $mod == 1 ) {
        say $b;
    }
    else {
        say $c;
    }
}


Your company was appointed to lay new asphalt on the highway of length $$$n$$$. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing.Skipping the repair is necessary because of the climate. The climate in your region is periodical: there are $$$g$$$ days when the weather is good and if you lay new asphalt these days it becomes high-quality pavement; after that, the weather during the next $$$b$$$ days is bad, and if you lay new asphalt these days it becomes low-quality pavement; again $$$g$$$ good days, $$$b$$$ bad days and so on.You can be sure that you start repairing at the start of a good season, in other words, days $$$1, 2, \dots, g$$$ are good.You don't really care about the quality of the highway, you just want to make sure that at least half of the highway will have high-quality pavement. For example, if the $$$n = 5$$$ then at least $$$3$$$ units of the highway should have high quality; if $$$n = 4$$$ then at least $$$2$$$ units should have high quality.What is the minimum number of days is needed to finish the repair of the whole highway?

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Next $$$T$$$ lines contain test cases — one per line. Each line contains three integers $$$n$$$, $$$g$$$ and $$$b$$$ ($$$1 \le n, g, b \le 10^9$$$) — the length of the highway and the number of good and bad days respectively.

Print $$$T$$$ integers — one per test case. For each test case, print the minimum number of days required to repair the whole highway if at least half of it should have high quality.

NoteIn the first test case, you can just lay new asphalt each day, since days $$$1, 3, 5$$$ are good.In the second test case, you can also lay new asphalt each day, since days $$$1$$$-$$$8$$$ are good.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $half = int( $n / 2 ) + $n % 2;

	my $times = int( $half / $g );

	my $days = 0;

	$days = $times * ( $g + $B );

	if( $half % $g == 0 ){
		$days -= $B;
		}

	$days += $half % $g;

	$days < $n and $days = $n;

	print $days;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $half = int( $n / 2 ) + $n % 2;

	my $times = int( $half / $g );

	my $days = 0;

	$days = $times * ( $g + $B );

	if( $half % $g == 0 ){
		$days -= $B;
		}

	$days += $half % $g;

	print $days;
	}


Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (u, v) that belongs to the graph, u and v belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below.Dr. Evil gave Mahmoud and Ehab a tree consisting of n nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add?A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same .

The first line of input contains an integer n — the number of nodes in the tree (1 ≤ n ≤ 105). The next n - 1 lines contain integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the description of the edges of the tree. It's guaranteed that the given graph is a tree.

Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions.

NoteTree definition: https://en.wikipedia.org/wiki/Tree_(graph_theory)Bipartite graph definition: https://en.wikipedia.org/wiki/Bipartite_graphIn the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0.In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5).

#!/usr/bin/perl

use warnings;
use strict;

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

while(<>){

	my %h;

	map {
		my( $u, $v ) = split ' ', <>;
		$h{ $u }{ $v } = 1;
		$h{ $v }{ $u } = 1;
		} 1 .. $_ - 1;

	my $color = 'C';
	my @keys;
	( $keys[ 0 ] ) = sort keys %h;
	push @keys, $color;

	my @color;
	my $i = 0;
	while( @keys ){
		$debug and print "keys:[@keys]";
		my $key = shift @keys;
		$key eq $color and do {
			push @keys, $color if @keys and $keys[ -1 ] ne $color;
			$i ++;
			next;
			};
		$color[ $i % 2 ] ++;
		my @new_keys = keys %{ $h{ $key } };
		delete $h{ $_ }{ $key } for @new_keys;
		push @keys, @new_keys;
		}

	$debug and print "color:[@color]";
	print 1 - $_ + eval join ' * ', @color;
	}


You are given an array $$$A$$$, consisting of $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$, and an array $$$B$$$, consisting of $$$m$$$ positive integers $$$b_1, b_2, \dots, b_m$$$. Choose some element $$$a$$$ of $$$A$$$ and some element $$$b$$$ of $$$B$$$ such that $$$a+b$$$ doesn't belong to $$$A$$$ and doesn't belong to $$$B$$$. For example, if $$$A = [2, 1, 7]$$$ and $$$B = [1, 3, 4]$$$, we can choose $$$1$$$ from $$$A$$$ and $$$4$$$ from $$$B$$$, as number $$$5 = 1 + 4$$$ doesn't belong to $$$A$$$ and doesn't belong to $$$B$$$. However, we can't choose $$$2$$$ from $$$A$$$ and $$$1$$$ from $$$B$$$, as $$$3 = 2 + 1$$$ belongs to $$$B$$$.It can be shown that such a pair exists. If there are multiple answers, print any.Choose and print any such two numbers.

The first line contains one integer $$$n$$$ ($$$1\le n \le 100$$$) — the number of elements of $$$A$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 200$$$) — the elements of $$$A$$$. The third line contains one integer $$$m$$$ ($$$1\le m \le 100$$$) — the number of elements of $$$B$$$. The fourth line contains $$$m$$$ different integers $$$b_1, b_2, \dots, b_m$$$ ($$$1 \le b_i \le 200$$$) — the elements of $$$B$$$. It can be shown that the answer always exists.

Output two numbers $$$a$$$ and $$$b$$$ such that $$$a$$$ belongs to $$$A$$$, $$$b$$$ belongs to $$$B$$$, but $$$a+b$$$ doesn't belong to nor $$$A$$$ neither $$$B$$$. If there are multiple answers, print any.

NoteIn the first example, we can choose $$$20$$$ from array $$$[20]$$$ and $$$20$$$ from array $$$[10, 20]$$$. Number $$$40 = 20 + 20$$$ doesn't belong to any of those arrays. However, it is possible to choose $$$10$$$ from the second array too.In the second example, we can choose $$$3$$$ from array $$$[3, 2, 2]$$$ and $$$1$$$ from array $$$[1, 5, 7, 7, 9]$$$. Number $$$4 = 3 + 1$$$ doesn't belong to any of those arrays.In the third example, we can choose $$$1$$$ from array $$$[1, 3, 5, 7]$$$ and $$$1$$$ from array $$$[7, 5, 3, 1]$$$. Number $$$2 = 1 + 1$$$ doesn't belong to any of those arrays.

use strict;
use warnings;

use Data::Dumper;

sub main {

    my $in= *STDIN;
    my $q= <$in>; chomp($q);

    my $a= <$in>; chomp($a);
    my @a= split(' ', $a);

    $q= <$in>;

    my $b= <$in>; chomp($b);
    my @b= split(' ', $b);

    my @results;
    for my $x (@a) {
        for my $y (@b) {
            my $z= $x + $y;

            if(
                !(grep {/$z/} @a) &&
                !(grep {/$z/} @b)
            ) {
                print "$x $y";
                return;
            };
        }
    }

}

main() unless caller();

use strict;
use warnings;

use Data::Dumper;

sub main {

    my $in= *STDIN;
    my $q= <$in>; chomp($q);

    my $a= <$in>; chomp($a);
    my @a= split(' ', $a);

    $q= <$in>;

    my $b= <$in>; chomp($b);
    my @b= split(' ', $b);

    my @results;
    for my $x (@a) {
        for my $y (@b) {
            my $z= $x + $y;

            unless(
                grep {/$z/} @a &&
                grep {/$z/} @b
            ) {
                print "$x $y";
                return;
            };
        }
    }

}

main() unless caller();


The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.

The first line contains integer n (2 ≤ n ≤ 300) — the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 300). It is guaranteed that at least one ai is positive.

Print the sequence that consists of k (1 ≤ k ≤ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.

$n = <>;
$line = <>;
@list = split(/\s/, $line);
$total = 0;
foreach $x (@list) {
    $total += $x;
}
$i = 0;
$len = $n - 1;
$dir = 1;
while ($total) {
    if ($list[$i]) {
        $list[$i] -= 1;
        $total -= 1;
        print 'P';
    }
    if ($i == 0) {
        $dir = 1;
    }
    elsif ($i == $len) {
        $dir = -1;
    }
    $i += $dir;
    if ($dir > 0) {print 'R';}
    else {print 'L';}
}


We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers. For each of them determine whether it is Т-prime or not.

The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.

Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't.

NoteThe given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".


Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:   Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).  For any two indices i and j (i < j), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.

The input contains a single integer: n (1 ≤ n ≤ 105).

Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one.

use warnings;
use strict;

my $n = <>;
print join " ", $n..$n*2-1;

use warnings;

my $n = <STDIN>;

for (my $i = 1e+6; $i < 1e+6 + $n; $i++) {
    print $i . " ";
}

#!/usr/bin/perl

use strict;

my $n = <>;

print join " ", $n .. $n * 2 - 1;

use warnings;

my $n = <STDIN>;

for (my $i = 1e+7; $i < 1e+7 + $n; $i++) {
    print $i . " ";
}


Ivan wants to play a game with you. He picked some string $$$s$$$ of length $$$n$$$ consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from $$$1$$$ to $$$n-1$$$), but he didn't tell you which strings are prefixes and which are suffixes.Ivan wants you to guess which of the given $$$2n-2$$$ strings are prefixes of the given string and which are suffixes. It may be impossible to guess the string Ivan picked (since multiple strings may give the same set of suffixes and prefixes), but Ivan will accept your answer if there is at least one string that is consistent with it. Let the game begin!

The first line of the input contains one integer number $$$n$$$ ($$$2 \le n \le 100$$$) — the length of the guessed string $$$s$$$. The next $$$2n-2$$$ lines are contain prefixes and suffixes, one per line. Each of them is the string of length from $$$1$$$ to $$$n-1$$$ consisting only of lowercase Latin letters. They can be given in arbitrary order. It is guaranteed that there are exactly $$$2$$$ strings of each length from $$$1$$$ to $$$n-1$$$. It is also guaranteed that these strings are prefixes and suffixes of some existing string of length $$$n$$$.

Print one string of length $$$2n-2$$$ — the string consisting only of characters 'P' and 'S'. The number of characters 'P' should be equal to the number of characters 'S'. The $$$i$$$-th character of this string should be 'P' if the $$$i$$$-th of the input strings is the prefix and 'S' otherwise. If there are several possible answers, you can print any.

NoteThe only string which Ivan can guess in the first example is "ababa".The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable.In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP" is also acceptable.

#!usr/bin/perl

use strict;
use warnings;

<> =~ m/(d+)/;
my $n = $1;

my @inputlog = ();
my @flaglog = ();
my @log = ();

my @pairrefs = (["", ""]);
while (<>) {
	chomp;
	push @inputlog, $_;
	unless (defined $pairrefs[length]) {
		$pairrefs[length] = [$_];
		push @flaglog, "first-in-its-length";
	} else {
		push @{$pairrefs[length]}, $_;
		push @flaglog, "second-in-its-length";
	}
}

#print "- @{$pairrefs[0]}\n";
#print "- @{$pairrefs[1]}\n";
#print "- @{$pairrefs[2]}\n";
#print "- @{$pairrefs[3]}\n";

#my @pairrefs2 = (["e", "k"], ["te", "ko"], ["kor", "rte"], ["orte", "kort"]);

my @prefs = ("");
my @suffs = ("");

my $flag = "prefix-suffox-order";

if ($flag eq "prefix-suffox-order") {
	my $length = 0;
	@log = ("-");
	foreach my $pairref (@pairrefs) {
		my ($string1, $string2) = @$pairref; #print "$string1 | $string2\n";

		if ($length > 0) {
			my $previously = $length - 1;
			if (is_prefix_of($prefs[$previously], $string1) && is_suffix_of($suffs[$previously], $string2)) {
				$prefs[$length] = $string1;
				$suffs[$length] = $string2;
				$log[$length] = "PS";
			} elsif (is_prefix_of($prefs[$previously], $string2) && is_suffix_of($suffs[$previously], $string1)) {
				$prefs[$length] = $string2;
				$suffs[$length] = $string1;
				$log[$length] = "SP";
			} else {
				$flag = "suffix-prefix-order";
				last;
			}
		}
		$length++;
	}
}

if ($flag eq "suffix-prefix-order") {
	my $length = 0;
	@log = ("-");
	foreach my $pairref (@pairrefs) {
		my ($string1, $string2) = @$pairref; #print "$string1 | $string2\n";

		if ($length > 0) {
			my $previously = $length - 1;
			if (is_prefix_of($prefs[$previously], $string2) && is_suffix_of($suffs[$previously], $string1)) {
				$prefs[$length] = $string2;
				$suffs[$length] = $string1;
				push @log, "SP";
			} elsif (is_prefix_of($prefs[$previously], $string1) && is_suffix_of($suffs[$previously], $string2)) {
				$prefs[$length] = $string1;
				$suffs[$length] = $string2;
				push @log, "PS";
			} else {
				$flag = "prefix-suffix-order";
				last;
			}
		}
		$length++;
	}
}

#print "Prefs: "; print join ", ", @prefs; print "\n";
#print "Suffs: "; print join ", ", @suffs; print "\n";
#print "Order: $flag\n";
#print "Log: @log\n";

#print "Result: ";
foreach my $i (keys @inputlog) {
	my $length = length $inputlog[$i];
	if ($flaglog[$i] eq 'first-in-its-length') {
		print substr($log[$length], 0, 1);
	} else {
		print substr($log[$length], 1, 1);
	}
}
print "\n";

sub is_prefix_of {
	my ($part, $whole) = @_;
	return (substr $whole, 0, length $part) eq $part;
}

sub is_suffix_of {
	my ($part, $whole) = @_;
	return 1 if $part eq "";
	return (substr $whole, -length $part) eq $part;
}

#!usr/bin/perl

use strict;
use warnings;

<> =~ m/(d+)/;
my $n = $1;

my @inputlog = ();
my @flaglog = ();
my @log = ();

my @pairrefs = (["", ""]);
while (<>) {
	chomp;
	push @inputlog, $_;
	unless (defined $pairrefs[length]) {
		$pairrefs[length] = [$_];
		push @flaglog, "first-in-its-length";
	} else {
		push @{$pairrefs[length]}, $_;
		push @flaglog, "second-in-its-length";
	}
}

#print "- @{$pairrefs[0]}\n";
#print "- @{$pairrefs[1]}\n";
#print "- @{$pairrefs[2]}\n";
#print "- @{$pairrefs[3]}\n";

#my @pairrefs2 = (["e", "k"], ["te", "ko"], ["kor", "rte"], ["orte", "kort"]);

my @prefs = ("");
my @suffs = ("");

my $flag = "prefix-suffox-order";

if ($flag eq "prefix-suffox-order") {
	my $length = 0;
	@log = ("-");
	foreach my $pairref (@pairrefs) {
		my ($string1, $string2) = @$pairref; #print "$string1 | $string2\n";

		if ($length > 0) {
			my $previously = $length - 1;
			if (is_prefix_of($prefs[$previously], $string1) && is_suffix_of($suffs[$previously], $string2)) {
				$prefs[$length] = $string1;
				$suffs[$length] = $string2;
				$log[$length] = "PS";
			} elsif (is_prefix_of($prefs[$previously], $string2) && is_suffix_of($suffs[$previously], $string1)) {
				$prefs[$length] = $string2;
				$suffs[$length] = $string1;
				$log[$length] = "SP";
			} else {
				$flag = "suffix-prefix-order";
				last;
			}
		}
		$length++;
	}
}

if ($flag eq "suffix-prefix-order") {
	my $length = 0;
	@log = ("-");
	foreach my $pairref (@pairrefs) {
		my ($string1, $string2) = @$pairref; print "$string1 | $string2\n";

		if ($length > 0) {
			my $previously = $length - 1;
			if (is_prefix_of($prefs[$previously], $string2) && is_suffix_of($suffs[$previously], $string1)) {
				$prefs[$length] = $string2;
				$suffs[$length] = $string1;
				push @log, "SP";
			} elsif (is_prefix_of($prefs[$previously], $string1) && is_suffix_of($suffs[$previously], $string2)) {
				$prefs[$length] = $string1;
				$suffs[$length] = $string2;
				push @log, "PS";
			} else {
				$flag = "prefix-suffix-order";
				last;
			}
		}
		$length++;
	}
}

#print "Prefs: "; print join ", ", @prefs; print "\n";
#print "Suffs: "; print join ", ", @suffs; print "\n";
#print "Order: $flag\n";
#print "Log: @log\n";

#print "Result: ";
foreach my $i (keys @inputlog) {
	my $length = length $inputlog[$i];
	if ($flaglog[$i] eq 'first-in-its-length') {
		print substr($log[$length], 0, 1);
	} else {
		print substr($log[$length], 1, 1);
	}
}
print "\n";

sub is_prefix_of {
	my ($part, $whole) = @_;
	return (substr $whole, 0, length $part) eq $part;
}

sub is_suffix_of {
	my ($part, $whole) = @_;
	return 1 if $part eq "";
	return (substr $whole, -length $part) eq $part;
}


At the school where Vasya is studying, preparations are underway for the graduation ceremony. One of the planned performances is a ball, which will be attended by pairs of boys and girls.Each class must present two couples to the ball. In Vasya's class, $$$a$$$ boys and $$$b$$$ girls wish to participate. But not all boys and not all girls are ready to dance in pairs.Formally, you know $$$k$$$ possible one-boy-one-girl pairs. You need to choose two of these pairs so that no person is in more than one pair.For example, if $$$a=3$$$, $$$b=4$$$, $$$k=4$$$ and the couples $$$(1, 2)$$$, $$$(1, 3)$$$, $$$(2, 2)$$$, $$$(3, 4)$$$ are ready to dance together (in each pair, the boy's number comes first, then the girl's number), then the following combinations of two pairs are possible (not all possible options are listed below):   $$$(1, 3)$$$ and $$$(2, 2)$$$;  $$$(3, 4)$$$ and $$$(1, 3)$$$; But the following combinations are not possible:   $$$(1, 3)$$$ and $$$(1, 2)$$$ — the first boy enters two pairs;  $$$(1, 2)$$$ and $$$(2, 2)$$$ — the second girl enters two pairs; Find the number of ways to select two pairs that match the condition above. Two ways are considered different if they consist of different pairs.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$k$$$ ($$$1 \le a, b, k \le 2 \cdot 10^5$$$) — the number of boys and girls in the class and the number of couples ready to dance together. The second line of each test case contains $$$k$$$ integers $$$a_1, a_2, \ldots a_k$$$. ($$$1 \le a_i \le a$$$), where $$$a_i$$$ is the number of the boy in the pair with the number $$$i$$$. The third line of each test case contains $$$k$$$ integers $$$b_1, b_2, \ldots b_k$$$. ($$$1 \le b_i \le b$$$), where $$$b_i$$$ is the number of the girl in the pair with the number $$$i$$$. It is guaranteed that the sums of $$$a$$$, $$$b$$$, and $$$k$$$ over all test cases do not exceed $$$2 \cdot 10^5$$$. It is guaranteed that each pair is specified at most once in one test case.

For each test case, on a separate line print one integer — the number of ways to choose two pairs that match the condition above.

NoteIn the first test case, the following combinations of pairs fit:   $$$(1, 2)$$$ and $$$(3, 4)$$$;  $$$(1, 3)$$$ and $$$(2, 2)$$$;  $$$(1, 3)$$$ and $$$(3, 4)$$$;  $$$(2, 2)$$$ and $$$(3, 4)$$$. There is only one pair in the second test case.In the third test case, the following combinations of pairs fit:   $$$(1, 1)$$$ and $$$(2, 2)$$$;  $$$(1, 2)$$$ and $$$(2, 1)$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

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

	my %h;
	my %g;

	while( @A ){
		my $A = shift @A;
		my $B = shift @B;

		$h{ $A }{ $B } ++;
		$g{ $B }{ $A } ++;
		}

	my $cnt = 0;

	for my $key ( sort { $a <=> $b } keys %h ){
		my $k1 = $k - keys %{ $h{ $key } };

		for my $key_back ( sort { $a <=> $b } keys %{ $h{ $key } } ){
			$cnt += $k1 - ( keys %{ $g{ $key_back } } ) + 1;
			}
		}

	print $cnt / 2;
	}


Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a1... a|t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya"  "nastya"  "nastya"  "nastya"  "nastya"  "nastya"  "nastya".Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey.It is guaranteed that the word p can be obtained by removing the letters from word t.

The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a1, a2, ..., a|t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ ai ≤ |t|, all ai are distinct).

Print a single integer number, the maximum number of letters that Nastya can remove.

NoteIn the first sample test sequence of removing made by Nastya looks like this:"ababcba"  "ababcba"  "ababcba"  "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba".So, Nastya will remove only three letters.


Yelisey has an array $$$a$$$ of $$$n$$$ integers.If $$$a$$$ has length strictly greater than $$$1$$$, then Yelisei can apply an operation called minimum extraction to it:   First, Yelisei finds the minimal number $$$m$$$ in the array. If there are several identical minima, Yelisey can choose any of them.  Then the selected minimal element is removed from the array. After that, $$$m$$$ is subtracted from each remaining element. Thus, after each operation, the length of the array is reduced by $$$1$$$.For example, if $$$a = [1, 6, -4, -2, -4]$$$, then the minimum element in it is $$$a_3 = -4$$$, which means that after this operation the array will be equal to $$$a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$$$.Since Yelisey likes big numbers, he wants the numbers in the array $$$a$$$ to be as big as possible.Formally speaking, he wants to make the minimum of the numbers in array $$$a$$$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $$$1$$$.Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. In the description of each test case, the first line contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the original length of the array $$$a$$$. The second line of the description lists $$$n$$$ space-separated integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

Print $$$t$$$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $$$a$$$, which can be obtained by several applications of the described operation to it.

NoteIn the first example test case, the original length of the array $$$n = 1$$$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $$$a_1 = 10$$$.In the second set of input data, the array will always consist only of zeros.In the third set, the array will be changing as follows: $$$[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$$$. The minimum elements are highlighted with $$$\color{blue}{\text{blue}}$$$. The maximal one is $$$2$$$.In the fourth set, the array will be modified as $$$[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$$$. Similarly, the maximum of the minimum elements is $$$5$$$.

use List::Util qw(first);
use List::Util qw(min);
use List::Util qw(max);
use POSIX;
my $line;
my @input1; my @input2;
my $key1 = 0; my $key2 = 0; my $key3 = 0; my $key4 = 0;
my $s = 0; my $c; my $result; my $i; my %h;

$line = <STDIN>;
chomp($line);
@input1 = split(' ', $line);

#$line = <STDIN>;
#chomp($line);
#@input2 = split(' ', $line);

my $line2;

for(1..@input1[0]) {
        $s = <STDIN>;
        chomp($s);
        $line = <STDIN>;
        chomp($line);
        @input2 = split(' ', $line);
        @input2 = sort {$a <=> $b} @input2;
        $max = @input2[0];
        $c = 0;
        foreach (@input2) {
                $max = max($max, $_ - $c);
                $c = $_;
        }
        print $max, "\n";
}


Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.

The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.

Print the sought minimum number of people

#!/usr/bin/perl -w

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

chomp($_ = <>);
my ($max, $min, $count) = (0, 0, 0);
for my $i (split //) {
    if ($i eq '+') {
        ++$count;
    } else {
        --$count;
    }
    $max = max($max, $count);
    $min = min($min, $count);
}
print $max - $min, "\n";


Ehab loves number theory, but for some reason he hates the number $$$x$$$. Given an array $$$a$$$, find the length of its longest subarray such that the sum of its elements isn't divisible by $$$x$$$, or determine that such subarray doesn't exist.An array $$$a$$$ is a subarray of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

The first line contains an integer $$$t$$$ $$$(1 \le t \le 5)$$$ — the number of test cases you need to solve. The description of the test cases follows. The first line of each test case contains 2 integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le x \le 10^4$$$) — the number of elements in the array $$$a$$$ and the number that Ehab hates. The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$0 \le a_i \le 10^4$$$) — the elements of the array $$$a$$$.

For each testcase, print the length of the longest subarray whose sum isn't divisible by $$$x$$$. If there's no such subarray, print $$$-1$$$.

NoteIn the first test case, the subarray $$$[2,3]$$$ has sum of elements $$$5$$$, which isn't divisible by $$$3$$$.In the second test case, the sum of elements of the whole array is $$$6$$$, which isn't divisible by $$$4$$$.In the third test case, all subarrays have an even sum, so the answer is $$$-1$$$.