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

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

while(<>){
	($n,$m)=split/ /;
	@distance=(); # empty
	@end=();
	$f=1;
	for $i(1..$n){

		$_=<>;
		/G\**S/ and (($distance[length($&)]++), next);
		$f=0;
		}
	$j=0;
	$_ and $j++ for @distance;
	printf "%d\n", $f? ( $j ) : -1;

	}

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

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

while(<>){
	($n,$m)=split/ /;
	@distance=(); # empty
	@end=();
	$f=1;
	for $i(1..$n){

		$_=<>;
		/G\**S\*/ and ((push @distance, length($&)-2), next);
		/G\**S$/ and ((push @end, length($&)-1), next);
		$f=0;
		}
	printf "%d\n", $f? (0+@end? min(@end) : max(@distance) ) : -1;

	}

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

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

while(<>){
	($n,$m)=split/ /;
	@distance=(); # empty
	@end=();
	$f=1;
	for $i(1..$n){

		chomp($_=<>);
		/G\**S/ ? (push @distance, $d=length($&)-1) : ($f=0);
		/S$/ and push @end, $d;
		}
	printf "%d\n", $f? min(max(@distance),min(@end)): -1;

	}

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

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

while(<>){
	($n,$m)=split/ /;
	@distance=(); # empty
	$f=1;
	for $i(1..$n){

		$_=<>;
		/G\**S/ ? (push @distance, length($&)-1) : ($f=0);

		}
	printf "%d\n", $f? max(@distance)-min(@distance)+1: -1;

	}


#!/usr/bin/perl

use strict;
use warnings;

while (<>) {
  chomp;
  my $n = eval;
  my $res = '';
  my @ds = split //, $n;
  for my $d (@ds) {
    $res .= '+' x ($d + 48) . '.>';
  }
  print "$res\n";
}

#!/usr/bin/perl

use strict;
use warnings;

while (<>) {
  chomp;
  my $n = eval;
  my @res = ();
  if ($n >= 0) {
    @res = ('+' x $n, '.');
  } else {
    @res = ('-' x -$n, '.');
  }
  print @res, "\n";
}

#!/usr/bin/perl

use strict;
use warnings;

while (<>) {
  chomp;
  my $n = eval;
  my @res = ('+' x $n, '.');
  print @res, "\n";
}


#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

while (<>){
	@a=@m=@sm=@smm=();
	$a=$c="";
	$n=0;
	@_=split/ /,<>;
	for (@_){$m[$_]++}
	@sm = sort num_rev @m;
	for $i(@sm){
		$i>0 and push @smm, $i;
		}
#		print "@m\n";
#		print "@sm\n";
#		print "@smm\n";
	for $i(@smm){
		#print " ...\n";
		for $j(1..@m-1){
			#print " $m[$j]==$i\n";
			if ($m[$j]==$i){

				$a.="$j "x$m[$j];
				$m[$j]=0;

				}

			}

		}
	# print $a; n();

	chop $a;

	$aa=@a=split/ /,$a;
	push @a, @a;

	for $i(0..$aa-1){
		$c.=$a[$i]." ".$a[$i+$smm[0]]."\n";
		if ($a[$i]==$a[$i+$smm[0]]){$n++}
		}
	print @_-$n,"\n";
	print "$c\n";
	}

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

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

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

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

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

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

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

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

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

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

use List::Util qw(max min);

my ($n, $m) = split ' ', scalar <>;
my @c = sort {$a cmp $b} split ' ', scalar <>;

$n == @c or die "invalid count";

my %cnt = ();

foreach (@c){
    $cnt{$_}++;
    }

my $mcnt = max(values %cnt);

my @d = @c[( $mcnt..$#c , 0..($mcnt-1) )];

my $res = min($n, 2*($n - $mcnt));

print "$res\n";
for(my $i = 0; $i < $n; $i++){
    print "$c[$i] $d[$i]\n"
    }

1;

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

while (<>){
	@a=@m=@smm=();
	$a=$c="";
	$n=0;
	@_=split/ /,<>;
	for (@_){$m[$_]++}
	@sm = sort num_rev @m;
	for $i(@sm){
		$i>0 and push @smm, $i;
		}

	for $i(@smm){
		for $j(1..@m-1){
			if ($m[$j]==$i){
				$a.="$j "x$m[$j];
				$m[$j]=0;
				}
			}
		}
	chop $a;

	$aa=@a=split/ /,$a;
	push @a, @a;

	for $i(0..$aa-1){
		$c.=$a[$i]." ".$a[$i+$smm[0]]."\n";
		if ($a[$i]==$a[$i+$smm[0]]){$n++}
		}
	print @_-$n,"\n";
	print "$c\n";
	}

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

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

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

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

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

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

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

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

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

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


<>;
while (<>) {
    $f = $_ =~ /(lala\.)$/;
    $r = $_ =~ /(^miao\.)/;
    if ($f == $r) {
        print "OMG>.< I don't know!\n";
    } elsif ($f) { print "Freda's\n"; } elsif ($r) { print "Rainbow's\n"; }
}

#!/usr/bin/perl

while ($eil=<>) {

sub any{print "OMG>.< I don't know!\n"};

while (<>){

    if (/lala\.$/ and /^miao\./){any; next}
    if (/lala\.$/){print "Freda's\n"; next}
    if (/^miao\./){print "Rainbow's\n"; next}
    any;

    }
}

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

my $n = <>;
for my $i (1..$n) {
    my $s = <>;
    chomp($s);
    my $isFreda = 0;
    my $isRainbow = 0;
    if ($s =~ m/^miao\./) {
        $isRainbow = 1;
    }
    if ($s =~ m/lala\.$/) {
        $isFreda = 1;
    }
    if ($isFreda && ! $isRainbow) {
        print "Freda's" . "\n";
    } elsif ($isRainbow && !$isFreda) {
        print "Rainbow's" . "\n";
    } else {
        print "OMG>.< I don't know!" . "\n";
    }
}

chomp($n=<STDIN>);
while($n > 0) {
	chomp($line=<STDIN>);
	if($line =~ /^miao\..*lala\.$/) {
		print "OMG>.< I don't know!\n";
	} elsif ($line =~ /lala\.$/) {
		print "Freda's\n";
	} elsif ($line =~ /^miao\./) {
		print "Rainbow's\n";
	} else {
		print "OMG>.< I don't know!\n";
	}
	$n--;
}

<>;
while (<>) {
    $f = $_ =~ /lala.$/;
    $r = $_ =~ /^miao./;
    if ($f == $r) { print "OMG>.< I don't know!"; }
    if ($f) { print "Freda's"; } elsif ($r) { print "Rainbow's"; }
}

chomp($n=<STDIN>);
while($n > 0) {
	chomp($line=<STDIN>);
	if($line eq 'miao\..*lala\.') {
		print "OMG>.< I don't know!\n";
	} elsif ($line =~ /lala\.$/) {
		print "Freda's\n";
	} elsif ($line =~ /^miao\./) {
		print "Rainbow's\n";
	} else {
		print "OMG>.< I don't know!\n";
	}
	$n--;
}

chomp($n=<STDIN>);
while($n > 0) {
	chomp($line=<STDIN>);
	if($line eq 'miao.lala.') {
		print "OMG>.< I don't know!\n";
	} elsif ($line =~ /lala\.$/) {
		print "Freda's\n";
	} elsif ($line =~ /^miao\./) {
		print "Rainbow's\n";
	} else {
		print "OMG>.< I don't know!\n";
	}
	$n--;
}

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

my $n = <>;
for my $i (1..$n) {
    my $s = <>;
    chomp($s);
    my $isFreda = 0;
    my $isRainbow = 0;
    if ($s =~ m/^miao\./) {
        $isRainbow = 1;
    }
    if ($s =~ m/lala\.$/) {
        $isFreda = 1;
    }
    print $isFreda . ' ' . $isRainbow . '\n';
    if ($isFreda && ! $isRainbow) {
        print "Freda's" . "\n";
    } elsif ($isRainbow && !$isFreda) {
        print "Rainbow's" . "\n";
    } else {
        print "OMG>.< I don't know!" . "\n";
    }
}

#!/usr/bin/perl

while ($eil=<>) {

while (<>){

    if (/lala\.$/ and !/miao\./){print "Freda's\n"; next}
    if (/miao\.$/){print "Rainbow's\n"; next}
    print "OMG>.< I don't know!\n"

    }
}

#!/usr/bin/perl

while ($eil=<>) {

while (<>){

    if (/lala\.$/ and !/miao\./){print "Freda's\n"; next}
    if (/miao\.$/ and !/lala\./){print "Rainbow's\n"; next}
    print "OMG>.< I don't know!\n"

    }
}

#!/usr/bin/perl

while ($eil=<>) {

sub any{print "OMG>.< I don't know!\n"};

while (<>){

    if (/lala\.$/ and /^miao\./){any; next}
    if (/miao\.$/){print "Rainbow's\n"; next}
    if (/^miao\./){print "Freda's\n"; next}
    any;

    }
}


# get input
my $a;
my $b;
$a = <STDIN>;
chomp ( $b = <STDIN> );
my @arr = split m/ /, $b;

# variable counts extrema
my $extrema = 0;

for ( my $i = 1; $i < (@arr - 1); $i += 1 ) {

    # if is local min or local max, increment extrema
    if ( (@arr[ $i ] < @arr[ $i-1 ] && @arr[ $i ] < @arr[ $i+1 ]) ||
	 (@arr[ $i ] > @arr[ $i-1 ] && @arr[ $i ] > @arr[ $i+1 ]) ) {
	$extrema += 1; }}

# print answer
print "$extrema\n";

# get input
my $a;
my $b;
$a = <STDIN>;
chomp ( $b = <STDIN> );
my @arr = split m/ /, $b;

# variable counts extrema
my $extrema = 0;

for ( my $i = 1; $i < (@arr - 1); $i += 1 ) {

    # if is local min or local max, increment extrema
    if ( ($arr[ $i ] < $arr[ $i-1 ] && $arr[ $i ] < $arr[ $i+1 ]) ||
	 ($arr[ $i ] > $arr[ $i-1 ] && $arr[ $i ] > $arr[ $i+1 ]) ) {
	$extrema += 1; }}

# print answer
print "$extrema\n";


#!/usr/bin/env perl

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

use Carp;

# essential
my @tokens = ();

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

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

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

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

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

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

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

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

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

    $$ref = !$$ref;
}

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

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

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

    my $sum = 0;

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

    return $sum;
}

# solution

my $n = read_token;

my @arr = split q{ }, read_line;

my $pre_number = shift @arr;
my $len = 1;
my $answer = 0;

for (@arr) {
    if ($_ <= $pre_number) {
        $answer = max($answer, $len);
        $len = 1;
        $pre_number = $_;
        next;
    }
    $len++;
    $pre_number = $_;
}

$answer = max($answer, $len);

say $answer;

#!/usr/bin/env perl

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

use Carp;

# essential
my @tokens = ();

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

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

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

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

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

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

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

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

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

    $$ref = !$$ref;
}

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

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

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

    my $sum = 0;

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

    return $sum;
}

# solution

my $n = read_token;

my $pre_number = read_token;
my $len = 1;
my $answer = 0;

for (1..$n-1) {
    my $num = read_token;
    if ($num <= $pre_number) {
        $answer = max($answer, $len);
        $len = 1;
        $pre_number = $num;
        next;
    }
    $len++;
    $pre_number = $num;

}

$answer = max($answer, $len);

say $answer;


#!/usr/bin/env perl

use v5.012;
use warnings;

my $cnt = <STDIN>;

my $x = 0;
while ($cnt--) {
	chomp(my $stmt = <STDIN>);
	$x++ if $stmt =~ /\+\+/;
	$x-- if $stmt =~ /\-\-/;
}
print $x;

use strict;
use warnings;

my $n = <>;
my $ans = 0;

while($n-- > 0){
    my $var = <>;
    if($var =~ /\+\+/){
        $ans++;
    }elsif($var =~ /--/){
        $ans--;
    }
}
print "$ans\n";

my $n = <>;
my $ans = 0;
my $str;
for (1..$n) {
    $str = <>;
    chomp $str;
    $ans++ if ($str eq "++X" || $str eq "X++");
    $ans-- if ($str eq "--X" || $str eq "X--");
}
print $ans . "\n";

#!/usr/bin/env perl

use 5.010;

@lines = <>;
$accum = 0;

foreach $line (@lines) {
	if ($line =~ /\+\+/) {
		$accum++;
	}
	if ($line =~ /--/) {
		$accum--;
	}
}

say $accum;

#!perl

use strict;
use warnings;

chomp( my $n =<STDIN> );

my $acc_num = 0 ;
foreach ( 0 .. ($n-1) ){
    my $readnum = <STDIN> ;

    if ( $readnum =~ m/\+\+/ ){
        $acc_num++;
    }else{
        $acc_num--;
    }
}
print "$acc_num\n" ;

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

$x = 0;
chomp($n = <>);
while ($n-- > 0) {
	chomp($line = <>);
	if ((substr $line, 1, 1) eq "+") {
		$x++
	} else {
		$x--;
	}
}
print $x;

chomp ($n = <STDIN>);
$x = 0;
while ($n--) {
	chomp ($str = <STDIN>);
	if ($str =~ /--/) { $x-- } else { $x++}
}
printf "$x\n";

use strict;
use warnings;

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

die ('n should be between 1 and 150') unless $n >= 1 && $n <= 150;

my $x = 0;
for (my $i = 0; $i < $n; $i++) {
    my $in = <>;
    chomp($in);
    if ($in =~ m/\+\+/) {
        $x++;
    } elsif ($in =~ m/\-\-/) {
        $x--;
    } else {
        die ('invalid input');
    }
}

print $x;

use strict;
use warnings;

my $n = <>;
my $x = 0;
for (1..$n) {
    my @term = split '', <>;
    if ($term[1] eq '+') {
        $x++;
    } else {
        $x--;
    }
}

print "$x\n";

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

chomp(my $n = <STDIN>);
my $x = 0;
for (my $i = 0; $i < $n; $i++) {
    chomp(my $cmd = <STDIN>);
    if (index($cmd, "++") != -1) {
        $x += 1;
    } elsif (index($cmd, "--") != -1) {
        $x -= 1;
    }
}
print $x;

use strict;
use warnings;
my $N=<STDIN>;
my $X=0;
for(my $i=0;$i<$N;$i++){
   my $s=<STDIN>;
   if ($s =~ /[X++]{3}/ ){
      $X+=1;
   }
   else {
      $X-=1;
   }
}
print STDOUT $X;

#!usr/bin/perl
#use warnings;
use 5.012;
use 5.010;
use 5.014;
#use strict;
#use autodie;
my($n,$count,$x,$line);
chomp($n=<STDIN>);
$count=0;
while($count ne $n)
{
    $count++;
    chomp($line=<STDIN>);
    if($line=~m/\+\+/)
    {$x++;}
    else
    {$x--;}
}
say "$x";

#!/usr/bin/perl
use strict;

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

my $x = 0;

foreach (1..$n) {
	$_ = <STDIN>;
	chomp;
	if ($_ eq "X++" or $_ eq "++X") { $x++; }
	else { $x--; }
}

print $x;

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

my $x = 0; <STDIN>;
/-/ ? --$x : ++$x while <STDIN>;
print $x . "\n"

$n = <STDIN>;
@a = undef;
$result = 0;
foreach (0..$n - 1) {
	chomp ($a[$_] = <STDIN>);
	#unshift (@a, <STDIN>)
}
foreach $a (@a) {
	if (index ($a, '+') >= 0) {
		$result += 1;
	} else {
		$result -= 1;
	}
}
print ($result);

my $len = <STDIN>;
my $ans = 0;

for (1 .. $len) {
	my $middle = substr <STDIN>, 1, 1;

	$ans += $middle eq "+"? 1 : -1;
}

print $ans."\n";

my $len = <STDIN>;
my $ans = 0;

for my $val (1 .. $len) {
	my $comm = <STDIN>;
	my $middle = substr $comm, 1, 1;

	$ans = $middle eq "+"? ($ans + 1) : ($ans - 1);
}

print $ans."\n";

use strict;
use warnings;
my $N=<STDIN>;
my $X=0;
for(my $i=0;$i<$N;$i++){
   my $s=<STDIN>;
   if ($s == "X++" || $s == "++X"){
      $X+=1;
   }
   else {
      $X-=1;
   }
}
print STDOUT; $X;

use strict;
use warnings;
my $N=<STDIN>;
my $X=0;
for(my $i=0;$i<$N;$i++){
   my $s=<STDIN>;
   if ($s == "X++"){
      $X+=1;
   }
   else {
      $X-=1;
   }
}
print STDOUT; $X;

use strict;
use warnings;
my $N=<STDIN>;
my $X=0;
for(my $i=0;$i<$N;$i++){
   my $s=<STDIN>;
   if ($s == "X++" || $s == "++X"){
      $X+=1;
   }
   else {
      $X-=1;
   }
}
print STDOUT $X;

#!usr/bin/perl
#use warnings;
use 5.012;
use 5.010;
use 5.014;
#use strict;
#use autodie;
my($n,$count,$x,$line);
chomp($n=<STDIN>);
$count=0;
while($count lt $n)
{
    $count++;
    chomp($line=<STDIN>);
    if($line=~m/\+\+/)
    {$x+=1;}
    else
    {$x-=1;}
}
say "$x";


#!/usr/bin/perl

my $sum = <>;
my @like_hist = split " ", <>;
@like_hist = map { $like_hist[$_] } 0..$sum-1;

my $counts = {};
my $max = {id => $like_hist[0], count => 1 };

my $k = 0;
for (0..$sum-1) {
	my $id = $like_hist[$_];
	my $count = ++$counts->{$id};
	$max = {id => $id, count => $count } if ($count > $max->{count});
}

print $max->{id};


use strict;
use warnings;

my $pi = 3.1415926535897;

sub solve {
	my ($d, $h, $v, $e) = split(" ", shift);
	$e = $e * $pi * ($d ** 2) / 4;
	if ($v <= $e) {
		return "NO";
	}
	return "YES\n" . ($h * $pi * ($d ** 2) / 4) / ($v - $e);
};

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

use strict;
use warnings;

my $pi = 3.1415926535897;

sub solve {
	my ($d, $h, $v, $e) = split(" ", shift);
	$e = $e * $pi * ($d ** 2) / 4;
	if ($v <= $e) {
		return "NO";
	}
	return ($h * $pi * ($d ** 2) / 4) / ($v - $e);
};

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


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

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

	my( $v, $h ) = split;

	my @v = sort { $a <=> $b } map ~~<>, 1 .. $v;
	chomp @v;

	push @v, 1e9 + 0;

	no warnings;
	my @h = sort { $a <=> $b } map { ( split )[ 1 ] } grep $_ == 1, map ~~<>, 1 .. $h;
	use warnings;

	$debug and print " h: [@h]";
	$debug and print " v: [@v]";

	my $c_h = @h;

	my @ans;
	my $i = 0;

	for my $v ( @v ){

		my $cnt = 0;

		while( @h ){
			my $h = shift @h;
			if( $v <= $h ){
				unshift @h, $h;
				last;
				}
			$cnt ++;
			}

		push @ans, $c_h - $cnt + $i;

		$c_h -= $cnt;

		$i ++;
		}

	$debug and print " ans: [@ans]";

	print 0 + ( sort { $a <=> $b } @ans )[ 0 ];
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

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

	my( $v, $h ) = split;

	my @v = sort { $a <=> $b } map ~~<>, 1 .. $v;
	chomp @v;

	push @v, 1e9 + 0;

	no warnings;
	my @h = sort { $a <=> $b } map { ( split )[ 1 ] } grep $_ == 1, map ~~<>, 1 .. $h;
	use warnings;

	$debug and print " h: [@h]";
	$debug and print " v: [@v]";

	my $c_h = @h;

	my @ans;
	my $i = 0;

	for my $v ( @v ){

		my $cnt = 0;

		while( @h ){
			my $h = shift @h;
			if( $v <= $h ){
				unshift @h, $h;
				last;
				}
			$cnt ++;
			}

		push @ans, $c_h - $cnt + $i;

		$i ++;
		}

	$debug and print " ans: [@ans]";

	print 0 + ( sort { $a <=> $b } @ans )[ 0 ];
	}


sub max {
	my $a = shift;
	my $b = (@_ == 1? shift: max(@_));
	$a > $b? $a: $b;
}

$_ = <>; chomp; @char = split //;
for $char (@char) {
	if ($char eq "a") {
			$aba = max($aba, $a, $ab) + 1;
			$a += 1;
	} else {
		$ab = max($a, $ab) + 1;
	}
}
print max($a, $ab, $aba);

#!/usr/bin/perl

use warnings;
use strict;

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

while(<>){
	chomp;
	$debug and print "[$_]";

	my $A = () = /a/g;

	my $from_L = 0;
	my $from_R = 0;
	my $max_L = 0;
	my $max_R = 0;

	while( /./g ){
		$from_L += 1 - 2 * ( $& eq 'a' );
		$from_L < 0 and $from_L = 0;
		$max_L < $from_L   and $max_L = $from_L;
		}

	my $rev = reverse $_;
	while( $rev =~ /./g ){
		$from_R += 1 - 2 * ( $& eq 'a' );
		$from_R < 0 and $from_R = 0;
		$max_R < $from_R and $max_R = $from_R;
		}

	$debug and print "max_L: $max_L";
	$debug and print "max_R: $max_R";

	print $A + ( $max_L > $max_R ? $max_L : $max_R );

	$debug and print '-' x 20;
	}

#!/usr/bin/perl

use warnings;
use strict;

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

while(<>){
	my $max_b = 0;

	/(b*)(??{ $max_b < length $1 and $max_b = length $1; 'X' })/;

	my $A = () = /a/g;

	print $max_b + $A;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	my $max = -~0;

	/(a*b*)(?=(a*)(??{ 0 and print "$1.$2"; $max < length( $1.$2 ) and $max = length( $1.$2 ); "X"}))/;

	print $max;
	}

#!/usr/bin/perl

use warnings;
use strict;

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

while(<>){
	chomp;

	my $max_b = length( ( grep length, sort split /a+/ )[ 0 ] );

	my $A = () = /a/g;

	print $max_b + $A;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	my $max = -~0;

	/(a*)(?=(b*a*)(??{ 0 and print "$1.$2"; $max < length( $1.$2 ) and $max = length( $1.$2 ); "X"}))/;

	print $max;
	}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	if( $n <= $k ){
		print 0 + ( int $k / $n ) + !!( $k % $n );
		}
	elsif( $n % $k == 0 ){
		print 1;
		}
	else{
		print 2;
		}
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	my( $n, $k ) = sort { $b <=> $a } split;

	print 0 + ( int $n / $k ) + !!( $n % $k );
	}


#!/usr/bin/env perl

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

my $line = <>;
chomp $line;
my ($N, $K) = split(/ +/, $line);

$line = <>;
chomp $line;
my @A = split(/ +/, $line);

my @D;
for (my $i = 0; $i < $N; ++$i) {
   push(@D, []);
}

my ($level, $col) = (0, 1);
for (my $t = 1; $col <= $K; ++$t) {
   my $new_col = 0;
   my $none_left = 1;
   for (my $i = 0; $i < $N; ++$i) {
      if ($A[$i] > 0) {
         $A[$i]--;
         push( @{$D[$i]}, $col);
         $none_left = 0 if ($A[$i] > 0);
      }
      else {
         $new_col = 1;
      #  printf "t = %d  i = %d\n", $t, $i;
      }
   }
   last if $none_left;
   $col++ if $new_col;
}

#print $col, "\n";
if ($col > $K) {
   print "NO\n"
}
else {
   print "YES\n";
   for (my $i = 0; $i < $N; ++$i) {
      for (my $j = 0; $j < @{$D[$i]}; ++$j) {
         print ' ' if $j > 0;
         print $D[$i][$j];
      }
      print "\n"
   }
}

#!/usr/bin/env perl

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

my $line = <>;
chomp $line;
my ($N, $K) = split(/ +/, $line);

$line = <>;
chomp $line;
my @A = split(/ +/, $line);

my @F = (1) x $N;
my @D;
for (my $i = 0; $i < $N; ++$i) {
   push(@D, []);
}

my ($level, $col) = (0, 1);
for (my $t = 1; $col <= $K; ++$t) {
   my $new_col = 0;
   my $none_left = 1;
   for (my $i = 0; $i < $N; ++$i) {
      if ($A[$i] > 0) {
         $A[$i]--;
         push( @{$D[$i]}, $col);
         $none_left = 0;
      }
      else {
         if ($F[$i]) {
            $F[$i] = 0;
            $new_col = 1;
         #  printf "t = %d  i = %d\n", $t, $i;
         }
      }
   }
   last if $none_left;
   $col++ if $new_col;
}

#print $col, "\n";
if ($col > $K) {
   print "NO\n"
}
else {
   print "YES\n";
   for (my $i = 0; $i < $N; ++$i) {
      for (my $j = 0; $j < @{$D[$i]}; ++$j) {
         print ' ' if $j > 0;
         print $D[$i][$j];
      }
      print "\n"
   }
}

#!/usr/bin/env perl

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

my $line = <>;
chomp $line;
my ($N, $K) = split(/ +/, $line);

$line = <>;
chomp $line;
my @A = split(/ +/, $line);

my @F = (1) x $N;
my @D;
for (my $i = 0; $i < $N; ++$i) {
   push(@D, []);
}

my ($level, $col) = (0, 1);
for (my $t = 1; $col <= $K; ++$t) {
   my $new_col = 0;
   my $none_left = 1;
   for (my $i = 0; $i < $N; ++$i) {
      if ($A[$i] > 0) {
         $A[$i]--;
         push( @{$D[$i]}, $col);
         $none_left = 0 if $A[$i] > 0;
      }
      else {
         if ($F[$i]) {
            $F[$i] = 0;
            $new_col = 1;
         #  printf "t = %d  i = %d\n", $t, $i;
         }
      }
   }
   last if $none_left;
   $col++ if $new_col;
}

#print $col, "\n";
if ($col > $K) {
   print "NO\n"
}
else {
   print "YES\n";
   for (my $i = 0; $i < $N; ++$i) {
      for (my $j = 0; $j < @{$D[$i]}; ++$j) {
         print ' ' if $j > 0;
         print $D[$i][$j];
      }
      print "\n"
   }
}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $sum = 0;

	/
		[02468]
		(?{ $sum += pos })
		(*F)
	/x;

	print $sum;
	}


use strict;
use POSIX;
my ($n,$k)=split(' ',<>);
$_=<>;
chomp;
my @l = split('',$_);
$\ = "\n";
unshift (@l,"lal");
my $adfs = 1 if $k == 1;

if($k >= floor($#l/2)+1)
{
    while($k<=$#l)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;
                print "RIGHT" if  $k++ <$#l;
    }
    $k--;

    goto exit if $adfs;

    while ($k>0)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;

        print "LEFT" if $k-- >1;
    }
}
else
{

    while ($k>0)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;
        print "LEFT" if $k-- >1;
    }
    $k++;
    while($k<=$#l)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;
        print "RIGHT" if  $k++ <$#l;

    }
}
exit

while(<>){
	chomp;
	($n,$m)=split/ /;
	$_=<>;
	chomp;

	if ($n<$m*2){
		for $i(1..($n-$m)){
			print "RIGHT\n"
			}
		$_=reverse $_;
		s/.// and print "PRINT $&\n";
		s/./print "LEFT\nPRINT $&\n"/ge;

		}
	else {
		for $i(1..($m-1)){
			print "LEFT\n"
			}
		s/.// and print "PRINT $&\n";
		s/./print "RIGHT\nPRINT $&\n"/ge;

		}

	}

use strict;
use POSIX;
my ($n,$k)=split(' ',<>);
$_=<>;
chomp;
my @l = split('',$_);
$\ = "\n";
unshift (@l,"lal");
my $adfs = 1 if $k == 1;

if($k>= floor($#l/2))
{
    do
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;
                print "RIGHT" if  $k++ <$#l;
    }
    while ($k<=$#l);
    $k--;

    while ($k>0 and !$adfs)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;

        print "LEFT" if $k-- >1;
    }
}
else
{

    while ($k>0)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;
        print "LEFT" if $k-- >1;
    }

    do{
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;
        print "RIGHT" if  $k++ <$#l;

    }while($k<$#l);
}
exit

use strict;
my ($n,$k)=split(' ',<>);
$_=<>;
chomp;
my @l = split('',$_);
$\ = "\n";
unshift (@l,"lal");
if($k>= ($#l/2))
{
    while($k<$#l)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;
                print "RIGHT" if  $k++ <$#l;
    }

    while ($k>0)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;

        print "LEFT" if $k-- >1;
    }
}
else
{

    while ($k>0)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;
        print "LEFT" if $k-- >1;
    }
    while($k<=$#l)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;
        print "RIGHT" if  $k++ <$#l;

    }
}

use strict;
use POSIX;
my ($n,$k)=split(' ',<>);
$_=<>;
chomp;
my @l = split('',$_);
$\ = "\n";
unshift (@l,"lal");
my $adfs = 1 if $k == 1;

if($k>= floor($#l/2))
{
    while($k<=$#l)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;
                print "RIGHT" if  $k++ <$#l;
    }
    $k--;

    goto exit if $adfs;

    while ($k>0)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;

        print "LEFT" if $k-- >1;
    }
}
else
{

    while ($k>0)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;
        print "LEFT" if $k-- >1;
    }
    while($k<$#l)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;
        print "RIGHT" if  $k++ <$#l;

    }
}
exit

use strict;
use POSIX;
my ($n,$k)=split(' ',<>);
$_=<>;
chomp;
my @l = split('',$_);
$\ = "\n";
unshift (@l,"lal");
my $adfs = 1 if $k == 1;

if($k>= floor($#l/2))
{
    while($k<=$#l)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;
                print "RIGHT" if  $k++ <$#l;
    }
    $k--;

    while ($k>0)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;

        print "LEFT" if $k-- >1;
    }
}
else
{

    while ($k>0)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;
        print "LEFT" if $k-- >1;
    }
    while($k<$#l)
    {
        print "PRINT $l[$k]" if defined $l[$k];
        $l[$k] = undef;
        print "RIGHT" if  $k++ <$#l;

    }
}


for (1..<>) {
        chomp (my $in = <>);
        my ($n, $l, $r, $k) = split / /, $in;
        $minprice = $l;
        $maxprice = $r;
        $total_cash = $k;
        chomp (my $in = <>);
        my @a = split / /, $in;

        @a = sort {$a <=> $b} @a;
        $t = 0;

        foreach (@a) {
                $_ < $minprice and next;
                $_ > $maxprice and last;
                $t++;
                $k -= $_;
                $k <= 0 and last;
        }
        $k < 0 and $t--;
        print $t, "\n";
}


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

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

while( $test_case -- > 0 ){
  my ($a,$b) = map { $_ - 0 } split(/\s+/,<STDIN>);
  if( $a < $b ){
    print "1\n";
    next;
  }
  my $mn = 10**9;
  my $ans = 0;
  if( $b == 1 ){
    $b++; $ans ++;
  }
  for(my $bb = $b; $bb <= $b+35; $bb++){
    my $cnt = $ans + ($bb-$b);
    my $t = 1;
    while( $bb ** $t <= $a ){
      $t++;
    }
    my $v = $cnt + $t;
    $mn = $v if $v < $mn;
  }
  print "$mn\n";

}

exit(0);

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $ans = 0;

	$B == 1 and do { $B ++; $ans ++; };

	my @cand;

	for my $i ( 0 .. 10 ){
		my $B2 = $B + $i;
		my $A2 = $A;
		my $ans2 = $ans + $i;

		while( $A2 >= 1 ){
			$A2 /= $B2;
			$A2 = int $A2;
			$ans2 ++;
			}

		push @cand, $ans2;
		}

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


#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

while(<>){
	s/(@\w)(\w+@)/$1,$2/g while /@(\w)(\w+)@/;
	print /@\w?@/||/^@/||/\@$/||!/@/?"No solution\n":"$_";
	}

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

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

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

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

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

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

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

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

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

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

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

while(<>){
	s/(@\w)(\w+@)/$1,$2/g while /@(\w)(\w+)@/;
	print /@\w?@/||/^@/||/\@$/?"No solution\n":"$_";
	}

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

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

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

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

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

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

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

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

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

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


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	@_ = split ' ', <>;

	my @max;

	push @max, ( sort { $b <=> $a } @_ )[ 0 ];

	my @sums = @_;

	for my $i ( 1 .. $n - 1 ){
		shift @_;
		pop @sums;

		my $max = -~0;
		for my $j ( 0 .. @sums - 1 ){
			$sums[ $j ] += $_[ $j ];
			$sums[ $j ] > $max and $max = $sums[ $j ];
			}
		push @max, $max;
		}

	my @cum = @max;

	for my $i ( reverse 0 .. @cum - 2 ){
		$cum[ $i ] = $cum[ $i ] > $cum[ $i + 1 ] ?
			$cum[ $i ] : $cum[ $i + 1 ];
		}

#	print "@cum";

	unshift @cum, $cum[ 0 ];

	for my $i ( 1 .. @cum - 1 ){
		$cum[ $i ] += $x * $i;
		}

	$cum[ 0 ] < 0 and $cum[ 0 ] = 0;

#	print "@cum";

	for my $i ( 1 .. @cum - 1 ){
		$cum[ $i ] = $cum[ $i ] > $cum[ $i - 1 ] ?
			$cum[ $i ] : $cum[ $i - 1 ];
		}

	print "@cum";

#	my @ans;

#	my $max = 0;
#	$max < $_ and $max = $_ for @max;

#	push @ans, $max;

#	for my $i ( 1 .. $n ){
#		my $max = $ans[ @ans - 1 ];

#		for my $j ( $i - 1 .. $n - 1 ){
#			$max[ $j ] += $x;

#			$max < $max[ $j ] and $max = $max[ $j ];
#			}

#		push @ans, $max;
#		}

#	print "@ans";
	}


use strict;
#open STDIN, '<input.txt';
#open STDOUT, '>output.txt';
my $n = <>;
my @a = split(' ', <>);
my $buf1 = 0;
my $buf2 = 0;
for(my $i = 0; $i < $n; $i++){
  if($a[$i] == 0){
    $buf1++;
  }
  else{
    $buf2++;
  }
}
my $ans = 0;
my $i = 0;
while($buf1 > 0 && $buf2 > 0){
  if($a[$i] == 0){
    $buf1--;
    $ans++;
  }
  else{
    $buf2--;
    $ans++;
  }
  $i++;
}
print $ans;

use strict;
use warnings;

use Data::Dumper;

sub main {

    my $in = *STDIN;
    # open(my $in, '<:encoding(UTF-8)', *STDIN);
    # open(my $out, '>:encoding(UTF-8)', './out.txt');

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

    $r= <$in>;
    my @d= split(' ', $r);

    my $dl= 0;
    my $dr= 0;

    for my $door (@d) {
        ($door eq 1) ? $dr++ : $dl++;
    }

    my $lc= 0;
    my $rc= 0;
    my $c= 0;
    for my $door (@d) {
        ($door eq 1) ? $rc++ : $lc++;
        $c++;

        if($rc >= $dr || $lc >= $dl) {
            print $c;
            # print $out $c;
            return;
        }
    }

}

main() unless caller();

use strict;
#open STDIN, '<input.txt';
#open STDOUT, '>output.txt';
my $n = <>;
my @a = split(' ', <>);
my $buf1 = 0;
my $buf2 = 0;
sub solve{
  my ($a, $n) = @_;
for(my $i = 0; $i < $n; $i++){
  if($a[$i] == 0){
    $buf1++;
  }
  else{
    $buf2++;
  }
}
my $ans = 0;
my $i = 0;
while($buf1 > 0 && $buf2 > 0){
  if($a[$i] == 0){
    $buf1--;
    $ans++;
  }
  else{
    $buf2--;
    $ans++;
  }
  $i++;
}
print $ans;
}
solve(\@a, $n);

use strict;
#open STDIN, '<input.txt';
#open STDOUT, '>output.txt';
my $n = <>;
my @a = split(' ', <>);
my %h;
for(my $i = 0; $i < $n; $i++){
  $h{$a[$i]}++;
}
my $ans = 0;
for(my $i = 0; $i < $n; $i++){
  $h{$a[$i]}--;
  $ans++;
  if($h{$a[$i]} == 0){
    print $ans;
    exit(0);
  }
}
print $ans;

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	y/ //d;

	my $len = length;

	$_ = reverse;

	print /^0++(?=1)|^1++(?=0)/ ? $len - length $& : 0;
	}

use strict;
use warnings;

use Data::Dumper;

sub main {

    open(my $in, '<:encoding(UTF-8)', './in.txt');
    # open(my $out, '>:encoding(UTF-8)', './out.txt');

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

    $r= <$in>;
    my @d= split(' ', $r);

    my $dl= 0;
    my $dr= 0;

    for my $door (@d) {
        ($door eq 1) ? $dr++ : $dl++;
    }

    my $lc= 0;
    my $rc= 0;
    my $c= 0;
    for my $door (@d) {
        ($door eq 1) ? $rc++ : $lc++;
        $c++;

        if($rc >= $dr || $lc >= $dl) {
            print $c;
            # print $out $c;
            return;
        }
    }

}

main() unless caller();

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	y/ //d;

	my $len = length;

	$_ = reverse;

	print /^(.)\1*+\B/ ? $len - length $& : 0;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	y/ //d;

	my $len = length;

	$_ = reverse;

	/(.)\1*/;

	print $len - length $&;
	}


#!/usr/bin/perl -w

use strict;

chomp($_ = <>);
my ($n, $m) = split;
my %votes;
my ($v_max, $v_candidate) = (0,1);

for my $i (0..$m-1) {
    chomp($_ = <>);
    my @city_votes = split;
    my ($max, $candidate) = (0, 1);
    my $len = @city_votes;
    for my $j (0..$len-1) {
        if($max < $city_votes[$j]) {
            $max = $city_votes[$j];
            $candidate = $j + 1;
        }
    }

    $votes{$candidate} += 1;
    if($votes{$candidate} > $v_max) {
        $v_max = $votes{$candidate};
        $v_candidate = $candidate;
    }
    elsif($votes{$candidate} == $v_max && $v_candidate > $candidate) {
        $v_max = $votes{$candidate};
        $v_candidate = $candidate;
    }
}

print $v_candidate, "\n";

#!/usr/bin/perl -w

use strict;

chomp($_ = <>);
my ($n, $m) = split;
my %votes;
my ($v_max, $v_candidate) = (0, 0);

for my $i (0..$m) {
    chomp($_ = <>);
    my @city_votes = split;
    my ($max, $candidate) = (0, 0);
    my $len = length(@city_votes);
    for my $j (0..$len) {
        if($max < $city_votes[$j]) {
            $max = $city_votes[$j];
            $candidate = $j + 1;
        }
    }

    $votes{$candidate} += 1;
    if($votes{$candidate} > $v_max) {
        $v_max = $votes{$candidate};
        $v_candidate = $candidate;
    }
    elsif($votes{$candidate} == $v_max && $v_candidate > $candidate) {
        $v_max = $votes{$candidate};
        $v_candidate = $candidate;
    }
}

print $v_candidate, "\n";

#!/usr/bin/perl -w

use strict;

chomp($_ = <>);
my ($n, $m) = split;
my %votes;
my ($v_max, $v_candidate) = (0, 0);

for my $i (0..$m-1) {
    chomp($_ = <>);
    my @city_votes = split;
    my ($max, $candidate) = (0, 0);
    my $len = @city_votes;
    for my $j (0..$len-1) {
        if($max < $city_votes[$j]) {
            $max = $city_votes[$j];
            $candidate = $j + 1;
        }
    }

    $votes{$candidate} += 1;
    if($votes{$candidate} > $v_max) {
        $v_max = $votes{$candidate};
        $v_candidate = $candidate;
    }
    elsif($votes{$candidate} == $v_max && $v_candidate > $candidate) {
        $v_max = $votes{$candidate};
        $v_candidate = $candidate;
    }
}

print $v_candidate, "\n";

#!/usr/bin/perl -w

use strict;

chomp($_ = <>);
my ($n, $m) = split;
my %votes;
my ($v_max, $v_candidate) = (0, 0);

for my $i (0..$m-1) {
    chomp($_ = <>);
    my @city_votes = split;
    my ($max, $candidate) = (0, 0);
    my $len = length(@city_votes);
    for my $j (0..$len-1) {
        if($max < $city_votes[$j]) {
            $max = $city_votes[$j];
            $candidate = $j + 1;
        }
    }

    $votes{$candidate} += 1;
    if($votes{$candidate} > $v_max) {
        $v_max = $votes{$candidate};
        $v_candidate = $candidate;
    }
    elsif($votes{$candidate} == $v_max && $v_candidate > $candidate) {
        $v_max = $votes{$candidate};
        $v_candidate = $candidate;
    }
}

print $v_candidate, "\n";


use strict;

use List::Util qw(sum min);

chomp(my $n = <>);
chomp($_ = <>);
my @a = split;

my %occurence = ();
++$occurence{$_} for @a;

my $sum = sum map { min $_, 2 } values %occurence;
my $x = int($sum / 2);
my $y = $sum - $x;

print $x * $y, "\n";

my %pos = ();
push @{$pos{$a[$_]}}, $_ for 0 .. $#a;

my @res = (0) x (2 * $n);
my @one = ();
my @rest = ();
my @h1 = ();
my @h2 = ();
while (my ($k, $v) = each %pos) {
    if (@$v == 1) {
        push @one, @$v;
    } else {
        push @h1, shift @$v;
        push @h2, shift @$v;
        push @rest, @$v;
    }
}
while (@one) {
    push @h1, shift @one;
    push @h2, shift @one if @one;
}
while (@rest) {
    if (@h1 < $n) {
        push @h1, shift @rest;
    } else {
        push @h2, shift @rest;
    }
}
$res[$_] = 1 for @h1;
$res[$_] = 2 for @h2;
print "@res\n";

use strict;

use List::Util qw(sum min);

chomp(my $n = <>);
chomp($_ = <>);
my @a = split;

my %occurence = ();
++$occurence{$_} for @a;

my $sum = sum map { min $_, 2 } values %occurence;
my $x = int($sum / 2);
my $y = $sum - $x;

print $x * $y, "\n";

my %pos = ();
push @{$pos{$a[$_]}}, $_ for 0 .. $#a;

my @res = (0) x (2 * $n);
my @one = ();
my @rest = ();
my @h1 = ();
my @h2 = ();
while (my ($k, $v) = each %occurence) {
    if (@{$pos{$k}} == 1) {
        push @one, @{$pos{$k}};
    } else {
        push @h1, shift @{$pos{$k}};
        push @h2, shift @{$pos{$k}};
        push @rest, @{$pos{$k}};
    }
}
while (@one) {
    push @h1, shift @one;
    push @h2, shift @one if @one;
}
for (@rest) {
    if (@h1 < $n) {
        push @h1, shift @rest;
    } else {
        push @h2, shift @rest;
    }
}
$res[$_] = 1 for @h1;
$res[$_] = 2 for @h2;
print "@res\n";

use strict;

use List::Util qw(sum min);

chomp(my $n = <>);
chomp($_ = <>);
my @a = split;

my %occurence = ();
++$occurence{$_} for @a;

my $sum = sum map { min $_, 2 } values %occurence;
my $x = int($sum / 2);
my $y = $sum - $x;

print $x * $y, "\n";

my %pos = ();
push @{$pos{$a[$_]}}, $_ for 0 .. $#a;

my @res = (0) x (2 * $n);
my @one = ();
my @rest = ();
while (my ($k, $v) = each %occurence) {
    if (@{$pos{$k}} == 1) {
        push @one, @{$pos{$k}};
    } else {
        $res[shift @{$pos{$k}}] = 1;
        $res[shift @{$pos{$k}}] = 2;
        push @rest, @{$pos{$k}};
        --$x;
        --$y;
    }
}
while (@one) {
    $res[shift @one] = 1;
    --$x;
    if (@one) {
        $res[shift @one] = 2;
        --$y;
    }
}
for (@rest) {
    if ($x > 0) {
        $res[shift @rest] = 1;
        --$x;
    } else {
        $res[shift @rest] = 2;
        --$y;
    }
}
print "@res\n";


#!/usr/bin/perl

use strict;
use warnings;
use integer;

<>;

my $bline = <>;
chomp $bline;

my @bseq = split /\s+/, $bline;

my ($low, $up) = (0, shift @bseq);

my @from_front = ($low);
my @from_back = ($up);

foreach my $b (@bseq) {
	my $sum = $low + $up;
	my $err = abs($sum - $b);
	$low+= $err if $sum < $b;
	$up -= $err if $sum > $b;
	push @from_front, $low;
	push @from_back , $up ;
}

print "@from_front";
print " ";
my @revd = reverse @from_back;
print "@revd\n";

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my @L;
	my @R;

	my $max = shift @_;
	unshift @L, 0;
	unshift @R, $max;

	for( @_ ){
		my $sum = $L[ 0 ] + $R[ 0 ];
		if( $sum == $_ ){
			unshift @L, $L[ 0 ];
			unshift @R, $R[ 0 ];
			}
		elsif( $sum < $_ ){
			unshift @L, $_ - $R[ 0 ];
			unshift @R, $R[ 0 ];
			}
		elsif( $sum > $_ ){
			unshift @R, $_ - $L[ 0 ];
			unshift @L, $L[ 0 ];
			}
		}

	print join ' ', ( reverse @L ), @R;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my @L;
	my @R;

	my $max = shift @_;
	unshift @L, 0;
	unshift @R, $max;

	for( @_ ){
		my $sum = $L[ 0 ] + $R[ 0 ];
		if( $sum == $_ ){
			unshift @L, $L[ 0 ];
			unshift @R, $R[ 0 ];
			}
		elsif( $sum < $_ ){
			unshift @L, $_ - $R[ 0 ];
			unshift @R, $R[ 0 ];
			}
		elsif( $sum > $_ ){
			unshift @R, $_ - $L[ 0 ];
			unshift @L, $L[ 0 ];
			}
		}

	print join ' ', ( reverse @L ), @R;
	}


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

my $rc = <>;
my $a;
my @rooms;
my @keys;
my %hk;
for (0 .. $rc - 2)
{

    read(STDIN, $keys[$_], 1);
    read(STDIN, $rooms[$_], 1);

    $keys[$_] = uc($keys[$_]);
    $rooms[$_] = uc($rooms[$_]);
    $hk{$rooms[$_]} = 0;
    $hk{$keys[$_]} = 0;

}
my $ans = 0;
for (0 .. $#rooms)
{
    $hk{$keys[$_]}++;
    if($hk{$rooms[$_]} <= 0)
    {
        $ans ++;
    }
    else
    {
        $hk{$rooms[$_]}--;
    }

}
print $ans;

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

my $rc = <>;
my $a;
my @rooms;
my @keys;
for (0 .. $rc - 2)
{
    read(STDIN, $rooms[$_], 1);
    $rooms[$_] = uc($rooms[$_]);
    read(STDIN, $keys[$_], 1);
}
my %hk;
my $ans = 0;
for (0 .. ($rc) / 2 + 1)
{
    $hk{$keys[$_]}++;
    if(!defined($hk{$rooms[$_]}) or $hk{$rooms[$_]} <= 0)
    {
        $ans ++;
    }
    else
    {
        $hk{$rooms[$_]}--;
    }
}
print $ans;

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

my $rc = <>;
my $a;
my @rooms;
my @keys;
my %hk;
for (0 .. $rc - 2)
{
    read(STDIN, $rooms[$_], 1);
    $rooms[$_] = uc($rooms[$_]);
    read(STDIN, $keys[$_], 1);
    $keys[$_] = uc($keys[$_]);
    $hk{$rooms[$_]} = 0;
    $hk{$keys[$_]} = 0;

}

my $ans = 0;
for (0 .. $#rooms)
{
    $hk{$keys[$_]}++;
    if($hk{$rooms[$_]} <= 0)
    {
        $ans ++;
    }
    else
    {
        $hk{$rooms[$_]}--;
    }

}
print $ans;

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

my $rc = <>;
my $a;
my @rooms;
my @keys;
for (0 .. $rc - 2)
{
    read(STDIN, $rooms[$_], 1);
    $rooms[$_] = uc($rooms[$_]);
    read(STDIN, $keys[$_], 1);
}
my %hk;
my $ans = 0;
for (0 .. $#rooms)
{
    $hk{$keys[$_]}++;
    if(!defined($hk{$rooms[$_]}) or $hk{$rooms[$_]} <= 0)
    {
        $ans ++;
    }
    else
    {
        $hk{$rooms[$_]}--;
    }
}
print $ans;


use strict;

my $n = <>;

my $counter = 1;
foreach my $i  (1..$n) {
	print $i.' ';

	my $number = $i;
	for my $j (1..$n - 1) {
		if ($number % $n == 0) {
			$counter = 1;
		}
		else {
			$counter = $n + 1;
		}
		$number = $counter + $number;
		print $number.' ';

		#my $counter = $n + 2 - $;
		#my $number = $i;

	}
	print "\n";
}

use strict;

my $n = 5;

my $counter = 1;
foreach my $i  (1..$n) {
	print $i.' ';

	my $number = $i;
	for my $j (1..$n - 1) {
		if ($number % $n == 0) {
			$counter = 1;
		}
		else {
			$counter = $n + 1;
		}
		$number = $counter + $number;
		print $number.' ';

		#my $counter = $n + 2 - $;
		#my $number = $i;

	}
	print "\n";
}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){

	@_ = sort { $a <=> $b } split ' ', <>;
	my $min = $_[0];
	my $max = $_[-1];

	my $cnt = 0;

	$_ != $min and $_ != $max and $cnt ++ for @_;

	print $cnt;
	}

#!/usr/bin/perl

my $num = <>;
chomp($num);
my $line2 = <>;
chomp($line2);
my @tokens = split (" ", $line2);
my @array = sort { $a <=> $b } @tokens;
my $min = $array[0];
my $max = $array[-1];
my $output = 0 ;
for (my $i=0;$i < $num;$i++) {
                #print "$tokens[$i] -- $min -- $max\n";
        if ($tokens[$i] > $min && $tokens[$i] < $max) {
                $output++;
        }
}
print "$output\n";

#!/usr/bin/perl

my $num = <>;
chomp($num);
my $line2 = <>;
chomp($line2);
my @tokens = split (" ", $line2);
my @array = sort { $a <=> $b } @tokens;
my $min = $array[0];
my $max = $array[-1];
my $output = 0 ;
for (my $i=1;$i < $num-1;$i++) {
                #print "$tokens[$i] -- $min -- $max\n";
        if ($tokens[$i] > $min && $tokens[$i] < $max) {
                $output++;
        }
}
print "$output\n";


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

sub main {
    my $n = int <STDIN>;
    my @arr = map int, split /\D/, <STDIN>;
    my @sorted_arr = sort { $a <=> $b } @arr;
    my $count = 0;
    for (0 .. $#arr) {
	if ($arr[$_] != $sorted_arr[$_]) {
	    $count++;
	}
    }
    if ($count <= 2) {
	print 'YES';
    } else {
	print 'NO';
    }
}

main();

__END__

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

sub badElems {
    my @a = @_;
    my @indexes;
    for my $i (1 .. $#a) {
	if ($a[$i] < $a[$i - 1]) {
	    push(@indexes, $i);
	}
    }
    return @indexes;
}

sub check {
    my ($i1, $i2, @a) = @_;
    ($a[$i1], $a[$i2]) = ($a[$i2], $a[$i1]);
return ( (($i1 == 0) || ($a[$i1-1] <= $a[$i1])) &&
	 ($a[$i1] <= $a[$i1+1]) &&
	 ($a[$i2-1] <= $a[$i2]) &&
	 (($i2 == $#a) || ($a[$i2] <= $a[$i2+1])));
}

sub findFirstToSwap {
    my ($i2, @a) = @_;
    my $i = $i2-1;
    my $ai = $a[$i];
    do {
	$i--;
    } while (($i > 0) && ($a[$i] = $ai));
    return $i;
}

sub isGood {
    my @a = @_;
    my @indexes = badElems(@a);
    if (! @indexes) {
	return 1;
    } elsif (@indexes > 2) {
	return 0;
    } else {
	if (@indexes == 1) {
	    unshift(@indexes, findFirstToSwap($indexes[0], @a));
	} else {
	    $indexes[0]--;
	}
	return check(@indexes, @a);
    }
}

sub main {
    my $n = int(<STDIN>);
    my @a = map(int, split(/\D/, <STDIN>));
    if (isGood(@a)) {
	print 'YES';
    } else {
	print 'NO';
    }
}

main();

__END__

4
2 2 2 1

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

sub badElems {
    my @a = @_;
    my @indexes;
    for my $i (1 .. $#a) {
	if ($a[$i] < $a[$i - 1]) {
	    push(@indexes, $i);
	}
    }
    return @indexes;
}

sub check {
    my ($i1, $i2, @a) = @_;
    ($a[$i1], $a[$i2]) = ($a[$i2], $a[$i1]);
return ( (($i1 == 0) || ($a[$i1-1] <= $a[$i1])) &&
	 ($a[$i1] <= $a[$i1+1]) &&
	 ($a[$i2-1] <= $a[$i2]) &&
	 (($i2 == $#a) || ($a[$i2] <= $a[$i2+1])));
}

sub isGood {
    my @a = @_;
    my @indexes = badElems(@a);
    if (! @indexes) {
	return 1;
    } elsif (@indexes > 2) {
	return 0;
    } else {
	if (@indexes == 1) {
	    unshift(@indexes, $indexes[0] - 1);
	} else {
	    $indexes[0]--;
	}
	return check(@indexes, @a);
    }
}

sub main {
    my $n = int(<STDIN>);
    my @a = map(int, split(/\D/, <STDIN>));
    if (isGood(@a)) {
	print 'YES';
    } else {
	print 'NO';
    }
}

main();

__END__


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

my $line1 = <>;
chomp($line1);
my @nk = split(" ",$line1);
my $n = $nk[0]; #computers
my $k = $nk[1]; #participants

my $line2 = <>;
chomp($line2);
my @a = split(" ",$line2); #max data transfer speed on ith computer

my @sorted = sort{ $b <=> $a } @a;

#n is basically useless, use k for index

say $sorted[$k-1];

use strict;
use POSIX;
my ($n,$k)=split(' ',<>);
my @l = split (' ',<>);
@l = sort{$b<=>$a} @l;
print  $l[$k-1];

use strict;
use POSIX;
my ($n,$k)=split(' ',<>);
my @l = split (' ',<>);
@l = sort @l;

print $l[$k-1]


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $fail = 0;
	my $pos = 0;

	while( $k -- ){
		my $ok = 0;

		for my $i ( 0 .. @_ - 2 ){
			if( $_[ $i ] < $_[ $i + 1 ] ){
				$_[ $i ] ++;
				$pos = $i + 1;
				$ok = 1;
				last;
				}
			}

		$ok or $fail = 1;
		last if $fail;
		}

	print $fail ? -1 : $pos;
	}


$\ = $/;

@regexes = split /^$/m, join '', <DATA>;

while ($t = <>){

	for (1 .. $t){

		($length, undef) = split ' ' , <>;

		@_[ 0 .. 2 ] = map scalar <>, 0 .. 2;  # main array

		$i = -1;
		$i ++, /^s/ and $s = $i for @_;
		@test_lines = ($s);

		s/.// for @_;
		s/$/....../ for @_;

		$fail = 0;

		for $i (0 .. $length / 3){

			$_3x3 = join '', map { s/...//; $& } @_;

			$new_test_lines = '';
			for $k (@test_lines){

				$k == 0 and $_3x3 =~ /$regexes[0]/x and $new_test_lines .= 0;
				$k == 0 and $_3x3 =~ /$regexes[1]/x and $new_test_lines .= 1;

				$k == 1 and $_3x3 =~ /$regexes[2]/x and $new_test_lines .= 0;
				$k == 1 and $_3x3 =~ /$regexes[3]/x and $new_test_lines .= 1;
				$k == 1 and $_3x3 =~ /$regexes[4]/x and $new_test_lines .= 2;

				$k == 2 and $_3x3 =~ /$regexes[5]/x and $new_test_lines .= 1;
				$k == 2 and $_3x3 =~ /$regexes[6]/x and $new_test_lines .= 2;

				}
			$new_test_lines = join '', sort split //, $new_test_lines;
			$new_test_lines =~ y///cs;  # sqeeze
			@test_lines = split //, $new_test_lines;
			@test_lines or $fail = 1 and last;

			}

		print qw(YES NO)[ $fail ];
		}

	}

__DATA__
 \. \. \.
  .  .  .
  .  .  .

 \.  .  .
 \. \. \.
  .  .  .

 \. \. \.
 \.  .  .
  .  .  .

  .  .  .
 \. \. \.
  .  .  .

  .  .  .
 \.  .  .
 \. \. \.

  .  .  .
 \. \. \.
 \.  .  .

  .  .  .
  .  .  .
 \. \. \.


$\ = $/;
while(<>){
	($n, $h, $k) = split;
	@_ = split ' ', <>;
	$sec = 0;
	$stack = 0;
	while( @_ or $stack ){
		while( @_ and $stack + $_[0] <= $h ){
			$stack += shift @_;
			}

		int( $stack / $k ) or do { $stack = 0; $sec ++ };
		$sec += int( $stack / $k );
		$stack %= $k;
		}
	print 0 + $sec
}

$\ = $/;
while(<>){
	($n, $h, $k) = split;
	@_ = split ' ', <>;
	$sec = 0;
	$stack = 0;
	while( @_ ){
		while( @_ and $stack + $_[0] <= $h ){
			$stack += shift @_;
			}

		$stack -= $k;
		$stack < 0 and $stack = 0;
		$sec ++;
		}
	print ++ $sec
}


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

sub main () {
	my $n = int <STDIN>;
	print "$n";
	for ( 1 .. $n - 1 ) {
		print " $_";
	}
	print "\n";
	exit 0;
}

main();

__END__


my $numberlines = <STDIN>;
my $numeros;
@arrayradios = split(/\s+/, $numberlines);
$R = $arrayradios[0];
$r = $arrayradios[1];
my $contador=0;
@arraydistancias=();
@radiosp=();
my $N= <STDIN>;
$l = $N-1;
for($i=$l;$l>=0;$l--)
{
	$numeros = <STDIN>;
	@arraynumeros = split(/\s+/, $numeros);
	$disteucl = sqrt(($arraynumeros[0] **2)+($arraynumeros[1] **2));
	push (@arraydistancias, $disteucl);
	push (@radiosp, $arraynumeros[2]);
}
for($i=$N-1;$N>=0;$N--)
{
	if ((($arraydistancias[$N] + $radiosp[$N]) <= $R) && (($arraydistancias[$N]-$radiosp[$N]) >= $R - $r)) {
		$contador = $contador+ 1;
	}
}

print $contador;

#!/usr/bin/perl
$line = <STDIN>;
@radios = split(/\s+/, $line);
$r = $radios[0];
$d = $radios[1];
my $N= <STDIN> - 1;
$dat = $N;
@distan=();
@rad=();
while ($dat >= 0){
	$ent = <STDIN>;
	@datos = split(/\s+/, $ent);
	$Tempd = sqrt(($datos[0] * $datos[0])+($datos[1] * $datos[1]));
	push (@distan, $Tempd);
	push (@rad, $datos[2]);
	$dat = $dat-1;
#	print "@distan\n";
#	print "@rad\n";
}
$c=0;
while ($N >= 0){
#	print $distan[$N]."\n";
#	print $rad[$N]."\n";
	if ((($distan[$N] + $rad[$N]) <= $r) && (($distan[$N]-$rad[$N]) >= $r - $d)) {
		$c = $c + 1;
	}
	$N = $N-1;
}
print $c."\n";

#!/usr/bin/perl
$line = <STDIN>;
@radios = split(/\s+/, $line);
$R = $radios[0];
$r = $radios[1];
my $N= <STDIN> - 1;
$dat = $N;
@distan=();
@rad=();
while ($dat >= 0){
	$ent = <STDIN>;
	@datos = split(/\s+/, $ent);
	$Tempd = sqrt(($datos[0] * $datos[0])+($datos[1] * $datos[1]));
	push (@distan, $Tempd);
	push (@rad, $datos[2]);
	$dat = $dat-1;
#	print "@distan\n";
#	print "@rad\n";
}
$c=0;
while ($N >= 0){
#	print $distan[$N]."\n";
#	print $rad[$N]."\n";
	if ((($distan[$N] + $rad[$N]) <= $R) && (($distan[$N]-$rad[$N]) >= $r)) {
		$c = $c + 1;
	}
	$N = $N-1;
}
print $c."\n";

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

my $m;
my $i;
my $j;
my $valor;
my @m1;
my @m2;
my $contador=0;
my $outside;
my $main;

print "Ingrese R:";
my $R = <STDIN>;
chomp $R;
print "R es '$R'\n";

print "Ingrese r:";
my $r = <STDIN>;
chomp $r;
print "r es '$r'\n";

print "ingrese los puntos:";
$m=<STDIN>;
chop($m);

for($i=0;$i<$m;$i++)
{
   for($j=0;$j<3;$j++)
   {$valor=<STDIN>;
   	chop($valor);
   	$m1[$i][$j]=$valor;
   }
}
for($i=0;$i<$m;$i++)
{
	for($j=0;$j<=3;$j++)
	{
		$m2[$i][$j]=sqrt($m1[$i][$j]**2+$m1[$i][$j+1]**2);
	}
	print "\n";
}

for($i=0;$i<$m;$i++)
{
   for($j=0;$j<1;$j++)
   {
   	if($m2[$i][$j]+$r<=$R)
   	{
   		$contador=$contador+1;
   	}
   }
   print "\n";
}
print $contador;

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

my $m;
my $i;
my $j;
my $valor;
my @m1;
my @m2;
my $contador=0;
my $outside;
my $main;

my $R = <STDIN>;
chomp $R;

my $r = <STDIN>;
chomp $r;

$m=<STDIN>;
chop($m);

for($i=0;$i<$m;$i++)
{
   for($j=0;$j<3;$j++)
   {$valor=<STDIN>;
   	chop($valor);
   	$m1[$i][$j]=$valor;
   }
}
for($i=0;$i<$m;$i++)
{
	for($j=0;$j<=3;$j++)
	{
		$m2[$i][$j]=sqrt($m1[$i][$j]**2+$m1[$i][$j+1]**2);
	}
}
for($i=0;$i<$m;$i++)
{
   for($j=0;$j<1;$j++)
   {
   	if($m2[$i][$j]+$r<=$R)
   	{
   		$contador=$contador+1;
   	}
   }
}
print $contador;


#!/usr/bin/perl

($n, $m, $k) = split(/\s/, <STDIN>);
($mCount, $kCount) = ($m, $k);
@a = split(/\s/, <STDIN>);
$answer = 0;

foreach $item (@a) {
  if( $item == 1 ) {
    if( $mCount > 0 ) {
      $mCount--;
    }
    else {
      $answer++;
    }
  }
  else {
    if( $kCount > 0 ) {
      $kCount--;
    }
    else {
      if( $mCount > 0 ) {
	$mCount--;
      }
      else {
	$answer++;
      }
    }
  }
}

print $answer, "\n";

#!/usr/bin/perl
use bignum;

($n, $m, $k) = split(/\s/, <STDIN>);
($mCount, $kCount) = ($m, $k);
@a = split(/\s/, <STDIN>);
$answer = 0;

foreach $item (@a) {
  if( $item == 1 ) {
    if( $mCount > 0 ) {
      $mCount--;
    }
    else {
      $answer++;
    }
  }
  else {
    if( $kCount > 0 ) {
      $kCount--;
    }
    else {
      if( $mCount > 0 ) {
	$mCount--;
      }
      else {
	$answer++;
      }
    }
  }
}

print $answer, "\n";

#!/usr/bin/perl

$input = <>;
($n, $m, $k)=split(/\s/, $input);
$input = <>;
@a = split(/\s/, $input);
$bowl = $m;
$plate = $k;
$total = @a;

foreach $i (@a){
    if($i == 1){
	if($bowl > 0){
	$bowl--;
	$total--;
    }
	else{
	    break;
	}

    }
    else{
	if($plate > 0 ){
	    $plate--;
	    $total--;
	}
	elsif($bowl > 0){
	    $bowl--;
	    $total--;
	}
	else{
	break;
    }

    }
}
print $total;


#!/usr/bin/perl

my $inp = <STDIN>;
my @ar = split(' ', $inp);

my $i;
my $h;
my $f = 0;
my $f_ans = -1;

for ($i = 1; $i <= $ar[1]; $i += 1) {
  my $tmp = <STDIN>;
  my $ans = $tmp % $ar[0];
  if ($h{$ans} == 2) {
    if ($f == 0) {
        $f = 1;
        $f_ans = $i;
    }
  } else {
    $h{$ans} = 2;
  }
}

print $f_ans;

# get first line as a string
my $f = <STDIN>;
chomp ( $f );

my $p, $n;
($p, $n) = split m/ /, $f;

my %h;
my $collison = 0;

for ( my $i =0 ; $i < $n; $i += 1 ) {
    $f = <STDIN>;
    chomp ( $f );
    if ( exists $h{ $f % $p } ) {
	print (($i + 1) . "\n");		# print answer
	$i = $n; 		# exit the loop
	$collision = 1;
    }
    $h{ $f % $p } = 1;
}

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

# get first line as a string
my $f = <STDIN>;
chomp ( $f );

my $p, $n;
($p, $n) = split m/ /, $f;

my %h;
my $colliison = 0;

for ( my $i =0 ; $i < $n; $i += 1 ) {
    $f = <STDIN>;
    chomp ( $f );
    if ( exists $h{ $f % $p } ) {
	print (($i + 1) . "\n");		# print answer
	$i = $n; 		# exit the loop
	$collision = 1;
    }
    $h{ $f % $p } = 1;
}

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

use strict ;
use warnings ;

my @array = split(/ /,<STDIN>) ;

my $p = $array[0] ;
my $n = $array[1] ;

my @x ;

for(my $j = 0 ; $j < $n ; $j++){
	$x[$j] = <STDIN> ;
}

my %hash ;

for(my $i = 0 ; $i < $n ; $i++ ) {
	my $value = $x[$i] ;
	my $remainder = $value % $p ;

	if(exists $hash{$remainder}){
		print $i + 1 ;
		exit ;
	}else{
		$hash{$remainder} = 1 ;
	}
}

print -1 ;

chomp ($line = <>);
($p, $n) = split ' ', $line;
for(1..$n)
{
    chomp($x = <>);
    print "$_\n" and exit if $seen{$x % $p};
    $seen{$x % $p} = 1;
}
print "-1\n";

# get first line as a string
my $f = <STDIN>;
chomp ( $f );

my $p, $n;
($p, $n) = split m/ /, $f;

print "two\n";

my %h;
my $colliison = 0;

for ( my $i =0 ; $i < $n; $i += 1 ) {
    $f = <STDIN>;
    chomp ( $f );
    if ( exists $h{ $f } ) {
	print "$i\n";		# print answer
	$i = $n; 		# exit the loop
	$collision = 1;
    }
    $h{ $f } = 1;
}

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

# get first line as a string
my $f = <STDIN>;
chomp ( $f );

my $p, $n;
($p, $n) = split m/ /, $f;

my %h;
my $colliison = 0;

for ( my $i =0 ; $i < $n; $i += 1 ) {
    $f = <STDIN>;
    chomp ( $f );
    if ( exists $h{ $f } ) {
	print "$i\n";		# print answer
	$i = $n; 		# exit the loop
	$collision = 1;
    }
    $h{ $f } = 1;
}

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

#!/usr/bin/perl

my $inp = <STDIN>;
my @ar = split(' ', $inp);

my $i;
my $h;
my $f = 0;
my $f_ans = -1;

for ($i = 1; $i <= $ar[1]; $i += 1) {
  my $tmp = <STDIN>;
  my $ans = $tmp % $ar[0];
  if ($h{$ans} == 2) {
    $f = 1;
    my $f_ans = $i;
  } else {
    $h{$ans} = 2;
  }
}

print $f_ans;

#!/usr/bin/perl

my $inp = <STDIN>;
my @ar = split(' ', $inp);

my $i;
my $h;
my $f = 0;
my $f_ans = -1;

for ($i = 1; $i <= $ar[1]; $i += 1) {
  my $tmp = <>;
  my $ans = $tmp % $ar[0];
  if ($h{$ans} == 2) {
    $f = 1;
    my $f_ans = $i;
  } else {
    $h{$ans} = 2;
  }
}

print $f_ans;


#!/usr/bin/perl
use 5.010;

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

my %mp;

foreach $c ( split //, $s )
{
	$char = "".$c;

	#print $char."\n";
	if( exists $mp{$char} ){
		my $val = $mp{$char};
		$mp{$char} = $val + 1;
	}
	else{
		$mp{$char}= 1;

	}

}

my $count = keys %mp;
my @v = values %mp;
my $cnt = 0;
for $val (@v){
			if($val>1){
				$cnt++;
			}
}
#print $count;

if( $count == 2 ){
		say( ($cnt==2) ? "Yes" : "No" );
}
elsif( $count == 3 ) {
		say( ($cnt>=1) ? "Yes" : "No" );
}
elsif ( $count ==4 ) {
	say("Yes");
}
else{
	say ("No");
}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	chomp;

	my %h;

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

	my @values = values %h;

	print do {
		if( 4 < keys %h ){
			'No';
			}
		elsif( 4 == keys %h ){
			'Yes';
			}
		elsif( 3 == keys %h ){
			( 3 < length ) ? 'Yes' : 'No';
			}
		elsif( 2 == keys %h ){
			do {
				if( $values[ 0 ] > 1 and $values[ 1 ] > 1 ){
					'Yes';
					}
				else{
					'No';
					}
				};
			}
		else{
			'No';
			}
		};
	}

#!/usr/bin/perl
use 5.010;

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

my %mp;

foreach $c ( split //, $s )
{
	$char = "".$c;

	#print $char."\n";
	if( exists $mp{$char} ){
		my $val = $mp{$char};
		$mp{$char} = $val + 1;
	}
	else{
		$mp{$char}= 1;

	}

}

my $count = keys %mp;
my @v = values %mp;
my $cnt = 0;
for $val (@v){
			if($val>1){
				$cnt++;
			}
}
print $count;

if( $count == 2 ){
		say( ($cnt==2) ? "Yes" : "No" );
}
elsif( $count == 3 ) {
		say( ($cnt>=1) ? "Yes" : "No" );
}
elsif ( $count ==4 ) {
	say("Yes");
}
else{
	say ("No");
}

#!/usr/bin/perl
use 5.010;

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

foreach $char ( split //, $s )
{
	$char = "".$char;
	if( exists $mp{$char} ){
		$mp[$char] = $mp[$char]+1;
	}
	else{
		$mp[$char] = 1;
	}
}

my $count = keys %mp;
my @v = values %mp;
my $cnt = 0;
for $val (@v){
			if($val>1){
				$cnt++;
			}
}

if( $count == 2 ){
		say( ($cnt==2) ? "Yes" : "No" );
}
elsif( $count == 3 ) {
		say( ($cnt>=1) ? "Yes" : "No" );
}
elsif ( $count ==4 ) {
	say("Yes");
}
else{
	say ("No");
}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){

	}


#use Time::HiRes qw(gettimeofday tv_interval);
#$t=[gettimeofday];

$fh=\*STDIN;
# open($fh,"<","t\\l")||die;

$n=<$fh>;
$s=<$fh>; chomp $s;

$inspect = 1;
$eq_len = 1;

sub z {
	if ($inspect = 1 && $eq_len > 1) {
    	$eq_count++;
    	if ($eq_len == 2 && $eq_count == 1) {
    		$add = 1;
    	}
    	elsif ($eq_len > 2 || $eq_count > 1) {
    		$add = 2;
    		$inspect = 0;
    	}
    	$eq_len = 1;
	}
}

for ($i=0; $i<length($s); $i++) {
	$ch = substr($s, $i, 1);
	# print "ch=$ch\n";
  	if ($prev ne $ch)  {
  		$prev = $ch;
  		$count++;
  		z();
  	} else {
  		$eq_len++;
  	}
}
z();

$count+=$add;
print $count;

# print tv_interval($t),"\n";

$inspect = 1;
$eq_len = 1;

sub z {
	if ($inspect = 1 && $eq_len > 0) {
    	$eq_count++;
    	if ($eq_len == 2 && $eq_count == 1) {
    		$add = 1;
    	}
    	elsif ($eq_len > 2 || $eq_count > 1) {
    		$add = 2;
    		$inspect = 0;
    	}
    	$eq_len = 1;
	}
}

$skip = 1;
while (($n = sysread(STDIN, $s, 1000)) > 0) {
	for ($i=0; $i<length($s); $i++) {
		$ch = substr($s, $i, 1);
		# print "ch=$ch\n";
		if ($skip == 1) {
			if ($ch eq chr(10)) {
				$skip = 0;
			}
		} else {
    		if ($prev ne $ch)  {
    			$prev = $ch;
    			$count++;
    			z();
    		} else {
    			$eq_len++;
    		}
		}
	}
}
z();

# print "count=$count\n";
# print "add=$add\n";
$count+=$add;
print $count;

#use Time::HiRes qw(gettimeofday tv_interval);
#$t=[gettimeofday];

$fh=\*STDIN;
# open($fh,"<","t\\l")||die;

$n=<$fh>;
$s=<$fh>; chomp $s;

$inspect = 1;
$eq_len = 1;

sub z {
	if ($inspect = 1 && $eq_len > 0) {
    	$eq_count++;
    	if ($eq_len == 2 && $eq_count == 1) {
    		$add = 1;
    	}
    	elsif ($eq_len > 2 || $eq_count > 1) {
    		$add = 2;
    		$inspect = 0;
    	}
    	$eq_len = 1;
	}
}

for ($i=0; $i<length($s); $i++) {
	$ch = substr($s, $i, 1);
	# print "ch=$ch\n";
  	if ($prev ne $ch)  {
  		$prev = $ch;
  		$count++;
  		z();
  	} else {
  		$eq_len++;
  	}
}
z();

$count+=$add;
print $count;

# print tv_interval($t),"\n";


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $time = 0;

	$time += $_ for @A;

	while( @B > 1 ){
		if( $B[ 0 ] < $B[ @B - 1 ] ){
			$time += $B[ 0 ];
			shift @B;
			}
		else{
			$time += $B[ @B - 1 ];
			pop @B;
			}
		}
	print $time;
	}


#!/usr/bin/perl -w

use strict;

my %donor = ();
my $n = <>;
my @a = split ' ', <>;
$donor{$a[$_ - 1]} = $_ for 1..$n;
print join ' ', map { $donor{$_} } sort { $a <=> $b } keys %donor;
print "\n";

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

chomp($n=<>);
@ans = (0) x ($n+1);
$i = 1;
$ans[$_]=$i++ foreach(split / /, <>);
1+shift @ans and say join ' ', @ans;

<STDIN>;
chomp($s = <STDIN>);
@arr = split(/ /, $s);

for($i = 0; $i <= $#arr; ++$i) {
    $result[$arr[$i] - 1] = $i + 1;
}
print "@result";

<stdin>; chomp($_=<stdin>);my @arr=split(" "); my $i = 0; my %hash = map {++$i => $_} @arr; %hash = reverse %hash; print "$hash{$_} " for (1..@arr-1); print "$hash{@arr}\n"

#!/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 @numbers = split q{ }, read_line;

my @answer = ();

for (1..$n) {
    my $i = shift @numbers;
    $answer[$i] = $_;
}

shift @answer;

say "@answer";

my $num = <>;
chomp $num;
my $index = <>;
chomp $index;
my @index = split / /, $index;
my @new;
for $n(1..$num) {
    my $count=1;
    $count++ while ($n != $index[$count-1]);
    push @new, $count;
}
print join " ", @new;

#!/usr/bin/perl -w

use strict;

my %donor = ();
my $n = <>;
my @a = split ' ', <>;
$donor{$a[$_ - 1]} = $_ for 1..$n;
print join ' ', map { $donor{$_} } sort keys %donor;
print "\n";

<STDIN>;
chomp($s = <STDIN>);
@arr = split(/ /, $s);

for($i = 0; $i <= $#arr; ++$i) {
    $result[$arr[$i] - 1] = $i + 1;
}
print @result;


#!/usr/bin/perl

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

my $line = <>;
chomp($line);
my @points = split(/\s/, $line);

$line = <>;
chomp($line);
my @prize = split(/\s/, $line);
my $min_prize = $prize[0];

my $point = 0;

my @ans = (0,0,0,0,0);
for (@points) {
    $point += $_;
    if ($point >= $min_prize) {
        get_prize();
    }
}

print join(" ", @ans), "\n";
print $point;

sub get_prize {
    for (my $i=4; $i>=0; $i--) {
        if ($point >= $prize[$i]) {
            my $tmp = int($point / $prize[$i]);
            $ans[$i] += $tmp;
            $point -= $prize[$i] * $tmp;
        }
    }
}


use integer;
$\ = $/;
while(<>){
($n, $m) = split;
undef $d1;
undef $h1;
$f = 0;
$max = 0;
for $i (1 .. $m){
($d2, $h2) = split " ", <>;
!defined $d1 ? do {$top = $h2 + $d2 - 1} : do {
$higher = ($h2 > $h1 ? $h2 : $h1);
$diff = ($d2 - $d1) - abs($h1 - $h2);
$diff < 0 and $f++;
$top = $higher + $diff / 2;
$higher > $max and $max = $higher;
};
$top > $max and $max = $top;
($d1, $h1) = ($d2, $h2);
}
$top = $h1 + ($n - $d1);
$top > $max and $max = $top;
print $f ? "IMPOSSIBLE" : $max;
}


#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

<>;
while (<>=~/ /){
	push @i,$`;
	push @j,$'+0;
	}
$i=min(@i);
$j=max(@j);

for $k(0..@i-1){
	$i[$k]==$i && $j[$k]==$j and print ($k+ ++$p);
	}

$p or print -1;

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

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

chomp(my $n = <>);
my @l = ();
my @r = ();

for my $i (1 .. $n) {
    chomp($_ = <>);
    my ($left, $right) = split;
    push @l, $left;
    push @r, $right;
}

my $min_low = min @l;
my $max_high = max @r;
my $find = 0;

for my $i (0 .. $n - 1) {
    if ($l[$i] == $min_low && $r[$i] == $max_high) {
        print $i + 1, "\n";
        $find = 1;
        last;
    }
}
unless ($find) {
    print "-1\n";
}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	$_ = 'WB' x $n;

	@_ = ();

	for my $i ( 1 .. $n ){
		push @_, substr $_, $i % 2, $n;
		}

	print for @_;
	}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	if( $l == $r and $l > 1 ){
		print 'YES';
		next;
		}

	$l % 2 or $l ++;
	$r % 2 or $r --;

	my $odds = ( $r - $l + 2 >> 1 );

	print $odds > $k ? 'NO' : 'YES';
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	if( $l == $r and $l > 1 ){
		print 'YES';
		next;
		}

	my $odds = ( $r - $l >> 1 ) + ( $l % 2 );

	print $odds > $k ? 'NO' : 'YES';
	}


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

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

say('#' x $m);

my $left = 0;

foreach (1..(($n-1) / 2))
{
    if ($left) {
        say('#' . '.' x ($m - 1));
    }
    else
    {
        say('.' x ($m - 1) . '#');
    }
    $left = !$left;
    say '#' x $m;
}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my( $two_stars ) = grep m/\*.*\*/, @_;

	if( defined $two_stars ){
		for( @_ ){
			$_ ne $two_stars and do {
				$_ = $two_stars;
				last;
				};
			}
		}
	else{
		my @lines = grep m/\*/, @_;

		if( $lines[ 0 ] eq $lines[ 1 ] ){
			m/\*/ and s/\./*/ for @_;
			}
		else{
			my @idx = map { index $_, '*' } @lines;
			for( @_ ){
				next if not m/\*/;
				substr $_, $idx[ 0 ], 1, '*';
				substr $_, $idx[ 1 ], 1, '*';
				}
			}
		}

	print for @_;
	}


$\ = $/;
<>;
undef %h;
while(<>){
	($n,$m)=split;
	defined $h{$n} ? ($h{$m} = $h{$n}, delete $h{$n}): ($h{$m} = $n);
	}
$, = $";
print scalar keys %h;
while (($k,$v) = each %h){
	print $v,$k
	}

#!/usr/bin/env perl
#===============================================================================
#         FILE: 2.pl
#       AUTHOR: Phoenix Ikki (liuxueyang.github.io), liuxueyang457@gmail.com
# ORGANIZATION: Hunan University
#      CREATED: 01/14/2015 11:18:24 AM
#===============================================================================

use strict;
use warnings;
use utf8;
use 5.012;

chomp(my $n = <STDIN>);

my %name;
while ( $n-- ) {
	chomp($_ = <STDIN>);
	my ($old, $new) = split(/ /);
	if ( exists($name{$old}) ) {
		my $origin = $name{$old};
		delete $name{$old};
		$name{$new} = $origin;
	}
	else {
		$name{$new} = $old;
	}
}
my $size = keys %name;
print "$size\n";
for my $key (keys %name) {
	print "$name{$key} $key\n";
}


chomp($n=<>);
foreach (split / /, <>) {
	$five++ if $_==5;
}
$zero = $n-$five;
print "-1\n" and exit if $zero==0;
print "0\n" and exit if $five<9;
print "5" x ($five-$five%9) . "0"x$zero . "\n";


#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

@_=<>;
chomp @_;
shift @_;

s/-//g for @_;

for (@_){
	if (/^\d{6}$/){
		@n=split//;
		$f=shift @n;
		$nT=$nP=0;
		for $i(@n){
			$f!=$i and $nT++;
			$i>=$f and $nP++;
			$f=$i;
			}
		$nT && $nP and $_=3;
		$nT && !$nP and $_=2;
		!$nT && $nP and $_=1;
		}

	}

# print "@_\n";

for (@_){
	s/^\d+ / /;
	}

$_=join"",@_;
# print; n();

while (/31|21|32/){
s/31|21|32/reverse $&/eg;
}

$j=0;
for $i(1..100){
	/1{$i}/ and $j++;
	}
s/([a-z]+)(\d*?1{$j})/(push @T,$1) and "$1"."$2"/ieg;
# print; n();
# print "@T\n";

$j=0;
for $i(1..100){
	/2{$i}/ and $j++;
	}
s/([a-z]+)(\d*?2{$j})/(push @P,$1) and "$1"."$2"/ieg;
# print; n();
# print "@P\n";

$j=0;
for $i(1..100){
	/3{$i}/ and $j++;
	}
s/([a-z]+)(\d*?3{$j})/(push @M,$1) and "$1"."$2"/ieg;
# print; n();
# print "@M\n";

print "If you want to call a taxi, you should call: ",(join", ",@T),".\n";
print "If you want to order a pizza, you should call: ",(join", ",@P),".\n";
print "If you want to go to a cafe with a wonderful girl, you should call: ",(join", ",@M),".\n";

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

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

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

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

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

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

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

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

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

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

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

@_=<>;
chomp @_;
shift @_;

s/-//g for @_;

for (@_){
	if (/^\d{6}$/){
		@n=split//;
		$f=shift @n;
		$nT=$nP=0;
		for $i(@n){
			$f!=$i and $nT++;
			$i>=$f and $nP++;
			$f=$i;
			}
		$nT && $nP and $_=3;
		$nT && !$nP and $_=2;
		!$nT && $nP and $_=1;
		}

	}

# print "@_\n";

for (@_){
	s/^\d+ / /;
	}

$_=join"",@_;
# print; n();

s#\d+#join"",(sort (split//,$&))#eg;
# print; n();
$j=0;
for $i(1..100){
	/1{$i}/ and $j++;
	}
s/([a-z]+)(\d*?1{$j})/(push @T,$1) and "$1"."$2"/ieg;
# print; n();
# print "@T\n";

$j=0;
for $i(1..100){
	/2{$i}/ and $j++;
	}
s/([a-z]+)(\d*?2{$j})/(push @P,$1) and "$1"."$2"/ieg;
# print; n();
# print "@P\n";

$j=0;
for $i(1..100){
	/3{$i}/ and $j++;
	}
s/([a-z]+)(\d*?3{$j})/(push @M,$1) and "$1"."$2"/ieg;
# print; n();
# print "@M\n";

print "If you want to call a taxi, you should call: ",(join", ",@T),".\n";
print "If you want to order a pizza, you should call: ",(join", ",@P),".\n";
print "If you want to go to a cafe with a wonderful girl, you should call: ",(join", ",@M),".\n";

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

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

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

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

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

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

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

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

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

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

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

@_=<>;
chomp @_;
shift @_;

s/-//g for @_;

for (@_){
	if (/^\d{6}$/){
		@n=split//;
		$f=shift @n;
		$nT=$nP=0;
		for $i(@n){
			$f!=$i and $nT++;
			$i>=$f and $nP++;
			$f=$i;
			}
		$nT && $nP and $_=3;
		$nT && !$nP and $_=2;
		!$nT && $nP and $_=1;
		}

	}

# print "@_\n";

for (@_){
	s/^\d+ / /;
	}

$_=join"",@_;
# print; n();

while (/31|21|32/){
s/31/13/g;
s/21/12/g;
s/32/23/g;
}

$j=0;
for $i(1..100){
	/1{$i}/ and $j++;
	}
s/([a-z]+)(\d*?1{$j})/(push @T,$1) and "$1"."$2"/ieg;
# print; n();
# print "@T\n";

$j=0;
for $i(1..100){
	/2{$i}/ and $j++;
	}
s/([a-z]+)(\d*?2{$j})/(push @P,$1) and "$1"."$2"/ieg;
# print; n();
# print "@P\n";

$j=0;
for $i(1..100){
	/3{$i}/ and $j++;
	}
s/([a-z]+)(\d*?3{$j})/(push @M,$1) and "$1"."$2"/ieg;
# print; n();
# print "@M\n";

print "If you want to call a taxi, you should call: ",(join", ",@T),".\n";
print "If you want to order a pizza, you should call: ",(join", ",@P),".\n";
print "If you want to go to a cafe with a wonderful girl, you should call: ",(join", ",@M),".\n";

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

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

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

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

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

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

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

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

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

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

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

@_=<>;
chomp @_;
shift @_;

s/-//g for @_;

for (@_){
	if (/^\d{6}$/){
		@n=split//;
		$f=shift @n;
		$nT=$nP=0;
		for $i(@n){
			$f!=$i and $nT++;
			$i>=$f and $nP++;
			$f=$i;
			}
		$nT && $nP and $_=3;
		$nT && !$nP and $_=2;
		!$nT && $nP and $_=1;
		}

	}

# print "@_\n";

for (@_){
	s/^\d+ / /;
	}

$_=join"",@_;
# print; n();

s#\d+#join"",(sort (split//,$&))#eg;
# print; n();
$j=0;
for $i(1..100){
	/1{$i}/ and $j++;
	}
s/([a-z]+)(1{$j})/(push @T,$1) and "$1"/ieg;
# print; n();
# print "@T\n";
s/1//g;

$j=0;
for $i(1..100){
	/2{$i}/ and $j++;
	}
s/([a-z]+)(2{$j})/(push @P,$1) and "$1"/ieg;
# print; n();
# print "@P\n";
s/2//g;

$j=0;
for $i(1..100){
	/3{$i}/ and $j++;
	}
s/([a-z]+)(3{$j})/(push @M,$1) and "$1"/ieg;
# print; n();
# print "@M\n";
s/3//g;

print "If you want to call a taxi, you should call: ",(join", ",@T),".\n";
print "If you want to order a pizza, you should call: ",(join", ",@P),".\n";
print "If you want to go to a cafe with a wonderful girl, you should call: ",(join", ",@M),".\n";

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

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

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

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

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

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

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

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

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

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

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

@_=<>;
chomp @_;
shift @_;

s/-//g for @_;

for (@_){
	if (/^\d{6}$/){
		@n=split//;
		$f=shift @n;
		$nT=$nP=0;
		for $i(@n){
			$f!=$i and $nT++;
			$i>=$f and $nP++;
			$f=$i;
			}
		$nT && $nP and $_=3;
		$nT && !$nP and $_=2;
		!$nT && $nP and $_=1;
		}

	}

# print "@_\n";

for (@_){
	s/^\d+ / /;
	}

$_=join"",@_;
# print; n();

$j=0;
for $i(1..100){
	/1{$i}/ and $j++;
	}
s/([a-z]+)(\d*?1{$j})/(push @T,$1) and "$1"."$2"/ieg;
# print; n();
# print "@T\n";

$j=0;
for $i(1..100){
	/2{$i}/ and $j++;
	}
s/([a-z]+)(\d*?2{$j})/(push @P,$1) and "$1"."$2"/ieg;
# print; n();
# print "@P\n";

$j=0;
for $i(1..100){
	/3{$i}/ and $j++;
	}
s/([a-z]+)(\d*?3{$j})/(push @M,$1) and "$1"."$2"/ieg;
# print; n();
# print "@M\n";

print "If you want to call a taxi, you should call: ",(join", ",@T),".\n";
print "If you want to order a pizza, you should call: ",(join", ",@P),".\n";
print "If you want to go to a cafe with a wonderful girl, you should call: ",(join", ",@M),".\n";

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

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

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

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

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

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

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

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

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

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

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

@_=<>;
chomp @_;
shift @_;

s/-//g for @_;

for (@_){
	if (/^\d{6}$/){
		@n=split//;
		$f=shift @n;
		$nT=$nP=0;
		for $i(@n){
			$f!=$i and $nT++;
			$i>=$f and $nP++;
			$f=$i;
			}
		$nT && $nP and $_=3;
		$nT && !$nP and $_=2;
		!$nT && $nP and $_=1;
		}

	}

# print "@_\n";

for (@_){
	s/^\d+ / /;
	}

$_=join"",@_;
# print; n();

s#\d+#join"",(sort (split//,$&))#eg;
# print; n();
$j=0;
for $i(1..100){
	/1{$i}/ and $j++;
	}
s/([a-z]+)(1{$j})/(push @T,$1) and "$1"/ieg;
# print; n();
# print "@T\n";

$j=0;
for $i(1..100){
	/2{$i}/ and $j++;
	}
s/([a-z]+)(2{$j})/(push @P,$1) and "$1"/ieg;
# print; n();
# print "@P\n";

$j=0;
for $i(1..100){
	/3{$i}/ and $j++;
	}
s/([a-z]+)(3{$j})/(push @M,$1) and "$1"/ieg;
# print; n();
# print "@M\n";

print "If you want to call a taxi, you should call: ",(join", ",@T),".\n";
print "If you want to order a pizza, you should call: ",(join", ",@P),".\n";
print "If you want to go to a cafe with a wonderful girl, you should call: ",(join", ",@M),".\n";

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

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

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

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

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

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

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

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

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

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

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

@_=<>;
chomp @_;
shift @_;

s/-//g for @_;

for (@_){
	if (/^\d{6}$/){
		@n=split//;
		$f=shift @n;
		$nT=$nP=0;
		for $i(@n){
			$f!=$i and $nT++;
			$i>=$f and $nP++;
			$f=$i;
			}
		$nT && $nP and $_=3;
		$nT && !$nP and $_=2;
		!$nT && $nP and $_=1;
		}

	}

# print "@_\n";

for (@_){
	s/^\d+ //;
	}

$_=join"",@_;
# print; n();

$j=0;
for $i(1..100){
	/1{$i}/ and $j++;
	}
s/([a-z]+)(\d*?1{$j})/(push @T,$1) and "$1"."$2"/ieg;
# print; n();
# print "@T\n";

$j=0;
for $i(1..100){
	/2{$i}/ and $j++;
	}
s/([a-z]+)(\d*?2{$j})/(push @P,$1) and "$1"."$2"/ieg;
# print; n();
# print "@P\n";

$j=0;
for $i(1..100){
	/3{$i}/ and $j++;
	}
s/([a-z]+)(\d*?3{$j})/(push @M,$1) and "$1"."$2"/ieg;
# print; n();
# print "@M\n";

print "If you want to call a taxi, you should call: ",(join", ",@T),".\n";
print "If you want to order a pizza, you should call: ",(join", ",@P),".\n";
print "If you want to go to a cafe with a wonderful girl, you should call: ",(join", ",@M),".\n";

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

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

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

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

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

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

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

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

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

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


#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

$ats=0; $i=1;
<>;
while(<>){
	chomp;
	($a,$b)=split/ /;
	$b or push @_,$a;
	$b and ($ats+=$a,$i+=$b-1);
	}
@_=sort num @_;
while ($i--){$ats+=pop@_}
print $ats;

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

$ats=0; $i=1;
<>;
while(<>=~/ /){
	$'+0 or push @_,$`;
	$'+0 and ($ats+=$`,$i+=$'-1);
	}
@_=sort num @_;
while ($i--){$ats+=pop@_}
print $ats;

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

$ats=0; $i=1;
<>;
while(<>){
	chomp;
	($a,$b)=split/ /;
	$b? ($ats+=$a,$i+=$b-1):(push @_,$a);
	}
@_=sort {$a <=> $b} @_;
while ($i--){$ats+=pop@_}
print $ats;

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

$ats=0; $i=1;
<>;
while(<>){
	chomp;
	($a,$b)=split/ /;
	$b? ($ats+=$a,$i+=$b-1):(push @_,$a);
	}
@_=sort num @_;
while ($i--){$ats+=pop@_}
print $ats;

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

$ats=0; $i=1;
<>;
while(<>=~/ /){
	$'+0 or push @_,$`;
	$'+0 and ($ats+=$`,$i+=$');
	}
@_=sort num @_;
while ($i--){$ats+=pop@_}
print $ats;

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

$ats=0;
<>;
while(<>=~/ /){
	$'+0 or push @_,$`;
	$'+0 and ($ats+=$`,$i+=$');
	}
@_=sort num @_;
$i or $i++;
while ($i--){$ats+=pop@_}
print $ats;

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

<>;
while(<>=~/ /){
	$'+0 or push @_,$`;
	$'+0 and ($ats+=$`,$i+=$');
	}
@_=sort num @_;
while ($i--){$ats+=pop@_}
print $ats;

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


chomp($n=<>);
chomp($_=<>);
@a = split / /;
foreach (@a) {
	if ($_) {
		++$ans && !$flag && ++$ans;
		$flag = 1;
	} else {
		$flag = 0;
	}
}
print "0\n" if !$ans;
print $ans-1,"\n" if $ans;

#!/usr/bin/perl

my $n = <>;

my @mail = split / /, <>;

my $ans = 0;
my $reading = 0;
for $i (@mail) {
	if (($i == 1) || ($reading)) {
		$ans++;
	}
	$reading = $i;
};

if (($mail[-1] == 0) && ($ans > 0)) {
	$ans--;
};

print $ans;


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

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

	my %h;
	my $i;

	for ( 0 .. 1 ){
		$i = -1;
		map { $i ++; $h{ $_ }{ $_[ $i ] } ++ } split ' ', <>;
		}

	<>;

	my %g;
	my %i;

	for my $color ( 1 .. 3 ){
		@{ $g{ $color } } = sort { $a <=> $b } keys %{ $h{ $color } };
		$debug and print "@{ $g{ $color } }";
		for my $clr ( 1 .. 3 ){
			$i{ $color }{ $clr } = 0;
			}
		}

	my @ans;
	my $ans;

	for my $color ( split ' ', <> ){

		while( $g{ $color }->[ $i{ $color }{ $color } ] and
			$g{ $color }->[ $i{ $color }{ $color } ] =~ / / ){
			$i{ $color }{ $color } ++;
			}

		if( $g{ $color }->[ $i{ $color }{ $color } ] ){
			push @ans, $ans = $g{ $color }->[ $i{ $color }{ $color } ];
			$g{ $color }->[ $i{ $color }{ $color } ] .= ' ';
			$i{ $color }{ $color } ++;

			for my $clr ( 1 .. 3 ){
				next if $clr == $color;

				while( $g{ $clr }->[ $i{ $color }{ $clr } ] and
					$g{ $clr }->[ $i{ $color }{ $clr } ] < $ans ){
					$i{ $color }{ $clr } ++;
					}

				if( $g{ $clr }->[ $i{ $color }{ $clr } ] and
					$g{ $clr }->[ $i{ $color }{ $clr } ] == $ans ){
					$g{ $clr }->[ $i{ $color }{ $clr } ] .= ' ';
					$i{ $color }{ $clr } ++;
					last;
					}

				}

			}
		else {
			push @ans, -1;
			}

		}

	print "@ans";
	}