$\ = $/;
$left = -10e9;
<>;
$ans = 0;

while(<>){
	$prev = $x;
	($x, $h) = split;
	$x <= $left and do {$ans -- ; $left = $prev };
	if ($x - $left > $h ){
		$left = $x;
		}
		else {
			$left = $x + $h;
			}
	$ans ++
}

print $ans


#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

while (<>=~/ (\d+) (\d+) /){

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

$c++;
for(1..1e5){
	$S+=$c*$`/$1; $c-=$c*$`/$1;
	$K+=$c*$2/$'; $c-=$c*$2/$'
}
print $S

}

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

sub fact{
	my $i= shift;   my $j= 1;
	$j*=$i-- while $i;
	return $j
}

# Transpose "charbox"
sub trans{
	my @t=(); my $i=0;
	$i=0, s/./$t[$i++].=$&/eg for @_;
	return @t
}

sub rotL{
	my @t=(); my $i=0; my $j;
	for (@_){
		$i=0, $j=length; $t[$i++].=chop while $j--
	}
	return @t
}

sub rotR{
    my @m=@_;  chomp @m;   my @t=();
	my $i= length $m[0];
	while ($i--){
		$t[$i]=~s/^/chop/e for @m
	}
return @t
}

sub revlines{
	$_=reverse $_ for @_;
	return @_
}

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

# rotL_s
# rotR_s

# slow?
sub revlines_s{
	$_=join" ", reverse split/\s+/ 	for @_;
	return @_
}

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

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

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

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

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

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

while (<>=~/ (\d+) (\d+) /){

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

$c++;
for(1..1e3){
	$S+=$c*$`/$1; $c-=$c*$`/$1;
	$K+=$c*$2/$'; $c-=$c*$2/$'
}
print $S

}

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

sub fact{
	my $i= shift;   my $j= 1;
	$j*=$i-- while $i;
	return $j
}

# Transpose "charbox"
sub trans{
	my @t=(); my $i=0;
	$i=0, s/./$t[$i++].=$&/eg for @_;
	return @t
}

sub rotL{
	my @t=(); my $i=0; my $j;
	for (@_){
		$i=0, $j=length; $t[$i++].=chop while $j--
	}
	return @t
}

sub rotR{
    my @m=@_;  chomp @m;   my @t=();
	my $i= length $m[0];
	while ($i--){
		$t[$i]=~s/^/chop/e for @m
	}
return @t
}

sub revlines{
	$_=reverse $_ for @_;
	return @_
}

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

# rotL_s
# rotR_s

# slow?
sub revlines_s{
	$_=join" ", reverse split/\s+/ 	for @_;
	return @_
}

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

sub uniq{
	my @m=sort @_; my @u;
	push @u, my $i=shift @m;
	$i eq $_ or push @u, $i=$_ for @m;
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

use warnings;
use strict;

$\ = $/;

<>;

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

	my %h;

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

	my $this;

	$h{ $_ } == 1 and $this = $_ for keys %h;

	for( my $i = 0; $i < @_; $i ++ ){
		$_[ $i ] == $this and do {
			print $i + 1;
			last;
			};
		}
	}


use strict;
use warnings;
use v5.020;

my $t = <>;
while($t--) {
    my $n;# = <>;
    chomp($n=<>);
    my @ans;
    if($n % 2 == 1){
        push @ans, int($n);
        for(my $i = 1; $i <= int($n/2); $i++){
            push @ans, $i;
            push @ans, $n-$i
        }
    } else {
        push @ans, int($n/2);
        for(my $i = 1; $i < $n/2; $i++){
            push @ans, $i;
            push @ans, $n+1-$i;
        }
        push @ans, $n/2 + 1;
    }
    say "@ans";
}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

while(<>){

	my $i = 0;
	my $j = 0;
	my @A;
	my @j;

	() = / (\w+),(\d+)
		(?{

			push @{ $A[@j - 0] }, $1;

			$debug and print "<$&>";

			push @j, $2;

			while( 1 ){
				@j or last;
				$j = pop @j;
				$j or next;
				$j --;
				push @j, $j;
				last;
				}

			$debug and print "[@j]";
		})
	/gx;

	print ~~ @A;
	print "@$_" for @A;

	$debug and print '-' x 10;
	}


use strict;
use List::MoreUtils 'firstidx';

my $range = <STDIN>;
my @numbers = split / /, <STDIN>;
my @sorted = reverse sort { $a <=> $b } @numbers;

for my $i (0..$range-1) {
    $numbers[$i] = ( firstidx { $_ == $numbers[$i] } @sorted ) + 1;
}

$, = ' ';
print @numbers;

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

my $n = <>;
my @num = split ' ',<>;
my (%rank,%freq);
my ($idx,$last) = (1,0);
foreach(@num){
    $freq{$_}++;
}
foreach(sort {$b <=> $a} keys %freq){
    $rank{$_} = $last+1;
    $last += $freq{$_};
}
foreach(@num){
    print $rank{$_}, " ";
}

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

my $n = <>;
my @num = split ' ',<>;
my @sorted = sort {$a <=> $b} @num;
my (%rank,%cnt);
my ($idx,$last) = (1,0);
foreach(@sorted){
    $cnt{$_}++;
}
foreach(sort {$b <=> $a} keys %cnt){
    $rank{$_} = $last+1;
    $last += $cnt{$_};
}
foreach(@num){
    print $rank{$_}, " ";
}

use strict;
my $t = <STDIN>;
my @input = split //, <STDIN>;

my $max = 0;
for my $i ( @input ) {
    if ( $i > $max ) {
        $max = $i;
    }
}

my %ranks;
my $rank = 1;

while( $max ) {
    if ( grep { $_ == $max } @input ) {
        my $plus = scalar grep { $_ == $max } @input;
        $ranks{ $max } = $rank;
        $rank += $plus;
    }
    $max--;
}

print $ranks{$_} for @input;

use strict;
$, = ' ';
my $t = <STDIN>;
my @input = split //, <STDIN>;
my $max = 0;
for my $i ( @input ) {
    if ( $i > $max ) {
        $max = $i;
    }
}

my %ranks;
my $rank = 1;
my @values;
while( $max ) {
    if ( grep { $_ == $max } @input ) {
        my $plus = scalar grep { $_ == $max } @input;
        $ranks{ $max } = $rank;
        $rank += $plus;
    }
    $max--;
}

push @values, $ranks{$_} for @input;
print @values;

use strict;
use List::MoreUtils 'firstidx';

my $range = <STDIN>;
my @numbers = split //, <STDIN>;
my @sorted = reverse sort @numbers;

for my $i (0..$range-1) {
    $numbers[$i] = ( firstidx { /$numbers[$i]/ } @sorted ) + 1;
}

$, = ' ';
print @numbers;

use strict;
use List::MoreUtils 'firstidx';

my $range = <STDIN>;
my @numbers = split / /, <STDIN>;
my @sorted = reverse sort @numbers;

for my $i (0..$range-1) {
    $numbers[$i] = ( firstidx { /$numbers[$i]/ } @sorted ) + 1;
}

$, = ' ';
print @numbers;


$n = <>;
%graph = map { $_ => [] } (1..$n);
for (2..$n) {
	($u, $v) = split ' ', <>;
	push @{$graph{$u}}, $v;
	push @{$graph{$v}}, $u;
}

sub dfs {
	my $v = shift || 1;
	my $par = shift || -1;
	(my $removed, my $size) = (0, 1);
	for my $u (@{$graph{$v}}) {
		if ($u != $par) {
			my $child = dfs($u, $v); # [removed, size]
			$removed += $child->[0];
			if (($child->[1]) % 2 == 0) {
				$removed += 1;
			}
			$size += $child->[1];
		}
	}
	return [$removed, $size];
}

$removed = dfs()->[0];
print ($n % 2 == 0 ? $removed : -1);

#!/usr/bin/perl

use warnings;
use strict;

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

while(<>){
	my %h;

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

	if( $_ % 2 ){
		print -1;
		next;
		}

	my @leafs = grep { 1 == keys %{ $h{ $_ } } } keys %h;

	$debug and print "leafs: @leafs";

	my @g = ( 1 ) x ( $_ + 1 );

	my $cnt = 0;

	my %next = map { $_ => 1 } @leafs;

##	my $c = 0;

	while( 1 ){

	##	$c ++ > 15 and last;

		@leafs = grep { 1 == keys %{ $h{ $_ } } } keys %next;

		$debug and print "  leafs: @leafs";

		last if not @leafs;

		undef %next;

		while( @leafs ){
			my $leaf = shift @leafs;
			my( $parent ) = keys %{ $h{ $leaf } };
			next if not $parent;
			$next{ $parent } ++;
			delete $h{ $parent }{ $leaf };
			delete $h{ $leaf };

			if( $g[ $leaf ] % 2 == 0 ){
				$cnt ++;
				}
			else{
				$g[ $parent ] += $g[ $leaf ];
				}
			}

		}

	print $cnt;

	$debug and print '-' x 15;
	}

use warnings;
use strict;
$\ = qq/\n/, $, = qq/ /;
chomp ( my $n = <STDIN> );
my %graph = ();
for ( 2 .. $n ) {
    my ( $u, $v ) = split qq/ /, <STDIN>;
    $graph { $u } -> { $v } = 1;
    $graph { $v } -> { $u } = 1;
}
my %nodes = ();
my %visited = ();
my $removed = 0;
sub dfs {
    return 0 if $visited { $_ [ 0 ] };
    my $curr = $_ [ 0 ];
    $visited { $curr } = 1;
    my $cnt = 1;
    for my $ii ( keys %{ $graph { $curr } } ) { $cnt += dfs ( $ii ) }
    if ( $cnt % 2 == 0 ) {
        $removed += 1;
        return 0;
    } else { return $cnt }
}
dfs ( 1 );
if ( $n % 2 == 1 ) { print qq/-1/ }
elsif ( $removed == 0 ) { print qq/-1/ }
else { print ( $removed - 1 ) }

use warnings;
use strict;
$\ = qq/\n/;
my $n = <STDIN>;
if ( $n == 0 ) { print qq/0/ }
elsif ( $n % 2 == 0 ) { print $n - 1 - int ( $n / 2 ) }
else { print qq/-1/ }

use warnings;
use strict;
$\ = qq/\n/, $, = qq/ /;
chomp ( my $n = <STDIN> );
my %graph = ();
for ( 2 .. $n ) {
    my ( $u, $v ) = split qq/ /, <STDIN>;
    $graph { $u } -> { $v } = 1;
    $graph { $v } -> { $u } = 1;
}
my %nodes = ();
my %visited = ();
my $removed = 0;
sub dfs {
    return 0 if $visited { $_ [ 0 ] };
    my $curr = $_ [ 0 ];
    $visited { $curr } = 1;
    my $cnt = 1;
    for my $ii ( keys %{ $graph { $curr } } ) { $cnt += dfs ( $ii ) }
    if ( $cnt % 2 == 0 ) {
        $removed += 1;
        return 0;
    } else { return $cnt }
}
dfs ( 1 );
if ( $removed == 0 ) { print qq/-1/ }
else { print ($removed - 1) }

use warnings;
use strict;
$\ = qq/\n/;
my $n = <STDIN>;
print qq/-1/ if $n % 2 == 1;
print $n - 1 - int ( $n / 2 ) if $n % 2 == 0;

use warnings;
use strict;
$\ = qq/\n/;
my $n = <STDIN>;
my %graph = ();
my ( $u, $v );
for my $edge ( 1 .. $n-1 ) {
    ( $u, $v ) = split ( qq/ /, <STDIN> );
    $graph { $u } = 0 if not exists $graph { $u };
    $graph { $u } += 1;
    $graph { $v } = 0 if not exists $graph { $v };
    $graph { $v } += 1;
}
my $val = grep { $_ == 1 } values %graph;
sub min { $_ [ 0 ] < $_ [ 1 ] ? $_ [ 0 ] : $_ [ 1 ] }
sub max { $_ [ 0 ] > $_ [ 1 ] ? $_ [ 0 ] : $_ [ 1 ] }
if ( $n % 2 == 1 ) { print qq/-1/ }
else { print STDOUT max ( 0, min ( $n - 1 - $val, $n - 1 - int ( $n / 2 ) ) ) }


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $sum = eval join ' + ', @_;

	my $half = 0;

	my $ans;

	for my $i ( 0 .. @_ - 1 ){
		$half += $_[ $i ];
		$half >= $sum / 2 and $ans = $i;
		$half >= $sum / 2 and last;
		}

	print $ans + 1;
	}

use warnings;
use strict;
$\  = qq/\n/, $, = qq/ /;
<STDIN>;
sub ceil { int ( $_ [ 0 ] ) < $_ [ 0 ] ? int ( $_ [ 0 ] ) + 1 : $_ [ 0 ] }
my @arr = split qq/ /, <STDIN>;
my $sum = 0;
$sum += $_ for @arr;
my $one = ceil ( $sum / 2 );
my ( $two, $ii ) = ( 0, 0 );
while ( $two < $one ) {
    $two += $arr [ $ii ];
    $ii += 1;
}
print $ii;


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	print +( sort { $a <=> $b } split )[ 1 ];
	}

<>;

print +( sort { $a <=> $b } split )[ 1 ] . $/ while <>


#!/usr/bin/perl

use warnings;
use strict;
use bigint;

$\ = $/;

while(<>){
	@_ = map ~~<>, 1 .. $_;

	for( @_ ){
		my( $A, $B, $k ) = split;

		if( $k % 2 == 1 ){
			print $A * int( $k / 2 ) + $A - $B * int( $k / 2 );
			}
		else{
			print 0 + ( $A - $B ) / 2 * $k;
			}

		}

	}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	chomp;

	print $_ == 2 ? 2 : $_ % 2 ? 1 : 0;
	}

#!/usr/bin/env perl

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

# essential
my @tokens = ();

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

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

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

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

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

sub remainder {
    my ($dividend, $divisor) = @_;
}

# solve

my $q = read_token;

for (1..$q) {
    my $n = read_token;
    if ($n == 2) {
        say 2;
        next;
    }

    if ($n % 2 == 1) {
        say 1;
    }
    else {
        say 0;
    }
}


$\ = $/;

while(<>){
	for (1 .. $_){

		<>;
		my %names = map { $_, 1 } split ' ', <>;
		my @msgs = map ~~<>, 1 .. <>;

		chomp @msgs;

		@msgs = ( '!:', @msgs, '!:' );

		for (@msgs){
			my( $name, $text ) = split ':';

			my %cand;

			if( $name eq '?' ){
				%cand = %names;
				delete $cand{ $_ } for grep $names{ $_ }, /\w+/g;
			}

			$_ = {
				name => $name,
				text => $text,
				cand => { %cand },
				};
			}

		my $FAIL = 0;
		my $del = 1;

		while( $del ){
			$del = 0;
			for my $i (1 .. @msgs - 2, reverse 1 .. @msgs - 2){
				next if $msgs[$i]->{name} ne '?';

				delete $msgs[$i]->{cand}->{ $msgs[$i + $_]->{name} } and $del ++ for -1, 1;

				my $num = keys %{ $msgs[$i]->{cand} };
				if( $num == 1 ){
					( $msgs[$i]->{name} ) = keys %{ $msgs[$i]->{cand} };
					}
				elsif( $num == 0 ){
					$FAIL = 1;
					last;
					}
				}
			}

		my $idx = -2;
		my $key;

		for my $i (0 .. @msgs - 1){
			last if $FAIL;

			$idx == $i - 1 and delete $msgs[$i]->{cand}->{$key};

			$msgs[$i]->{name} eq '?' and do {
				$key = ( keys %{ $msgs[$i]->{cand} } )[ 0 ];
				%{ $msgs[$i]->{cand} } = ();
				$msgs[$i]->{name} = $key;
				$idx = $i;
				};
			}

		print $FAIL ? "Impossible" : join "\n", map { "$_->{name}:$_->{text}" } @msgs[1 .. @msgs-2];

		}

	}

$\ = $/;

while(<>){
	for (1 .. $_){

		<>;
		my %names = map { $_, 1 } split ' ', <>;
		my @msgs = map ~~<>, 1 .. <>;

		chomp @msgs;

		@msgs = ( '!:', @msgs, '!:' );

		for (@msgs){
			my( $name, $text ) = split ':';

			my %cand;

			if( $name eq '?' ){
				%cand = %names;
				delete $cand{ $_ } for grep $names{ $_ }, /\w+/g;
			}

			$_ = {
				name => $name,
				text => $text,
				cand => { %cand },
				};
			}

		my $FAIL = 0;
		my $del = 1;

		while( $del ){
			$del = 0;
			for my $i (1 .. @msgs - 2, 1 .. @msgs - 2){
				next if $msgs[$i]->{name} ne '?';

				delete $msgs[$i]->{cand}->{ $msgs[$i + $_]->{name} } and $del ++ for -1, 1;

				my $num = keys %{ $msgs[$i]->{cand} };
				if( $num == 1 ){
					( $msgs[$i]->{name} ) = keys %{ $msgs[$i]->{cand} };
					}
				elsif( $num == 0 ){
					$FAIL = 1;
					last;
					}
				}
			}

		my $idx = -2;
		my $key;

		for my $i (0 .. @msgs - 1){
			last if $FAIL;

			$idx == $i - 1 and delete $msgs[$i]->{cand}->{$key};

			$msgs[$i]->{name} eq '?' and do {
				$key = ( keys %{ $msgs[$i]->{cand} } )[ 0 ];
				%{ $msgs[$i]->{cand} } = ();
				$msgs[$i]->{name} = $key;
				$idx = $i;
				};
			}

		print $FAIL ? "Impossible" : join "\n", map { "$_->{name}:$_->{text}" } @msgs[1 .. @msgs-2];

		}

	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

while(<>){
	for (1 .. $_){
		$debug and print '-' x 10;

		my $n = <>;
		my %names = map { $_, 1 } split ' ', <>;
		my $m = <>;
		my @msgs = map ~~<>, 1 .. $m;

		chomp @msgs;

		unshift @msgs, 'a!:';
		push @msgs, 'z!:';

		for (@msgs){
			my( $name, $text ) = split ':';
			my @found_names = grep { $names{ $_ } } /\w+/g;

			$debug and print "${name}[@found_names]";

			my %cand_names;

			if( $name eq '?' ){
				%cand_names = %names;
				delete $cand_names{ $_ } for @found_names;
			}

			$_ = {
				name => $name,
				text => $text,
				cand => { %cand_names },
				};
			}

		$debug and do {
			for (@msgs){
				print "[$_->{name}]",
					"[$_->{text}]",
					"[", (join ' ', keys %{$_->{cand}} ), "]"
				}
			};

		my $FAIL = 0;
		my $del = 1;

		while( $del ){
			$del = 0;
			for my $i (1 .. @msgs - 2, reverse 1 .. @msgs - 2){
				next if $msgs[$i]->{name} ne '?';

				$debug and print map "<<$_>>", join ' ', keys %{ $msgs[$i]->{cand} };

				delete $msgs[$i]->{cand}->{ $msgs[$i-1]->{name} } and $del ++;
				delete $msgs[$i]->{cand}->{ $msgs[$i+1]->{name} } and $del ++;

				$debug and print "del:$del";

				my $num = keys %{ $msgs[$i]->{cand} };
				if( $num == 1 ){
					( $msgs[$i]->{name} ) = keys %{ $msgs[$i]->{cand} };
					}
				elsif( $num == 0 ){
					$FAIL = 1;
					last;
					}
				}
			}

		$debug and do {
			for (@msgs){
				print "[$_->{name}]",
					"[$_->{text}]",
					"[", (join ' ', keys %{$_->{cand}} ), "]"
				}
			};

		my $idx = -2;
		my $key;

		for my $i (0 .. @msgs - 1){
			last if $FAIL;

			$idx == $i - 1 and delete $msgs[$i]->{cand}->{$key};

			$msgs[$i]->{name} eq '?' and do {
				$key = ( keys %{ $msgs[$i]->{cand} } )[ 0 ];
				%{ $msgs[$i]->{cand} } = ();
				$msgs[$i]->{name} = $key;
				$idx = $i;
				};
			}

		shift @msgs;
		pop @msgs;

		print $FAIL ? "Impossible" : join "\n", map { "$_->{name}:$_->{text}" } @msgs;

		}

	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

while(<>){
	for (1 .. $_){
		$debug and print '-' x 10;

		my $n = <>;
		my %names = map { $_, 1 } split ' ', <>;
		my $m = <>;
		my @msgs = map ~~<>, 1 .. $m;

		chomp @msgs;

		unshift @msgs, 'a!:';
		push @msgs, 'z!:';

		for (@msgs){
			my( $name, $text ) = split ':';
			my @found_names = grep { $names{ $_ } } /\w+/g;

			$debug and print "${name}[@found_names]";

			my %cand_names;

			if( $name eq '?' ){
				%cand_names = %names;
				delete $cand_names{ $_ } for @found_names;
			}

			$_ = {
				name => $name,
				text => $text,
				cand => { %cand_names },
				};
			}

		$debug and do {
			for (@msgs){
				print "[$_->{name}]",
					"[$_->{text}]",
					"[", (join ' ', keys %{$_->{cand}} ), "]"
				}
			};

		my $FAIL = 0;
		my $del = 1;

		while( $del ){
			$del = 0;
			for my $i (1 .. @msgs - 2){
				next if $msgs[$i]->{name} ne '?';

				$debug and print map "<<$_>>", join ' ', keys %{ $msgs[$i]->{cand} };

				delete $msgs[$i]->{cand}->{ $msgs[$i-1]->{name} } and $del ++;
				delete $msgs[$i]->{cand}->{ $msgs[$i+1]->{name} } and $del ++;

				$debug and print "del:$del";

				my $num = keys %{ $msgs[$i]->{cand} };
				if( $num == 1 ){
					( $msgs[$i]->{name} ) = keys %{ $msgs[$i]->{cand} };
					}
				elsif( $num == 0 ){
					$FAIL = 1;
					last;
					}
				}
			}

		$debug and do {
			for (@msgs){
				print "[$_->{name}]",
					"[$_->{text}]",
					"[", (join ' ', keys %{$_->{cand}} ), "]"
				}
			};

		shift @msgs;
		pop @msgs;

		print $FAIL ? "Impossible" : join "\n", map { "$_->{name}:$_->{text}" } @msgs;

		}

	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

while(<>){
	for (1 .. $_){
		$debug and print '-' x 10;

		my $n = <>;
		my %names = map { $_, 1 } split ' ', <>;
		my $m = <>;
		my @msgs = map ~~<>, 1 .. $m;

		chomp @msgs;

		unshift @msgs, 'a!:';
		push @msgs, 'z!:';

		for (@msgs){
			my( $name, $text ) = split ':';
			my @found_names = grep { $names{ $_ } } /\w+/g;

			$debug and print "${name}[@found_names]";

			my %cand_names;

			if( $name eq '?' ){
				%cand_names = %names;
				delete $cand_names{ $_ } for @found_names;
			}

			$_ = {
				name => $name,
				text => $text,
				cand => { %cand_names },
				};
			}

		$debug and do {
			for (@msgs){
				print "[$_->{name}]",
					"[$_->{text}]",
					"[", (join ' ', keys %{$_->{cand}} ), "]"
				}
			};

		my $FAIL = 0;
		my $del = 1;

		while( $del ){
			$del = 0;
			for my $i (1 .. @msgs - 2){
				next if $msgs[$i]->{name} ne '?';

				$debug and print map "<<$_>>", join ' ', keys %{ $msgs[$i]->{cand} };

				delete $msgs[$i]->{cand}->{ $msgs[$i-1]->{name} } and $del ++;
				delete $msgs[$i]->{cand}->{ $msgs[$i+1]->{name} } and $del ++;

				$debug and print "del:$del";

				my $num = keys %{ $msgs[$i]->{cand} };
				if( $num == 1 ){
					( $msgs[$i]->{name} ) = keys %{ $msgs[$i]->{cand} };
					}
				elsif( $num == 0 ){
					$FAIL = 1;
					last;
					}
				}
			}

		$debug and do {
			for (@msgs){
				print "[$_->{name}]",
					"[$_->{text}]",
					"[", (join ' ', keys %{$_->{cand}} ), "]"
				}
			};

		my $idx = -2;
		my $key;

		for my $i (0 .. @msgs - 1){
			last if $FAIL;

			$idx == $i - 1 and delete $msgs[$i]->{cand}->{$key};

			$msgs[$i]->{name} eq '?' and do {
				$key = ( keys %{ $msgs[$i]->{cand} } )[ 0 ];
				%{ $msgs[$i]->{cand} } = ();
				$msgs[$i]->{name} = $key;
				$idx = $i;
				};
			}

		shift @msgs;
		pop @msgs;

		print $FAIL ? "Impossible" : join "\n", map { "$_->{name}:$_->{text}" } @msgs;

		}

	}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	@_ = map ~~<>, 1 .. $_;

	my $L = 0;
	my $R = 0;

	for( @_ ){
		my( $x, $y ) = split;
		$x > 0 and $R ++;
		$x < 0 and $L ++;
		}

	if( $R <= 1 or $L <= 1 ){
		print "Yes"
		}
	else{
		print "No"
		}
	}


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

sub issubstr {
    my ($s,$a) = @_;
    for (0 .. @$a-1) {
	return 1 if index($a->[$_],$s) != -1;
    }
    return 0;
}

my $n = int <>;
my @a;
for (1 .. $n) {
    my $s = <>;
    chomp $s;
    push @a, $s;
}
my $s = 'a';
while (issubstr($s,\@a)) {
    $s++;
}
print $s;

my $num = <>;
chomp $num;
my @title;
for (1..$num) {
    my $title = <>;
    chomp $title;
    push @title, $title;
}

my $title = '';
my $flag = 0;
while (!$flag) {
    for ('a'..'z') {
        my $new = $title.$_;
        if (!grep /$new/, @title) {
            $title = $new;
            $flag = 1;
            last;
        }
    }
    if (!$flag) {
        if ($title =~ /^z*$/) {
            $title = 'a' x (1 + length $title);
        } else {
            $title =~ /(.*?)([^z]z*)$/;
            my $temp = $2;
            $temp =~ y/a-z/b-za/;
            $title = $1.$temp;
        }
    }

}
print $title;

my $num = <>;
chomp $num;
my @title;
for (1..$num) {
    my $title = <>;
    chomp $title;
    push @title, $title;
}

my $title = '';
my $flag = 0;
while (!$flag) {
    for ('a'..'z') {
        my $new = $title.$_;
        if (!grep /$new/, @title) {
            $title = $new;
            $flag = 1;
            last;
        }
    }
    $title .= 'a' if !$flag;
}
print $title;


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

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

while( $test_case -- > 0 ){
  my ($r,$b,$d) = map { $_ - 0 } split(/\s+/,<STDIN>);
  if( $d == 0 ){
    print ( $r == $b ? "YES\n" : "NO\n" ); next;
  }
  ($r,$b) = ($b,$r) if $r < $b;
  my $di = $r - $b;
  my $dv = ($di+($d-1))/$d;
  if( $b < $dv ){
    print "NO\n";
  } else {
    print "YES\n";
  }

}

exit(0);


use strict;
use warnings;

use Data::Dumper;

sub main {

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

    for(my $i=0; $i<$q; $i++) {
        my $i= <$in>; chomp($i);
        my ($b, $p, $f)= split(' ', $i);

        $i= <$in>; chomp($i);
        my ($h, $c)= split(' ', $i);

        my $profit= 0;
        if($h > $c) { # make hamburgers as much as u can
            while($b>=2 && $p>0) {
                $profit += $h;
                $b-= 2;
                $p--;
            }

            while($b>=2 && $f>0) {
                $profit += $c;
                $b-= 2;
                $f--;
            }
        } else {
            while($b>=2 && $f>0) {
                $profit += $c;
                $b-= 2;
                $f--;
            }

            while($b>=2 && $p>0) {
                $profit += $h;
                $b-= 2;
                $p--;
            }
        }

        print $profit;
        print $/;
    }

}

main() unless caller();

#!/usr/bin/env perl

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

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

for (1..$t) {
    $line = <STDIN>;
    my ($b, $p, $f) = split q{ }, $line;
    $b = $b - 1 if $b % 2 == 1;
    $line = <STDIN>;
    my ($h, $c) = split q{ }, $line;

    my $price = 0;

    if ( $h > $c ) {
        $price += $h * make(\$b, \$p);
        $price += $c * make(\$b, \$f);
    }
    else {
        $price += $c * make(\$b, \$f);
        $price += $h * make(\$b, \$p);
    }
    say $price;
}

sub make {
    my ($b, $m) = @_;
    my $count = 0;
    if ( 2*$$m > $$b ) {
        $count = $$b/2;
        $$b = 0;
        $$m -= $count;
    }
    else {
        $count = $$m;
        $$m = 0;
        $$b -= 2 * $count;
    }
    return $count;
}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

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

	my( $b, $p, $f ) = split;
	my( $h, $c ) = split ' ', <>;

	$b /= 2;

	my $middle = 'p' x $p . 'f' x $f;

	if( $h < $c ){
		$middle = reverse $middle;
		}

	my $L = substr $middle, 0, $b;

	$debug and print $L;

	my $cp = () = $L =~ /p/g;
	my $cf = () = $L =~ /f/g;

	$debug and print "$cp $cf";

	print $cp * $h + $cf * $c;
	}

use strict;
use warnings;

use Data::Dumper;

sub main {

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

    for(my $i=0; $i<$q; $i++) {
        my $i= <$in>; chomp($i);
        my ($b, $p, $f)= split(' ', $i);

        $i= <$in>; chomp($i);
        my ($h, $c)= split(' ', $i);

        my $profit= 0;
        if($h > $c) { # make hamburgers as much as u can
            while($b>=2 && $p>0) {
                $profit += $h;
                $b-= 2;
                $p--;
            }

            while($b>=2 && $f>0) {
                $profit += $c;
                $b-= 2;
                $f--;
            }
        } else {
            while($b>=2 && $f>0) {
                $profit += $c;
                $b-= 2;
                $f--;
            }

            while($b>=2 && $p>0) {
                $profit += $h;
                $b-= 2;
                $p--;
            }
        }

        print $profit;
    }

}

main() unless caller();


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	my $A = 'a' x 4;

	my %h;

	$_ = join ' ', reverse
		map { $h{ $_ } or $h{ $_ } = ++ $A and "$A," } split ' ', <>;

	my $ans = 0;
	my $min;
	my $new_min;

	m/
		\b(\w+)\b(,)?+
		(?{
			if( not defined $min ){
				$min = $1;
				}
			elsif( $min lt $1 or $min eq $1 and !$2 ){
				$ans ++;
				}
			elsif( $min gt $1 ){
				if( not defined $new_min ){
					$new_min = $1;
					}
				else{
					$new_min gt $1 and $new_min = $1;
					$ans ++;
					}
				}

			if( $min eq $1 and $2 ){
				if( defined $new_min ){
					$min = $new_min;
					undef $new_min;
					$ans ++;
					}
				else{
					undef $min;
					}
				}
			})
		(*FAIL)
		/x;

	print $ans;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my @ABC;
my $abc = 'a';

for my $i ( 0 .. 2e5 ){
	push @ABC, $abc ++;
	}

while(<>){
	@_ = map $ABC[ $_ ], split ' ', <>;

	$_ = join ' ', @_;

	my %B;

	for my $i ( 0 .. @_ - 1 ){
		$B{ $_[ $i ] } = exists $B{ $_[ $i ] } ? $i : -1;
		}

	my $ans = 0;
	my $under = 0;
	my $cover;
	my $far_cover;
	my $far_dist;

	my $i = 0;

	m/
		\b\w+\b
		(?{
			$i ++;

			if( $under ){
				if( $& eq $cover ){
					if( $B{ $& } + 1 != $i ){
						$ans ++;
						}
					elsif( defined $far_dist and $far_dist >= $i ){
						$cover = $far_cover;
						undef $far_cover;
						undef $far_dist;
						}
					else{
						$under = 0;
						undef $cover;
						undef $far_dist;
						undef $far_cover;
						}
					}
				else{
					$ans ++;
					if( $B{ $& } > -1 and not
						( defined $far_dist and $B{ $& } <= $far_dist ) ){
						$far_dist = $B{ $& };
						$far_cover = $&;
						}
					}
				}
			else{
				if( $B{ $& } > -1 ){
					$cover = $&;
					$under = 1;
					}
				}
		})
		(*FAIL)
		/x;

	print $ans;
	}

#!/usr/bin/perl

use warnings;
use strict;

my $debug = 0;

$\ = $/;

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

	@_ = split ' ', <>;

	$debug and print "[@_]";

	my @B = ( -2 ) x ( @_ + 1 );

	for my $i ( 0 .. @_ - 1 ){
		if( $B[ $_[ $i ] ] == -2 ){
			$B[ $_[ $i ] ] = -1;
			}
		elsif( $B[ $_[ $i ] ] > -2 ){
			$B[ $_[ $i ] ] = $i;
			}
		}

	my $ans = 0;
	my $under = 0;
	my $cover;
	my $far_cover;
	my $far_dist;

	my $i = 0;

	while( @_ ){
		$_ = shift @_;
		$i ++;
		$debug and print "$i:[$_]";

		if( $under ){
			if( $_ == $cover ){
				$debug and print " 1)";
				if( $B[ $_ ] + 1 != $i ){
					$debug and print "  1.1) $B[$_],$i";
					$ans ++;
					}
				elsif( defined $far_dist and $far_dist >= $i ){
					$cover = $far_cover;
					undef $far_cover;
					undef $far_dist;
					}
				else{
					$under = 0;
					undef $cover;
					undef $far_dist;
					undef $far_cover;
					}
				}
			else{
				$debug and print " 2)";
				$ans ++;
				$debug and print " $cover,$_";
				if( $B[ $_ ] > -1 ){
					if( defined $far_dist ) {
						if( $B[ $_ ] > $far_dist ){
							$far_dist = $B[ $_ ];
							$far_cover = $_;
							}
						}
					else{
						$far_dist = $B[ $_ ];
						$far_cover = $_;
						}
					}
				}
			}
		else{
			$debug and print " 3)";
			if( $B[ $_ ] > -1 ){
				$cover = $_;
				$under = 1;
				}
			}

		}

	print $ans;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	my $A = 'a' x 4;

	my %h;

	$_ = join ' ', reverse
		map { $h{ $_ } or $h{ $_ } = ++ $A and "$A," } split ' ', <>;

	my $ans = 0;
	my $q = 0;
	my $min = 'z';

	m/
		\b(\w+)\b(,)?+
		(?{
			if( defined $2 and $min ge $1 ){
				$min eq $1 and -- $ans;
				$q > 1 and -- $ans;
				$q = 0;
				}
			else{
				++ $ans;
				$min gt $1 and $min = $1 and ++ $q;
				}
			})
		(*FAIL)
		/x;

	print $ans;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	my $A = 'a' x 4;

	my %h;

	$_ = join ' ', reverse
		map { $h{ $_ } or $h{ $_ } = ++ $A and "$A," } split ' ', <>;

	my $ans = 0;
	my $min = 'z';

	m/
		\b(\w+)\b(,)?+
		(?{
			if( $min lt $1 or $min eq $1 and !$2 ){
				$ans ++;
				}
			$1 lt $min and $min = $1;
			})
		(*FAIL)
		/x;

	print $ans;
	}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	my %h;

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

		for my $j ( 0 .. @_ - 1 ){
			$h{ $sum - $_[ $j ] }{ $i } = $j + 1;
			}
		}

	my $ok = 0;

	for my $i ( keys %h ){
		my @keys = keys %{ $h{ $i } };
		next if @keys < 2;
		print "YES";
		print $keys[ 0 ], ' ', $h{ $i }{ $keys[ 0 ] };
		print $keys[ 1 ], ' ', $h{ $i }{ $keys[ 1 ] };
		$ok = 1;
		last;
		}

	$ok or print "NO";
	}

use warnings;
use strict;
$\ = qq/\n/, $, = qq/ /;
sub sum {
    my $result = 0;
    $result += $_ for @{ $_ [ 0 ] };
    $result;
}
my $k = <STDIN>;
chomp ( $k );
my %h = ();
for my $i ( 1 .. $k ) {
    chomp ( my $n = <STDIN> );
    my @a = split qq/ /, <STDIN>;
    my $s = sum ( \@a );
    my $index = 1;
    for my $j ( @a ) {
        if ( exists $h { $s - $j } and $h { $s - $j } -> [ 0 ] != $i ) {
            print "YES";
            print + $i, $index;
            print + $h { $s - $j } -> [ 0 ], $h { $s - $j } -> [ 1 ];
            exit;
        } else { $h { $s - $j } = [ $i, $index ] }
        $index += 1;
    }
}
print "NO";

use warnings;
use strict;
$\ = qq/\n/, $, = qq/ /;
sub sum {
    my $result = 0;
    $result += $_ for @{ $_ [ 0 ] };
    $result;
}
my $k = <STDIN>;
chomp ( $k );
my %h = ();
for my $i ( 1 .. $k ) {
    chomp ( my $n = <STDIN> );
    my @a = split qq/ /, <STDIN>;
    my $s = sum ( \@a );
    my $index = 1;
    for my $j ( @a ) {
        if ( exists $h { $s - $j } and $h { $s - $j } -> [ 0 ] != $i ) {
            print "YES";
            print + $i, $j;
            print + $h { $s - $j } -> [ 0 ], $h { $s - $j } -> [ 1 ];
            exit;
        } else { $h { $s - $j } = [ $i, $index ] }
        $index += 1;
    }
}
print "NO";


#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

<>=~/1/ and $F++;
while(<>){
	/^1|1$/ and $F++;
	 $a=$_;
	}
$a=~/1/ and $F++;

print $F?2:4;

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

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

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

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

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

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

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

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

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

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

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

<>=~/1/ and $F++;
while($a=<>){
	$a=~/^1|1$/ and $F++;
	}
$a=~/1/ and $F++;

print $F?2:4;

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

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

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

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

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

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

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

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

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

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

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

<>=~/1/ and $F++;
while(<>){
	/^1|1$/ and $F++;
	}
/1/ and $F++;

print $F?2:4;

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

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	my( $n, $L, $R, $s ) = split;

	my $diff = $R - $L + 1;

	my @arr = 1 .. $diff;

	my $sum = 0;

	$sum += $_ for @arr;

	if( $s < $sum ){
		print -1;
		next;
		}

	my $i = @arr - 1;

	while( $s != $sum ){
		$arr[ $i ] ++;
		$sum ++;
		$i --;
		$i < 0 and $i = @arr - 1;
		}

	if( $arr[ @arr - 1 ] > $n ){
		print -1;
		next;
		}

	my %h;

	$h{ $_ } ++ for @arr;

	for( 1 .. $n ){
		next if exists $h{ $_ };

		push @arr, $_;
		}

	for( 1 .. $L - 1 ){
		my $tmp = pop @arr;
		unshift @arr, $tmp;
		}

	print "@arr";
	}


my $n = <>;
my @sizes = split ' ', <>;
my $line = <>; chomp $line;
my (@is, @es);
@is = sort { @sizes[$b - 1] <=> @sizes[$a - 1] } (1..$n);
for my $i (split '', $line) {
    if ($i eq '0') {
        $_ = pop @is;
        push @es, $_;
    } else {
        $_ = pop @es;
    }
    print $_ . ' ';
}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my %h;

	my $i = 0;

	map { $h{ $_ } = ++ $i } @_;

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

	$_ = <>, chomp;

	my @ans;
	my @stack;

	for( split // ){
		if( $_ ){
			push @ans, $h{ pop @stack };
			}
		else{
			my $w = shift @_;
			push @ans, $h{ $w };
			push @stack, $w;
			}
		}

	print "@ans";
	}


#!/usr/bin/env perl

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

chomp (my $line = <STDIN>);

for ( 1..$line ) {
    chomp ($line = <STDIN>);
    my ($c, $m, $x) = split q{ }, $line;
    my $answer = 0;

    $answer = min(min($c, $m), int(($c+$m+$x)/3));

    say $answer;
}

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

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

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

	my( $c, $m, $x ) = split;

	( $c, $m ) = sort { $b <=> $a } $c, $m;

	my( $min ) = sort { $a <=> $b } $c, $m, $x;

	$debug and print "$c, $m, $x";

	map $_ -= $min, $c, $m, $x;

	$debug and print "$c, $m, $x";

	print $min + do {
		if( $x == 0 ){
			( sort { $a <=> $b } int( ( $c + $m ) / 3 ), $m )[ 0 ];
			}
		else{
			0;
			}
		};
	}

#!/usr/bin/env perl

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

chomp (my $line = <STDIN>);

for ( 1..$line ) {
    chomp ($line = <STDIN>);
    my ($c, $m, $x) = split q{ }, $line;
    my $answer = 0;

    if ( $c >= 1 and $m >= 1 and $x >= 1 ) {
        my $min = min($c, $m, $x);
        $c -= $min, $m -= $min, $x -= $min;
        $answer += $min;
    }

    if ( $c >= 3 and $m >= 3 ) {
        my $min = min(int($c/3), int($m/3));
        $c -= 3*$min, $m -= 3*$min;
        $answer += $min*2;
    }

    if ( $c < $m ) {
        ($c, $m) = ($m, $c);
    }

    if ( $c >= 2 and $m >= 1 ) {
        $c -= 2, $m -= 1;
        $answer += 1;
        next;
    }
    last;

    say $answer;
}

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

#!/usr/bin/env perl

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

chomp (my $line = <STDIN>);

for ( 1..$line ) {
    chomp ($line = <STDIN>);
    my ($c, $m, $x) = split q{ }, $line;
    my $answer = 0;

    if ( $c >= 1 and $m >= 1 and $x >= 1 ) {
        my $min = min($c, $m, $x);
        $c -= $min, $m -= $min, $x -= $min;
        $answer += $min;
    }

    while ( 1 ) {

        if ( $c < $m ) {
            ($c, $m) = ($m, $c);
        }

        if ( $c >= 2 and $m >= 1 ) {
            my $min = min(int($c/2), $m);
            $c -= 2*$min, $m -= $min;
            $answer += $min;
            next;
        }
        last;
    }

    say $answer;
}

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

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

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

	my( $c, $m, $x ) = split;

	( $c, $m ) = sort { $b <=> $a } $c, $m;

	my( $min ) = sort { $a <=> $b } $c, $m, $x;

	$debug and print "$c, $m, $x";

	map $_ -= $min, $c, $m, $x;

	$debug and print "$c, $m, $x";

	print $min + do {
		if( $x == 0 ){
			int( ( $c + $m ) / 3 );
			}
		else{
			0;
			}
		};
	}


use strict;
use warnings;
use integer;

my $q = <>;
for (my $i = 0; $i < $q; $i++) {core();};

sub core {
	my ($n, $m) = readpos(); # board sizes
	my ($wx1, $wy1, $wx2, $wy2) = readrect(); # spill white rectangle
	my ($bx1, $by1, $bx2, $by2) = readrect(); # spill black rectangle

	my ($white, $black) = aftercolors($m, $n, $wx1, $wy1, $wx2, $wy2, $bx1, $by1, $bx2, $by2);
	print "$white $black\n";
}

sub readpos {
	<> =~ /(\d+)\s+(\d+)/;
	return ($1, $2);
}

sub readrect {
	<> =~ /(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/;
	return ($1, $2, $3, $4);
}

sub aftercolors {
	my ($m, $n, $wx1, $wy1, $wx2, $wy2, $bx1, $by1, $bx2, $by2) = @_;
	my $boardwhite    = white(1, 1, $m, $n);
	my $boardblack    = black(1, 1, $m, $n);

	my $whiteunderwhitespillarea = white($wx1, $wy1, $wx2, $wy2);
	my $blackunderwhitespillarea = black($wx1, $wy1, $wx2, $wy2);
	my $whiteunderblackspillarea = white($bx1, $by1, $bx2, $by2);
	my $blackunderblackspillarea = black($bx1, $by1, $bx2, $by2);

	my ($cx1, $cy1, $cx2, $cy2) = commonargs($wx1, $wy1, $wx2, $wy2, $bx1, $by1, $bx2, $by2);

	my $whiteundercommon = white($cx1, $cy1, $cx2, $cy2);
	my $blackundercommon = black($cx1, $cy1, $cx2, $cy2);

	my $white = $boardwhite + $blackunderwhitespillarea - $blackundercommon - $whiteunderblackspillarea;
	my $black = $boardblack - $blackunderwhitespillarea + $blackundercommon + $whiteunderblackspillarea;

	return ($white, $black);
}

sub valid {
	my ($x1, $y1, $x2, $y2) = @_;
	return $x1 <= $x2 && $y1 <= $y2;
}

sub commonargs {
	my ($wx1, $wy1, $wx2, $wy2, $bx1, $by1, $bx2, $by2) = @_;
	return (max($wx1, $bx1), max($wy1, $by1), min($wx2, $bx2), min($wy2, $by2));
}

sub color {
	my ($color, $x1, $y1, $x2, $y2) = @_;
	my $area = area($x1, $y1, $x2, $y2);

	if ($area % 2 == 0) {
		return $area / 2;
	} else {
		return colorpos($color, $x1, $y1) ? ($area + 1) / 2 : ($area - 1) / 2;
	}
}

sub colorpos {
	my ($color, $x, $y) = @_;
	my $diagonal = $x % 2 == $y % 2;
	return $color eq "white" ? $diagonal : !$diagonal;
}

sub white {
	my ($x1, $y1, $x2, $y2) = @_;
	return color("white", $x1, $y1, $x2, $y2);
}

sub black {
	my ($x1, $y1, $x2, $y2) = @_;
	return color("black", $x1, $y1, $x2, $y2);
}

sub area {
	my ($x1, $y1, $x2, $y2) = @_;
	if (valid($x1, $y1, $x2, $y2)) {
		my $lx = $x2 - $x1 + 1;
		my $ly = $y2 - $y1 + 1;
		return $lx * $ly;
	} else {
		return 0;
	}
}

# use List::Util qw[min max];
sub min {
	my ($a, $b) = @_;
	return $a <= $b ? $a : $b;
}
sub max {
	my ($a, $b) = @_;
	return $a <= $b ? $b : $a;
}

use strict;
use warnings;
use integer;

my $q = <>;
for (my $i = 0; $i < $q; $i++) {core();};

sub core {
	my ($n, $m) = readpos(); # board sizes
	my ($wx1, $wy1, $wx2, $wy2) = readrect(); # spill white rectangle
	my ($bx1, $by1, $bx2, $by2) = readrect(); # spill black rectangle

	my ($white, $black) = aftercolors($m, $n, $wx1, $wy1, $wx2, $wy2, $bx1, $by1, $bx2, $by2);
	print "$white $black\n";
}

sub readpos {
	<> =~ /(\d+)\s+(\d+)/;
	return ($1, $2);
}

sub readrect {
	<> =~ /(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/;
	return ($1, $2, $3, $4);
}

sub aftercolors {
	my ($m, $n, $wx1, $wy1, $wx2, $wy2, $bx1, $by1, $bx2, $by2) = @_;
	my ($boardwhite, $boardblack) = colors(1, 1, $m, $n);

	my ($whiteunderwhitespillarea, $blackunderwhitespillarea) = colors($wx1, $wy1, $wx2, $wy2);
	my ($whiteunderblackspillarea, $blackunderblackspillarea) = colors($bx1, $by1, $bx2, $by2);

	my ($cx1, $cy1, $cx2, $cy2) = commonargs($wx1, $wy1, $wx2, $wy2, $bx1, $by1, $bx2, $by2);
	my ($whiteundercommon, $blackundercommon) = colors($cx1, $cy1, $cx2, $cy2);

	my $white = $boardwhite + $blackunderwhitespillarea - $blackundercommon - $whiteunderblackspillarea;
	my $black = $boardblack - $blackunderwhitespillarea + $blackundercommon + $whiteunderblackspillarea;

	return ($white, $black);
}

sub valid {
	my ($x1, $y1, $x2, $y2) = @_;
	return $x1 <= $x2 && $y1 <= $y2;
}

sub commonargs {
	my ($wx1, $wy1, $wx2, $wy2, $bx1, $by1, $bx2, $by2) = @_;
	return (max($wx1, $bx1), max($wy1, $by1), min($wx2, $bx2), min($wy2, $by2));
}

sub colors {
	my ($x1, $y1, $x2, $y2) = @_;
	my $area = area($x1, $y1, $x2, $y2);

	if ($area % 2 == 0) {
		my $halfarea = $area / 2;
		return ($halfarea, $halfarea);
	} else {
		my ($more, $less) = (($area + 1) / 2, ($area - 1) / 2);
		return colorpos("white", $x1, $y1) ? ($more, $less) : ($less, $more);
	}
}

sub colorpos {
	my ($color, $x, $y) = @_;
	my $diagonal = $x % 2 == $y % 2;
	return $color eq "white" ? $diagonal : !$diagonal;
}

sub area {
	my ($x1, $y1, $x2, $y2) = @_;
	if (valid($x1, $y1, $x2, $y2)) {
		my $lx = $x2 - $x1 + 1;
		my $ly = $y2 - $y1 + 1;
		return $lx * $ly;
	} else {
		return 0;
	}
}

# use List::Util qw[min max];
sub min {
	my ($a, $b) = @_;
	return $a <= $b ? $a : $b;
}
sub max {
	my ($a, $b) = @_;
	return $a <= $b ? $b : $a;
}

use strict;
use warnings;
use integer;

<>;
while (<>) {
	/(\d+)\s+(\d+)/;
	my $r = sumbetween($1, $2);
	print $r, "\n";
}

sub sumbetween {
	my ($beg, $end) = @_;
	my $all = mount($end);
	my $before = mount($beg - 1);
	return $all - $before;
}

sub mount {
	my $i = shift(@_);
	my $sign = $i % 2 == 0 ? +1 : -1;
	# print "(", $sign * upperdiv($i, 2), ")";
	return $sign * upperdiv($i, 2);
}

sub upperdiv {
	my ($a, $b) = @_;
	my $r = $a / $b;
	$r++ if $a % $b > 0;
	return $r;
}


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

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

my $i = 1;
my @h;
while ($i != $n + 1) {
    $h[$i] = shift (@data);
    $i++;
}

if ($n == $k) {
    print $h[1];
    exit;
}

my @s;
my $j = 1;
while ($j != $n - 1) {
    $s[$j] = $h[$j] + $h[$j+1] + $h[$j+2];
    $j++;
}

my $j = 1;
my $p = $s[$j];
my $index = 0;
while ($j != $n - 2) {
    if (($p < $s[$j+1]) || ($p == $s[$j+1])) {
        $x = 0;
    }else{
        $p = $s[$j+1];
        $index = $j + 1;
    }
    $j++;
}

print $index;


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	print +( grep { /-/ || ( sqrt ) =~ /\./ } sort { $b <=> $a } split ' ', <> )[ 0 ]
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	print +( grep { ( sqrt ) =~ /\./ } grep !/-/, sort { $b <=> $a } split ' ', <> )[ 0 ]
	}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;
my $debug = 1;

while(<>){
	my( $n, $m ) = split;
	my $s = <>;
	my $t = <>;
	chomp $s;
	chomp $t;

	my @C;

	while( $t =~ /(?=(.{$n}))/g ){
		my $T = $1;
		my $S = $s;
		my @c;
		for( my $i = 0; $i < $n; $i ++ ){
			$T =~ s/.//;
			my $cT = $&;
			$S =~ s/.//;
			my $cS = $&;
			$cS eq $cT or push @c, $i + 1;
		}
		push @C, @c . "\n" . join ' ', @c;
		}

	my $min = ( sort { $a <=> $b } @C )[ 0 ];
	print $min;

	}


#Scott Heinrich - A01273823
use strict;
use warnings;
use 5.010;

my $count = 0;
my $line1 = <>;
chomp($line1);
my $line2 = <>;
chomp($line2);
my @n = split("",$line1);
my @m = split("",$line2);
my %nhash;
my %mhash;
my $pass = 1;

#make both hashes, key is character in @n,@m
foreach (@n)
{
  $nhash{$_}++;
}
foreach (@m)
{
  $mhash{$_}++;
}

foreach my $key (keys %mhash)
{
    if(!$nhash{$key})
    {
        $pass = 0;
        last;
    }
    if($nhash{$key} > $mhash{$key})
    {
      $count += $mhash{$key}
    }
    else
    {
      $count += $nhash{$key}
    }
}

if ($pass)
{
  say $count;
}
else
{
  say "-1";
}

#!perl

chomp ($string1 =<>);
chomp ($string2 =<>);

@array1 = split('',$string1);
@array2 = split('',$string2);

%hash1;
%hash2;
for $char (@array1)
{
($hash1{$char})++;
}

for $char (@array2)
{
($hash2{$char})++;
}

$sum;
for (keys(%hash2))
{
    if($hash1{$_} == 0) {$fail = 1;}
    $sum += min($hash1{$_},$hash2{$_});
}

if (($sum == 0)or $fail)
{
 print (-1);
}
else
{
print $sum;
}
<>;
sub min ($$)
{
    if($_[0] < $_[1])
    {
    return $_[0];
    }
    else
    {
    return $_ [1];
    }
}

sub n{print "\n"}
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

while(<>){

	$a=$_;
	$b=<>;
	chomp $a;
	chomp $b;
	#a..z
	#count a string 1
	#count a string 2
	#cnt1 <=> cnt 2

	$ans=0;
	$f=0;
	for $i('a'..'z'){

		$cnt1 = count($i,(split//,$a));
		$cnt2 = count($i,(split//,$b));
		if (!$cnt1 and $cnt2){$f++}

		if ($cnt1 < $cnt2){ $ans += $cnt1}
		else { $ans += $cnt2 }

	}
	if ($f){print -1;next}
	print $ans? $ans : -1 ;
	n();

	}

sub n{print "\n"}
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

while(<>){

	$a=$_;
	$b=<>;
	#a..z
	#count a string 1
	#count a string 2
	#cnt1 <=> cnt 2

	$ans=0;
	for $i('a'..'z'){

		$cnt1 = count($i,(split//,$a));
		$cnt2 = count($i,(split//,$b));

		if ($cnt1 < $cnt2){ $ans += $cnt1}
		else { $ans += $cnt2 }

	}

	print $ans? $ans : -1 ;
	n();

	}

sub n{print "\n"}
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

while(<>){

	$a=$_;
	$b=<>;
	chomp $a;
	chomp $b;
	#a..z
	#count a string 1
	#count a string 2
	#cnt1 <=> cnt 2

	$ans=0;
	for $i('a'..'z'){

		$cnt1 = count($i,(split//,$a));
		$cnt2 = count($i,(split//,$b));

		if ($cnt1 < $cnt2){ $ans += $cnt1}
		else { $ans += $cnt2 }

	}

	print $ans? $ans : -1 ;
	n();

	}

#Scott Heinrich - A01273823
use strict;
use warnings;
use 5.010;

my $count = 0;
my $line1 = <>;
chomp($line1);
my $line2 = <>;
chomp($line2);
my @n = split("",$line1);
my @m = split("",$line2);
my %nhash;
my %mhash;

#make both hashes, key is character in @n,@m
foreach (@n)
{
  $nhash{$_}++;
}
foreach (@m)
{
  $mhash{$_}++;
}

foreach my $key (keys %mhash)
{
    if(!$nhash{$key})
    {
        say "-1";
        last;
    }
    if($nhash{$key} > $mhash{$key})
    {
      $count += $mhash{$key}
    }
    else
    {
      $count += $nhash{$key}
    }
}

if ($count)
{
  say $count;
}

#Scott Heinrich - A01273823
use strict;
use warnings;
use 5.010;

my $count = 0;
my $line1 = <>;
chomp($line1);
my $line2 = <>;
chomp($line2);
my @n = split("",$line1);
my @m = split("",$line2);
my %nhash;
my %mhash;

#make both hashes, key is character in @n,@m
foreach (@n)
{
  $nhash{$_}++;
}
foreach (@m)
{
  $mhash{$_}++;
}

foreach my $key (keys %mhash)
{
    if(!$nhash{$key})
    {
        say "-1";
        last;
    }
    if($nhash{$key} > $mhash{$key})
    {
      $count += $mhash{$key}
    }
    else
    {
      $count += $nhash{$key}
    }
}

if ($count != 0)
{
  say $count;
}

#!perl

chomp ($string1 =<>);
chomp ($string2 =<>);

@array1 = split('',$string1);
@array2 = split('',$string2);

%hash1;
%hash2;
for $char (@array1)
{
($hash1{$char})++;
}

for $char (@array2)
{
($hash2{$char})++;
}

$sum;
for (keys(%hash2))
{

    $sum += min($hash1{$_},$hash2{$_});
}

if ($sum == 0)
{
 print (-1);
}
else
{
print $sum;
}
<>;
sub min ($$)
{
    if($_[0] < $_[1])
    {
    return $_[0];
    }
    else
    {
    return $_ [1];
    }
}


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

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

while( $testcase -- > 0 ){
  my @A = map { $_ - 0 } split(/\s+/,<STDIN>);
  $A[2] = $A[6] - $A[0] - $A[1];
  print ( join(' ',@A[0..2]) . "\n" );
}

exit(0);


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	$_ = <>, chomp;

	my %h;

	map $h{ $_ } ++, m/./g;

	print 0 + ( length ) + keys %h;
	}


#!/usr/bin/perl
use 5.010;

sub Solve {
    my $ret = 0;
    my $inc = 1;
    while (($idx, $val) = each(@_)) {
        $idx == $val && $ret++;
        $idx != $val && $_[$val] == $idx && ($inc = 2);
    }
    return $ret == @_? $ret : $ret + $inc;
}

while (<>) {
    @line = split /\s+/, <>;
    say Solve(@line);
}

my $num = <>;
chomp $num;
my @perm = split ' ', <>;
my %perm = map { $_, $perm[$_] } 0..$num-1;
$count = 0;
my $ext = 0;
for (0..$num-1) {
    if ($perm{$_} == $_) {
        $count++;
    } elsif (!$ext && $perm{$perm{$_}} == $_) {
        $ext = 2;
    }
}
$ext = 1 unless $ext == 2 || $count == $num;
$count += $ext;
print $count;


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

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

while( $test_case -- > 0 ){
  my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
  my @a = split(//,( '' . $n ));
  my $mx = 1;
  for(my $i=0;$i<=$#a;$i++){
    $mx = $a[$i] - 0 if $a[$i] - 0 > $mx;
  }
  print "$mx\n";
}

exit(0);

<>;
chomp, print +(sort split'')[-1] . $/ for <>

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

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

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

  my $cnt = 0;
  while( $n > 0 ){
    my $ns = '' . $n;
    my $ov = undef;
    my $top = substr($ns,0,1) - 0;
    my $ms = $top;
    for(my $i=1;$i<length($ns);$i++){
      if( $ov ){
        $ms .= $top;
      } else {
        my $j = substr($ns,$i,1) - 0;
        if( $j == $top ){
          $ms .= $top;
        } else {
          $ms .= ( $j > $top ? $top : '0' );
          $ov = 1;
        }
      }
    }
    $n -= ( $ms - 0 );
    $cnt += $top;
  }
  print "$cnt\n";

}

exit(0);


use strict;
use warnings;

$\ = "\n";

sub dist {
    my ($x, $y, $n) = @_;
    ($y - $x + $n) % $n;
}

my ($n, $m) = split ' ', <>;
my @tasks = split ' ', <>;
my $pos = 1;
my $time = 0;

for my $task (@tasks) {
    $time += dist($pos, $task, $n);
    $pos = $task;
}

print $time;

($n, $m) = split ' ', <>;
@arr = split ' ', <>;
$total = 0;
$last = 1;
for (@arr) {
    if ($_ >= $last) {
        $total += $_ - $last;
        $last = $_;
    } else {
        $total += $n - ($last - $_);
        $last = $_;
    }
}
print $total;

#!/usr/bin/perl

use strict;
use warnings;

use constant POS_START=>1;  # 開始位置

main();

## main()
# メイン処理
sub main {
    # 標準入力の取得
    my $line1 = <>;
    my $line2 = <>;
    chomp($line1);
    chomp($line2);

    # 標準入力の解析
    my ($n, $m) = split(/ /, $line1);
    my (@a) = split(/ /, $line2);
    if ($m != $#a+1) {
        print "illeagal arguments\n";
        exit -1;
    }

    my $pos = POS_START;
    my $cnt_round = 0;
    foreach(@a) {
        if ($_ > $n || $_ < 1) {
            print "illeagal arguments\n";
            exit -1;
        }
        if ($pos > $_) { $cnt_round++; }
        $pos = $_;
    }

    my $time_total = $cnt_round * $n + $pos - POS_START;
    print "$time_total\n";
}

#!/usr/bin/perl

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

@_=split/ /,<>;
unshift @_,1;
for $i(1..@_-1){
    $_[$i]>=$_[$i-1] ? ($sum+=$_[$i]-$_[$i-1]) : ($sum+= $`+$_[$i]-$_[$i-1]);
    }
print $sum;

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

use warnings;
use strict;

$\ = $/;

my $MOD = 1e9 + 7;

while(<>){
	chomp;
	my $c;
	my $ans = 0;
	my $B = 0;

	while( $c = chop ){

		if( $c eq 'b' ){
			$B ++;
			}
		else{
			map { $_ %= $MOD } $ans += $B, $B <<= 1;
			}
		}

	print $ans;
	}


$_ = <STDIN>;
chomp;

if ( $_=~m/[BCDEFGJKLNPQRSZ]/ ){
    print "NO";
}else{
    if ( $_ eq (reverse $_)){
        print "YES";
    }else{
        print "NO";
    }
}

$_=<>; chomp;
$r=reverse$_;
print /[^AHIOMT-Y]/ || $r ne $_? NO:YES

use strict;
use POSIX;

chomp (my $s = <>);
my @s = split '', $s;
print "NO" and exit if $s=~ m/[BCDEFGJKLNPQRSZ]/;
my $f=0;
a:for(0..$#s/2)
{
if ($s[$_] ne $s[$#s - $_])
{
$f = 2;
last a;

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

$st=<>;
chomp($st);
$rv=reverse $st;
($rv ne $st || $st=~/[^AHIOMT-Y]/ )? print "NO":print "YES";

use integer;

while(<>){

	chomp;
	$f=0;

	# A H I O U V W T Y X M
	# <>

	$le = length;
	@_=qw(A H I O U V W T Y X M);
#	print "@_\n";

	/[^AHIOUVWTYXM]/ and $f=1;

	@a=split//;
#	print 0+@a,"\n";

	if (!$f)
	{
		for $i(0..(@a/2)){

			$a[$i] eq $a[@a-$i-1] or $f=2;

		}

	}
#	print "$f\n";
	print $f? "NO\n":"YES\n";

	}

#Scott Heinrich - A01273823
use strict;
use warnings;
use 5.010;

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

if ($line1 =~ m/[BCDEFGJKLNPQRSZ]/)
{
  say "NO";
  exit;
}
elsif ($line1 eq reverse($line1))
{
  say "YES";
  exit;
}
else
{
  say "NO";
  exit;
}

$_ = <STDIN>;
chomp;

if ( $_=~m/[BCDEFGJKLMNPQRSZ]/ ){
    print "NO";
}else{
    if ( $_ eq (reverse $_)){
        print "YES";
    }else{
        print "NO";
    }
}

#Scott Heinrich - A01273823
use strict;
use warnings;
use 5.010;

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

if ($line1 =~ m/[BCDEFGJKLNPQRSZ]/)
{
  say "No";
  exit;
}
elsif ($line1 eq reverse($line1))
{
  say "Yes";
  exit;
}
else
{
  say "No";
  exit;
}

use strict;
use POSIX;

chomp (my $s = <>);
my @s = split '', $s;
print "NO" and exit if $s=~ m/[BCDEFGJKLNPQRS]/;
my $f=0;
a:for(0..$#s/2)
{
if ($s[$_] ne $s[$#s - $_])
{
$f = 2;
last a;

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

$st=<>;
chomp($st);
$rv=reverse $st;
($rv eq $st)? print "YES":print "NO";

$st=<>;
chomp($st);
$rv=reverse $st;
($rt eq $st && length($rt)!=1)? print "YES":print "NO";

$st=<>;
chomp($st);
$rv=reverse $st;
($rv eq $st&& length($rv)!=1)? print "YES":print "NO";

$st=<>;
chomp($st);
$rv=reverse $st;
($rv eq $st && length($rv)!=1)? print "YES":print "NO";

$st=<>;
chomp($st);
$rt=reverse $st;
($rt eq $st && length($rt)!=1)? print "YES":print "NO";

$st=<>;
chomp($st);
$rv=reverse $st;
($rv ne $st || $st=~/[^AHITOMY]/ )? print "NO":print "YES";


use strict;
<>;
my (@a) = split (' ',<>);
my $cop=0;
my $ans = 0;
for my $event (@a)
{
    if($event > 0)
    {
        $cop += $event;
    }
    else
    {
        $ans++ if $cop == 0;
        $cop-- if $cop > 0;
    }
}
print $ans;

my $n = <>;
chomp($n);
my $in = <>;
chomp($in);
my @A = split ' ', $in;
my ($sum, $ans) = (0, 0);
for (my $i = 0; $i < $n; ++$i) {
    $sum += $A[$i];
    $ans = $sum if $ans > $sum;
}
print abs $ans;

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

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

<>;
my @events = split ' ', <>;
my $free = 0;
my $missed = 0;

for my $event (@events) {
    $free += $event;
    while ($free < 0) {
        $missed++;
        $free++;
    }
}

print $missed, "\n";


#!/usr/bin/perl

use warnings;
use strict;
use bignum;

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

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

	while( $k > $d ){
		if( $k % $d == 0 ){ $d = $k; last; }
		my $i = int $k / $d;
		$d = ( $i + 1 ) * $d;
		}

	$debug and print "[$k|$d]";

	my $c = $k + 0.5 * ( $d - $k );

	print do {

		if( $k == $d ){
			$t;
			}
		else{
			my $i = int $t / $c;
			my $r = $t - $i * $c;

			$debug and print " <$i|$r>";

			$i * $d +
				do {
					if( $r <= $k ){
						$r;
						}
					else{
						$k + 2 * ( $r - $k );
						}
				};
			}
		};

	}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $i = 0;

	OUTER:
	while( @_ ){
		while( $_[ 0 ] == 0 ){
			shift @_;
			next OUTER;
			}
		while( $_[ @_ - 1 ] == 1 ){
			pop @_;
			next OUTER;
			}

		$i ++;
		shift @_;
		pop @_;
		}

	print $i;
	}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	@_ = split ' ', <>;

	my $sum = 0;

	$sum += (int $_ / $k) + !!($_ % $k) for @_;

	print int( $sum / 2 ) + $sum % 2;

	}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	chomp;

	if( $_ % 2 == 1 ){
		print -1;
		next;
		}

	$_ >>= 1;

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

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	chomp;

	if( $_ % 2 == 1 ){
		print -1;
		next;
		}

	$_ >>= 1;

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


use strict;
use warnings;

use Data::Dumper;

my $n = <>;
chomp $n;

die ('wrong n..') unless $n >= 1;

my %player_wins;
$player_wins{Mishka} = 0;
$player_wins{Chris} = 0;

for (my $i=0; $i<$n; $i++) {
    my $in = <>;
    chomp $in;
    my ($m , $c) = split(' ', $in);

    if ($m > $c) {
        $player_wins{Mishka}++;
    } elsif($c > $m) {
        $player_wins{Chris}++;
    }
}

if ($player_wins{Mishka} > $player_wins{Chris}) {
    print 'Mishka';
} elsif($player_wins{Chris} > $player_wins{Mishka}) {
    print 'Chris';
} else {
    print 'Friendship is magic!^^';
}

# cf703a
my $n=<>;
my $s;
foreach (<>) {
  my ($m,$c)=split(' ',$_);
  if($m>$c) {++$s;}
  elsif($m<$c) {--$s;}
}

print $s>0 ? 'Mishka' : $s<0 ? 'Chris' : 'Friendship is magic!^^';

#!/usr/bin/env perl

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

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

# essential
my @tokens = ();

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

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

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

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

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

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

# solve

my $a = "Mishka";
my $b = "Chris";
my $c = "Friendship is magic!^^";

my $n = read_token;

my $balance = 0;

for (1..$n) {
    my $p = read_token;
    my $q = read_token;
    $balance++ if $p > $q;
    $balance-- if $p < $q;
}

say $a if $balance > 0;
say $b if $balance < 0;
say $c if $balance == 0;

use strict;
use warnings;

use Data::Dumper;

my $n = <>;
chomp $n;

die ('wrong n..') unless $n >= 1;

my %player_wins;
$player_wins{Mishka} = 0;
$player_wins{Chris} = 0;

for (my $i=0; $i<$n; $i++) {
    my $in = <>;
    chomp $in;
    my ($m , $c) = split(' ', $in);

    if ($m > $c) {
        $player_wins{Mishka}++;
    } else {
        $player_wins{Chris}++;
    }
}

if ($player_wins{Mishka} > $player_wins{Chris}) {
    print 'Mishka';
} elsif($player_wins{Chris} > $player_wins{Mishka}) {
    print 'Chris';
} else {
    print 'Friendship is magic!^^';
}

use strict;
use warnings;

my $n = <>;
chomp $n;

die ('wrong n..') unless $n >= 1;

my %player_wins;
$player_wins{Mishka} = 0;
$player_wins{Chris} = 0;
$player_wins{draw} = 0;

for (my $i=0; $i<$n; $i++) {
    my $in = <>;
    chomp $in;
    my ($m , $c) = split(' ', $in);

    if ($m == $c) {
        $player_wins{draw}++;
    } elsif ($m > $c) {
        $player_wins{Mishka}++;
    } else {
        $player_wins{Chris}++;
    }
}

my $max = 'draw';

    if ($player_wins{Mishka} > $player_wins{$max}) {
        $max = 'Mishka';
    }
    if ($player_wins{Chris} > $player_wins{$max}) {
        $max = 'Chris';
    }
    if ($player_wins{Chris} == $player_wins{Mishka}) {
        $max = 'draw';
    }
print $max;

use strict;
use warnings;

my $n = <>;
chomp $n;

die ('wrong n..') unless $n >= 1;

my %player_wins;
$player_wins{Mishka} = 0;
$player_wins{Chris} = 0;
$player_wins{draw} = 0;

for (my $i=0; $i<$n; $i++) {
    my $in = <>;
    chomp $in;
    my ($m , $c) = split(' ', $in);

    if ($m == $c) {
        $player_wins{draw}++;
    } elsif ($m > $c) {
        $player_wins{Mishka}++;
    } else {
        $player_wins{Chris}++;
    }
}

my $max = 'draw';

    if ($player_wins{Mishka} > $player_wins{$max}) {
        $max = 'Mishka';
    }
    if ($player_wins{Chris} > $player_wins{$max}) {
        $max = 'Chris';
    }
    if ($player_wins{Chris} == $player_wins{Mishka}) {
        $max = 'draw';
    }
my $out = ($max eq 'draw') ? 'Friendship is magic!^^' : $max;

print $out;

use strict;
use warnings;

use Data::Dumper;

# rows 10
# per row: 2x2
# find to seats next to each other...

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

die('wrong number or rows') unless $n >=0 && $n <= 100;

# store input as array with length n * 2
# loop array, find first seat with OO.
# found: change 00 to ++
# exit and print result

my @buss;
my @left;
my @right;
for (0..$n-1) {
    my $in = <>;
    chomp($in);
    my @seats = split('\|', $in);
#    print Dumper \@seats;
    push @left, $seats[0];
    push @right, $seats[1];
}
@buss = (@left, @right);

for (@buss) {
    if ($_ eq 'OO') {
        print "YES\n";
        $_ = '++';
        print_bus(\@buss, $n);
        exit;
    }
}
print "NO\n";

sub print_bus {
    my ($buss, $n) = @_;

    for (my $i=0; $i<$n; $i++) {
        my $row = $buss->[$i] . '|' . $buss->[$n + $i];
        print $row . "\n";
    }
}

use strict;
use warnings;

my $n = <>;
chomp $n;

die ('wrong n..') unless $n >= 1;

my %player_wins;
for (my $i=0; $i<$n; $i++) {
    my $in = <>;
    chomp $in;
    my ($m , $c) = split(' ', $in);

    if ($m == $c) {
        $player_wins{draw}++;
    } elsif ($m > $c) {
        $player_wins{Mishka}++;
    } else {
        $player_wins{Chris}++;
    }
}

my @sorted = sort { $player_wins{$b} <=> $player_wins{$a} } keys %player_wins;
my $winner = shift @sorted;

my $out = ($winner eq 'draw') ? 'Friendship is magic!^^' : $winner;

print $out;


#!/usr/bin/env perl

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

# essential
my @tokens = ();

my @sums = split q{ }, read_line();

@sums = sort { $a <=> $b } @sums;

my $abc = pop @sums;

my $answer = '';

$answer .= $sums[0] + $sums[1] - $abc;
$answer .= ' ';
$answer .= $sums[1] + $sums[2] - $abc;
$answer .= ' ';
$answer .= $sums[2] + $sums[0] - $abc;

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

my $line = <STDIN>;
chomp $line;
my @numbers = split ' ', $line;

my $max = 0;
my $idx = 0;
for (@numbers) {
    $max = $idx if $_ > $numbers[$max];
    $idx++;
}

my @output;
$idx = 0;
for (@numbers) {
    if ($idx != $max) {
        push @output, $numbers[$max] - $_;
    }
    $idx++;
}

print join(' ', @output) . "\n";

my $line = <STDIN>;
chomp $line;
my @numbers = split ' ', $line;

my $max = -1;
my $idx = 0;
for (@numbers) {
    $max = $idx if $_ > $numbers[max];
    $idx++;
}

my @output;
$idx = 0;
for (@numbers) {
    if ($idx != $max) {
        push @output, $numbers[$max] - $_;
    }
    $idx++;
}

print join(' ', @output) . "\n";

#!/usr/bin/env perl

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

# essential
my @tokens = ();

my @sums = split q{ }, read_line();

@sums = sort { $a <=> $b } @sums;

say @sums;

my $abc = pop @sums;

my $answer = '';

$answer .= $sums[0] + $sums[1] - $abc;
$answer .= ' ';
$answer .= $sums[1] + $sums[2] - $abc;
$answer .= ' ';
$answer .= $sums[2] + $sums[0] - $abc;

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

#!/usr/bin/env perl

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

# essential
my @tokens = ();

my @sums = split q{ }, read_line();

@sums = sort @sums;

my $abc = pop @sums;

my $answer = '';

$answer .= $sums[0] + $sums[1] - $abc;
$answer .= ' ';
$answer .= $sums[1] + $sums[2] - $abc;
$answer .= ' ';
$answer .= $sums[2] + $sums[0] - $abc;

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


use warnings; use strict;
my ($n, $m) = split ' ', scalar<>;
$n += 0; $m+= 0;
my @a = split ' ', scalar <>; $_ += 0 foreach @a;
my @b = split ' ', scalar <>; $_ -= 1 foreach @b;
my @c = (0) x $n;
my @after = (0) x $n;
$after[$_] = [(0) x $n] foreach (0 .. ($n-1));
my $res = 0;
foreach my $b (@b){
    $res += $c[$b];
    #print @{$after[$_]}, "\n" foreach (0 .. ($n-1));
    #print join ' ', @c;
    #print " $res\n";
    foreach (0 .. ($n-1)){
        $c[$_] += $a[$b] unless $after[$b][$_];
        }
    foreach (0 .. ($n-1)){
        $after[$b][$_] = 1;
        $after[$_][$b] = 0;
        }
    $c[$b] = 0;
    }
print "$res\n";

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

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

my @order;
my %seen;
foreach (@b) {
  push @order, $_ if not exists $seen{$_};
  $seen{$_}++;
}

my @arr;
foreach (@order) {
  push @arr, $w[$_ - 1];
}

# printf "@arr\n";
my $sum = 0;
my $x;

sub findIdx {
  for (my $i = 0; $i < @order; $i++) {
    return $i if ($order[$i] == $_[0])
  }
}

foreach (@b) {
  $x = &findIdx($_);
  $sum += &sum(@arr[0 .. ($x - 1)]) if ($x > 0);
  unshift @arr, splice @arr, $x, 1;
  unshift @order, splice @order, $x, 1;
}

printf "$sum\n";


$,=" ";
my $n=<>;
my $str=<>;
chomp($str);
while(1)
{
  last if index($str,'><')<0;
  $str =~ s/>+<+//g;
}

print length($str) , "\n";

$,=" ";
my $n=<>;
my $str=<>;
chomp($str);
while(1)
{
  last if index($str,'><')<0;
  $str =~ s/><//g;
}

print length($str) , "\n";


#!/usr/bin/perl

use warnings;
use strict;

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

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

	my @sA = sort { $a <=> $b } @A;
	my @B;

	my $prev = $sA[ 0 ];
	my %h;

	for my $i ( 0 .. @sA - 1 ){
		next if $sA[ $i ] == $prev;
		$h{ $sA[ $i ] } = $i;
		$prev = $sA[ $i ];
		}

	$debug and print "$_ => $h{ $_ }" for sort keys %h;

	for( 1 .. $k ){
		my( $u, $v ) = split ' ', <>;
		$debug and print "$u|$v||$A[ $u - 1 ]|$A[ $v - 1 ]";
		next if $A[ $u - 1 ] == $A[ $v - 1 ];
		$B[ $A[ $u - 1 ] > $A[ $v - 1 ] ? $u - 1 : $v - 1 ] --;
		}

	$debug and print "$_ => $h{ $_ }" for sort keys %h;

	print join ' ', map { ( $h{ $_ } || 0 ) + shift @B } @A;

	$debug and print '-' x 15;
	}

# author : Gabriel Hofer
use strict;
use warnings;
use constant NL => qq/\n/;
sub max { $_ [ 0 ] > $_ [ 1 ] ? $_ [ 0 ] : $_ [ 1 ] }
my %quarrel = ();
my ( $n, $k ) = split qq / /, <STDIN>;
my @skill = split qq/ /, <STDIN>;
my @skill_sorted = sort { $a <=> $b } @skill;

my %h = ();
AA: for ( 1 .. $k  ) {
    my ( $five, $six ) = split qq/ /, <STDIN>;
    if ( $skill [ $five - 1 ] > $skill [ $six - 1 ] ) {
        $quarrel { $five } = 0 if not exists $quarrel { $five };
        $quarrel { $five } += 1;
        next AA
    } elsif ( $skill [ $five - 1 ] < $skill [ $six - 1 ] ) {
        $quarrel { $six } = 0 if not exists $quarrel { $six };
        $quarrel { $six } += 1;
        next AA
    }
}

AB: for my $j ( 1 .. ($#skill + 1) ) {
    (not (my $left = 0)) and (my $right = $#skill + 1) and (my $mid);
    AC: while ( $left < $right ) {
        $mid = int ( ( $left + $right ) / 2 );
        if ( $skill_sorted [ $mid ] < ($skill [ $j - 1 ]) ) { ($left = $mid + 1) and next AC }
        else { ($right = $mid) and next AC }
    }
    $mid = int ( ( $left + $right ) / 2 );
    if ( exists $quarrel { $j } ) { print max ( 0, $mid - $quarrel { $j } ) }
    else { print $mid }
    print qq/ /;
}
print NL;

# author : Gabriel Hofer
use strict;
use warnings;
use constant NL => qq/\n/;
sub max { $_ [ 0 ] > $_ [ 1 ] ? $_ [ 0 ] : $_ [ 1 ] }
my %quarrel = ();
my ( $n, $k ) = split qq / /, <STDIN>;
my @skill = split qq/ /, <STDIN>;
my @skill_sorted = sort { $a <=> $b } @skill;

my %h = ();
AA: for ( 1 .. $k  ) {
    my ( $five, $six ) = ( <STDIN> =~ m /(\d+)\s(\d+)/ );
    my $nine;
    if ( $skill [ $five - 1 ] > $skill [ $six - 1 ] ) { $nine = $five }
    else { $nine = $six }
    $quarrel { $nine } = 0 if not exists $quarrel { $nine };
    $quarrel { $nine } += 1;
}

AA: for my $j ( 1 .. ($#skill + 1) ) {
    (not (my $left = 0)) and (my $right = $#skill + 1) and (my $mid);
    AB: while ( $left < $right ) {
        $mid = int ( ( $left + $right ) / 2 );
        if ( $skill_sorted [ $mid ] < ($skill [ $j - 1 ]) ) { ($left = $mid + 1) and next AB }
        else { ($right = $mid) and next AB }
    }
    $mid = int ( ( $left + $right ) / 2 );
    if ( exists $quarrel { $j } ) { print $mid - $quarrel { $j } }
    else { print $mid }
    print qq/ /;
}
print NL;

# author : Gabriel Hofer
use strict;
use warnings;
use constant NL => qq/\n/;
sub max { $_ [ 0 ] > $_ [ 1 ] ? $_ [ 0 ] : $_ [ 1 ] }
my %quarrel = ();
my ( $n, $k ) = split qq / /, <STDIN>;
my @skill = split qq/ /, <STDIN>;
my @skill_sorted = sort { $a <=> $b } @skill;

my %h = ();
AA: for ( 1 .. $k  ) {
    my ( $five, $six ) = ( <STDIN> =~ m /(\d+)\s(\d+)/ );
    my $nine;
    if ( $skill [ $five - 1 ] > $skill [ $six - 1 ] ) { $nine = $five }
    else { $nine = $six }
    $quarrel { $nine } = 0 if not exists $quarrel { $nine };
    $quarrel { $nine } += 1;
}

AA: for my $j ( 1 .. ($#skill + 1) ) {
    (not (my $left = 0)) and (my $right = $#skill + 1) and (my $mid);
    AB: while ( $left < $right ) {
        $mid = int ( ( $left + $right ) / 2 );
        if ( $skill_sorted [ $mid ] < ($skill [ $j - 1 ]) ) { ($left = $mid + 1) and next AB }
        else { ($right = $mid) and next AB }
    }
    $mid = int ( ( $left + $right ) / 2 );
    if ( exists $quarrel { $j } ) { print max ( 0, $mid - $quarrel { $j } ) }
    else { print $mid }
    print qq/ /;
}
print NL;

#!/usr/bin/perl

use warnings;
use strict;

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

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

	my @sA = sort { $a <=> $b } @A;
	my @B;

	my $prev = $sA[ 0 ];
	my %h;

	for my $i ( 0 .. @sA - 1 ){
		next if $sA[ $i ] == $prev;
		$h{ $sA[ $i ] } = $i;
		$prev = $sA[ $i ];
		}

	$debug and print "$_ => $h{ $_ }" for sort keys %h;

	for( 1 .. $k ){
		my( $u, $v ) = split ' ', <>;
		$debug and print "$u|$v||$A[ $u - 1 ]|$A[ $v - 1 ]";
		$B[ $A[ $u - 1 ] > $A[ $v - 1 ] ? $u - 1 : $v - 1 ] --;
		}

	$debug and print "$_ => $h{ $_ }" for sort keys %h;

	print join ' ', map { ( $h{ $_ } || 0 ) + shift @B } @A;

	$debug and print '-' x 15;
	}


#
# Hello World Program in Perl
#
use strict;

my $count = <>;
my (%hf, %hs);
my %pair;
my %all;
for(1..$count)
{
    my ($a, $b) = split /\s/, <>;

    $hf{$a}++;
    $hs{$b}++;

    if($a == $b)
    {
        $pair{$a}++;
    }
    else
    {
        $all{"[$a][$b]"}++;
    }
}
my $ans = 0;

my @toDel;
for(keys(%hf))
{
    $ans += f($hf{$_});

}

for(keys(%hs))
{
    $ans += f($hs{$_});

}

for(keys(%pair))
{
    $ans -=f($pair{$_});
}

for(keys(%all))
{
    $ans-=f($all{$_});
}

print $ans;

sub f($)
{
    my $ans = 0;
    for(1..$_[0]-1)
    {
        $ans += $_;
    }
    return $ans;
}


#!/usr/bin/env perl

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

# essential
my @tokens = ();

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

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

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

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

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

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

# solve

my $n = read_token;
my $h = read_token;

my @talls = split q{ }, read_line;

my $answer = $n;

for (@talls) {
    $answer++ if $_ > $h;
}

say $answer;

my (undef, $h) = split ' ', <>;
my @a = split ' ', <>;

print scalar(@a + grep { $_ > $h } @a), "\n";

#!/usr/bin/perl
use strict;
my $data = <STDIN>;
my $array =<STDIN>;
my @data_p = split(' ',$data);
my @array_p=split(' ', $array);
my ($n , $h) = @data_p;
my $sum = 0;
foreach my $item (@array_p)
{
    if ( $item > $h )
    {
        $sum = $sum + 2 ;
    }
    else
    {
        $sum = $sum + 1 ;
    }
}
print $sum;

(undef, $h) = split ' ', <>;
$sum += 1 + ($_ > $h) for split ' ', <>;
print $sum

(undef, $h) = split ' ', <>;
$sum += 1 + ($_ * 2 > $h) for split ' ', <>;
print $sum


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my %h;

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

	if( $h{ 1 } and $h{ 0 } || $h{ 2 } ){
		print "NO";
		}
	else{
		print "YES";
		}
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	if( ( grep $_ == 1, @_ ) and ( grep $_ % 2 == 0, @_ ) ){
		print "NO";
		}
	else{
		print "YES";
		}

	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	if( ( grep $_ == 0, @_ ) and ( grep $_ == 1, @_ ) ){
		print "NO";
		}
	else{
		print "YES";
		}

	}


($n, $k) = split ' ', <>;
($L, @_) = reverse map length, <>;

$short = grep { $L > $_ } @_;

print join ' ', map {
	$_ + 5 * int ~- $_ / $k
	} $short + 1, $short + grep { $L == $_ } @_

$\ = $/;

while(<>){
	($n, $k) = split;
	@_ = ();
	for (1 .. $n){
		push @_, ~~<>;
		}
	chomp(@_);
	chomp( $psw = <> );
	$len_psw = length $psw;
	$short = grep { $len_psw >  length } @_;
	$equal = grep { $len_psw == length } @_;

	print join ' ', map {
		$_ + 5 * int( ($_-1) / $k)
		} $short + 1, $short + $equal;
	}

$\ = $/;

while(<>){
	($n, $k) = split;
	@_ = ();
	for (1 .. $n){
		push @_, ~~<>;
		}
	chomp(@_);
	chomp( $psw = <> );
	$len_psw = length $psw;
	$short = grep { $len_psw >  length } @_;
	$equal = grep { $len_psw == length } @_;

	print join ' ', map {
		$_ + 5 * int $_ / $k
		} $short + 1, $short + $equal;
	}


my $T=<>;
chomp($T);
my %DATA;
while($T--){
my ($a,$b)=split(/ /,<>);
chomp($a,$b);
$DATA{$b}=$a;
}
my @S=map { $DATA{$_} } sort { $a <=> $b } keys %DATA;
for(0..@S-2){
if($S[$_] > $S[$_+1]){
print  "Happy Alex \n";
exit(0);
}
}
print  "Poor Alex\n";

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

my $n = <>;
chomp $n;

my @laps;

for (1..$n) {
    my $l = <>;
    chomp $l;
    $l =~ /^(\d+) (\d+)$/;

    push(@laps, [int($1), int($2)]);
}

@laps = sort {
if ($a->[0] < $b->[0]) {
    return -1;
} elsif ($a->[0] == $b->[0]) {
    if ($a->[1] < $b->[1]) {
        return -1;
    } elsif ($a->[1] == $b->[1]) {
        return 0;
    } else {
        return 1;
    }
} else {
    return 1;
}
} @laps;

for (my $i = 1; $i <= $#laps; $i++) {
    if ($laps[$i-1]->[1] > $laps[$i]->[1]) {
            print "Happy Alex\n";
            exit 0;
    }
}

print "Poor Alex\n";

my $T=<>;
chomp($T);
my %DATA;
while($T--){
my ($a,$b)=split(/ /,<>);
chomp($a,$b);
$DATA{$b}=$a;
}
my @S=map { $DATA{$_} } sort { $a <=> $b } keys %DATA;
for(0..@S-2){
if($S[$_] > $S[$_+1]){
print  "Happy Alex \n";
last;
}
}
print  "Poor Alex\n";

my $T=<>;
chomp($T);
my %DATA;
while($T--){
my ($a,$b)=split(/ /,<>);
chomp($a,$b);
$DATA{$b}=$a;
}
my @S=map { $DATA{$_} } sort { $a <=> $b } keys %DATA;
for(0..@S-2){
if($S[$_] > $S[$_+1]){
print  "Happy Alex \n";
}
}
print  "Poor Alex\n";

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

my $n = <>;
chomp $n;

my @laps;

for (1..$n) {
    my $l = <>;
    chomp $l;
    $l =~ /^(\d+) (\d+)$/;

    push(@laps, [$1, $2]);
}

@laps = sort { $a->[0] cmp $b->[0] } @laps;

for (my $i = 0; $i <= $#laps; $i++) {
    for (my $j = 0; $j < $i; $j++) {
        if ($laps[$i]->[1] < $laps[$j]->[1]) {
            print "Happy Alex\n";
            exit 0;
        }
    }
}

print "Poor Alex\n";

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

my $n = <>;
chomp $n;

my @laps;

for (1..$n) {
    my $l = <>;
    chomp $l;
    $l =~ /^(\d+) (\d+)$/;

    push(@laps, [$1, $2]);
}

@laps = sort { $a->[0] cmp $b->[0] } @laps;

my $max = $laps[$#laps]->[1];
my $cost = $laps[$#laps]->[0];

for (my $i = $#laps-1; $i >= 0; $i--) {
    if ($laps[$i]->[0] < $cost && $laps[$i]->[1] > $max) {
            print "Happy Alex\n";
            exit 0;
    }
}

print "Poor Alex\n";

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

my $n = <>;
chomp $n;

my (@a, @b);

for (1..$n) {
    my $l = <>;
    chomp $l;
    $l =~ /^(\d+) (\d+)$/;

    push(@a, $1);
    push(@b, $2);
}

@a = sort @a;
@b = sort @b;

for (my $i = 0; $i <= $#a; $i++) {
    if ($a[$i] != $b[$i]) {
        print "Poor Alex\n";
        exit 0;
    }
}

print "Happy Alex\n";

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

my $n = <>;
chomp $n;

my @laps;

for (1..$n) {
    my $l = <>;
    chomp $l;
    $l =~ /^(\d+) (\d+)$/;

    push(@laps, [int($1), int($2)]);
}

@laps = sort {
if ($a->[0] <= $b->[0]) {
    if ($a->[1] < $b->[1]) {
        return 1;
    } elsif ($a->[1] == $b->[1]) {
        return 0;
    } else {
        return -1;
    }
} else {
    return 1;
}
} @laps;

for (my $i = 1; $i <= $#laps; $i++) {
    if ($laps[$i-1]->[1] > $laps[$i]->[1]) {
            print "Happy Alex\n";
            exit 0;
    }
}

print "Poor Alex\n";

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

my $n = <>;
chomp $n;

my @laps;

for (1..$n) {
    my $l = <>;
    chomp $l;
    $l =~ /^(\d+) (\d+)$/;

    push(@laps, [$1, $2]);
}

@laps = sort { $a->[0] cmp $b->[0] } @laps;

for (my $i = 0; $i <= $#laps; $i++) {
    for (my $j = $i; $j <= $#laps; $j++) {
        if ($laps[$i]->[1] > $laps[$j]->[1]) {
            print "Happy Alex\n";
            exit 0;
        }
    }
}

print "Poor Alex\n";

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

my $n = <>;
chomp $n;

my @laps;

for (1..$n) {
    my $l = <>;
    chomp $l;
    $l =~ /^(\d+) (\d+)$/;

    push(@laps, [int($1), int($2)]);
}

@laps = sort {
if ($a->[0] <= $b->[0]) {
    if ($a->[1] < $b->[1]) {
        return 1;
    } elsif ($a->[1] == $b->[1]) {
        return 0;
    } else {
        return -1;
    }
} else {
    return 1;
}
} @laps;

my $max = $laps[$#laps]->[1];
my $cost = $laps[$#laps]->[0];

for (my $i = $#laps-1; $i >= 0; $i--) {
    if ($laps[$i]->[0] < $cost && $laps[$i]->[1] > $max) {
            print "Happy Alex\n";
            exit 0;
    }
}

use Data::Dumper;
print Dumper(\@laps);

print "Poor Alex\n";

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

my $n = <>;
chomp $n;

my @laps;

for (1..$n) {
    my $l = <>;
    chomp $l;
    $l =~ /^(\d+) (\d+)$/;

    push(@laps, [int($1), int($2)]);
}

@laps = sort {
if ($a->[0] <= $b->[0]) {
    if ($a->[1] < $b->[1]) {
        return 1;
    } elsif ($a->[1] == $b->[1]) {
        return 0;
    } else {
        return -1;
    }
} else {
    return 1;
}
} @laps;

my $max = $laps[$#laps]->[1];
my $cost = $laps[$#laps]->[0];

for (my $i = $#laps-1; $i >= 0; $i--) {
    if ($laps[$i]->[0] < $cost && $laps[$i]->[1] > $max) {
            print "Happy Alex\n";
            exit 0;
    }
}

print "Poor Alex\n";


use strict;
use warnings;
my %hash     = ();
my $distinct = 0;
chomp(my ( $n, $k ) = split( " ", <STDIN> ));
chomp(my @array = split( " ", <STDIN> ));
for my $elt (@array) {
    if ( not exists $hash{$elt} ) {
        $distinct++;
        $hash{$elt}++;
    }
}

if ( $distinct < $k ) {
    print "-1 -1";
    exit;
}

my $first = $array[0];

my %hash2     = ($first => 1);

my $distinct2 = 1;
my $start     = 0;
my $end       = 0;
for ( my $i = 1 ; $i < @array ; $i++ ) {
    if ( $distinct2 == $k ) {
        last;
    }
    $end = $i;
    if ( not exists $hash2{ $array[$i] } ) {
        $hash2{ $array[$i] }++;
        $distinct2++;
    }
    #print "d = $distinct2, k = $k, start = $start, end = $end\n";

    if ( $array[$i] == $array[$start] ) {
        $start++;
    }
}
#print "$start $end\n";
my $found = 1;
while ($found) {
    my $count = 0;
    for ( my $i = $start ; $i <= $end ; $i++ ) {
        if ( $i != $start && $array[$i] == $array[$start] ) {
            $count++;
            $start++;
        }
        if ($i != $end && $array[$i] == $array[$end] ) {
            $count++;
            $end--;
        }
    }
    if ( $count == 0 ) { $found = 0; }
}

$start++;
$end++;
print "$start $end";

use strict;
use warnings;
my %hash     = ();
my $distinct = 0;
chomp(my ( $n, $k ) = split( " ", <STDIN> ));
chomp(my @array = split( " ", <STDIN> ));
for my $elt (@array) {
    if ( not exists $hash{$elt} ) {
        $distinct++;
        $hash{$elt}++;
    }
}

if ( $distinct < $k ) {
    print "-1 -1";
    exit;
}

my $first = $array[0];

my %hash2     = ($first => 1);

my $distinct2 = 1;
my $start     = 0;
my $end       = 0;
for ( my $i = 1 ; $i < @array ; $i++ ) {
    $end = $i;
    if ( not exists $hash2{ $array[$i] } ) {
        $hash2{ $array[$i] }++;
        $distinct2++;
    }
    print "d = $distinct2, k = $k, start = $start, end = $end\n";
    if ( $distinct2 == $k ) {
        last;
    }
    if ( $array[$i] == $array[$start] ) {
        $start++;
    }
}
print "$start $end\n";
my $found = 1;
while ($found) {
    my $count = 0;
    for ( my $i = $start ; $i <= $end ; $i++ ) {
        if ( $i != $start && $array[$i] == $array[$start] ) {
            $count++;
            $start++;
        }
        if ($i != $end && $array[$i] == $array[$end] ) {
            $count++;
            $end--;
        }
    }
    if ( $count == 0 ) { $found = 0; }
}

$start++;
$end++;
print "$start $end";

use strict;
use warnings;
my %hash     = ();
my $distinct = 0;
chomp(my ( $n, $k ) = split( " ", <STDIN> ));
chomp(my @array = split( " ", <STDIN> ));
for my $elt (@array) {
    if ( not exists $hash{$elt} ) {
        $distinct++;
        $hash{$elt}++;
    }
}

if ( $distinct < $k ) {
    print "-1 -1";
    exit;
}

my $first = $array[0];

my %hash2     = ($first => 1);

my $distinct2 = 1;
my $start     = 0;
my $end       = 0;
for ( my $i = 1 ; $i < @array ; $i++ ) {
    $end = $i;
    if ( not exists $hash2{ $array[$i] } ) {
        $hash2{ $array[$i] }++;
        $distinct2++;
    }
    #print "d = $distinct2, k = $k, start = $start, end = $end\n";
    if ( $distinct2 == $k ) {
        last;
    }
    if ( $array[$i] == $array[$start] ) {
        $start++;
    }
}
#print "$start $end\n";
my $found = 1;
while ($found) {
    my $count = 0;
    for ( my $i = $start+1 ; $i <= $end ; $i++ ) {
        if ( $array[$i] == $array[$start] ) {
            $count++;
            $start++;
        }
    }
    if ( $count == 0 ) { $found = 0; }
}

$start++;
$end++;
print "$start $end";

use strict;
use warnings;
my %hash     = ();
my $distinct = 0;
chomp(my ( $n, $k ) = split( " ", <STDIN> ));
chomp(my @array = split( " ", <STDIN> ));
for my $elt (@array) {
    if ( not exists $hash{$elt} ) {
        $distinct++;
        $hash{$elt}++;
    }
}

if ( $distinct < $k ) {
    print "-1 -1";
    exit;
}

my $first = $array[0];

my %hash2     = ($first => 1);

my $distinct2 = 1;
my $start     = 0;
my $end       = 0;
for ( my $i = 1 ; $i < @array ; $i++ ) {
    $end = $i;
    if ( not exists $hash2{ $array[$i] } ) {
        $hash2{ $array[$i] }++;
        $distinct2++;
    }
    #print "d = $distinct2, k = $k, start = $start, end = $end\n";
    if ( $distinct2 == $k ) {
        last;
    }
    if ( $array[$i] == $array[$start] ) {
        $start++;
    }
}
#print "$start $end\n";
my $found = 1;
while ($found) {
    my $count = 0;
    for ( my $i = $start ; $i <= $end ; $i++ ) {
        if ( $i != $start && $array[$i] == $array[$start] ) {
            $count++;
            $start++;
        }
        if ($i != $end && $array[$i] == $array[$end] ) {
            $count++;
            $end--;
        }
    }
    if ( $count == 0 ) { $found = 0; }
}

$start++;
$end++;
print "$start $end";

use strict;
use warnings;
my %hash     = ();
my $distinct = 0;
chomp(my ( $n, $k ) = split( " ", <STDIN> ));
chomp(my @array = split( " ", <STDIN> ));
for my $elt (@array) {
    if ( not exists $hash{$elt} ) {
        $distinct++;
        $hash{$elt}++;
    }
}

if ( $distinct < $k ) {
    print "-1 -1";
    exit;
}

my $first = $array[0];

my %hash2     = ($first => 1);

my $distinct2 = 1;
my $start     = 0;
my $end       = 0;
for ( my $i = 1 ; $i < @array ; $i++ ) {
    $end = $i;
    if ( not exists $hash2{ $array[$i] } ) {
        $hash2{ $array[$i] }++;
        $distinct2++;
    }
    #print "d = $distinct2, k = $k, start = $start, end = $end\n";
    if ( $distinct2 == $k ) {
        last;
    }
    if ( $array[$i] == $array[$start] ) {
        $start++;
    }
}
#print "$start $end\n";
my $found = 1;
while ($found) {
    my $count = 0;
    for ( my $i = $start+1 ; $i < $end ; $i++ ) {
        if ( $array[$i] == $array[$start] ) {
            $count++;
            $start++;
        }
        if ( $array[$i] == $array[$end] ) {
            $count++;
            $end--;
        }
    }
    if ( $count == 0 ) { $found = 0; }
}

$start++;
$end++;
print "$start $end";


sub count_disjoint_sets {

    my $ds_ref = $_[0];
    my %count = ();
    for my $i (values %{ $ds_ref }) {
	$count { $i } = 1;
    }
    return (scalar (keys %count));
}

sub make_disjoint_sets {

    my ($e_ref, $l_ref, $ds_ref,
	$v_ref, $person, $id ) = @_;

    # return if we've already visited this person
    if ( exists $v_ref -> { $person } ) {
	return;
    }
    # mark visited
    $v_ref -> { $person } = 1;
    # add to dijoint set
    $ds_ref -> { $person } = $id;

    for my $i ( keys %{ $l_ref -> { $person } } ) {
	for my $j ( keys %{ $e_ref -> { $i } } ) {
	    &make_disjoint_sets ( $e_ref, $l_ref, $ds_ref,
				  $v_ref, $j, $id );
	}}
}

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

my %emp_of_langs;
my %langs_of_emp;
my @lst;
my $language_exists = 0;
my $val;
for my $i (1..$n) {
    $val = 0;
    @lst = ();
    $f = <STDIN>;
    chomp ( $f );
    @lst = split m/ /, $f;
    $val = shift @lst;
    if ( $val > 0 ) {
	$language_exists = 1;
    }
    for my $j (@lst) {
	$langs_of_emp{ $i }{ $j } = 1;
	$emp_of_langs{ $j }{ $i } = 1;
    }
}

my %ds = ();
my %visit = ();

# initialize disjoint set
for my $i (1..$n) {
    $ds { $i } = $i;
}

for my $i (1..$n) {
    &make_disjoint_sets ( \%emp_of_langs, \%langs_of_emp, \%ds,
			  \%visit, $i, $i );
}

my $answer = &count_disjoint_sets ( \%ds );

if ( not $language_exists ) {
    print $answer;
    print "\n";
}
else {
    print ($answer - 1);
    print "\n";
}

sub count_disjoint_sets {

    my $ds_ref = $_[0];
    my %count = ();
    for my $i (values %{ $ds_ref }) {
	$count { $i } = 1;
    }
    return (scalar (keys %count));
}

sub make_disjoint_sets {

    my ($e_ref, $l_ref, $ds_ref,
	$v_ref, $person, $id ) = @_;

    # return if we've already visited this person
    if ( exists $v_ref -> { $person } ) {
	return;
    }
    # mark visited
    $v_ref -> { $person } = 1;
    # add to dijoint set
    $ds_ref -> { $person } = $id;

    for my $i ( keys %{ $l_ref -> { $person } } ) {
	for my $j ( keys %{ $e_ref -> { $i } } ) {
	    &make_disjoint_sets ( $e_ref, $l_ref, $ds_ref,
				  $v_ref, $j, $id );
	}}
}

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

my %emp_of_langs;
my %langs_of_emp;
my @lst;
for my $i (1..$n) {
    @lst = ();
    $f = <STDIN>;
    chomp ( $f );
    @lst = split m/ /, $f;
    shift @lst;

    for my $j (@lst) {
	$langs_of_emp{ $i }{ $j } = 1;
	$emp_of_langs{ $j }{ $i } = 1;
    }
}

my %ds = ();
my %visit = ();

for my $i (1..$n) {
    &make_disjoint_sets ( \%emp_of_langs, \%langs_of_emp, \%ds,
			  \%visit, $i, $i );
}

my $answer = &count_disjoint_sets ( \%ds );

print ($answer - 1);
print "\n";


<>;
my %hash;
my $max  = 0;
for(split / /, <>) {
    $hash{int$_}++;
    $max = $hash{int$_} if ($hash{int$_} > $max);
}
print ($max . " " . scalar keys %hash);

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

chomp($n = <>);
$tb{int($_)}++ foreach (split / /, <>);
@a = keys %tb;
($mx, $ans) = (0, scalar @a);
$mx=$mx>$tb{$_} ? $mx:$tb{$_} foreach (@a);
say "$mx $ans";


($_ > $max and $max = $_), unshift @a, $max for reverse @_ = split ' ', (<>, <>);
shift @a;
print join ' ', map { (sort {$b <=> $a} ( (shift @a) - $_ + 1, 0) )[0] } @_


#!/bin/usr/perl

my $t=<>;
chomp($t);
while ($t--){
	my $line = <>;
	chomp($line);
	@numbers = split(" ",$line);
	my $a = $numbers[0];
	my $b = $numbers[1];
	print($a+$b);
	print("\n");
}


$,=" ";
my $n=<>;
chomp($n);
$n--;
my ($x,$y)=split / /,<>;
chomp($x,$y);
my $amount=$y;
my $cost=$x*$amount;
while($n--)
{
  ($x,$y)=split / /,<>;
  chomp($x,$y);
  if($y<$amount)
  {
    $amount=$y;
  }
  $cost+=$x*$amount;
}
print $cost , "\n";

#!/usr/bin/perl

use 5.012;
use warnings;

my $n = <>;
my $cheapest = 101;
my $cost;
while ($n--) {
	chomp(my $line = <>);
	my ($a, $p) = split / /, $line;
	$cheapest = $p if $p < $cheapest;
	$cost += $a * $cheapest;
}
print $cost;

<>;
$min = ~0;
( $min > (split)[1] and $min = (split)[1] ), $sum += $_ * $min for <>;
print $sum

use 5.016;
use strict;
use warnings;

sub argmin {
  my ($aref) = @_;

  my $argmin = 0;
  for my $i (1..$#$aref) {
    if ($aref->[$i] < $aref->[$argmin]) {
      $argmin = $i;
    }
  }
  $argmin;
}

sub sum_range {
  my ($aref, $l, $r) = @_;

  my $sum = 0;
  for my $i ($l..$r) {
    $sum += $aref->[$i];
  }
  $sum;
}

my @eat;
my @price;

my $n = <>;
for (1..$n) {
  my ($eat, $price) = split ' ', <>;
  push @eat, $eat;
  push @price, $price;
}

my $cost = 0;

while (@eat) {
  my $i = argmin(\@price);
  $cost += $price[$i] * sum_range(\@eat, $i, $#eat);
  splice @price, $i;
  splice @eat, $i;
}

say $cost;

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

<>;
my $m = 111;
my $ans;
for(<>)
{
    my ($a, $p) = split(' ', $_);
    $m = ($p < $m) ? $p : $m;

    $ans += $a * $m;
}

print $ans;


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

my $n = <STDIN>;

my @first = split(' ', <STDIN>);
my @second = split(' ', <STDIN>);

my %set;

shift @first;
shift @second;
foreach my $level ((@first, @second))
{
    unless ($level == 0)
    {
        $set{$level} = 1;
    }
}
my $size = keys %set;
if ($size == $n) {
    print "I become the guy.";
}
else {
    print "Oh, my keyboard!";
}

my $n = <>;
($na, @a) = split " ", <>;
($nb, @b) = (split " ", <>);
push @b, @a;

%k = ();
grep { $k{$_} = $_ } @b;

print scalar keys %k == $n? "I become the guy.\n" : "Oh, my keyboard!\n";

my $n = <>;
my %hash;
my @a = split " ", <>;
my @b = split " ", <>;
shift @a;
shift @b;
$hash{$_} = 0 foreach(1..$n);
$hash{$_} = 1 foreach(@a);
$hash{$_} = 1 foreach(@b);
my $ans = "I become the guy.\n";
foreach(values %hash) {
    $ans = "Oh, my keyboard!\n" if ($_ == 0);
}
print $ans;

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

chomp($n = <>);
my %tb;
@a = split / /, <>;
$tb{int($_)}=1 foreach(@a[1..$#a]);
@a = split / /, <>;
$tb{int($_)}=1 foreach(@a[1..$#a]);
scalar(keys %tb)==$n and say "I become the guy." or say "Oh, my keyboard!";

chomp (my $n = <>);

chomp (my @ps = split / /, <>);
chomp (my @qs = split / /, <>);

shift @ps;
shift @qs;

my %ls;

$ls{$_}++ foreach (@ps, @qs);

if ((scalar keys %ls) == $n) {
  printf "I become the guy.\n";
} else {
  printf "Oh, my keyboard!\n";
}

#!/usr/bin/perl
use strict;
use warnings;
#pass array by reference

my $n = <>;
my @arr = (0) x $n;
my @arr1 = split(' ',<>); shift(@arr1);
my @arr2 = split(' ',<>); shift(@arr2);

foreach(@arr1){
    $arr[$_-1] = 1;
}
foreach(@arr2){
    $arr[$_-1] = 1;
}
my $yes = 1;
foreach(@arr){
    if($_ == 0){
        $yes=0;
        last;
    }
}
if($yes == 1){
    print "I become the guy.\n";
}
else{
    print "Oh, my keyboard!\n";
}

my $n = <>;
my %hash;
my @a = split " ", <>;
push @a, split " ", <>;
$hash{$_} = 0 foreach(1..$n);
$hash{$_} = 1 foreach(@a);
my $ans = "I become the guy.\n";
foreach(values %hash) {
    $ans = "Oh, my keyboard!\n" if ($_ == 0);
}
print $ans;

my $n = <>;

my @ps = split / /, <>;
my @qs = split / /, <>;

shift @ps;
shift @qs;

my %ls;

$ls{$_}++ foreach (@ps, @qs);

if (scalar keys %ls == $n) {
  printf "I become the guy.\n";
} else {
  printf "Oh, my keyboard!\n";
}

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

my $n = <>;
my @arr = (0) x $n;
my @arr1 = split(' ',readline);
my @arr2 = split(' ',readline);

foreach(@arr1){
    $arr[$_-1] = 1;
}
foreach(@arr2){
    $arr[$_-1] = 1;
}
my $yes = 1;
foreach(@arr){
    if($_ == 0){
        $yes=0;
        last;
    }
}
if($yes == 1){
    print "I become the guy.\n";
}
else{
    print "Oh, my keyboard!\n";
}

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

my $n = <STDIN>;

my @first = split(' ', <STDIN>);
my @second = split(' ', <STDIN>);

my %set;

foreach my $level ((@first, @second))
{
    unless ($level != 0)
    {
        $set{$level} = 1;
    }
}
my $size = keys %set;
if ($size == $n) {
    print "I become the guy.";
}
else {
    print "Oh, my keyboard!";
}

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

my $n = <STDIN>;

my @first = split(' ', <STDIN>);
my @second = split(' ', <STDIN>);

my %set;

foreach my $level ((@first, @second))
{
    $set{$level} = 1;
}
my $size = keys %set;
if ($size == $n) {
    print "I become the guy.";
}
else {
    print "Oh, my keyboard!";
}

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

my $n = <STDIN>;

my @first = split(' ', <STDIN>);
my @second = split(' ', <STDIN>);

my %set;

foreach my $level ((@first, @second))
{
    unless ($level == 0)
    {
        $set{$level} = 1;
    }
}
my $size = keys %set;
if ($size == $n) {
    print "I become the guy.";
}
else {
    print "Oh, my keyboard!";
}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my %h;

	map { my( $name, $ip ) = ( split ' ', <> ); $h{ $ip }{ name } = $name } 1 .. $n;

	for( 1 .. $m ){
		my( $comm, $ip ) = split ' ', <>;
		chop $ip;

		print "$comm $ip; #$h{ $ip }{ name }"
		}
	}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $A = grep m/1/, @_;

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

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

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

while( $testcase -- > 0 ){

  my ($n,$k) = map { $_ - 0 } split(/\s+/,<STDIN>);
  my @A = map { $_ - 0 } split(/\s+/,<STDIN>);
  my $c1 = 0; my $c0 = 0;
  for(my $i=0;$i<$n;$i++){
    $c1++ if( $A[$i] == 1 );
    $c0++ if( $A[$i] == 0 );
  }
  if( $c0 == 0 ){
    print "YES\n"; next;
  }
  if( $c1 == 0 ){
    print "NO\n"; next;
  }
  if( $k > $n ){
    print "NO\n"; next;
  }
  print "YES\n";

}

exit(0);

sub max {
  my $r = undef;
  foreach my $e (@_){  $r = $e if !defined($r) or $e > $r;  }
  return $r;
}
sub min {
  my $r = undef;
  foreach my $e (@_){  $r = $e if !defined($r) or $e < $r;  }
  return $r;
}
sub sum {
  my $r = 0;
  foreach my $e (@_){ $r += $e; }
  return $r;
}
sub ruisum {   # my @rui = (0); &ruisum(\@rui,\@array);
  my $r = shift; my $ar = shift;
  $#{$r} = 1+$#{$ar}; $r->[0] = 0; my $rr = 0;
  for(my $i=0;$i<=$#ar;$i++){
    $rr += $ar->[$i];
    $r->[1+$i] = $rr;
  }
}


sub solve {
	my $n = shift;
	my @a = split(" ", shift);
	my $s = 0;
	for my $x (@a) {
		$s += $x;
	}
	my $res = 0;
	for my $x (@a) {
		my $tmp = 2 * $x - $s;
		if ($res < $tmp) {
			$res = $tmp;
		}
	}
	return $res + 1;
};

my $n = <>;
my $input = <>;
print solve($n, $input);