Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.

The input contains three positive integer numbers in the first line: n,  m and a (1 ≤  n, m, a ≤ 109).

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)

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

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($n, $m, $a) = split(" ", <STDIN>);
print int(($n + $a -1) / $a) * int(($m + $a -1) / $a);

#!/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;

#!/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";
}

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

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;

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 $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";

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

#!/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 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";

my $f;

#fdlgkjjgkjhkuggjhlkjyfuyljhkjgchjyfjhgj

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

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;

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;

#!/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"

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

#!/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 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 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);
}

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

#!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;

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

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


Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland.Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is working.It is known that the garland contains light bulbs of four colors: red, blue, yellow and green. The garland is made as follows: if you take any four consecutive light bulbs then there will not be light bulbs with the same color among them. For example, the garland can look like "RYBGRYBGRY", "YBGRYBGRYBG", "BGRYB", but can not look like "BGRYG", "YBGRYBYGR" or "BGYBGY". Letters denote colors: 'R' — red, 'B' — blue, 'Y' — yellow, 'G' — green.Using the information that for each color at least one light bulb still works count the number of dead light bulbs of each four colors.

The first and the only line contains the string s (4 ≤ |s| ≤ 100), which describes the garland, the i-th symbol of which describes the color of the i-th light bulb in the order from the beginning of garland:    'R' — the light bulb is red,  'B' — the light bulb is blue,  'Y' — the light bulb is yellow,  'G' — the light bulb is green,  '!' — the light bulb is dead.  The string s can not contain other symbols except those five which were described.  It is guaranteed that in the given string at least once there is each of four letters 'R', 'B', 'Y' and 'G'.  It is guaranteed that the string s is correct garland with some blown light bulbs, it means that for example the line "GRBY!!!B" can not be in the input data.

In the only line print four integers kr, kb, ky, kg — the number of dead light bulbs of red, blue, yellow and green colors accordingly.

NoteIn the first example there are no dead light bulbs.In the second example it is obvious that one blue bulb is blown, because it could not be light bulbs of other colors on its place according to the statements.


Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it.  The painting is a square 3 × 3, each cell contains a single integer from 1 to n, and different cells may contain either different or equal integers.  The sum of integers in each of four squares 2 × 2 is equal to the sum of integers in the top left square 2 × 2.  Four elements a, b, c and d are known and are located as shown on the picture below. Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong.Two squares are considered to be different, if there exists a cell that contains two different integers in different squares.

The first line of the input contains five integers n, a, b, c and d (1 ≤ n ≤ 100 000, 1 ≤ a, b, c, d ≤ n) — maximum possible value of an integer in the cell and four integers that Vasya remembers.

Print one integer — the number of distinct valid squares.

NoteBelow are all the possible paintings for the first sample.  In the second sample, only paintings displayed below satisfy all the rules.


To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.The parking lot before the office consists of one line of (2n - 2) parking spaces. Unfortunately the total number of cars is greater than the parking lot capacity. Furthermore even amount of cars of each make is greater than the amount of parking spaces! That's why there are no free spaces on the parking lot ever.Looking on the straight line of cars the company CEO thought that parking lot would be more beautiful if it contained exactly n successive cars of the same make. Help the CEO determine the number of ways to fill the parking lot this way.

The only line of the input contains one integer n (3 ≤ n ≤ 30) — the amount of successive cars of the same make.

Output one integer — the number of ways to fill the parking lot by cars of four makes using the described way.

NoteLet's denote car makes in the following way: A — Aston Martin, B —   Bentley, M — Mercedes-Maybach, Z — Zaporozhets. For n = 3 there are the following appropriate ways to fill the parking lot: AAAB AAAM AAAZ ABBB AMMM AZZZ BBBA BBBM BBBZ BAAA BMMM BZZZ MMMA MMMB MMMZ MAAA MBBB MZZZ ZZZA ZZZB ZZZM ZAAA ZBBB ZMMMOriginally it was planned to grant sport cars of Ferrari, Lamborghini, Maserati and Bugatti makes but this idea was renounced because it is impossible to drive these cars having small road clearance on the worn-down roads of IT City.

#!/usr/bin/env perl

use bigint;

sub factorial {
    my $n = shift;
    if ($n==0) {
        return 1;
    } else {
        return $n*factorial($n-1);
    }
}

sub subfactorial {
    my $n = shift;
    my $sub = shift;
    if ($n==$sub) {
        return 1;
    } else {
        return $n*subfactorial($n-1, $sub);
    }
}

$n = <STDIN>;
$result = 2*4*3*(4**($n-3));
$result += ($n-3)*4*(3**2)*(4**($n-4)) if $n > 3;
print "$result\n";

#!/usr/bin/env perl

use bigint;

sub factorial {
    my $n = shift;
    if ($n==0) {
        return 1;
    } else {
        return $n*factorial($n-1);
    }
}

sub subfactorial {
    my $n = shift;
    my $sub = shift;
    if ($n==$sub) {
        return 1;
    } else {
        return $n*subfactorial($n-1, $sub);
    }
}

$n = <STDIN>;
$result = ($n-1)*4*(3**($n-2));
print "$result\n";


You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can be decorated if we know number of balloons of each color?Your task is to write a program that for given values r, g and b will find the maximum number t of tables, that can be decorated in the required manner.

The single line contains three integers r, g and b (0 ≤ r, g, b ≤ 2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.

Print a single integer t — the maximum number of tables that can be decorated in the required manner.

NoteIn the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively.

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

use bigint;

my @cnt = split / /, <>;
@cnt = sort {$a <=> $b} @cnt;
$ans = int (($cnt[0] + $cnt[1] + (min ($cnt[2], 2 * ($cnt[0] + $cnt[1])))) / 3);
print $ans, "\n";

use List::Util qw(min max);

use bigint;
use integer;

my @cnt = split / /, <>;
@cnt = sort {$a <=> $b} @cnt;
my $ans = $cnt[0];
$cnt[1] -= $cnt[0];
$cnt[2] -= $cnt[0];
$ans += min ($cnt[1], $cnt[2], ($cnt[1] + $cnt[2]) / 3);
print $ans, "\n";

use List::Util qw(min max);

use bigint;
use integer;

my @cnt = split / /, <>;
@cnt = sort @cnt;
my $ans = $cnt[0];
$cnt[1] -= $cnt[0];
$cnt[2] -= $cnt[0];
$ans += min ($cnt[1], $cnt[2] / 2);
print $ans, "\n";

use List::Util qw(min max);

use bigint;
use integer;

my @cnt = split / /, <>;
@cnt = sort @cnt;
my $ans = $cnt[0];
$cnt[1] -= $cnt[0];
$cnt[2] -= $cnt[0];
$ans += min ($cnt[1], $cnt[2], ($cnt[1] + $cnt[2]) / 3);
print $ans, "\n";

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

use bigint;
use integer;

my @cnt = split / /, <>;
@cnt = sort {$a <=> $b} @cnt;
$ans = ($cnt[0] + $cnt[1] + (min ($cnt[2], 2 * ($cnt[0] + $cnt[1])))) / 3;
print $ans, "\n";

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

use bigint;
use integer;

my @cnt = split / /, <>;
@cnt = sort {$a <=> $b} @cnt;
$cnt[2] = min ($cnt[2], 2 * ($cnt[0] + $cnt[1]));
$ans = (sum @cnt) / 3;
print $ans, "\n";


When Valera was playing football on a stadium, it suddenly began to rain. Valera hid in the corridor under the grandstand not to get wet. However, the desire to play was so great that he decided to train his hitting the ball right in this corridor. Valera went back far enough, put the ball and hit it. The ball bounced off the walls, the ceiling and the floor corridor and finally hit the exit door. As the ball was wet, it left a spot on the door. Now Valera wants to know the coordinates for this spot.Let's describe the event more formally. The ball will be considered a point in space. The door of the corridor will be considered a rectangle located on plane xOz, such that the lower left corner of the door is located at point (0, 0, 0), and the upper right corner is located at point (a, 0, b) . The corridor will be considered as a rectangular parallelepiped, infinite in the direction of increasing coordinates of y. In this corridor the floor will be considered as plane xOy, and the ceiling as plane, parallel to xOy and passing through point (a, 0, b). We will also assume that one of the walls is plane yOz, and the other wall is plane, parallel to yOz and passing through point (a, 0, b).We'll say that the ball hit the door when its coordinate y was equal to 0. Thus the coordinates of the spot are point (x0, 0, z0), where 0 ≤ x0 ≤ a, 0 ≤ z0 ≤ b. To hit the ball, Valera steps away from the door at distance m and puts the ball in the center of the corridor at point . After the hit the ball flies at speed (vx, vy, vz). This means that if the ball has coordinates (x, y, z), then after one second it will have coordinates (x + vx, y + vy, z + vz).See image in notes for clarification.When the ball collides with the ceiling, the floor or a wall of the corridor, it bounces off in accordance with the laws of reflection (the angle of incidence equals the angle of reflection). In the problem we consider the ideal physical model, so we can assume that there is no air resistance, friction force, or any loss of energy.

The first line contains three space-separated integers a, b, m (1 ≤ a, b, m ≤ 100). The first two integers specify point (a, 0, b), through which the ceiling and one of the corridor walls pass. The third integer is the distance at which Valera went away from the door. The second line has three space-separated integers vx, vy, vz (|vx|, |vy|, |vz| ≤ 100, vy < 0, vz ≥ 0) — the speed of the ball after the hit. It is guaranteed that the ball hits the door.

Print two real numbers x0, z0 — the x and z coordinates of point (x0, 0, z0), at which the ball hits the exit door. The answer will be considered correct, if its absolute or relative error does not exceed 10  - 6.


Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.

The first line contains two numbers n, k (1 ≤ n ≤ 100, 0 ≤ k ≤ 10 000), the number of instruments and number of days respectively. The second line contains n integers ai (1 ≤ ai ≤ 100), representing number of days required to learn the i-th instrument.

In the first line output one integer m representing the maximum number of instruments Amr can learn. In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order. if there are multiple optimal solutions output any. It is not necessary to use all days for studying.

NoteIn the first test Amr can learn all 4 instruments.In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.In the third test Amr doesn't have enough time to learn the only presented instrument.

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

my ($n, $k) = split ' ',<>;
my @input = split ' ', <>;
my @data;
for my $i(0..@input-1){
    push @data, [$input[$i], $i+1];
}
@data = sort {$a->[0] <=> $b->[0]} @data;
my ($sum,@res) = (0,());
foreach(@data){
    last if $sum + $_->[0] > $k;
    $sum += $_->[0];
    push @res, $_->[1];
}
print scalar @res , "\n@res";


There are three doors in front of you, numbered from $$$1$$$ to $$$3$$$ from left to right. Each door has a lock on it, which can only be opened with a key with the same number on it as the number on the door.There are three keys — one for each door. Two of them are hidden behind the doors, so that there is no more than one key behind each door. So two doors have one key behind them, one door doesn't have a key behind it. To obtain a key hidden behind a door, you should first unlock that door. The remaining key is in your hands.Can you open all the doors?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 18$$$) — the number of testcases. The first line of each testcase contains a single integer $$$x$$$ ($$$1 \le x \le 3$$$) — the number on the key in your hands. The second line contains three integers $$$a, b$$$ and $$$c$$$ ($$$0 \le a, b, c \le 3$$$) — the number on the key behind each of the doors. If there is no key behind the door, the number is equal to $$$0$$$. Values $$$1, 2$$$ and $$$3$$$ appear exactly once among $$$x, a, b$$$ and $$$c$$$.

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


The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points.As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:   At least one participant should get a diploma.  None of those with score equal to zero should get awarded.  When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas.

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≤ ai ≤ 600) — participants' scores. It's guaranteed that at least one participant has non-zero score.

Print a single integer — the desired number of ways.

NoteThere are three ways to choose a subset in sample case one.  Only participants with 3 points will get diplomas.  Participants with 2 or 3 points will get diplomas.  Everyone will get a diploma! The only option in sample case two is to award everyone.Note that in sample case three participants with zero scores cannot get anything.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){

	my %h;

	map $h{ $_ } ++, grep $_ > 0, split ' ', <>;

	print 0 + keys %h;
	}

<>;

map $h{ $_ } ++, grep $_, split ' ', <>;

print 0 + keys %h


Right now she actually isn't. But she will be, if you don't solve this problem.You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations:   Subtract 1 from x. This operation costs you A coins.  Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins.  What is the minimum amount of coins you have to pay to make x equal to 1?

The first line contains a single integer n (1 ≤ n ≤ 2·109). The second line contains a single integer k (1 ≤ k ≤ 2·109). The third line contains a single integer A (1 ≤ A ≤ 2·109). The fourth line contains a single integer B (1 ≤ B ≤ 2·109).

Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.

NoteIn the first testcase, the optimal strategy is as follows:   Subtract 1 from x (9 → 8) paying 3 coins.  Divide x by 2 (8 → 4) paying 1 coin.  Divide x by 2 (4 → 2) paying 1 coin.  Divide x by 2 (2 → 1) paying 1 coin. The total cost is 6 coins.In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total.


Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt.Unfortunately, you didn't manage to get into top 25, but you got into top 500, taking place p.Now the elimination round of 8VC Venture Cup 2017 is being held. It has been announced that the Codecraft-17 T-shirt winners will be chosen as follows. Let s be the number of points of the winner of the elimination round of 8VC Venture Cup 2017. Then the following pseudocode will be executed: i := (s div 50) mod 475repeat 25 times:    i := (i * 96 + 42) mod 475    print (26 + i)Here "div" is the integer division operator, "mod" is the modulo (the remainder of division) operator.As the result of pseudocode execution, 25 integers between 26 and 500, inclusive, will be printed. These will be the numbers of places of the participants who get the Codecraft-17 T-shirts. It is guaranteed that the 25 printed integers will be pairwise distinct for any value of s.You're in the lead of the elimination round of 8VC Venture Cup 2017, having x points. You believe that having at least y points in the current round will be enough for victory.To change your final score, you can make any number of successful and unsuccessful hacks. A successful hack brings you 100 points, an unsuccessful one takes 50 points from you. It's difficult to do successful hacks, though.You want to win the current round and, at the same time, ensure getting a Codecraft-17 T-shirt. What is the smallest number of successful hacks you have to do to achieve that?

The only line contains three integers p, x and y (26 ≤ p ≤ 500; 1 ≤ y ≤ x ≤ 20000) — your place in Codecraft-17, your current score in the elimination round of 8VC Venture Cup 2017, and the smallest number of points you consider sufficient for winning the current round.

Output a single integer — the smallest number of successful hacks you have to do in order to both win the elimination round of 8VC Venture Cup 2017 and ensure getting a Codecraft-17 T-shirt. It's guaranteed that your goal is achievable for any valid input data.

NoteIn the first example, there is no need to do any hacks since 10880 points already bring the T-shirt to the 239-th place of Codecraft-17 (that is, you). In this case, according to the pseudocode, the T-shirts will be given to the participants at the following places: 475 422 84 411 453 210 157 294 146 188 420 367 29 356 398 155 102 239 91 133 365 312 449 301 343In the second example, you have to do two successful and one unsuccessful hack to make your score equal to 7408.In the third example, you need to do as many as 24 successful hacks to make your score equal to 10400.In the fourth example, it's sufficient to do 6 unsuccessful hacks (and no successful ones) to make your score equal to 6500, which is just enough for winning the current round and also getting the T-shirt.


InputThe input contains a single integer a (1 ≤ a ≤ 40).OutputOutput a single string.ExamplesInput2OutputAdamsInput8OutputVan BurenInput29OutputHarding

#!/usr/bin/perl

use strict;
use warnings;

=pot
1 George and Martha Washington
2 John and Abigail Adams
3 Thomas Jefferson
4 James and Dolley Madison
5 James and Elizabeth Monroe
6 John Quincy and Louisa Adams
7 Andrew and Rachel Jackson
8 Martin and Hannah Van Buren
9 William and Anna Harrison
10 John Tyler
11 James and Sarah Polk
12 Zachary and Margaret Taylor
13 Millard and Abigail Fillmore
14 Franklin and Jane Pierce
15 James Buchanan
16 Abraham and Mary Lincoln
17 Andrew and Eliza Johnson
18 Ulysses and Julia Grant
19 Rutherford and Lucy Hayes
20 James and Lucretia Garfield
21 Chester and Ellen Arthur
22 Grover Cleveland and Maria Halpin
23 Benjamin Harrison
24 Grover and Frances Cleveland
25 William and Ida McKinley
26 Theodore Roosevelt
27 William and Helen Taft
28 Woodrow and Ellen Wilson
29 Warren G. Harding
30 Calvin and Grace Coolidge
31 Herbert and Lou Hoover
32 Franklin and Eleanor Roosevelt
33 Harry and Bess Truman
34 Dwight and Mamie Eisenhower
35 John and Jackie Kennedy
36 Lyndon and Lady Bird Johnson
37 Richard and Pat Nixon
38 Gerald and Betty Ford
39 Jimmy and Rosalynn Carter
40 Ronald Reagan
=cut

my @a = (
    'Washington',
    'Adams',
    'Jefferson',
    'Madison',
    'Monroe',
    'Adams',
    'Jackson',
    'Van Buren',
    'Harrison',
    'Tyler',
    'Polk',
    'Taylor',
    'Fillmore',
    'Pierce',
    'Buchanan',
    'Lincoln',
    'Johnson',
    'Grant',
    'Hayes',
    'Garfield',
    'Arthur',
    'Cleveland',
    'Harrison',
    'Cleveland',
    'McKinley',
    'Roosevelt',
    'Taft',
    'Wilson',
    'Harding',
    'Coolidge',
    'Hoover',
    'Roosevelt',
    'Truman',
    'Eisenhower',
    'Kennedy',
    'Johnson',
    'Nixon',
    'Ford',
    'Carter',
    'Reagan',
);

chomp($_ = <>);
print $a[$_ - 1];

@_=split/,/,'"Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson", "Van Buren", "Harrison", "Tyler", "Polk", "Taylor", "Fillmore", "Pierce", "Buchanan", "Lincoln", "Johnson", "Grant", "Hayes", "Garfield", "Arthur", "Cleveland", "Harrison", "Cleveland", "McKinley", "Roosevelt", "Taft", "Wilson", "Harding", "Coolidge", "Hoover", "Roosevelt", "Truman", "Eisenhower", "Kennedy", "Johnson", "Nixon", "Ford", "Carter", "Reagan"';
$_=$_[<>-1];
s/^\W*|\W*$//g;
print;
print "\n"

#!/usr/bin/perl

use strict;
use warnings;

=pot
1 George and Martha Washington
2 John and Abigail Adams
3 Thomas Jefferson
4 James and Dolley Madison
5 James and Elizabeth Monroe
6 John Quincy and Louisa Adams
7 Andrew and Rachel Jackson
8 Martin and Hannah Van Buren
9 William and Anna Harrison
10 John Tyler
11 James and Sarah Polk
12 Zachary and Margaret Taylor
13 Millard and Abigail Fillmore
14 Franklin and Jane Pierce
15 James Buchanan
16 Abraham and Mary Lincoln
17 Andrew and Eliza Johnson
18 Ulysses and Julia Grant
19 Rutherford and Lucy Hayes
20 James and Lucretia Garfield
21 Chester and Ellen Arthur
22 Grover Cleveland and Maria Halpin
23 Benjamin Harrison
24 Grover and Frances Cleveland
25 William and Ida McKinley
26 Theodore Roosevelt
27 William and Helen Taft
28 Woodrow and Ellen Wilson
29 Warren G. Harding
30 Calvin and Grace Coolidge
31 Herbert and Lou Hoover
32 Franklin and Eleanor Roosevelt
33 Harry and Bess Truman
34 Dwight and Mamie Eisenhower
35 John and Jackie Kennedy
36 Lyndon and Lady Bird Johnson
37 Richard and Pat Nixon
38 Gerald and Betty Ford
39 Jimmy and Rosalynn Carter
40 Ronald Reagan
=cut

my @a = (
    'Washington',
    'Adams',
    'Jefferson',
    'Madison',
    'Monroe',
    'Adams',
    'Jackson',
    'Van Buren',
    'Harrison',
    'Tyler',
    'Polk',
    'Taylor',
    'Fillmore',
    'Pierce',
    'Buchanan',
    'Lincoln',
    'Johnson',
    'Grant',
    'Hayes',
    'Garfield',
    'Arthur',
    'Halpin',
    'Harrison',
    'Cleveland',
    'McKinley',
    'Roosevelt',
    'Taft',
    'Wilson',
    'Harding',
    'Coolidge',
    'Hoover',
    'Roosevelt',
    'Truman',
    'Eisenhower',
    'Kennedy',
    'Johnson',
    'Nixon',
    'Ford',
    'Carter',
    'Reagan',
);

chomp($_ = <>);
print $a[$_ - 1];

chomp($n=<>);
@_=split/\n/,"    1.1 George Washington
    1.2 John Adams
    1.3 Thomas Jefferson
    1.4 James Madison
    1.5 James Monroe
    1.6 John Quincy Adams
    1.7 Andrew Jackson
    1.8 Martin Van Buren
    1.9 William Henry Harrison
    1.10 John Tyler
    1.11 James K. Polk
    1.12 Zachary Taylor
    1.13 Millard Fillmore
    1.14 Franklin Pierce
    1.15 James Buchanan
    1.16 Abraham Lincoln
    1.17 Andrew Johnson
    1.18 Ulysses S. Grant
    1.19 Rutherford B. Hayes
    1.20 James A. Garfield
    1.21 Chester A. Arthur
    1.22 Grover Cleveland
    1.23 Benjamin Harrison
    1.24 William McKinley
    1.25 Theodore Roosevelt
    1.26 William Howard Taft
    1.27 Woodrow Wilson
    1.28 Warren G. Harding
    1.29 Calvin Coolidge
    1.30 Herbert Hoover
    1.31 Franklin D. Roosevelt
    1.32 Harry S. Truman
    1.33 Dwight D. Eisenhower
    1.34 John F. Kennedy
    1.35 Lyndon B. Johnson
    1.36 Richard Nixon
    1.37 Gerald Ford
    1.38 Jimmy Carter
    1.39 Ronald Reagan
    1.40 George H. W. Bush
    1.41 Bill Clinton
    1.42 George W. Bush
    1.43 Barack Obama";
for (@_){
if (/$n/){
    s/\s*1\.\d+\s\w+\s//;
    s/.*\.\s//;
    print;
    print "\n";
    last
    }
}

@_=split/,/,'"Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson", "Van Buren", "Harrison", "Tyler", "Polk", "Taylor", "Fillmore", "Pierce", "Buchanan", "Lincoln", "Johnson", "Grant", "Hayes", "Garfield", "Arthur", "Cleveland", "Harrison", "Cleveland", "McKinley", "Roosevelt", "Taft", "Wilson", "Harding", "Coolidge", "Hoover", "Roosevelt", "Truman", "Eisenhower", "Kennedy", "Johnson", "Nixon", "Ford", "Carter", "Reagan"';
$_=$_[<>-1];
s/\W//g;
print;
print "\n"

$n=<>;
@_=split/\n/,"    1.1 George Washington
    1.2 John Adams
    1.3 Thomas Jefferson
    1.4 James Madison
    1.5 James Monroe
    1.6 John Quincy Adams
    1.7 Andrew Jackson
    1.8 Martin Van Buren
    1.9 William Henry Harrison
    1.10 John Tyler
    1.11 James K. Polk
    1.12 Zachary Taylor
    1.13 Millard Fillmore
    1.14 Franklin Pierce
    1.15 James Buchanan
    1.16 Abraham Lincoln
    1.17 Andrew Johnson
    1.18 Ulysses S. Grant
    1.19 Rutherford B. Hayes
    1.20 James A. Garfield
    1.21 Chester A. Arthur
    1.22 Grover Cleveland
    1.23 Benjamin Harrison
    1.24 William McKinley
    1.25 Theodore Roosevelt
    1.26 William Howard Taft
    1.27 Woodrow Wilson
    1.28 Warren G. Harding
    1.29 Calvin Coolidge
    1.30 Herbert Hoover
    1.31 Franklin D. Roosevelt
    1.32 Harry S. Truman
    1.33 Dwight D. Eisenhower
    1.34 John F. Kennedy
    1.35 Lyndon B. Johnson
    1.36 Richard Nixon
    1.37 Gerald Ford
    1.38 Jimmy Carter
    1.39 Ronald Reagan
    1.40 George H. W. Bush
    1.41 Bill Clinton
    1.42 George W. Bush
    1.43 Barack Obama";
for (@_){
if (/$n/){
    s/\s*1\.\d+\s\w+\s//;
    s/.*\.\s//;
    print;
    print "\n";
    last
    }
}

$n=<>;
@_=split/\n/,"    1.1 George Washington
    1.2 John Adams
    1.3 Thomas Jefferson
    1.4 James Madison
    1.5 James Monroe
    1.6 John Quincy Adams
    1.7 Andrew Jackson
    1.8 Martin Van Buren
    1.9 William Henry Harrison
    1.10 John Tyler
    1.11 James K. Polk
    1.12 Zachary Taylor
    1.13 Millard Fillmore
    1.14 Franklin Pierce
    1.15 James Buchanan
    1.16 Abraham Lincoln
    1.17 Andrew Johnson
    1.18 Ulysses S. Grant
    1.19 Rutherford B. Hayes
    1.20 James A. Garfield
    1.21 Chester A. Arthur
    1.22 Grover Cleveland
    1.23 Benjamin Harrison
    1.24 William McKinley
    1.25 Theodore Roosevelt
    1.26 William Howard Taft
    1.27 Woodrow Wilson
    1.28 Warren G. Harding
    1.29 Calvin Coolidge
    1.30 Herbert Hoover
    1.31 Franklin D. Roosevelt
    1.32 Harry S. Truman
    1.33 Dwight D. Eisenhower
    1.34 John F. Kennedy
    1.35 Lyndon B. Johnson
    1.36 Richard Nixon
    1.37 Gerald Ford
    1.38 Jimmy Carter
    1.39 Ronald Reagan
    1.40 George H. W. Bush
    1.41 Bill Clinton
    1.42 George W. Bush
    1.43 Barack Obama";
for (@_){
chomp;
if (/$n/){
    s/\s*1\.\d+\s\w+\s//;
    s/.*\.\s//;
    print;
    print "\n";
    last
    }
}


Finished her homework, Nastya decided to play computer games. Passing levels one by one, Nastya eventually faced a problem. Her mission is to leave a room, where a lot of monsters live, as quickly as possible.There are $$$n$$$ manholes in the room which are situated on one line, but, unfortunately, all the manholes are closed, and there is one stone on every manhole. There is exactly one coin under every manhole, and to win the game Nastya should pick all the coins. Initially Nastya stands near the $$$k$$$-th manhole from the left. She is thinking what to do.In one turn, Nastya can do one of the following:   if there is at least one stone on the manhole Nastya stands near, throw exactly one stone from it onto any other manhole (yes, Nastya is strong).  go to a neighboring manhole;  if there are no stones on the manhole Nastya stays near, she can open it and pick the coin from it. After it she must close the manhole immediately (it doesn't require additional moves).     The figure shows the intermediate state of the game. At the current position Nastya can throw the stone to any other manhole or move left or right to the neighboring manholes. If she were near the leftmost manhole, she could open it (since there are no stones on it). Nastya can leave the room when she picks all the coins. Monsters are everywhere, so you need to compute the minimum number of moves Nastya has to make to pick all the coins.Note one time more that Nastya can open a manhole only when there are no stones onto it.

The first and only line contains two integers $$$n$$$ and $$$k$$$, separated by space ($$$2 \leq n \leq 5000$$$, $$$1 \leq k \leq n$$$) — the number of manholes and the index of manhole from the left, near which Nastya stays initially. Initially there is exactly one stone near each of the $$$n$$$ manholes.

Print a single integer — minimum number of moves which lead Nastya to pick all the coins.

NoteLet's consider the example where $$$n = 2$$$, $$$k = 2$$$. Nastya should play as follows:  At first she throws the stone from the second manhole to the first. Now there are two stones on the first manhole.  Then she opens the second manhole and pick the coin from it.  Then she goes to the first manhole, throws two stones by two moves to the second manhole and then opens the manhole and picks the coin from it. So, $$$6$$$ moves are required to win.

#!/usr/bin/perl -wl

use strict;

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

    print $n + $n - 1 + $min + 1 + $n;
    }

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

while (<>) {
    my ($n, $k) = split;
    my ($step) = sort {$a <=> $b} ($n - $k, $k - 1);
    $step += $n - 1;
    print $step + 2 * $n + 1;
}


Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.A year is leap in one of two cases: either its number is divisible by 4, but not divisible by 100, or is divisible by 400. For example, the following years are leap: 2000, 2004, but years 1900 and 2018 are not leap.In this problem you are given n (1 ≤ n ≤ 24) integers a1, a2, ..., an, and you have to check if these integers could be durations in days of n consecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there is a month in some year, such that its duration is a1 days, duration of the next month is a2 days, and so on.

The first line contains single integer n (1 ≤ n ≤ 24) — the number of integers. The second line contains n integers a1, a2, ..., an (28 ≤ ai ≤ 31) — the numbers you are to check.

If there are several consecutive months that fit the sequence, print "YES" (without quotes). Otherwise, print "NO" (without quotes). You can print each letter in arbitrary case (small or large).

NoteIn the first example the integers can denote months July, August, September and October.In the second example the answer is no, because there are no two consecutive months each having 30 days.In the third example the months are: February (leap year) — March — April – May — June.In the fourth example the number of days in the second month is 28, so this is February. March follows February and has 31 days, but not 30, so the answer is NO.In the fifth example the months are: December — January — February (non-leap year).

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $y = join ' ',
	map {
		join ' ', 31, $_,
			qq{
			... в марте 31 день, в апреле 30 дней,
			в мае 31 день, в июне 30 дней, в июле 31 день,
			в августе 31 день, в сентябре 30 дней, в октябре 31 день,
			в ноябре 30 дней, в декабре 31 день.
			} =~ /\d+/g
	} 28, 28, 28, 29, 28, 28;

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

	print $y =~ /$_/ ? "Yes" : "No";
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $y = join ' ',
	map {
		join ' ', 31, $_,
			qq{
			... в марте 31 день, в апреле 30 дней,
			в мае 31 день, в июне 30 дней, в июле 31 день,
			в августе 31 день, в сентябре 30 дней, в октябре 31 день,
			в ноябре 30 дней, в декабре 31 день.
			} =~ /\d+/g
	} 28, 28, 29, 28;

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

	print $y =~ /$_/ ? "Yes" : "No";
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $y = join ' ',
	map {
		join ' ', 31, $_,
			qq{
			... в марте 31 день, в апреле 30 дней,
			в мае 31 день, в июне 30 дней, в июле 31 день,
			в августе 31 день, в сентябре 30 дней, в октябре 31 день,
			в ноябре 30 дней, в декабре 31 день.
			} =~ /\d+/g
	} 28, 28, 29, 28;

print $y;

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

	print $y =~ /$_/ ? "Yes" : "No";
	}


It is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through n, are arranged so that the i-th cow occupies the i-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his k minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute.Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the k minutes that they have. We denote as pi the label of the cow in the i-th stall. The messiness of an arrangement of cows is defined as the number of pairs (i, j) such that i < j and pi > pj.

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100 000) — the number of cows and the length of Farmer John's nap, respectively.

Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than k swaps.

NoteIn the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.In the second sample, there is only one cow, so the maximum possible messiness is 0.

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

my $maxSwaps = $n >> 1;
$maxSwaps = ($maxSwaps < $k) ? $maxSwaps : $k;

my $x = $maxSwaps;

$x = $x * (($n << 1) - ($x << 1) - 1);

print $x;

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

my $maxSwaps = $n >> 1;
$maxSwaps = ($maxSwaps < $k) ? $maxSwaps : $k;

my $x = $maxSwaps << 1;

$x++ if ($n & 1);
print (($x * ($x - 1)) >> 1);


There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.

The first line contains integer n (1 ≤ n ≤ 50) — the number of stones on the table.  The next line contains string s, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to n from left to right. Then the i-th character s equals "R", if the i-th stone is red, "G", if it's green and "B", if it's blue.

Print a single integer — the answer to the problem.

#!/usr/bin/perl

use strict;
use warnings;

<>;
chomp($_ = <>);
my @a = split //;
my $res = 0;
my $pre = shift @a;
while (@a) {
    my $cur = shift @a;
    ++$res if $pre eq $cur;
    $pre = $cur;
}
print "$res\n";

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

chomp($len = <>);
chomp($line = <>);
@a = split //, $line;
$i = 0;
$ans = 0;
while ($i < $len) {
	$j = $i++;
	while ($i<$len && $a[$i] eq $a[$j]) {
		++$i;
	}
	$ans += $i-$j-1;
}
say $ans;

use strict;
use warnings;

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

my $in = <>;
chomp($in);
my @s = split('', $in);

my $n=0;

# r b g
# if ff or bb or gg we have to remove one stone
# if this stone==next stone, remove this stone. move to next....

for (my $i=0; $i<$stones-1; $i++) {
    if ($s[$i] eq $s[$i+1]) {
        $n++;
    }
}

print $n;

use strict;
use warnings;

<>;
$_ = <>;
chomp;
my @l = split '';
my $res = 0;
for my $i (1..@l-1) {
    $res++ if ($l[$i] eq $l[$i-1]);
}
print "$res\n";

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

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

my @chrs = split("", $s);
my $i = 0;
my $cnt = 0;
while ($i < ($n - 1)) {
    if ($chrs[$i] eq $chrs[$i + 1]) {
        # <STDIN>;
        splice(@chrs, $i, 1);
        $cnt += 1;
        $n -= 1;
    } else {
        $i += 1;
    }
}
print $cnt;
# print $n;
# print $s;

<STDIN>;
@str = split(//, <STDIN>);
$count = 0;

for($i = 0; $i < $#str; $i++)
{
    if($str[$i] eq $str[$i + 1])
    {
        ++$count;
    }
}
print STDOUT $count;

<stdin>; chomp($_ = <stdin>); my ($last, $res)=("", 0); for(split("")){ if( $last eq $_ ){ $res += 1 }else{ $last = $_ } } print "$res\n"

#!/bin/perl

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

$s =~ s/R+/c/g;
$s =~ s/G+/c/g;
$s =~ s/B+/c/g;

print ( $n - length $s );

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

my $n = <STDIN>; $_ = <STDIN>;
foreach my $c (qw[R G B]) { s/$c+/$c/g }
print $n + 1 - length . "\n";

#!/bin/perl

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

$b = $s;

$s =~ s/R+/c/;
$s =~ s/G+/c/;
$s =~ s/B+/c/;

print ( ( length $b ) - ( length $s ) );


Gerald is setting the New Year table. The table has the form of a circle; its radius equals R. Gerald invited many guests and is concerned whether the table has enough space for plates for all those guests. Consider all plates to be round and have the same radii that equal r. Each plate must be completely inside the table and must touch the edge of the table. Of course, the plates must not intersect, but they can touch each other. Help Gerald determine whether the table is large enough for n plates.

The first line contains three integers n, R and r (1 ≤ n ≤ 100, 1 ≤ r, R ≤ 1000) — the number of plates, the radius of the table and the plates' radius.

Print "YES" (without the quotes) if it is possible to place n plates on the table by the rules given above. If it is impossible, print "NO". Remember, that each plate must touch the edge of the table.

NoteThe possible arrangement of the plates for the first sample is:

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

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

$`-1 or (print ($'>$1?"NO":"YES"));
$`-1 or last;
print (($'+$'/sin($PI/$`)>$1)?"NO":"YES")

}

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

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

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

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

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

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

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

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

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

# rotL_s
# rotR_s

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

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

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

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

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

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


Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".To play Mau-Mau, you need a pack of $$$52$$$ cards. Each card has a suit (Diamonds — D, Clubs — C, Spades — S, or Hearts — H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.

The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand. Each string is two characters long. The first character denotes the rank and belongs to the set $$$\{{\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, {\tt 9}, {\tt T}, {\tt J}, {\tt Q}, {\tt K}, {\tt A}\}$$$. The second character denotes the suit and belongs to the set $$$\{{\tt D}, {\tt C}, {\tt S}, {\tt H}\}$$$. All the cards in the input are different.

If it is possible to play a card from your hand, print one word "YES". Otherwise, print "NO". You can print each letter in any case (upper or lower).

NoteIn the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.In the second example, you cannot play any card.In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table.

#!/usr/bin/env perl

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

# essential
my @tokens = ();

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

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

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

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

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

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

# solve

my $card_on_table = read_token;

my ($suit, $rank) = split q{}, $card_on_table;

my @cards_on_hand = split q{ }, read_line;

my $flag = 0;

for (@cards_on_hand) {
    my ($s, $r) = split q{}, $_;
    if ( $s eq $suit || $r eq $rank ) {
        $flag = 1;
        last;
    }
}

if ($flag) {
    say 'YES';
}
else {
    say 'NO';
}


Karen is getting ready for a new school day!  It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.

The first and only line of input contains a single string in the format hh:mm (00 ≤  hh  ≤ 23, 00 ≤  mm  ≤ 59).

Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.

NoteIn the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome.

sub checkPl
{
    my ($h, $m) = @_;

    $h=scalar reverse $h;
    if($h==$m)
    {
        return "1";
    }
    return "0";
}
$str=<STDIN>;
my @chars = split("", $str);
$h=$chars[0].$chars[1];
$m=$chars[3].$chars[4];
$steps=0;
while(1)
{
    if(checkPl($h,$m)=="1")
    {
        print $steps;
        last;
    }
    $steps++;
    $m++;
    if($m==60)
    {
        $m=0;
        $h++;
    }
    if($h==24)
       { $h=0;}
}


You want to arrange n integers a1, a2, ..., an in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.More formally, let's denote some arrangement as a sequence of integers x1, x2, ..., xn, where sequence x is a permutation of sequence a. The value of such an arrangement is (x1 - x2) + (x2 - x3) + ... + (xn - 1 - xn).Find the largest possible value of an arrangement. Then, output the lexicographically smallest sequence x that corresponds to an arrangement of the largest possible value.

The first line of the input contains integer n (2 ≤ n ≤ 100). The second line contains n space-separated integers a1, a2, ..., an (|ai| ≤ 1000).

Print the required sequence x1, x2, ..., xn. Sequence x should be the lexicographically smallest permutation of a that corresponds to an arrangement of the largest possible value.

NoteIn the sample test case, the value of the output arrangement is (100 - ( - 50)) + (( - 50) - 0) + (0 - 50) + (50 - ( - 100)) = 200. No other arrangement has a larger value, and among all arrangements with the value of 200, the output arrangement is the lexicographically smallest one.Sequence x1, x2, ... , xp is lexicographically smaller than sequence y1, y2, ... , yp if there exists an integer r (0 ≤ r < p) such that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1.

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

<>;
@_=split/ /,<>;
chomp (@_);
@_= sort num_rev @_;
$first = shift @_;
$last = pop @_;
@_= reverse @_;
unshift @_, $first;
push @_, $last;
print "@_";

#***********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/ /,<>;
chomp (@_);
@_= sort num_rev @_;
$first = shift @_;
$last = pop @_;
@_= sort @_;
unshift @_, $first;
push @_, $last;
print "@_\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+) /;

<>;
@_=split/ /,<>;
@_= sort num_rev @_;
$first = shift @_;
$last = pop @_;
@_= sort @_;
unshift @_, $first;
push @_, $last;
print "@_";

#***********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/ /,<>;
@_= sort num_rev @_;
$first = shift @_;
$last = pop @_;
@_= sort @_;
print $first, " @_ ", $last;

#***********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/ /,<>;
chomp (@_);
@_= sort num_rev @_;
$first = shift @_;
$last = pop @_;
@_= sort @_;
unshift @_, $first;
push @_, $last;
print "@_";

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


When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number k. Moreover, petricium la petricium stands for number k2, petricium la petricium la petricium stands for k3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.Petya's invention brought on a challenge that needed to be solved quickly: does some number l belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.

The first input line contains integer number k, the second line contains integer number l (2 ≤ k, l ≤ 231 - 1).

You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number l.


Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not. The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).

The tic-tac-toe position is given in four lines. Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.

Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.

NoteIn the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.In the second example it wasn't possible to win by making single turn.In the third example Ilya could have won by placing X in the last row between two existing Xs.In the fourth example it wasn't possible to win by making single turn.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

while(!eof){
	$_ = join '', map ~~<>, 1 .. 4;
	y/./,/;

	my @rxs;

	for my $join ( map { '.' x $_ } 0, 3, 4, 5 ){
		for my $arrange ( 'xx,xx' =~ /(?=(...))/g ){
			push @rxs, join $join, split '', $arrange;
			}
		}

	my $re = join '|', @rxs;

	$debug and print $re;

	print /$re/gs ? "YES" : "NO";

	$debug and print "pos:", pos, "[$&]";
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

while(!eof){
	$_ = join '', split ' ', join '', map ~~<>, 1 .. 4;
	y/./,/;

	my @rxs;

	for my $join ( map { '[^o]' x $_ } 0, 2, 3, 4 ){
		for my $arrange ( 'xx,xx' =~ /(?=(...))/g ){
			push @rxs, join $join, split '', $arrange;
			}
		}

	$debug and print "/xx,|x,x|,xx|x...x...,|x...,...x|,...x...x|x....x....,|x....,....x|,....x....x|/";

	my $re = join '|', @rxs;

	$debug and print $re;

	print /$re/ ? "YES" : "NO";

	}


qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf.

jxu ydfkj sediyiji ev q iydwbu ydjuwuh d (1 ≤ d ≤ 11184) — jxu edu-rqiut ydtun ev jxu ucyhf je vydt.

my $total = 1000000;
my @isp = (1) x ($total + 1);
for my $i (2 .. $total) {
	next unless $isp[$i];
	for my $j ($i .. int($total / $i)) {
		$isp[$i * $j] = 0;
	}
}
chomp(my $n = <>);
my $count = 0;
for my $i (2 .. $total) {
	next unless $isp[$i];
	my $j = join '', reverse split //, $i;
	next unless $isp[$j] && $i != $j;
	if (++$count == $n) {
		print "$i\n";
		last;
	}
}