use strict;
use warnings;

my $input = <STDIN>;
my ($n, $m, $l) = map {$_+0} split / /, $input;
$input = <STDIN>;
my @hairs = map {$_+0} split / /, $input;
my @res = ();
my $counter = 0;
my $r = 0;
for my $i (0 .. $m - 1) {
    $input = <STDIN>;
    my @req = map {$_+0} (split(/ /, $input));
    if (scalar @req == 1 && $req[0] == 0) {
        unless (@res) {
            $r = f(\@hairs, $n, $l);
        }
        push @res, $r;
    } elsif (scalar @req == 3 && $req[0] == 1) {
        my $j = $req[1] - 1;
        my $d = $hairs[$j] + $req[2];
        if (scalar @res > 0 && $hairs[$j] <= $l && $d > $l) {
            if ($j == 0 && $n > 1 && $hairs[1] <= $l) {
                $r++;
            } elsif ($j == $n-1 && $n > 1 && $hairs[$n-2] <= $l) {
                $r++;
            } elsif ($j != $n-1 && $j != 0 && $hairs[$j-1] <= $l && $hairs[$j+1] <= $l) {
                $r++;
            } elsif ($j != $n-1 && $j != 0 && $hairs[$j-1] > $l && $hairs[$j+1] > $l) {
                $r--;
            } elsif ($n == 1) {
                $r++;
            }
        }
        $hairs[$req[1]-1] = $d;
    }
}

my $j = scalar @res;
for my $i (0..$j-1) {
    print $res[$i];
    print "\n" if $i != $j-1;
}

sub f {
    my $hairs = shift;
    my $n = shift;
    my $l = shift;
    my $counter = 0;
    my $flag = 0;
    for my $i (0..$n-1) {
        if ($hairs->[$i] > $l) {
            $flag = 1;
        } else {
            $counter++ if $flag == 1;
            $flag = 0;
        }
    }
    $counter++ if ($flag == 1);
    return $counter;
}

use strict;
use warnings;

my $input = <STDIN>;
my ($n, $m, $l) = map {$_+0} split / /, $input;
$input = <STDIN>;
my @hairs = map {$_+0} split / /, $input;
my @res = ();
for my $i (0 .. $m - 1) {
    $input = <STDIN>;
    my @req = map {$_+0} (split(/ /, $input));
    if (scalar @req == 1 && $req[0] == 0) {
        push @res, f(\@hairs, $n, $l);
    } elsif (scalar @req == 3 && $req[0] == 1) {
        $hairs[$req[1]-1] += $hairs[$req[2]];
    }
}

my $j = scalar @res;
for my $i (0..$j-1) {
    print $res[$i];
    print "\n" if $i != $j-1;
}

sub f {
    my $hairs = shift;
    my $n = shift;
    my $l = shift;
    my $counter = 0;
    my $flag = 0;
    for my $i (0..$n-1) {
        if ($hairs->[$i] > $l) {
            $flag = 1;
        } else {
            $counter++ if $flag == 1;
            $flag = 0;
        }
    }
    $counter++ if ($flag == 1);
    return $counter;
}

use strict;
use warnings;

my $input = <STDIN>;
my ($n, $m, $l) = map {$_+0} split / /, $input;
$input = <STDIN>;
my @hairs = map {$_+0} split / /, $input;
my @res = ();
my $counter = 0;
my $r = 0;
for my $i (0 .. $m - 1) {
    $input = <STDIN>;
    my @req = map {$_+0} (split(/ /, $input));
    if (scalar @req == 1 && $req[0] == 0) {
        unless (@res) {
            $r = f(\@hairs, $n, $l);
        }
        push @res, $r;
    } elsif (scalar @req == 3 && $req[0] == 1) {
        my $j = $req[1] - 1;
        my $d = $hairs[$j] + $req[2];
        if (scalar @res > 0 && $hairs[$j] <= $l && $d > $l) {
            if ($j == 0 && $n > 1 && $hairs[$j+1] <= $l) {
                $r++;
            } elsif ($j == $n-1 && $n > 1 && $hairs[$j-1] <= $l) {
                $r++;
            } elsif ($j != $n-1 && $j != 0 && $hairs[$j-1] <= $l && $hairs[$j+1] <= $l) {
                $r++;
            } elsif ($j != $n-1 && $j != 0 && $hairs[$j-1] > $l && $hairs[$j+1] > $l) {
                $r--;
            }
        }
        $hairs[$req[1]-1] = $d;
    }
}

my $j = scalar @res;
for my $i (0..$j-1) {
    print $res[$i];
    print "\n" if $i != $j-1;
}

sub f {
    my $hairs = shift;
    my $n = shift;
    my $l = shift;
    my $counter = 0;
    my $flag = 0;
    for my $i (0..$n-1) {
        if ($hairs->[$i] > $l) {
            $flag = 1;
        } else {
            $counter++ if $flag == 1;
            $flag = 0;
        }
    }
    $counter++ if ($flag == 1);
    return $counter;
}

use strict;
use warnings;

my $input = <STDIN>;
my ($n, $m, $l) = map {$_+0} split / /, $input;
$input = <STDIN>;
my @hairs = map {$_+0} split / /, $input;
my @res = ();
for my $i (0 .. $m - 1) {
    $input = <STDIN>;
    my @req = map {$_+0} (split(/ /, $input));
    if (scalar @req == 1) {
        push @res, f(\@hairs, $n, $l);
    } else {
        $hairs[$req[1]-1] += $hairs[$req[2]];
    }
}

my $j = scalar @res;
for my $i (0..$j-1) {
    print $res[$i];
    print "\n" if $i != $j-1;
}

sub f {
    my $hairs = shift;
    my $n = shift;
    my $l = shift;
    my $counter = 0;
    my $flag = 0;
    for my $i (0..$n-1) {
        if ($hairs->[$i] > $l) {
            $flag = 1;
        } else {
            $counter++ if $flag == 1;
            $flag = 0;
        }
    }
    $counter++ if ($flag == 1);
    return $counter;
}


use strict;
use warnings;
use List::Util qw(first max maxstr min minstr reduce shuffle sum);;
our $ans = 0;
my $n = <>;

my @elm = split / /,<>;
unshift @elm ,"www";
reet(@elm);
print $ans;
sub reet
{
    my @a = @_;
    my $i = $#a;
    if ($i <= 1)
    {
        return;
    }
    my @b = @a[0..($#a - 1)/2];
    while ($i > $#a/2)
    {
        #print "$i : ",$a[$i]," ";
        $b[($i - 1)/2] += max($a[$i], $a[$i - 1]);
        $ans += abs($a[$i] - $a[$i - 1]);
        $i -= 2;
    }

    reet(@b);
}

 #!perl

 $\ ="\n";

 sub count
 {
    my $link = shift;
    my @a = @{$link};

    if($#a == 1)
    {
        return @a;
    }
    else
    {
        my $first = shift @a;
        my $second = shift @a;

        my $p = ($#a + 1)/2 - 1;
        my @branch_1 = @a[0..$p];
        my @branch_2 = @a[($p + 1)..$#a];

        for my $i (@branch_1)
        {
            $i += $first;
        }

        for my $j (@branch_2)
        {
            $j += $second;
        }

        return (count(\@branch_1), count(\@branch_2));
    }
 }

 sub  find_answer
 {
    my $link = shift;
    my @a = @{$link};
    my $m = shift;

    if($#a == 1)
    {
        my $left = $m - @a[0];
        my $right = $m - @a[1];

        return $left > $right ? $left : $right;
    }
    else
    {
        my $first = shift @a;
        my $second = shift @a;

        my $p = ($#a + 1)/2 - 1;
        my @branch_1 = @a[0..$p];
        my @branch_2 = @a[($p + 1)..$#a];

        my $left = find_answer(\@branch_1, $m) - $first;
        my $right = find_answer(\@branch_2, $m) - $second;

        return $left + $right;
    }
 }

 $n = <>;
 @lamps = split / /, <>;

 @paths = count(\@lamps);

 $max = 0;
 for my $item (@paths)
 {
    $max = $item if $max < $item;
 }

 print find_answer(\@lamps, $max);


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

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

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

	my @k = partition( $k );

	my $k_re = join '', map { "0{0,$_}" } @k;

	$debug and print "k_re:[$k_re]";

	s/1 \K ( $k_re ) / "1" x length $1 /gex;

	$_ = reverse;

	s/1 \K ( $k_re ) / "1" x length $1 /gex;

	$_ = reverse;

	$debug and print "[$_]";

	my @free_rows = grep $_, map length, split /1+/, $_;

	$debug and print "free_rows[@free_rows]";

	my $ans = 0;

	for my $i ( @free_rows ){
		while( $i >= $k + 1 ){
			$ans ++;
			$i -= $k + 1;
			}
		$i and $ans ++;
		}

	print $ans;
	}

sub partition {
	my $i = shift;

	my @arr;
	my $max = 1e4;

	while( $i > $max ){
		push @arr, $max;
		$i -= $max;
		}

	$i > 0 and push @arr, $i;

	@arr;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

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

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

	my @k = partition( $k );

	my $k_re = join '|', map { "0{0,$_}" } @k;

	$debug and print "k_re:[$k_re]";

	s/1 \K ( $k_re ) / "1" x length $1 /gex;

	$_ = reverse;

	s/1 \K ( $k_re ) / "1" x length $1 /gex;

	$_ = reverse;

	$debug and print "[$_]";

	my @free_rows = grep $_, map length, split /1+/, $_;

	$debug and print "free_rows[@free_rows]";

	my $ans = 0;

	for my $i ( @free_rows ){
		while( $i >= $k + 1 ){
			$ans ++;
			$i -= $k + 1;
			}
		$i and $ans ++;
		}

	print $ans;
	}

sub partition {
	my $i = shift;

	my @arr;
	my $max = 1e4;

	while( $i > $max ){
		push @arr, $max;
		$i -= $max;
		}

	$i > 0 and push @arr, $i;

	@arr;
	}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	my( $n, $k ) = split;
	@_ = split ' ', <>;
	my $pre = $_[ 0 ];
	my $ok = 0;
	my $cnt = 0;

	for my $i ( 1 .. @_ - 1 ){
		my $new = $_[ $i ] > $pre ? $_[ $i ] : $pre;
		if( $pre == $new ){
			$cnt ++;
			}
		else{
			$cnt = 1;
			}
		$cnt == $k and do {
			$ok = 1;
			last;
			};
	#	print "  pre: $pre, new: $new";
		$pre = $new;
		}

	print $pre;
	}


#!/usr/bin/env perl

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

# essential
my @tokens = ();

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

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

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

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

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

# solve

read_token;
read_token;

my @a = split q{ }, read_line;
my @b = split q{ }, read_line;
my $length_of_a = @a;
my $length_of_b = @b;

my $q = read_line;

for (1..$q) {
    my $year = read_line;
    my $mod_of_a = $year % $length_of_a;
    my $mod_of_b = $year % $length_of_b;
    say "$a[$mod_of_a-1]$b[$mod_of_b-1]";
}


#!/usr/bin/perl
use strict;
use warnings;
my $n = <>;
chomp $n;
my $na = <>;
chomp $na;
my $nb = <>;
chomp $nb;

my $res = 0;

my @a = split(//, $na);
my @b = split(//, $nb);

for (my $i = 0; $i < $n; $i++) {
    my ($m, $M);
    my $c1 = abs($a[$i] - $b[$i]);
    my $c2 = 10 - $c1;
    if ($c1 < $c2) {
        $res += $c1;
    } else {
        $res += $c2;
    }
}

print "$res\n";

#!/usr/bin/perl
use strict;
use warnings;
sub min{
    return $_[0] < $_[1] ? $_[0] : $_[1];
}
my $n = <>;
my @src = split '',<>;
my @dest = split '',<>;
my $res = 0;
foreach my $i(0 .. $n-1){
    my $d = abs($src[$i] - $dest[$i]);
    $res += min($d, 10 - $d);
}
print $res;

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

sub abs {
	$a = shift;
	return $a>0 ? $a:-$a;
};

sub min {
	($a, $b) = (shift, shift);
	return $a<$b ? $a:$b;
};

chomp($len = <>);
chomp($l1 = <>);
chomp($l2 = <>);
$ans = 0;
foreach (0..$len-1) {
	($a, $b) = (substr($l1, $_, 1), substr($l2, $_, 1));
	$tmp = abs($a-$b);
	$ans += min($tmp, 10-$tmp);
}
say $ans;

#!perl

<>;
my @start_state = split //, <>;
my @combination = split //, <>;

my $answer = 0;
for my $i (0..$#start_state - 1)
{
    (my $x1, my $x2) = @start_state[$i] < @combination[$i] ? (@start_state[$i], @combination[$i]) : (@combination[$i], @start_state[$i]);
    my $a = $x2 - $x1;
    my $b = 9 - $x2 + $x1 + 1;
    $answer += $a < $b ? $a : $b;
}

print $answer, "\n";


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	@_ = map ord, split //;

	my $j = @_ - 1;

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

	substr $_, $j, 1, '';

	print;
	}


#!perl
use strict;
use warnings;

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

__END__

#!/usr/bin/perl

use strict;
use warnings;

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

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

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


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

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

}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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


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

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

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


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

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

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

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

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

#!/usr/bin/perl

use strict;
use warnings;

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

my @words;

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

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

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

#!/usr/bin/env perl

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

# essential
my @tokens = ();

my $n = read_token();

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

my $m = 0;

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

$answer .= 'it';

say $answer;

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

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

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

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

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

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


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

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

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

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

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

#! /usr/bin/env perl

use strict;
use warnings;

<>;
$_ = <>;

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

print $_;

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

#! /usr/bin/env perl

use strict;
use warnings;

<>;
$_ = <>;

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

print $_;

#! /usr/bin/env perl

use strict;
use warnings;

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

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

print $_;


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $sum = 0;

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

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

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

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

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

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

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $sum = 0;

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

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

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

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


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

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

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

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

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


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $sum = 0;

	$sum += $_ for @_;

	<>;

	my @ans;

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

	print for @ans;
	}


#!/usr/bin/perl

use 5.012;
use warnings;

chomp(my $stops = <>);

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

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

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

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

use strict;
use warnings;

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

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

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

    $current += $b;

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

print $max;

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

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

use strict;
use warnings;

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

print "$mx\n";

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

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

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

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

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

use warnings;
use strict;

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

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

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

print $out;

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

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


#!/usr/bin/perl -w

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

chomp ($piles, $juicy);

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

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

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

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

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

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

#!/usr/bin/perl -w

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

chomp ($piles, $juicy);

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

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

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

#!/usr/bin/perl -w

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

chomp ($piles, $juicy);

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

print "$piles: @psize\n";

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


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

#!/usr/bin/perl

use warnings;
use strict;

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

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

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

	$_ = <>, chomp;

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

	$debug and print "[@_]";

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

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

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

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

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

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

	$debug and print '-' x 10;
	}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my %h;

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

	my $is = $_;

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

	print "@ans";
	}

$x = <>;

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

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


$\ = $/;

<>;

while(<>){
	chomp;

	my %h;

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

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

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

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

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

	print for length $ans, $ans;
	}


#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

@_=split/ /,<>;

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

print $seroga, ' ', $dima;

1;


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

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


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

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

#!/usr/bin/env perl

use strict;
use warnings;

<>;

my %hash;

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

#!/usr/bin/env perl

use strict;
use warnings;

<>;

my %hash;

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


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

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

print $square;

#!/usr/bin/perl

use strict;
use warnings;

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

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

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

print $square;


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

while(<>){
	chomp;

	$debug and print '-' x 10;

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

	$debug and do {

		print "         $_ -> $B";

		$_ > 100 and next;

		my $c = 0;

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

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

			$c += ! $form;
			}

		print "$_ : $c";

		};

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


#!/usr/bin/env perl

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

chomp (my $line = <STDIN>);

my $q = $line;

for (1..$q) {
    chomp ($line = <STDIN>);
    my ($n, $r) = split q{ }, $line;
    chomp ($line = <STDIN>);
    my @monsters = split q{ }, $line;

    my $set = {};
    for (@monsters) {
        $set->{$_} = 1 if !defined $set->{$_};
    }

    @monsters = sort { $a <=> $b } keys %$set;

    my $answer = 0;
    my $i = @monsters-1;
    while ( $i >= 0 ) {
        if ( $monsters[$i] > $answer * $r ) {
            $answer++;
        }
        $i--;
    }

    say $answer;
}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $cnt = 0;

	while( @_ ){
		my $last = pop @_;
		if( @_ and $_[ @_ - 1 ] == $last ){
			next;
			}
		if( $last - $cnt * $r > 0 ){
			$cnt ++;
			}
		else{
			last;
			}
		}

	print $cnt;
	}

#!/usr/bin/env perl

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

chomp (my $line = <STDIN>);

my $q = $line;

for (1..$q) {
    chomp ($line = <STDIN>);
    my ($n, $r) = split q{ }, $line;
    chomp ($line = <STDIN>);
    my @monsters = split q{ }, $line;

    my $set = {};
    for (@monsters) {
        $set->{$_} = 1 if !defined $set->{$_};
    }

    @monsters = sort keys %$set;

    my $answer = 0;
    while ( @monsters ) {
        my $last = $monsters[-1];
        while ( @monsters && $monsters[-1] == $last ) {
            pop @monsters;
        }
        @monsters = grep { $_ > 0 } map { $_-1 } @monsters;
        $answer++;
    }
    say $answer;
}

#!/usr/bin/env perl

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

chomp (my $line = <STDIN>);

my $q = $line;

for (1..$q) {
    chomp ($line = <STDIN>);
    my ($n, $r) = split q{ }, $line;
    chomp ($line = <STDIN>);
    my @monsters = split q{ }, $line;

    my $set = {};
    for (@monsters) {
        $set->{$_} = 1 if !defined $set->{$_};
    }

    @monsters = sort keys %$set;

    my $answer = 0;
    while ( @monsters ) {
        my $last = $monsters[-1];
        while ( @monsters && $monsters[-1] == $last ) {
            pop @monsters;
        }
        @monsters = grep { $_ > 0 } map { $_-$r } @monsters;
        $answer++;
    }
    say $answer;
}

#!/usr/bin/env perl

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

chomp (my $line = <STDIN>);

my $q = $line;

for (1..$q) {
    chomp ($line = <STDIN>);
    my ($n, $r) = split q{ }, $line;
    $r++;
    chomp ($line = <STDIN>);
    my @monsters = split q{ }, $line;

    my $set = {};
    for (@monsters) {
        $set->{$_} = 1 if !defined $set->{$_};
    }

    @monsters = sort { $a <=> $b } keys %$set;

    my $answer = 0;
    my $i = 0;
    while ( $i < @monsters ) {
        if ( $r * $answer <= $monsters[$i] ) {
            pop @monsters;
            $answer++;
        }
        $i++;
    }
    say $answer;
}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	my $cnt = 0;

	while( @_ ){
		my $last = pop @_;
		if( $last - $cnt * $r > 0 ){
			$cnt ++;
			}
		else{
			last;
			}
		}

	print $cnt;
	}


import strict;
import warnings;

$_ = (<>, <>);
map {$me = $_; if($me >= $x){$k ++;}else{$k = 1;} if($k > $s) {$s = $k;} $x = $me; } split;

print "$s\n";

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

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

my $result = 1;
my $local_result = 1;

for (my $i = 1; $i < @numbers; $i++)
{
    if ($numbers[$i] >= $numbers[$i-1])
    {
        $local_result++;
    }
    else
    {
        $result = $local_result if $local_result > $result;
        $local_result = 1
    }
}
$result = $local_result if $local_result > $result;

say $result;

my $n = <>;
my @array = split ' ', <>;
my $last = shift @array;
my $c = 1;
my $max_c = 1;
while (my $a = shift @array) {
    if ($a < $last) {
      $max_c = $c if ($max_c < $c);
      $c = 1;
    }
    else {
      ++$c;
    }
    $last = $a;
}
$max_c = $c if ($max_c < $c);
print $max_c;

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

<>;
my @a = split ' ', <>;
my $len = 1;
my $maxlen = 1;
for my $i (1..$#a) {
    if ($a[$i - 1] <= $a[$i]) {
        $len++;
        $maxlen = $len if $len > $maxlen;
    } else {
        $len = 1;
    }
}
print "$maxlen\n";

#!/bin/perl

$n = <STDIN>;
$s = <STDIN>;

chomp $s;
@ciong = split / +/, $s;

$pop = 0;
$maks = 0;
$t = 0;

for($i=0;$i<$n;$i++)
{

  if(@ciong[$i] >= $pop)
  {

    $t++;

    if( $t > $maks )
    {

      $maks = $t;

    }

  }
  else
  {

    $t = 1;

  }

  $pop = @ciong[$i];

}

print $maks;

use strict;
use warnings;

my $n = <>;
my @all = split " ", <>;

$n = 2_000_000_000;
my ($len, $mx) = (0, 0);
for my $i (@all){
	if ($i >= $n){
		$n = $i;
		++$len;
	}
	else {
		$len = 1;
		$n = $i;
	}
	$mx = $len if $len > $mx;
}
print "$mx\n";

use strict;
use warnings;

my $n = <>;
my @all = split " ", <>;

$n = 2_000_000_000;
my ($len, $mx) = (0, 0);
for my $i (@all){
	if ($i >= $n){
		$n = $i;
		++$len;
		$mx = $len if $len > $mx;
	}
	else {
		$len = 1;
		$n = $i;
	}
}
print "$mx\n";

use strict;
use warnings;

my $n = <>;
my @all = split " ", <>;

$n = 2_000_000_000;
my ($len, $mx) = (0, 0);
for my $i (@all){
	if ($i >= $n){
		$n = $i;
		++$len;
		$mx = $len if $len > $mx;
	}
	else {
		$mx = $len if $len > $mx;
		$len = 1;
		$n = $i;
	}
}
print "$mx\n";


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

my ($n, $m) = map int, split /\D/, <>;
my @prices = map int, split /\D/, <>;
my %fruits;
for (1..$m) {
    my $fruit = <>;
    chomp $fruit;
    if (defined $fruits{$fruit}) {
	$fruits{$fruit}++;
    } else {
	$fruits{$fruit} = 1;
    }
}

@prices = sort { $a <=> $b } @prices;
my ($cmin, $cmax, $in, $ix) = (0, 0, 0, $#prices);
for my $key (sort { $fruits{$b} <=> $fruits{$a} } keys %fruits) {
    $cmin += $fruits{$key} * $prices[$in++];
    $cmax += $fruits{$key} * $prices[$ix--];
}

print "$cmin $cmax\n";


use bigint;

my $m, $n, $a, $b, $c;
my $i, $j;

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

my $g = $f;

if ( $f <= 2 ) {
    print "-1\n";}
elsif ( $g % 2 == 0 ) {		# n is even
    $g /= 2;
    $a = $g * $g + 1;
    $b = $g * $g - 1;
    print "$a $b\n";
}
else {				# n is odd
    my $var = ($g * $g + 1) / 2;
    my $uu = sqrt ( ($var * $var) - ($g * $g) );
    print "$var $uu\n";
}

my $m, $n, $a, $b, $c;
my $i, $j;
my $upper = int sqrt ( 10 ** 9 );

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

my $g = $f;
# every even number is will be the side of a pythagorean triple
if ( $f <= 2 ) {
    print "-1\n"; }
elsif ( $g % 2 == 0 ) {
    $a = $g * $g  + 1;
    $b = $g * $g - 1;
    print "$a $b\n";
}
else {

    for ( $i = 1; $i < $upper and (not $found); $i += 1 ) {
	for ( $j = $i + 1; $j < $upper and (not $found); $j += 1 ) {
	    $a = ($j ** 2) - ($i ** 2);
	    $b = 2 * $j * $i;
	    $c = ($j ** 2) + ($i ** 2);
	    if ( $a == $f or $b == $f or $c == $f ) {
		if ( $a != $f ) { print "$a ";}
		if ( $b != $f ) { print "$b ";}
		if ( $c != $f ) { print "$c ";}
		$found = 1;}
	}
    }

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


#!/usr/bin/perl -w

use strict;

chomp($_ = <>);
my ($n, $k) = split;
chomp($_ = <>);
my @a = split;
@a = sort { -($a <=> $b) } @a;
if ($k - 1 < $n) {
    my $res = $a[$k - 1];
    print "$res $res\n";
} else {
    print "-1\n";
}


#!/usr/bin/env perl

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

chomp (my $line = <STDIN>);

my $t = $line;
my @primes = (2, 3, 5, 7, 11);

TESTCASE:
for (1..$t) {
    chomp ($line = <STDIN>);
    my ($x, $y) = split q{ }, $line;

    my $z = $x - $y;

    if ( $z == 1 ) { say "no"; next TESTCASE; }
    else           { say "yes"; next TESTCASE; }
}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	print $x == $y + 1 ? "NO" : "YES";
	}


<>;
s/\B.{9,}\B/length$&/e, print for <>

#!/usr/bin/env perl

use strict;
use warnings;
use utf8;
use v5.20;

sub main {
    my %args = @_;

    my $lines = int(readline(STDIN)) || 0;

    while ($lines--) {
        my $world = readline(STDIN);
        $world =~ s/(?<=^\w).{9,}(?=\w$)/length $&/e;
        print $world;
    }

    return;
}

main();

exit;

chomp($num = <STDIN>);
while($num-- > 0) {
	chomp($word = <STDIN>);
	$l = length($word);
	if($l < 11) {
		print $word;
	} else {
		print substr($word, 0, 1).($l-2).substr($word, -1, 1);
	}
	print "\n";
}

use strict;
use warnings;

my $n = <>;
for (1..$n) {
	my $s = <>;
	chomp $s;
	my $len = length $s;
	if ($len > 10) {
		substr($s,1,-1) = $len-2;
	}
	print "$s\n";
}

#!/usr/bin/perl

chomp($n=<STDIN>);
while($n--)
{
chomp ($str=<STDIN>);
my @array = split(//,$str);
$c=$#array;
if ($c<10)
{
print "$str\n";}
else
{
$m=$c-1;
my $e= pop(@array);
$b= shift(@array);
print"$b";
print"$m";
print"$e\n";
}
}

#!/bin/perl
use strict;
use warnings;
my @chars = ();
my $line = '';

chomp (my $line_n = <>);
for (1..$line_n) {
    chomp($line = <>);
    if (length($line) >= 11) {
        @chars = $line =~ /./sg;
        $line = "$chars[0]" . (length($line)-2) . "$chars[-1]";
    }
    print "$line \n";
}

#!/bin/perl
use strict;
use warnings;
my @chars = ();
my $line = '';
my $l = 0;

chomp (my $line_n = <>);
for (1..$line_n) {
    chomp($line = <>);
    $l = length($line);
    if ($l >= 11) {
        @chars = $line =~ /./sg;
        $line = "$chars[0]" . ($l-2) . "$chars[-1]";
    }
    print "$line \n";
}

use strict;
use warnings;
chomp (my $line_n = <>);
my @chars = ();
my $i = 0;
my $line = '';
my @out = ();
my $l = 0;
for ($i=0; $i<$line_n; $i++) {
    chomp($line = <>);
    $l = length($line);
    if ($l < 11) {
        $out[$i] = $line;
    } else {
        @chars = $line =~ /./sg;
        $out[$i] = "$chars[0]" . ($l-2) . "$chars[-1]";
    }
}
foreach (@out) {print "$_ \n";}

<STDIN>; while(<STDIN>){chomp; if((our $len = length $_) <= 10){ print "$_\n"; }else{ print substr($_, 0, 1), $len-2, substr($_, -1, 1), "\n" } }

use strict;
use warnings;
use feature "say";

my $n = <STDIN>;

for ($_ = 0; $_ < $n; $_++)
{
    my $word = <STDIN>;
    chomp $word;
    my $len = length $word;
    if ($len > 10)
    {
        $word = substr($word, 0, 1) . ($len - 2) . substr($word, $len - 1, 1)
    }
    say $word;
}

use v5.20;

use warnings;
use strict;

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

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

	if(length $s > 10)
	{
		my $first = substr($s, 0, 1);
		my $last = substr($s, -1);
		my $length = (length $s) - 2;
		say "$first$length$last";
	}
	else
	{
		say "$s";
	}
}

#!/usr/bin/env perl

use v5.012;
use warnings;

chomp(my $count = <STDIN>);

while ($count--) {
	chomp(my $word = <STDIN>);
	if (length $word > 10) {
		$word =~ /^(.)(.*)(.)$/;
		$word = $1 . (length $2) . $3;
	}
	say $word;
}

use strict;
use warnings;

my $n = <STDIN>;

while($n-- > 0){
    my $s = <STDIN>;
    chomp($s);
    if(length($s) <= 10){
        print "$s\n";
    }else{
        print substr($s,0,1).(length($s)-2).substr($s,length($s)-1,1)."\n";
    }
}

#!/usr/bin/perl
$cases = <>; #number of cases
while($cases--){
    $myname=<>; #get input name
    $lengthofmyname=length($myname); #get its name
    $lengthofmyname = $lengthofmyname+0; #covt to num for being safe
    $maxlen=11; #maxlen permissible
    if($lengthofmyname>$maxlen){
        $first=substr($myname,0,1); #get first letter
        $last=substr($myname,$lengthofmyname-2,1); #get last letter
        $lengthofmyname=$lengthofmyname-3; #decr by 3 as it returns one extra
        print $first;
        print $lengthofmyname;
        print $last;
        print "\n";
    }
    else{
        print "$myname\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;

for (1..$n) {
    my $word = read_token;
    my $len = length $word;
    my $answer;
    if ($len > 10) {
        $answer = substr($word, 0, 1).($len-2).substr($word, $len-1, 1);
    }
    else {
        $answer = $word;
    }
    say $answer;
}

chomp($n = <STDIN>);
while($n--)
{
    chomp($word = <STDIN>);
    if (length($word) > 10)
    {
        $len = length($word) - 2;
        $word =~ s/(^.).+?(.$)/$1$len$2/;
        push @words, $word;
    }
    else
    {
        push @words, $word;
    }
}

foreach $word (@words)
{
    print "$word\n";
}

$n = <>;

for ($i = 0; $i < $n; ++$i) {
    $str = <>;
    chomp $str;
    $len = (length $str) - 2;
    $str = substr ($str, 0, 1) . "$len" . chop ($str) if $len > 8;
    print $str . "\n";
}

#!/usr/bin/perl;

$n = <STDIN>;

my @words;

for ($i = 0; $i < $n; $i++) {
	$m = <STDIN>;
	push(@words, $m);
}

for ($i = 0; $i < $n; $i++) {
	if (length(@words[$i]) < 12) {
		print(@words[$i]);
	} else {
		print(substr(@words[$i], 0, 1),(length(@words[$i]) - 3),substr(@words[$i], -2, 1),"\n");
	}
}

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

sub shorten
{ my $s = $_[0]; my $n = length($s) - 3;
  substr $s, 1, $n, $n if $n > 8; $s }

<STDIN>;
print shorten $_ while <STDIN>

#!/usr/bin/perl

$n = <>;

while($n--){
	$word = <>;

	$len = length($word) - 1;
	if($len <11){
		print "$word\n";
	}
	else{
		$mid = $len - 2;
		@chars = split("",$word);
		print "$chars[0]$mid$chars[$len-1]\n";
	}
}

my $n = <STDIN>;
while($n--) {
    my $s = <STDIN>;
    if((length($s) -1) > 10) {
        print substr($s, 0, 1).(length($s) - 3).substr($s, length($s) - 2, 1)."\n";
    }
    else {
        print $s;
    }
}

my $n = <STDIN>;
while($n--) {
    my $s = <STDIN>;
    chomp($s);
    if(length($s) > 10) {
        print substr($s, 0, 1).(length($s) - 2).substr($s, length($s) - 1, 1)."\n";
    }
    else {
        print $s."\n";
    }
}

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

chomp ($n = <>);
while ($n-- > 0) {
	chomp($line = <>);
	$len = length($line)-2;
	$line_ = substr($line, 0, 1) . "$len" . substr($line, $len+1, 1);
	$len<=8 and say $line or say $line_;
}

use strict;
use warnings;

my $input_lines = <>;
my @words;
for (1..$input_lines) {
    my $line = <>;
    chomp $line;
    push @words, $line;
}

my $max_len = 10;

for my $word (@words) {
    my $word_len = length($word);
    if ( $word_len > $max_len ) {
        print substr($word, 0, 1) . ($word_len-2) . substr($word, $word_len-1, 1) . "\n";
    } else {
        print "$word\n";
    }
}

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

my $i=<>;
while ($i--){
my $a=<>;
if(($b=length($a)-3)>8) {print substr($a,0,1),$b,substr($a,-2,1),"\n";} else {print "$a\n";}
}

use strict;
use warnings;

sub main
{
    my $input = <STDIN>;
    my @words;
    my $word;
    my $newWord="";
    my $wordLen;
    for(my $i=0;$i<$input;$i++){
        my $inputwords = <STDIN>;
        push @words, $inputwords;
    }
    for(my $i=0;$i<$input;$i++){
        $word = shift @words;
        $wordLen = length($word);
        if($wordLen-1>10){
            $wordLen=$wordLen-3;
            my $headword = substr($word,0,1);
            my $tailword = substr($word,length($word)-2,1);
            $newWord = $headword.$wordLen.$tailword;
            printf("$newWord\n");
        }
        else{
            printf("$word");
        }
    }
}

main();

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

<STDIN>;
for (<STDIN>) {
    chomp;
    s/^(.)(.+)(.)$/$1.length($2).$3/e if length > 10;
    say;
}

#!perl

my $num = <STDIN>;
for (1..$num) {
    my $word = <STDIN>;
    chomp $word;
    my @word = split //, $word;
    (@word > 10) ? print $word[0], @word - 2 , $word[-1],"\n" : print $word, "\n";
}

my $len = <STDIN>;

for my $val (1 .. $len) {
	my $word = <STDIN>;
	$word =~ s/\s//g;

	my $word_length = length $word;

	if ($word_length > 10) {
		my $f_let = substr $word, 0, 1;
		my $l_let = substr $word, $word_length - 1, 1;

		print $f_let.($word_length - 2).$l_let."\n";
	} else {
		print $word."\n";
	}
}

my $a = <>;
foreach (0 .. $a)
{
    my $str = <>;
    chomp $str;
    if (length $str <= 10) {
        print $str, "\n";
    } else {
        print substr ($str, 0, 1), (length $str) - 2, substr ($str, -1, 1), "\n";
    }
}

my $n = <>;
my $str;
my @arr;
for(1..$n) {
    $str = <>;
    chomp $str;
    @arr = split "", $str;
    $str =  $arr[0] . (scalar @arr-2) . $arr[-1] if (scalar @arr > 10);
    print $str . "\n";
}

$n = <STDIN>;
while($n != 0) {
	$s = <STDIN>;
	if(length($s) - 1 > 10) {
		print substr($s, 0, 1) . (length($s) - 3) . substr($s, length($s) - 2, 1) . "\n";
	} else {
		print "$s";
	}
	$n--;
}

# 4
# word
# localization
# internationalization
# pneumonoultramicroscopicsilicovolcanoconiosis

# Выходные данные

# word
# l10n
# i18n
# p43s

# Author Badhan Sen
# CSE-14, JUST

# 71A. Way Too Long Words
# Accepted

my $num=<>;

while($num--){
	my $str=<>;

	if(length($str)-1 > 10){
		print substr($str, 0, 1).(length($str)-3).substr($str, length($str)-2, 1);
		print "\n";
	}
	else{
		print $str;
		print "\n";
	}
}

#!/usr/bin/env perl

chomp(my $n = <STDIN>);

for ( 0..$n - 1 )
{
	chomp(my $word = <STDIN>);

	if ( length($word) > 10 )
	{
		$word = substr($word, 0, 1).(length($word) - 2).substr($word, length($word) - 1);

	}

	print("$word\n");

}

#!/usr/bin/env perl

use strict;
use warnings;
use utf8;
use v5.20;

sub main {
    my $lines = int(readline(STDIN)) || 0;

    while ($lines--) {
        my $word = readline(STDIN);
        chomp $word;
        say length $word <= 10
            ? $word
            : substr($word, 0, 1 ) . length(substr($word, 1, -1)) . substr($word,-1);
    }

    return;
}

main();

exit;

use strict;
use warnings;

sub main
{
    my $input = <STDIN>;
    my @words;
    my $word;
    my $newWord="";
    my $wordLen;
    for(my $i=0;$i<$input;$i++){
        my $inputwords = <STDIN>;
        push @words, $inputwords;
    }
    for(my $i=0;$i<$input;$i++){
        $word = shift @words;
        $wordLen = length($word);
        if($wordLen>10){
            $wordLen=$wordLen-3;
            my $headword = substr($word,0,1);
            my $tailword = substr($word,length($word)-2,1);
            $newWord = $headword.$wordLen.$tailword;
            printf("$newWord\n");
        }
        else{
            printf("$word");
        }
    }
}

main();

use strict;
use warnings;

my $n = <>;
for (1..$n) {
	my $s = <>;
	chomp $s;
	my $len = length $s;
	if ($len > 10) {
		substr($s,1,-2) = $len-2;
	}
	print "$s\n";
}

#!/usr/bin/perl

chomp($str=<STDIN>);
my @array = split(//,$str);
$c=$#array;
if ($c<=10)
{
print "$str\n";}
else
{
$m=$c-2;
my $e= pop(@array);
$b= shift(@array);
print"$b";
print"$m";
print"$e";
}

#!/usr/bin/perl

chomp($n=<STDIN>);
while($n--)
{
chomp ($str=<STDIN>);
my @array = split(//,$str);
$c=$#array;
if ($c<=10)
{
print "$str\n";}
else
{
$m=$c-2;
my $e= pop(@array);
$b= shift(@array);
print"$b";
print"$m";
print"$e\n";
}
}

#!/usr/bin/perl

chomp($n=<STDIN>);
while($n--)
{
chomp ($str=<STDIN>);
my @array = split(//,$str);
$c=$#array;
if ($c<=10)
{
print "$str\n";}
else
{
$m=$c-1;
my $e= pop(@array);
$b= shift(@array);
print"$b";
print"$m";
print"$e\n";
}
}

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

chomp (my $line_n = <>);
my @chars = ();
my $i = 0;
my $line = '';
my @out = ();
my $l = 0;
for ($i=0; $i<$line_n; $i++) {
    chomp($line = <>);
    $l = length($line);
    if ($l < 10) {
        $out[$i] = $line;
    } else {
        @chars = $line =~ /./sg;
        $out[$i] = "$chars[0]" . ($l-2) . "$chars[-1]";
    }
}
foreach (@out) {
    print "$_ \n";
}

<STDIN>; while(<STDIN>){chomp; if((our $len = length $_) <= 10){ print "$_\n"; }else{ print substr($_, 0, 1), $len, substr($_, -1, 1), "\n" } }

#!/usr/bin/perl
$inputlines=<>;
while($inputlines--){
    $word=<>;
    $len = length $word;
    if($len > 10){
        #then unpack them in array and print abbvr
        $len -=2;
        $first=substr($word,0,1);
        $last=substr($word,$len,1);
        $len=$len-1;
        print $first;
        print $len;
        print $last;
        print "\n";
    }
    else{
        print "$word\n";
    }
}

#!/usr/bin/perl
$inputlines=<>;
while($inputlines--){
    $word=<>;
    $len = length $word;
    if($len > 10){
        #then unpack them in array and print abbvr
        $len -=2;
        $first=substr($word,0,1);
        $last=substr($word,$len,1);
        print $first;
        print $len;
        print $last;
        print "\n";
    }
    else{
        print "$word\n";
    }
}

#!/usr/bin/perl;

$n = <STDIN>;

my @words;

for ($i = 0; $i < $n; $i++) {
	$m = <STDIN>;
	push(@words, $m);
}

for ($i = 0; $i < $n; $i++) {
	if (length(@words[$i]) < 11) {
		print(@words[$i]);
	} else {
		print(substr(@words[$i], 0, 1),(length(@words[$i]) - 3),substr(@words[$i], -2, 1),"\n");
	}
}

@in = <>;
$n = $in;
print $in;
print "\n";
print $n;
print "\n";
for($i = 1; $i < $n; $i++) {
    print $in[$i];
}

<>;
s/\B.{8,}\B/length$&/e, print for <>

#!perl

my $num = <STDIN>;
for (1..$num) {
    my $word = <STDIN>;
    chomp $word;
    my @word = split //, $word;
    (@word > 10) ? print $word[0] , length $word - 2 , $word[-1],"\n" : print $word, "\n";
}

use 5.020;

my $len = <>;
chomp $len;

while(<>) {
   chomp;
   next if length $_ <= $len;
   s/(.)(.+)(.)/$1 . length($2) . $3/e;
   say;
}

$n = <STDIN>;
while($n != 0) {
	$s = <STDIN>;
	if(length($s) > 10) {
		print substr($s, 0, 1) . (length($s) - 3) . substr($s, length($s) - 2, 1) . "\n";
	} else {
		print "$s";
	}
	$n--;
}

# 4
# word
# localization
# internationalization
# pneumonoultramicroscopicsilicovolcanoconiosis

# Выходные данные

# word
# l10n
# i18n
# p43s

#!/usr/bin/env perl

use strict;
use warnings;
use utf8;
use v5.20;

sub main {
    my %args = @_;

    my $lines = int(readline(STDIN)) || 0;

    while ($lines--) {
        my $world = readline(STDIN);
        $world =~ s/(?<=^\w).{6,}(?=\w$)/length $&/e;
        print $world;
    }

    return;
}

main();

exit;

my $n = <STDIN>;
while($n--) {
    my $s = <STDIN>;
    if((length($s) -1) >= 10) {
        print substr($s, 0, 1).(length($s) - 3).substr($s, length($s) - 2, 1);
    }
    else {
        print $s;
    }
}

my $n = <STDIN>;
while($n--) {
    my $s = <STDIN>;
    chomp($s);
    if(length($s) > 10) {
        print substr($s, 0, 1).(length($s) - 2).substr($s, length($s) - 1, 1)."\n";
    }
    else {
        print $s;
    }
}

my $n = <STDIN>;
while($n--) {
    my $s = <STDIN>;
    if((length($s) -1) >= 10) {
        print substr($s, 0, 1).(length($s) - 3).substr($s, length($s) - 2, 1)."\n";
    }
    else {
        print $s;
    }
}

use strict;
use warnings;

my $input_lines = <>;
my @words;
print "\n***\n";
for (1..$input_lines) {
    my $line = <>;
    chomp $line;
    push @words, $line;
}

my $max_len = 10;

for my $word (@words) {
    my $word_len = length($word);
    if ( $word_len > $max_len ) {
        print substr($word, 0, 1) . ($word_len-2) . substr($word, $word_len-1, 1) . "\n";
    } else {
        print "$word\n";
    }
}

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

my $i=<>;
while ($i--){
my $a=<>;
if(($b=length($a)-3)>7) {print substr($a,0,1),$b,substr($a,-2,1),"\n";} else {print "$a\n";}
}

#!/usr/bin/perl -w
use strict;
my $i=<>;
while ($i--){
my $a=<>;
if(($b=length($a)-3)>7) {print substr($a,0,1),$b,substr($a,-2,1);} else {print $a;}
}

#!/usr/bin/perl -w
use strict;
my $i=<>;
while ($i--){
my $a=<>;
if(($b=length($a)-2)>8) {print substr($a,0,1),$b,substr($a,-1,1);} else {print $a;}
}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $max = -~0;
	my $min = ~0;
	my $M;
	my $MM;

	for my $i ( 0 .. @A - 1 ){
		my $max = -~0;
		my $M;
		for my $j ( @A[ 0 .. $i - 1, $i + 1 .. @A - 1 ] ){
			for my $k ( @B ){
			#	print " $i $j $k";
				$max < $j * $k and do { $max = $j * $k; $M = "$j $k" };
				}
			}
		$min > $max and do { $min = $max; $MM = $M };
		}

	use bigint;
	print 0 + eval join ' * ', split ' ', $MM;
	no bigint;
	}

#!/usr/bin/perl

use warnings;
use strict;

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

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

	my $max = -~0;
	my $min = ~0;
	my $M;
	my @M;

	$debug and print "$max|$min";

	for my $i ( @A ){
		my $max = -~0;
		for my $j ( @B ){
			$debug and print " $i $j | ", $j * $i;
			$max < $j * $i and do { $max = $j * $i; $M = "$j $i" };
			}
		push @M, [ $max, $M ];
		}

	use bigint;
	print 0 + eval join ' * ', split ' ', join '', map $_->[ 1 ], ( sort { $a->[ 0 ] <=> $b->[ 0 ] } @M )[ -2 ];
	no bigint;
	}

#!/usr/bin/perl

use warnings;
use strict;

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

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

	my $max = -~0;
	my $min = ~0;
	my $M;
	my @M;

	$debug and print "$max|$min";

	for my $i ( @A ){
		my $max = -~0;
		for my $j ( @B ){
			$debug and print " $i $j | ", $j * $i;
			$max < $j * $i and do { $max = $j * $i; $M = "$j $i" };
			}
		push @M, [ $max, $M ];
		}

#	use bigint;
	print 0 + eval join ' * ', split ' ', join '', map $_->[ 1 ], ( sort { $a->[ 0 ] <=> $b->[ 0 ] } @M )[ -2 ];
#	no bigint;
	}

#!/usr/bin/perl

use warnings;

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

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

	my @M;

	for $i ( @A ){
		$max = -~0;
		for $j ( @B ){
			$max < $j * $i and $max = $j * $i;
			}
		push @M, $max;
		}

	print +( sort { $a <=> $b } @M )[ -2 ]
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $max = -~0;
	my $min = ~0;
	my $M;
	my $MM;

	for my $i ( 0 .. @A - 1 ){
		my $max = -~0;
		my $M;
		for my $j ( @A[ 0 .. $i - 1, $i + 1 .. @A - 1 ] ){
			for my $k ( @B ){
				print " $i $j $k";
				$max < $j * $k and do { $max = $j * $k; $M = "$j $k" };
				}
			}
		$min > $max and do { $min = $max; $MM = $M };
		}

	use bigint;
	print 0 + eval join ' * ', split ' ', $MM;
	no bigint;
	}


#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

$n=<>;
while(<>=~/ /)
{
	$` and $i++;
	$'+0 and $j++;
	}
print (min($i,$n-$i)+min($j,$n-$j));

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

$n=<>;
while(<>=~/ /)
{
	$` and $i++;
	$' and $j++;
	}
print (min($i,$n-$i)+min($j,$n-$j));

#***********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 Data::Dumper;
use integer;   ### important!
my $mod = 10 ** 9 + 7;
# my $mod = 998244353;

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

while( $testcase -- > 0 ){

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

  my @a = ( ($n) , ( 1 .. ($n-1) ));
  print ( join(' ',@a) . "\n" );

}

exit(0);

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


#!/usr/bin/perl

use warnings;
use strict;

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

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

	my $x = 'x' x $n;

	@_ = split ' ', <>;

	substr $x, $_ - 1, 1, 'o' for @_;

	$debug and print $x;

	my $i = 1;

	while( $x =~ /x/ ){
		$x =~ s/x(?=o)|(?<=o)x/o/g;
		$debug and print " $x";
		$i ++;
		}

	print $i;
	}


my $n = int<>;
my @ans;
(scalar(() = <> =~ / 1|3/) == 0) and push @ans, $_ for(1..$n);
print scalar @ans;
print "\n@ans\n";


#!/usr/bin/perl

use warnings;
use strict;

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

while(<>){
	chomp;
	print;

	my %h = map { $_ => 1 } split ' ';

	for ( 1 .. <> ){
		@_ = split ' ', <>;
		exists $h{ $_ } ? delete $h{ $_ } : ($h{ $_ } = 1) for @_;

		print join ' ', keys %h;
		}

	$debug and print '-' x 10;
	}

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

my $line = <>;
chomp($line);
my @init_pot = split (" ", $line);
print "$init_pot[0] $init_pot[1]\n";
my $num = <>;
chomp($num);

for (my $i=0;$i < $num;$i++) {
        my $line = <>;
        chomp($line);
        my @pot = split (" ", $line);
        if ($init_pot [0] eq $pot[0]) {
                $init_pot[0] = $pot[1];
        } elsif ($init_pot [1] eq $pot[0]) {
                $init_pot[1] = $pot[1];
        }

print "$init_pot[0] $init_pot[1]\n";
}


$ch=<>;
chomp$ch;
$pos=index($ch,'.');

if(substr($ch,$pos-1,1) eq "9"){
print "GOTO Vasilisa.";
}
elsif(substr($ch,$pos+1,1) lt "5"){
print substr($ch,0,$pos);
}
else{
$car=substr($ch,$pos-1,1)+1;
$res= substr($ch,0,$pos-1).$car;
print $res;

}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

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

	my @C;

	while( @A ){
		push @C, [ ( pop @A ), ( pop @B ) ];
		}

	@C = sort { $a->[ 0 ] <=> $b->[ 0 ] } @C;

	while( @C and $C[ 0 ][ 0 ] <= $k ){
		my $c = shift @C;

		$k += $c->[ 1 ];
		}

	print $k;
	}


#!/usr/bin/perl

use warnings;
use strict;

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

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

	@_ = ();

	for ( map ~~<>, 1 .. $n ){
		my $i = 0;
		map { $_[ $i ++ ] .= $_ } split;
		}

	$debug and print for @_;
	@_ = grep m/1/, @_;
	my $ex = 0;
	my $lf = 0;

	for ( @_ ){
		my $_1 = 0;
		my $max = 0;
		my $max_id = -1;
		my @A = ();
		my $shift = 0;

		while( /(.)/g ){
			$_1 += $1;
			push @A, $1;
			if( @A > $k ){
				$_1 -= shift @A;
				$shift ++;
				}
			$debug and print "[@A]|$_1";
			$max < $_1 and $max_id = $shift;
			$max < $_1 and $max = $_1;
			}

		$debug and print $max;
		$debug and print $max_id;

		s/.{$max_id}//;
		$ex += () = $& =~ /1/g;
		s/.{1,$k}//;
		$lf += () = $& =~ /1/g;
		}

	print "$lf $ex";
	$debug and print '-' x 20;
	}


#!/usr/bin/perl
use strict;
use warnings;
chomp(my $n = <>);
my $ans = 0;
my $hashKeyCount;
my %h;
chomp(my $line = <>);
my @socks = split(/ /,$line);
foreach(@socks){
        if(defined $h{$_}){
                delete $h{$_};
        }else{
                $h{$_} = 1;
                $hashKeyCount = keys %h;
                $ans = $hashKeyCount > $ans ? $hashKeyCount : $ans;
        }
}
print "$ans\n";

#!/usr/bin/perl
use strict;
use warnings;
chomp(my $n = <>);
my $ans = 0;
my $tableCount = 0;
my %h;
chomp(my $line = <>);
my @socks = split(/ /,$line);
foreach(@socks){
	if(defined $h{$_}){
		if($tableCount > $ans){
			$ans = $tableCount;
			$tableCount -= 1;
		}
	}else{
		$h{$_} = 1;
		$tableCount++;
	}
}
print "$ans\n";


use warnings; use strict;
my $n = scalar <> + 0;
my @aa = split ' ', scalar <>; $_ += 0 foreach @aa;
@aa == $n or die "err";
my @m = <>;
@m == $n or die "err";
foreach (@m){ chomp; $_ = [ split '', $_ ];  foreach (@$_) { $_ += 0; } @$_ == $n or die "err"; }
my @used = (0) x $n;
my @comp = ();
my @cc = ();
sub dfs{ my $i = shift;
    return if $used[$i];
    $used[$i] = 1; push @cc, $i;
    foreach (0 .. ($n-1)) {
        dfs($_) if $m[$i][$_] == 1 || $m[$_][$i] == 1;
        }
    }
sub numeric {$a <=> $b}
foreach (0 .. ($n-1)){
    dfs($_);
    #print join(' ', @cc), "\n";
    push @comp, [sort numeric @cc] if @cc;
    @cc = ();
    }
foreach (@comp){
    #print join(' ', @$), "\n";
    @aa[@$_] = sort numeric @aa[@$_];
    }
print join ' ', @aa;
print "\n";

use warnings; use strict;
my $n = scalar <> + 0;
my @a = split ' ', scalar <>; $_ += 0 foreach @a;
@a == $n or die "err";
my @m = <>;
@m == $n or die "err";
foreach (@m){ chomp; $_ = [ split '', $_ ];  foreach (@$_) { $_ += 0; } @$_ == $n or die "err"; }
my @used = (0) x $n;
my @comp = ();
my @cc = ();
sub dfs{ my $i = shift;
    return if $used[$i];
    $used[$i] = 1; push @cc, $i;
    foreach (0 .. ($n-1)) {
        dfs($_) if $m[$i][$_] || $m[$_][$i];
        }
    }
foreach (0 .. ($n-1)){
    dfs($_);
    push @comp, [sort @cc] if @cc;
    @cc = ();
    }
@a[@$_] = sort @a[@$_] foreach (@comp);
print join ' ', @a;
print "\n";

use warnings; use strict;
my $n = scalar <> + 0;
my @a = split ' ', scalar <>; $_ += 0 foreach @a;
@a == $n or die "err";
my @m = <>;
@m == $n or die "err";
foreach (@m){ chomp; $_ = [ split '', $_ ];  foreach (@$_) { $_ += 0; } }
my @used = (0) x $n;
my @comp = ();
my @cc = ();
sub dfs{ my $i = shift;
    return if $used[$i];
    $used[$i] = 1; push @cc, $i;
    foreach (0 .. ($n-1)) {
        dfs($_) if $m[$i][$_];
        }
    }
foreach (0 .. ($n-1)){
    dfs($_);
    push @comp, [sort @cc] if @cc;
    @cc = ();
    }
@a[@$_] = sort @a[@$_] foreach (@comp);
print join ' ', @a;
print "\n";

use warnings; use strict;
my $n = scalar <> + 0;
my @a = split ' ', scalar <>; $_ += 0 foreach @a;
@a == $n or die "err";
my @m = <>;
@m == $n or die "err";
foreach (@m){ chomp; $_ = [ split '', $_ ];  foreach (@$_) { $_ += 0; } @$_ == $n or die "err"; }
my @used = (0) x $n;
my @comp = ();
my @cc = ();
sub dfs{ my $i = shift;
    return if $used[$i];
    $used[$i] = 1; push @cc, $i;
    foreach (0 .. ($n-1)) {
        dfs($_) if $m[$i][$_] == 1 || $m[$_][$i] == 1;
        }
    }
foreach (0 .. ($n-1)){
    dfs($_);
    print join(' ', @cc), "\n";
    push @comp, [sort {$a <=> $b} @cc] if @cc;
    @cc = ();
    }
foreach (@comp){
    print join(' ', @$), "\n";
    @a[@$_] = sort @a[@$_];
    }
print join ' ', @a;
print "\n";

use warnings; use strict;
my $n = scalar <> + 0;
my @aa = split ' ', scalar <>; $_ += 0 foreach @aa;
@aa == $n or die "err";
my @m = <>;
@m == $n or die "err";
foreach (@m){ chomp; $_ = [ split '', $_ ];  foreach (@$_) { $_ += 0; } @$_ == $n or die "err"; }
my @used = (0) x $n;
my @comp = ();
my @cc = ();
sub dfs{ my $i = shift;
    return if $used[$i];
    $used[$i] = 1; push @cc, $i;
    foreach (0 .. ($n-1)) {
        dfs($_) if $m[$i][$_] == 1 || $m[$_][$i] == 1;
        }
    }
foreach (0 .. ($n-1)){
    dfs($_);
    #print join(' ', @cc), "\n";
    push @comp, [sort {$a <=> $b} @cc] if @cc;
    @cc = ();
    }
foreach (@comp){
    #print join(' ', @$), "\n";
    @aa[@$_] = sort @aa[@$_];
    }
print join ' ', @aa;
print "\n";

use warnings; use strict;
my $n = scalar <> + 0;
my @a = split ' ', scalar <>; $_ += 0 foreach @a;
my @m = <>; $#m = $n-1;
foreach (@m){ chomp; $_ = [ split '', $_ ];  foreach (@$_) { $_ += 0; } }
my @used = (0) x $n;
my @comp = ();
my @cc = ();
sub dfs{ my $i = shift;
    return if $used[$i];
    $used[$i] = 1; push @cc, $i;
    foreach (0 .. ($n-1)) {
        dfs($_) if $m[$i][$_] || $m[$i][$_];
        }
    }
foreach (0 .. ($n-1)){
    dfs($_);
    push @comp, [sort @cc] if @cc;
    @cc = ();
    }
@a[@$_] = sort @a[@$_] foreach (@comp);
print join ' ', @a;
print "\n";


=item
797 B

You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.

Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

You should write a program which finds sum of the best subsequence.
Input

The first line contains integer number n (1 ≤ n ≤ 105).

The second line contains n integer numbers a1, a2, ..., an ( - 104 ≤ ai ≤ 104). The sequence contains at least one subsequence with odd sum.
Output

Print sum of resulting subseqeuence.
Examples
Input

4
-2 2 -3 1

Output

3

Input

3
2 -5 -3

Output

-1
=cut

my $n=<>;
chomp $n;
my @vs=split(' ',<>);
# print "# $n : ",join('|',@vs),"\n";

my @ps;
my @ns;

my $spos=0;
for(my $i=0;$i<$n;++$i) {
  my $v=$vs[$i];
  if($v>0) {
    push @ps,$v;
    $spos+=$v;
  } else {
    push @ns,$v;
  }
}
if(($spos%2)==1) {
  print "$spos\n";
  exit();
}
# print "# spos=$spos : ps=@ps : ns=@ns\n";
@ops=sort {$a-$b} grep {$_%2==1} @ps;
@ons=sort {$a-$b} grep {$_%2==1} @ns;
# print "# ops=@ops : ons=@ons\n";

my $mp=scalar(@ops)>0 ? $ops[0] : 1e20;
my $mn=scalar(@ons)>0 ? -$ons[-1] : 1e20;

$m=($mp<$mn ? $mp : $mn);
# print "# mp=$mp mn=$mn m=$m\n";
$spos-=$m;
print "$spos\n";

=item
797 B

You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.

Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

You should write a program which finds sum of the best subsequence.
Input

The first line contains integer number n (1 ≤ n ≤ 105).

The second line contains n integer numbers a1, a2, ..., an ( - 104 ≤ ai ≤ 104). The sequence contains at least one subsequence with odd sum.
Output

Print sum of resulting subseqeuence.
Examples
Input

4
-2 2 -3 1

Output

3

Input

3
2 -5 -3

Output

-1
=cut

my $n=<>;
chomp $n;
my @vs=split(' ',<>);
# print "# $n : ",join('|',@vs),"\n";

my @ps;
my @ns;

my $spos=0;
for(my $i=0;$i<$n;++$i) {
  my $v=$vs[$i];
  if($v>0) {
    push @ps,$v;
    $spos+=$v;
  } else {
    push @ns,$v;
  }
}
if($spos % 2 ==1) {
  print "$spos\n";
  exit();
}
# print "# spos=$spos : ps=@ps : ns=@ns\n";
@ops=sort {$a-$b} grep {$_%2==1} @ps;
@ons=sort {$a-$b} grep {$_%2==1} @ns;
# print "# ops=@ops : ons=@ons\n";

my $mp=scalar(@ops)>0 ? $ops[0] : 0;
my $mn=scalar(@ons)>0 ? -$ons[-1] : 0;

$m=((0<$mp and $mp<$mn) ? $mp : $mn);
# print "# mp=$mp mn=$mn m=$m\n";
$spos-=$m;
print "$spos\n";

=item
797 B

You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.

Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

You should write a program which finds sum of the best subsequence.
Input

The first line contains integer number n (1 ≤ n ≤ 105).

The second line contains n integer numbers a1, a2, ..., an ( - 104 ≤ ai ≤ 104). The sequence contains at least one subsequence with odd sum.
Output

Print sum of resulting subseqeuence.
Examples
Input

4
-2 2 -3 1

Output

3

Input

3
2 -5 -3

Output

-1
=cut

my $n=<>;
chomp $n;
my @vs=split(' ',<>);
print "# $n : ",join('|',@vs),"\n";

my @ps;
my @ns;

my $spos=0;
for(my $i=0;$i<$n;++$i) {
  my $v=$vs[$i];
  if($v>0) {
    push @ps,$v;
    $spos+=$v;
  } else {
    push @ns,$v;
  }
}
if($spos % 2 ==1) {
  print "$spos\n";
  exit();
}
print "# spos=$spos : ps=@ps : ns=@ns\n";
@ops=sort {$a-$b} grep {$_%2==1} @ps;
@ons=sort {$a-$b} grep {$_%2==1} @ns;
print "# ops=@ops : ons=@ons\n";

my $mp=scalar(@ops)>0 ? $ops[0] : 0;
my $mn=scalar(@ons)>0 ? -$ons[-1] : 0;

$m=((0<$mp and $mp<$mn) ? $mp : $mn);
print "# mp=$mp mn=$mn m=$m\n";
$spos-=$m;
print "$spos\n";

=item
797 B

You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.

Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

You should write a program which finds sum of the best subsequence.
Input

The first line contains integer number n (1 ≤ n ≤ 105).

The second line contains n integer numbers a1, a2, ..., an ( - 104 ≤ ai ≤ 104). The sequence contains at least one subsequence with odd sum.
Output

Print sum of resulting subseqeuence.
Examples
Input

4
-2 2 -3 1

Output

3

Input

3
2 -5 -3

Output

-1
=cut

my $n=<>;
chomp $n;
my @vs=split(' ',<>);
print "# $n : ",join('|',@vs),"\n";

my $m=-1e20;
for(my $i=0;$i<$n;++$i) {
  my $s=0;
  for(my $j=$i;$j<$n;++$j) {
    $s+=$vs[$j];
    if($s % 2 == 1 and $s>$m) {
      $m=$s;
    }
  }
}
print "$m\n";


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	print 1 - <> ? 'NO' : 'YES';
	}