Dima got into number sequences. Now he's got sequence a1, a2, ..., an, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence:  f(0) = 0;  f(2·x) = f(x);  f(2·x + 1) = f(x) + 1. Dima wonders, how many pairs of indexes (i, j) (1 ≤ i < j ≤ n) are there, such that f(ai) = f(aj). Help him, count the number of such pairs.

The first line contains integer n (1 ≤ n ≤ 105). The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). The numbers in the lines are separated by single spaces.

In a single line print the answer to the problem. Please, don't use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

NoteIn the first sample any pair (i, j) will do, so the answer is 3.In the second sample only pair (1, 2) will do.

#!/usr/bin/perl

#print "Content-type: text/html\n\n";
#print "
Hello!
\n";

$n=<>;
@dig;   $sum=0;
@num=split(/ /,<>);

for $i(0..$n-1)
{      $digi=0;
     while($num[$i])
     {
        $digi+=($num[$i]&1); $num[$i]>>=1;
     }
     $sum+=$dig[$digi]++;
}

print $sum;


A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to n clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if n = 5, then after the third throw the child number 2 has the ball again. Overall, n - 1 throws are made, and the game ends.The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw.

The first line contains integer n (2 ≤ n ≤ 100) which indicates the number of kids in the circle.

In the single line print n - 1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.


They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so.Limak is a little polar bear who loves to play. He has recently got a rectangular grid with h rows and w columns. Each cell is a square, either empty (denoted by '.') or forbidden (denoted by '#'). Rows are numbered 1 through h from top to bottom. Columns are numbered 1 through w from left to right.Also, Limak has a single domino. He wants to put it somewhere in a grid. A domino will occupy exactly two adjacent cells, located either in one row or in one column. Both adjacent cells must be empty and must be inside a grid.Limak needs more fun and thus he is going to consider some queries. In each query he chooses some rectangle and wonders, how many way are there to put a single domino inside of the chosen rectangle?

The first line of the input contains two integers h and w (1 ≤ h, w ≤ 500) – the number of rows and the number of columns, respectively. The next h lines describe a grid. Each line contains a string of the length w. Each character is either '.' or '#' — denoting an empty or forbidden cell, respectively. The next line contains a single integer q (1 ≤ q ≤ 100 000) — the number of queries. Each of the next q lines contains four integers r1i, c1i, r2i, c2i (1 ≤ r1i ≤ r2i ≤ h, 1 ≤ c1i ≤ c2i ≤ w) — the i-th query. Numbers r1i and c1i denote the row and the column (respectively) of the upper left cell of the rectangle. Numbers r2i and c2i denote the row and the column (respectively) of the bottom right cell of the rectangle.

Print q integers, i-th should be equal to the number of ways to put a single domino inside the i-th rectangle.

NoteA red frame below corresponds to the first query of the first sample. A domino can be placed in 4 possible ways.


The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil.

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of cities. The next line contains n integers, separated by single spaces: the i-th integer represents the time needed to go from town Rozdil to the i-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to n, inclusive. Rozdil is not among the numbered cities.

Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).

NoteIn the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil".

chomp (my $n = <STDIN>);
chomp (my @num = split /\s+/, <STDIN>);

my ($min,$pos)=(1+(10**9),-1);
for (my $i=0; $i<$n; $i++) {
  if ($num[$i]<$min) {
    $min = $num[$i];
    $pos = $i+1;
  } elsif ($num[$i]==$min) {
    $pos = -1;
  }
}
if ($pos == -1) {
  print "Still Rozdil\n";
} else {
  print "$pos";
}

#!perl
use strict;
use warnings;

<>;
my $istr = <>;
my @arr = map int, split /\D/, $istr;
my $min = shift @arr;
my $mini = 1;
my $double = 0;
my $index_shift = 2;
for my $i ( 0 .. @arr-1 ) {
    if ( $arr[$i] == $min ) {
        $double = 1;
    } elsif ( $arr[$i] < $min ) {
        $min = $arr[$i];
        $mini = $i + $index_shift;
        $double = 0;
    }
}
if ( $double ) {
    print 'Still Rozdil';
} else {
    print $mini;
}

__END__

#!/usr/bin/perl

use strict;
use warnings;

my $num =<>;
my $min=10000000000;
my $min_num=0;
my $city;
my @cities=split(' ',<>);
foreach my $i(1..$num){
	if($cities[$i-1]<$min){
		$min=$cities[$i-1];
		$city=$i;
		$min_num=1;
	}
	elsif($cities[$i-1]==$min){
		$min_num++;
	}
}
if($min_num==1){
	print $city;
}else{
	print"Still Rozdil";
}


You are an upcoming movie director, and you have just released your first movie. You have also launched a simple review site with two buttons to press — upvote and downvote.However, the site is not so simple on the inside. There are two servers, each with its separate counts for the upvotes and the downvotes.$$$n$$$ reviewers enter the site one by one. Each reviewer is one of the following types:   type $$$1$$$: a reviewer has watched the movie, and they like it — they press the upvote button;  type $$$2$$$: a reviewer has watched the movie, and they dislike it — they press the downvote button;  type $$$3$$$: a reviewer hasn't watched the movie — they look at the current number of upvotes and downvotes of the movie on the server they are in and decide what button to press. If there are more downvotes than upvotes, then a reviewer downvotes the movie. Otherwise, they upvote the movie. Each reviewer votes on the movie exactly once.Since you have two servers, you can actually manipulate the votes so that your movie gets as many upvotes as possible. When a reviewer enters a site, you know their type, and you can send them either to the first server or to the second one.What is the maximum total number of upvotes you can gather over both servers if you decide which server to send each reviewer to?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. Then the descriptions of $$$t$$$ testcases follow. The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of reviewers. The second line of each testcase contains $$$n$$$ integers $$$r_1, r_2, \dots, r_n$$$ ($$$1 \le r_i \le 3$$$) — the types of the reviewers in the same order they enter the site.

For each testcase print a single integer — the maximum total number of upvotes you can gather over both servers if you decide which server to send each reviewer to.

NoteIn the first testcase of the example you can send the only reviewer to either of the servers — they'll downvote anyway. The movie won't receive any upvotes.In the second testcase of the example you can send all reviewers to the first server:   the first reviewer upvotes;  the second reviewer downvotes;  the last reviewer sees that the number of downvotes is not greater than the number of upvotes — upvote themselves. There are two upvotes in total. Alternatevely, you can send the first and the second reviewers to the first server and the last reviewer — to the second server:   the first reviewer upvotes on the first server;  the second reviewer downvotes on the first server;  the last reviewer sees no upvotes or downvotes on the second server — upvote themselves.

chomp(my $q = <STDIN>);
foreach (1..$q)
{
    <STDIN>;
    chomp($inp = <STDIN>);
    @a = split / /, $inp;
    $res = 0;
    foreach (@a)
    {
        $res++ if $_ != 2;
    }
    print $res, "\n";
}

chomp(my $q = <STDIN>);
foreach (1..$q)
{
    <STDIN>;
    chomp($inp = <STDIN>);
    @a = split / /, $inp;
    foreach (@a)
    {
        $res++ if $_ != 2;
    }
    print $res, "\n";
}


It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers x and y from the board, he gets gcd(x, y) points. At the beginning of the game Bimokh has zero points.Mashmokh wants to win in the game. For this reason he wants his boss to get exactly k points in total. But the guy doesn't know how choose the initial sequence in the right way. Please, help him. Find n distinct integers a1, a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109.

The first line of input contains two space-separated integers n, k (1 ≤ n ≤ 105; 0 ≤ k ≤ 108).

If such sequence doesn't exist output -1 otherwise output n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Notegcd(x, y) is greatest common divisor of x and y.


Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions:  $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty.  $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells.    These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$.

The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$.

NoteIn the first example, this is the other possible case.  In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

our $fail;

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

    my( $h, $w ) = split;

    @_ = ( 0 x $w ) x $h;

    my @h = split ' ', <>;
    my @w = split ' ', <>;

    $fail = 0;

    fill( \@h, \@_ );

    $debug and print for @_;

    @_ = transpose( \@_ );

    $debug and print for @_;

    fill( \@w, \@_ );

    $debug and print for @_;

    $debug and print "fail: $fail";

    my $cnt = 0;

    map { $cnt += () = /0/g } @_;

    $debug and print "cnt: $cnt";

    print $fail ? 0 : do {
        my $j = 1;
        for my $i ( 1 .. $cnt ){
            $j *= 2;
            $j %= ( 1e9 + 7 );
            }
        $j;
        };
	}

sub fill {
    my( $ref_fills, $ref_main ) = @_;

    for my $i ( 0 .. @{ $ref_fills } - 1 ){
        $ref_main->[ $i ] =~ s/
            ^[01]{$ref_fills->[ $i ]}(?!1)(.)?
            /
            1 x $ref_fills->[ $i ] . ( defined $1 ? 2 : '' );
            /xe or $fail = 1;
        }
    }

sub transpose {
    my $ref = shift;

    my @new;

    for my $i ( 0 .. -1 + length $ref->[ 0 ] ){
        push @new, join '', map { chop } @{ $ref };
        }

    return reverse @new;
    }

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

our $fail;

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

    my( $h, $w ) = split;

    @_ = ( 0 x $w ) x $h;

    my @h = split ' ', <>;
    my @w = split ' ', <>;

    $fail = 0;

    fill( \@h, \@_ );

    $debug and print for @_;

    @_ = transpose( \@_ );

    $debug and print for @_;

    fill( \@w, \@_ );

    $debug and print for @_;

    $debug and print "fail: $fail";

    my $cnt = 0;

    map { $cnt += () = /0/g } @_;

    $debug and print "cnt: $cnt";

    print $fail ? 0 : 2 ** $cnt % ( 1e9 + 7 );
	}

sub fill {
    my( $ref_fills, $ref_main ) = @_;

    for my $i ( 0 .. @{ $ref_fills } - 1 ){
        $ref_main->[ $i ] =~ s/
            ^[01]{$ref_fills->[ $i ]}(?!1)(.)?
            /
            1 x $ref_fills->[ $i ] . ( defined $1 ? 2 : '' );
            /xe or $fail = 1;
        }
    }

sub transpose {
    my $ref = shift;

    my @new;

    for my $i ( 0 .. -1 + length $ref->[ 0 ] ){
        push @new, join '', map { chop } @{ $ref };
        }

    return reverse @new;
    }

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

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

    @_ = ( 0 x $w ) x $h;

    my @h = split ' ', <>;
    my @w = split ' ', <>;

    fill( \@h, \@_ );

    #$debug and print for @_;

    @_ = transpose( \@_ );

    #$debug and print for @_;

    fill( \@w, \@_ );

    #$debug and print for @_;

    my $cnt = 0;

    map { $cnt += () = /0/g } @_;

    #$debug and print "cnt: $cnt";

    print 2 ** $cnt % ( 1e9 + 7 );
	}

sub fill {
    my( $ref_fills, $ref_main ) = @_;

    for my $i ( 0 .. @{ $ref_fills } - 1 ){
        substr $ref_main->[ $i ], 0, $ref_fills->[ $i ], 1 x $ref_fills->[ $i ];
        substr $ref_main->[ $i ], $ref_fills->[ $i ], 1, 2
            if $ref_fills->[ $i ] < length $ref_main->[ $i ];
        }
    }

sub transpose {
    my $ref = shift;

    my @new;

    for my $i ( 0 .. -1 + length $ref->[ 0 ] ){
        push @new, join '', map { chop } @{ $ref };
        }

    return reverse @new;
    }

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

our $fail;

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

    my( $h, $w ) = split;

    @_ = ( 0 x $w ) x $h;

    my @h = split ' ', <>;
    my @w = split ' ', <>;

    $fail = 0;

    fill( \@h, \@_ );

    $debug and print for @_;

    @_ = transpose( \@_ );

    $debug and print for @_;

    fill( \@w, \@_ );

    $debug and print for @_;

    $debug and print "fail: $fail";

    my $cnt = 0;

    map { $cnt += () = /0/g } @_;

    $debug and print "cnt: $cnt";

    print $fail ? 0 : 2 ** $cnt % ( 1e9 + 7 );
	}

sub fill {
    my( $ref_fills, $ref_main ) = @_;

    for my $i ( 0 .. @{ $ref_fills } - 1 ){
        #substr $ref_main->[ $i ], 0, $ref_fills->[ $i ], 1 x $ref_fills->[ $i ];
        #substr $ref_main->[ $i ], $ref_fills->[ $i ], 1, 2
        #    if $ref_fills->[ $i ] < length $ref_main->[ $i ];
        $ref_main->[ $i ] =~ s/
            ^[01]{$ref_fills->[ $i ]}(.)?
            /
            1 x $ref_fills->[ $i ] . ( defined $1 ? 2 : '' );
            /xe or $fail = 1;
        }
    }

sub transpose {
    my $ref = shift;

    my @new;

    for my $i ( 0 .. -1 + length $ref->[ 0 ] ){
        push @new, join '', map { chop } @{ $ref };
        }

    return reverse @new;
    }


On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya also remembers that there was at most one event in one day. Help him choose such n dates of famous events that will fulfill both conditions. It is guaranteed that it is possible.

The first line contains one integer n (1 ≤ n ≤ 100) — the number of known events. Then follow n lines containing two integers li and ri each (1 ≤ li ≤ ri ≤ 107) — the earliest acceptable date and the latest acceptable date of the i-th event.

Print n numbers — the dates on which the events took place. If there are several solutions, print any of them. It is guaranteed that a solution exists.

sub max { my ($a, $b) = @_; $a > $b? $a: $b }
sub priority { max($a->{start}, $current) <=> max($b->{start}, $current) || $a->{end} <=> $b->{end} }

(undef, @input) = <STDIN>;
for (@input) {
	@val = split;
	push @p, {start => $val[0], end => $val[1], index => $i++ }
}

while (@p) {
	($p, @p) = sort priority @p;
	$current = max $p->{start}, $current;
	$r[ $p->{index} ] = $current++;
}

print "@r";

sub compare { $a <=> $b }
sub max { my ($a, $b) = @_; $a > $b? $a: $b }

(undef, @input) = <STDIN>;
for (@input) { push @p, (split)[0] }
@p = sort compare @p;

for $p (@p) {
	$d = max $p, $d;
	push @r, $d;
	$d++;
}

print "@r";


Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.Help him do this!

The first line contains integer n (1 ≤ n ≤ 200 000) — the length of strings S and T. The second line contains string S. The third line contains string T. Each of the lines only contains lowercase Latin letters.

In the first line, print number x — the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S. In the second line, either print the indexes i and j (1 ≤ i, j ≤ n, i ≠ j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters. If there are multiple possible answers, print any of them.

NoteIn the second test it is acceptable to print i = 2, j = 3.

use strict;
use warnings;
<>;
my $a = 0;

my @first = split //, <>;
my @second = split //, <>;
my %s;
my @matrix;
for(0..$#first - 1)
{
    unless ($first[$_] eq $second[$_])
    {
        $s{$first[$_].$second[$_]} = $_ ;
        $matrix[ord ($first[$_]) - (ord 'a')][ord ($second[$_]) - ord( 'a')] = $_;
        $a++;
    }

}

for my $key (keys %s)
{
    my $key2 = do{$key =~ /(.)(.)/; $2.$1};
    if (defined $s{$key2})
    {
        print $a - 2,"\n";
        printf "%i %i\n",  $s{$key}+1 ,$s{$key2}+1;
        exit 0;
    }
}

for my $f (0..$#matrix)
{
    for my $s (0..$#{$matrix[$f]})
    {
        if(defined $matrix[$f][$s])
        {
            for my $f2 (0..$#matrix)
            {
                if(defined($matrix[$f2][$f])  )
                {
                    printf "%i\n%i %i", $a - 1,$matrix[$f2][$f] + 1, $matrix[$f][$s] + 1;
                    exit 0;
                }
            }
        }
    }
}
printf "%i\n%i %i", $a,-1, -1;

$\ = $/;
while(<>){
	$n = $_;
	chomp ($A=<>);
	chomp ($B=<>);
	undef %h;
	undef $ans;
	$k = 0;
	for $i (0 .. -1 + length $A){
		$a = chop $A;
		$b = chop $B;
	#	print $a," ",$b;
		$a eq $b and $k ++;
		$a ne $b and do { $h{$a.$b} = $n - $i };

	}
	$, = $";
#	print %h;
	$k = $n - $k;

	OUT:
	for $i (keys %h){
		for $j (keys %h){
			$i eq (reverse $j) and do { $ans = $h{$i}." ".$h{$j}; $k --;  last OUT};
			(substr $i, 0, 1) eq (substr $j, 1, 1) and do { $ans = $h{$i}." ".$h{$j} };
		}

	}
	$ans and $k--;
	print $k;
	print $ans ? $ans : "-1 -1";
}

use strict;
use warnings;use List::Util qw(first max maxstr min minstr reduce shuffle sum);
use Data::Dumper;
<>;
chomp (my $t = <>);
my @S = split //, $t;

chomp ($t = <>);
my @T = split //, $t;
my $ans = 0;

my @di;
my %TT;
my %SS;
for(0.. $#S)
{
    if($S[$_] ne $T[$_])
    {
        $ans ++;
        push @di, $_;
        push @{$TT{$T[$_]}}, $_;
        push @{$SS{$S[$_]}}, $_;
    }
}

my @TTL = keys %TT;
my @SSL = keys %SS;
my @sht;

for my $l ('a'..'z')
{
    my @tttl = grep {$_ eq $l} @TTL;
    my @tssl = grep {$_ eq $l} @SSL;

    if($#tttl != -1 and $#tssl != -1)
    {
        push (@sht, $l);
    }
}
if( $#sht == -1)
{
    print "$ans\n-1 -1";
    exit 0;
}

if( $#sht == 0)
{
    $ans--;
    my $let = $sht[0];
    my $l =  $TT{$let}->[0];
    my $r =  $SS{$let}->[0];
    print $ans,"\n";

    print min($l+1,$r+1)," ", max($l+1,$r+1);
    exit 0;
}
my %rr = map {$_, 1} @sht;
for my $e (keys %rr)
{
    for(@{$TT{$e}})
    {
        if(defined $rr{$S[$_]})
        {
            print $ans-2,"\n";
            my $l = $_;
            my $r = $TT{$S[$_]}->[0];
            print    min($l+1,$r+1)," ", max($l+1,$r+1);
            exit 0;
        }
    }
}
print "такого я не ожидал( ";

$\ = $/;
while(<>){
	$n = $_;
	chomp ($A=<>);
	chomp ($B=<>);
	undef %h;
	undef $ans;
	for $i (0 .. -1 + length $A){
		$a = chop $A;
		$b = chop $B;
	#	print $a," ",$b;
		$a ne $b and do { $h{$a.$b} = $n - $i };

	}
	$, = $";
#	print %h;

	OUT:
	for $i (keys %h){
		for $j (keys %h){
			$i eq (reverse $j) and do { $ans = $h{$i}." ".$h{$j}; last OUT};
			(substr $i, 0, 1) eq (substr $j, 1, 1) and do { $ans = $h{$i}." ".$h{$j} };
		}

	}
	print $ans ? $ans : "-1 -1";
}


A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba".If string s has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible.Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.

The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s. The second line contains the string s of length n consisting of only lowercase English letters.

If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.

NoteIn the first sample one of the possible solutions is to change the first character to 'b'.In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".

<>,<> =~ /.+/;
$_ = join '', sort split //, $&;
print length > 26 ? -1 : (length) - length y///csr


Valera is a collector. Once he wanted to expand his collection with exactly one antique item.Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller is sij. Valera gets on well with each of the n sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him.Unfortunately, Valera has only v units of money. Help him to determine which of the n sellers he can make a deal with.

The first line contains two space-separated integers n, v (1 ≤ n ≤ 50; 104 ≤ v ≤ 106) — the number of sellers and the units of money the Valera has. Then n lines follow. The i-th line first contains integer ki (1 ≤ ki ≤ 50) the number of items of the i-th seller. Then go ki space-separated integers si1, si2, ..., siki (104 ≤ sij ≤ 106) — the current prices of the items of the i-th seller.

In the first line, print integer p — the number of sellers with who Valera can make a deal. In the second line print p space-separated integers q1, q2, ..., qp (1 ≤ qi ≤ n) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.

NoteIn the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him.

my ($n, $money) = split / /, <>;
my @ans;
for(1..$n) {
    push @ans, $_ if($money > (sort{$a <=> $b} split / /, <>)[1]);
}
print scalar @ans . "\n@ans";

$i=0;
$in = <>;
( $n, $v ) = split( ' ', $in );
while($n--){
    $line = <>;
    ( $item, @items ) = split( ' ', $line );
    foreach (@items) {
        if ( $_ < $v ) {
            push( @res, ( $i + 1 ) );
            last;
        }
    }
$i++;
}
print ($#res+1); print "\n";
print join(' ',@res);

( $n, $v ) = split( ' ', <> );
for $i ( 1 .. $n ) {
    $line = <>;
    ( $item, @items ) = split( ' ', $line );
    foreach (@items) {
        if ( $_ < $v ) {
            push( @res, $i );
            last;
        }
    }
}
print( $#res+ 1 ) and print "\n@res";


Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, second one is love, third one is hate and so on...For example if n = 1, then his feeling is "I hate it" or if n = 2 it's "I hate that I love it", and if n = 3 it's "I hate that I love that I hate it" and so on.Please help Dr. Banner.

The only line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of layers of love and hate.

I hate it
I hate that I love it
I hate that I love that I hate it

$n = <>; $_ = join " that ", ("I hate") x $n;
s/I hate that I hate/I hate that I love/g;
print "$_ it";

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

my $n = <> + 0;
my @feelings = ();

for (my $i = 0; $i < $n; $i++) {
    if($i % 2 eq 0) {
        push(@feelings, "I hate");
    } else {
        push(@feelings, "I love");
    }
}

my $result = join(" that ", @feelings);
print $result . " it\n";

#!/usr/bin/perl

use strict;
use warnings;

my $n = <>;
my @items = qw(hate love);
my $i = 0;

my @words;

for (1..$n) {
    push @words, 'I', $items[$i], 'that';
    $i = !$i;
}

$words[$#words] = 'it';

$\ = "\n";
$, = ' ';
print @words;

#!/usr/bin/env perl

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

# essential
my @tokens = ();

my $n = read_token();

my $answer = 'I hate ';
$n--;

my $m = 0;

while ( $n > 0 ) {
    if ( $m % 2 == 0 ) {
        $answer .= 'that I love ';
    }
    else {
        $answer .= 'that I hate ';
    }
    $m++;
    $n--;
}

$answer .= 'it';

say $answer;

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

# cf706a # solution courtesy 19744936	s_p
use strict;
my $n=<>;
$_=join(' that ',('I hate') x $n)." it";
print s/I hate that I hate/I hate that I love/gr;


Sehr Sus is an infinite hexagonal grid as pictured below, controlled by MennaFadali, ZerooCool and Hosssam.They love equilateral triangles and want to create $$$n$$$ equilateral triangles on the grid by adding some straight lines. The triangles must all be empty from the inside (in other words, no straight line or hexagon edge should pass through any of the triangles).You are allowed to add straight lines parallel to the edges of the hexagons. Given $$$n$$$, what is the minimum number of lines you need to add to create at least $$$n$$$ equilateral triangles as described?  Adding two red lines results in two new yellow equilateral triangles.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^{9}$$$) — the required number of equilateral triangles.

For each test case, print the minimum number of lines needed to have $$$n$$$ or more equilateral triangles.

NoteIn the first and second test cases only 2 lines are needed. After adding the first line, no equilateral triangles will be created no matter where it is added. But after adding the second line, two more triangles will be created at once.   In the third test case, the minimum needed is 3 lines as shown below.


Stepan likes to repeat vowel letters when he writes words. For example, instead of the word "pobeda" he can write "pobeeeedaaaaa".Sergey does not like such behavior, so he wants to write a program to format the words written by Stepan. This program must combine all consecutive equal vowels to a single vowel. The vowel letters are "a", "e", "i", "o", "u" and "y".There are exceptions: if letters "e" or "o" repeat in a row exactly 2 times, like in words "feet" and "foot", the program must skip them and do not transform in one vowel. For example, the word "iiiimpleeemeentatiioon" must be converted to the word "implemeentatioon".Sergey is very busy and asks you to help him and write the required program.

The first line contains the integer n (1 ≤ n ≤ 100 000) — the number of letters in the word written by Stepan. The second line contains the string s which has length that equals to n and contains only lowercase English letters — the word written by Stepan.

Print the single string — the word written by Stepan converted according to the rules described in the statement.

pobeda implemeentatioon aeiouyaeeioouy aoiuyeggghhh

my $first;
while (<>) {
    $first++ or next;
    s/a+/a/g;
    s/eee+/e/g;
    s/i+/i/g;
    s/ooo+/o/g;
    s/u+/u/g;
    s/y+/y/g;
    print;
}

use warnings;
use strict;
my $n = int <>;
my $s = <>;
my @s = split //, $s;
my $cur = '-';
my $cnt = 0;
for my $i (0..$n) {
    if ($s[$i] eq $cur) {
        $cnt += 1;
    } else {
        unless ($cur eq '-') {
            if ($cnt == 2 and ($cur eq 'e' or $cur eq 'o')) {
                print $cur;
                print $cur;
            } elsif ($cur eq 'e' or $cur eq 'o' or $cur eq 'i' or $cur eq 'a' or $cur eq 'y' or $cur eq 'u') {
                print $cur;
            } else {
                for (0..$cnt-1) {
                    print $cur;
                }
            }
        }
        $cnt = 1;
        $cur = $s[$i];
    }
}
print "\n";

$lineno = 0;
while ($line = <STDIN>){
    if ($lineno == 0) {
        $lineno += 1;
    } else {
        $line =~ s/[a]+/a/g;
        $line =~ s/[e]{3,}/e/g;
        $line =~ s/[i]+/i/g;
        $line =~ s/[o]{3,}/o/g;
        $line =~ s/[u]+/u/g;
        $line =~ s/[y]+/y/g;
        print $line;
        last;
    }
}

#!/usr/bin/perl
# your code goes here
my $len = <STDIN>;
my $str = <STDIN>;
$str =~ s/a+/a/g;
$str =~ s/eee+/e/g;
$str =~ s/i+/i/g;
$str =~ s/ooo+/o/g;
$str =~ s/u+/u/g;
$str =~ s/y+/y/g;
print $str;

$string = <>; $string = <>;
$string =~ s/a+/a/g;
$string =~ s/i+/i/g;
$string =~ s/u+/u/g;
$string =~ s/y+/y/g;
$string =~ s/eee+/e/g;
$string =~ s/ooo+/o/g;
print($string)

#! /usr/bin/env perl

use strict;
use warnings;

<>;
$_ = <>;

s/a+/a/g;
s/eee+/e/g;
s/i+/i/g;
s/ooo+/o/g;
s/u+/u/g;
s/y+/y/g;

print $_;

$lineno = 0;
while ($line = <STDIN>){
    if ($lineno == 0) {
        $lineno += 1;
    } else {
        $line =~ s/[a]+/a/g;
        $line =~ s/[e]{3,}/e/g;
        $line =~ s/[i]+/i/g;
        $line =~ s/[o]{3,}/o/g;
        $line =~ s/[u]+/u/g;
        print $line;
        last;
    }
}

#! /usr/bin/env perl

use strict;
use warnings;

<>;
$_ = <>;

s/a+/a/g;
s/e+/e/g;
s/i+/i/g;
s/o+/o/g;
s/u+/u/g;
s/y+/y/g;

print $_;

#! /usr/bin/env perl

use strict;
use warnings;

# my $n = <>;
# <>;
$_ = <>;

s/a+/a/g;
s/e+/e/g;
s/i+/i/g;
s/o+/o/g;
s/u+/u/g;
s/y+/y/g;

print $_;


The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops.If $$$x$$$ is the number of passengers in a bus just before the current bus stop and $$$y$$$ is the number of passengers in the bus just after current bus stop, the system records the number $$$y-x$$$. So the system records show how number of passengers changed.The test run was made for single bus and $$$n$$$ bus stops. Thus, the system recorded the sequence of integers $$$a_1, a_2, \dots, a_n$$$ (exactly one number for each bus stop), where $$$a_i$$$ is the record for the bus stop $$$i$$$. The bus stops are numbered from $$$1$$$ to $$$n$$$ in chronological order.Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $$$w$$$ (that is, at any time in the bus there should be from $$$0$$$ to $$$w$$$ passengers inclusive).

The first line contains two integers $$$n$$$ and $$$w$$$ $$$(1 \le n \le 1\,000, 1 \le w \le 10^{9})$$$ — the number of bus stops and the capacity of the bus. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(-10^{6} \le a_i \le 10^{6})$$$, where $$$a_i$$$ equals to the number, which has been recorded by the video system after the $$$i$$$-th bus stop.

Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $$$w$$$. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0.

NoteIn the first example initially in the bus could be $$$0$$$, $$$1$$$ or $$$2$$$ passengers.In the second example initially in the bus could be $$$1$$$, $$$2$$$, $$$3$$$ or $$$4$$$ passengers.In the third example initially in the bus could be $$$0$$$ or $$$1$$$ passenger.

# author : Gabriel Hofer
use strict;
use warnings;
use constant NL => qq/\n/;
sub max { $_ [ 0 ] > $_ [ 1 ] ? $_ [ 0 ] : $_ [ 1 ] }
my ( $n, $w ) = split qq/ /, <STDIN>;
my @one = split qq/ /, <STDIN>;
# assumption : 0 people are initially on the bus
my ($max, $min, $sum);
$max = $min = $sum = 0;
AA: for my $i ( @one ) {
    $sum += $i;
    if ( $sum < $min ) { $min = $sum }
    if ( $sum > $max ) { $max = $sum }
}
print (max (0, ($w - ($max - $min) + 1)), NL);

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $sum = 0;

	my $min = 0;
	my $max = 0;

	for( @_ ){
		$sum += $_;
		$sum < $min and $min = $sum;
		$sum > $max and $max = $sum;
		}

#%	print "[$min|$max]";

	my $ans = ( $w - $max + 1 ) - ( -$min );

	print $ans < 0 ? 0 : $ans;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $sum = 0;

	my $min = 0;
	my $max = 0;

	for( @_ ){
		$sum += $_;
		$sum < $min and $min = $sum;
		$sum > $max and $max = $sum;
		}

#%	print "[$min|$max]";

	print 1 + $w - ( $max - $min );
	}


Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.

The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.

Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.

my $n = int<>;
my $odd = 0;
my @arr = split / /, <>;
$odd += $_ % 2 for(@arr);
my %hash;
$hash{$arr[$_ - 1] % 2} = $_ foreach(1..$n);

if ($odd == 1) {
    print $hash{1};
}
else {
    print $hash{0};
}

#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
my ($odd, $even, $last_odd, $last_even) = (0, 0, 0, 0);
$_ = <>;
my @numbers = split(' ', <>);

foreach my $i (1..scalar(@numbers))
{
    my $number = $numbers[$i-1];
    if ($number % 2 == 0)
    {
        $even++;
        $last_even = $i;
    }
    else
    {
        $odd++;
        $last_odd = $i;
    }
}

print $even > $odd ? $last_odd : $last_even;


You came to a local shop and want to buy some chocolate bars. There are $$$n$$$ bars in the shop, $$$i$$$-th of them costs $$$a_i$$$ coins (and you want to buy all of them).You have $$$m$$$ different coupons that allow you to buy chocolate bars. $$$i$$$-th coupon allows you to buy $$$q_i$$$ chocolate bars while you have to pay only for the $$$q_i - 1$$$ most expensive ones (so, the cheapest bar of those $$$q_i$$$ bars is for free).You can use only one coupon; if you use coupon $$$i$$$, you have to choose $$$q_i$$$ bars and buy them using the coupon, and buy all the remaining $$$n - q_i$$$ bars without any discounts.To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$) — the number of chocolate bars in the shop. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the cost of $$$i$$$-th chocolate bar. The third line contains one integer $$$m$$$ ($$$1 \le m \le n - 1$$$) — the number of coupons you have. The fourth line contains $$$m$$$ integers $$$q_1$$$, $$$q_2$$$, ..., $$$q_m$$$ ($$$2 \le q_i \le n$$$), where $$$q_i$$$ is the number of chocolate bars you have to buy using $$$i$$$-th coupon so that the least expensive of them will be for free. All values of $$$q_i$$$ are pairwise distinct.

Print $$$m$$$ integers, $$$i$$$-th of them should be the minimum amount of money you have to pay if you buy $$$q_i$$$ bars with $$$i$$$-th coupon, and all the remaining bars one by one for their full price.

NoteConsider the first example.If we use the first coupon, we may choose chocolate bars having indices $$$1$$$, $$$6$$$ and $$$7$$$, and we pay $$$18$$$ coins for them and $$$9$$$ coins for all other bars.If we use the second coupon, we may choose chocolate bars having indices $$$1$$$, $$$5$$$, $$$6$$$ and $$$7$$$, and we pay $$$25$$$ coins for them and $$$5$$$ coins for all other bars.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $sum = 0;

	$sum += $_ for @_;

	<>;

	my @ans;

	for my $i ( split ' ', <> ){
		push @ans, $sum - $_[ $i - 1 ];
		}

	print for @ans;
	}


Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.

The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops.  Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement.   The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0.  At the last stop, all the passengers exit the tram and it becomes empty. More formally, .  No passenger will enter the train at the last stop. That is, bn = 0.

Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).

NoteFor the first example, a capacity of 6 is sufficient:   At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3.  At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now.  At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now.  Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.

#!/usr/bin/perl

use 5.012;
use warnings;

chomp(my $stops = <>);

my $cnt = 0;
my $max = 0;
while ($stops--) {
	chomp(my $line = <>);
	my ($exit, $enter) = split / /, $line;
	$cnt = $cnt - $exit + $enter;
	$max = $cnt if $cnt > $max;
}
print $max;

my $n = <STDIN>;
my $max = 0;
my $count = 0;
while($n--) {
    my($a, $b) = split(' ', <STDIN>);
    $count = $count - $a + $b;
    $max = ($max > $count) ? $max : $count;
}
print $max;

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

chomp($n = <>);
$ans = 0;
$tot = 0;
while ($n-- > 0) {
	($a, $b) = split / /, <>;
	$tot += $b - $a;
	$ans = $tot>$ans ? $tot:$ans;
}
print $ans;

use strict;
use warnings;

my $n = <>;
chomp($n);
die('n is wrong') unless $n >= 2 && $n <= 1000;

my $max = 0;
my $current = 0;
for (my $i = 0; $i < $n; $i++) {
    my $line = <>;
    chomp($line);
    my ($a, $b) = split(' ', $line);
    #check if a,b is 0<a,b<=1000
    #max 1000 per stop for 1000 stops. mean max=1M passangers. fits in int

    $current -= $a;
    die('wrong input') if $current < 0;

    $current += $b;

    if ($current > $max) {
        $max = $current;
    }
}

print $max;

chomp($numstops=<STDIN>);
my $max = -1;
my $capa = 0;
while($numstops-- > 0) {
	chomp($line = <STDIN>);
	($l, $b) = $line =~ /(\d+)\s+(\d+)/;

	$capa = $capa - $l + $b;
	$max = $capa if($capa > $max);
}
print "$max\n";

use strict;
use warnings;

my $n = <>;
my $mx = 0;
my $curr = 0;
for (1..$n) {
    my ($a, $b) = split ' ', <>;
    $curr += $b - $a;
    $mx = $curr if $mx < $curr;
}

print "$mx\n";

chomp(my $testCase=<STDIN>);
my @maximum;
my $sum = 0;
while($testCase){
	chomp(my $values = <STDIN>);
	my @arr = split / /,$values;
	$sum -= $arr[0];
	$sum += $arr[1];
	push (@maximum,$sum);
	$testCase--;
}
my $answer;
my @articles = sort {$b <=> $a} @maximum;
$answer = $articles[0];
print $answer;

<stdin>; my ($count, $res)=(0,0); do{ chomp; my ($out, $in) = split(" "); $count-=$out; $count += $in; ;$res = ($res > $count ? $res : $count) } while <stdin>; print "$res\n"

<stdin>; @res=(0,0); do{ chomp; my ($out, $in) = split " ", $_; $res[0]-=$out; $res[0] += $in; $res[1] = $res[0] if $res[0] > $res[1] } while <stdin>; print "$res[1]\n"

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

<STDIN>; my ($max, $cap, $out, $in) = 0;
while (<STDIN>)
{ ($out, $in) = split ' ', $_; $cap += $in - $out;
  $max = $cap if $max < $cap }
print $max . "\n"

use warnings;
use strict;

my $in = <>;
chomp($in);
die('to many chars') unless length($in) <= 1000;

my @chars = split('', $in);

$chars[0] = uc($chars[0]);
my $out = join('', @chars);

print $out;

chomp($numstops=<STDIN>);
my $maxcapa = -1;
my $capa = 0;
while($numstops-- > 0) {
	chomp($line = <STDIN>);
	($l, $b) = $line =~ /(\d+)\s+(\d+)/;

	$capa = $capa - $l + $b;
	$max = $capa if($capa > $max);
}
print "$max\n";


The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters:   R, G, B — denoting red, green and blue doors, respectively;  r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once.

For each testcase, print YES if the knight can open all doors. Otherwise, print NO.

NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door.


It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to a1, worms in second pile are labeled with numbers a1 + 1 to a1 + a2 and so on. See the example for a better understanding.Mole can't eat all the worms (Marmot brought a lot) and, as we all know, Mole is blind, so Marmot tells him the labels of the best juicy worms. Marmot will only give Mole a worm if Mole says correctly in which pile this worm is contained.Poor Mole asks for your help. For all juicy worms said by Marmot, tell Mole the correct answers.

The first line contains a single integer n (1 ≤ n ≤ 105), the number of piles. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103, a1 + a2 + ... + an ≤ 106), where ai is the number of worms in the i-th pile. The third line contains single integer m (1 ≤ m ≤ 105), the number of juicy worms said by Marmot. The fourth line contains m integers q1, q2, ..., qm (1 ≤ qi ≤ a1 + a2 + ... + an), the labels of the juicy worms.

Print m lines to the standard output. The i-th line should contain an integer, representing the number of the pile where the worm labeled with the number qi is.

NoteFor the sample input:  The worms with labels from [1, 2] are in the first pile.  The worms with labels from [3, 9] are in the second pile.  The worms with labels from [10, 12] are in the third pile.  The worms with labels from [13, 16] are in the fourth pile.  The worms with labels from [17, 25] are in the fifth pile.

#!/usr/bin/perl -w

my $piles = <>;
my @psize = split(/ /, <>);
my $juicy = <>;

chomp ($piles, $juicy);

my $sum = 0;
foreach (@psize) {
    $sum += $_;
    $_ = $sum;
}

# print "$piles: @psize\n";

foreach my $q (split (/ /, <>)) {
    chomp($q);
    my ($start, $end) = (0, $#psize);
    while ($start < $end) {
	$mid = ($start + $end) >> 1;
	if ($q <= $psize[$mid]) {
#	    print "lt: q=$q.   st=$start  mid=$mid  end=$end\n";
	    $end   = $mid;  # not $mid - 1 like we would for a binary search.  We want std::lower_bound style behaviour
#	} elsif ($q == $psize[$mid]) {
#	    $start = $end = $mid;
	} else {
#	    print "gt: q=$q.   st=$start  mid=$mid  end=$end\n";
	    $start = $mid + 1;
	}
    }
    #    print $start + 1, "\tst=$start en=$end\n";
    print $start + 1, "\n";
}

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

my @cum;
sub bs{
    my $val = shift;
    my ($low,$high) = (0 ,scalar @cum);
    while($low < $high){
        my $mid = int(($low + $high) / 2);
        if($cum[$mid] >= $val){$high = $mid;}
        else{$low = $mid + 1;}
    }
    return $low+1;
}
my $n = <>;
my @pile = split ' ',<>;
my $m = <>;
my @lbl = split ' ',<>;
for my $i(0..$n-1){
    if($i == 0){
        push @cum, $pile[$i];
    }
    else{
        push @cum, $cum[$#cum]+$pile[$i];
    }
}

for my $i(0..$m-1){
    print bs($lbl[$i]),"\n";
}

#!/usr/bin/perl -w

my $piles = <>;
my @psize = split(/ /, <>);
my $juicy = <>;

chomp ($piles, $juicy);

my $sum = 0;
foreach (@psize) {
    $sum += $_;
    $_ = $sum;
}

# print "$piles: @psize\n";

foreach my $q (split (/ /, <>)) {
    chomp($q);
    my ($start, $end) = (0, $#psize);
    while ($start < $end) {
    $mid = ($start + $end) >> 1;
    if ($q < $psize[$mid]) {
#       print "lt: q=$q.   st=$start  mid=$mid  end=$end\n";
        $end   = $mid;  # not $mid - 1 like we would for a binary search.  We want std::lower_bound style behaviour
#   } elsif ($q == $psize[$mid]) {
#       $start = $end = $mid;
    } else {
#       print "gt: q=$q.   st=$start  mid=$mid  end=$end\n";
        $start = $mid + 1;
    }
    }
    #    print $start + 1, "\tst=$start en=$end\n";
    print $start + 1, "\n";
}

#!/usr/bin/perl -w

my $piles = <>;
my @psize = split(/ /, <>);
my $juicy = <>;

chomp ($piles, $juicy);

my $sum = 0;
foreach (@psize) {
    $sum += $_;
    $_ = $sum;
}

print "$piles: @psize\n";

foreach my $q (split (/ /, <>)) {
    chomp($q);
    my ($start, $end) = (0, $#psize);
    while ($start < $end) {
	$mid = ($start + $end) >> 1;
	if ($q < $psize[$mid]) {
#	    print "lt: q=$q.   st=$start  mid=$mid  end=$end\n";
	    $end   = $mid;  # not $mid - 1 like we would for a binary search.  We want std::lower_bound style behaviour
#	} elsif ($q == $psize[$mid]) {
#	    $start = $end = $mid;
	} else {
#	    print "gt: q=$q.   st=$start  mid=$mid  end=$end\n";
	    $start = $mid + 1;
	}
    }
    print $start + 1, "\tst=$start en=$end\n";
}


There are $$$n$$$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.The university team for the Olympiad consists of $$$a$$$ student-programmers and $$$b$$$ student-athletes. Determine the largest number of students from all $$$a+b$$$ students, which you can put in the railway carriage so that:  no student-programmer is sitting next to the student-programmer;  and no student-athlete is sitting next to the student-athlete. In the other words, there should not be two consecutive (adjacent) places where two student-athletes or two student-programmers are sitting.Consider that initially occupied seat places are occupied by jury members (who obviously are not students at all).

The first line contain three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \le n \le 2\cdot10^{5}$$$, $$$0 \le a, b \le 2\cdot10^{5}$$$, $$$a + b > 0$$$) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes. The second line contains a string with length $$$n$$$, consisting of characters "." and "*". The dot means that the corresponding place is empty. The asterisk means that the corresponding place is occupied by the jury member.

Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete.

NoteIn the first example you can put all student, for example, in the following way: *.AB*In the second example you can put four students, for example, in the following way: *BAB*BIn the third example you can put seven students, for example, in the following way: B*ABAB**A*BThe letter A means a student-programmer, and the letter B — student-athlete.

use warnings;
use strict;
use integer;
$\ = qq/\n/, $, = qq/ /;
my ( $n, $aa, $bb ) = split qq/ /, <STDIN>;
chomp ( my $str = <STDIN> );
my $sum = 0;
sub min { my $one = $_ [ 0 ] < $_ [ 1 ] ? $_ [ 0 ] : $_ [ 1 ] }
for my $ii ( $str =~ m/\.+/g ) {
    if ( length ( $ii ) % 2 == 0 ) {
        $sum += min ( $aa, length ( $ii ) / 2 ) + min ( $bb, length ( $ii ) / 2 );
        $aa -= min ( $aa, length ( $ii ) / 2 );
        $bb -= min ( $bb, length ( $ii ) / 2 );
    } else {
        if ( min ( $aa, ( length ( $ii ) + 1 ) / 2 ) +
             min ( $bb, ( length ( $ii ) + 1 ) / 2 ) >
             length $ii ) {
            if ( $aa >= $bb ) {
                $sum += min ( $aa, ( length ( $ii ) + 1 ) / 2 ) + min ( $bb, ( length ( $ii ) ) / 2 );
                $aa -= min ( $aa, ( length ( $ii ) + 1 ) / 2 );
                $bb -= min ( $bb, ( length ( $ii ) ) / 2 );
            } else {
                $sum += min ( $aa, ( length ( $ii ) ) / 2 ) + min ( $bb, ( length ( $ii ) + 1 ) / 2 );
                $aa -= min ( $aa, ( length ( $ii ) ) / 2 );
                $bb -= min ( $bb, ( length ( $ii ) + 1 ) / 2 );
            }
        } else {
            $sum += min ( $aa, ( length ( $ii ) + 1 ) / 2 ) + min ( $bb, ( length ( $ii ) + 1 ) / 2 );
            $aa -= min ( $aa, ( length ( $ii ) + 1 ) / 2 );
            $bb -= min ( $bb, ( length ( $ii ) + 1 ) / 2 );
        }
    }
}
print $sum;

#!/usr/bin/perl

use warnings;
use strict;

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

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

	$A > $B and ( $A, $B ) = ( $B, $A );

	$_ = <>, chomp;

	@_ = map length, grep $_, split /\*/;

	$debug and print "[@_]";

	my @lyg = sort { $a <=> $b } grep $_ % 2 == 0, @_;
	my @nel = sort { $a <=> $b } grep $_ % 2 == 1, @_;

	$debug and print "[@lyg]";
	$debug and print "[@nel]";

	my $spaces = eval join ' + ', @_;
	my $AB = $A + $B;
	my $all = 0;
	my $cnt = 0;

	NEL:
	while( $A < $B ){
		$debug and print " $A < $B";
		if( @nel ){
			my $nel = shift @nel;
			my $min = $nel >> 1;
			$A -= $min;
			$B -= $min + 1;
			$A < 0 and $A = 0;
			$B < 0 and $B = 0;
			}
		elsif( @lyg ){
			my $lyg = shift @lyg;
			my $half = $lyg >> 1;
			$A -= $half;
			$B -= $half;
			$A < 0 and $A = 0;
			$B < 0 and $B = 0;
			}
		else{
			last;
			}
		}

	while( $A == $B ){
		$debug and print " $A = $B";
		if( @lyg ){
			my $lyg = shift @lyg;
			my $half = $lyg >> 1;
			$A -= $half;
			$B -= $half;
			$A < 0 and $A = 0;
			$B < 0 and $B = 0;
			}
		elsif( @nel ){
			my $nel = shift @nel;
			my $min = $nel >> 1;
			$A -= $min + 1;
			$B -= $min;
			$A < 0 and $A = 0;
			$B < 0 and $B = 0;
			goto NEL;
			}
		else{
			last;
			}
		}

	$debug and print "[all:$all]";
	print $all ? $spaces : $AB - $A - $B;

	$debug and print '-' x 10;
	}


There is a programing contest named SnakeUp, 2n people want to compete for it. In order to attend this contest, people need to form teams of exactly two people. You are given the strength of each possible combination of two people. All the values of the strengths are distinct.Every contestant hopes that he can find a teammate so that their team’s strength is as high as possible. That is, a contestant will form a team with highest strength possible by choosing a teammate from ones who are willing to be a teammate with him/her. More formally, two people A and B may form a team if each of them is the best possible teammate (among the contestants that remain unpaired) for the other one. Can you determine who will be each person’s teammate?

There are 2n lines in the input.  The first line contains an integer n (1 ≤ n ≤ 400) — the number of teams to be formed. The i-th line (i > 1) contains i - 1 numbers ai1, ai2, ... , ai(i - 1). Here aij (1 ≤ aij ≤ 106, all aij are distinct) denotes the strength of a team consisting of person i and person j (people are numbered starting from 1.)

Output a line containing 2n numbers. The i-th number should represent the number of teammate of i-th person.

NoteIn the first sample, contestant 1 and 2 will be teammates and so do contestant 3 and 4, so the teammate of contestant 1, 2, 3, 4 will be 2, 1, 4, 3 respectively.


Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$) — the number of stops Arkady saw. The next $$$n$$$ lines describe the stops. Each of them starts with a single integer $$$r$$$ ($$$1 \le r \le 100$$$) — the number of tram lines that stop there. $$$r$$$ distinct integers follow, each one between $$$1$$$ and $$$100$$$, inclusive, — the line numbers. They can be in arbitrary order. It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.

Print all tram lines that Arkady could be in, in arbitrary order.

NoteConsider the first example. Arkady woke up three times. The first time he saw a stop with lines $$$1$$$, $$$4$$$, $$$6$$$. The second time he saw a stop with lines $$$1$$$, $$$4$$$. The third time he saw a stop with lines $$$10$$$, $$$5$$$, $$$6$$$, $$$4$$$ and $$$1$$$. He can be in a tram of one of two lines: $$$1$$$ or $$$4$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	@_ = map s/\d+ //r, map ~~<>, 1 .. $_;

	my %h;

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

	my $is = $_;

	my @ans = grep { $is == $h{ $_ } } keys %h;

	print "@ans";
	}

$x = <>;

map { map $h{ $_ } ++, split  } map s/\d+ //r, <>;

print join ' ', grep $x == $h{ $_ }, keys %h;


Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team solved problems individually.After the contest was over, Valera was interested in results. He found out that:  each student in the team scored at least l points and at most r points;  in total, all members of the team scored exactly sall points;  the total score of the k members of the team who scored the most points is equal to exactly sk; more formally, if a1, a2, ..., an is the sequence of points earned by the team of students in the non-increasing order (a1 ≥ a2 ≥ ... ≥ an), then sk = a1 + a2 + ... + ak. However, Valera did not find out exactly how many points each of n students scored. Valera asked you to recover any distribution of scores between the students of the team, such that all the conditions above are met.

The first line of the input contains exactly six integers n, k, l, r, sall, sk (1 ≤ n, k, l, r ≤ 1000; l ≤ r; k ≤ n; 1 ≤ sk ≤ sall ≤ 106). It's guaranteed that the input is such that the answer exists.

Print exactly n integers a1, a2, ..., an — the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order.

#!/usr/bin/perl

while(<>){
	@KK=();
	@MM=();
	($n, $k, $l, $r, $sa, $sk) = split/ /;
#	print " $n $m $k";
#   @_=split/ /,<>;
# div($sk, $k);

$csk=$sk;
$ck=$k;
while ($ck--){
	push @KK, 0;
	}
while ($csk--){
	$KK[$csk%$k]++;
	}
	# print "  @KK\n";
$d=$sa-$sk;
$cm=$m=$n-$k;
while ($cm--){
	push @MM, 0;
	}
while ($d--){
	$MM[$d%$m]++;
	}
	# print "  @MM\n";

print "@KK @MM\n";
}

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

while(<>){
	@KK=();
	@MM=();
	($n, $k, $l, $r, $sa, $sk) = split/ /;
#	print " $n $m $k";
#   @_=split/ /,<>;
# div($sk, $k);

$csk=$sk;
$ck=$k;
while ($ck--){
	push @KK, 0;
	}
while ($csk--){
	$KK[$csk%$k]++;
	}
	print "  @KK\n";
$d=$sa-$sk;
$cm=$m=$n-$k;
while ($cm--){
	push @MM, 0;
	}
while ($d--){
	$MM[$d%$m]++;
	}
	print "  @MM\n";

print "@KK @MM\n";
}

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


Recently you have bought a snow walking robot and brought it home. Suppose your home is a cell $$$(0, 0)$$$ on an infinite grid.You also have the sequence of instructions of this robot. It is written as the string $$$s$$$ consisting of characters 'L', 'R', 'U' and 'D'. If the robot is in the cell $$$(x, y)$$$ right now, he can move to one of the adjacent cells (depending on the current instruction).  If the current instruction is 'L', then the robot can move to the left to $$$(x - 1, y)$$$;  if the current instruction is 'R', then the robot can move to the right to $$$(x + 1, y)$$$;  if the current instruction is 'U', then the robot can move to the top to $$$(x, y + 1)$$$;  if the current instruction is 'D', then the robot can move to the bottom to $$$(x, y - 1)$$$. You've noticed the warning on the last page of the manual: if the robot visits some cell (except $$$(0, 0)$$$) twice then it breaks.So the sequence of instructions is valid if the robot starts in the cell $$$(0, 0)$$$, performs the given instructions, visits no cell other than $$$(0, 0)$$$ two or more times and ends the path in the cell $$$(0, 0)$$$. Also cell $$$(0, 0)$$$ should be visited at most two times: at the beginning and at the end (if the path is empty then it is visited only once). For example, the following sequences of instructions are considered valid: "UD", "RL", "UUURULLDDDDLDDRRUU", and the following are considered invalid: "U" (the endpoint is not $$$(0, 0)$$$) and "UUDD" (the cell $$$(0, 1)$$$ is visited twice).The initial sequence of instructions, however, might be not valid. You don't want your robot to break so you decided to reprogram it in the following way: you will remove some (possibly, all or none) instructions from the initial sequence of instructions, then rearrange the remaining instructions as you wish and turn on your robot to move. Your task is to remove as few instructions from the initial sequence as possible and rearrange the remaining ones so that the sequence is valid. Report the valid sequence of the maximum length you can obtain.Note that you can choose any order of remaining instructions (you don't need to minimize the number of swaps or any other similar metric).You have to answer $$$q$$$ independent test cases.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^4$$$) — the number of test cases. The next $$$q$$$ lines contain test cases. The $$$i$$$-th test case is given as the string $$$s$$$ consisting of at least $$$1$$$ and no more than $$$10^5$$$ characters 'L', 'R', 'U' and 'D' — the initial sequence of instructions. It is guaranteed that the sum of $$$|s|$$$ (where $$$|s|$$$ is the length of $$$s$$$) does not exceed $$$10^5$$$ over all test cases ($$$\sum |s| \le 10^5$$$).

For each test case print the answer on it. In the first line print the maximum number of remaining instructions. In the second line print the valid sequence of remaining instructions $$$t$$$ the robot has to perform. The moves are performed from left to right in the order of the printed sequence. If there are several answers, you can print any. If the answer is $$$0$$$, you are allowed to print an empty line (but you can don't print it).

6
LRU
DURLDRUDRULRDURDDL
LRUDDLRUDRUL
LLLLRRRR
URDUR
LLL

2
LR
14
RUURDDDDLLLUUR
12
ULDDDRRRUULL
2
LR
2
UD
0

NoteThere are only two possible answers in the first test case: "LR" and "RL".The picture corresponding to the second test case:  Note that the direction of traverse does not matter Another correct answer to the third test case: "URDDLLLUURDR".

$\ = $/;

<>;

while(<>){
	chomp;

	my %h;

	map $h{ $_ } ++, split //, 'LURD' . $_;

	map $h{ $_ } --, keys %h;

	@h{ split //, 'LRUD' } = map { ( ( sort { $a <=> $b } @h{ split // } )[ 0 ] ) x 2 } 'LR', 'UD';

	my $ans = join '', map $_ x $h{ $_ }, split //, 'LURD';

	( $ans ) = $ans =~ /LR|UD/g if $h{ 'L' } xor $h{ 'U' };

	print for length $ans, $ans;
	}


A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol's artificial intelligence.Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol's director decided to replace some characters in AI name with "#". As this operation is pretty expensive, you should find the minimum number of characters to replace with "#", such that the name of AI doesn't contain the name of the phone as a substring.Substring is a continuous subsequence of a string.

The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100 000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters.

Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring.

NoteIn the first sample AI's name may be replaced with "int#llect".In the second sample Gogol can just keep things as they are.In the third sample one of the new possible names of AI may be "s#ris#ri".

$\ = $/;

$_ = <>, chomp;
$A = <>;
chomp $A;

while( m/(?=$A)/g ){
	push @pos, pos;
	}

$i = shift @pos;
$len = 1;

for (@pos){
	if ($i + 1 == $_){
		$len ++;
		}
	else {
		push @len, $len;
		$len = 1;
		}
	$i = $_;
	}

push @len, $len;

map { $_ += -1 + length $A } @len;

$ans = 0;

for (@len){
	$ans += (int $_ / length $A) + !! ($_ % length $A);
	}

print $ans

$\ = $/;

$_ = <>, chomp;
$A = <>;
chomp $A;

while( m/(?=$A)/g ){
	push @pos, pos;
	}

$i = shift @pos;
$len = 1;

for (@pos){
	if ($i + 1 == $_){
		$len ++;
		}
	else {
		push @len, $len;
		$len = 1;
		}
	$i = $_;
	}

push @len, $len if m/(?=$A)/;

map { $_ += -1 + length $A } @len;

$ans = 0;

for (@len){
	$ans += (int $_ / length $A) + !! ($_ % length $A);
	}

print $ans


Sereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers l1, l2, ..., lm (1 ≤ li ≤ n). For each number li he wants to know how many distinct numbers are staying on the positions li, li + 1, ..., n. Formally, he want to find the number of distinct numbers among ali, ali + 1, ..., an.?Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each li.

The first line contains two integers n and m (1 ≤ n, m ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105) — the array elements. Next m lines contain integers l1, l2, ..., lm. The i-th line contains integer li (1 ≤ li ≤ n).

Print m lines — on the i-th line print the answer to the number li.

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

@_=split/ /,<>;

for (1..$`){
	$a[pop @_]++ or $i++;
	unshift @b, $i;
	}

while (<>){
	print "$b[$_-1]\n";
	}

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


Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.

The first line contains integer n (1 ≤ n ≤ 1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.

On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.

NoteIn the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.

my $num = <STDIN>;
my $data = <STDIN>;
my @cards = split(' ', $data);

my $seroga = 0;
my $dima = 0;
my $turn = 1;

while(@cards)
{
    my $grt;
    $num--;
    if(@cards[$num] > @cards[0])
    {
        $grt = pop @cards;
    }
    else
    {
        $grt = shift @cards;
    }

    if($turn % 2)
    {
        $seroga += $grt;
    }
    else
    {
        $dima += $grt;
    }
    $turn++;
}

print $seroga, ' ', $dima;

1;

my $n = <STDIN>;
chomp ($n);
my $numbers = <STDIN>;
chomp ($numbers);
my (@data) = split (" ", $numbers);

my $ind = 0; my $c = 0; my $serg = 0; my $dima = 0;

while ($c != $n) {
    if ($ind != 1) {
        if ($data[0] > $data[(scalar (@data))-1]) {
           $serg = $serg + shift (@data);
        }else{
           $serg = $serg + pop (@data);
        }
        $c++;
        $ind = 1;
    } else {
        if ($data[0] > $data[(scalar (@data))-1]) {
           $dima = $dima + shift (@data);
        }else{
           $dima = $dima + pop (@data);
        }
        $c++;
        $ind = 0;
    }
}
print "$serg $dima";


You will receive 5 points for solving this problem.Manao has invented a new operation on strings that is called folding. Each fold happens between a pair of consecutive letters and places the second part of the string above first part, running in the opposite direction and aligned to the position of the fold. Using this operation, Manao converts the string into a structure that has one more level than there were fold operations performed. See the following examples for clarity.We will denote the positions of folds with '|' characters. For example, the word "ABRACADABRA" written as "AB|RACA|DAB|RA" indicates that it has been folded three times: first, between the leftmost pair of 'B' and 'R' letters; second, between 'A' and 'D'; and third, between the rightmost pair of 'B' and 'R' letters. Here are several examples of folded strings:"ABCDEF|GHIJK" |  "A|BCDEFGHIJK" |  "AB|RACA|DAB|RA" |  "X|XXXXX|X|X|XXXXXX"               |                 |                   |       XXXXXX    KJIHG      |   KJIHGFEDCB    |      AR           |       X   ABCDEF      |            A    |     DAB           |       X               |                 |     ACAR          |       XXXXX               |                 |       AB          |           XOne last example for "ABCD|EFGH|IJ|K":  KIJHGFEABCDManao noticed that each folded string can be viewed as several piles of letters. For instance, in the previous example, there are four piles, which can be read as "AHI", "BGJK", "CF", and "DE" from bottom to top. Manao wonders what is the highest pile of identical letters he can build using fold operations on a given word. Note that the pile should not contain gaps and should start at the bottom level. For example, in the rightmost of the four examples above, none of the piles would be considered valid since each of them has gaps, starts above the bottom level, or both.

The input will consist of one line containing a single string of n characters with 1 ≤ n ≤ 1000 and no spaces. All characters of the string will be uppercase letters. This problem doesn't have subproblems. You will get 5 points for the correct submission.

Print a single integer — the size of the largest pile composed of identical characters that can be seen in a valid result of folding operations on the given string.

NoteConsider the first example. Manao can create a pile of three 'A's using the folding "AB|RACAD|ABRA", which results in the following structure: ABRADACAR   ABIn the second example, Manao can create a pile of three 'B's using the following folding: "AB|BB|CBDB". CBDBBBABAnother way for Manao to create a pile of three 'B's with "ABBBCBDB" is the following folding: "AB|B|BCBDB".  BCBDB BABIn the third example, there are no folds performed and the string is just written in one line.

chomp ($a = <>);
map $x |= $_, split 0, join $\, map $_ = (1 + length) % 2, split $_, $a for a .. z;
print length $x

$_ = <>, chomp;
$_ = join $/, map {$j ++ % 2 ? $_ : scalar reverse} split /\|/;
$min = (sort {$a <=> $b} @_ = map $_ = ($a += (-1) ** ($i ++ % 2) * length) - (++ $k % 2 and length), split /\n/ )[0];
s/$/ q( ) x (- $min + shift @_) /emg;
print scalar reverse


Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter — its complexity. The complexity of the i-th chore equals hi.As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi ≤ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?

The first input line contains three integers n, a and b (2 ≤ n ≤ 2000; a, b ≥ 1; a + b = n) — the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different. All numbers on the lines are separated by single spaces.

Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.

NoteIn the first sample the possible values of x are 3, 4 or 5.In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.


Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.He has names of n people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.Formally, for a name si in the i-th line, output "YES" (without quotes) if there exists an index j such that si = sj and j < i, otherwise, output "NO" (without quotes).

First line of input contains an integer n (1 ≤ n ≤ 100) — the number of names in the list. Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.

Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower).

NoteIn test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".

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

my %h;
my $str;
for ( my $i = 0; $i < $f; $i += 1 ) {
    $str = <STDIN>;
    chomp ( $f );
    if ( exists $h{ $str } ) {
	print "YES\n";}
    else {
	$h{ $str } = 1;
	print "NO\n"; }}

#!/usr/bin/env perl

use strict;
use warnings;

<>;

my %hash;

while (<>) {
	chomp;
	if (exists $hash{$_}) {
		print "YES\n";
	}
	else {
		print "NO\n";
	}
	$hash{$_} = 1;
}

#!/usr/bin/env perl

use strict;
use warnings;

<>;

my %hash;

while (<>) {
	chomp;
	if (exists $hash{$_}) {
		print "YES\n";
	}
	else {
		print "NO\n";
		$hash{$_} = 1;
	}
}


Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vanya chose n rectangles with sides that go along borders of squares (some rectangles probably occur multiple times). After that for each cell of the table he counted the number of rectangles it belongs to and wrote this number into it. Now he wants to find the sum of values in all cells of the table and as the table is too large, he asks you to help him find the result.

The first line contains integer n (1 ≤ n ≤ 100) — the number of rectangles. Each of the following n lines contains four integers x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ 100, 1 ≤ y1 ≤ y2 ≤ 100), where x1 and y1 are the number of the column and row of the lower left cell and x2 and y2 are the number of the column and row of the upper right cell of a rectangle.

In a single line print the sum of all values in the cells of the table.

NoteNote to the first sample test:Values of the table in the first three rows and columns will be as follows:121121110So, the sum of values will be equal to 10.Note to the second sample test:Values of the table in the first three rows and columns will be as follows:222222222So, the sum of values will be equal to 18.


Define the score of some binary string $$$T$$$ as the absolute difference between the number of zeroes and ones in it. (for example, $$$T=$$$ 010001 contains $$$4$$$ zeroes and $$$2$$$ ones, so the score of $$$T$$$ is $$$|4-2| = 2$$$).Define the creepiness of some binary string $$$S$$$ as the maximum score among all of its prefixes (for example, the creepiness of $$$S=$$$ 01001 is equal to $$$2$$$ because the score of the prefix $$$S[1 \ldots 4]$$$ is $$$2$$$ and the rest of the prefixes have a score of $$$2$$$ or less).Given two integers $$$a$$$ and $$$b$$$, construct a binary string consisting of $$$a$$$ zeroes and $$$b$$$ ones with the minimum possible creepiness.

The first line contains a single integer $$$t$$$ $$$(1\le t\le 1000)$$$  — the number of test cases. The description of the test cases follows. The only line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$ 1 \le a, b \le 100$$$)  — the numbers of zeroes and ones correspondingly.

For each test case, print a binary string consisting of $$$a$$$ zeroes and $$$b$$$ ones with the minimum possible creepiness. If there are multiple answers, print any of them.

NoteIn the first test case, the score of $$$S[1 \ldots 1]$$$ is $$$1$$$, and the score of $$$S[1 \ldots 2]$$$ is $$$0$$$.In the second test case, the minimum possible creepiness is $$$1$$$ and one of the other answers is 101.In the third test case, the minimum possible creepiness is $$$3$$$ and one of the other answers is 0001100.


In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states:  If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$.  If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$.  If it is off, snakes can travel in either direction.   Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there?

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows.   The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms.  The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'.   If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise.  If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise.  If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off.  It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$.

For each test case, output the number of returnable rooms.

NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts.


One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric.

The first line contains the single integer n (1 ≤ n ≤ 100). The second line contains n space-separated integers ri (1 ≤ ri ≤ 1000) — the circles' radii. It is guaranteed that all circles are different.

Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10 - 4.

NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 12 = π.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 42 - π × 22) + π × 12 = π × 12 + π = 13π

$n=<STDIN>;
$rads=<STDIN>;
@radius=sort {$b <=> $a} split(" ",$rads);
$square=0;
$\="\n";
$controller=1;

foreach $i (@radius){
    if (($controller++)%2==0){
        $square-=3.141592653589793*$i*$i;
        #print $i,"chet";
    }else{
        $square+=3.141592653589793*$i*$i;
        #print $i,"nechet";
    }
}

print $square;

#!/usr/bin/perl

use strict;
use warnings;

my $n=<>;
my @r=split(' ',<>);
my $total=0;
my $count=0;
my $now;
my $pi=3.1415926535;
if($n%2==1){
	$now=1;
}else{
	$now=-1;
}
while($count<$n-1){
	if($r[$count]>$r[$count+1]){
		my $temp=$r[$count];
		$r[$count]=$r[$count+1];
		$r[$count+1]=$temp;
		$count=-1;
	}
	$count++;
}
foreach my $count(0..$#r){
	$total+=$now*$pi*$r[$count]*$r[$count];
	$now*=-1;
}
print $total;

$n=<STDIN>;
$rads=<STDIN>;
@radius=sort {$a <=> $b} split(" ",$rads);
$square=0;
$\="\n";
$controller=1;

foreach $i (@radius){
    if (($controller++)%2==0){
        $square-=3.141592653589793*$i*$i;
        #print $i,"chet";
    }else{
        $square+=3.141592653589793*$i*$i;
        #print $i,"nechet";
    }
}

print $square;


Colossal! — exclaimed Hawk-nose. — A programmer! That's exactly what we are looking for.Arkadi and Boris Strugatsky. Monday starts on SaturdayReading the book "Equations of Mathematical Magic" Roman Oira-Oira and Cristobal Junta found an interesting equation: $$$a - (a \oplus x) - x = 0$$$ for some given $$$a$$$, where $$$\oplus$$$ stands for a bitwise exclusive or (XOR) of two integers (this operation is denoted as ^ or xor in many modern programming languages). Oira-Oira quickly found some $$$x$$$, which is the solution of the equation, but Cristobal Junta decided that Oira-Oira's result is not interesting enough, so he asked his colleague how many non-negative solutions of this equation exist. This task turned out to be too difficult for Oira-Oira, so he asks you to help.

Each test contains several possible values of $$$a$$$ and your task is to find the number of equation's solution for each of them. The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of these values. The following $$$t$$$ lines contain the values of parameter $$$a$$$, each value is an integer from $$$0$$$ to $$$2^{30} - 1$$$ inclusive.

For each value of $$$a$$$ print exactly one integer — the number of non-negative solutions of the equation for the given value of the parameter. Print answers in the same order as values of $$$a$$$ appear in the input. One can show that the number of solutions is always finite.

NoteLet's define the bitwise exclusive OR (XOR) operation. Given two integers $$$x$$$ and $$$y$$$, consider their binary representations (possibly with leading zeroes): $$$x_k \dots x_2 x_1 x_0$$$ and $$$y_k \dots y_2 y_1 y_0$$$. Here, $$$x_i$$$ is the $$$i$$$-th bit of the number $$$x$$$ and $$$y_i$$$ is the $$$i$$$-th bit of the number $$$y$$$. Let $$$r = x \oplus y$$$ be the result of the XOR operation of $$$x$$$ and $$$y$$$. Then $$$r$$$ is defined as $$$r_k \dots r_2 r_1 r_0$$$ where:$$$$$$ r_i = \left\{ \begin{aligned} 1, ~ \text{if} ~ x_i \ne y_i \\ 0, ~ \text{if} ~ x_i = y_i \end{aligned} \right. $$$$$$For the first value of the parameter, only $$$x = 0$$$ is a solution of the equation.For the second value of the parameter, solutions are $$$x = 0$$$ and $$$x = 2$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

while(<>){
	chomp;

	$debug and print '-' x 10;

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

	$debug and do {

		print "         $_ -> $B";

		$_ > 100 and next;

		my $c = 0;

		for my $i ( 0 .. 2 ** ( length $B ) - 1 ){
			$debug and print sprintf " %b", $i;

			$debug and print join ' ', ':', $_, $i, $_ ^ $i;
			my $form = $_ - $i - ( $_ ^ $i );
			$debug and print ' ', $form;

			$c += ! $form;
			}

		print "$_ : $c";

		};

	print 2 ** ( () = $B =~ /1/g );
	}


You are given a list of $$$n$$$ integers. You can perform the following operation: you choose an element $$$x$$$ from the list, erase $$$x$$$ from the list, and subtract the value of $$$x$$$ from all the remaining elements. Thus, in one operation, the length of the list is decreased by exactly $$$1$$$.Given an integer $$$k$$$ ($$$k>0$$$), find if there is some sequence of $$$n-1$$$ operations such that, after applying the operations, the only remaining element of the list is equal to $$$k$$$.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \leq n \leq 2\cdot 10^5$$$, $$$1 \leq k \leq 10^9$$$), the number of integers in the list, and the target value, respectively. The second line of each test case contains the $$$n$$$ integers of the list $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^9 \leq a_i \leq 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases is not greater that $$$2 \cdot 10^5$$$.

For each test case, print YES if you can achieve $$$k$$$ with a sequence of $$$n-1$$$ operations. Otherwise, print NO. You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer).

NoteIn the first example we have the list $$$\{4, 2, 2, 7\}$$$, and we have the target $$$k = 5$$$. One way to achieve it is the following: first we choose the third element, obtaining the list $$$\{2, 0, 5\}$$$. Next we choose the first element, obtaining the list $$$\{-2, 3\}$$$. Finally, we choose the first element, obtaining the list $$$\{5\}$$$.


Polycarp is wondering about buying a new computer, which costs $$$c$$$ tugriks. To do this, he wants to get a job as a programmer in a big company.There are $$$n$$$ positions in Polycarp's company, numbered starting from one. An employee in position $$$i$$$ earns $$$a[i]$$$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $$$1$$$ and has $$$0$$$ tugriks.Each day Polycarp can do one of two things:   If Polycarp is in the position of $$$x$$$, then he can earn $$$a[x]$$$ tugriks.  If Polycarp is in the position of $$$x$$$ ($$$x < n$$$) and has at least $$$b[x]$$$ tugriks, then he can spend $$$b[x]$$$ tugriks on an online course and move to the position $$$x+1$$$. For example, if $$$n=4$$$, $$$c=15$$$, $$$a=[1, 3, 10, 11]$$$, $$$b=[1, 2, 7]$$$, then Polycarp can act like this:   On the first day, Polycarp is in the $$$1$$$-st position and earns $$$1$$$ tugrik. Now he has $$$1$$$ tugrik;  On the second day, Polycarp is in the $$$1$$$-st position and move to the $$$2$$$-nd position. Now he has $$$0$$$ tugriks;  On the third day, Polycarp is in the $$$2$$$-nd position and earns $$$3$$$ tugriks. Now he has $$$3$$$ tugriks;  On the fourth day, Polycarp is in the $$$2$$$-nd position and is transferred to the $$$3$$$-rd position. Now he has $$$1$$$ tugriks;  On the fifth day, Polycarp is in the $$$3$$$-rd position and earns $$$10$$$ tugriks. Now he has $$$11$$$ tugriks;  On the sixth day, Polycarp is in the $$$3$$$-rd position and earns $$$10$$$ tugriks. Now he has $$$21$$$ tugriks;  Six days later, Polycarp can buy himself a new computer. Find the minimum number of days after which Polycarp will be able to buy himself a new computer.

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 $$$n$$$ and $$$c$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$1 \le c \le 10^9$$$) — the number of positions in the company and the cost of a new computer. The second line of each test case contains $$$n$$$ integers $$$a_1 \le a_2 \le \ldots \le a_n$$$ ($$$1 \le a_i \le 10^9$$$). The third line of each test case contains $$$n - 1$$$ integer $$$b_1, b_2, \ldots, b_{n-1}$$$ ($$$1 \le b_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.