Phoenix has a string $$$s$$$ consisting of lowercase Latin letters. He wants to distribute all the letters of his string into $$$k$$$ non-empty strings $$$a_1, a_2, \dots, a_k$$$ such that every letter of $$$s$$$ goes to exactly one of the strings $$$a_i$$$. The strings $$$a_i$$$ do not need to be substrings of $$$s$$$. Phoenix can distribute letters of $$$s$$$ and rearrange the letters within each string $$$a_i$$$ however he wants.For example, if $$$s = $$$ baba and $$$k=2$$$, Phoenix may distribute the letters of his string in many ways, such as:   ba and ba  a and abb  ab and ab  aa and bb But these ways are invalid:   baa and ba  b and ba  baba and empty string ($$$a_i$$$ should be non-empty) Phoenix wants to distribute the letters of his string $$$s$$$ into $$$k$$$ strings $$$a_1, a_2, \dots, a_k$$$ to minimize the lexicographically maximum string among them, i. e. minimize $$$max(a_1, a_2, \dots, a_k)$$$. Help him find the optimal distribution and print the minimal possible value of $$$max(a_1, a_2, \dots, a_k)$$$.String $$$x$$$ is lexicographically less than string $$$y$$$ if either $$$x$$$ is a prefix of $$$y$$$ and $$$x \ne y$$$, or there exists an index $$$i$$$ ($$$1 \le i \le min(|x|, |y|))$$$ such that $$$x_i$$$ < $$$y_i$$$ and for every $$$j$$$ $$$(1 \le j < i)$$$ $$$x_j = y_j$$$. Here $$$|x|$$$ denotes the length of the string $$$x$$$.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case consists of two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^5$$$) — the length of string $$$s$$$ and the number of non-empty strings, into which Phoenix wants to distribute letters of $$$s$$$, respectively. The second line of each test case contains a string $$$s$$$ of length $$$n$$$ consisting only of lowercase Latin letters. It is guaranteed that the sum of $$$n$$$ over all test cases is $$$\le 10^5$$$.

Print $$$t$$$ answers — one per test case. The $$$i$$$-th answer should be the minimal possible value of $$$max(a_1, a_2, \dots, a_k)$$$ in the $$$i$$$-th test case.

6
4 2
baba
5 2
baacb
5 3
baacb
5 3
aaaaa
6 4
aaxxzz
7 1
phoenix

NoteIn the first test case, one optimal solution is to distribute baba into ab and ab. In the second test case, one optimal solution is to distribute baacb into abbc and a.In the third test case, one optimal solution is to distribute baacb into ac, ab, and b.In the fourth test case, one optimal solution is to distribute aaaaa into aa, aa, and a.In the fifth test case, one optimal solution is to distribute aaxxzz into az, az, x, and x.In the sixth test case, one optimal solution is to distribute phoenix into ehinopx.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	$_ = <>, chomp;

	my %h;

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

	$_ = join '', sort split //;

	if( ( substr $_, 0, 1 ) x $k eq substr $_, 0, $k ){
		if( 2 < keys %h ){
			print substr $_, $k - 1;
			}
		elsif( 1 == keys %h ){
			print +( keys %h )[ 0 ] x ( int $n / $k + !!( $n % $k ) );
			}
		elsif( $h{ substr $_, 0 , 1 } == $k ){
			print +( substr $_, 0, 1 ) . substr( $_, $k, 1 ) x ( -1 + int $n / $k + !!( $n % $k ) );
			}
		else{
			print substr $_, $k - 1;
			}
		}
	else{
		print substr $_, $k - 1, 1;
		}

	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	$_ = <>, chomp;

	my %h;

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

	$_ = join '', sort split //;

	if( ( substr $_, 0, 1 ) x $k eq substr $_, 0, $k ){
		if( 2 < keys %h ){
			print substr $_, $k - 1;
			}
		elsif( 1 == keys %h ){
			print +( keys %h )[ 0 ] x ( int $n / $k + !!( $n % $k ) );
			}
		else{
			print +( substr $_, 0, 1 ) . substr( $_, $k, 1 ) x ( -1 + int $n / $k + !!( $n % $k ) );
			}
		}
	else{
		print substr $_, $k - 1, 1;
		}

	}


Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts its price will be bi.Not all of sellers are honest, so now some products could be more expensive than after a week of discounts.Igor decided that buy at least k of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all n items.

In the first line there are two positive integer numbers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104) — prices of items after discounts (i.e. after a week).

Print the minimal amount of money Igor will spend to buy all n items. Remember, he should buy at least k items right now.

NoteIn the first example Igor should buy item 3 paying 6. But items 1 and 2 he should buy after a week. He will pay 3 and 1 for them. So in total he will pay 6 + 3 + 1 = 10.In the second example Igor should buy right now items 1, 2, 4 and 5, paying for them 3, 4, 10 and 3, respectively. Item 3 he should buy after a week of discounts, he will pay 5 for it. In total he will spend 3 + 4 + 10 + 3 + 5 = 25.


Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on.

The first line of the input contains integers n and m (1 ≤ n, m ≤ 100) — the number of buttons and the number of bulbs respectively.  Each of the next n lines contains xi (0 ≤ xi ≤ m) — the number of bulbs that are turned on by the i-th button, and then xi numbers yij (1 ≤ yij ≤ m) — the numbers of these bulbs.

If it's possible to turn on all m bulbs print "YES", otherwise print "NO".

NoteIn the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.


You are given an integer $$$n$$$. Check if $$$n$$$ has an odd divisor, greater than one (does there exist such a number $$$x$$$ ($$$x > 1$$$) that $$$n$$$ is divisible by $$$x$$$ and $$$x$$$ is odd).For example, if $$$n=6$$$, then there is $$$x=3$$$. If $$$n=4$$$, then such a number does not exist.

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 contains one integer $$$n$$$ ($$$2 \le n \le 10^{14}$$$). Please note, that the input for some test cases won't fit into $$$32$$$-bit integer type, so you should use at least $$$64$$$-bit integer type in your programming language.

For each test case, output on a separate line:    "YES" if $$$n$$$ has an odd divisor, greater than one;  "NO" otherwise.  You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	chomp;

	$_ = sprintf "%b", $_;

	my $ones = () = /1/g;

	print $ones == 1 ? "NO" : "YES";
	}


There is a special offer in Vasya's favourite supermarket: if the customer buys $$$a$$$ chocolate bars, he or she may take $$$b$$$ additional bars for free. This special offer can be used any number of times.Vasya currently has $$$s$$$ roubles, and he wants to get as many chocolate bars for free. Each chocolate bar costs $$$c$$$ roubles. Help Vasya to calculate the maximum possible number of chocolate bars he can get!

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of testcases. Each of the next $$$t$$$ lines contains four integers $$$s, a, b, c~(1 \le s, a, b, c \le 10^9)$$$ — the number of roubles Vasya has, the number of chocolate bars you have to buy to use the special offer, the number of bars you get for free, and the cost of one bar, respectively.

Print $$$t$$$ lines. $$$i$$$-th line should contain the maximum possible number of chocolate bars Vasya can get in $$$i$$$-th test.

NoteIn the first test of the example Vasya can buy $$$9$$$ bars, get $$$3$$$ for free, buy another bar, and so he will get $$$13$$$ bars.In the second test Vasya buys $$$1000000000$$$ bars and gets $$$1000000000000000000$$$ for free. So he has $$$1000000001000000000$$$ bars.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $cnt = 0;

	my $akc = int( $s / ( $A * $c ) );

	my $mod = $s % ( $A * $c );

#	print "$akc | $mod";

	$cnt += $akc * ( $A + $B );

	$cnt += int( $mod / $c );

	print $cnt;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $cnt = 0;

	my $akc = int( $s / ( $A * $c ) );

	my $mod = $s % ( $A * $c );

#	print "$akc | $mod";

	$cnt += $akc * ( $A + $B );

	$cnt += $mod;

	print $cnt;
	}


Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport. To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.Print the minimum cost Vladik has to pay to get to the olympiad.

The first line contains three integers n, a, and b (1 ≤ n ≤ 105, 1 ≤ a, b ≤ n) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.  The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.

Print single integer — the minimum cost Vladik has to pay to get to the olympiad.

NoteIn the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1. In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.

#!/usr/bin/perl

use strict;
use warnings;

my $tmp = <>;
$tmp =~ s/\s+$//;
my ($n, $fs, $sn) = split /\s+/, $tmp;

my $s = <>;
$s =~ s/\s+$//;

if (substr($s, $fs - 1, 1) eq substr($s, $sn - 1, 1)) {
    print "0";
} else {
    print "1";
}

use strict;

$,=" ";
my ($n,$ax,$bx)=split / /,<>;
chomp($n,$ax,$bx);
$ax--;
$bx--;
$n--;
my $str=<>;
chomp($str);
my @aa=split //,$str;

if($aa[$ax]==$aa[$bx]){
	print "0 \n";
}else{
	print "1 \n";
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $CA = substr $_, $A - 1, 1;
	my $CB = substr $_, $B - 1, 1;

	print do {
		if( abs( $CA - $CB ) == 1 ){
			1;
			}
		else{
			0;
			}
		};
	}

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

my ($n,$ax,$bx)=split / /,<>;
chomp($n,$ax,$bx);
$ax--;
$bx--;
$n--;
my $str=<>;
chomp($str);
my @aa=split //,$str;
my %b_cost;
my %a_cost;
for my $k(0..$n){
    $b_cost{$k}->[0]=$aa[$k]-$aa[$bx];
	$b_cost{$k}->[1]=abs($bx-$k);
}

if($b_cost{$ax}->[0]==0){
	print "0\n";
}
else{

for my $k (sort { $b_cost{$a}->[1] <=> $b_cost{$b}->[1]  } keys %b_cost){
if($b_cost{$k}->[0]==1){
	print $b_cost{$k}->[1] . "\n";
	last;
}
}
}

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

my ($n,$ax,$bx)=split / /,<>;
chomp($n,$ax,$bx);
$ax--;
$bx--;
$n--;
my $str=<>;
chomp($str);
my @aa=split //,$str;
my %b_cost;
my %a_cost;
for my $k(0..$n){
    $b_cost{$k}->[0]=abs($aa[$k]-$aa[$bx]);
	$b_cost{$k}->[1]=abs($bx-$k);
}

if($b_cost{$ax}->[0]==0){
	print "0\n";
}
else{
for my $k (sort { $b_cost{$a}->[1] <=> $b_cost{$b}->[1]  } keys %b_cost){
if($b_cost{$k}->[0]==1){
	print $b_cost{$k}->[1] . "\n";
	last;
}
}
}

use strict;

$,=" ";
my ($n,$ax,$bx)=split / /,<>;
chomp($n,$ax,$bx);
$ax--;
$bx--;
$n--;
my $str=<>;
chomp($str);
my @aa=split //,$str;

my $b_cost=0;
my $ans=10000000000;
if($aa[$ax]==$aa[$bx])
{
	print "0\n";
}
else
{
for my $k(0..$n){
$b_cost=0;
my $a_to_vertx=0;
my $b_to_vertx=0;
 if($aa[$k]==$aa[$ax]){
 	$a_to_vertx=0;
 }else{
 	$a_to_vertx=abs($ax-$k);
 }
 if($aa[$k]==$aa[$bx]){
 	$b_to_vertx=0;
 }else{
 	$b_to_vertx=abs($bx-$k);
 }
 #print $a_to_vertx,$b_to_vertx . "\n";
    $b_cost=$a_to_vertx+$b_to_vertx;
    $ans=min($b_cost,$ans);
}
print $ans . "\n";
}

sub min{
	return $_[0]>$_[1] ? $_[1] : $_[0];
}


Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime:  Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string.  Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows:  If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string.  If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s.

The first line contains a non-empty string s.  It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.

In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s.

NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this:  string "yxyxy" transforms into string "xyyxy";  string "xyyxy" transforms into string "xyxyy";  string "xyxyy" transforms into string "xxyyy";  string "xxyyy" transforms into string "xyy";  string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

$_=<>;
chomp;
@_=split//;
$_ eq'x'and $x++ for@_;
$y=@_-$x;
print (($x>$y?'x':'y')x($x+$y-min($x,$y)*2));

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

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

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

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

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

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

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

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

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

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

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

@_=split//,<>;
$_ eq'x'and $x++ for@_;
$y=@_-$x;
print (($x>$y?'x':'y')x($x+$y-min($x,$y)*2));

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

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

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

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

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

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

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

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

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

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

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

@_=split//,<>;chomp$_[@_-1];
$_ eq'x'and $x++ for@_;
$y=@_-$x;
print (($x>$y?'x':'y')x($x+$y-min($x,$y)*2));

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

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

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

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

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

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

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

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

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

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


For the New Year, Polycarp decided to send postcards to all his $$$n$$$ friends. He wants to make postcards with his own hands. For this purpose, he has a sheet of paper of size $$$w \times h$$$, which can be cut into pieces.Polycarp can cut any sheet of paper $$$w \times h$$$ that he has in only two cases:   If $$$w$$$ is even, then he can cut the sheet in half and get two sheets of size $$$\frac{w}{2} \times h$$$;  If $$$h$$$ is even, then he can cut the sheet in half and get two sheets of size $$$w \times \frac{h}{2}$$$; If $$$w$$$ and $$$h$$$ are even at the same time, then Polycarp can cut the sheet according to any of the rules above.After cutting a sheet of paper, the total number of sheets of paper is increased by $$$1$$$.Help Polycarp to find out if he can cut his sheet of size $$$w \times h$$$ at into $$$n$$$ or more pieces, using only the rules described above.

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 containing three integers $$$w$$$, $$$h$$$, $$$n$$$ ($$$1 \le w, h \le 10^4, 1 \le n \le 10^9$$$) — the width and height of the sheet Polycarp has and the number of friends he needs to send a postcard to.

For each test case, output on a separate line:    "YES", if it is possible to cut a sheet of size $$$w \times h$$$ into at least $$$n$$$ pieces;  "NO" otherwise.  You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).

NoteIn the first test case, you can first cut the $$$2 \times 2$$$ sheet into two $$$2 \times 1$$$ sheets, and then cut each of them into two more sheets. As a result, we get four sheets $$$1 \times 1$$$. We can choose any three of them and send them to our friends.In the second test case, a $$$3 \times 3$$$ sheet cannot be cut, so it is impossible to get two sheets.In the third test case, you can cut a $$$5 \times 10$$$ sheet into two $$$5 \times 5$$$ sheets.In the fourth test case, there is no need to cut the sheet, since we only need one sheet.In the fifth test case, you can first cut the $$$1 \times 4$$$ sheet into two $$$1 \times 2$$$ sheets, and then cut each of them into two more sheets. As a result, we get four sheets $$$1 \times 1$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my @m = map { length s/.*?(0*)$/$1/r }
		map { eval sprintf "%0b", $_ } $w, $h;

	for( @m ){
		$_ > 13 and $_ = 13;
		}

	my $m = eval join '*', map 2 ** $_, @m;

	print $m >= $n ? "YES" : "NO";
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my @m = map { length s/.*?(0*)$/$1/r }
		map { eval sprintf "%0b", $_ } $w, $h;

	for( @m ){
		$_ > 11 and $_ = 11;
		}

	my $m = eval join '*', map 2 ** $_, @m;

	print $m >= $n ? "YES" : "NO";
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $m = length join '', map { s/.*?(0*)$/$1/r }
		map { eval sprintf "%0b", $_ } $w, $h;

	if( $m < 11 ){
		$m = 2 ** $m;
		}

	print $m >= $n ? "YES" : "NO";
	}


Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar.

The first line contains the integer n (1 ≤ n ≤ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≤ ai, bi, ci ≤ 109) — the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones.

In the first line print k (1 ≤ k ≤ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them.

NoteIn the first example we can connect the pairs of stones:  2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1  2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively.  2 and 6, the size of the parallelepiped: 3 × 5 × 4, the radius of the inscribed sphere 1.5  4 and 5, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1  5 and 6, the size of the parallelepiped: 3 × 4 × 5, the radius of the inscribed sphere 1.5 Or take only one stone:  1 the size of the parallelepiped: 5 × 5 × 5, the radius of the inscribed sphere 2.5  2 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1  3 the size of the parallelepiped: 1 × 4 × 1, the radius of the inscribed sphere 0.5  4 the size of the parallelepiped: 2 × 1 × 3, the radius of the inscribed sphere 0.5  5 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1  6 the size of the parallelepiped: 3 × 3 × 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone.


The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least k times?

The first line contains two integers, n and k (1 ≤ n ≤ 2000; 1 ≤ k ≤ 5). The next line contains n integers: y1, y2, ..., yn (0 ≤ yi ≤ 5), where yi shows the number of times the i-th person participated in the ACM ICPC world championship.

Print a single number — the answer to the problem.

NoteIn the first sample only one team could be made: the first, the fourth and the fifth participants.In the second sample no teams could be created.In the third sample two teams could be created. Any partition into two teams fits.

my ($n, $k) = split / /, <>;
my @arr = split / /, <>;
my $count = 0;
$_ += $k for(@arr);
$count = $count + ($_ <=5 ? 1:0) for(@arr);
print int($count / 3);

my ($n, $k) = split / /, <>;
my $count = 0;
$_ <= 5 - $k && $count++ for(split / /, <>);
print int($count / 3);

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

($n, $k) = split / /, <>;
($tot, $k) = (0, 5 - $k);
$_<=$k and ++$tot foreach (split / /, <>);
say $tot/3;

my ($n, $k) = split ' ', <>;
my @people = split ' ', <>;
my @rem = map { 5 - $_ } @people;

my $ok = int((scalar grep { $_ >= $k } @rem) / 3);

print "$ok\n";

my @firstline = split (' ', <>);
my @secondline = split (' ', <>);
my @goodguys;
my $n = $firstline[0];
my $k = $firstline[1];
my $goodguys = 0;
foreach (@secondline){
    if (($k+$_) <= 5){
        $goodguys++;

}
}
print int($goodguys / 3);


George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.

The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.

Print a single integer — the answer to the problem.

NoteIn the first sample the set of the prepared problems meets the requirements for a good round.In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.


Petya recieved a gift of a string s with length up to 105 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves:  Extract the first character of s and append t with this character.  Extract the last character of t and append u with this character. Petya wants to get strings s and t empty and string u lexicographically minimal.You should write a program that will help Petya win the game.

First line contains non-empty string s (1 ≤ |s| ≤ 105), consisting of lowercase English letters.

# function returns true if the current
# character is the smallest in the rest
# otherwise, it returns false
# of string s
# parameters are the character and
# the hash
sub is_small {
    my $chr = shift @_;
    my $h_ref = shift @_;
    for my $i ( keys %{ $h_ref } ) {
	if ( ($i lt $chr) and ${ $h_ref }{ $i } > 0 ) {
	    return 0;}}		# return false if character is less than
    return 1;			# chr and there are still chrs in the string
}

# initialize hash
my $h;
for my $i (a..z) {
    $h{ $i } = 0; }

# read input
my $f = <STDIN>;
chomp ( $f );
# put the string into an array
my @s = split m//, $f;

# calculate frequencies for each character
# in the string and store in the hash
for (@s) {
    $h{ $_ } += 1;}

# strings described in problem statement
my @t;
my @u;

# temporary varaibles for pushing and poping and shifting
my $front;
my $back;

# main algorithm with two operations
while ( @s > 0 ) {

    # remove character from front of string
    $front = shift @s;

    # decrement value for $front character
    $h { $front } -= 1;

    # remove key - value pair if value become zero
    if ( $h { $front } == 0 ) {
	delete $h { $front }; }

    # push character to the end of @t string
    push @t, $front;

    # take advantage of short circuiting
    while ( @t > 0 and &is_small ( $t[ @t-1 ], \%h ) ) {

	$back = pop @t;
	push @u, $back;}
}

# put the remainder of @t onto @u
while ( @t > 0 ) {
    $back = pop @t;
    push @u, $back; }

# print the resuling string
print @u;
print "\n";

# function returns true if the current
# character is the smallest in the rest
# otherwise, it returns false
# of string s
# parameters are the character and
# the hash
sub is_small {
    my $chr = shift @_;
    my $h_ref = shift @_;
    for my $i ( keys %{ $h_ref } ) {
	if ( ($i lt $chr) and ${ $h_ref }{ $i } > 0 ) {
	    return 0;}}		# return false if character is less than
    return 1;			# chr and there are still chrs in the string
}

# initialize hash
my $h;
for my $i (a..z) {
    $h{ $i } = 0; }

# read input
my $f = <STDIN>;
chomp ( $f );
# put the string into an array
my @s = split m//, $f;

# calculate frequencies for each character
# in the string and store in the hash
for (@s) {
    $h{ $_ } += 1;}

# strings described in problem statement
my @t;
my @u;

# temporary varaibles for pushing and poping and shifting
my $front;
my $back;

# main algorithm with two operations
while ( @s > 0 ) {

    $front = shift @s;
    push @t, $front;
    if ( &is_small ( $front, \%h ) ) {
	$back = pop @t;
	push @u, $back;}
}

# put the remainder of @t onto @u
while ( @t > 0 ) {
    $back = pop @t;
    push @u, $back; }

# print the resuling string
print @u;
print "\n";


Three friends are going to meet each other. Initially, the first friend stays at the position $$$x = a$$$, the second friend stays at the position $$$x = b$$$ and the third friend stays at the position $$$x = c$$$ on the coordinate axis $$$Ox$$$.In one minute each friend independently from other friends can change the position $$$x$$$ by $$$1$$$ to the left or by $$$1$$$ to the right (i.e. set $$$x := x - 1$$$ or $$$x := x + 1$$$) or even don't change it.Let's introduce the total pairwise distance — the sum of distances between each pair of friends. Let $$$a'$$$, $$$b'$$$ and $$$c'$$$ be the final positions of the first, the second and the third friend, correspondingly. Then the total pairwise distance is $$$|a' - b'| + |a' - c'| + |b' - c'|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.Friends are interested in the minimum total pairwise distance they can reach if they will move optimally. Each friend will move no more than once. So, more formally, they want to know the minimum total pairwise distance they can reach after one minute.You have to answer $$$q$$$ independent test cases.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 1000$$$) — the number of test cases. The next $$$q$$$ lines describe test cases. The $$$i$$$-th test case is given as three integers $$$a, b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) — initial positions of the first, second and third friend correspondingly. The positions of friends can be equal.

For each test case print the answer on it — the minimum total pairwise distance (the minimum sum of distances between each pair of friends) if friends change their positions optimally. Each friend will move no more than once. So, more formally, you have to find the minimum total pairwise distance they can reach after one minute.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	my( $A, $B, $C ) = sort { $a <=> $b } split;

	$A ++ if $C - $A > 1;
	$C -- if $C - $A > 0;

	print 2 * ( $C - $A );
	}

my $tests = <>;
#printf("tests:$tests\n");
chomp ($tests);
foreach my $t (1..$tests) {
 my $in = <>;
 chomp($in);
 my @arr = split(" ",$in);
 my @sorted = sort { $a <=> $b } @arr;
 my $a = $sorted[0];
 my $b = $sorted[1];
 my $c = $sorted[2];
 #print "a,b,c:$a,$b,$c\n";
 if ($a != $b) {
     $a++;
     if ($b != $c) {
      $c--;
     } else {
         $c--;
         $b--;
     }
 }
 #print "a,b,c:$a,$b,$c\n";
 my $d = ($c - $b) + ($b - $a) + ($c - $a);
 print "$d\n";
}

my $tests = <>;
#printf("tests:$tests\n");
chomp ($tests);
foreach my $t (1..$tests) {
 my $in = <>;
 chomp($in);
 my @arr = split(" ",$in);
 my @sorted = sort { $a <=> $b } @arr;
 my $a = $sorted[0];
 my $b = $sorted[1];
 my $c = $sorted[2];
 #print "a,b,c:$a,$b,$c\n";
 if ($a != $b) {
     $a++;
     if ($b != $c) {
      $c--;
     } else {
         $c--;
         $b--;
     }
 } elsif ($b != $c) {
     $c--;
 }

 #print "a,b,c:$a,$b,$c\n";
 my $d = ($c - $b) + ($b - $a) + ($c - $a);
 print "$d\n";
}

my $tests = <>;
#printf("tests:$tests\n");
chomp ($tests);
foreach my $t (1..$tests) {
 my $in = <>;
 chomp($in);
 my @arr = split(" ",$in);
 my @sorted = sort { $a <=> $b } @arr;
 my $a = $sorted[0];
 my $b = $sorted[1];
 my $c = $sorted[2];
 #print "a,b,c:$a,$b,$c\n";
 if ($a != $b) {
     $a++;
     if ($b != $c) {
      $c--;
     } elsif ($a != $b) {
         $c--;
         $b--;
     }
 } elsif ($b != $c) {
     $c--;
 }

 #print "a,b,c:$a,$b,$c\n";
 my $d = ($c - $b) + ($b - $a) + ($c - $a);
 print "$d\n";
}


You are given a string $$$s$$$ of length $$$n$$$, which consists only of the first $$$k$$$ letters of the Latin alphabet. All letters in string $$$s$$$ are uppercase.A subsequence of string $$$s$$$ is a string that can be derived from $$$s$$$ by deleting some of its symbols without changing the order of the remaining symbols. For example, "ADE" and "BD" are subsequences of "ABCDE", but "DEA" is not.A subsequence of $$$s$$$ called good if the number of occurences of each of the first $$$k$$$ letters of the alphabet is the same.Find the length of the longest good subsequence of $$$s$$$.

The first line of the input contains integers $$$n$$$ ($$$1\le n \le 10^5$$$) and $$$k$$$ ($$$1 \le k \le 26$$$). The second line of the input contains the string $$$s$$$ of length $$$n$$$. String $$$s$$$ only contains uppercase letters from 'A' to the $$$k$$$-th letter of Latin alphabet.

Print the only integer — the length of the longest good subsequence of string $$$s$$$.

NoteIn the first example, "ACBCAB" ("ACAABCCAB") is one of the subsequences that has the same frequency of 'A', 'B' and 'C'. Subsequence "CAB" also has the same frequency of these letters, but doesn't have the maximum possible length.In the second example, none of the subsequences can have 'D', hence the answer is $$$0$$$.

use strict;
#open STDIN, '<input.txt';
#open STDOUT, '>output.txt';
my ($n, $m) = split(' ', <>);
my $s = <>;
my @a = split(//, $s);
my %h;
for(my $i = 0; $i < $n; $i++){
  $h{$a[$i]}++;
}
my $mini = 100000000;
if(keys(%h) < $m){
  print 0;
  exit(0);
}
else{
  while (my ($k, $v) = each(%h) ) {
    if($v < $mini){
      $mini = $v;
    }
  }
}
print $mini * keys(%h);


You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n × n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door: The cleaning of all evil will awaken the door! Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile — then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.You would like to purify all n × n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.

The first line will contain a single integer n (1 ≤ n ≤ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.

If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.

NoteThe first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.   In the second example, it is impossible to purify the cell located at row 1 and column 1.For the third example:


You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence.We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2... s|s|.String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or exists such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. Characters in lines are compared like their ASCII codes.

The single line contains a non-empty string s, consisting only of lowercase English letters. The string's length doesn't exceed 105.

Print the lexicographically maximum subsequence of string s.

NoteLet's look at samples and see what the sought subsequences look like (they are marked with uppercase bold letters).The first sample: aBaBBAThe second sample: abbCbCCaCbbCBaaBA

#!perl -w
use strict;
use warnings;

main();

sub main {
    my $s = <>;
    chomp($s);
    my @str1 = split //, $s;
    my ( $min, @str2 ) = ( $str1[$#str1], () );
    for ( my $i = @str1 - 1; $i >= 0; $i-- ) {
        if ( $str1[$i] ge $min ) {
            unshift @str2, $str1[$i];
            $min = $str1[$i];
        }
    }
    print @str2;
}

__END__


Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.

The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.

For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.


You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x < n$$$ and $$$1 \le y < m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.

If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ — the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

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

	my( $n, $m ) = split;

	$_ = join '', map ~~<>, 1 .. $n;
	y/ //d;
	chomp;

	$debug and print;

	my $gap = $m - 2 + 1;

	0 while
		s/
			[1,]{2} (.{$gap})
			[1,]{2}
		/
			":," . $1 .
			",,"
		/xse;

	$debug and print;

	/1/ and print -1 and next;

	@_ = split "\n", $_;

	my @coords;

	for my $i ( 0 .. $n - 1 ){
		while( $_[ $i ] =~ /:/g ){
			push @coords, join " ", $i + 1, pos $_[ $i ];
			}
		}

	print for ~~ @coords, @coords;
	}


A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).

The first and only line consists of a string $$$S$$$ ($$$ 1 \le |S| \le 5\,000 $$$). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.

Print "YES" or "NO", according to the condition.

NoteConsider first example: the number of 'c' is equal to the number of 'a'. Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.Consider third example: the number of 'c' is equal to the number of 'b'.

#!/usr/bin/env perl

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

sub check($) {
   my $S = shift;
   if ($S !~ m/^(a+)(b+)(c+)$/) {
      return 0;
   }
   my $a = $1;
   my $b = $2;
   my $c = $3;
   return length($c) == length($a) || length($c) == length($b);
}

my $S = <>;
chomp $S;

print check($S) ? 'YES' : 'NO', "\n";


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

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

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

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

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

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

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

AE somewhere
AE in line 3
Unhandled Exception

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

#!/usr/bin/perl

use 5.006;
use strict;
use warnings;

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

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

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

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

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

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

    }
}

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

#!perl
use strict;
use warnings;

main();

sub main {
    my $n = int <>;
    my ($tries, $ltries, $type, $message) = (0, 0, "", 'Unhandled Exception');
tc: for (1..$n) {
        my $str = <>;
        chomp($str);
        $str =~ s/[(),]/ /g;
        $str =~ s/^[ \t]*//g;
        $str =~ s/ +/ /g;
        my ($cmd, $ttype, $cmessage) = split / /, $str, 3;
        if (! $cmd) { next tc; }
        if ($cmd eq 'try') {
            if ($type) {
                $ltries++;
            } else {
                $tries++;
            }
        } elsif ($cmd eq 'catch') {
            if ($ltries) {
                $ltries--;
            } else {
                if ($type) {
                    if ($type eq $ttype) {
                        $message = $cmessage;
                        $message =~ s/ +$//g;
                        $message =~ s/"//g;
                        last tc;
                    }
                } else {
                    $tries--;
                }
            }
        } elsif ($cmd eq 'throw') {
            $type = $ttype;
        }
    }
    print $message;
}

__END__

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

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

 my $n = <STDIN>;

  my $found = 0;

  my $level = 0;

  my $throwLevel = -1;

  my $e = "";

  foreach (1 .. $n) {

      my $line = <STDIN>;

      if ($line =~ /^\s*try/) {

          $level ++;

      } elsif ($line =~ /^\s*throw\s*\(\s*(\w+)\s*\)/) {

          $e = $1;

          $throwLevel = $level;

          # print "throw $e at level $throwLevel\n";

      } elsif ($line =~ /^\s*catch\s*\(\s*(\w+)\s*,\s*"(.+)"\s*\)/) {

          my $ce = $1;

          my $msg = $2;

          if ($ce eq $e && $level <= $throwLevel) {

              $found = 1;

              print "$msg\n";

              last;

          }

          $level --;

          if ($throwLevel > $level) {

              $throwLevel = $level;

              # print "decrease throwLevel to $throwLevel\n";

          }

      }

  }

  if (!$found) {

      print "Unhandled Exception";

  }

#!/usr/local/bin/perl
$n              = <>;
$openBlocks     = 0;
$needlessBlocks =
  0;    #это блоки, открытые после эксепшена TODO
$wasThrow = 0;
$eType;
for ( 1 .. $n ) {
    my $line = <>;

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

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

#!perl
use strict;
use warnings;

main();

sub main {
    my $n = int <>;
    my ($tries, $ltries, $type, $message) = (0, 0, "", 'Unhandled Exception');
tc: for (1..$n) {
        my $str = <>;
        chomp($str);
        $str =~ s/[(),]/ /g;
        $str =~ s/^[ \t]*//g;
        $str =~ s/ +/ /g;
        my ($cmd, $ttype, $cmessage) = split / /, $str, 3;
        if (! $cmd) { next tc; }
        if ($cmd eq 'try') {
            if ($type) {
                $ltries++;
            } else {
                $tries++;
            }
        } elsif ($cmd eq 'catch') {
            if ($ltries) {
                $ltries--;
            } else {
                if ($type) {
                    if ($type eq $ttype) {
                        $message = $cmessage;
                        last tc;
                    }
                } else {
                    $tries--;
                }
            }
        } elsif ($cmd eq 'throw') {
            $type = $ttype;
        }
    }
    print $message;
}

__END__

#!perl
use strict;
use warnings;

main();

sub main {
    my $n = int <>;
    my ($tries, $ltries, $type, $message) = (0, 0, "", 'Unhandled Exception');
tc: for (1..$n) {
        my $str = <>;
        chomp($str);
        $str =~ s/[(),]/ /g;
        $str =~ s/^[ \t]*//g;
        $str =~ s/ +/ /g;
        my ($cmd, $ttype, $cmessage) = split / /, $str, 3;
        if (! $cmd) { next tc; }
        if ($cmd eq 'try') {
            if ($type) {
                $ltries++;
            } else {
                $tries++;
            }
        } elsif ($cmd eq 'catch') {
            if ($ltries) {
                $ltries--;
            } else {
                if ($type) {
                    if ($type eq $ttype) {
                        $message = $cmessage;
                        $message =~ s/"//g;
                        last tc;
                    }
                } else {
                    $tries--;
                }
            }
        } elsif ($cmd eq 'throw') {
            $type = $ttype;
        }
    }
    print $message;
}

__END__

#!/usr/local/bin/perl
$n              = <>;
$openBlocks     = 0;
$needlessBlocks =
  0;    #это блоки, открытые после эксепшена TODO
$wasThrow = 0;
$eType;
for ( 1 .. $n ) {
    my $line = <>;

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

    }
}
print "Unhandled Exception\n";

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

#!/usr/local/bin/perl
$n              = <>;
$openBlocks     = 0;
$needlessBlocks =
  0;    #это блоки, открытые после эксепшена TODO
$wasThrow = 0;
$eType;
for ( 1 .. $n ) {
    my $line = <>;

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

    }
}

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


Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly n characters.   Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the i-th letter of her name should be 'O' (uppercase) if i is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to n. Fibonacci sequence is the sequence f where  f1 = 1,  f2 = 1,  fn = fn - 2 + fn - 1 (n > 2). As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.

The first and only line of input contains an integer n (1 ≤ n ≤ 1000).

Print Eleven's new name on the first and only line of output.

$_ = <>, chomp;

$o = 'O';

$o =~ s/o*O?o*O$/ $& . reverse ucfirst lc $& /e for 1 .. 14;

print 'O' . substr $o, 0, $_ - 1

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	my $n = $_;
	$_ = 'o' x 1e3;

	s/o/O/;

	my $i = 1;
	my $j = 1;

	while( $j < 1 + length ){
		substr $_, $j - 1, 1, 'O';
		my $tmp = $j;
		$j += $i;
		$i = $tmp;
		}

	print substr $_, 0, $n;
	}


Santa has $$$n$$$ candies and he wants to gift them to $$$k$$$ kids. He wants to divide as many candies as possible between all $$$k$$$ kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.Suppose the kid who recieves the minimum number of candies has $$$a$$$ candies and the kid who recieves the maximum number of candies has $$$b$$$ candies. Then Santa will be satisfied, if the both conditions are met at the same time:  $$$b - a \le 1$$$ (it means $$$b = a$$$ or $$$b = a + 1$$$);  the number of kids who has $$$a+1$$$ candies (note that $$$a+1$$$ not necessarily equals $$$b$$$) does not exceed $$$\lfloor\frac{k}{2}\rfloor$$$ (less than or equal to $$$\lfloor\frac{k}{2}\rfloor$$$). $$$\lfloor\frac{k}{2}\rfloor$$$ is $$$k$$$ divided by $$$2$$$ and rounded down to the nearest integer. For example, if $$$k=5$$$ then $$$\lfloor\frac{k}{2}\rfloor=\lfloor\frac{5}{2}\rfloor=2$$$.Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The $$$i$$$-th test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^9$$$) — the number of candies and the number of kids.

For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.

NoteIn the first test case, Santa can give $$$3$$$ and $$$2$$$ candies to kids. There $$$a=2, b=3,a+1=3$$$.In the second test case, Santa can give $$$5, 5, 4$$$ and $$$4$$$ candies. There $$$a=4,b=5,a+1=5$$$. The answer cannot be greater because then the number of kids with $$$5$$$ candies will be $$$3$$$.In the third test case, Santa can distribute candies in the following way: $$$[1, 2, 2, 1, 1, 2, 1]$$$. There $$$a=1,b=2,a+1=2$$$. He cannot distribute two remaining candies in a way to be satisfied.In the fourth test case, Santa can distribute candies in the following way: $$$[3, 3]$$$. There $$$a=3, b=3, a+1=4$$$. Santa distributed all $$$6$$$ candies.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $div = int $n / $k;

	my $ans = $div * $k;

	my $rest = $n - $ans;

	my $min = ( sort { $a <=> $b } $rest, int $k / 2 )[ 0 ];

	print $ans + $min;
	}


Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent.One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the n drinks and mixed them. Then he wondered, how much orange juice the cocktail has.Find the volume fraction of orange juice in the final drink.

The first input line contains a single integer n (1 ≤ n ≤ 100) — the number of orange-containing drinks in Vasya's fridge. The second line contains n integers pi (0 ≤ pi ≤ 100) — the volume fraction of orange juice in the i-th drink, in percent. The numbers are separated by a space.

Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10  - 4.

NoteNote to the first sample: let's assume that Vasya takes x milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal  milliliters. The total cocktail's volume equals 3·x milliliters, so the volume fraction of the juice in the cocktail equals , that is, 66.(6) percent.

my $n = <STDIN>;
my @a = split(/\s/, <STDIN>);
my $total = 0;
map{ $total += $_ } @a;
printf("%.12f", $total/$n);

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

chomp($n = <>);
$tot+=$_ foreach (split / /, <>);
$ans = $tot / $n;
say $ans;

#!perl
use strict;

main();

sub main {
    my $n = int <>;
    my @arr = map int, split /\D/, <>;
    my $res = 0;
    for (@arr) {
        $res += $_;
    }
    $res /= $n;
    print $res;
}

__END__

#!/usr/bin/env perl

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

# essential
my @tokens = ();

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

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

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

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

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

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

# solve

my $n = read_token;

my @percents = split q{ }, read_line;

my @proportions = map { $_ / 100 } @percents;

my $sums = sum(@proportions);

say $sums / $n * 100;


All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi — a coordinate on the Ox axis. No two cities are located at a single point.Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.For each city calculate two values mini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city

The first line of the input contains integer n (2 ≤ n ≤ 105) — the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.

Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.

use 5.016;
use strict;
use warnings;

my %min;
my %max;

<>;
my @cities = split ' ', <>;

for my $i (1..$#cities) {
  my $d = abs($cities[$i - 1] - $cities[$i]);
  $min{$i - 1} = $d if !exists $min{$i - 1} || $d < $min{$i - 1};
  $min{$i}     = $d if !exists $min{$i}     || $d < $min{$i};
}

for my $i (0..$#cities) {
  my $left = $cities[$i] - $cities[0];
  my $right = $cities[-1] - $cities[$i];
  $max{$i} = $left > $right ? $left
                            : $right;
}

for my $i (0..$#cities) {
  say "$min{$i} $max{$i}"
}

#!perl
$\ = "\n";

$n = <>;

@a = split /\s/, <>;

push @result, (abs @a[0] - @a[1]).' '.(abs @a[0] - @a[$#a]);

for my $i (1..$#a - 1)
{
    my $minLeft = abs @a[$i] - @a[$i - 1];
    my $minRight = abs @a[$i] - @a[$i + 1];

    my $maxLeft = abs @a[$i] - @a[0];
    my $maxRight = abs @a[$i] - @a[$#a];

    my $min = $minLeft < $minRight ? $minLeft : $minRight;
    my $max = $maxLeft > $maxRight ? $maxLeft : $maxRight;

    push @result, $min.' '.$max;
}

push @result, (abs @a[$#a - 1] - @a[$#a]).' '.(abs @a[0] - @a[$#a]);

print join "\n", @result;

use 5.016;
use strict;
use warnings;

my %min;
my %max;

<>;
my @cities = split ' ', <>;

for my $i (1..$#cities) {
  my $d = abs($cities[$i - 1] - $cities[$i]);
  $min{$i - 1} = $d if !exists $min{$i - 1} || $d < $min{$i - 1};
  $min{$i}     = $d if !exists $min{$i}     || $d < $min{$i};
}

for my $i (0..$#cities) {
  my $left = $cities[$i] - $cities[0];
  my $right = $cities[-1] - $cities[0];
  $max{$i} = $left > $right ? $left
                            : $right;
}

for my $i (0..$#cities) {
  say "$min{$i} $max{$i}"
}


Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:   climb one area up;  climb one area down;  jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall. If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon.The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.The level is considered completed if the ninja manages to get out of the canyon.After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.

The first line contains two integers n and k (1 ≤ n, k ≤ 105) — the height of the canyon and the height of ninja's jump, correspondingly. The second line contains the description of the left wall — a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area. The third line describes the right wall in the same format. It is guaranteed that the first area of the left wall is not dangerous.

Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).

NoteIn the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon. In the second sample there's no way the ninja can get out of the canyon.


You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example:  The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened;  The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise.

NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

my $debug = 0;

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

	@_ = split ' ', <>;

	print qw( No Yes )[ 0 + do{
		if( $_ % 2 ){
			is_over_pyramide( @_ );
			}
		else{
			is_over_pyramide( @_ ) || is_over_pyramide( reverse @_ );
			}
		} ];

	}

sub is_over_pyramide {
	my @A = @_;

	my @up = 0 .. @A - 1;
	my @down = reverse @up;

	my @pyramide;

	while( @up ){
		push @pyramide, ( sort { $a <=> $b } shift @up, shift @down )[ 0 ];
		}

	for my $i ( 0 .. @pyramide - 2 ){
		$pyramide[ $i ] == $pyramide[ $i + 1 ] and do {
			$pyramide[ $i ] ++;
			last;
			};
		}

	$debug and print ":[@pyramide]";
	$debug and print ":[@A]";

	my $ok = 1;

	while( @pyramide ){
		$ok *= ( shift @pyramide ) <= shift @A;
		}

	$ok;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	print qw( No Yes)[ 0 + do{
		if( $_ % 2 ){
			over_pyramide( @_ );
			}
		else{
			over_pyramide( @_, 0 ) || over_pyramide( 0, @_ );
			}
		} ];

	}

sub over_pyramide {
	my @A = @_;

	my @up = 0 .. @A - 1;
	my @down = reverse @up;

	my @pyramide;

	while( @up ){
		push @pyramide, ( sort { $a <=> $b } shift @up, shift @down )[ 0 ];
		}

	my $ok = 1;

	while( @pyramide ){
		$ok &= ( shift @pyramide ) <= shift @A;
		}

	$ok;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

my $debug = 0;

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

	@_ = split ' ', <>;

	print qw( No Yes )[ 0 + do{
		if( $_ % 2 ){
			is_over_pyramide( @_ );
			}
		else{
			is_over_pyramide( @_, 0 ) || is_over_pyramide( 0, @_ );
			}
		} ];

	}

sub is_over_pyramide {
	my @A = @_;

	my @up = 0 .. @A - 1;
	my @down = reverse @up;

	my @pyramide;

	while( @up ){
		push @pyramide, ( sort { $a <=> $b } shift @up, shift @down )[ 0 ];
		}

	my $ok = 1;

	$debug and print ":[@pyramide]";
	$debug and print ":[@A]";

	while( @pyramide ){
		$ok *= ( shift @pyramide ) <= shift @A;
		}

	$ok;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

my $debug = 1;

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

	@_ = split ' ', <>;

	print qw( No Yes )[ 0 + do{
		if( $_ % 2 ){
			is_over_pyramide( @_ );
			}
		else{
			is_over_pyramide( @_ ) || is_over_pyramide( reverse @_ );
			}
		} ];

	}

sub is_over_pyramide {
	my @A = @_;

	my @up = 0 .. @A - 1;
	my @down = reverse @up;

	my @pyramide;

	while( @up ){
		push @pyramide, ( sort { $a <=> $b } shift @up, shift @down )[ 0 ];
		}

	for my $i ( 0 .. @pyramide - 2 ){
		$pyramide[ $i ] == $pyramide[ $i + 1 ] and do {
			$pyramide[ $i ] ++;
			last;
			};
		}

	$debug and print ":[@pyramide]";
	$debug and print ":[@A]";

	my $ok = 1;

	while( @pyramide ){
		$ok *= ( shift @pyramide ) <= shift @A;
		}

	$ok;
	}


You have a list of numbers from $$$1$$$ to $$$n$$$ written from left to right on the blackboard.You perform an algorithm consisting of several steps (steps are $$$1$$$-indexed). On the $$$i$$$-th step you wipe the $$$i$$$-th number (considering only remaining numbers). You wipe the whole number (not one digit).  When there are less than $$$i$$$ numbers remaining, you stop your algorithm. Now you wonder: what is the value of the $$$x$$$-th remaining number after the algorithm is stopped?

The first line contains one integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. The next $$$T$$$ lines contain queries — one per line. All queries are independent. Each line contains two space-separated integers $$$n$$$ and $$$x$$$ ($$$1 \le x < n \le 10^{9}$$$) — the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least $$$x$$$ numbers.

Print $$$T$$$ integers (one per query) — the values of the $$$x$$$-th number after performing the algorithm for the corresponding queries.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	print $x * 2;
	}


Kawashiro Nitori is a girl who loves competitive programming.One day she found a string and an integer. As an advanced problem setter, she quickly thought of a problem.Given a string $$$s$$$ and a parameter $$$k$$$, you need to check if there exist $$$k+1$$$ non-empty strings $$$a_1,a_2...,a_{k+1}$$$, such that $$$$$$s=a_1+a_2+\ldots +a_k+a_{k+1}+R(a_k)+R(a_{k-1})+\ldots+R(a_{1}).$$$$$$ Here $$$+$$$ represents concatenation. We define $$$R(x)$$$ as a reversed string $$$x$$$. For example $$$R(abcd) = dcba$$$. Note that in the formula above the part $$$R(a_{k+1})$$$ is intentionally skipped.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case description contains two integers $$$n$$$, $$$k$$$ ($$$1\le n\le 100$$$, $$$0\le k\le \lfloor \frac{n}{2} \rfloor$$$)  — the length of the string $$$s$$$ and the parameter $$$k$$$. The second line of each test case description contains a single string $$$s$$$ of length $$$n$$$, consisting of lowercase English letters.

For each test case, print "YES" (without quotes), if it is possible to find $$$a_1,a_2,\ldots,a_{k+1}$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower).

7
5 1
qwqwq
2 1
ab
3 1
ioi
4 2
icpc
22 0
dokidokiliteratureclub
19 8
imteamshanghaialice
6 3
aaaaaa

NoteIn the first test case, one possible solution is $$$a_1=qw$$$ and $$$a_2=q$$$.In the third test case, one possible solution is $$$a_1=i$$$ and $$$a_2=o$$$.In the fifth test case, one possible solution is $$$a_1=dokidokiliteratureclub$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $fail = 0;

	while( $k -- ){
		s/^(.)(.+)(.)$/$2/ and
		$1 eq $3 or do { $fail = 1; last };
		}

	print $fail ? 'NO' : 'YES';
	}


You are given a string $$$s$$$ consisting of the characters '0', '1', and '?'. You need to replace all the characters with '?' in the string $$$s$$$ by '0' or '1' so that the string becomes a palindrome and has exactly $$$a$$$ characters '0' and exactly $$$b$$$ characters '1'. Note that each of the characters '?' is replaced independently from the others.A string $$$t$$$ of length $$$n$$$ is called a palindrome if the equality $$$t[i] = t[n-i+1]$$$ is true for all $$$i$$$ ($$$1 \le i \le n$$$).For example, if $$$s=$$$"01?????0", $$$a=4$$$ and $$$b=4$$$, then you can replace the characters '?' in the following ways:   "01011010";  "01100110". For the given string $$$s$$$ and the numbers $$$a$$$ and $$$b$$$, replace all the characters with '?' in the string $$$s$$$ by '0' or '1' so that the string becomes a palindrome and has exactly $$$a$$$ characters '0' and exactly $$$b$$$ characters '1'.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 2 \cdot 10^5$$$, $$$a + b \ge 1$$$). The second line of each test case contains the string $$$s$$$ of length $$$a+b$$$, consisting of the characters '0', '1', and '?'. It is guaranteed that the sum of the string lengths of $$$s$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output:    "-1", if you can't replace all the characters '?' in the string $$$s$$$ by '0' or '1' so that the string becomes a palindrome and that it contains exactly $$$a$$$ characters '0' and exactly $$$b$$$ characters '1';  the string that is obtained as a result of the replacement, otherwise.  If there are several suitable ways to replace characters, you can output any.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $reverse = reverse;

	for my $i ( 0 .. -1 + length ){
		my $c1 = substr $_, $i, 1;
		my $c2 = substr $reverse, $i, 1;
		if( 0 ){ ; }
		elsif( $c1 eq '?' and $c2 eq '?' ){
			;
			}
		elsif( $c1 eq '?' and $c2 eq '0' ){
			substr $_, $i, 1, 0;
			}
		elsif( $c1 eq '0' and $c2 eq '?' ){
			substr $reverse, $i, 1, 0;
			}
		elsif( $c1 eq '?' and $c2 eq '1' ){
			substr $_, $i, 1, 1;
			}
		elsif( $c1 eq '1' and $c2 eq '?' ){
			substr $reverse, $i, 1, 1;
			}
		}

	if( $_ ne reverse ){
		print -1;
		next;
		}

	my $_0 = () = m/0/g;
	my $_1 = () = m/1/g;

	$A -= $_0;
	$B -= $_1;

	if( $A < 0 or $B < 0 ){
		print -1;
		next;
		}

	my @change;

	if( ( length ) % 2 == 1 ){
		if( $A % 2 == 1 ){
			$A --;
			push @change, 0;
			}
		elsif( $B % 2 == 1 ){
			$B --;
			push @change, 1;
			}
		}

	if( $A % 2 == 1 or $B % 2 == 1 ){
		print -1;
		next;
		}

	push @change, ( 0 ) x ( $A / 2 ), ( 1 ) x ( $B / 2 );
	unshift @change, ( 1 ) x ( $B / 2 ), ( 0 ) x ( $A / 2 );

	s/\?/shift @change/ge;

	print;
	}


There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote. The voting procedure is rather complicated:   Each of n employees makes a statement. They make statements one by one starting from employees 1 and finishing with employee n. If at the moment when it's time for the i-th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting).  When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote. It's allowed to deny from voting people who already made the statement or people who are only waiting to do so. If someone is denied from voting he no longer participates in the voting till the very end.  When all employees are done with their statements, the procedure repeats: again, each employees starting from 1 and finishing with n who are still eligible to vote make their statements.  The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting. Of course, he votes for the decision suitable for his fraction. You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction). Predict the outcome of the vote.

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of employees.  The next line contains n characters. The i-th character is 'D' if the i-th employee is from depublicans fraction or 'R' if he is from remocrats.

Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win.

NoteConsider one of the voting scenarios for the first sample:   Employee 1 denies employee 5 to vote.  Employee 2 denies employee 3 to vote.  Employee 3 has no right to vote and skips his turn (he was denied by employee 2).  Employee 4 denies employee 2 to vote.  Employee 5 has no right to vote and skips his turn (he was denied by employee 1).  Employee 1 denies employee 4.  Only employee 1 now has the right to vote so the voting ends with the victory of depublicans.

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

my @RINDEX;
my @DINDEX;

for(my $i=0;$i<length($s);$i++)
{
	if(substr($s,$i,1) eq "R")
	{
	push(@RINDEX,$i)
	}
	if(substr($s,$i,1) eq "D")
	{
	push(@DINDEX,$i)
	}
}
my $j=0;
while(scalar(@RINDEX) and scalar(@DINDEX)){

	if($RINDEX[0]==$j)
	   {
	   		shift @DINDEX;
	   		push(@RINDEX,shift @RINDEX);
		}elsif($DINDEX[0]==$j){
	   		shift @RINDEX;
	   		push(@DINDEX,shift @DINDEX);
		}
$j++;
if($j>=length($s)){
	$j=0;
}
}

if(scalar(@RINDEX)){
	print "R \n";
}
if(scalar(@DINDEX)){
	print "D \n";
}

use strict;
my $n=<>;
chomp($n);
my $s=<>;
chomp($s);

my $i=0;
my @RINDEX;
my @DINDEX;

for(my $i=0;$i<length($s);$i++)
{
	if(substr($s,$i,1) eq "R")
	{
	push(@RINDEX,$i)
	}
	if(substr($s,$i,1) eq "D")
	{
	push(@DINDEX,$i)
	}
}
my $j=0;
while(scalar(@RINDEX)>0 and scalar(@DINDEX)>0 ){

	if($RINDEX[0]==$j)
	   {
	   		shift @DINDEX;
	   		push(@RINDEX,shift @RINDEX);
		}elsif($DINDEX[0]==$j){
	   		shift @RINDEX;
	   		push(@DINDEX,shift @DINDEX);
		}
$j++;
if($j>=length($s)){
	$j=0;
}
}

if(scalar(@RINDEX)>0){
	print "R \n";
}
if(scalar(@DINDEX)>0){
	print "D \n";
}

use strict;
use warnings;
my $n=<>;
chomp($n);
my $s=<>;
chomp($s);

my $i=0;

while(index($s,"D") >=0 and index($s,"R") >=0)
{

	if(substr($s,$i,1) eq "R")
	{
		my $ind=index($s,"D");
		substr($s,$ind,1,"0");
	}
	elsif(substr($s,$i,1) eq "D")
	{
		my $ind=index($s,"R");
		substr($s,$ind,1,"0");
	}
	$i++;
	$s =~ s/0//g;
	if($i>=length($s)){
		$i=0;
	}

}

if(index($s,"D")>=0){
	print "D\n";
}
if(index($s,"R")>=0){
	print "R\n";
}

use strict;
my $n=<>;
chomp($n);
my $s=<>;
chomp($s);

my $i=0;
my @RINDEX;
my @DINDEX;
my $j=0;
my $k=0;
for(my $i=0;$i<length($s);$i++)
{
	if(substr($s,$i,1) eq "R")
	{
	$RINDEX[$j++]=$i;
	}
	if(substr($s,$i,1) eq "D")
	{
	$DINDEX[$k++]=$i;
	}
}

$i=0;
$j=0;
$k=0;
while(scalar(@RINDEX)>0 and scalar(@DINDEX)>0 ){
if($RINDEX[$i] == $j ){
	shift @DINDEX;
	if($k>0){
		$k--;
	}
    $i++;
}elsif( $DINDEX[$k] == $j){
	shift @RINDEX;
	if($i>0){
		$i--;
	}
	$k++;
}
$j++;
if($j>=length($s)){
$i=0;
$j=0;
$k=0;
}
}

if(scalar(@RINDEX)>0){
	print "R \n";
}
if(scalar(@DINDEX)>0){
	print "D \n";
}

use strict;
use warnings;
my $n=<>;
chomp($n);
my $s=<>;
chomp($s);

my $i=0;
my @RINDEX;
my @DINDEX;
my $j=0;
my $k=0;
for(my $i=0;$i<length($s);$i++)
{
	if(substr($s,$i,1) eq "R")
	{
	$RINDEX[$j++]=$i;
	}
	if(substr($s,$i,1) eq "D")
	{
	$DINDEX[$k++]=$i;
	}
}

$i=0;
while(scalar(@RINDEX)>0 and scalar(@DINDEX)>0){
if($RINDEX[$i] > $DINDEX[$i]){
	shift @DINDEX;
}else{
	shift @RINDEX;
}
}

if(scalar(@RINDEX)>0){
	print "R \n";
}
if(scalar(@DINDEX)>0){
	print "D \n";
}

use strict;
use warnings;
my $n=<>;
chomp($n);
my $s=<>;
chomp($s);

my $i=0;
my @RINDEX;
my @DINDEX;
my $j=0;
my $k=0;
for(my $i=0;$i<length($s);$i++)
{
	if(substr($s,$i,1) eq "R")
	{
	$RINDEX[$j++]=$i;
	}
	if(substr($s,$i,1) eq "D")
	{
	$DINDEX[$k++]=$i;
	}
}

$i=0;
while(scalar(@RINDEX)>0 and scalar(@DINDEX)>0){
if($RINDEX[$i] < $DINDEX[$i]){
	shift @DINDEX;
}elsif($RINDEX[$i] > $DINDEX[$i]){
	shift @RINDEX;
}
}

if(scalar(@RINDEX)>0){
	print "R \n";
}
if(scalar(@DINDEX)>0){
	print "D \n";
}

use strict;
use warnings;
my $n=<>;
chomp($n);
my $s=<>;
chomp($s);

my $i=0;
my @RINDEX;
my @DINDEX;
my $j=0;
my $k=0;
for(my $i=0;$i<length($s);$i++)
{
	if(substr($s,$i,1) eq "R")
	{
	$RINDEX[$j++]=$i;
	}
	if(substr($s,$i,1) eq "D")
	{
	$DINDEX[$k++]=$i;
	}
}

$i=0;
while(scalar(@RINDEX)>0 and scalar(@DINDEX)>0){
print "@RINDEX \n";
print "@DINDEX \n";
if($RINDEX[$i] < $DINDEX[$i]){
	shift @DINDEX;
}elsif($RINDEX[$i] > $DINDEX[$i]){
	shift @RINDEX;
}
}

if(scalar(@RINDEX)>0){
	print "R \n";
}
if(scalar(@DINDEX)>0){
	print "D \n";
}


One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.You are given an integer n no less than 12, express it as a sum of two composite numbers.

The only line contains an integer n (12 ≤ n ≤ 106).

Output two composite integers x and y (1 < x, y < n) such that x + y = n. If there are multiple solutions, you can output any of them.

NoteIn the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.

use strict;
use warnings;

my $n = <>;

sub isPrime{
        my $num = shift;
        my $count = 0;
        for(my $i = 1 ; $i <= int(sqrt($num)) ; $i++){
                if($num % $i == 0){
                        $count++;
                }
        }
        if($count > 1){
                return 0;
        }else{
                return 1;
        }
}

for(my $j = 2 ;;$j++){
        my $p = $n - $j;
        if(!isPrime($p) && !isPrime($j)){
                print "$j $p";
                last;
        }
}

#!/usr/bin/perl

my $n = <>;

sub isPrime($) {
	my $arg = $_[0];
	my $res = 1;
	for (my $i = 2; $i <= sqrt($arg); $i++) {
		unless ($arg % $i) {
			$res = 0;
		}
	}

	return $res;
}

for (my $i = 4; $i <= ($n / 2); $i++) {
	if (!isPrime($i) && !isPrime($n - $i)) {
		print($i . " " . ($n - $i));
		exit;
	}
}

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

chomp($n = <>);
$n%2==0 and say 4,' ',$n-4 or say 9,' ',$n-9;

#!/usr/bin/perl -w

use strict;

sub primeq {
    my $n = shift;
    return '' if $n < 2;
    for (2 .. sqrt($n) + 1) {
        return '' if $n % $_ == 0;
    }
    return 1;
}

my $n = <>;
for (4 .. $n / 2) {
    if (!primeq($_) && !primeq($n - $_)) {
        print "$_ ", $n - $_, "\n";
        last;
    }
}


You have $$$n$$$ gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The $$$i$$$-th gift consists of $$$a_i$$$ candies and $$$b_i$$$ oranges.During one move, you can choose some gift $$$1 \le i \le n$$$ and do one of the following operations:  eat exactly one candy from this gift (decrease $$$a_i$$$ by one);  eat exactly one orange from this gift (decrease $$$b_i$$$ by one);  eat exactly one candy and exactly one orange from this gift (decrease both $$$a_i$$$ and $$$b_i$$$ by one). Of course, you can not eat a candy or orange if it's not present in the gift (so neither $$$a_i$$$ nor $$$b_i$$$ can become less than zero).As said above, all gifts should be equal. This means that after some sequence of moves the following two conditions should be satisfied: $$$a_1 = a_2 = \dots = a_n$$$ and $$$b_1 = b_2 = \dots = b_n$$$ (and $$$a_i$$$ equals $$$b_i$$$ is not necessary).Your task is to find the minimum number of moves required to equalize all the given gifts.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of gifts. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the number of candies in the $$$i$$$-th gift. The third line of the test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 10^9$$$), where $$$b_i$$$ is the number of oranges in the $$$i$$$-th gift.

For each test case, print one integer: the minimum number of moves required to equalize all the given gifts.

NoteIn the first test case of the example, we can perform the following sequence of moves:  choose the first gift and eat one orange from it, so $$$a = [3, 5, 6]$$$ and $$$b = [2, 2, 3]$$$;  choose the second gift and eat one candy from it, so $$$a = [3, 4, 6]$$$ and $$$b = [2, 2, 3]$$$;  choose the second gift and eat one candy from it, so $$$a = [3, 3, 6]$$$ and $$$b = [2, 2, 3]$$$;  choose the third gift and eat one candy and one orange from it, so $$$a = [3, 3, 5]$$$ and $$$b = [2, 2, 2]$$$;  choose the third gift and eat one candy from it, so $$$a = [3, 3, 4]$$$ and $$$b = [2, 2, 2]$$$;  choose the third gift and eat one candy from it, so $$$a = [3, 3, 3]$$$ and $$$b = [2, 2, 2]$$$.


You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters.We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels: 'a', 'e', 'i', 'o', 'u' and 'y'.Each word of the text that contains at least one vowel can be divided into syllables. Each character should be a part of exactly one syllable. For example, the word "mamma" can be divided into syllables as "ma" and "mma", "mam" and "ma", and "mamm" and "a". Words that consist of only consonants should be ignored.The verse patterns for the given text is a sequence of n integers p1, p2, ..., pn. Text matches the given verse pattern if for each i from 1 to n one can divide words of the i-th line in syllables in such a way that the total number of syllables is equal to pi.You are given the text and the verse pattern. Check, if the given text matches the given verse pattern.

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of lines in the text. The second line contains integers p1, ..., pn (0 ≤ pi ≤ 100) — the verse pattern. Next n lines contain the text itself. Text consists of lowercase English letters and spaces. It's guaranteed that all lines are non-empty, each line starts and ends with a letter and words are separated by exactly one space. The length of each line doesn't exceed 100 characters.

If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).

4
13 11 15 15
to be or not to be that is the question
whether tis nobler in the mind to suffer
the slings and arrows of outrageous fortune
or to take arms against a sea of troubles

NoteIn the first sample, one can split words into syllables in the following way: in-telco-dech al-len-geSince the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one.

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

my $n = <>;
my @arr = split " ", <>;
# print "@arr";
my $ans = "YES";
for (0..$n-1) {
  my $count = 0;
  chomp(my $line = <>);
  $count = () = $line =~ /[aeiouy]/g;
  if ($count != $arr[$_]) {
    $ans = "NO";
    last;
  }
}
print "$ans\n";

$n = int(<STDIN>);
@k = split(/ /, <STDIN>);
my $i = 0;
while(<STDIN>) {
    if(($_ =~ tr/[aeiouy]//) != $k[$i]) {
        print "NO\n";
        exit 0;
    }
    $i++;
}
print "YES\n";

my $n = <> + 0;
my $P = <>;
my @pp = split ' ', $P;

for (my $i = 0; $i < $n; ++$i) {
	my $line = <>;
	my @lets = split //, $line;
	foreach (@lets) {
		--$pp[$i] if /a|e|i|o|u|y/;
	}
	if ($pp[$i] != 0){
		print "NO\n";
		exit 0;
	}
}
print "YES\n";

<>;

print <> =~ s/\n//r eq (join ' ', map y/yaeiou//d, <>) ? "YES" : "NO"

<>;

@_ = split ' ', <>;

y/yaeiou//d == shift @_ or $f++ while <>;

print $f ? "NO" : "YES"


Let $$$s(x)$$$ be sum of digits in decimal representation of positive integer $$$x$$$. Given two integers $$$n$$$ and $$$m$$$, find some positive integers $$$a$$$ and $$$b$$$ such that   $$$s(a) \ge n$$$,  $$$s(b) \ge n$$$,  $$$s(a + b) \le m$$$.

The only line of input contain two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1129$$$).

Print two lines, one for decimal representation of $$$a$$$ and one for decimal representation of $$$b$$$. Both numbers must not contain leading zeros and must have length no more than $$$2230$$$.

NoteIn the first sample, we have $$$n = 6$$$ and $$$m = 5$$$. One valid solution is $$$a = 6$$$, $$$b = 7$$$. Indeed, we have $$$s(a) = 6 \ge n$$$ and $$$s(b) = 7 \ge n$$$, and also $$$s(a + b) = s(13) = 4 \le m$$$.