use warnings;
use strict;
use integer;
$\ = qq/\n/, $, = qq/ / ;
my $n = <STDIN>;
my @arr = sort { $a <=> $b } split qq/ /, <STDIN>;
my $black = 0;
for ( my $ii = 0; $ii < ( $n / 2 ); $ii += 1 ) {
    $black += abs ( $arr [ $ii ] - ( 1 + ( 2 * $ii ) ) )
}
my $white = 0;
for ( my $ii = 0; $ii < ( $n / 2 ); $ii += 1 ) {
    $white += abs ( $arr [ $ii ] - ( 2 + ( 2 * $ii ) ) )
}
print ( $black > $white ? $white : $black );

use warnings;
use strict;
$, = q/ /, $\ = qq/\n/;
my ( $n, $m ) = split q/ /, <STDIN>;
my @a = ();
for ( 1 .. $n ) {
    chomp ( my $s = [ split q//, <STDIN> ] );
    push @a, $s;
}
my %lamp_to_switch = ();
for my $i ( 0 .. ($n - 1) ) {
    my $bl = 1;
    for my $j ( 0 .. ($m - 1) ) {
        if ( $a[$i][$j] eq '1' ) {
            if ( not exists $lamp_to_switch { $j + 1} ) {
                $lamp_to_switch { $i + 1 } -> { $j + 1 } = 1;
                $bl = 0;
            }
        }
    }
    if ( $bl ) {
        print "YES";
        exit;
    }
}
print "NO";
exit;

use warnings;
use strict;
use integer;
$\ = qq/\n/, $, = qq/ / ;
my $n = <STDIN>;
my @arr = split qq/ /, <STDIN>;
my $sum = 0;
for ( my $ii = 0; $ii < ( $n / 2 ); $ii += 1 ) {
    $sum += abs ( $arr [ $ii ] - ( 1 + ( 2 * $ii ) ) )
}
print $sum;

use warnings;
use strict;
use integer;
$\ = qq/\n/, $, = qq/ / ;
my $n = <STDIN>;
my @arr = sort { $a <=> $b } split qq/ /, <STDIN>;
my $black = 0;
for ( my $ii = 0; $ii < ( $n / 2 ); $ii += 1 ) {
    $black += abs ( $arr [ $ii ] - ( 1 + ( 2 * $ii ) ) )
}
my $white = 0;
for ( my $ii = 0; $ii < ( $n / 2 ); $ii += 1 ) {
    $white += abs ( $arr [ $ii ] - ( 2 + ( 2 * $ii ) ) )
}
print qq/white $white/;
print qq/black $black/;

print ( $black > $white ? $white : $black );

use warnings;
use strict;
use integer;
$\ = qq/\n/, $, = qq/ / ;
my $n = <STDIN>;
my @arr = split qq/ /, <STDIN>;
my $black = 0;
for ( my $ii = 0; $ii < ( $n / 2 ); $ii += 1 ) {
    $black += abs ( $arr [ $ii ] - ( 1 + ( 2 * $ii ) ) )
}
my $white = 0;
for ( my $ii = 0; $ii < ( $n / 2 ); $ii += 1 ) {
    $white += abs ( $arr [ $ii ] - ( 2 + ( 2 * $ii ) ) )
}
print ( $black > $white ? $white : $black );


my $n = <STDIN>;
my $loop = 1;

sub itr {
    my $x = shift;
    my $y = shift;
    my $i = shift;
    $loop++;
    my $sum;
    if($i){
        $sum = $i*($i+1)/2;
        $i++;
    }else{
        $i = 2;
        $sum = 1;
    }
    for($i; $sum<$y; $i++){
        $sum += $i;
    }

    #print "$x, $y, $i, $sum, $loop \n";
    if($sum == $y){
        print "YES";
    }
    elsif($x > $y){
        print  "NO";
    }
    elsif($sum > $y){
        &itr($x + $loop, $y - $loop, $i-2);
    }
}
&itr(1, $n-1, 0);

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

my $n = <>;
my $s = int ((sqrt $n) + 1) * 2;
my %tri = ();
my $i = 1;
my $result;
find: while ($i <= $s) {
	my $num = ($i * ($i + 1)) / 2;
	$tri{$num} = 1;
	if ($tri{$n-$num}) {
		$result = "YES";
		last find;
	} else {
		$i++;
	}
}
$result ||= "NO";
print $result;

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

my $n = <>;
my $s = int (sqrt $n) + 1;
my %tri = ();
my $i = 1;
my $result;
find: while ($i <= $s) {
	my $num = ($i * ($i + 1)) / 2;
	$tri{$num} = 1;
	if ($tri{$n-$num}) {
		$result = "YES";
		last find;
	} else {
		$i++;
	}
}
$result ||= "NO";
print $result;


use Data::Dumper;

my ($n, @lengths) = split ' ', <>;
my @cuts;
$cuts[0] = 0;

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

$\ = "\n";
$, = " ";
for my $l (1..$n) {
    for my $k (keys %lengths) {
        next unless $l >= $k && defined $cuts[$l - $k];
        my $can = $cuts[$l - $k] + 1;
        $cuts[$l] = $can if $can > $cuts[$l];
    }
}

print "$cuts[$n]\n";

#!/usr/bin/perl
sub cut {
    my $n = shift;
    my $a = shift;
    my $b = shift;
    my $c = shift;
    my @hash;
    $hash[0] = 1;
    $hash[$n] = 1;
    for ($key = 0; $key < $n; $key++)   {
        if ($hash[$key] > 0) {
            foreach $elem (($a,$b,$c)) {
                my $next = $key + $elem;
                $hash[$next] = $hash[$next] > $hash[$key] + 1 ? $hash[$next] : $hash[$key] + 1;
            }
        }
    }
    return $hash[$n] - 1;
}
while(<>) {
    my @arr = split;
    my $n = $arr[0];
    my $a = $arr[1];
    my $b = $arr[2];
    my $c = $arr[3];
    print cut($n,$a,$b, $c);
}


#!perl -w

use strict;

chomp ( my $n = <STDIN> ) ;
my @apples = split /\s+/s , <STDIN>;
my @apple200 = grep{$_ == 200} @apples;
my @apple100 = grep{$_ == 100} @apples;
my $apple200d2  = @apple200 % 2 ;
my $apple100minfill = $apple200d2 ? @apple100 - 2 : @apple100 ;
if($apple100minfill < 0){
    print "NO\n";
}elsif($apple100minfill % 2){
    print "NO\n";
}else{
    print "YES\n";
}


use strict;

use List::Util qw(first max maxstr min minstr reduce shuffle sum);
<>;
my @input = split //, <>;
my $h=1;
my @ar;
for (@input)
{
    push @ar, (Er(fact($_)));
}

my $p ={
2 =>"2",
3 =>"23",
5 =>"22235",
7 =>"22223357"
};
@ar = reverse sort @ar;
my @s = @ar;
my @d;
until($#s == -1)
{
    push @d , $s[0];
    @s = Reject(@s,$p->{$s[0]});
}
print @d;

sub Reject(\@$)
{
    my @a;
    my @d = split //, pop;
    @a = @_;
    g:for my $p (@d)
    {
        for (@a)
        {
            if ($p == $_)
            {
                $_ = 0;
                next g;
            }
        }
    }
    return (grep {$_ != 0} @a);
};

sub Er
{
    my $n=shift;
    my @ans;

    for(2..$n)
    {
        until($n % $_)
        {
            push @ans, $_;
            $n /=$_;
        }
    }

    return @ans;
};
sub nod
 {
 return  $_[0] != 0  ?  nod ( ( $_[1] % $_[0] ), $_[0] )  :  $_[1];
 };

sub fact()
{
    my $n = shift;
    my $s = 1;
    for (1..$n)
    {
     $s*=$_;
    }
    return $s;

}

use strict;
use warnings;
use List::Util qw(reduce);
print "5\n";

use strict;

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

my @input = split //, <>;
my $h=1;
my @ar;
for (@input)
{
    push @ar, (Er(fact($_)));
}

my $p ={
2 =>"2",
3 =>"23",
5 =>"22235",
7 =>"22223357"
};
@ar = reverse sort @ar;
my @s = @ar;
my @d;
until($#s == -1)
{
    push @d , $s[0];
    @s = Reject(@s,$p->{$s[0]});
}
print @d;

sub Reject(\@$)
{
    my @a;
    my @d = split //, pop;
    @a = @_;
    g:for my $p (@d)
    {
        for (@a)
        {
            if ($p == $_)
            {
                $_ = 0;
                next g;
            }
        }
    }
    return (grep {$_ != 0} @a);
};

sub Er
{
    my $n=shift;
    my @ans;

    for(2..$n)
    {
        until($n % $_)
        {
            push @ans, $_;
            $n /=$_;
        }
    }

    return @ans;
};
sub nod
 {
 return  $_[0] != 0  ?  nod ( ( $_[1] % $_[0] ), $_[0] )  :  $_[1];
 };

sub fact()
{
    my $n = shift;
    my $s = 1;
    for (1..$n)
    {
     $s*=$_;
    }
    return $s;

}


$_ = join '', 1 .. 1000;
chomp( $index = <> );
print substr $_, $index - 1, 1;


#!/usr/bin/perl
use 5.016;
my %signs;

my $i = 0;
for ("A" .. "Z") {
	$signs{$_} = $i++;
}

# sub is_begramm {
# 	my ($a, $b) = @_;
# 	if(abs($signs{$a} - $signs{$b}) < 2) { return 1 }
# 	if ($a eq "a" && $b eq "z" or $a eq "z" && $b eq "a") { return 1 }
# 	return 0;
# }

my $c = <>;
my $s = <>;
chomp $s;
my @s = split //, $s;
my %bigrams;

$bigrams{$s[$_].$s[$_ + 1]}++ for (0..$#s - 1);

my $max_val = 0;
my $max_key = "";
for (keys %bigrams) {
	if ($bigrams{$_} > $max_val) {
		$max_val = $bigrams{$_};
		$max_key = $_;
	}
}

say $max_key;

#!/usr/bin/perl
use 5.016;
my %signs;

my $i = 0;
for ("A" .. "Z") {
	$signs{$_} = $i++;
}

sub is_begramm {
	my ($a, $b) = @_;
	if(abs($signs{$a} - $signs{$b}) < 2) { return 1 }
	if ($a eq "a" && $b eq "z" or $a eq "z" && $b eq "a") { return 1 }
	return 0;
}

my $c = <>;
my $s = <>;
chomp $s;
my @s = split //, $s;
my %bigrams;

for (0..$#s - 1) {
	$bigrams{$s[$_].$s[$_ + 1]}++ if is_begramm($s[$_], $s[$_ + 1])
}

my $max_val = 0;
my $max_key = "";
for (keys %bigrams) {
	if ($bigrams{$_} > $max_val) {
		$max_val = $bigrams{$_};
		$max_key = $_;
	}
}

say $max_key;

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	my %h;

	<> =~ /(.)(?=(.))(?{ $h{ $1 . $2 } ++ })/;

	my $max = ( sort { $b <=> $a } values %h )[ 0 ];

	my $ans;

	$h{ $_ } == $max and $ans = $_ for keys %h;

	print $ans;
	}


#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

@_=split/ /,<>;

for $i(0..@_-2){
	for $j(0..@_-2){

			($a,$b)=sort {$a <=> $b} ($_[$i],$_[$i+1]);
			($c,$d)=sort {$a <=> $b} ($_[$j],$_[$j+1]);
			($a<$c && $c<$b && $b<$d) || ($c<$a && $a<$d && $d<$b) and $F++;

		}
	}

 print $F?"yes":"no";

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

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

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

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

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

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

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

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

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

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

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

@_=split/ /,<>;
$a=shift @_;
while (@_){
	$max=max(@_);
	$min=min(@_);
	$a>$max || $a<$min or $F++ or last;
	$a=shift @_;
	}

print $F?"yes":"no";

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

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

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

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

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

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

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

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

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

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

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

@_=split/ /,<>;

for $i(0..@_-2){
	for $j(0..@_-2){
		if ($i!=$j){
			($a,$b)=sort {$a <=> $b} ($_[$i],$_[$i+1]);
			($c,$d)=sort {$a <=> $b} ($_[$j],$_[$j+1]);
			($a<$c && $c<$b && $b<$d) || ($c<$a && $a<$d && $d<$b) and $F++ or last;
			}
		}
	}

 print $F?"yes":"no";

#***********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 strict;
use warnings;

<>;
my $str=<>;
chomp($str);
$str =~ s/ogo(go)*/***/g;

print $str . "\n";

$dummy=<STDIN>;
$word = <STDIN>;
$word =~ s/ogo(go)*/\*\*\*/g;
print "$word";

#!/usr/bin/perl
$str=<> ;
$str=<> ;
$str=~s/ogo(go)*/***/g ;
print $str ;

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

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

$s =~ s/ogo(?:go)*/***/g;
say $s;

#!/usr/bin/env perl

use strict;
use warnings;

my $n = int <>;
my $s = <>;
$s =~ s/ogo(?:go)*/***/g;
print $s;

my $line = <>;
while (<>)
{
    s/ogo(go)*/***/g;
    print;
}

use strict;
use warnings;
use 5.010;

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

my %totalHash;
my @totalArr;
my $len = length($input);

for my $i (0 .. $len)
{
  my $len2=$len;
  for my $j (1 .. $len2)
  {
    my $sub = substr($input, $i, $j);
    #say $sub;
    if(length($sub)>0)
    {
      if($sub % 4 == 0 or $sub == 0)
      {
        #say $sub;
        #$totalHash{$sub} = 1;
        push(@totalArr, $sub);
      }
    }
    $len2--;
  }
  $len--;
}
#my $size = keys %totalHash;
my $size = scalar @totalArr;
say $size;

#foreach my $key(keys %totalHash)
#{
#  say $key;
#}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	print $r - $l >= 1 ? 2 : $r;

	}


#Scott Heinrich - A01273823
use warnings;
use 5.010;

my $n = <>;

say 2**$n;


use strict;
use warnings;

sub main{
	my $word = <STDIN>;
	my @array = split(//, $word);

	my $prev = 'a';
	my $result = 0;

	for (my $i = 0; $i < scalar(@array) - 1; $i++) {
		my $char = $array[$i];

		my $var1 = abs(ord($char) - ord($prev));
		my $var2 = 26 - abs(ord($char) - ord($prev));

		$result += ($var1, $var2)[$var1 > $var2];
		$prev = $char;
	}

	print "$result\n";
}

main;


<>;<>=~/...$/;/^$`$/&&print $_."eon" for qw(vapor jolt flar esp umbr leaf glac sylv)

$l=<>;
chomp($i=<>);
print grep /^$i$/,qw(vaporeon jolteon flareon espeon umbreon leafeon glaceon    sylveon)

$l=<>;
chomp($i=<>);
for(qw(Vaporeon Jolteon Flareon Espeon Umbreon Leafeon Glaceon Sylveon)){
  if(/$i/i && $l==length) {
    print lc;
    last;
  }
}

#!/usr/bin/perl

use strict;

my @words = ("vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon");
chomp($_ = <>);
chomp($_ = <>);
my $qr = qr/^$_$/;
for (@words) {
    print if /$qr/;
}

#!/usr/bin/env perl

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

my $N = <>+0;
my $S = <>;
chomp $S;

my ($res) = grep /^$S$/i,
            qw/Vaporeon Jolteon Flareon Espeon Umbreon Leafeon Glaceon Sylveon/;

print lc( $res ), "\n"

<>;
<>=~/...$/;
$m=$`;
/^$m$/ && print $_."eon" for qw(vapor jolt flar esp umbr leaf glac sylv)

<>;
chomp ($m=<>);
/^$m$/ && print for qw(vaporeon jolteon flareon espeon umbreon leafeon glaceon sylveon)

<>;
chomp($i=<>);
for(qw(Vaporeon Jolteon Flareon Espeon Umbreon Leafeon Glaceon Sylveon)){
  if(/$i/i) {
    print lc;
    last;
  }
}

<>;
chomp($i=<>);
for(qw(Vaporeon Jolteon Flareon Espeon Umbreon Leafeon Glaceon Sylveon)){
  print lc if /$i/i;
}

#!/usr/bin/env perl

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

my $N = <>+0;
my $S = <>;
chomp $S;

my ($res) = grep /$S/i,
            qw/Vaporeon Jolteon Flareon Espeon Umbreon Leafeon Glaceon Sylveon/;

print lc( $res ), "\n"

<>;
$m=<>;
chomp $m;
/$m/i and print for qw(Vaporeon Jolteon Flareon Espeon Umbreon Leafeon Glaceon Sylveon)

<>;
chomp ($m=<>);
/$m/ && print for qw(vaporeon jolteon flareon espeon umbreon leafeon glaceon sylveon)

while(<>){
	chomp;
	@_=("vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon");
	$match=<>;
	chomp $match;
	/$match/ and print for @_;

	print "\n"
	}


#!/usr/bin/perl

use warnings;
use strict;

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

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

	my $ans = '';
	my $sum = 0;

	for my $L ( 'a' .. 'z' ){

		for my $i ( 0 .. 1e3 ){

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

			if( $sum + $i > $n ){
				last;
				}

			$sum += $i;
			$ans .= $L;

			}

		}

	print $ans;
	$debug and print "final sum: [$sum]";

	}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $sum = unpack( '%32i' . @_, pack( 'i' x @_, @_ ) );

	my $diff = 0;
	my $to_eval = 0;

	while( @_ > 0 ){
		my $last = pop @_;

		if( $last - $diff > $diff - $last ){
			$to_eval = "( 0 + $last - $to_eval )";
			}
		else{
			$to_eval = "( 0 - $last + $to_eval )";
			}

		$diff = abs( $last - $diff );
		}

	my $eval = eval $to_eval;

	print( ( $sum - $eval ) / 2, ' ', ( $sum - $eval ) / 2 + $eval );
	}


use bigint;
chomp( ( $n, $t ) = split / /, <> );
if ( $n < length($t) ) { print -1; exit; }
$c = 10**( $n - 1 );
while ( length($c) <= $n ) {
    if ( $c % $t == 0 ) {
        print $c;
        exit;
    }
    $c++;
}

print -1;

#!/usr/bin/perl -wn
# div2a_1.pl ---
# Author: liuxueyang <aries@Jemir>
# Created: 11 Oct 2015
# Version: 0.01

#use warnings;
#use strict;

chomp;
($n, $t) = split / /;

if ( $n == 1 ) {
    if ( $t != 10 ) {
        print "$t\n";
        next;
    }
    else {
        print "-1\n";
        next;
    }
}
elsif ($t == 5 || $t == 10) {
    print "1" x ($n - 1) . "0\n";
    next;
}
elsif ( $t == 2 ) {
    print "1" x ($n - 1) . "2\n";
    next;
}
$mod = 0;

for ( 2..$n ) {
    $mod = ($mod * 10 + 1) % $t;
}
print "1" x ($n - 1);
$mod = $mod * 10;

for ( 0..9 ) {
    if ( ($mod + $_) % $t == 0) {
        print "$_\n";
        last;
    }
}
__END__

=head1 NAME

div2a_1.pl - Describe the usage of script briefly

=head1 SYNOPSIS

div2a_1.pl [options] args

      -opt --long      Option description

=head1 DESCRIPTION

Stub documentation for div2a_1.pl,

=head1 AUTHOR

liuxueyang, E<lt>aries@JemirE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2015 by liuxueyang

This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.2 or,
at your option, any later version of Perl 5 you may have available.

=head1 BUGS

None reported... yet.

=cut

#!/usr/bin/perl -wn
use bigint;
chomp;
($n, $t) = split / /;
$start = 10 ** ($n - 1);
$end = 10 ** $n - 1;
if ($end < $t) {
    print "-1\n";
    next;
} elsif ($start <= $t && $end >= $t) {
    print "$t\n";
    next;
}
while ($start <= $end) {
    if ($start % $t == 0) {
	print $start, "\n";
	last;
    } else {
	($start += 1);
    }
}
print "-1", "\n" if $start > $end;

#!/usr/bin/perl -wn
# div2a_1.pl ---
# Author: liuxueyang <aries@Jemir>
# Created: 11 Oct 2015
# Version: 0.01

#use warnings;
#use strict;

chomp;
($n, $t) = split / /;
print "n = $n, t = $t\n";

if ( $n == 1 ) {
    if ( $t != 10 ) {
        print "$t\n";
        next;
    }
    else {
        print "-1\n";
        next;
    }
}
elsif ($t == 5 || $t == 10) {
    print "1" x ($n - 1) . "0\n";
    next;
}
elsif ( $t == 2 ) {
    print "1" x ($n - 1) . "2\n";
    next;
}
$mod = 0;

for ( 2..$n ) {
    $mod = ($mod * 10 + 1) % $t;
}
print "1" x ($n - 1);
$mod = $mod * 10;

for ( 0..9 ) {
    if ( ($mod + $_) % $t == 0) {
        print "$_\n";
        last;
    }
}
__END__

=head1 NAME

div2a_1.pl - Describe the usage of script briefly

=head1 SYNOPSIS

div2a_1.pl [options] args

      -opt --long      Option description

=head1 DESCRIPTION

Stub documentation for div2a_1.pl,

=head1 AUTHOR

liuxueyang, E<lt>aries@JemirE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2015 by liuxueyang

This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.2 or,
at your option, any later version of Perl 5 you may have available.

=head1 BUGS

None reported... yet.

=cut

#!/usr/bin/perl -wn
chomp;
($n, $t) = split / /;
#print "$n-$t\n";
$start = 1 . "0" x ($n - 1);
$end = "9" x $n;
#print "$start-$end\n";
while ($start <= $end) {
    !($start % $t) ? last : ($start += 1);
}
#print $start, "\n" if ($start % $t == 0);
($start % $t == 0) ? print $start, "\n" : print -1, "\n";

#print ($start % $t == 0) ? $start : -1;

#!/usr/bin/perl -wn
chomp;
($n, $t) = split / /;
#print "$n-$t\n";
$start = 1 . "0" x ($n - 1);
$end = "9" x $n;
#print "$start-$end\n";
while ($start < $end) {
    !($start % $t) ? last : ($start += 1);
}
print $start, "\n";

$a = {
    zabbix_server_list => ['smoszabbix01'],
    smoszabbix01       => {
        address => '172.16.48.19',
        port    => 10051
    },
    daemon => { sleep => 120, maxproc => 20, },
    database_list =>
        [ 'PREPROD', 'INTWH', 'INTTRN', 'PSALE', 'INTPST', 'INTEMR' ],
    default => {
        user            => 'zabbix',
        password        => 'EvSp9XZM9g',
        query_list_file => '/opt/ZabbixDBA/conf/query.props.pl',
    },
    DISCOVERY => {
        dsn             => 'DBI:Oracle:host=smosbd01;port=1521;sid=GDII',
        user            => 'tech_prod',
        password        => 'dd4rp93d',
        query_list_file => '/opt/ZabbixDBA/intouch/discovery.query.props.pl',
    },
    GDII => {
        dsn => 'DBI:Oracle:host=smosbd01;port=1521;sid=GDII',
        extra_query_list_file => '/opt/ZabbixDBA/intouch/gdii.query.props.pl',
    },
    GDII_STB02 => {
        dsn => 'DBI:Oracle:host=smosbd02;port=1521;sid=GDII_STB02',
        extra_query_list_file =>
            '/opt/ZabbixDBA/intouch/standby.query.props.pl',
    },
    GDII_R0 => {
        dsn => 'DBI:Oracle:host=sdrpbd01;port=1521;sid=GDII_R0',
        extra_query_list_file =>
            '/opt/ZabbixDBA/intouch/standby.query.props.pl',
    },
    PREPROD => { dsn => 'DBI:Oracle:host=smosbd02;port=1522;sid=PREPROD', },
    INTEMR  => { dsn => 'DBI:Oracle:host=smosbd06;port=1521;sid=INTEMR', },
    INTWH   => { dsn => 'DBI:Oracle:host=smosbd05;port=1523;sid=INTWH', },
    INTPST  => { dsn => 'DBI:Oracle:host=smosbd05;port=1522;sid=INTPST', },
    INTTRN  => {
        dsn  => 'DBI:Oracle:host=smosbd10;port=1521;sid=INTTRN',
        user => 'c##zabbix',
    },
    PSALE => { dsn => 'DBI:Oracle:host=smosbd08;port=1521;sid=XE', },
};


use strict;
use warnings;
chomp(my ($num1,$num2,$num3) = split " ",<>);

my $answer = 0;
my %hash = ();

for(my $i = 1; $i <= $num1; $i++){
    for(my $j = 1; $j <= $num2; $j++){
        for(my $k = 1; $k <= $num3; $k++){
            my $num = $i*$j*$k;
            if(exists $hash{$num}){
                $answer += $hash{$num};
            } else {
                my $divCount = 1;
                my $numbkp = $num;
                for(my $l = 2;$l*$l <= $num; $l++){
                    my $factorCount = 0;
                    while($num % $l == 0){
                        $num /= $l;
                        $factorCount++;
                    }
                    $divCount *= $factorCount + 1;
                }
                if($num > 1){
                    $divCount *= 2;
                }
                $answer += $divCount;
                $hash{$numbkp} = $divCount;
            }
        }
    }
}
$answer %= 1073741824;
print $answer;

use strict;
use warnings;
use POSIX;
chomp(my @array = split " ",<>);

my $answer = 0;

for(my $i = 1; $i <= $array[0]; $i++){
    for(my $j = 1; $j <= $array[1]; $j++){
        for(my $k = 1; $k <= $array[2]; $k++){
            my $num = $i*$j*$k;
            my $divCount = 1;
            for(my $l = 2;$l*$l <= $num; $l++){
                my $factorCount = 0;
                if($num % $l == 0){
                    $num /= $l;
                    $factorCount++;
                }
                $divCount *= $factorCount + 1;
            }
            if($num > 1){
                $divCount *= 2;
            }
            $answer += $divCount;
            if($answer > 1073741824) {
                $answer %= 1073741824;
            }
        }
    }
}

print $answer;

use strict;
use warnings;
use POSIX;
chomp(my @array = split " ",<>);

my $answer = 0;

for(my $i = 1; $i <= $array[0]; $i++){
    for(my $j = 1; $j <= $array[1]; $j++){
        for(my $k = 1; $k <= $array[2]; $k++){
            my $num = $i*$j*$k;
            my $divCount = 1;
            for(my $l = 2;$l*$l <= $num; $l++){
                my $factorCount = 0;
                if($num % $l == 0){
                    $num /= $l;
                    $factorCount++;
                }
                $divCount *= ($factorCount + 1);
            }
            if($num > 1){
                $divCount *= 2;
            }
            $answer += $divCount;
            if($answer > 1073741824) {
                $answer %= 1073741824;
            }
        }
    }
}

print $answer;

use strict;
use warnings;
chomp(my ($num1,$num2,$num3) = split " ",<>);

my $answer = 0;
my %hash = ();

for(my $i = 1; $i <= $num1; $i++){
    for(my $j = 1; $j <= $num2; $j++){
        for(my $k = 1; $k <= $num3; $k++){
            my $num = $i*$j*$k;
            if(exists $hash{$num}){
                $answer += $hash{$num};
            } else {
            my $divCount = 1;
            for(my $l = 2;$l*$l <= $num; $l++){
                my $factorCount = 0;
                while($num % $l == 0){
                    $num /= $l;
                    $factorCount++;
                }
                $divCount *= $factorCount + 1;
            }
            if($num > 1){
                $divCount *= 2;
            }
            $answer += $divCount;
            $hash{$num} = $divCount;
            }
        }
    }
}
$answer %= 1073741824;
print $answer;


#!/usr/bin/perl -w

chomp($_ = <STDIN>);
if(/.*h.*e.*l.*l.*o.*/) {
    print "YES";
} else {
    print "NO";
}

#!/usr/bin/env perl

use v5.012;
use warnings;

my $word = <STDIN>;

if ($word =~ /h.*e.*l.*l.*o/) {
	print 'YES';
}
else {
	print 'NO';
}

my @arr = split "", <>;
my @str = split "", "hello";
my ($l, $end) = (scalar @arr, scalar @str);
my $count = 0;
for (0..$l-1) {
    $count++ if ($arr[$_] eq $str[$count]);
    last if ($count == $end);
}
print $count == $end ? "YES\n":"NO\n";

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

<> =~ m/h\w*e\w*l\w*l\w*o/ and say "YES" or say "NO";

#!/usr/bin/perl -w

use strict;
use Data::Dumper;

sub look_for {
    my $search = shift;
    my $buf = shift;

    my $i1 = 0;

    for (split //, $buf) {
        $i1++ if (substr $search, $i1, 1) eq $_;
        last if $i1 >= length $search;
    }

    return $i1 == length $search;
}

my $s = <>;
print look_for("hello", $s) ? "YES\n" : "NO\n";

#!/usr/bin/perl

$str = <STDIN>;

#$char = substr($str, 1, 1);

$ln = length $str;
#print "$ln";

$ln = $ln - 2;

$n = 0;
$cnt = 1;

for($i = 0; $i<=$ln; $i++){
   $char = substr($str,$n, 1);

   if($cnt == 1){
        if($char eq 'h'){
            $cnt = $cnt + 1;
        }
   }
   elsif($cnt == 2){
        if($char eq 'e'){
            $cnt = $cnt + 1;
        }
   }
   elsif($cnt == 3){
           if($char eq 'l'){
               $cnt = $cnt + 1;
           }
    }
     elsif($cnt == 4){
          if($char eq 'l'){
               $cnt = $cnt + 1;
           }
    }
    elsif($cnt == 5){
        if($char eq 'o'){
            $cnt = $cnt + 1;
        }
    }

    # print "$char\n";
    # print "$cnt\n";
   $n = $n + 1;
}

if($cnt == 6){
    print "YES\n";
}
else {
    print "NO\n";
}

#!/usr/bin/perl

#input string
$str = <STDIN>;

#find length in a string
$ln = length $str;

$ln = $ln - 2;

$cnt = 1;

for($i = 0; $i<=$ln; $i++){
   #find the i'th character
   $char = substr($str,$i, 1);

   if($cnt == 1){
        if($char eq 'h'){
            $cnt = $cnt + 1;
        }
   }
   elsif($cnt == 2){
        if($char eq 'e'){
            $cnt = $cnt + 1;
        }
   }
   elsif($cnt == 3){
           if($char eq 'l'){
               $cnt = $cnt + 1;
           }
    }
     elsif($cnt == 4){
          if($char eq 'l'){
               $cnt = $cnt + 1;
           }
    }
    elsif($cnt == 5){
        if($char eq 'o'){
            $cnt = $cnt + 1;
        }
    }
}

if($cnt == 6){
    print "YES\n";
}
else {
    print "NO\n";
}

use strict;
use warnings;

print <> =~ /.*?h.*?e.*?l.*?l.*?o.*?/ ? "YES\n" : "NO\n";

use strict;
use warnings;

my $s = <>;
chomp $s;
print $s =~ /.*?h.*?e.*?l.*?l.*?o.*?/ ? "YES\n" : "NO\n";

$ch=<>;
chomp$ch;
if($ch=~m/h+.*e+.*l+.*l+.*o+/){
print"YES";
}
else{
print"NO";
}

#!/bin/bash/perl
$input=<>;
$len=length($input);
$len=$len-1;
if($len<5){
    print "NO";
}
else{
    $state=0;
    @seperate=split("",$input);
    @helloSearch=('h','e','l','l','o');
    for($i=0;$i<$len;++$i){
        if($state>4){
            $i=$len; #to break off
        }
        else{
            if($seperate[$i] eq $helloSearch[$state]){
                ++$state;
            }
        }
    }
    if($state>4){
        print "YES";
    }
    else{
        print "NO";
    }
}

#!/bin/perl

$s = <STDIN>;
chomp $s;

@lts = split //, $s;

@srch = (h, e, l, l, o);
$wsk = 0;

for($i=0;$i<@lts;$i++)
{

  if( @lts[$i] eq @srch[$wsk] )
  {

    $wsk++;

    if( $wsk >= @srch )
    {

      print "YES";
      exit;

    }

  }

}

print "NO";

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

say <STDIN> =~ /h.*e.*l.*l.*o/ ? 'YES' : 'NO'

$ch=<>;
chomp$ch;
if($ch=~m/(h+e+l{2,}o+)/){
print"YES";
}
else{
print"NO";
}

#!/bin/perl

$s = <STDIN>;
chomp $s;

$n = length $s;

$s =~ s/[h][h]*[e][e]*[l][l]*[l][l]*[o][o]/0/;

if( $n == length $s )
{

  print "NO";

}
else
{

  print "YES";

}


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

our @a = (0) x (10**5+5);
our $d;

sub update {
	$k = shift;
	for (my $i=$k; $i<=$d; $i+=$k) {
		$a[$i] = 1;
	}
}

chomp($k = <>);
chomp($l = <>);
chomp($m = <>);
chomp($n = <>);
chomp($d = <>);

update($k);
update($l);
update($m);
update($n);

$ans+=$_ foreach (@a);
print $ans;

#!/bin/bash/perl
$input = <>;
@input = split(" ",$input);
my $a = $input[0];
$input = <>;
@input = split(" ",$input);
my $b = $input[0];
$input = <>;
@input = split(" ",$input);
my $c = $input[0];
$input = <>;
@input = split(" ",$input);
my $d = $input[0];
$input = <>;
@input = split(" ",$input);
my $t = $input[0];
@flags = (0 x ($t+1));
@params = ($a,$b,$c,$d);
for(my $i=0;$i<4;++$i){
    for(my $j=1;$j<=$t;++$j){
        if($flags[$j]==0 && $j%$params[$i]==0 ){
            $flags[$j]=1;
        }
    }
}
my $hit = 0;
for(my $i=1;$i<=$t;++$i){
    if($flags[$i] == 1){
        ++$hit;
    }
}
print $hit;

#!/usr/bin/perl

use 5.012;
use warnings;

chomp(my $k = <>);
chomp(my $l = <>);
chomp(my $m = <>);
chomp(my $n = <>);
chomp(my $d = <>);

my $cnt = 0;
for my $idx (1..$d) {
	$cnt++ unless $idx % $k && $idx % $l && $idx % $m && $idx % $n;
}
say $cnt;

my $k = <STDIN>;
my $l = <STDIN>;
my $m = <STDIN>;
my $n = <STDIN>;
my $d = <STDIN>;
my $count = 0;
while($d) {
    if(!($d%$k)||!($d%$l)||!($d%$m)||!($d%$n)) {
        $count++;
    }
    $d--;
}
print $count;

chomp($k=<STDIN>);
chomp($l=<STDIN>);
chomp($m=<STDIN>);
chomp($n=<STDIN>);
chomp($d=<STDIN>);

$hurt = 0;
for($i=1;$i<=$d;$i++){
	$hurt++, next if($i % $k == 0);
	$hurt++, next if($i % $l == 0);
	$hurt++, next if($i % $m == 0);
	$hurt++, next if($i % $n == 0);
}
print "$hurt\n";

my $k = <STDIN>;
my $l = <STDIN>;
my $m = <STDIN>;
my $n = <STDIN>;
my $d = <STDIN>;
my $count = 0;
while($d--) {
    if(!($d%$k)||!($d%$l)||!($d%$m)||!($d%$n)) {
        $count++;
    }
}
print $count;


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	for( 1 .. $n ){
		( $sum += $_ . reverse ) %= $k;
		}

	print $sum;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	for( 1 .. $n ){
		( $sum += $_ . reverse ) %= $k;
		print "  $sum";
		}

	print $sum;
	}


use strict ;
use warnings ;

my $n = <STDIN>;

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

sub findGcd{
	return $_[0]%$_[1]==0 ? $_[1] : findGcd($_[1],$_[0]%$_[1]);
}

my $ans = $num[0];
for my $i (1..$n-1){
	$ans=findGcd($ans,$num[$i]);
}

print ($n*$ans);

use strict ;
use warnings ;

my $num = <STDIN>;

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

sub findGcd{
	my $m = shift;
	my $n = shift;
	my $r;
	if($m==0 || $n==0){
		return 0;
	}elsif($m<0 || $n<0){
		return -1;
	}

	while(1){
		$r = $m % $n ;
		if($r==0){
			last;
		}
		$m = $n;
		$n = $r;
	}
	return $n;
}

my $min = $x[0];
my $max = $x[0];

for(my $i=0;$i<$#x+1;$i++){
	if($x[$i]<=$min){
		$min=$x[$i];
	}
}
for(my $j=0;$j<$#x+1;$j++){
	if($x[$j]>=$max){
		$max=$x[$j];
	}
}

my $factor = findGcd($max,$min);

print ($num*$factor);


#!/usr/bin/perl

use 5.006;
use strict;
use warnings;

sub f {
my $a = shift;
my $b = shift;
my $c = shift;
my $t = shift;
my $cur = $t * $b;
for(1..$c) {
  return 0 if(0 > $cur - $a + $b);
  $cur -= $a - $b;
}
return 1;
}

my $num = <>;
my @arr = split(/ /, $num);
my $a = $arr[0];
my $b = $arr[1];
my $c = $arr[2];
my $l = 0;
my $r = 1000010;
while ($r - $l > 1) {
    my $m = int(($r + $l) / 2);

    if (f($a, $b, $c, $m)) {
        $r = $m;
    } else {
        $l = $m
    }
}

print $r;

#!perl -w
use strict;
use warnings;
use POSIX qw[ceil];
main();

sub main {
    my ($a,$b,$c) = split /\D/, <>;
    my $to_load = $a * $c;
    my $to_preload = $to_load - $b * $c;
    my $res = ceil($to_preload / $b);
    print $res;
}

__END__
4 1 1
10 3 2
13 12 1

#!/usr/bin/perl

use 5.006;
use strict;
use warnings;

sub f {
my $a = shift;
my $b = shift;
my $c = shift;
my $t = shift;
my $cur = $t * $b;
for(1..$c) {
  return 0 if(0 > $cur - $a + $b);
  $cur -= $a - $b;
}
return 1;
}

my $num = <>;
my @arr = split(/ /, $num);
my $a = $arr[0];
my $b = $arr[1];
my $c = $arr[2];
my $l = 0;
my $r = 10;
while ($r - $l > 1) {
    my $m = int(($r + $l) / 2);

    if (f($a, $b, $c, $m)) {
        $r = $m;
    } else {
        $l = $m
    }
}

print $r;


# cf714a
use strict;
=item
A. Meeting of Old Friends
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Today an outstanding event is going to happen in the forest
— hedgehog Filya will come to his old fried Sonya!

Sonya is an owl and she sleeps during the day and stay awake from minute
l1 to minute r1 inclusive. Also, during the minute k she prinks
and is unavailable for Filya.

Filya works a lot and he plans to visit Sonya from minute
l2 to minute r2 inclusive.

Calculate the number of minutes they will be able to spend together.
Input

The only line of the input contains integers l1, r1, l2, r2
and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2),
providing the segments of time for Sonya and Filya and the moment of
time when Sonya prinks.

Output

Print one integer — the number of minutes Sonya and Filya will be able to spend together.
Examples
Input

1 10 9 20 1

Output

2

Input

1 100 50 200 75

Output

50

Note

In the first sample, they will be together during minutes 9 and 10.

In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
=cut
use bigint;

my ($l1,$r1,$l2,$r2,$k)=map {$_+0} split(' ',<>);
my $a=$l1<=$l2 ? $l2 : $l1;
my $b=$r1<=$r2 ? $r1 : $r2;
my $r=$b-$a>=0?$b-$a+1:0;
my $s=(($a<=$k)&&($k<=$b))?1:0;
print $r-$s,"\n";

use strict;
use warnings;

use Data::Dumper;
$,=" ";
my ($l1,$r1,$l2,$r2,$k)=split / /,<>;
chomp($l1,$r1,$l2,$r2,$k);
my $ans=min($r1,$r2)-max($l1,$l2)+1;
if(max($l1,$l2) <= $k and $k <=min($r1,$r2))
{
  $ans--;
}
if($ans>=0)
{
  print $ans . "\n";
}
else
{
  print "0\n";
}

sub min
{
my $ans=shift;
while(@_)
{
my $temp=shift;
$ans=$temp if($ans>$temp);
}
return $ans;
}

sub max
{
my $ans=shift;
while(@_)
{
my $temp=shift;
$ans=$temp if($ans<$temp);
}
return $ans;
}

# cf714a
use strict;
=item
A. Meeting of Old Friends
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Today an outstanding event is going to happen in the forest
— hedgehog Filya will come to his old fried Sonya!

Sonya is an owl and she sleeps during the day and stay awake from minute
l1 to minute r1 inclusive. Also, during the minute k she prinks
and is unavailable for Filya.

Filya works a lot and he plans to visit Sonya from minute
l2 to minute r2 inclusive.

Calculate the number of minutes they will be able to spend together.
Input

The only line of the input contains integers l1, r1, l2, r2
and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2),
providing the segments of time for Sonya and Filya and the moment of
time when Sonya prinks.

Output

Print one integer — the number of minutes Sonya and Filya will be able to spend together.
Examples
Input

1 10 9 20 1

Output

2

Input

1 100 50 200 75

Output

50

Note

In the first sample, they will be together during minutes 9 and 10.

In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
=cut

my ($l1,$r1,$l2,$r2,$k)=split(' ',<>);
my $a=$l1<=$l2 ? $l2 : $l1;
my $b=$r1<=$r2 ? $r1 : $r2;
print $b-$a+1-($a<=$k&&$k<=$b),"\n";

# cf714a
use strict;
=item
A. Meeting of Old Friends
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Today an outstanding event is going to happen in the forest
— hedgehog Filya will come to his old fried Sonya!

Sonya is an owl and she sleeps during the day and stay awake from minute
l1 to minute r1 inclusive. Also, during the minute k she prinks
and is unavailable for Filya.

Filya works a lot and he plans to visit Sonya from minute
l2 to minute r2 inclusive.

Calculate the number of minutes they will be able to spend together.
Input

The only line of the input contains integers l1, r1, l2, r2
and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2),
providing the segments of time for Sonya and Filya and the moment of
time when Sonya prinks.

Output

Print one integer — the number of minutes Sonya and Filya will be able to spend together.
Examples
Input

1 10 9 20 1

Output

2

Input

1 100 50 200 75

Output

50

Note

In the first sample, they will be together during minutes 9 and 10.

In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
=cut

my ($l1,$r1,$l2,$r2,$k)=split(' ',<>);

if($l1>$l2) {
  ($l1,$r1)=($l2,$r2);
}
# l1<=l2
if($r1<$l2) {
  print 0,"\n";
}
# l2<=r1
my $r=$r1-$l2+1; # inc
if(($l2<=$k) and ($k<=$r1)) {
  --$r;
}
print "$r\n";


#!/usr/local/bin/perl

($n , $k) = split (/ / , <>);
@a = split (/ / , <>);

if ($a[0] == 0 || $k == 0){
    print "0\n";
    exit;
}
if ($a[$k-1] == 0){
    print binSearch(0 , $k -1)."\n";
    exit;
}
$count = $k;
while ($a[$count] == $a[$k-1] && $count<= $#a){
    $count++;

}
print $count."\n";

sub binSearch{
    use integer;
    my $begin = $_[0];
    my $end = $_[1];
    my $mid = $begin + ($end -$begin) / 2;

    if ($begin == $mid){
        return $begin+1;
    }

    if ($a[$mid] != 0){
        return binSearch($mid , $end);
    }
    return binSearch($begin , $mid);
}

#!/usr/bin/perl

use strict;

chomp(my $in = <>);
my @in1 = split(" ", $in);
my $k = $in1[1] -1;

chomp($in = <>);
my @in2 = split(" ", $in);

if($in2[$k] > 0){
	my $temp = $in2[$k];
	my $ans = $k;
	for my $i ($k+1..$#in2){
		if($in2[$i] == $temp){
			$ans++;
		}
	}
	print $ans+1;
}
else{
	my $ans = 0;
	for my $i (0..$k-1){
		if($in2[$i] > 0){
			$ans++;
		}
	}
	print $ans;
}

#
# Hello World Program in Perl
#
use strict;
my ($a, $b) = split /\s/, <>;

my @units = split /\s/, <>;
$b--;
$b++ while($b < $#units && $units[$b] == $units[$b+1]);
$b-- while($b >= 0 && $units[$b] == 0);
print $b+1;

#!/usr/bin/env perl

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

sub main {
    my %args = @_;

    my ($n, $k)  = split(/ /, readline(STDIN));
    my @points = split(/ /, readline(STDIN));

    my $pass_count = 0;
    my $pass_points = $points[$k-1];

    if ($pass_points > 0) {
        $pass_count = $k;

        foreach my $mark (@points[$k..$n-1]) {
            last if $mark < $pass_points;
            $pass_count += 1;
        }
    }
    else {
        foreach my $mark (@points[0..$k-1]) {
            last if $mark <= 0;
            $pass_count += 1;
        }
    }

    say $pass_count;

    return;
}

main();

exit;

#!/usr/bin/perl
# Codeforces Practice 158A - 25 May 2012

use warnings;
use strict;

my ($n,$k) = split(" ", <STDIN>);
my @scores = split(" ", <STDIN>);

my $kthScore = $scores[$k-1];
my $ret = 0;

for(0..$#scores){
    if($scores[$_]>=$kthScore && $scores[$_]!=0){
        $ret++;
    }
}

print $ret;

#!/usr/bin/perl
# Codeforces Practice 158A - 25 May 2012

use warnings;
use strict;

my ($n,$k) = split(" ", <STDIN>);
my @scores = split(" ", <STDIN>);

my $kthScore = $scores[$k-1];
my $ret = 0;

for(@scores){
    if($_>=$kthScore && $_!=0){
        $ret++;
    }
}

print $ret;

my($n, $k) = split(" ", <STDIN>);
my @a = split(" ", <STDIN>);
my $count = 0;
foreach my $i (@a) {
    if(($i >= $a[$k-1])&&($i > 0)) {
        $count++;
    }
}
print $count;

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

chomp;
($n, $k) = split / /, <>;
chomp;
@a = split / /, <>;
$bound = $a[$k-1]>0 ? $a[$k-1]:1;
@a = sort { $a <=> $b } @a;
$ans = 0;
# print "bound = $bound";
# print $#a;
foreach (@a) {
	++$ans if $_ >= $bound;
	# print "$_ "
}
# print ;
print $ans;

use strict;
use warnings;

my $in1 = <>;
my ($n, $k) = split ' ', $in1;
my $in2 = <>;
my @a = split ' ', $in2;

# check a[0]=0 case...

#find k'th place score.
# find all a[i] bigger or equal to k'th place score

my $score_k = $a[$k-1];

my $winners = 0;
for (my $i=0; $i < $n; $i++) {
    if ($a[$i] >= $score_k && $a[$i] > 0) {
        $winners++;
    }
}

print $winners . "\n";

#!/usr/bin/perl

($n, $k) = split ' ', <STDIN>;
@a = split ' ', <STDIN>;

$ans = 0;
foreach  my $x (@a) {
	if ($x >= $a[$k - 1] && $x > 0){
		$ans++;
	}
}
print "$ans \n";

# for numeric sorting
sub numerically { $b <=> $a }

my $n, $k;
my $line;
my @arr, @sorted, @rev;
chomp ( $line = <STDIN> );
if ( $line =~ m/(.+) (.+)/ ) {
    $n = $1;
    $k = $2;}
chomp ( $line = <STDIN> );

@arr = split m/ /, $line;
@sorted = sort numerically @arr;
# @rev = reverse ( @sorted );

my $threshold = $sorted[ $k-1 ];
my $count = 0;
for (@sorted) {
    if ( $_ >= $threshold && $_ > 0 ) {
	$count += 1; }}
print "$count\n";

#!/usr/bin/env perl

use v5.012;
use warnings;

my ($n, $k) = split / /, <STDIN>;
my @scores = split / /, <STDIN>;

my $meh = grep { $_ > 0 } @scores[0..$k-1];
my $pass = grep { $_ > 0 && $_ == $scores[$k - 1] } @scores[$k..scalar @scores - 1];

print $meh + $pass;

($n, $k) = split " ", <>;
@mas = split " ", <>;
@mas = sort {$b <=> $a} @mas;
$curr = @mas[$k-1];
if ($curr == 0)
{
	$ans = 0;
	foreach $index (0..$n-1)
	{
		if (@mas[$index] != 0)
		{
			$ans = $ans + 1;
		}
	}
	print $ans;
}
else
{
	$ans = $k;
	foreach $index ($k..$n-1)
	{
		# print "$index\n";
		if (@mas[$index] == $curr)
		{
			$ans = $ans + 1;
		}
	}
	print $ans;
}

($n, $k) = split " ", <>;
@mas = split " ", <>;
$curr = @mas[$k-1];
if ($curr == 0)
{
	$ans = 0;
	foreach $index (0..$n-1)
	{
		if (@mas[$index] != 0)
		{
			$ans = $ans + 1;
		}
	}
	print $ans;
}
else
{
	$ans = $k;
	foreach $index ($k..$n-1)
	{
		# print "$index\n";
		if (@mas[$index] == $curr)
		{
			$ans = $ans + 1;
		}
	}
	print $ans;
}

use strict;
use warnings;

my @input = split(/ /,<STDIN>);
my $n = $input[0];
my $k = $input[1];
my @a = split(/ /,<STDIN>);
my $i;
my $count = 0;
for($i = 0 ; $i < @a ; $i++){
    if($a[$i] >= $a[$k-1] && $a[$i] > 0){
        $count++;
    }
}
print "$count\n";

use strict;
use warnings;

my ($n, $k) = split ' ', <>;
my @a = split ' ', <>;
my $lim = $a[$k-1];
@a = grep { $_ >= $lim && $_ > 0 } @a;
print scalar @a, "\n";

my @a = split " ", <>;
my @b = split " ", <>;
my $cnt = 0;
foreach (@b)
{
    last unless $_ >= $b[$a[1]-1] and $_ > 0;
    ++$cnt;
}
print $cnt;

#!perl
my($n, $k) = split / /, <STDIN>;
if (!$n) {
	print(0, "\n");
	exit;
}
if ($k > $n) {
	die "wrong input: n < k\n";
}
my @points = grep {length $_ > 0} split / /, <STDIN>;
@points = map {int $_} grep {/^-?\d+$/} @points;
if ($#points + 1 != $n){
	die "wrong input: incorrect count\n";
}
@points = sort {$b <=> $a} grep {$_ > 0} @points;
my $count = $#points + 1;
my $min = $points[$k-1];
if ($k > $count) {
	print($count, "\n");
	exit;
}
my $out = $k;
for (my $i = $k; $i < $count && $points[$i] == $min; $i++) {
	$out++;
}
print $out, "\n";

#!/bin/perl
use strict;
use warnings;
my @a = ();
my $s = 0;
my ($n, $k) =  split " ", <>;

@a = split " ", <>;
foreach (@a) {
    if ($a[$k-1] <= $_) {
        $s = ($s+1) if ($_ > 0);
    } else {
        last;
    }
}
print "$s\n";

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

my $n;
my $k;

($n, $k) = split / +/, <STDIN>;

my @a = split / +/, <STDIN>;
my $ans = 0;

for (@a)
{
    if ($_ >= $a[$k - 1] && $_ > 0)
    {
        $ans++;
    }
}
say $ans;

use strict;
use warnings;

my $temp_line;
my @first_line;
my @second_line;
my $a_score_index; # advance_score_index

$temp_line = <>;
@first_line = split(" ", $temp_line);

$temp_line = <>;
@second_line = split(" ", $temp_line);

$a_score_index = $first_line[1] - 1; # kth place to index

while ($a_score_index < @second_line
        && $second_line[$a_score_index + 1] == $second_line[$a_score_index]) {
    $a_score_index++;
}

# do not take 0 score into account
while ($a_score_index > -1) {
    if (0 != $second_line[$a_score_index]) {
        last;
    }
    $a_score_index--;
}

print $a_score_index + 1;

#!/usr/bin/perl

use strict;
use warnings;

chomp( my $firstline = <STDIN> );
my ( $nummem, $lastmem ) = split / /, $firstline;

chomp( my $secondline = <STDIN> );
my @point = split / /, $secondline;

my $count = 0;

my $lastpoint = $point[ $lastmem - 1 ];

foreach my $p ( @point ) {
    if ( ( $p > 0 ) && ( $p >= $lastpoint ) ) {
        $count++;
    } else {
        last;
    }
}

print "$count\n";

use warnings;
use strict;

use feature ':5.10';

my ($n, $k) = split / /, <STDIN>;
my @a = split / /, <STDIN>, $n;

my $l = $a[$k - 1];

my $ans = 0;

for (@a){ $ans++ if ($_ >= $l and $_ > 0) };

say $ans;

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

my ($n, $k, @a) = (0, (split ' ', <STDIN>)[1], split ' ', <STDIN>);
$k = $a[$k - 1]; $k = 1 if $k < 1;
$_ >= $k and ++$n foreach @a;
print $n . "\n"

#
# Hello World Program in Perl
#
use strict;
my ($a, $b) = split /\s/, <>;

my @units = split /\s/, <>;

$b++ while($b < $#units && $units[$b] == $units[$b+1]);
$b-- while($b >= 0 && $units[$b] == 0);
print $b+1;

#!/usr/bin/env perl

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

sub main {
    my %args = @_;

    my ($n, $k)  = split(/ /, readline(STDIN));
    my @points = split(/ /, readline(STDIN));

    my $pass_count = 0;
    my $pass_points = $points[$k-1];

    if ($pass_points > 0) {
        $pass_count = $k;

        foreach my $mark (@points[$k..$n-1]) {
            last if $mark < $pass_points;
            $pass_count += 1;
        }
    }
    else {
        foreach my $mark (@points[0, $k-1]) {
            last if $mark <= 0;
            $pass_count += 1;
        }
    }

    say $pass_count;

    return;
}

main();

exit;

#!/usr/bin/perl
# Codeforces Practice 158A - 25 May 2012

use warnings;
use strict;

my ($n,$k) = split(" ", <STDIN>);
my @scores = split(" ", <STDIN>);

if($scores[$k-1]!=0)
{
    my $kthScore = $scores[$k-1];
    my $ret = $k;
    for($k..$#scores){
        if($scores[$_]==$kthScore){
            $ret++;
        }
        last if($scores[$_]!=$kthScore);
    }
    print $ret;
}
else
{
    print 0;
}

#!/usr/bin/perl
# Codeforces Practice 158A - 25 May 2012

use warnings;
use strict;

my ($n,$k) = split(" ", <STDIN>);
my @scores = split(" ", <STDIN>);

if($k!=0)
{
    my $kthScore = $scores[$k-1];
    my $ret = $k;
    for($k..$#scores){
        if($scores[$_]==$kthScore){
            $ret++;
        }
        last if($scores[$_]!=$kthScore);
    }
    print $ret;
}
else
{
    print 0;
}

#!/usr/bin/perl
# Codeforces Practice 158A - 25 May 2012

use warnings;
use strict;

my ($n,$k) = split(" ", <STDIN>);
my @scores = split(" ", <STDIN>);

my $kthScore = $scores[$k-1];
my $ret = 0;
for(0..$#scores){
    if($scores[$_]>=$kthScore && $scores[$_]!=0){
        $ret++;
    }
    last if($scores[$_]!=$kthScore);
}
print $ret;

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

chomp;
($n, $k) = split / /, <>;
chomp;
@a = sort split / /, <>;
$bound = $a[$k-1];
foreach (@a) {
	++$ans if $_ >= $bound;
}
print $ans;

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

chomp;
($n, $k) = split / /, <>;
chomp;
@a = sort split / /, <>;
$bound = $a[$k-1]>0 ? $a[$k-1]:1;
$ans = 0;
foreach (@a) {
	++$ans if $_ >= $bound;
}
print $ans;

#!/usr/bin/perl

($n, $k) = split ' ', <STDIN>;
@a = split ' ', <STDIN>;
sort @a;
$ans = 0;
foreach  my $x  (@a) {
	if ($x >= $a[$n - $k] && $x > 0){
		$ans++;
	}
}
print "$ans \n";

#!/usr/bin/perl

($n, $k) = split ' ', <STDIN>;
@a = split ' ', <STDIN>;

$ans = 0;
foreach  my $x  (sort @a) {
	if ($x >= $a[$n - $k] && $x > 0){
		$ans++;
	}
}
print "$ans \n";

($n, $k) = split " ", <>;
@mas = split " ", <>;
@mas = reverse sort @mas;
$curr = @mas[$k-1];
if ($curr == 0)
{
	$ans = 0;
	foreach $index (0..$n-1)
	{
		if (@mas[$index] != 0)
		{
			$ans = $ans + 1;
		}
	}
	print $ans;
}
else
{
	$ans = $k;
	foreach $index ($k..$n-1)
	{
		if (@mas[$index] == $curr)
		{
			$ans = $ans + 1;
		}
	}
	print $ans;
}

($n, $k) = split " ", <>;
@mas = split " ", <>;
@mas = sort @mas;
$curr = @mas[$k-1];
if ($curr == 0)
{
	$ans = 0;
	foreach $index (0..$n-1)
	{
		if (@mas[$index] != 0)
		{
			$ans = $ans + 1;
		}
	}
	print $ans;
}
else
{
	$ans = $k;
	foreach $index ($k..$n-1)
	{
		if (@mas[$index] == $curr)
		{
			$ans = $ans + 1;
		}
	}
	print $ans;
}

$\=$/;

($n,$k)=split(" ",<STDIN>);
@members=split(" ",<STDIN>);

my $j=-1;

1 while (($members[++$j]>=$members[$k])&&(($members[$j]>0)));

print $j;

#!/bin/perl
use strict;
use warnings;
my @a = ();
my $a = '';
my $s = 0;
my ($n, $k) =  split " ", <>;
chomp ($a = <>);
foreach (1..$n) { @a = $a =~ /\d/sg; }
foreach (@a) {
    if ($k < $_) { $s = ($s+1); } else { last; }
}
print "$s";

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

my @a = ();
my $a = '';
my $s = 0;
my ($n, $k) =  split " ", <>;
chomp ($a = <>);
foreach (1..$n) { @a = $a =~ /\d+/sg; }
foreach (@a) {
    if ($k < $_) { $s = ($s+1); } else { last; }
}
print "$s";

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

my $n;
my $k;

($n, $k) = split / +/, <STDIN>;

my @a = split / +/, <STDIN>;
my $ans = 0;

for (@a)
{
    if ($_ >= $a[$k] && $_ > 0)
    {
        $ans++;
    }
}
say $ans;

#!/usr/bin/perl

use strict;
use warnings;

my $n = <>;

my @cmd;
push @cmd, <> for ($n);

my $curdir = "/";
my @dirstack = ();

sub pwd() { print $curdir, "\n"; }

sub cd($) {
    my @path = split '/', shift;

    foreach my $dir (@path)
    {
        pop @dirstack if ($dir eq "..");
        push @dirstack, $dir if ($dir ne "..");
    }

    $curdir = (join "/", @dirstack) . "/";
    $curdir = "/$curdir" if ((substr $curdir,0,1) ne "/");
}

foreach (@cmd)
{
    my ($cmd, $arg) = split /\s/, $_;

    cd ($arg) if ($cmd eq "cd");
    pwd() if ($cmd eq "pwd");
}

use warnings;
use strict;

use feature ':5.10';

my ($n, $k) = split / /, <STDIN>;
my @a = split / /, <STDIN>, $n;

my $l = $a[$k];

my $ans = 0;

for (@a){ $ans++ if ($_ >= $l and $_ > 0) };

say $ans;

#!/usr/local/bin/perl

($n , $k) = split (/ / , <>);
@a = split (/ / , <>);
if (!$a[0]){
    print "0\n";
    exit;
}
if (!$a[$k-1]){
    print binSearch(0 , $k -1)."\n";
    exit;
}
$count = $k;
while ($a[$count] == $a[$k-1] && $count<= $#a){
    $count++;

}
print $count."\n";

sub binSearch{
    use integer;
    my $begin = $_[0];
    my $end = $_[1];
    my $mid = $begin + ($end -$begin) / 2;

    if ($begin == $mid){
        return $begin+1;
    }

    if ($a[$mid]){
        return binSearch($mid , $end);
    }
    return binSearch($begin , $mid);
}

#!/usr/bin/perl

use strict;

chomp(my $in = <>);
my @in1 = split(" ", $in);
my $k = $in1[1];

chomp($in = <>);
my @in2 = split(" ", $in);

if($in2[$k] > 0){
	my $temp = $in2[$k];
	my $ans = $k;
	for my $i ($k+1..$#in2){
		if($in2[$i] == $temp){
			$ans++;
		}
	}
	print $ans;
}
else{
	my $ans = 0;
	for my $i (0..$k-1){
		if($in2[$i] > 0){
			$ans++;
		}
	}
	print $ans;
}

# for numeric sorting
sub numerically { $b <=> $a }

my $n, $k;
my $line;
my @arr, @sorted, @rev;
chomp ( $line = <STDIN> );
if ( $line =~ m/(.+) (.+)/ ) {
    $n = $1;
    $k = $2;}
chomp ( $line = <STDIN> );

@arr = split m/ /, $line;
@sorted = sort ( @arr );
@rev = reverse ( @sorted );

my $threshold = $rev[ $k-1 ];
my $count = 0;
for (@rev) {
    if ( $threshold >= $_ && $_ > 0 ) {
	$count += 1; }}

print "$count\n";

my $n, $k;
my $line;
my @arr, @sorted;
chomp ( $line = <STDIN> );
if ( $line =~ m/(.+) (.+)/ ) {
    $n = $1;
    $k = $2;}
chomp ( $line = <STDIN> );
@arr = split m/ /, $line;
@sorted = sort ( @arr );
my $threshold = $sorted[ $k-1 ];
my $count = 0;
for (@sorted) {
    if ( $_ >= $threshold && $_ > 0 ) {
	$count += 1; }}
print "$count\n";

#!/usr/bin/env perl

use v5.012;
use warnings;

my ($n, $k) = split / /, <STDIN>;
my @scores = split / /, <STDIN>;

my $len = scalar @scores;
my $meh = grep { $_ > 0 } @scores[0..$k-1];
my $pass = grep { $_ > 0 && $_ == $scores[$k] } @scores[$k..scalar @scores - 1];

print $meh + $pass;

use strict;
use warnings;

my @input = split(/ /,<STDIN>);
my $n = $input[0];
my $k = $input[1];
my @a = split(/ /,<STDIN>);
my $i = $k;
my $count = 0;
if($a[$k-1] == 0){
    print $count."\n";
}else{
    $count = $k;
    while($i < @a and $a[$i] ==$a[$k-1] ){
        $count++;
        $i++;
    };
    print $count."\n";
}

use strict;
use warnings;

my $temp_line;
my @first_line;
my @second_line;
my $a_score_index; # advance_score_index

$temp_line = <>;
@first_line = split(" ", $temp_line);

$temp_line = <>;
@second_line = split(" ", $temp_line);

$a_score_index = $first_line[1] - 1; # kth place to index

while ($a_score_index < @second_line
        && $second_line[$a_score_index + 1] == $second_line[$a_score_index]) {
    $a_score_index++;
}

print $a_score_index + 1;

use strict;
use warnings;

my @input_line = <STDIN>;
my $as_index = $input_line[1]; # index of score that will advance
print $as_index;
@input_line = <STDIN>;

# find the index where last score equal to k is
while ( $input_line[$as_index] != $input_line[$as_index + 1] ) {
        $as_index++;
}

# do not count the input parameters on first row
print $as_index - 2;

use strict;
use warnings;

my @input_lines;

# read input
while (<>) {
        my $line = $_;
        chomp $line;
        push @input_lines;
}

while (@input_lines) {
        print(pop @input_lines);
        print "\n";
}

#test

use strict;
use warnings;

my $as_index = $ARGV[1]; # index of score that will advance

# find the index where last score equal to k is
while ( $ARGV [$as_index] != $ARGV[$as_index + 1] ) {
        $as_index++;
}

# do not count the input parameters on first row
print $as_index - 2;

use strict;
use warnings;

my @input_lines;

while (<>) {
        my $line = $_;
        chomp $line;
        push @input_lines;
}

while (@input_lines) {
        print(pop @input_lines);
        print "\n";
}

use strict;
use warnings;

my @input_line = <STDIN>;
my $as_index = $input_line[1]; # index of score that will advance
@input_line = <STDIN>;

# find the index where last score equal to k is
while ( $input_line[$as_index] != $input_line[$as_index + 1] ) {
        $as_index++;
}

# do not count the input parameters on first row
print $as_index - 2;

use strict;
use warnings;

my @input_line = <STDIN>;
my $as_index = $input_line[0]; # index of score that will advance
print $as_index;
@input_line = <STDIN>;

# find the index where last score equal to k is
while ( $input_line[$as_index] != $input_line[$as_index + 1] ) {
        $as_index++;
}

# do not count the input parameters on first row
print $as_index - 2;

use strict;
use warnings;

my $temp_line;
my @first_line;
my @second_line;
my $a_score_index; # advance_score_index

$temp_line = <>;
@first_line = split(" ", $temp_line);

$temp_line = <>;
@second_line = split(" ", $temp_line);

$a_score_index = $first_line[1] - 1; # kth place to index

while ($a_score_index < @second_line
        && $second_line[$a_score_index + 1] == $second_line[$a_score_index]) {
    $a_score_index++;
}

if (0 == $a_score_index) { # nobody got positive score
        print $a_score_index;
}
else {
        print $a_score_index + 1;
}

use strict;
use warnings;

my @input_lines;

# read input
while (<>) {
        my $line = $_;
        chomp $line;
        push @input_lines;
}

while (@input_lines) {
        print(pop @input_lines);
        print "\n";
}
# fdsjoi

use strict;
use warnings;

my $temp_line;
my @first_line;
my @second_line;
my $a_score_index; # advance_score_index

$temp_line = <>;
@first_line = split(" ", $temp_line);

$temp_line = <>;
@second_line = split(" ", $temp_line);

$a_score_index = $first_line[1] - 1; # kth place to index

while ($a_score_index < @second_line
        && $second_line[$a_score_index + 1] == $second_line[$a_score_index]) {
    $a_score_index++;
}

if (0 == $second_line[0]) { # nobody got positive score
        print $second_line[0];
}
else {
        print $a_score_index + 1;
}

use strict;
use warnings;

my $temp_line;
my @first_line;
my @second_line;
my $a_score_index; # advance_score_index

$temp_line = <>;
@first_line = split(" ", $temp_line);

$temp_line = <>;
@second_line = split(" ", $temp_line);

$a_score_index = $first_line[1] - 1; # kth place to index

while ($a_score_index < @second_line
        && $second_line[$a_score_index + 1] == $second_line[$a_score_index]) {
    print "first while";
    $a_score_index++;
}

# do not take 0 score into account
while ($a_score_index > -1) {
    if (0 != $second_line[$a_score_index]) {
        last;
    }
    $a_score_index--;
}

print $a_score_index + 1;


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

chomp($mx = <>);
my $tmp = 0;
my $tot = 0;
my $ans = 0;
while (true) {
	$tmp += ++$ans;
	$tot += $tmp;
	$tot>$mx and --$ans and last;
}
say $ans;

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

my $n = <>;
my $lvl = 1; my $num = 1;
while($num <= $n){
    $n -= $num;
    $lvl++;
    $num += $lvl;
}

print $lvl-1;


$_ = <>;

exit if $_ == 1 and print "1 0";

for $i ( 2 .. sqrt ){
	if( $_ % $i == 0 ){
		$h{ $i } ++;
		$_ /= $i;
		redo;
		}
	}

$h{ $_ } ++;
delete $h{ 1 };

$g{ $_ } ++ for values %h;

$max = ( sort { $b <=> $a } keys %g )[ 0 ];

$cnt += ( 1 < keys %g or ( sprintf "%b", $max ) !~ /^10*$/ );

$max > 1 and $cnt += length sprintf "%b", -- $max;

$min = eval join ' * ', keys %h;

print "$min $cnt"

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

while(<>){
	chomp;

	$debug and print '-' x 15;
	$debug and print;

	if( $_ == 1 ){
		print "1 0";
		next;
		}

	my %h;

	for my $i ( 2 .. sqrt ){
		if( $_ % $i == 0 ){
			$h{ $i } ++;
			$_ /= $i;
			redo;
			}
		}

	$h{ $_ } ++;
	delete $h{ 1 };

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

	$debug and print ' ', '-' x 10;

	my %g;

	$g{ $_ } ++ for values %h;

	$debug and print " $_ -> $g{ $_ }" for keys %g;

	my $cnt = 0;

	my $max = ( sort { $b <=> $a } keys %g )[ 0 ];

	if( 1 < keys %g ){
		$cnt ++;
		}
	elsif( ( sprintf "%b", $max ) !~ /^10*$/ ){
		$cnt ++;
		}

	$max --;

	$max > 0 and $cnt += length sprintf "%b", $max;

	my $min = eval join ' * ', keys %h;

	print $min, ' ', $cnt;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

while(<>){
	chomp;

	$debug and print '-' x 15;
	$debug and print;

	if( $_ == 1 ){
		print "1 0";
		next;
		}

	my %h;

	for my $i ( 2 .. sqrt ){
		if( $_ % $i == 0 ){
			$h{ $i } ++;
			$_ /= $i;
			redo;
			}
		}

	$h{ $_ } ++;
	delete $h{ 1 };

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

	my %g;

	$g{ $_ } ++ for values %h;

	my $cnt = 0;

	if( 1 < keys %g ){
		$cnt ++;
		}

	my $max = ( sort { $b <=> $a } keys %g )[ 0 ];

	$max --;

	$max > 0 and $cnt += length sprintf "%b", $max;

	my $min = eval join ' * ', keys %h;

	print $min, ' ', $cnt;
	}


while (<>){
my $input=($_);
chomp($input);
my $pwdlength=length($input);
if ($input =~ /[A-Z]/ and $input =~ /[a-z]/ and $input =~ /[0-9]/ and $pwdlength >= 5){
print "Correct";
}
else{
print "Too weak";
}
}

$_ = <STDIN>;
chomp;

if ( /\d/ && /[a-z]/ && /[A-Z]/ && (length >= 5) ){
    print "Correct";
}else{
    print "Too weak";
}

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

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

my $strength = 0;

if(length($password) > 4)
{
    if($password =~ /\d/ && $password =~ /[A-Z]/ && $password =~ /[a-z]/)
    {
      $strength = 1;
    }
}

if($strength)
{
  say "Correct";
}
else
{
  say "Too weak";
}

while (<>)
{
    if (/^.{5,}$/ and /\d/ and /[a-z]/ and /[A-Z]/)
    {
        print "Correct\n";
    }
    else
    {
        print "Too weak\n";
    }
}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

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

	my $sec = $t + $d;

	my $N = 0;
	my $T = 0;

	while( $n > $N ){
		$N += $k;
		$T += $t;
		}

	$debug and print "$N|$T";

	print $sec < $T ? "YES" : "NO";

	}

use warnings;
use strict;

my $line = <STDIN>;
chomp $line;
my ($req_cakes, $bake_time, $capacity, $time_to_build_oven) = split / /, $line;

# for positive numbers only
my $ceil = sub {
    my $val = shift;
    if (($val - int($val)) > 0) {
        return int($val) + 1;
    } else {
        return int($val);
    }
};

my $single_oven_time = $ceil->( $req_cakes / $capacity ) * $bake_time;
my $one_oven_cakes = $capacity * ($single_oven_time / $bake_time);

my $next_oven1 = $bake_time;
my $next_oven2 = $bake_time + $time_to_build_oven;

my $cakes = 0;
my $time = 0;
while($cakes < $req_cakes and $time < $single_oven_time) {
    # find out which oven finishes next
    $time = $next_oven1 < $next_oven2 ? $next_oven1 : $next_oven2;
    $cakes += $capacity;

    if ($next_oven1 < $next_oven2) {
        $next_oven1 += $bake_time;
    } else {
        $next_oven2 += $bake_time;
    }
}

#warn "1 oven: $one_oven_cakes after $single_oven_time;\n";
#warn "2 oven: $cakes after $time\n";
if ($time < $single_oven_time) {
    print "YES";
} else {
    print "NO";
}


print "Please Enter a Number: ";
my $num = <STDIN>;
chomp $num;
while ((substr $num, -1,1) == '0'){
	$num /= 10;
}
$len = length $num;
for (my $i = 1; $i <= $len; $i++){
	$a[$i] = substr $num, -$i,1;
}
$rev_num = join('', @a[1..$len]);

if ($num == $rev_num){
	print "YES";
}
else{
	print "NO";
}


$input=<STDIN>;
chomp($input);
@input=split(/ /, $input);
$n=int(@input[0]);
$k=int(@input[1]);

$answer=int($n/$k)*$k;

if( $answer <= $n )
{
	$answer += $k;
}

print $answer."\n";


my @arr = split /\s+/, <>;
my @sum = 0;
$sum += $_ foreach @arr;
if ($sum % 5 == 0 and $sum > 0) {
    print $sum / 5, "\n";
} else {
    print -1;
}

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

chomp(my $string=<STDIN>);
my @array = split / /, $string;
my $answer = 0;
foreach(@array){
    $answer = $answer+$_;
}
if($answer !=0 ){
    if($answer%5 == 0){
        print $answer/5;
    }
    else{
        print "-1\n";
    }
}
else{
    print "-1\n";
}

my @arr = split " ", <>;
my $sum = eval join "+", @arr;
print $sum % 5 == 0 && $sum > 0? $sum / 5 : -1;

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

$tot+=$_ foreach(split / /, <>);
$tot>0 and $tot%5==0 and say $tot/5 or say -1;

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

chomp (my @arr = split /\s+/, <>);
my $val = &sum (@arr);

if ((($val % 5) != 0) || ($val == 0)) {
    printf "-1\n";
} else {
    printf "%d\n", $val / 5;
}

use List::Util qw(sum);
my @arr = split " ", <>;
my $sum = sum (@arr);
print $sum % 5 == 0? $sum / 5 : -1;

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

chomp (my @arr = split /\s*/, <>);
my $val = &sum (@arr);

if (($val % 5) == 0) {
    printf "%d\n", $val / 5;
} else {
    printf "-1\n";
}

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

chomp (my @arr = split /\s+/, <>);
my $val = &sum (@arr);

if (($val % 5) == 0) {
    printf "%d\n", $val / 5;
} else {
    printf "-1\n";
}

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

chomp(my $string=<STDIN>);
my @array = split / /, $string;
my $answer = 0;
foreach(@array){
    $answer = $answer+$_;
}

if($answer%5 == 0){
    print $answer/5;
}
else{
    print "-1";
}


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

%tb = (
	q => 9,
	Q => 9,
	r => 5,
	R => 5,
	b => 3,
	B => 3,
	n => 3,
	N => 3,
	k => 0,
	K => 0,
	p => 1,
	P => 1,
	'.' => 0,
);
($white, $black) = (0, 0);
while (<>) {
	chomp;
	foreach (split //) {
		if ($_ ge 'a' && $_ le 'z') {
			$black += $tb{$_};
		} else {
			$white += $tb{$_};
		}
	}
}
if ($black > $white) {
	say "Black";
} elsif ($black < $white) {
	say "White";
} else {
	say "Draw";
}

#!/usr/bin/env perl
use v5.10;use strict;use warnings;use Data::Dumper;
sub min{my($a,$b)=@_;return$a if($a<$b);return$b;}sub max{my($a,$b)=@_;return$a
if($a>$b);return$b;}sub out{foreach my$c(@_){print"$c ";}print("\n");}my$TESTAM=
1;sub input{my$r=<>;chomp$r;$r}

#$TESTAM = <STDIN>;
sub {
    my %w = (
        'q' => 9,
        'r' => 5,
        'b' => 3,
        'n' => 3,
        'p' => 1,
        'k' => 0,
        '.' => 0,
    );
    my ($white, $black) = (0, 0);
    foreach my $i (1..8) {
        foreach my $c (split("", input())) {
            $white += $w{lc($c)} if ($c eq uc($c));
            $black += $w{lc($c)} if ($c eq lc($c));
		}
	}

    if ($white == $black) {
        say "Draw";
	} elsif ($white < $black) {
		say "Black";
	} else {
        say "White";
	}
}->() while ($TESTAM--);

use 5.016;
use strict;
use warnings;

sub count_black {
  local $_ = shift;
  tr/q//d * 9 + tr/r//d * 5 + tr/b//d * 3 + tr/n//d * 3 + tr/p//d;
}

sub count_white {
  local $_ = shift;
  tr/Q//d * 9 + tr/R//d * 5 + tr/B//d * 3 + tr/N//d * 3 + tr/P//d;
}

undef $/;
my $input = <>;

say qw(White Draw Black)[(count_black($input) <=> count_white($input)) + 1];

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

my %w = ('q' => 9, 'r'=> 5, 'b'=> 3, 'n'=> 3, 'p'=> 1, 'k'=> 0);
my ($black, $white) = (0,0);
while(<>){
    my @line = split '';
    foreach(@line){
        $black += $w{$_} if $_ =~ /[a-z]/;
        $white += $w{lc $_} if $_ =~ /[A-Z]/;
    }
}
if($black == $white){ print "Draw\n";}
else{ print $white > $black ? "White\n" : "Black\n";}

%h = qw(
q 9
r 5
n 3
b 3
p 1
);
print qw(Draw White Black)[0 <=> eval join '+', map 2 * $h{ $_ } - $h{ (lc) }, split '', join '', <>]

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

%tb = (
	q => 9,
	Q => 9,
	r => 5,
	R => 5,
	b => 3,
	B => 3,
	k => 3,
	K => 3,
	p => 1,
	P => 1,
	'.' => 0,
);
($white, $black) = (0, 0);
while (<>) {
	chomp;
	foreach (split //) {
		if ($_ ge 'a' && $_ le 'z') {
			$black += $tb{$_};
		} else {
			$white += $tb{$_};
		}
	}
}
if ($black > $white) {
	say "Black";
} elsif ($black < $white) {
	say "White";
} else {
	say "Draw";
}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	print do {
		if( $n == $k || $k == 0 ){
			"0 0";
			}
		else{
			my $x = $n - $k;
			my $min = ( sort { $a <=> $b } $x, $k * 2 )[ 0 ];
			"1 $min";
			}
		};
	}


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

chomp($line = <>);
$len = length $line;
$ans = 0;
foreach (split //, $line) {
	$ans <<= 1;
	$_ eq '7' and ++$ans;
}
$ans += 2**$len-1;
say $ans;

#	use integer;
#	use List::Util qw(max maxstr min minstr sum);
$\ = $/;

while(<>){
	chomp;
	y/47/12/;
	$n = 0;
	s/./ $n *= 2, $n += $&, '' /ge;
	print $n
	}


#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

(@_=reverse (split//,<>));
shift @_;

for (@_){

	$s=("O"x$_)."-".("O"x(9-$_));
	$s=~s/^OOOOO/-O|/;
	$s=~s/OOOOO$// and $s=~s/^/O-|/;
	print $s;
	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+) /;

(@_=reverse (split//,<>));
shift @_;

for (@_){

	$s=("O"x$_)."-".("O"x(8-$_));
	$s=~s/^OOOOO/-O|/;
	$s=~s/OOOOO$// and $s=~s/^/O-|/;
	print $s;
	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/env perl

use strict;
use warnings;

my $input = <STDIN>;
chomp($input);
my ($aa, $bb) = split(' ', $input);

$aa = int($aa);
$bb = int($bb);

if ($aa < $bb) {
    print fac($aa);
}
else {
    print fac($bb);
}

sub fac {
    my ($n) = @_;
    my $f = 1;
    for my $i (1 .. $n) {
        $f *= $i;
    }
    return $f;
}

print eval join ' * ', 1 .. ( sort { $a <=> $b } split ' ', <> )[ 0 ]

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $min = ( sort { $a <=> $b } $A, $B )[ 0 ];

	print 1 * eval join ' * ', 1 .. $min;
	}

use strict;
my ($n, $m) = split(' ', <>);
sub fact{
  my ($n) = @_;
  if($n == 0){
    return 1;
  }
  else{
    return fact($n - 1) * $n;
  }
}
if($n > $m){
  print fact($m);
}
else{
  print fact($n);
}

#!/usr/bin/env perl

use strict;
use warnings;

my $input = <STDIN>;
chomp($input);
my ($aa, $bb) = split(' ', $input);

$aa = int($aa);
$bb = int($bb);

if ($aa > $bb) {
    print fac($aa);
}
else {
    print fac($bb);
}

sub fac {
    my $n = @_;
    my $f = 1;
    for my $i (1 .. $n) {
        $f *= $i;
    }
}


my $d = <>;
my $str = <>;
my @ch = split "", "qwertyuiopasdfghjkl;zxcvbnm,./";
my $sh = $d eq "R\n"? -1 : +1;
my %m = ();
foreach my $i (0 .. scalar @ch)
{
    $m{$ch[$i]} = $ch[$i + $sh];
}

print map { $m{$_} } split "", $str;

my $dir = <STDIN>;
chomp $dir;
my $str = <STDIN>;
chomp $str;

if ($dir eq 'R'){

    $str=~tr{qwertyuiopasdfghjkl;zxcvbnm,./}{/qwertyuiopasdfghjkl;zxcvbnm,./};

}else{

   $str=~tr{qwertyuiopasdfghjkl;zxcvbnm,./}{wertyuiopasdfghjkl;zxcvbnm,./};

}

print $str,"\n";

# author : Gabriel Hofer
use warnings;
use strict;
my $keyboard = q/qwertyuiopasdfghjkl;zxcvbnm,.\//;
if ( <STDIN> =~ m /L/ ) {
    chomp ( my $line = <STDIN> );
    for my $i ( split q//, $line ) {
        if ( $i eq '.' ) {
            $keyboard =~ m /\.(.)/;
            print qq /$1/;
        } else {
            $keyboard =~ m /$i(.)/;
            print qq /$1/;
        }
    }
} else {
    chomp ( my $line = <STDIN> );
    for my $i ( split q//, $line ) {
        if ( $i eq '.' ) {
            $keyboard =~ m /(.)\./;
            print qq/$1/;
        } else {
            $keyboard =~ m /(.)$i/;
            print qq/$1/;
        }}
}
print qq/\n/;

my @arr = ([split //,("qwertyuiop")],[split //,("asdfghjkl;")], [split //,"zxcvbnm,./"]);
chomp(my $ch  = <>);
$ch = $ch eq 'L' ? -1 : 1;
my @str = split //,<>;
pop @str;
my %key;
for my $i(0..2) {
    for my $j(0..9) {
        $key{$arr[$i][$j]} = $arr[$i][$j - $ch];
    }
}
print $key{$_} foreach(@str);

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

$delta = <> eq "R\n" ? -1:1;
@a = split //, "qwertyuiopasdfghjkl;zxcvbnm,./";
chomp($line = <>);
foreach $c(split //, $line) {
	foreach(0..$#a) {
		$a[$_] eq $c and print $a[$_+$delta] and last;
	}
}

my @arr = split /\s*/, "qwertyuiopasdfghjkl;zxcvbnm,./";

my (%l, %r);

for (my $i = 0; $i < @arr; $i++) {
    $l{$arr[$i]} = $arr[$i+1];
    $r{$arr[$i]} = $arr[$i-1];
}

chomp (my $k = <>);
chomp (my @in = split /\s*/, <>);
if ($k eq 'L') {
    printf "$l{$_}" foreach (@in);
} else {
    printf "$r{$_}" foreach (@in);
}
printf "\n";

use 5.016;
use strict;
use warnings;

sub left {
  $_[0] =~ tr{qwertyuioasdfghjklzxcvbnm,.}
             {wertyuiopsdfghjkl;xcvbnm,./}r;
}

sub right {
  $_[0] =~ tr{wertyuiopsdfghjkl;xcvbnm,./}
             {qwertyuioasdfghjklzxcvbnm,.}r;
}

my %dirs = (
  L => \&left,
  R => \&right,
);

chomp (my $dir = <>);
my $tr = $dirs{$dir};

my $msg = <>;
say $tr->($msg);

while($dirr=<>){

	$_="qwertyuiopasdfghjkl;zxcvbnm,./";

	for $i(split//,<>){
		$qi = quotemeta $i;
		($dirr =~ /R/ ? /(.)$qi/ : /$qi(.)/) and print $1
		}

	}

my $dir = <STDIN>;

if ($dir eq 'R'){

	print tr{wertyuiopasdfghjkl;zxcvbnm,./}{qwertyuiopasdfghjkl;zxcvbnm,.};

}else{

	print tr{qwertyuiopasdfghjkl;zxcvbnm,.}{wertyuiopasdfghjkl;zxcvbnm,./};

}

my $dir = <STDIN>;

$_ = <STDIN>;

if ($dir eq 'R'){

    print tr{wertyuiopasdfghjkl;zxcvbnm,./}{qwertyuiopasdfghjkl;zxcvbnm,.};

}else{

    print tr{qwertyuiopasdfghjkl;zxcvbnm,.}{wertyuiopasdfghjkl;zxcvbnm,./};

}

# author : Gabriel Hofer
use warnings;
use strict;
my $keyboard = q/qwertyuiopasdfghjkl;zxcvbnm,.\//;
if ( <STDIN> =~ m /L/ ) {
    chomp ( my $line = <STDIN> );
    for my $i ( split q//, $line ) {
       $keyboard =~ m /$i(.)/;
       print qq/$1/; }
} else {
    chomp ( my $line = <STDIN> );
    for my $i ( split q//, $line ) {
       $keyboard =~ m /(.)$i/;
       print qq/$1/; }
}
print qq/\n/;

my $d = <>;
my $str = <>;
my @ch = split "", "qwertyuiopasdfghjkl;zxcvbnm,./";
my $sh = $d eq "R"? 1 : -1;
my %m = ();
foreach my $i (0 .. scalar @ch)
{
    $m{$ch[$i]} = $ch[$i + $sh];
}

print map { $m{$_} } split "", $str;

my @arr = ([split //,("qwertyuiop")],[split //,("asdfghjkl;")], [split //,"zxcvbnm,./"]);
my $ch  = <> eq 'L' ? -1 : 1;
my @str = split //,<>;
pop @str;
my %key;
for my $i(0..2) {
    for my $j(0..9) {
        $key{$arr[$i][$j]} = $arr[$i][$j - $ch];
    }
}
print $key{$_} foreach(@str);

my @arr = split /\s*/, "qwertyuiopasdfghjkl;zxcvbnm,./";

my (%l, %r);

for (my $i = 0; $i < @arr; $i++) {
    $l{$arr[$i]} = $arr[$i-1];
    $r{$arr[$i]} = $arr[$i-1];
}

chomp (my $k = <>);
chomp (my @in = split /\s*/, <>);
if ($k eq 'L') {
    printf "$l{$_}" foreach (@in);
} else {
    printf "$r{$_}" foreach (@in);
}
printf "\n";


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $op = $x;

	for ( @_ ){
		$_ == $x and do {
			$op ++;
			last;
			};
		$_ < $x and do {
			$op --;
			next;
			};
		}

	print $op;
	}


$\ = $/;

while(<>){
	($n, $m) = split;
	while( $m ){
		unshift @m, $m;
		$m eq $n and last;
		$m < $n and ++ $f and last;
		$m =~ s/1$// and next;
		$m % 2 and ++ $f and last;
		$m /= 2;
		}

	print $f ? 'NO' :
		'YES' . "\n" . @m . "\n" . join ' ', @m;
	}


use strict;
use warnings;
use utf8;
$| =1;

my $n = <>;
my $a = [map {$_&1} split " ",<>];

NO() if $a->[0]==0 or $a->[$#$a]==0;
OK() if $n & 1 == 1;

can_be_diveded($a, 0) ? OK() : NO();

sub OK {
    print "yes";
    exit(0);
}

sub NO {
    print "no";
    exit(0);
}

sub can_be_diveded {
    my $array = shift;
    my $even_lenght_bit = shift;
    my $retval = 0;
    my $last = $#$array;
    if (!$even_lenght_bit and !($last & 1) and ($array->[$last] & 1) ){
        $retval = 1;
    }

    for (my $i=0; ($i+1) < $last and $retval == 1 ; $i+=2){
        if ($array->[$i] & $array->[$i+1]){
            $retval = 1 if can_be_diveded([@$array[($i+1)..$last]], !$even_lenght_bit);
            last if $retval == 1;
        }
    }
    $retval;
}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	if( @A % 2 and $A[0] % 2 and $A[-1] % 2 ){
		print "YES";
		}
	else{
		print "NO";
		}
	}

use strict;
use warnings;
use utf8;
$| =1;

my $n = <>;
my @a = map {$_&1} split " ",<>;

NO() if $a[0]==0 or $a[$#a]==0;
OK() if $n & 1 == 1;

my $blockNum = 0;
for (my $i=0;$i<($n-1) and $blockNum < 2;$i++){
    $blockNum++ if ($a[$i] & $a[$i+1]);
}
OK() if $blockNum > 1;
NO();

sub OK {
    print "yes";
    exit(0);
}

sub NO {
    print "no";
    exit(0);
}


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

my $n = <> + 0;
my $isEasy = 1;
my $line = <>;

my @numbers = split ' ', $line;

foreach my $number (@numbers) {
    if($number == 1) {
        $isEasy = 0;
    }
}

if($isEasy) {
    print "EASY\n";
} else {
    print "HARD\n";
}

use strict;
my $n = <>;
my @a = split(' ', <>);
for (my $i = 0; $i <= $#a; $i++){
  if($a[$i] == 1){
    print "HARD";
    exit(0);
  }
}
print "EASY";

#!/usr/bin/env perl

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

# essential
my @tokens = ();

my $n = read_token();
my $m = 0;

for ( 1..$n ) {
    $m = max($m, read_token());
}

if ( $m == 1 ) {
    say "hard";
}
else {
    say "easy";
}

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

#!perl -w
use strict;
use warnings;

my ($i, $num, $str, $flag);
my (@arr_str, $len);

$num = <STDIN>;
chomp $num;

$str = <STDIN>;
chomp $str;

@arr_str = $str =~ /\d/g;
$len = @arr_str;

$flag = 0; # Если flag == 0, то задача легкая

for ($i  = 0; $i < $len; $i++) {
	if($arr_str[$i]) {
		$flag = 1;
		last;
	}
}

if($flag) {
	print "HARD";
}
else {
	print "EASY";}

exit 0;

#!/usr/bin/env perl

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

# essential
my @tokens = ();

my $n = read_token();
my $m = 0;

for ( 1..$n ) {
    $m = max($m, read_token());
}

if ( $m == 1 ) {
    say "hard";
}
else {
    say "easy";
}

say $n;

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

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

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

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

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


use strict;
use warnings;

my ($x, $y, $s) = split / /, <>;

if ($s < abs($x) + abs($y)){print "No"}
else
{
unless($s % 2 == ($x + $y) %2) {print "No" }
else {print "Yes";}
}

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

my ($x,$y,$s) = split ' ',<>;
my $sum = abs($x) + abs($y);
if($s < $sum){print "No\n";}
else{ print ( ($s-$sum)&1? "No\n" : "Yes\n" );}

use strict;
use warnings;

my $A = <STDIN>;
my ($a,$b,$s) = (split(" ", $A));

if( $s >= abs($a) + abs($b) and ($s - abs($a) - abs($b))%2 eq 0 ) {
	print "Yes";
	exit 0;
}

print "No";

use strict;
use warnings;

my ($x, $y, $s) = split / /, <>;

if ($s < $x + $y){print "No"}
else
{
unless($s % 2 == ($x + $y) %2) {print "No" }
else {print "Yes";}
}

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

my ($x,$y,$s) = split ' ',<>;
if($s < $x+$y){print "No\n";}
else{ print (($s-($x+$y))&1? "No\n" : "Yes\n");}

use strict;
use warnings;

my ($a,$b,$s);

$a = <STDIN>; $b = <STDIN>; $s = <STDIN>;
if( $s >= abs($a) + abs($b) and ($s - abs($a) - abs($b))%2 eq 0 ) {
	print "Yes";
}

print "No";


#!/usr/bin/perl
# POPITKA № 9998

my $a = <STDIN>;

while ($a > 0){
$result+= $a%2;
$a--;}

print $result-1;

my $n = <STDIN>;
$n-- if ($n % 2 == 0);
use integer;
print ($n/2);

#!/usr/bin/perl
#BOG PERLA NA SVYAZI

    my $a = <STDIN>;
    my $check = $a;

    while ($a > 0){
    $b = $a; $a--; $c = $a;
    $result+= ($b+$c)%(2+1);
    $a--;
    }

    if ($check%2 == 0){
    print $result;}
    else {
    print $result-1;}

#!/usr/bin/perl
#BOG PERLA NA SVYAZI

my $a = 31809;

while ($a > 0){
$result+= $a%2;
$a--;}

print $result-1;

#!/usr/bin/perl
#BOG PERLA NA SVYAZI

    my $a = <STDIN>;
    my $check = $a;

    while ($a >= 0){
    $b = $a; $a--; $c = $a;
    $result+= ($b+$c)%(2+1);
    $a--;
    }

    if ($check%2 == 0){
    print $result;}
    else {
    print $result-1;}


print eval sprintf "1 + ( %d + %d - 1 ) %% %d", reverse split ' ', <>


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $sum = eval join ' + ', split //;

	my $ok = 0;

	for my $i ( 2 .. 100 ){
		my $d = $sum / $i;
		next if $d =~ /\./;

		my $s = 0;
		my $c = 0;

		while( /./g ){
			$s += $&;
			if( $s == $d ){
				$c ++;
				$s = 0;
				}
			}

		$i == $c and do {
			$ok = 1;
			last;
			};
		}

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


use strict;
use Data::Dumper;
use POSIX;

my $input = <>;

my ($n, $m, $a) = split(/ /, $input);

printf('%11.0f', paveSquare($n, $m, $a));

sub paveSquare {
	my ($n, $m, $a) = @_;
	return ceil($n / $a) * ceil($m / $a);
}

#!/usr/bin/env perl
# perl learning...
package Codeforces::contest1::A;
use warnings;
#use List::Util qw[min max];
use v5.20;
sub input
    { return <>; }

sub ceildiv {
    my ($a, $b) = @_;
    return int($a / $b) + ($a % $b != 0);
}

sub main {
    my ($n, $m, $a) = split(" ", input());
    print(int(ceildiv($n, $a)) * int(ceildiv($m, $a)), "\n");
}

main();

use strict;
use Data::Dumper;
use POSIX;

my $input = <>;

my ($n, $m, $a) = split(/ /, $input);

printf('%11.0f', paveSquare($n, $m, $a));

sub paveSquare {
	my ($n, $m, $a) = @_;
	my $counter = 0;

	if ($n > $m) {
		my $k = $n;
		$n = $m;
		$m = $k;
	}
	$counter += ceil($n / $a);
	$counter *= ceil($m / $a);
	return ceil($n / $a) * ceil($m / $a);
}

use strict;
use Data::Dumper;
use POSIX;

my $input = <>;

my ($n, $m, $a) = split(/ /, $input);

printf('%11.0f', paveSquare($n, $m, $a));

sub paveSquare {
	my ($n, $m, $a) = @_;
	my $counter = 0;

	if ($n > $m) {
		my $k = $n;
		$n = $m;
		$m = $k;
	}
	my $remain = $m - $n;
	$counter += ceil($n / $a);
	warn $counter;
	$counter *= ceil($m / $a);
	return $counter;
}

use bigint;($a,$b,$c)=split' ',<>;sub t{((shift)-1)/$c+1};print t($a)*t$b

use strict;
use bigint;

my ($n, $m, $a) = split /\s+/, <STDIN>;
my $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );

print $result, "\n";

use strict;
use bigint;

my ($n, $m, $a) = split /\s+/, <STDIN>;
my $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );

print $result, "\n";

my $a;

use Math::BigInt;
use POSIX(ceil);
$_ = <>;
@a = split;
print Math::BigInt->new(ceil($a[0] / $a[2]) * ceil($a[1] / $a[2]));

my ($n, $m, $a) =
  split " ", <STDIN>;

sub ceil{
  $x = shift;
  if($x == int($x)){
    $x;
  }else{
    int($x)+1;
  }
}

print ceil($n / $a) * ceil($m/$a), "\n";

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

my $n;
my $m;
my $a;

my $line = <STDIN>;

($n, $m, $a) = split / +/, $line;

say int(($m + $a - 1) / $a) * int(($n + $a - 1) / $a);

use strict;
use warnings;

my $input = <STDIN>;

my @t = split(/ /,$input);
my $n = $t[0];
my $m = $t[1];
my $a = $t[2];

my $res =  int(($m+$a-1) / $a) * int(($n+$a-1) / $a);

print "$res\n";

use strict;
use bigint;

my( $str );
$str = <STDIN>;
my ($n, $m, $a) = split / /, $str;

my($na, $ma);

print int(($n+$a-1)/$a)*int(($m+$a-1)/$a)

#!/usr/bin/perl -w
use strict;
use warnings;
use POSIX qw{ceil};
my ($n, $m, $a) = map int, split /\D/, <>;
print sprintf "%.0f", (ceil ($n/$a) * ceil ($m/$a));

# Author Badhan Sen
# CSE-14, JUST

# 1A Theatre Square

my $n, $m, $a;

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

$x=int($n/$a);
$y=int($m/$a);

if($n%$a!=0){
	$x++;
}

if($m%$a!=0){
	$y++;
}

$ans=$x*$y;
print $ans;

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

my $n;
my $m;
my $a;

my $line = <STDIN>;

($n, $m, $a) = split / / , $line;
say int(($n+$a-1)/$a)  * int(($m+$a-1)/$a);

use bigint;

my ($m, $n, $a)  = split(' ', <>);
my $wid = int ( $m/$a ) + ( $m % $a ? 1 : 0 );
my $height = int ( $n/$a ) + ( $n % $a ? 1 : 0 );
print $wid * $height;

#!/usr/bin/perl
use POSIX;
use Math::BigInt;
@l = split ' ', <>;
$m = ceil($l[0]/$l[2]);
$n = ceil($l[1]/$l[2]);
$" = Math::BigInt->new($m*$n);
print $";

use strict;
use warnings;
use Math::BigFloat;

my $input = do { local $/; scalar <> };
my ($n, $m, $a) = split /\s+/s, $input;

my ($dm, $dn) = map { ceil( $_ , $a ) } $m, $n;

print $dn * $dm;

sub ceil {
  my ( $x , $a ) = @_;
  my $frac = Math::BigFloat->new( $x )->bdiv($a);
  return 1 if $frac < 1;
  return $frac->bceil;
}

#!/usr/bin/env perl

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

sub main {
    my %args = @_;

    my $input = readline(STDIN);
    chomp $input;
    my ($n, $m, $a) = split(/\s+/, $input);
    my $n_tile = int($n / $a) + !!($n % $a);
    my $m_tile = int($m / $a) + !!($m % $a);

    say $n_tile * $m_tile;

    return;
}

main();

exit;

  use bigint;
  $_ = <>;
  my @arr = split/\s+/;
  #print @arr;
  my $tiles1 = 0;
  my $tiles2 = 0;
  {
    use integer;
    $tiles1 += $arr[0]/$arr[2];
    $tiles2 += $arr[1]/$arr[2];
  }
  if ($arr[0]%$arr[2] != 0) {
    $tiles1 += 1;
  }
  if ($arr[1]%$arr[2] != 0) {
    $tiles2 += 1;
  }
  my $tiles = $tiles1*$tiles2;
  print "$tiles\n";
  exit 0;

use strict;
use bigint;

my ($n, $m, $a) = split /\s+/, <STDIN>;
my $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );

print $result, "\n";

my $f;

#fdlgkjjgkjhkuggsjkhkkhgjhgkjguyfuyljhkjgchjyfjhgj

use strict;
use bigint;

my ($n, $m, $a) = split /\s+/, <STDIN>;
my $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );

print $result, "\n";

my $f;

#fdlgkjjgkjhkuggsjkhkkhgjhgkjgukljhlkjyfuyljhkjgchjyfjhgj

use strict;
use bigint;

my ($n, $m, $a) = split /\s+/, <STDIN>;
my $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );

print $result, "\n";

my $f;

#fdlgkjjgkjhkljhkjgchjyfjhgj

use strict;
use bigint;

my ($n, $m, $a) = split /\s+/, <STDIN>;
my $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );

print $result, "\n";

use strict;
use bigint;

my ($n, $m, $a) = split /\s+/, <STDIN>;
my $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );

print $result, "\n";

my $f;

#fdlgkjjgkjhkuggjhlkjyfuyljhkjgchjyfjhgj

use Math::BigInt;
$input = <STDIN>;

## $xx[0] : n / $xx[1] : m / $xx[2] : a
@xx = split(" ",$input);

$hh = Math::BigInt->new(int($xx[0] / $xx[2]));
if ($xx[0] % $xx[2]) {Math::BigInt->new($hh++);}

$ww = Math::BigInt->new(int($xx[1] / $xx[2]));
if ($xx[1] % $xx[2]) {Math::BigInt->new($ww++);}

print Math::BigInt->new($hh*$ww);
exit;

#!/usr/bin/perl
# your code goes here
use bigint;

($n, $m, $a) = split / /, <>;
# print "$n $m $a";
$ans = (($n+$a-1)/$a) * (($m+$a-1)/$a);
print $ans;

use Math::BigInt;
use bigint;
my $data = <STDIN>;
my (@data) = split (" ", $data);

my $n = shift (@data);
my $m = shift (@data);
my $a = shift (@data);

my $ma = $m/$a;
my $na = $n/$a;

if (int($ma) != $ma) {
    $ma = int($ma) +1;
}

if (int($na) != $na) {
    $na = int($na) +1;
}

$x = Math::BigInt->new($ma*$na);
print $x;

use bigint;
my($n, $m, $a) = split(" ", <STDIN>);
print int(($n + $a -1) / $a) * int(($m + $a -1) / $a);

#!/usr/bin/perl

use strict;
use warnings;

my ($m, $n, $a);
my @input;
my ($x, $y);

while (<STDIN>) {
    chomp;
    ($m, $n, $a) = split ' ';
    if ($m % $a) {
        $x= int($m/$a)+1;
    } else {
        $x = $m/$a;
    }

    if ($n % $a) {
        $y = int($n/$a)+1;
    } else {
        $y = $n/$a;
    }

#    print "$m $n $x $y\n";
    print $x*$y,"\n";
}

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

sub ceil { my $j = $_[0]; my $i = int $j; $i < $j ? $i + 1 : $i }

my ($n, $m, $a) = split ' ', <STDIN>;
print ceil($n / $a) * ceil($m / $a) . "\n"

use strict;
use warnings;

#use POSIX qw(ceil);

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

# cover n x m meters with ? number of stones of size a x a.
# calculate how many stones needed in n direction and then in m direction.

my $n_stones = int( $n / $a ) + ( $n % $a > 0 ? 1 : 0 );
my $m_stones = int( $m / $a ) + ( $m % $a > 0 ? 1 : 0 );
my $needed_stones = $n_stones * $m_stones;
#print int($n_stones);
#print int($m_stones);
print "$needed_stones\n";

#!/usr/bin/perl

use strict;
use warnings;

use v5.10;

my $line = <>;
chomp $line;
my ($n, $m, $a) = split /\s+/, $line;

my $w = int($n/$a) + ($n % $a == 0 ? 0 : 1);
my $l = int($m/$a) + ($m % $a == 0 ? 0 : 1);

say ( $w * $l );

use strict;
use warnings;

use Data::Dumper;

my $line = <STDIN>;

my ($n, $m, $a) = split(/\s+/, $line);

$n += $n % $a ? $a - $n % $a : 0;
$m += $m % $a ? $a - $m % $a : 0;

printf("%.0f\n", (($n/$a) * ($m/$a)));

use strict;
use warnings;
use utf8;
use Math::BigInt;

my $stdin=<STDIN>;
chomp($stdin);
my @in=split(" ", $stdin);

my $h=int($in[0]/$in[2]);
$h++	unless($in[0]%$in[2]==0);

my $w=int($in[1]/$in[2]);
$w++	unless($in[1]%$in[2]==0);

print Math::BigInt->new($h*$w)."\n";

#! /usr/bin/env perl
use 5.012;
use bignum;
use List::Util;

my ($n, $m, $a) = split /\s/, <STDIN>;
say int(($n+$a-1) / $a) * int(($m+$a-1) / $a);

#!/usr/bin/perl
use strict;
use warnings;
use bignum;
my $input=<stdin>;
my ($m,$n,$a)=split " ",$input;
my $d1=$m%$a?1:0;
my $d2=$n%$a?1:0;
my $output=(int $m/$a+$d1)*(int $n/$a+$d2);
print $output;

#!/usr/bin/perl
use strict;
use warnings;
#use POSIX qw(ceil);

#my ($m, $n, $a) = ($ARGV[0], $ARGV[1], $ARGV[2]);  #(7,6,4);
my $userinput =  <STDIN>; #read stdin and put it in $userinput
chomp ($userinput);    #cut the return / line feed character
my ($m, $n, $a) = split(/\s+|,/, $userinput);

my $add1 = ($m%$a>0)?1:0;
my $add2 = ($n%$a>0)?1:0;
my $ret = int($m/$a + $add1)  *  int($n/$a + $add2);
printf "%.0f",  $ret;

use POSIX qw(ceil);
use Math::BigInt;
($n,$m,$a)=split (' ',<STDIN>);
print Math::BigInt->new(ceil($n/$a)*ceil($m/$a));

use strict;
use bigint;

my ($n, $m, $a) = split /\s+/, <STDIN>;
my $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );

print $result, "\n";

use strict;
use bigint;

my ($n, $m, $a) = split /\s+/, <STDIN>;
my $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );

print $result, "\n";

my $f;

#fdlgkjjgkjhkuggsjkhkkhgjhgkjguyfuygchjyfjhgj

#!perl

use strict;
use warnings;

sub myceil {

   my ($num) = @_;
   my $diff = $num - int($num);
   my $ret = $diff ? int($num+0.99999999999999) : $num;
   #print "ceil of $num is $ret\n";
   $ret;
}

my  $n;
my  $m;
my  $a;
while (<>) {
   chomp;
   ($n, $m, $a) = split(/ /);
   last;
}

my $r1 = myceil($n/$a);
my $r2 = myceil($m/$a);
#use POSIX;
#die "$r1" if ($r1 != ceil($n/$a));
#die "$r2" if ($r2 != ceil($m/$a));
my $area = $r1 * $r2;
$area = 1 if ($area < 1);
print "$area\n";

exit(0);

my @items = split / /, <>;
printf "%d\n", int(($items[0]+$items[2]-1)/$items[2]) * int(($items[1]+$items[2]-1)/$items[2]);

use bigint;

my ($n, $m, $a) = split /\s+/, <STDIN>;

my $h = (int $n/$a) + !!($n % $a);
my $w = (int $m/$a) + !!($m % $a);

my $area = $h * $w;

printf "%.0f", $area;

#!/usr/bin/env perl

use strict;
use warnings;
use integer;

my $line = <STDIN>;

my ($h, $w, $a);
if ($line =~ /(\d+) (\d+) (\d+)/) {
	$h = $1;
	$w = $2;
	$a = $3;
}
my $ver = $h / $a + ($h % $a != 0);
my $hor = $w / $a + ($w % $a != 0);
print $ver * $hor;

use strict;
use Data::Dumper;
use POSIX;

my $input = <>;

my ($n, $m, $a) = split(/ /, $input);

warn $n;
warn $m;
warn $a;
print paveSquare($n, $m, $a);

sub paveSquare {
	my ($n, $m, $a) = @_;
	my $counter = 0;
	$counter += ceil($n / $a);
	$counter += ceil($m / $a);
	return $counter;
}

use strict;
use Data::Dumper;
use POSIX;

my $input = <>;

my ($n, $m, $a) = split(/ /, $input);

printf('%011.0f', paveSquare($n, $m, $a));

sub paveSquare {
	my ($n, $m, $a) = @_;
	my $counter = 0;

	if ($n > $m) {
		my $k = $n;
		$n = $m;
		$m = $k;
	}
	my $remain = $m - $n;
	$counter += ceil($n / $a);
	warn $counter;
	$counter *= ceil($m / $a);
	return $counter;
}

use strict;
use Data::Dumper;
use POSIX;

my $input = <>;

my ($n, $m, $a) = split(/ /, $input);

print paveSquare($n, $m, $a);

sub paveSquare {
	my ($n, $m, $a) = @_;
	my $counter = 0;
# 	$counter += ceil($n / $a);
#
# 	my $remain = ceil($m / $a);
# 	return $counter;
	if ($n > $m) {
		my $k = $n;
		$n = $m;
		$m = $k;
	}
	my $remain = $m - $n;
	$counter += ceil($n / $a) ** 2;
	$counter += ceil($n / $a) * ceil($remain / $a);
	return $counter;
}

use POSIX qw(ceil);
($n,$m,$a)=split (' ',<STDIN>);
print ceil($n/$a)*ceil($m/$a);

#!/usr/bin/perl
use strict;
use warnings;
#use POSIX qw(ceil);

#my ($m, $n, $a) = ($ARGV[0], $ARGV[1], $ARGV[2]);  #(7,6,4);
my $userinput =  <STDIN>; #read stdin and put it in $userinput
chomp ($userinput);    #cut the return / line feed character
my ($m, $n, $a) = split(/\s+|,/, $userinput);

my $add = ($m%$a>0)?1:0;
my $ret = int($m/$a + $add)  *  int($n/$a + $add);
printf "%.0f",  $ret;

use strict;

my( $str );
$str = <STDIN>;
my ($n, $m, $a) = split / /, $str;

my($na, $ma);

print int(($n+$a-1)/$a)*int(($m+$a-1)/$a);

  $_ = <>;
  my @arr = split/\s+/;
  #print @arr;
  my $tiles1 = 0;
  my $tiles2 = 0;
  {
    use integer;
    $tiles1 += $arr[0]/$arr[2];
    $tiles2 += $arr[1]/$arr[2];
  }
  if ($arr[0]%$arr[2] != 0) {
    $tiles1 += 1;
  }
  if ($arr[1]%$arr[2] != 0) {
    #$tiles += 1;
  }
  my $tiles = $tiles1*$tiles2;
  print "$tiles\n";
  exit 0;

use strict;
use warnings;
use utf8;

my $stdin=<STDIN>;
chomp($stdin);
my @in=split(" ", $stdin);

my $h=int($in[0]/$in[2]);
$h++	unless($in[0]%$in[2]==0);

my $w=int($in[1]/$in[2]);
$w++	unless($in[1]%$in[2]==0);

print $h * $w."\n";

use strict;
use warnings;

#use POSIX qw(ceil);

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

# cover n x m meters with ? number of stones of size a x a.
# calculate how many stones needed in n direction and then in m direction.

my $n_stones = int( $n / $a + 0.99 );
my $m_stones = int( $m / $a + 0.99 );
my $needed_stones = $n_stones * $m_stones;

print "$needed_stones\n";

use strict;
use warnings;

use Data::Dumper;

my $line = <STDIN>;

my ($n, $m, $a) = split(/\s+/, $line);

$n += $n % $a ? $a - $n % $a : 0;
$m += $m % $a ? $a - $m % $a : 0;

print (($n/$a) + ($m/$a));
print "\n";

#!/usr/bin/perl
# your code goes here
use integer;

($n, $m, $a) = split / /, <>;
# print "$n $m $a";
$ans = (($n+$a-1)/$a) * (($m+$a-1)/$a);
print $ans;

#!/usr/bin/env perl

my ($n, $m, $a) = split /\s+/, <STDIN>;

my $h = (int $n/$a) + !!($n % $a);
my $w = (int $m/$a) + !!($m % $a);

print $h * $w

#!/usr/bin/perl
use POSIX;
use bigint;
@l = split ' ', <>;
$m = ceil($l[0]/$l[2]);
$n = ceil($l[1]/$l[2]);
$" = $m*$n;
print $";

use bigint;

my $input = do { local $/; scalar <> };
my ($n, $m, $a) = split /\s+/s, $input;

my ($dm, $dn) = map { ceil( $_ / $a ) } $m, $n;

printf "%d\n", $dn * $dm;

sub ceil {
  my ( $x ) = @_;
  return 1 if $x < 1;
  return int( $x ) < $x ? int($x) + 1 : int $x;
}

#!/usr/bin/perl

$input_line = <STDIN>;
chop($input_line);
($n,$m,$a)=split(/ /,$input_line);
$ni = int($n/$a);
$mi = int($m/$a);
$i = $ni*$mi;
$size = ($n*$m)-($i*$a);
if ($size == ($n*$m)) {$i++;}
elsif ($size != 0){$i += ($ni+$mi+1);}
print("$i\n");

#!/usr/bin/perl -w
use strict;
use warnings;
use POSIX qw{ceil};
my ($n, $m, $a) = map int, split /\D/, <>;
print int (ceil ($n/$a) * ceil ($m/$a));

use strict;

my( $str );
$str = <STDIN>;
my ($n, $m, $a) = split / /, $str;

my ($na, $ma );

if( $n%$a != 0 ) {
    $na = int( ($n+$a)/$a )
} else {
    $na = $n/$a
}

if( $m%$a != 0 ) {
    $ma = int( ($m+$a)/$a )
} else {
    $ma = $m/$a
}

print $na*$ma;

use bigint;
use POSIX(ceil);
$_ = <>;
@a = split;
print ceil($a[0] / $a[2]) * ceil($a[1] / $a[2]);

use strict;

my ($n, $m, $a) = split /\s+/, <STDIN>;
my $result = int( ( $n - 1 ) / $a + 1 ) * int( ( $m - 1 ) / $a + 1 );

print $result, "\n";

#!/usr/bin/perl -w
use strict;
use warnings;
use POSIX qw{ceil};
my ($n, $m, $a) = map int, split /\D/, <>;
print sprintf "%d", (ceil ($n/$a) * ceil ($m/$a));

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

my $n = shift (@data);
my $m = shift (@data);
my $a = shift (@data);

my $ma = $m/$a;
my $na = $n/$a;

if (int($ma) != $ma) {
    $ma = int($ma) +1;
}

if (int($na) != $na) {
    $na = int($na) +1;
}

$x = $ma*$na;
print $x;

use strict;
use Data::Dumper;
use POSIX;

my $input = <>;

my ($n, $m, $a) = split(/ /, $input);

print paveSquare($n, $m, $a);

sub paveSquare {
	my ($n, $m, $a) = @_;
	my $counter = 0;

	if ($n > $m) {
		my $k = $n;
		$n = $m;
		$m = $k;
	}
	my $remain = $m - $n;
	$counter += ceil($n / $a);
	warn $counter;
	$counter *= ceil($m / $a);
	return int($counter);
}

use bigint;

sub ceil {
    if ( @_[0] > (int @_[0]) ) {
	return (int ( @_[0] ) + 1); }
    else {
	return ( @_[0] ) }
}

my $f = <STDIN>;
my $one;
my $two;
my $thr;

if ( $f =~ m/(\d)+ (\d)+ (\d)+/ ) {
    $one = $1;
    $two = $2;
    $thr = $3; }

my $ans = &ceil ( $one / $thr ) * &ceil ( $two / $thr );
print $ans . "\n";

#!/usr/bin/perl
use integer;
($n,$m,$a)=split' ',<>;
$answer = ($n*$m)/($a*$a);
print "$answer";

use strict;
use warnings;

#use POSIX qw(ceil);

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

# cover n x m meters with ? number of stones of size a x a.
# calculate how many stones needed in n direction and then in m direction.

my $n_stones = int( $n / $a + 0.999999999999 );
my $m_stones = int( $m / $a + 0.999999999999 );
my $needed_stones = $n_stones * $m_stones;

print "$needed_stones\n";

use strict;
use warnings;

use Data::Dumper;

my $line = <STDIN>;

my ($n, $m, $a) = split(/\s+/, $line);

$n += $n % $a ? $a - $n % $a : 0;
$m += $m % $a ? $a - $m % $a : 0;

print (($n/$a) * ($m/$a));
print "\n";

#!/usr/bin/perl
use POSIX;
use bigint;
@l = split ' ', <>;
$m = ceil($l[0]/$l[2]);
$n = ceil($l[1]/$l[2]);
$" = $m*$n;
print $";

#!/usr/bin/env perl

use strict;
use warnings;
use integer;

my $line = <STDIN>;

my ($height, $width, $a);
if ($line =~ /(\d+) (\d+) (\d+)/) {
	$height = $1;
	$width = $2;
	$a = $3;
}
print (($height / $a) + 1 + ($width / $a) + 1);

use strict;
use warnings;

#use POSIX qw(ceil);

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

# cover n x m meters with ? number of stones of size a x a.
# calculate how many stones needed in n direction and then in m direction.

my $n_stones = ( $n / $a ) + ( $n % $a > 0 ? 1 : 0 );
my $m_stones = ( $m / $a ) + ( $n % $a > 0 ? 1 : 0 );
my $needed_stones = int($n_stones) * int($m_stones);

print "$needed_stones\n";

#!/usr/bin/perl

$input_line = <STDIN>;
chop($input_line);
($n,$m,$a)=split(/ /,$input_line);
$ni = int($n/$a);
$mi = int($m/$a);
$i = $ni*$mi;
$size = ($n*$m)-($i*$a);
if ($size != 0){$i += ($ni+$mi+1);}
print("$i\n");

#!perl

#use strict;
#use warnings;

my  $n;
my  $m;
my  $a;
while (<>) {
   chomp;
   ($n, $m, $a) = split(/ /);
   last;
}

my $r1 = sprintf("%.0f", $n/$a);
my $r2 = sprintf("%.0f", $m/$a);
my $area = $r1 * $r2;
$area = 1 if ($area < 1);
print "$area\n";

exit(0);